Go to the documentation of this file.
37 #include "debug/EthernetAll.hh"
45 for (
int i = 0;
i <
p->port_interface_connection_count; ++
i) {
46 std::string interfaceName =
csprintf(
"%s.interface%d",
name(),
i);
48 p->output_buffer_size,
p->delay,
49 p->delay_var,
p->fabric_speed,
i);
65 if (if_name ==
"interface") {
83 DPRINTF(Ethernet,
"Fifo is full. Drop packet: len=%d\n",
84 std::prev(
fifo.end())->packet->length);
86 _size -= std::prev(
fifo.end())->packet->length;
91 warn(
"EtherSwitch: Packet length (%d) exceeds the maximum storage "
92 "capacity of port fifo (%d)", ptr->length,
_maxsize);
99 if (!
empty() &&
fifo.begin()->packet == ptr) {
111 assert(_size >= fifo.begin()->packet->length);
113 _size -= fifo.begin()->packet->length;
114 fifo.erase(fifo.begin());
126 uint64_t outputBufferSize,
Tick delay,
127 Tick delay_var,
double rate,
unsigned id)
141 learnSenderAddr(srcMacAddr,
this);
142 Interface *receiver = lookupDestPort(destMacAddr);
145 for (
auto it : parent->interfaces)
147 it->enqueue(packet, interfaceId);
149 DPRINTF(Ethernet,
"sending packet from MAC %x on port "
150 "%s to MAC %x on port %s\n", uint64_t(srcMacAddr),
151 this->
name(), uint64_t(destMacAddr), receiver->
name());
153 receiver->
enqueue(packet, interfaceId);
173 if (outputFifo.push(packet, senderId)) {
174 parent->reschedule(txEvent,
curTick() + switchingDelay(),
true);
182 assert(!outputFifo.empty());
184 if (!sendPacket(outputFifo.front())) {
185 DPRINTF(Ethernet,
"output port busy...retry later\n");
186 if (!txEvent.scheduled())
189 DPRINTF(Ethernet,
"packet sent: len=%d\n", outputFifo.front()->length);
193 if (!outputFifo.empty()) {
194 parent->schedule(txEvent,
curTick() + switchingDelay());
202 Tick delay = (
Tick)ceil(((
double)outputFifo.front()->simLength
203 * ticksPerByte) + 1.0);
206 delay += switchDelay;
213 auto it = parent->forwardingTable.find(uint64_t(destMacAddr));
215 if (it == parent->forwardingTable.end()) {
216 DPRINTF(Ethernet,
"no entry in forwaring table for MAC: "
217 "%x\n", uint64_t(destMacAddr));
222 if ((
curTick() - it->second.lastUseTime) > parent->ttl) {
225 parent->forwardingTable.erase(it);
229 DPRINTF(Ethernet,
"found entry for MAC address %x on port %s\n",
230 uint64_t(destMacAddr), it->second.interface->name());
231 return it->second.interface;
239 auto it = parent->forwardingTable.find(uint64_t(srcMacAddr));
243 if (it == parent->forwardingTable.end()) {
244 DPRINTF(Ethernet,
"adding forwarding table entry for MAC "
245 " address %x on port %s\n", uint64_t(srcMacAddr),
250 parent->forwardingTable.insert(std::make_pair(uint64_t(srcMacAddr),
251 forwardingTableEntry));
253 it->second.lastUseTime =
curTick();
261 it->serializeSection(
cp, it->name());
269 it->unserializeSection(
cp, it->name());
276 bool event_scheduled = txEvent.scheduled();
279 if (event_scheduled) {
280 Tick event_time = txEvent.when();
283 outputFifo.serializeSection(
cp,
"outputFifo");
289 bool event_scheduled;
292 if (event_scheduled) {
295 parent->schedule(txEvent, event_time);
297 outputFifo.unserializeSection(
cp,
"outputFifo");
303 packet->serialize(
"packet",
cp);
311 packet = make_shared<EthPacketData>(16384);
312 packet->unserialize(
"packet",
cp);
321 int fifosize = fifo.size();
326 for (
const auto &entry : fifo)
327 entry.serializeSection(
cp,
csprintf(
"entry%d",
i++));
339 for (
int i = 0;
i < fifosize; ++
i) {
350 EtherSwitchParams::create()
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
void serialize(CheckpointOut &cp) const
Serialize an object.
std::set< PortFifoEntry, EntryOrder > fifo
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
#define UNSERIALIZE_SCALAR(scalar)
std::vector< Interface * > interfaces
void serialize(CheckpointOut &cp) const
Serialize an object.
const double ticksPerByte
void serialize(CheckpointOut &cp) const
Serialization stuff.
uint64_t Tick
Tick count type.
Model for an Ethernet switch port.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
bool push(EthPacketPtr ptr, unsigned senderId)
Push a packet into the fifo and sort the packets with same recv tick by port id.
void unserialize(CheckpointIn &cp)
Unserialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void learnSenderAddr(Net::EthAddr srcMacAddr, Interface *sender)
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
EtherSwitch(const Params *p)
Ports are used to interface objects to each other.
void enqueue(EthPacketPtr packet, unsigned senderId)
enqueue packet to the outputFifo
const PortID id
A numeric identifier to distinguish ports in a vector, and set to InvalidPortID in case this port is ...
#define SERIALIZE_SCALAR(scalar)
PortFifo outputFifo
output fifo at each interface
virtual const std::string name() const
std::shared_ptr< EthPacketData > EthPacketPtr
Interface(const std::string &name, EtherSwitch *_etherSwitch, uint64_t outputBufferSize, Tick delay, Tick delay_var, double rate, unsigned id)
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
const std::string & name() const
Return port name (for DPRINTF).
Overload hash function for BasicBlockRange type.
Interface * lookupDestPort(Net::EthAddr destAddr)
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...
bool recvPacket(EthPacketPtr packet)
When a packet is received from a device, route it through an (several) output queue(s)
std::ostream CheckpointOut
EventFunctionWrapper txEvent
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserialize(CheckpointIn &cp)
Unserialize an object.
const unsigned interfaceId
void unserialize(CheckpointIn &cp)
Unserialize an object.
std::string csprintf(const char *format, const Args &...args)
Tick curTick()
The current simulated tick.
Abstract superclass for simulation objects.
Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17