54 #include "debug/Ethernet.hh" 55 #include "debug/EthernetData.hh" 59 #include "params/EtherLink.hh" 70 p->delay, p->delay_var, p->dump);
72 p->delay, p->delay_var, p->dump);
91 if (if_name ==
"int0")
93 else if (if_name ==
"int1")
108 : objName(name), parent(p), number(num), txint(NULL), rxint(NULL),
109 ticksPerByte(rate), linkDelay(delay), delayVar(delay_var),
dump(d),
131 DPRINTF(Ethernet,
"packet received: len=%d\n", packet->length);
132 DDUMP(EthernetData, packet->data, packet->length);
167 assert(next.first >
curTick());
171 assert(cur.first ==
curTick());
179 DPRINTF(Ethernet,
"packet not sent, link busy\n");
183 DPRINTF(Ethernet,
"packet sent: len=%d\n", pkt->length);
184 DDUMP(EthernetData, pkt->data, pkt->length);
191 DPRINTF(Ethernet,
"scheduling packet: delay=%d, (rate=%f)\n",
192 delay, ticksPerByte);
201 bool packet_exists =
packet !=
nullptr;
202 paramOut(cp, base +
".packet_exists", packet_exists);
204 packet->serialize(base +
".packet", cp);
207 paramOut(cp, base +
".event_scheduled", event_scheduled);
208 if (event_scheduled) {
210 paramOut(cp, base +
".event_time", event_time);
213 const size_t tx_queue_size(
txQueue.size());
214 paramOut(cp, base +
".tx_queue_size", tx_queue_size);
218 pe.second->serialize(
csprintf(
"%s.txQueue[%i].packet", base, idx), cp);
228 paramIn(cp, base +
".packet_exists", packet_exists);
230 packet = make_shared<EthPacketData>();
231 packet->unserialize(base +
".packet", cp);
234 bool event_scheduled;
235 paramIn(cp, base +
".event_scheduled", event_scheduled);
236 if (event_scheduled) {
238 paramIn(cp, base +
".event_time", event_time);
242 size_t tx_queue_size = 0;
243 if (
optParamIn(cp, base +
".tx_queue_size", tx_queue_size)) {
244 for (
size_t idx = 0; idx < tx_queue_size; ++idx) {
246 EthPacketPtr delayed_packet = make_shared<EthPacketData>();
249 delayed_packet->unserialize(
250 csprintf(
"%s.txQueue[%i].packet", base, idx), cp);
253 "Invalid txQueue packet order in EtherLink!\n");
254 txQueue.emplace_back(std::make_pair(tick, delayed_packet));
263 warn(
"Old-style EtherLink serialization format detected, " 264 "in-flight packets may have been dropped.\n");
269 EtherLinkParams::create()
EventFunctionWrapper txQueueEvent
std::deque< std::pair< Tick, EthPacketPtr > > txQueue
Maintain a queue of in-flight packets.
void txComplete(EthPacketPtr packet)
const std::string & name() const
Return port name (for DPRINTF).
Ports are used to interface objects to each other.
Interface(const std::string &name, Link *txlink, Link *rxlink)
void unserialize(const std::string &base, CheckpointIn &cp)
#define DDUMP(x, data, count)
Overload hash function for BasicBlockRange type.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
EventFunctionWrapper doneEvent
Link(const std::string &name, EtherLink *p, int num, double rate, Tick delay, Tick delay_var, EtherDump *dump)
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Tick curTick()
The current simulated tick.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
std::string csprintf(const char *format, const Args &...args)
bool optParamIn(CheckpointIn &cp, const std::string &name, T ¶m, bool warn=true)
uint64_t Tick
Tick count type.
void dump(EthPacketPtr &pkt)
EtherLink(const Params *p)
void paramOut(CheckpointOut &cp, const string &name, ExtMachInst const &machInst)
const std::string name() const
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
std::shared_ptr< EthPacketData > EthPacketPtr
void schedule(Event &event, Tick when)
void serialize(CheckpointOut &cp) const override
Serialize an object.
bool scheduled() const
Determine if the current event is scheduled.
bool sendPacket(EthPacketPtr packet)
virtual const std::string name() const
std::ostream CheckpointOut
const double ticksPerByte
void setRxInt(Interface *i)
void paramIn(CheckpointIn &cp, const string &name, ExtMachInst &machInst)
bool transmit(EthPacketPtr packet)
void setTxInt(Interface *i)
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
void dump()
Dump all statistics data to the registered outputs.
Tick when() const
Get the time that the event is scheduled.
Abstract superclass for simulation objects.
void serialize(const std::string &base, CheckpointOut &cp) const
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.