etherpkt.hh revision 2566
13691SN/A/* 23691SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 39449SAli.Saidi@ARM.com * All rights reserved. 410409Sandreas.hansson@arm.com * 510409Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68721SN/A * modification, are permitted provided that the following conditions are 711606Sandreas.sandberg@arm.com * met: redistributions of source code must retain the above copyright 811606Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer; 911606Sandreas.sandberg@arm.com * redistributions in binary form must reproduce the above copyright 1011606Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer in the 1111606Sandreas.sandberg@arm.com * documentation and/or other materials provided with the distribution; 1210409Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 1310409Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 1410778Snilay@cs.wisc.edu * this software without specific prior written permission. 1510778Snilay@cs.wisc.edu * 1611530Sandreas.sandberg@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1710778Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1810778Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1910778Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2010778Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2110778Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2210778Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2310778Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2410778Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2510778Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2610778Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2710778Snilay@cs.wisc.edu */ 2810778Snilay@cs.wisc.edu 2910778Snilay@cs.wisc.edu/* @file 3010778Snilay@cs.wisc.edu * Reference counted class containing ethernet packet data 3110778Snilay@cs.wisc.edu */ 3210778Snilay@cs.wisc.edu 3310778Snilay@cs.wisc.edu#ifndef __ETHERPKT_HH__ 3410778Snilay@cs.wisc.edu#define __ETHERPKT_HH__ 3510778Snilay@cs.wisc.edu 3610778Snilay@cs.wisc.edu#include <iosfwd> 3710778Snilay@cs.wisc.edu#include <memory> 3810778Snilay@cs.wisc.edu#include <assert.h> 3910778Snilay@cs.wisc.edu 4010778Snilay@cs.wisc.edu#include "base/refcnt.hh" 4110778Snilay@cs.wisc.edu#include "sim/host.hh" 4210778Snilay@cs.wisc.edu 4310778Snilay@cs.wisc.edu/* 4410778Snilay@cs.wisc.edu * Reference counted class containing ethernet packet data 4510778Snilay@cs.wisc.edu */ 4611530Sandreas.sandberg@arm.comclass Checkpoint; 4711530Sandreas.sandberg@arm.comclass EthPacketData : public RefCounted 4810778Snilay@cs.wisc.edu{ 4910778Snilay@cs.wisc.edu public: 5010778Snilay@cs.wisc.edu /* 5110778Snilay@cs.wisc.edu * Pointer to packet data will be deleted 5210778Snilay@cs.wisc.edu */ 5310778Snilay@cs.wisc.edu uint8_t *data; 5410778Snilay@cs.wisc.edu 5510778Snilay@cs.wisc.edu /* 5610778Snilay@cs.wisc.edu * Length of the current packet 5710778Snilay@cs.wisc.edu */ 5810778Snilay@cs.wisc.edu int length; 5910778Snilay@cs.wisc.edu 6010778Snilay@cs.wisc.edu /* 6110778Snilay@cs.wisc.edu * Extra space taken up by the packet in whatever data structure 6210778Snilay@cs.wisc.edu * it is in. 6310778Snilay@cs.wisc.edu * 6410778Snilay@cs.wisc.edu * NOTE: This can only be use by *one* data structure at a time! 6510778Snilay@cs.wisc.edu */ 6610778Snilay@cs.wisc.edu int slack; 6710778Snilay@cs.wisc.edu 6810778Snilay@cs.wisc.edu public: 6910778Snilay@cs.wisc.edu EthPacketData() : data(NULL), length(0), slack(0) { } 7010778Snilay@cs.wisc.edu explicit EthPacketData(size_t size) 7110778Snilay@cs.wisc.edu : data(new uint8_t[size]), length(0), slack(0) { } 7210778Snilay@cs.wisc.edu EthPacketData(std::auto_ptr<uint8_t> d, int l, int s = 0) 7310778Snilay@cs.wisc.edu : data(d.release()), length(l), slack(s) { } 7410778Snilay@cs.wisc.edu ~EthPacketData() { if (data) delete [] data; } 7510778Snilay@cs.wisc.edu 7610778Snilay@cs.wisc.edu public: 7710778Snilay@cs.wisc.edu void serialize(const std::string &base, std::ostream &os); 7810778Snilay@cs.wisc.edu void unserialize(const std::string &base, Checkpoint *cp, 7910778Snilay@cs.wisc.edu const std::string §ion); 8010778Snilay@cs.wisc.edu}; 8111530Sandreas.sandberg@arm.com 8211530Sandreas.sandberg@arm.comtypedef RefCountingPtr<EthPacketData> EthPacketPtr; 8311530Sandreas.sandberg@arm.com 8411530Sandreas.sandberg@arm.com#endif // __ETHERPKT_HH__ 8511530Sandreas.sandberg@arm.com