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

Server-side process EtherAppClient. More...

#include <EtherAppServer.h>

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

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessageWhenUp (cMessage *msg) override
 
virtual void finish () override
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
void registerDsap (int dsap)
 
void sendPacket (Packet *datapacket, int interfaceId, const MacAddress &destAddr, int destSap)
 
virtual void socketDataArrived (Ieee8022LlcSocket *, Packet *msg) override
 
virtual void socketClosed (Ieee8022LlcSocket *socket) 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 = 0
 
Ieee8022LlcSocket llcSocket
 
long packetsSent = 0
 
long packetsReceived = 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
 

Detailed Description

Server-side process EtherAppClient.

Member Function Documentation

◆ finish()

void inet::EtherAppServer::finish ( )
overrideprotectedvirtual
133 {
134 }

◆ handleCrashOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

57 {
58  EV_INFO << "Crash the application\n";
59  if (operation->getRootModule() != getContainingNode(this))
61 }

◆ handleMessageWhenUp()

void inet::EtherAppServer::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

◆ handleStartOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

44 {
45  EV_INFO << "Starting application\n";
47 }

◆ handleStopOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

50 {
51  EV_INFO << "Stop the application\n";
52  llcSocket.close();
53  delayActiveOperationFinish(par("stopOperationTimeout"));
54 }

◆ initialize()

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

Reimplemented from inet::OperationalMixin< cSimpleModule >.

25 {
27 
28  if (stage == INITSTAGE_LOCAL) {
29  localSap = par("localSAP");
30 
31  // statistics
33 
34  // socket
35  llcSocket.setOutputGate(gate("out"));
36  llcSocket.setCallback(this);
37 
38  WATCH(packetsSent);
39  WATCH(packetsReceived);
40  }
41 }

◆ numInitStages()

virtual int inet::EtherAppServer::numInitStages ( ) const
inlineoverrideprotectedvirtual
36 { return NUM_INIT_STAGES; }

◆ registerDsap()

void inet::EtherAppServer::registerDsap ( int  dsap)
protected
126 {
127  EV_DEBUG << getFullPath() << " registering DSAP " << dsap << "\n";
128 
129  llcSocket.open(-1, dsap, -1);
130 }

Referenced by handleStartOperation().

◆ sendPacket()

void inet::EtherAppServer::sendPacket ( Packet datapacket,
int  interfaceId,
const MacAddress destAddr,
int  destSap 
)
protected
113 {
114  datapacket->addTag<InterfaceReq>()->setInterfaceId(interfaceId);
115  datapacket->addTag<MacAddressReq>()->setDestAddress(destAddr);
116  auto ieee802SapReq = datapacket->addTag<Ieee802SapReq>();
117  ieee802SapReq->setSsap(localSap);
118  ieee802SapReq->setDsap(destSap);
119 
120  emit(packetSentSignal, datapacket);
121  llcSocket.send(datapacket);
122  packetsSent++;
123 }

Referenced by socketDataArrived().

◆ socketClosed()

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

Implements inet::Ieee8022LlcSocket::ICallback.

64 {
65  if (operationalState == State::STOPPING_OPERATION && !llcSocket.isOpen())
66  startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime"));
67 }

◆ socketDataArrived()

void inet::EtherAppServer::socketDataArrived ( Ieee8022LlcSocket ,
Packet msg 
)
overrideprotectedvirtual

Implements inet::Ieee8022LlcSocket::ICallback.

