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

#include <Ieee8022LlcSocketIo.h>

Inheritance diagram for inet::Ieee8022LlcSocketIo:
inet::ApplicationBase inet::Ieee8022LlcSocket::ICallback inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessageWhenUp (cMessage *message) override
 
virtual void finish () override
 
virtual void refreshDisplay () const override
 
virtual void setSocketOptions ()
 
virtual void socketDataArrived (Ieee8022LlcSocket *socket, Packet *packet) override
 
virtual void socketClosed (Ieee8022LlcSocket *socket) override
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
- Protected Member Functions inherited from inet::ApplicationBase
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
- Protected Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual void handleActiveOperationTimeout (cMessage *message)
 
virtual bool isUp () const
 utility functions More...
 
virtual bool isDown () const
 
virtual void setOperationalState (State newState)
 
virtual void scheduleOperationTimeout (simtime_t timeout)
 
virtual void setupActiveOperation (LifecycleOperation *operation, IDoneCallback *doneCallback, State)
 
virtual void delayActiveOperationFinish (simtime_t timeout)
 
virtual void startActiveOperationExtraTime (simtime_t delay=SIMTIME_ZERO)
 
virtual void startActiveOperationExtraTimeOrFinish (simtime_t extraTime)
 
virtual void finishActiveOperation ()
 

Protected Attributes

int localSap = -1
 
int remoteSap = -1
 
MacAddress remoteAddress
 
MacAddress localAddress
 
NetworkInterfacenetworkInterface = nullptr
 
Ieee8022LlcSocket socket
 
int numSent = 0
 
int numReceived = 0
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Additional Inherited Members

- Public Member Functions inherited from inet::ApplicationBase
 ApplicationBase ()
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 
- Public Member Functions inherited from inet::Ieee8022LlcSocket::ICallback
virtual ~ICallback ()
 
- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Member Function Documentation

◆ finish()

void inet::Ieee8022LlcSocketIo::finish ( )
overrideprotectedvirtual
83 {
84  recordScalar("packets sent", numSent);
85  recordScalar("packets received", numReceived);
86  ApplicationBase::finish();
87 }

◆ handleCrashOperation()

void inet::Ieee8022LlcSocketIo::handleCrashOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

131 {
132  socket.destroy();
133 }

◆ handleMessageWhenUp()

void inet::Ieee8022LlcSocketIo::handleMessageWhenUp ( cMessage *  message)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

65 {
66  if (socket.belongsToSocket(message))
67  socket.processMessage(message);
68  else {
69  auto packet = check_and_cast<Packet *>(message);
70  if (packet->findTag<PacketProtocolTag>() == nullptr) {
71  auto packetProtocolTag = packet->addTag<PacketProtocolTag>();
72  packetProtocolTag->setProtocol(&Protocol::unknown);
73  }
74  auto& macAddressReq = packet->addTag<MacAddressReq>();
75  macAddressReq->setDestAddress(remoteAddress);
76  socket.send(packet);
77  numSent++;
78  emit(packetSentSignal, packet);
79  }
80 }

◆ handleStartOperation()

void inet::Ieee8022LlcSocketIo::handleStartOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

118 {
120  socket.setOutputGate(gate("socketOut"));
122 }

◆ handleStopOperation()

void inet::Ieee8022LlcSocketIo::handleStopOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

125 {
126  socket.close();
127  delayActiveOperationFinish(par("stopOperationTimeout"));
128 }

◆ initialize()

void inet::Ieee8022LlcSocketIo::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalMixin< cSimpleModule >.

