57 #include "debug/Ethernet.hh" 58 #include "debug/EthernetData.hh" 62 #include "params/EtherLink.hh" 73 p->delay, p->delay_var, p->dump);
75 p->delay, p->delay_var, p->dump);
94 if (if_name ==
"int0")
96 else if (if_name ==
"int1")
111 : objName(name), parent(p), number(num), txint(NULL), rxint(NULL),
112 ticksPerByte(rate), linkDelay(delay), delayVar(delay_var),
dump(d),
134 DPRINTF(Ethernet,
"packet received: len=%d\n", packet->length);
135 DDUMP(EthernetData, packet->data, packet->length);
170 assert(next.first >
curTick());
174 assert(cur.first ==
curTick());
182 DPRINTF(Ethernet,
"packet not sent, link busy\n");
186 DPRINTF(Ethernet,
"packet sent: len=%d\n", pkt->length);
187 DDUMP(EthernetData, pkt->data, pkt->length);
194 DPRINTF(Ethernet,
"scheduling packet: delay=%d, (rate=%f)\n",
195 delay, ticksPerByte);
204 bool packet_exists =
packet !=
nullptr;
205 paramOut(cp, base +
".packet_exists", packet_exists);
207 packet->serialize(base +
".packet", cp);
210 paramOut(cp, base +
".event_scheduled", event_scheduled);
211 if (event_scheduled) {
213 paramOut(cp, base +
".event_time", event_time);
216 const size_t tx_queue_size(
txQueue.size());
217 paramOut(cp, base +
".tx_queue_size", tx_queue_size);
221 pe.second->serialize(
csprintf(
"%s.txQueue[%i].packet", base, idx), cp);
231 paramIn(cp, base +
".packet_exists", packet_exists);
233 packet = make_shared<EthPacketData>();
234 packet->unserialize(base +
".packet", cp);
237 bool event_scheduled;
238 paramIn(cp, base +
".event_scheduled", event_scheduled);
239 if (event_scheduled) {
241 paramIn(cp, base +
".event_time", event_time);
245 size_t tx_queue_size = 0;
246 if (
optParamIn(cp, base +
".tx_queue_size", tx_queue_size)) {
247 for (
size_t idx = 0; idx < tx_queue_size; ++idx) {
249 EthPacketPtr delayed_packet = make_shared<EthPacketData>();
252 delayed_packet->unserialize(
253 csprintf(
"%s.txQueue[%i].packet", base, idx), cp);
256 "Invalid txQueue packet order in EtherLink!\n");
257 txQueue.emplace_back(std::make_pair(tick, delayed_packet));
266 warn(
"Old-style EtherLink serialization format detected, " 267 "in-flight packets may have been dropped.\n");
272 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)
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
void unserialize(const std::string &base, CheckpointIn &cp)
Tick when() const
Get the time that the event is scheduled.
#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.
std::string csprintf(const char *format, const Args &...args)
bool scheduled() const
Determine if the current event is scheduled.
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 serialize(CheckpointOut &cp) const override
Serialize an object.
virtual const std::string name() const
bool sendPacket(EthPacketPtr packet)
std::ostream CheckpointOut
const double ticksPerByte
void setRxInt(Interface *i)
void schedule(Event &event, Tick when)
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.
bool optParamIn(CheckpointIn &cp, const std::string &name, T ¶m, bool warn=true)
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.