75 {
76  EV_INFO << "Received packet `" << msg->getName() << "'\n";
77  const auto& req = msg->peekAtFront<EtherAppReq>();
78  if (req == nullptr)
79  throw cRuntimeError("data type error: not an EtherAppReq arrived in packet %s", msg->str().c_str());
81  emit(packetReceivedSignal, msg);
82 
83  MacAddress srcAddr = msg->getTag<MacAddressInd>()->getSrcAddress();
84  int srcInterfaceId = msg->getTag<InterfaceInd>()->getInterfaceId();
85  int srcSap = msg->getTag<Ieee802SapInd>()->getSsap();
86  long requestId = req->getRequestId();
87  long replyBytes = req->getResponseBytes();
88 
89  // send back packets asked by EtherAppClient side
90  for (int k = 0; replyBytes > 0; k++) {
91  int l = replyBytes > MAX_REPLY_CHUNK_SIZE ? MAX_REPLY_CHUNK_SIZE : replyBytes;
92  replyBytes -= l;
93 
94  std::ostringstream s;
95  s << msg->getName() << "-resp-" << k;
96 
97  Packet *outPacket = new Packet(s.str().c_str(), IEEE802CTRL_DATA);
98  const auto& outPayload = makeShared<EtherAppResp>();
99  outPayload->setRequestId(requestId);
100  outPayload->setChunkLength(B(l));
101  outPayload->addTag<CreationTimeTag>()->setCreationTime(simTime());
102  outPacket->insertAtBack(outPayload);
103 
104  EV_INFO << "Send response `" << outPacket->getName() << "' to " << srcAddr << " ssap=" << localSap << " dsap=" << srcSap << " length=" << l << "B requestId=" << requestId << "\n";
105 
106  sendPacket(outPacket, srcInterfaceId, srcAddr, srcSap);
107  }
108 
109  delete msg;
110 }

Member Data Documentation

◆ llcSocket

◆ localSap

int inet::EtherAppServer::localSap = 0
protected

◆ packetsReceived

long inet::EtherAppServer::packetsReceived = 0
protected

Referenced by initialize(), and socketDataArrived().

◆ packetsSent

long inet::EtherAppServer::packetsSent = 0
protected

Referenced by initialize(), and sendPacket().


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::EtherAppServer::llcSocket
Ieee8022LlcSocket llcSocket
Definition: EtherAppServer.h:28
inet::IEEE802CTRL_DATA
@ IEEE802CTRL_DATA
Definition: Ieee802Ctrl_m.h:58
inet::EtherAppServer::sendPacket
void sendPacket(Packet *datapacket, int interfaceId, const MacAddress &destAddr, int destSap)
Definition: EtherAppServer.cc:112
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
InterfaceReq
removed InterfaceReq
Definition: IUdp-gates.txt:11
MAX_REPLY_CHUNK_SIZE
#define MAX_REPLY_CHUNK_SIZE
Definition: EtherAppServer.h:18
inet::packetSentSignal
simsignal_t packetSentSignal
Definition: Simsignals.cc:96
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::EtherAppServer::packetsSent
long packetsSent
Definition: EtherAppServer.h:31
inet::packetReceivedSignal
simsignal_t packetReceivedSignal
Definition: Simsignals.cc:97
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::isOpen
virtual bool isOpen() const override
Returns true if the socket is open.
Definition: SocketBase.h:55
inet::physicallayer::k
const double k
Definition: Qam1024Modulation.cc:14
inet::SocketBase::close
virtual void close() override
Unbinds the socket.
Definition: SocketBase.cc:43
inet::EtherAppServer::packetsReceived
long packetsReceived
Definition: EtherAppServer.h:32
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::EtherAppServer::registerDsap
void registerDsap(int dsap)
Definition: EtherAppServer.cc:125
inet::OperationalMixin< cSimpleModule >::startActiveOperationExtraTimeOrFinish
virtual void startActiveOperationExtraTimeOrFinish(simtime_t extraTime)
Definition: OperationalMixinImpl.h:179
inet::Ieee8022LlcSocket::processMessage
virtual void processMessage(cMessage *msg) override
Examines the message, takes ownership, and updates socket state.
Definition: Ieee8022LlcSocket.cc:57
inet::EtherAppServer::localSap
int localSap
Definition: EtherAppServer.h:26
inet::SocketBase::destroy
virtual void destroy() override
Notify the protocol that the owner of ISocket has destroyed the socket.
Definition: SocketBase.cc:52