23 {
25  if (stage == INITSTAGE_LOCAL) {
26  localSap = par("localSap");
27  remoteSap = par("remoteSap");
28  numSent = 0;
29  numReceived = 0;
30  WATCH(numSent);
31  WATCH(numReceived);
32  }
33  else if (stage == INITSTAGE_NETWORK_INTERFACE_CONFIGURATION + 1) {
34  const char *localAddressString = par("localAddress");
35  if (*localAddressString != '\0') {
36  L3Address l3Address;
37  L3AddressResolver addressResolver;
38  addressResolver.tryResolve(localAddressString, l3Address, L3AddressResolver::ADDR_MAC);
39  if (l3Address.getType() == L3Address::MAC)
40  localAddress = l3Address.toMac();
41  else
42  localAddress = MacAddress(localAddressString);
43  }
44  const char *remoteAddressString = par("remoteAddress");
45  if (*remoteAddressString != '\0') {
46  L3Address l3Address;
47  L3AddressResolver addressResolver;
48  addressResolver.tryResolve(remoteAddressString, l3Address, L3AddressResolver::ADDR_MAC);
49  if (l3Address.getType() == L3Address::MAC)
50  remoteAddress = l3Address.toMac();
51  else
52  remoteAddress = MacAddress(remoteAddressString);
53  }
54  const char *interface = par("interface");
55  if (interface[0] != '\0') {
56  auto interfaceTable = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this);
57  networkInterface = interfaceTable->findInterfaceByName(interface);
58  if (networkInterface == nullptr)
59  throw cRuntimeError("Cannot find network interface");
60  }
61  }
62 }

◆ numInitStages()

virtual int inet::Ieee8022LlcSocketIo::numInitStages ( ) const
inlineoverrideprotectedvirtual
32 { return NUM_INIT_STAGES; }

◆ refreshDisplay()

void inet::Ieee8022LlcSocketIo::refreshDisplay ( ) const
overrideprotectedvirtual
90 {
92  char buf[100];
93  sprintf(buf, "rcvd: %d pks\nsent: %d pks", numReceived, numSent);
94  getDisplayString().setTagArg("t", 0, buf);
95 }

◆ setSocketOptions()

void inet::Ieee8022LlcSocketIo::setSocketOptions ( )
protectedvirtual
98 {
99  socket.setCallback(this);
100 }

Referenced by handleStartOperation().

◆ socketClosed()

void inet::Ieee8022LlcSocketIo::socketClosed ( Ieee8022LlcSocket socket)
overrideprotectedvirtual

Implements inet::Ieee8022LlcSocket::ICallback.

112 {
113  if (operationalState == State::STOPPING_OPERATION)
114  startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime"));
115 }

◆ socketDataArrived()

void inet::Ieee8022LlcSocketIo::socketDataArrived ( Ieee8022LlcSocket socket,
Packet packet 
)
overrideprotectedvirtual

Implements inet::Ieee8022LlcSocket::ICallback.

103 {
104  emit(packetReceivedSignal, packet);
105  EV_INFO << "Received packet: " << packet << endl;
106  numReceived++;
107  packet->removeTag<SocketInd>();
108  send(packet, "trafficOut");
109 }

Member Data Documentation

◆ localAddress

MacAddress inet::Ieee8022LlcSocketIo::localAddress
protected

Referenced by initialize().

◆ localSap

int inet::Ieee8022LlcSocketIo::localSap = -1
protected

Referenced by handleStartOperation(), and initialize().

◆ networkInterface

NetworkInterface* inet::Ieee8022LlcSocketIo::networkInterface = nullptr
protected

Referenced by handleStartOperation(), and initialize().

◆ numReceived

int inet::Ieee8022LlcSocketIo::numReceived = 0
protected

◆ numSent

int inet::Ieee8022LlcSocketIo::numSent = 0
protected

◆ remoteAddress

MacAddress inet::Ieee8022LlcSocketIo::remoteAddress
protected

Referenced by handleMessageWhenUp(), and initialize().

◆ remoteSap

int inet::Ieee8022LlcSocketIo::remoteSap = -1
protected

Referenced by handleStartOperation(), and initialize().

◆ socket


The documentation for this class was generated from the following files:
inet::Ieee8022LlcSocket::setCallback
void setCallback(ICallback *callback)
Sets a callback object, to be used with processMessage().
Definition: Ieee8022LlcSocket.h:49
inet::OperationalMixin< cSimpleModule >::operationalState
State operationalState
Definition: OperationalMixin.h:23
inet::SocketBase::setOutputGate
void setOutputGate(cGate *gate)
Sets the gate on which to send messages.
Definition: SocketBase.h:36
inet::Ieee8022LlcSocketIo::remoteAddress
MacAddress remoteAddress
Definition: Ieee8022LlcSocketIo.h:22
inet::Ieee8022LlcSocketIo::networkInterface
NetworkInterface * networkInterface
Definition: Ieee8022LlcSocketIo.h:24
inet::Ieee8022LlcSocketIo::localAddress
MacAddress localAddress
Definition: Ieee8022LlcSocketIo.h:23
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
inet::Ieee8022LlcSocketIo::numSent
int numSent
Definition: Ieee8022LlcSocketIo.h:28
inet::packetSentSignal
simsignal_t packetSentSignal
Definition: Simsignals.cc:96
inet::Ieee8022LlcSocketIo::remoteSap
int remoteSap
Definition: Ieee8022LlcSocketIo.h:21
inet::L3AddressResolver::ADDR_MAC
@ ADDR_MAC
Definition: L3AddressResolver.h:72
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::INITSTAGE_NETWORK_INTERFACE_CONFIGURATION
INET_API InitStage INITSTAGE_NETWORK_INTERFACE_CONFIGURATION
Initialization of network interfaces includes:
inet::NetworkInterface::getInterfaceId
int getInterfaceId() const
Definition: NetworkInterface.h:232
inet::packetReceivedSignal
simsignal_t packetReceivedSignal
Definition: Simsignals.cc:97
inet::Ieee8022LlcSocketIo::numReceived
int numReceived
Definition: Ieee8022LlcSocketIo.h:29
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::SocketBase::close
virtual void close() override
Unbinds the socket.
Definition: SocketBase.cc:43
inet::SocketBase::send
virtual void send(Packet *packet) override
Sends a data packet to the address and port specified previously in a connect() call.
Definition: SocketBase.cc:36
inet::Ieee8022LlcSocket::open
virtual void open(int interfaceId, int localSap, int remoteSap)
Definition: Ieee8022LlcSocket.cc:40
inet::OperationalMixin< cSimpleModule >::delayActiveOperationFinish
virtual void delayActiveOperationFinish(simtime_t timeout)
Definition: OperationalMixinImpl.h:161
inet::Ieee8022LlcSocketIo::socket
Ieee8022LlcSocket socket
Definition: Ieee8022LlcSocketIo.h:26
inet::OperationalMixin< cSimpleModule >::startActiveOperationExtraTimeOrFinish
virtual void startActiveOperationExtraTimeOrFinish(simtime_t extraTime)
Definition: OperationalMixinImpl.h:179
inet::L3Address::MAC
@ MAC
Definition: L3Address.h:38
inet::Ieee8022LlcSocketIo::localSap
int localSap
Definition: Ieee8022LlcSocketIo.h:20
inet::OperationalMixin< cSimpleModule >::refreshDisplay
virtual void refreshDisplay() const override
Definition: OperationalMixinImpl.h:200
inet::Ieee8022LlcSocket::processMessage
virtual void processMessage(cMessage *msg) override
Examines the message, takes ownership, and updates socket state.
Definition: Ieee8022LlcSocket.cc:57
inet::Ieee8022LlcSocketIo::setSocketOptions
virtual void setSocketOptions()
Definition: Ieee8022LlcSocketIo.cc:97
inet::SocketBase::belongsToSocket
virtual bool belongsToSocket(cMessage *msg) const override
Returns true if the message belongs to this socket instance.
Definition: SocketBase.cc:61
inet::SocketBase::destroy
virtual void destroy() override
Notify the protocol that the owner of ISocket has destroyed the socket.
Definition: SocketBase.cc:52
inet::Protocol::unknown
static const Protocol unknown
Definition: Protocol.h:133