etherpkt.hh revision 10923
12SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu * Lisa Hsu 302SN/A */ 312SN/A 321388SN/A/* @file 332SN/A * Reference counted class containing ethernet packet data 342SN/A */ 352SN/A 361191SN/A#ifndef __ETHERPKT_HH__ 371191SN/A#define __ETHERPKT_HH__ 381191SN/A 391388SN/A#include <cassert> 401717SN/A#include <iosfwd> 412651Ssaidi@eecs.umich.edu#include <memory> 422680Sktlim@umich.edu 431977SN/A#include "base/types.hh" 443144Shsul@eecs.umich.edu#include "sim/serialize.hh" 45161SN/A 462190SN/A/* 4756SN/A * Reference counted class containing ethernet packet data 482190SN/A */ 492SN/Aclass EthPacketData 501062SN/A{ 511062SN/A public: 522359SN/A /* 532359SN/A * Pointer to packet data will be deleted 542359SN/A */ 552SN/A uint8_t *data; 562SN/A 572SN/A /* 582SN/A * Length of the current packet 592SN/A */ 602SN/A unsigned length; 612SN/A 622SN/A public: 632SN/A EthPacketData() 643126Sktlim@umich.edu : data(NULL), length(0) 653126Sktlim@umich.edu { } 663126Sktlim@umich.edu 673126Sktlim@umich.edu explicit EthPacketData(unsigned size) 683126Sktlim@umich.edu : data(new uint8_t[size]), length(0) 693126Sktlim@umich.edu { } 703126Sktlim@umich.edu 713126Sktlim@umich.edu ~EthPacketData() { if (data) delete [] data; } 723126Sktlim@umich.edu 732356SN/A public: 742356SN/A /** 752356SN/A * This function pulls out the MAC source and destination addresses from 762367SN/A * the packet data and stores them in the caller specified buffers. 772356SN/A * 782356SN/A * @param src_addr The buffer to store the source MAC address. 792367SN/A * @param dst_addr The buffer to store the destination MAC address. 802356SN/A * @param length This is an inout parameter. The caller stores in this 812356SN/A * the size of the address buffers. On return, this will contain the 822356SN/A * actual address size stored in the buffers. (We assume that source 832367SN/A * address size is equal to that of the destination address.) 842367SN/A */ 852367SN/A void packAddress(uint8_t *src_addr, uint8_t *dst_addr, unsigned &length); 862367SN/A 872356SN/A void serialize(const std::string &base, CheckpointOut &cp) const; 882356SN/A void unserialize(const std::string &base, CheckpointIn &cp); 892356SN/A 902356SN/A unsigned size() const { return length; } 912356SN/A}; 922356SN/A 932356SN/Atypedef std::shared_ptr<EthPacketData> EthPacketPtr; 942356SN/A 952356SN/A#endif // __ETHERPKT_HH__ 962356SN/A