/*
- * Copyright (c) 2002-2004 The Regents of The University of Michigan
+ * Copyright (c) 2002-2005 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <string>
#include <vector>
+#include "base/random.hh"
#include "base/trace.hh"
#include "dev/etherdump.hh"
#include "dev/etherint.hh"
#include "sim/builder.hh"
#include "sim/serialize.hh"
#include "sim/system.hh"
-#include "sim/universe.hh"
+#include "sim/root.hh"
using namespace std;
EtherLink::EtherLink(const string &name, EtherInt *peer0, EtherInt *peer1,
- Tick speed, Tick dly, EtherDump *dump)
+ double rate, Tick delay, Tick delayVar, EtherDump *dump)
: SimObject(name)
{
- double rate = ((double)ticksPerSecond * 8.0) / (double)speed;
- Tick delay = US2Ticks(dly);
-
- link[0] = new Link(name + ".link0", this, 0, rate, delay, dump);
- link[1] = new Link(name + ".link1", this, 1, rate, delay, dump);
+ link[0] = new Link(name + ".link0", this, 0, rate, delay, delayVar, dump);
+ link[1] = new Link(name + ".link1", this, 1, rate, delay, delayVar, dump);
interface[0] = new Interface(name + ".int0", link[0], link[1]);
interface[1] = new Interface(name + ".int1", link[1], link[0]);
}
EtherLink::Link::Link(const string &name, EtherLink *p, int num,
- double rate, Tick delay, EtherDump *d)
+ double rate, Tick delay, Tick delay_var, EtherDump *d)
: objName(name), parent(p), number(num), txint(NULL), rxint(NULL),
- ticksPerByte(rate), linkDelay(delay), dump(d),
+ ticksPerByte(rate), linkDelay(delay), delayVar(delay_var), dump(d),
doneEvent(this)
{ }
packet = pkt;
Tick delay = (Tick)ceil(((double)pkt->length * ticksPerByte) + 1.0);
+ if (delayVar != 0) {
+ Random<Tick> var;
+ delay += var.uniform(0, delayVar);
+ }
DPRINTF(Ethernet, "scheduling packet: delay=%d, (rate=%f)\n",
delay, ticksPerByte);
doneEvent.schedule(curTick + delay);
SimObjectParam<EtherInt *> int1;
SimObjectParam<EtherInt *> int2;
- Param<Tick> speed;
+ Param<double> speed;
Param<Tick> delay;
+ Param<Tick> delay_var;
SimObjectParam<EtherDump *> dump;
END_DECLARE_SIM_OBJECT_PARAMS(EtherLink)
INIT_PARAM(int1, "interface 1"),
INIT_PARAM(int2, "interface 2"),
- INIT_PARAM_DFLT(speed, "link speed in bits per second", 100000000),
- INIT_PARAM_DFLT(delay, "transmit delay of packets in us", 0),
- INIT_PARAM_DFLT(dump, "object to dump network packets to", NULL)
+ INIT_PARAM(speed, "link speed in bits per second"),
+ INIT_PARAM(delay, "transmit delay of packets in us"),
+ INIT_PARAM(delay_var, "Difference in amount of time to traverse wire"),
+ INIT_PARAM(dump, "object to dump network packets to")
END_INIT_SIM_OBJECT_PARAMS(EtherLink)
CREATE_SIM_OBJECT(EtherLink)
{
- return new EtherLink(getInstanceName(), int1, int2, speed, delay, dump);
+ return new EtherLink(getInstanceName(), int1, int2, speed, delay, delay_var,
+ dump);
}
REGISTER_SIM_OBJECT("EtherLink", EtherLink)