40 #include "debug/EthernetAll.hh" 48 for (
int i = 0;
i < p->port_interface_connection_count; ++
i) {
49 std::string interfaceName =
csprintf(
"%s.interface%d",
name(),
i);
50 Interface *
interface = new Interface(interfaceName, this,
51 p->output_buffer_size, p->delay,
52 p->delay_var, p->fabric_speed, i);
68 if (if_name ==
"interface") {
82 fifo.emplace_hint(fifo.end(), ptr,
curTick(), senderId);
86 DPRINTF(Ethernet,
"Fifo is full. Drop packet: len=%d\n",
87 std::prev(fifo.end())->packet->length);
89 _size -= std::prev(fifo.end())->packet->length;
90 fifo.erase(std::prev(fifo.end()));
94 warn(
"EtherSwitch: Packet length (%d) exceeds the maximum storage " 95 "capacity of port fifo (%d)", ptr->length, _maxsize);
102 if (!empty() && fifo.begin()->packet == ptr) {
114 assert(_size >= fifo.begin()->packet->length);
116 _size -= fifo.begin()->packet->length;
117 fifo.erase(fifo.begin());
129 uint64_t outputBufferSize,
Tick delay,
130 Tick delay_var,
double rate,
unsigned id)
131 :
EtherInt(name), ticksPerByte(rate), switchDelay(delay),
132 delayVar(delay_var), interfaceId(id), parent(etherSwitch),
133 outputFifo(name +
".outputFifo", outputBufferSize),
152 DPRINTF(Ethernet,
"sending packet from MAC %x on port " 153 "%s to MAC %x on port %s\n", uint64_t(srcMacAddr),
154 this->
name(), uint64_t(destMacAddr), receiver->
name());
188 DPRINTF(Ethernet,
"output port busy...retry later\n");
219 DPRINTF(Ethernet,
"no entry in forwaring table for MAC: " 220 "%x\n", uint64_t(destMacAddr));
232 DPRINTF(Ethernet,
"found entry for MAC address %x on port %s\n",
233 uint64_t(destMacAddr), it->second.interface->name());
234 return it->second.interface;
247 DPRINTF(Ethernet,
"adding forwarding table entry for MAC " 248 " address %x on port %s\n", uint64_t(srcMacAddr),
252 forwardingTableEntry.lastUseTime =
curTick();
254 forwardingTableEntry));
256 it->second.lastUseTime =
curTick();
264 it->serializeSection(cp, it->name());
272 it->unserializeSection(cp, it->name());
282 if (event_scheduled) {
292 bool event_scheduled;
295 if (event_scheduled) {
306 packet->serialize(
"packet", cp);
314 packet = make_shared<EthPacketData>(16384);
315 packet->unserialize(
"packet", cp);
324 int fifosize = fifo.size();
329 for (
const auto &entry : fifo)
330 entry.serializeSection(cp,
csprintf(
"entry%d", i++));
342 for (
int i = 0;
i < fifosize; ++
i) {
353 EtherSwitchParams::create()
void serialize(CheckpointOut &cp) const override
Serialize an object.
const std::string & name() const
Return port name (for DPRINTF).
Ports are used to interface objects to each other.
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
bool recvPacket(EthPacketPtr packet)
When a packet is received from a device, route it through an (several) output queue(s) ...
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
Tick when() const
Get the time that the event is scheduled.
Interface(const std::string &name, EtherSwitch *_etherSwitch, uint64_t outputBufferSize, Tick delay, Tick delay_var, double rate, unsigned id)
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
Model for an Ethernet switch port.
Overload hash function for BasicBlockRange type.
std::vector< Interface * > interfaces
std::map< uint64_t, SwitchTableEntry > forwardingTable
EventFunctionWrapper txEvent
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...
PortFifo outputFifo
output fifo at each interface
#define UNSERIALIZE_SCALAR(scalar)
void learnSenderAddr(Net::EthAddr srcMacAddr, Interface *sender)
Tick curTick()
The current simulated tick.
Interface * lookupDestPort(Net::EthAddr destAddr)
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 unserialize(CheckpointIn &cp)
Unserialize an object.
void serialize(CheckpointOut &cp) const
Serialize an object.
std::shared_ptr< EthPacketData > EthPacketPtr
void unserialize(CheckpointIn &cp) override
Unserialize an object.
virtual const std::string name() const
bool push(EthPacketPtr ptr, unsigned senderId)
Push a packet into the fifo and sort the packets with same recv tick by port id.
const unsigned interfaceId
EtherSwitch(const Params *p)
const double ticksPerByte
#define SERIALIZE_SCALAR(scalar)
bool sendPacket(EthPacketPtr packet)
void reschedule(Event &event, Tick when, bool always=false)
std::ostream CheckpointOut
void unserialize(CheckpointIn &cp)
Unserialize an object.
void enqueue(EthPacketPtr packet, unsigned senderId)
enqueue packet to the outputFifo
void schedule(Event &event, Tick when)
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
void serialize(CheckpointOut &cp) const
Serialization stuff.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
void serialize(CheckpointOut &cp) const
Serialize an object.
Abstract superclass for simulation objects.
void unserialize(CheckpointIn &cp)
Unserialize an object.