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)
: SimObject(name)
{
double rate = ((double)ticksPerSecond * 8.0) / (double)speed;
Tick delay = US2Ticks(dly);
- link1 = new Link(name + ".link1", rate, delay, dump);
- link2 = new Link(name + ".link2", rate, delay, dump);
+ link[0] = new Link(name + ".link0", this, 0, rate, delay, dump);
+ link[1] = new Link(name + ".link1", this, 1, rate, delay, dump);
- int1 = new Interface(name + ".int1", link1, link2);
- int2 = new Interface(name + ".int2", link2, link1);
+ interface[0] = new Interface(name + ".int0", link[0], link[1]);
+ interface[1] = new Interface(name + ".int1", link[1], link[0]);
- int1->setPeer(i1);
- i1->setPeer(int1);
- int2->setPeer(i2);
- i2->setPeer(int2);
+ interface[0]->setPeer(peer0);
+ peer0->setPeer(interface[0]);
+ interface[1]->setPeer(peer1);
+ peer1->setPeer(interface[1]);
}
EtherLink::~EtherLink()
{
- delete link1;
- delete link2;
+ delete link[0];
+ delete link[1];
- delete int1;
- delete int2;
+ delete interface[0];
+ delete interface[1];
}
EtherLink::Interface::Interface(const string &name, Link *tx, Link *rx)
rx->setRxInt(this);
}
-EtherLink::Link::Link(const string &name, double rate, Tick delay,
- EtherDump *d)
- : objName(name), txint(NULL), rxint(NULL), ticksPerByte(rate),
- linkDelay(delay), dump(d), doneEvent(this)
-{}
+EtherLink::Link::Link(const string &name, EtherLink *p, int num,
+ double rate, Tick delay, EtherDump *d)
+ : objName(name), parent(p), number(num), txint(NULL), rxint(NULL),
+ ticksPerByte(rate), linkDelay(delay), dump(d),
+ doneEvent(this)
+{ }
void
EtherLink::serialize(ostream &os)
{
- nameOut(os, name() + ".link1");
- link1->serialize(os);
- nameOut(os, name() + ".link2");
- link2->serialize(os);
+ link[0]->serialize("link0", os);
+ link[1]->serialize("link1", os);
}
void
EtherLink::unserialize(Checkpoint *cp, const string §ion)
{
- link1->unserialize(cp, section + ".link1");
- link2->unserialize(cp, section + ".link2");
+ link[0]->unserialize("link0", cp, section);
+ link[1]->unserialize("link1", cp, section);
}
void
EtherLink::Link *link;
PacketPtr packet;
- // non-scheduling version for createForUnserialize()
- LinkDelayEvent(EtherLink::Link *link);
-
public:
+ // non-scheduling version for createForUnserialize()
+ LinkDelayEvent();
LinkDelayEvent(EtherLink::Link *link, PacketPtr pkt, Tick when);
void process();
const string §ion);
};
-
void
EtherLink::Link::txDone()
{
}
void
-EtherLink::Link::serialize(ostream &os)
+EtherLink::Link::serialize(const string &base, ostream &os)
{
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();
- SERIALIZE_SCALAR(event_scheduled);
+ paramOut(os, base + ".event_scheuled", event_scheduled);
if (event_scheduled) {
Tick event_time = doneEvent.when();
- SERIALIZE_SCALAR(event_time);
+ paramOut(os, base + ".event_time", event_time);
}
- if (packet_exists)
- packet->serialize("packet", os);
}
void
-EtherLink::Link::unserialize(Checkpoint *cp, const string §ion)
+EtherLink::Link::unserialize(const string &base, Checkpoint *cp,
+ const string §ion)
{
bool packet_exists;
- UNSERIALIZE_SCALAR(packet_exists);
+ paramIn(cp, section, base + ".packet_exists", packet_exists);
if (packet_exists) {
packet = new PacketData(16384);
- packet->unserialize("packet", cp, section);
+ packet->unserialize(base + ".packet", cp, section);
}
bool event_scheduled;
- UNSERIALIZE_SCALAR(event_scheduled);
+ paramIn(cp, section, base + ".event_scheduled", event_scheduled);
if (event_scheduled) {
Tick event_time;
- UNSERIALIZE_SCALAR(event_time);
+ paramIn(cp, section, base + ".event_time", event_time);
doneEvent.schedule(event_time);
}
}
-LinkDelayEvent::LinkDelayEvent(EtherLink::Link *l)
- : Event(&mainEventQueue), link(l)
+LinkDelayEvent::LinkDelayEvent()
+ : Event(&mainEventQueue), link(NULL)
{
setFlags(AutoSerialize);
setFlags(AutoDelete);
{
paramOut(os, "type", string("LinkDelayEvent"));
Event::serialize(os);
- SERIALIZE_OBJPTR(link);
+
+ EtherLink *parent = link->parent;
+ bool number = link->number;
+ SERIALIZE_OBJPTR(parent);
+ SERIALIZE_SCALAR(number);
packet->serialize("packet", os);
}
LinkDelayEvent::unserialize(Checkpoint *cp, const string §ion)
{
Event::unserialize(cp, section);
+
+ EtherLink *parent;
+ bool number;
+ UNSERIALIZE_OBJPTR(parent);
+ UNSERIALIZE_SCALAR(number);
+
+ link = parent->link[number];
+
packet = new PacketData(16384);
packet->unserialize("packet", cp, section);
}
Serializable *
LinkDelayEvent::createForUnserialize(Checkpoint *cp, const string §ion)
{
- EtherLink::Link *link;
- UNSERIALIZE_OBJPTR(link);
- return new LinkDelayEvent(link);
+ return new LinkDelayEvent();
}
REGISTER_SERIALIZEABLE("LinkDelayEvent", LinkDelayEvent)
#include "sim/sim_object.hh"
class EtherDump;
-
+class Checkpoint;
/*
* Model for a fixed bandwidth full duplex ethernet link
*/
/*
* Model for a single uni-directional link
*/
- class Link : public Serializable {
+ class Link
+ {
protected:
std::string objName;
+ EtherLink *parent;
+ int number;
+
Interface *txint;
Interface *rxint;
void txComplete(PacketPtr packet);
public:
- Link(const std::string &name, double rate, Tick delay,
- EtherDump *dump);
+ Link(const std::string &name, EtherLink *p, int num,
+ double rate, Tick delay, EtherDump *dump);
~Link() {}
- virtual const std::string name() const { return objName; }
+ const std::string name() const { return objName; }
bool busy() const { return (bool)packet; }
bool transmit(PacketPtr packet);
void setTxInt(Interface *i) { assert(!txint); txint = i; }
void setRxInt(Interface *i) { assert(!rxint); rxint = i; }
- virtual void serialize(std::ostream &os);
- virtual void unserialize(Checkpoint *cp, const std::string §ion);
+ void serialize(const std::string &base, std::ostream &os);
+ void unserialize(const std::string &base, Checkpoint *cp,
+ const std::string §ion);
};
/*
void sendDone() { peer->sendDone(); }
};
- Link *link1;
- Link *link2;
-
- EtherInt *int1;
- EtherInt *int2;
+ Link *link[2];
+ EtherInt *interface[2];
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);
virtual ~EtherLink();