1572SN/A/*
21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
3572SN/A * All rights reserved.
4572SN/A *
5572SN/A * Redistribution and use in source and binary forms, with or without
6572SN/A * modification, are permitted provided that the following conditions are
7572SN/A * met: redistributions of source code must retain the above copyright
8572SN/A * notice, this list of conditions and the following disclaimer;
9572SN/A * redistributions in binary form must reproduce the above copyright
10572SN/A * notice, this list of conditions and the following disclaimer in the
11572SN/A * documentation and/or other materials provided with the distribution;
12572SN/A * neither the name of the copyright holders nor the names of its
13572SN/A * contributors may be used to endorse or promote products derived from
14572SN/A * this software without specific prior written permission.
15572SN/A *
16572SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17572SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18572SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19572SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20572SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21572SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22572SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23572SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24572SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25572SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26572SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665SN/A *
282665SN/A * Authors: Nathan Binkert
29572SN/A */
30572SN/A
3111263Sandreas.sandberg@arm.com#include "dev/net/etherpkt.hh"
3211263Sandreas.sandberg@arm.com
33572SN/A#include <iostream>
34572SN/A
3511263Sandreas.sandberg@arm.com#include "base/inet.hh"
3612334Sgabeblack@google.com#include "base/logging.hh"
37572SN/A#include "sim/serialize.hh"
38572SN/A
39572SN/Ausing namespace std;
40572SN/A
41572SN/Avoid
4210905SN/AEthPacketData::serialize(const string &base, CheckpointOut &cp) const
43572SN/A{
4411701Smichael.lebeane@amd.com    paramOut(cp, base + ".simLength", simLength);
4511719Smichael.lebeane@amd.com    paramOut(cp, base + ".bufLength", bufLength);
4610905SN/A    paramOut(cp, base + ".length", length);
4710905SN/A    arrayParamOut(cp, base + ".data", data, length);
48572SN/A}
49572SN/A
50572SN/Avoid
5110905SN/AEthPacketData::unserialize(const string &base, CheckpointIn &cp)
52572SN/A{
5310905SN/A    paramIn(cp, base + ".length", length);
5411719Smichael.lebeane@amd.com    unsigned chkpt_buf_length;
5511719Smichael.lebeane@amd.com    if (optParamIn(cp, base + ".bufLength", chkpt_buf_length)) {
5611719Smichael.lebeane@amd.com        // If bufLength is in the checkpoint, make sure that the current buffer
5711719Smichael.lebeane@amd.com        // is unallocated or that the checkpoint requested size is smaller than
5811719Smichael.lebeane@amd.com        // the current buffer.
5911719Smichael.lebeane@amd.com        assert(!data || chkpt_buf_length <= bufLength);
6011719Smichael.lebeane@amd.com        bufLength = chkpt_buf_length;
6111719Smichael.lebeane@amd.com    } else {
6211719Smichael.lebeane@amd.com        // If bufLength is not in the checkpoint, try to use the existing
6311719Smichael.lebeane@amd.com        // buffer or use length to size the buffer
6411719Smichael.lebeane@amd.com        if (!data)
6511719Smichael.lebeane@amd.com            bufLength = length;
6611701Smichael.lebeane@amd.com    }
6711719Smichael.lebeane@amd.com    assert(length <= bufLength);
6811719Smichael.lebeane@amd.com    if (!data)
6911719Smichael.lebeane@amd.com        data = new uint8_t[bufLength];
7011719Smichael.lebeane@amd.com    arrayParamIn(cp, base + ".data", data, length);
7111701Smichael.lebeane@amd.com    if (!optParamIn(cp, base + ".simLength", simLength))
7211701Smichael.lebeane@amd.com        simLength = length;
73572SN/A}
7410923SN/A
75