Fix serialization of the EtherLink object
dev/etherlink.cc: - The EtherLink::Link object is no lonver serializable, so it is now necessary to prepend the object's name (as determined by the parent) to all parameters. - Fix the serialization of the LinkDelayEvent so it actually works - Rename some variables to make serialization simpler dev/etherlink.hh: - Make the EtherLink::Link object *not* derive from serializeable. Instead, the serialize function will take a base name from the parent EtherLink object and prepend that base name to each of its variable names when serializing. This is similar to the PacketData and PacketFifo classes. - Make the EtherLink::Link object keep a pointer to its parent and its link number so the LinkDelayEvent can be properly serialized. - Rename some variables to make serialization simpler. --HG-- extra : convert_revision : e5aa54cd9e07b5e033989809100e1640abfb8bed
This commit is contained in:
parent
47dec0f411
commit
b9c847563d
|
@ -47,32 +47,32 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
EtherLink::EtherLink(const string &name, EtherInt *i1, EtherInt *i2,
|
EtherLink::EtherLink(const string &name, EtherInt *peer0, EtherInt *peer1,
|
||||||
Tick speed, Tick dly, EtherDump *dump)
|
Tick speed, Tick dly, EtherDump *dump)
|
||||||
: SimObject(name)
|
: SimObject(name)
|
||||||
{
|
{
|
||||||
double rate = ((double)ticksPerSecond * 8.0) / (double)speed;
|
double rate = ((double)ticksPerSecond * 8.0) / (double)speed;
|
||||||
Tick delay = US2Ticks(dly);
|
Tick delay = US2Ticks(dly);
|
||||||
|
|
||||||
link1 = new Link(name + ".link1", rate, delay, dump);
|
link[0] = new Link(name + ".link0", this, 0, rate, delay, dump);
|
||||||
link2 = new Link(name + ".link2", rate, delay, dump);
|
link[1] = new Link(name + ".link1", this, 1, rate, delay, dump);
|
||||||
|
|
||||||
int1 = new Interface(name + ".int1", link1, link2);
|
interface[0] = new Interface(name + ".int0", link[0], link[1]);
|
||||||
int2 = new Interface(name + ".int2", link2, link1);
|
interface[1] = new Interface(name + ".int1", link[1], link[0]);
|
||||||
|
|
||||||
int1->setPeer(i1);
|
interface[0]->setPeer(peer0);
|
||||||
i1->setPeer(int1);
|
peer0->setPeer(interface[0]);
|
||||||
int2->setPeer(i2);
|
interface[1]->setPeer(peer1);
|
||||||
i2->setPeer(int2);
|
peer1->setPeer(interface[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
EtherLink::~EtherLink()
|
EtherLink::~EtherLink()
|
||||||
{
|
{
|
||||||
delete link1;
|
delete link[0];
|
||||||
delete link2;
|
delete link[1];
|
||||||
|
|
||||||
delete int1;
|
delete interface[0];
|
||||||
delete int2;
|
delete interface[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
EtherLink::Interface::Interface(const string &name, Link *tx, Link *rx)
|
EtherLink::Interface::Interface(const string &name, Link *tx, Link *rx)
|
||||||
|
@ -82,26 +82,25 @@ EtherLink::Interface::Interface(const string &name, Link *tx, Link *rx)
|
||||||
rx->setRxInt(this);
|
rx->setRxInt(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
EtherLink::Link::Link(const string &name, double rate, Tick delay,
|
EtherLink::Link::Link(const string &name, EtherLink *p, int num,
|
||||||
EtherDump *d)
|
double rate, Tick delay, EtherDump *d)
|
||||||
: objName(name), txint(NULL), rxint(NULL), ticksPerByte(rate),
|
: objName(name), parent(p), number(num), txint(NULL), rxint(NULL),
|
||||||
linkDelay(delay), dump(d), doneEvent(this)
|
ticksPerByte(rate), linkDelay(delay), dump(d),
|
||||||
{}
|
doneEvent(this)
|
||||||
|
{ }
|
||||||
|
|
||||||
void
|
void
|
||||||
EtherLink::serialize(ostream &os)
|
EtherLink::serialize(ostream &os)
|
||||||
{
|
{
|
||||||
nameOut(os, name() + ".link1");
|
link[0]->serialize("link0", os);
|
||||||
link1->serialize(os);
|
link[1]->serialize("link1", os);
|
||||||
nameOut(os, name() + ".link2");
|
|
||||||
link2->serialize(os);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EtherLink::unserialize(Checkpoint *cp, const string §ion)
|
EtherLink::unserialize(Checkpoint *cp, const string §ion)
|
||||||
{
|
{
|
||||||
link1->unserialize(cp, section + ".link1");
|
link[0]->unserialize("link0", cp, section);
|
||||||
link2->unserialize(cp, section + ".link2");
|
link[1]->unserialize("link1", cp, section);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -118,10 +117,9 @@ class LinkDelayEvent : public Event
|
||||||
EtherLink::Link *link;
|
EtherLink::Link *link;
|
||||||
PacketPtr packet;
|
PacketPtr packet;
|
||||||
|
|
||||||
// non-scheduling version for createForUnserialize()
|
|
||||||
LinkDelayEvent(EtherLink::Link *link);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// non-scheduling version for createForUnserialize()
|
||||||
|
LinkDelayEvent();
|
||||||
LinkDelayEvent(EtherLink::Link *link, PacketPtr pkt, Tick when);
|
LinkDelayEvent(EtherLink::Link *link, PacketPtr pkt, Tick when);
|
||||||
|
|
||||||
void process();
|
void process();
|
||||||
|
@ -132,7 +130,6 @@ class LinkDelayEvent : public Event
|
||||||
const string §ion);
|
const string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EtherLink::Link::txDone()
|
EtherLink::Link::txDone()
|
||||||
{
|
{
|
||||||
|
@ -173,43 +170,44 @@ EtherLink::Link::transmit(PacketPtr pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EtherLink::Link::serialize(ostream &os)
|
EtherLink::Link::serialize(const string &base, ostream &os)
|
||||||
{
|
{
|
||||||
bool packet_exists = packet;
|
bool packet_exists = packet;
|
||||||
SERIALIZE_SCALAR(packet_exists);
|
paramOut(os, base + ".packet_exists", packet_exists);
|
||||||
|
if (packet_exists)
|
||||||
|
packet->serialize(base + ".packet", os);
|
||||||
|
|
||||||
bool event_scheduled = doneEvent.scheduled();
|
bool event_scheduled = doneEvent.scheduled();
|
||||||
SERIALIZE_SCALAR(event_scheduled);
|
paramOut(os, base + ".event_scheuled", event_scheduled);
|
||||||
if (event_scheduled) {
|
if (event_scheduled) {
|
||||||
Tick event_time = doneEvent.when();
|
Tick event_time = doneEvent.when();
|
||||||
SERIALIZE_SCALAR(event_time);
|
paramOut(os, base + ".event_time", event_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet_exists)
|
|
||||||
packet->serialize("packet", os);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EtherLink::Link::unserialize(Checkpoint *cp, const string §ion)
|
EtherLink::Link::unserialize(const string &base, Checkpoint *cp,
|
||||||
|
const string §ion)
|
||||||
{
|
{
|
||||||
bool packet_exists;
|
bool packet_exists;
|
||||||
UNSERIALIZE_SCALAR(packet_exists);
|
paramIn(cp, section, base + ".packet_exists", packet_exists);
|
||||||
if (packet_exists) {
|
if (packet_exists) {
|
||||||
packet = new PacketData(16384);
|
packet = new PacketData(16384);
|
||||||
packet->unserialize("packet", cp, section);
|
packet->unserialize(base + ".packet", cp, section);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool event_scheduled;
|
bool event_scheduled;
|
||||||
UNSERIALIZE_SCALAR(event_scheduled);
|
paramIn(cp, section, base + ".event_scheduled", event_scheduled);
|
||||||
if (event_scheduled) {
|
if (event_scheduled) {
|
||||||
Tick event_time;
|
Tick event_time;
|
||||||
UNSERIALIZE_SCALAR(event_time);
|
paramIn(cp, section, base + ".event_time", event_time);
|
||||||
doneEvent.schedule(event_time);
|
doneEvent.schedule(event_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkDelayEvent::LinkDelayEvent(EtherLink::Link *l)
|
LinkDelayEvent::LinkDelayEvent()
|
||||||
: Event(&mainEventQueue), link(l)
|
: Event(&mainEventQueue), link(NULL)
|
||||||
{
|
{
|
||||||
setFlags(AutoSerialize);
|
setFlags(AutoSerialize);
|
||||||
setFlags(AutoDelete);
|
setFlags(AutoDelete);
|
||||||
|
@ -234,7 +232,11 @@ LinkDelayEvent::serialize(ostream &os)
|
||||||
{
|
{
|
||||||
paramOut(os, "type", string("LinkDelayEvent"));
|
paramOut(os, "type", string("LinkDelayEvent"));
|
||||||
Event::serialize(os);
|
Event::serialize(os);
|
||||||
SERIALIZE_OBJPTR(link);
|
|
||||||
|
EtherLink *parent = link->parent;
|
||||||
|
bool number = link->number;
|
||||||
|
SERIALIZE_OBJPTR(parent);
|
||||||
|
SERIALIZE_SCALAR(number);
|
||||||
|
|
||||||
packet->serialize("packet", os);
|
packet->serialize("packet", os);
|
||||||
}
|
}
|
||||||
|
@ -244,6 +246,14 @@ void
|
||||||
LinkDelayEvent::unserialize(Checkpoint *cp, const string §ion)
|
LinkDelayEvent::unserialize(Checkpoint *cp, const string §ion)
|
||||||
{
|
{
|
||||||
Event::unserialize(cp, section);
|
Event::unserialize(cp, section);
|
||||||
|
|
||||||
|
EtherLink *parent;
|
||||||
|
bool number;
|
||||||
|
UNSERIALIZE_OBJPTR(parent);
|
||||||
|
UNSERIALIZE_SCALAR(number);
|
||||||
|
|
||||||
|
link = parent->link[number];
|
||||||
|
|
||||||
packet = new PacketData(16384);
|
packet = new PacketData(16384);
|
||||||
packet->unserialize("packet", cp, section);
|
packet->unserialize("packet", cp, section);
|
||||||
}
|
}
|
||||||
|
@ -252,9 +262,7 @@ LinkDelayEvent::unserialize(Checkpoint *cp, const string §ion)
|
||||||
Serializable *
|
Serializable *
|
||||||
LinkDelayEvent::createForUnserialize(Checkpoint *cp, const string §ion)
|
LinkDelayEvent::createForUnserialize(Checkpoint *cp, const string §ion)
|
||||||
{
|
{
|
||||||
EtherLink::Link *link;
|
return new LinkDelayEvent();
|
||||||
UNSERIALIZE_OBJPTR(link);
|
|
||||||
return new LinkDelayEvent(link);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_SERIALIZEABLE("LinkDelayEvent", LinkDelayEvent)
|
REGISTER_SERIALIZEABLE("LinkDelayEvent", LinkDelayEvent)
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
#include "sim/sim_object.hh"
|
#include "sim/sim_object.hh"
|
||||||
|
|
||||||
class EtherDump;
|
class EtherDump;
|
||||||
|
class Checkpoint;
|
||||||
/*
|
/*
|
||||||
* Model for a fixed bandwidth full duplex ethernet link
|
* Model for a fixed bandwidth full duplex ethernet link
|
||||||
*/
|
*/
|
||||||
|
@ -53,10 +53,14 @@ class EtherLink : public SimObject
|
||||||
/*
|
/*
|
||||||
* Model for a single uni-directional link
|
* Model for a single uni-directional link
|
||||||
*/
|
*/
|
||||||
class Link : public Serializable {
|
class Link
|
||||||
|
{
|
||||||
protected:
|
protected:
|
||||||
std::string objName;
|
std::string objName;
|
||||||
|
|
||||||
|
EtherLink *parent;
|
||||||
|
int number;
|
||||||
|
|
||||||
Interface *txint;
|
Interface *txint;
|
||||||
Interface *rxint;
|
Interface *rxint;
|
||||||
|
|
||||||
|
@ -78,11 +82,11 @@ class EtherLink : public SimObject
|
||||||
void txComplete(PacketPtr packet);
|
void txComplete(PacketPtr packet);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Link(const std::string &name, double rate, Tick delay,
|
Link(const std::string &name, EtherLink *p, int num,
|
||||||
EtherDump *dump);
|
double rate, Tick delay, EtherDump *dump);
|
||||||
~Link() {}
|
~Link() {}
|
||||||
|
|
||||||
virtual const std::string name() const { return objName; }
|
const std::string name() const { return objName; }
|
||||||
|
|
||||||
bool busy() const { return (bool)packet; }
|
bool busy() const { return (bool)packet; }
|
||||||
bool transmit(PacketPtr packet);
|
bool transmit(PacketPtr packet);
|
||||||
|
@ -90,8 +94,9 @@ class EtherLink : public SimObject
|
||||||
void setTxInt(Interface *i) { assert(!txint); txint = i; }
|
void setTxInt(Interface *i) { assert(!txint); txint = i; }
|
||||||
void setRxInt(Interface *i) { assert(!rxint); rxint = i; }
|
void setRxInt(Interface *i) { assert(!rxint); rxint = i; }
|
||||||
|
|
||||||
virtual void serialize(std::ostream &os);
|
void serialize(const std::string &base, std::ostream &os);
|
||||||
virtual void unserialize(Checkpoint *cp, const std::string §ion);
|
void unserialize(const std::string &base, Checkpoint *cp,
|
||||||
|
const std::string §ion);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -108,14 +113,11 @@ class EtherLink : public SimObject
|
||||||
void sendDone() { peer->sendDone(); }
|
void sendDone() { peer->sendDone(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
Link *link1;
|
Link *link[2];
|
||||||
Link *link2;
|
EtherInt *interface[2];
|
||||||
|
|
||||||
EtherInt *int1;
|
|
||||||
EtherInt *int2;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EtherLink(const std::string &name, EtherInt *i1, EtherInt *i2,
|
EtherLink(const std::string &name, EtherInt *peer0, EtherInt *peer1,
|
||||||
Tick speed, Tick delay, EtherDump *dump);
|
Tick speed, Tick delay, EtherDump *dump);
|
||||||
virtual ~EtherLink();
|
virtual ~EtherLink();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue