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

UDP application. More...

#include <UDPEchoApp.h>

Inheritance diagram for inet::UDPEchoApp:
inet::ApplicationBase inet::OperationalBase 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 bool handleNodeStart (IDoneCallback *doneCallback) override
 
virtual bool handleNodeShutdown (IDoneCallback *doneCallback) override
 
virtual void handleNodeCrash () override
 
- Protected Member Functions inherited from inet::ApplicationBase
virtual bool isInitializeStage (int stage) override
 
virtual bool isNodeStartStage (int stage) override
 
virtual bool isNodeShutdownStage (int stage) override
 
- Protected Member Functions inherited from inet::OperationalBase
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual void setOperational (bool isOperational)
 

Protected Attributes

UDPSocket socket
 
int numEchoed
 
- Protected Attributes inherited from inet::OperationalBase
bool isOperational
 
simtime_t lastChange
 

Static Protected Attributes

static simsignal_t pkSignal = registerSignal("pk")
 

Additional Inherited Members

- Public Member Functions inherited from inet::ApplicationBase
 ApplicationBase ()
 
- Public Member Functions inherited from inet::OperationalBase
 OperationalBase ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Detailed Description

UDP application.

See NED for more info.

Member Function Documentation

void inet::UDPEchoApp::finish ( )
overrideprotectedvirtual
74 {
75  ApplicationBase::finish();
76 }
void inet::UDPEchoApp::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::OperationalBase.

41 {
42  if (msg->getKind() == UDP_I_ERROR) {
43  // ICMP error report -- discard it
44  delete msg;
45  }
46  else if (msg->getKind() == UDP_I_DATA) {
47  cPacket *pk = PK(msg);
48  // statistics
49  numEchoed++;
50  emit(pkSignal, pk);
51 
52  // determine its source address/port
53  UDPDataIndication *ctrl = check_and_cast<UDPDataIndication *>(pk->removeControlInfo());
54  L3Address srcAddress = ctrl->getSrcAddr();
55  int srcPort = ctrl->getSrcPort();
56  delete ctrl;
57 
58  // send back
59  socket.sendTo(pk, srcAddress, srcPort);
60  }
61  else {
62  throw cRuntimeError("Message received with unexpected message kind = %d", msg->getKind());
63  }
64 }
UDPSocket socket
Definition: UDPEchoApp.h:34
Definition: UDPControlInfo_m.h:83
void sendTo(cPacket *msg, L3Address destAddr, int destPort, const SendOptions *options=nullptr)
Sends a data packet to the given address and port.
Definition: UDPSocket.cc:88
int numEchoed
Definition: UDPEchoApp.h:35
Definition: UDPControlInfo_m.h:84
#define PK(msg)
Definition: INETDefs.h:92
static simsignal_t pkSignal
Definition: UDPEchoApp.h:36
void inet::UDPEchoApp::handleNodeCrash ( )
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

95 {
96 }
bool inet::UDPEchoApp::handleNodeShutdown ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

89 {
90  //TODO if(socket.isOpened()) socket.close();
91  return true;
92 }
bool inet::UDPEchoApp::handleNodeStart ( IDoneCallback doneCallback)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

79 {
80  socket.setOutputGate(gate("udpOut"));
81  int localPort = par("localPort");
82  socket.bind(localPort);
83  MulticastGroupList mgl = getModuleFromPar<IInterfaceTable>(par("interfaceTableModule"), this)->collectMulticastGroups();
85  return true;
86 }
UDPSocket socket
Definition: UDPEchoApp.h:34
void joinLocalMulticastGroups(MulticastGroupList mgl)
Joins the socket to each multicast group that are registered with any of the interfaces.
Definition: UDPSocket.cc:194
void setOutputGate(cGate *toUdp)
Sets the gate on which to send to UDP.
Definition: UDPSocket.h:110
void bind(int localPort)
Bind the socket to a local port number.
Definition: UDPSocket.cc:53
std::vector< MulticastGroup > MulticastGroupList
Definition: IInterfaceTable.h:36
void inet::UDPEchoApp::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalBase.

30 {
32 
33  if (stage == INITSTAGE_LOCAL) {
34  // init statistics
35  numEchoed = 0;
36  WATCH(numEchoed);
37  }
38 }
int numEchoed
Definition: UDPEchoApp.h:35
Local initializations.
Definition: InitStages.h:35
virtual void initialize(int stage) override
Definition: OperationalBase.cc:32
virtual int inet::UDPEchoApp::numInitStages ( ) const
inlineoverrideprotectedvirtual

Reimplemented from inet::OperationalBase.

39 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::UDPEchoApp::refreshDisplay ( ) const
overrideprotectedvirtual
67 {
68  char buf[40];
69  sprintf(buf, "echoed: %d pks", numEchoed);
70  getDisplayString().setTagArg("t", 0, buf);
71 }
int numEchoed
Definition: UDPEchoApp.h:35

Member Data Documentation

int inet::UDPEchoApp::numEchoed
protected
simsignal_t inet::UDPEchoApp::pkSignal = registerSignal("pk")
staticprotected

Referenced by handleMessageWhenUp().

UDPSocket inet::UDPEchoApp::socket
protected

The documentation for this class was generated from the following files: