gem5 v24.0.0.0
Loading...
Searching...
No Matches
etherswitch.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/* @file
30 * Device model for an ethernet switch
31 */
32
33#ifndef __DEV_ETHERSWITCH_HH__
34#define __DEV_ETHERSWITCH_HH__
35
36#include <map>
37#include <set>
38#include <string>
39#include <vector>
40
41#include "base/inet.hh"
42#include "dev/net/etherint.hh"
43#include "dev/net/etherlink.hh"
44#include "dev/net/etherpkt.hh"
45#include "dev/net/pktfifo.hh"
46#include "params/EtherSwitch.hh"
47#include "sim/eventq.hh"
48#include "sim/serialize.hh"
49#include "sim/sim_object.hh"
50
51namespace gem5
52{
53
54class EtherSwitch : public SimObject
55{
56 public:
57 using Params = EtherSwitchParams;
58
59 EtherSwitch(const Params &p);
61
62 Port &getPort(const std::string &if_name,
63 PortID idx=InvalidPortID) override;
64
65 protected:
69 class Interface : public EtherInt, public Serializable
70 {
71 public:
72 Interface(const std::string &name, EtherSwitch *_etherSwitch,
73 uint64_t outputBufferSize, Tick delay, Tick delay_var,
74 double rate, unsigned id);
79 bool recvPacket(EthPacketPtr packet);
83 void enqueue(EthPacketPtr packet, unsigned senderId);
84 void sendDone() {}
86
88 void learnSenderAddr(networking::EthAddr srcMacAddr, Interface *sender);
89
90 void serialize(CheckpointOut &cp) const;
91 void unserialize(CheckpointIn &cp);
92
93 private:
94 const double ticksPerByte;
97 const unsigned interfaceId;
98
100 protected:
102 {
103 PortFifoEntry(EthPacketPtr pkt, Tick recv_tick, unsigned id)
104 : packet(pkt), recvTick(recv_tick), srcId(id) {}
105
108 // id of the port that the packet has been received from
109 unsigned srcId;
111 {
112 packet = nullptr;
113 recvTick = 0;
114 srcId = 0;
115 }
116 void serialize(CheckpointOut &cp) const;
117 void unserialize(CheckpointIn &cp);
118 };
119
120 class PortFifo : public Serializable
121 {
122 protected:
124 {
125 bool operator() (const PortFifoEntry& lhs,
126 const PortFifoEntry& rhs) const
127 {
128 if (lhs.recvTick == rhs.recvTick)
129 return lhs.srcId < rhs.srcId;
130 else
131 return lhs.recvTick < rhs.recvTick;
132 }
133 };
134 std::set<PortFifoEntry, EntryOrder> fifo;
135
136 const std::string objName;
137 const unsigned _maxsize;
138 unsigned _size;
139
140 public:
141 PortFifo(const std::string &name, int max)
142 :objName(name), _maxsize(max), _size(0) {}
144
145 const std::string name() { return objName; }
146 // Returns the available capacity of the fifo.
147 // It can return a negative value because in "push" function
148 // we first push the received packet into the fifo and then
149 // check if we exceed the available capacity (if avail() < 0)
150 // and remove packets from the end of fifo
151 int avail() const { return _maxsize - _size; }
152
153 EthPacketPtr front() { return fifo.begin()->packet; }
154 bool empty() const { return _size == 0; }
155 unsigned size() const { return _size; }
156
161 bool push(EthPacketPtr ptr, unsigned senderId);
162 void pop();
163 void clear();
167 void serialize(CheckpointOut &cp) const;
168 void unserialize(CheckpointIn &cp);
169 };
174 void transmit();
176 };
177
183
184 private:
185 // time to live for MAC address mappings
186 const double ttl;
187 // all interfaces of the switch
189 // table that maps MAC address to interfaces
190 std::map<uint64_t, SwitchTableEntry> forwardingTable;
191
192 void serialize(CheckpointOut &cp) const override;
193 void unserialize(CheckpointIn &cp) override;
194};
195
196} // namespace gem5
197
198#endif // __DEV_ETHERSWITCH_HH__
const std::string & name() const
Return port name (for DPRINTF).
Definition etherint.hh:62
bool push(EthPacketPtr ptr, unsigned senderId)
Push a packet into the fifo and sort the packets with same recv tick by port id.
std::set< PortFifoEntry, EntryOrder > fifo
void serialize(CheckpointOut &cp) const
Serialization stuff.
PortFifo(const std::string &name, int max)
void unserialize(CheckpointIn &cp)
Unserialize an object.
Model for an Ethernet switch port.
PortFifo outputFifo
output fifo at each interface
void learnSenderAddr(networking::EthAddr srcMacAddr, Interface *sender)
Interface * lookupDestPort(networking::EthAddr destAddr)
void unserialize(CheckpointIn &cp)
Unserialize an object.
void enqueue(EthPacketPtr packet, unsigned senderId)
enqueue packet to the outputFifo
bool recvPacket(EthPacketPtr packet)
When a packet is received from a device, route it through an (several) output queue(s)
EventFunctionWrapper txEvent
Interface(const std::string &name, EtherSwitch *_etherSwitch, uint64_t outputBufferSize, Tick delay, Tick delay_var, double rate, unsigned id)
void serialize(CheckpointOut &cp) const
Serialize an object.
std::vector< Interface * > interfaces
EtherSwitchParams Params
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void serialize(CheckpointOut &cp) const override
Serialize an object.
EtherSwitch(const Params &p)
std::map< uint64_t, SwitchTableEntry > forwardingTable
const double ttl
Ports are used to interface objects to each other.
Definition port.hh:62
const PortID id
A numeric identifier to distinguish ports in a vector, and set to InvalidPortID in case this port is ...
Definition port.hh:79
Basic support for object serialization.
Definition serialize.hh:170
Abstract superclass for simulation objects.
STL vector class.
Definition stl.hh:37
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
std::ostream CheckpointOut
Definition serialize.hh:66
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
std::shared_ptr< EthPacketData > EthPacketPtr
Definition etherpkt.hh:90
void unserialize(CheckpointIn &cp)
Unserialize an object.
void serialize(CheckpointOut &cp) const
Serialize an object.
PortFifoEntry(EthPacketPtr pkt, Tick recv_tick, unsigned id)
bool operator()(const PortFifoEntry &lhs, const PortFifoEntry &rhs) const

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0