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

UDP application. More...

#include <UdpEchoApp.h>

Inheritance diagram for inet::UdpEchoApp:
inet::ApplicationBase inet::UdpSocket::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 *msg) override
 
virtual void finish () override
 
virtual void refreshDisplay () const override
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
virtual void socketDataArrived (UdpSocket *socket, Packet *packet) override
 Notifies about data arrival, packet ownership is transferred to the callee. More...
 
virtual void socketErrorArrived (UdpSocket *socket, Indication *indication) override
 Notifies about error indication arrival, indication ownership is transferred to the callee. More...
 
virtual void socketClosed (UdpSocket *socket) override
 Notifies about socket closed, indication ownership is transferred to the callee. More...
 
- 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

UdpSocket socket
 
int numEchoed
 
- 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::UdpSocket::ICallback
virtual ~ICallback ()
 
- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Detailed Description

UDP application.

See NED for more info.

Member Function Documentation

◆ finish()

void inet::UdpEchoApp::finish ( )
overrideprotectedvirtual
73 {
74  ApplicationBase::finish();
75 }

◆ handleCrashOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

94 {
95  if (operation->getRootModule() != getContainingNode(this)) // closes socket when the application crashed only
96  socket.destroy(); // TODO in real operating systems, program crash detected by OS and OS closes sockets of crashed programs.
97  socket.setCallback(nullptr);
98 }

◆ handleMessageWhenUp()

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

◆ handleStartOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

78 {
79  socket.setOutputGate(gate("socketOut"));
80  int localPort = par("localPort");
81  socket.bind(localPort);
82  MulticastGroupList mgl = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this)->collectMulticastGroups();
84  socket.setCallback(this);
85 }

◆ handleStopOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

88 {
89  socket.close();
90  delayActiveOperationFinish(par("stopOperationTimeout"));
91 }

◆ initialize()

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

Reimplemented from inet::OperationalMixin< cSimpleModule >.

21 {
23 
24  if (stage == INITSTAGE_LOCAL) {
25  // init statistics
26  numEchoed = 0;
27  WATCH(numEchoed);
28  }
29 }

◆ numInitStages()

virtual int inet::UdpEchoApp::numInitStages ( ) const
inlineoverrideprotectedvirtual
26 { return NUM_INIT_STAGES; }

◆ refreshDisplay()

void inet::UdpEchoApp::refreshDisplay ( ) const
overrideprotectedvirtual
64 {
66 
67  char buf[40];
68  sprintf(buf, "echoed: %d pks", numEchoed);
69  getDisplayString().setTagArg("t", 0, buf);
70 }

◆ socketClosed()

void inet::UdpEchoApp::socketClosed ( UdpSocket socket)
overrideprotectedvirtual

Notifies about socket closed, indication ownership is transferred to the callee.

Implements inet::UdpSocket::ICallback.

58 {
59  if (operationalState == State::STOPPING_OPERATION)
60  startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime"));
61 }

◆ socketDataArrived()

void inet::UdpEchoApp::socketDataArrived ( UdpSocket socket,
Packet packet 
)
overrideprotectedvirtual

Notifies about data arrival, packet ownership is transferred to the callee.

Implements inet::UdpSocket::ICallback.

37 {
38  // determine its source address/port
39  L3Address remoteAddress = pk->getTag<L3AddressInd>()->getSrcAddress();
40  int srcPort = pk->getTag<L4PortInd>()->getSrcPort();
41  pk->clearTags();
42  pk->trim();
43 
44  // statistics
45  numEchoed++;
46  emit(packetSentSignal, pk);
47  // send back
48  socket->sendTo(pk, remoteAddress, srcPort);
49 }

◆ socketErrorArrived()

void inet::UdpEchoApp::socketErrorArrived ( UdpSocket socket,
Indication indication 
)
overrideprotectedvirtual

Notifies about error indication arrival, indication ownership is transferred to the callee.

Implements inet::UdpSocket::ICallback.

52 {
53  EV_WARN << "Ignoring UDP error report " << indication->getName() << endl;
54  delete indication;
55 }

Member Data Documentation

◆ numEchoed

int inet::UdpEchoApp::numEchoed
protected

◆ socket


The documentation for this class was generated from the following files:
inet::UdpSocket::setOutputGate
void setOutputGate(cGate *toUdp)
Sets the gate on which to send to UDP.
Definition: UdpSocket.h:117
inet::OperationalMixin< cSimpleModule >::operationalState
State operationalState
Definition: OperationalMixin.h:23
inet::UdpSocket::bind
void bind(int localPort)
Bind the socket to a local port number.
Definition: UdpSocket.cc:34
inet::UdpSocket::sendTo
void sendTo(Packet *msg, L3Address destAddr, int destPort)
Sends a data packet to the given address and port.
Definition: UdpSocket.cc:69
inet::UdpEchoApp::socket
UdpSocket socket
Definition: UdpEchoApp.h:22
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
inet::UdpSocket::destroy
virtual void destroy() override
Notify the protocol that the owner of ISocket has destroyed the socket.
Definition: UdpSocket.cc:98
L3AddressInd
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
inet::packetSentSignal
simsignal_t packetSentSignal
Definition: Simsignals.cc:96
inet::UdpSocket::setCallback
void setCallback(ICallback *cb)
Sets a callback object, to be used with processMessage().
Definition: UdpSocket.cc:338
inet::UdpEchoApp::numEchoed
int numEchoed
Definition: UdpEchoApp.h:23
inet::UdpSocket::joinLocalMulticastGroups
void joinLocalMulticastGroups(MulticastGroupList mgl)
Joins the socket to each multicast group that are registered with any of the interfaces.
Definition: UdpSocket.cc:265
inet::UdpSocket::processMessage
virtual void processMessage(cMessage *msg) override
Examines the message, takes ownership, and updates socket state.
Definition: UdpSocket.cc:343
inet::MulticastGroupList
std::vector< MulticastGroup > MulticastGroupList
Definition: IInterfaceTable.h:26
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::UdpSocket::close
virtual void close() override
Unbinds the socket.
Definition: UdpSocket.cc:87
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
L4PortInd
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L4PortInd
Definition: IUdp-gates.txt:20
inet::OperationalMixin< cSimpleModule >::delayActiveOperationFinish
virtual void delayActiveOperationFinish(simtime_t timeout)
Definition: OperationalMixinImpl.h:161
inet::OperationalMixin< cSimpleModule >::startActiveOperationExtraTimeOrFinish
virtual void startActiveOperationExtraTimeOrFinish(simtime_t extraTime)
Definition: OperationalMixinImpl.h:179
inet::OperationalMixin< cSimpleModule >::refreshDisplay
virtual void refreshDisplay() const override
Definition: OperationalMixinImpl.h:200