etherpkt.cc revision 11719:e832056deaed
16899SN/A/*
26899SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
36899SN/A * All rights reserved.
46899SN/A *
56899SN/A * Redistribution and use in source and binary forms, with or without
66899SN/A * modification, are permitted provided that the following conditions are
76899SN/A * met: redistributions of source code must retain the above copyright
86899SN/A * notice, this list of conditions and the following disclaimer;
96899SN/A * redistributions in binary form must reproduce the above copyright
106899SN/A * notice, this list of conditions and the following disclaimer in the
116899SN/A * documentation and/or other materials provided with the distribution;
126899SN/A * neither the name of the copyright holders nor the names of its
136899SN/A * contributors may be used to endorse or promote products derived from
146899SN/A * this software without specific prior written permission.
156899SN/A *
166899SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176899SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186899SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196899SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206899SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216899SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226899SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236899SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246899SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256899SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266899SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276899SN/A *
286899SN/A * Authors: Nathan Binkert
296899SN/A */
307053SN/A
317053SN/A#include "dev/net/etherpkt.hh"
326899SN/A
337055SN/A#include <iostream>
347055SN/A
357632SBrad.Beckmann@amd.com#include "base/inet.hh"
368164Snilay@cs.wisc.edu#include "base/misc.hh"
377053SN/A#include "sim/serialize.hh"
387053SN/A
396899SN/Ausing namespace std;
407053SN/A
416899SN/Avoid
426899SN/AEthPacketData::serialize(const string &base, CheckpointOut &cp) const
436899SN/A{
447053SN/A    paramOut(cp, base + ".simLength", simLength);
456899SN/A    paramOut(cp, base + ".bufLength", bufLength);
467053SN/A    paramOut(cp, base + ".length", length);
477053SN/A    arrayParamOut(cp, base + ".data", data, length);
487053SN/A}
498932SBrad.Beckmann@amd.com
508932SBrad.Beckmann@amd.comvoid
516899SN/AEthPacketData::unserialize(const string &base, CheckpointIn &cp)
527053SN/A{
537053SN/A    paramIn(cp, base + ".length", length);
547053SN/A    unsigned chkpt_buf_length;
557053SN/A    if (optParamIn(cp, base + ".bufLength", chkpt_buf_length)) {
566899SN/A        // If bufLength is in the checkpoint, make sure that the current buffer
577055SN/A        // is unallocated or that the checkpoint requested size is smaller than
586899SN/A        // the current buffer.
597053SN/A        assert(!data || chkpt_buf_length <= bufLength);
608184Ssomayeh@cs.wisc.edu        bufLength = chkpt_buf_length;
617053SN/A    } else {
627053SN/A        // If bufLength is not in the checkpoint, try to use the existing
637053SN/A        // buffer or use length to size the buffer
646899SN/A        if (!data)
657053SN/A            bufLength = length;
667053SN/A    }
676899SN/A    assert(length <= bufLength);
687053SN/A    if (!data)
696899SN/A        data = new uint8_t[bufLength];
707053SN/A    arrayParamIn(cp, base + ".data", data, length);
719208Snilay@cs.wisc.edu    if (!optParamIn(cp, base + ".simLength", simLength))
727053SN/A        simLength = length;
737053SN/A}
747053SN/A
757053SN/A