Changed ev5_trap from a function of the execution context to a function of the fault...
[gem5.git] / dev / etherpkt.hh
index 09516c427c54077b69a2efef237c5beb99c10b1f..cb9022d7256d108d424819fa3764576d5de6e90f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003 The Regents of The University of Michigan
+ * Copyright (c) 2002-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #include <iosfwd>
 #include <memory>
+#include <assert.h>
 
-#include "sim/host.hh"
 #include "base/refcnt.hh"
-
-#define EADDR_LEN 6
-
-class Checkpoint;
-
-struct pseudo_header
-{
-    uint32_t src_ip_addr;
-    uint32_t dest_ip_addr;
-    uint16_t protocol;
-    uint16_t len;
-};
-
-/** Ethernet header struct for casting purposes */
-struct eth_header
-{
-    uint8_t dest[EADDR_LEN];
-    uint8_t src[EADDR_LEN];
-    uint16_t type;
-};
-
-struct ip_header
-{
-    uint8_t vers_len;
-    uint8_t service_type;
-    uint16_t dgram_len;
-    uint16_t ID;
-    uint16_t flags_frag_offset;
-    uint8_t TTL;
-    uint8_t protocol;
-    uint16_t hdr_chksum;
-    uint32_t src_ip_addr;
-    uint32_t dest_ip_addr;
-    uint8_t *options;
-    uint8_t *transport_header;
-};
-
-struct tcp_header
-{
-    uint16_t src_port_num;
-    uint16_t dest_port_num;
-    uint32_t seq_num;
-    uint32_t ack_num;
-    uint8_t hdr_len;
-    uint8_t flags;
-    uint16_t rcv_window;
-    uint16_t chksum;
-    uint16_t urgent;
-    uint8_t *options;
-    uint8_t *data;
-};
-
-struct udp_header
-{
-    uint16_t src_port_num;
-    uint16_t dest_port_num;
-    uint16_t len;
-    uint16_t chksum;
-    uint8_t *data;
-};
+#include "sim/host.hh"
 
 /*
  * Reference counted class containing ethernet packet data
  */
-class EtherPacket : public RefCounted
+class Checkpoint;
+class PacketData : public RefCounted
 {
   public:
+    /*
+     * Pointer to packet data will be deleted
+     */
     uint8_t *data;
+
+    /*
+     * Length of the current packet
+     */
     int length;
 
-  public:
-    EtherPacket() : data(NULL), length(0) {}
-    EtherPacket(std::auto_ptr<uint8_t> d, int l)
-        : data(d.release()), length(l) {}
-    ~EtherPacket() { if (data) delete [] data; }
+    /*
+     * Extra space taken up by the packet in whatever data structure
+     * it is in.
+     *
+     * NOTE: This can only be use by *one* data structure at a time!
+     */
+    int slack;
 
   public:
-    bool IsUnicast() { return data[0] == 0x00; }
-    bool IsMulticast() { return data[0] == 0x01; }
-    bool IsBroadcast() { return data[0] == 0xff; }
-
-    ip_header *getIpHdr() { return (ip_header *) (data + 14); }
-
-    void *getTransportHdr() {
-        ip_header *ip = getIpHdr();
-        return (void *) (ip + (ip->vers_len & 0xf));
-    }
+    PacketData() : data(NULL), length(0), slack(0) { }
+    explicit PacketData(size_t size)
+        : data(new uint8_t[size]), length(0), slack(0) { }
+    PacketData(std::auto_ptr<uint8_t> d, int l, int s = 0)
+        : data(d.release()), length(l), slack(s) { }
+    ~PacketData() { if (data) delete [] data; }
 
-
-    typedef RefCountingPtr<EtherPacket> PacketPtr;
-
-    void serialize(std::ostream &os);
-    void unserialize(Checkpoint *cp, const std::string &section);
+  public:
+    void serialize(const std::string &base, std::ostream &os);
+    void unserialize(const std::string &base, Checkpoint *cp,
+                     const std::string &section);
 };
 
-typedef RefCountingPtr<EtherPacket> PacketPtr;
+typedef RefCountingPtr<PacketData> PacketPtr;
 
 #endif // __ETHERPKT_HH__