always initalize the size of a packet (forgotten on checkpoints
[gem5.git] / dev / etherpkt.hh
index 76b4a9156978423d37b2223e987814db32c7d0e6..7a7809f0a1f12f5ad8a34f73d0df335938d05c94 100644 (file)
 #include <memory>
 #include <assert.h>
 
-#include "sim/host.hh"
 #include "base/refcnt.hh"
-#include "base/inet_hdrs.hh"
+#include "sim/host.hh"
 
-class Checkpoint;
 /*
  * Reference counted class containing ethernet packet data
  */
-class EtherPacket : public RefCounted
+class Checkpoint;
+class PacketData : public RefCounted
 {
   public:
     uint8_t *data;
     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; }
+    PacketData() : data(NULL), length(0) { }
+    explicit PacketData(size_t size) : data(new uint8_t[size]), length(0) { }
+    PacketData(std::auto_ptr<uint8_t> d, int l)
+        : data(d.release()), length(l) { }
+    ~PacketData() { if (data) delete [] data; }
 
   public:
-    bool IsUnicast() { return data[0] == 0x00; }
-    bool IsMulticast() { return data[0] == 0x01; }
-    bool IsBroadcast() { return data[0] == 0xff; }
-
-    bool isIpPkt() {
-        eth_header *eth = (eth_header *) data;
-        return (eth->type == 0x800);
-    }
-    bool isTcpPkt() {
-        ip_header *ip = getIpHdr();
-        return (ip->protocol == 6);
-    }
-    bool isUdpPkt() {
-        ip_header *ip = getIpHdr();
-        return (ip->protocol == 17);
-    }
-
-    ip_header *getIpHdr() {
-        assert(isIpPkt());
-        return (ip_header *) (data + sizeof(eth_header));
-    }
-
-    tcp_header *getTcpHdr(ip_header *ip) {
-        return (tcp_header *) (ip + (ip->vers_len & 0xf));
-    }
-
-    udp_header *getUdpHdr(ip_header *ip) {
-        return (udp_header *) (ip + (ip->vers_len & 0xf));
-    }
-    typedef RefCountingPtr<EtherPacket> PacketPtr;
-
-    void serialize(std::ostream &os);
-    void unserialize(Checkpoint *cp, const std::string &section);
+    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__