INET Framework for OMNeT++/OMNEST
inet::EthernetSocketTable Class Reference

#include <EthernetSocketTable.h>

Inheritance diagram for inet::EthernetSocketTable:

Classes

struct  Socket
 

Public Member Functions

virtual ~EthernetSocketTable ()
 
virtual void addSocket (int socketId, MacAddress localAddress, MacAddress remoteAddress, const Protocol *protocol, bool steal)
 
virtual void removeSocket (int socketId)
 
virtual std::vector< Socket * > findSockets (MacAddress localAddress, MacAddress remoteAddress, const Protocol *protocol) const
 

Protected Member Functions

virtual void initialize (int stage) override
 

Protected Attributes

std::map< int, Socket * > socketIdToSocketMap
 

Constructor & Destructor Documentation

◆ ~EthernetSocketTable()

inet::EthernetSocketTable::~EthernetSocketTable ( )
virtual
24 {
25  for (auto it : socketIdToSocketMap)
26  delete it.second;
27 }

Member Function Documentation

◆ addSocket()

void inet::EthernetSocketTable::addSocket ( int  socketId,
MacAddress  localAddress,
MacAddress  remoteAddress,
const Protocol protocol,
bool  steal 
)
virtual
36 {
37  if (containsKey(socketIdToSocketMap, socketId))
38  throw cRuntimeError("Socket already added");
39  Socket *socket = new Socket(socketId);
40  socket->localAddress = localAddress;
41  socket->remoteAddress = remoteAddress;
42  socket->protocol = protocol;
43  socket->steal = steal;
44  socketIdToSocketMap[socketId] = socket;
45 }

◆ findSockets()

std::vector< EthernetSocketTable::Socket * > inet::EthernetSocketTable::findSockets ( MacAddress  localAddress,
MacAddress  remoteAddress,
const Protocol protocol 
) const
virtual
59 {
60  std::vector<EthernetSocketTable::Socket *> result;
61  for (auto& it : socketIdToSocketMap) {
62  auto socket = it.second;
63  if (!socket->localAddress.isUnspecified() && !localAddress.isBroadcast() && localAddress != socket->localAddress)
64  continue;
65  if (!socket->remoteAddress.isUnspecified() && !remoteAddress.isBroadcast() && remoteAddress != socket->remoteAddress)
66  continue;
67  if (socket->protocol != nullptr && protocol != socket->protocol)
68  continue;
69  result.push_back(socket);
70  }
71  return result;
72 }

◆ initialize()

void inet::EthernetSocketTable::initialize ( int  stage)
overrideprotectedvirtual
30 {
31  if (stage == INITSTAGE_LOCAL)
32  WATCH_PTRMAP(socketIdToSocketMap);
33 }

◆ removeSocket()

void inet::EthernetSocketTable::removeSocket ( int  socketId)
virtual
48 {
49  auto it = socketIdToSocketMap.find(socketId);
50  if (it != socketIdToSocketMap.end()) {
51  delete it->second;
52  socketIdToSocketMap.erase(it);
53  }
54  else
55  throw cRuntimeError("Socket not found");
56 }

Member Data Documentation

◆ socketIdToSocketMap

std::map<int, Socket *> inet::EthernetSocketTable::socketIdToSocketMap
protected

The documentation for this class was generated from the following files:
protocol
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
inet::EthernetSocketTable::socketIdToSocketMap
std::map< int, Socket * > socketIdToSocketMap
Definition: EthernetSocketTable.h:32
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::containsKey
bool containsKey(const std::map< K, V, _C > &m, const Tk &a)
Definition: stlutils.h:80