X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=dev%2Fetherpkt.hh;h=cb9022d7256d108d424819fa3764576d5de6e90f;hb=60e92986f739a025a6534972b8e1cf9498ce3fd2;hp=abdf301663216d69de3be99865e7df2aa4a713f8;hpb=75ed8090bf34c38123c779a7f040108268d32a1b;p=gem5.git diff --git a/dev/etherpkt.hh b/dev/etherpkt.hh index abdf30166..cb9022d72 100644 --- a/dev/etherpkt.hh +++ b/dev/etherpkt.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2004 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 @@ -37,70 +37,48 @@ #include #include -#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: + /* + * 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 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; } + 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 d, int l, int s = 0) + : data(d.release()), length(l), slack(s) { } + ~PacketData() { if (data) delete [] data; } - bool isIpPkt() { - eth_header *eth = (eth_header *) data; - return (eth->type == 0x8); - } - bool isTcpPkt(ip_header *ip) { - return (ip->protocol == 0x6); - } - bool isTcpPkt() { - ip_header *ip = getIpHdr(); - return (ip->protocol == 0x6); - } - bool isUdpPkt(ip_header *ip) { - return (ip->protocol == 17); - } - 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) { - assert(isTcpPkt(ip)); - return (tcp_header *) ((uint8_t *) ip + (ip->vers_len & 0xf)*4); - } - - udp_header *getUdpHdr(ip_header *ip) { - assert(isUdpPkt(ip)); - return (udp_header *) ((uint8_t *) ip + (ip->vers_len & 0xf)*4); - } - typedef RefCountingPtr PacketPtr; - - void serialize(std::ostream &os); - void unserialize(Checkpoint *cp, const std::string §ion); + public: + void serialize(const std::string &base, std::ostream &os); + void unserialize(const std::string &base, Checkpoint *cp, + const std::string §ion); }; -typedef RefCountingPtr PacketPtr; +typedef RefCountingPtr PacketPtr; #endif // __ETHERPKT_HH__