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

TODO. More...

#include <EchoProtocol.h>

Inheritance diagram for inet::EchoProtocol:

Protected Types

typedef std::map< long, int > PingMap
 

Protected Member Functions

virtual void processPacket (EchoPacket *packet)
 
virtual void processEchoRequest (EchoPacket *packet)
 
virtual void processEchoReply (EchoPacket *packet)
 
virtual void sendEchoRequest (PingPayload *packet)
 
virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 

Protected Attributes

PingMap pingMap
 

Detailed Description

TODO.

Member Typedef Documentation

typedef std::map<long, int> inet::EchoProtocol::PingMap
protected

Member Function Documentation

void inet::EchoProtocol::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
39 {
40  cGate *arrivalGate = msg->getArrivalGate();
41  if (!strcmp(arrivalGate->getName(), "localIn"))
42  processPacket(check_and_cast<EchoPacket *>(msg));
43  else if (!strcmp(arrivalGate->getName(), "pingIn"))
44  sendEchoRequest(check_and_cast<PingPayload *>(msg));
45 }
virtual void sendEchoRequest(PingPayload *packet)
Definition: EchoProtocol.cc:96
virtual void processPacket(EchoPacket *packet)
Definition: EchoProtocol.cc:47
void inet::EchoProtocol::initialize ( int  stage)
overrideprotectedvirtual
29 {
30  cSimpleModule::initialize(stage);
31 
32  if (stage == INITSTAGE_NETWORK_LAYER_2) {
33  IPSocket socket(gate("sendOut"));
34  socket.registerProtocol(IP_PROT_ICMP);
35  }
36 }
Definition: IPProtocolId_m.h:77
Initialization of network-layer protocols, stage 2.
Definition: InitStages.h:78
virtual int inet::EchoProtocol::numInitStages ( ) const
inlineoverrideprotectedvirtual
45 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::EchoProtocol::processEchoReply ( EchoPacket packet)
protectedvirtual

Referenced by processPacket().

81 {
82  cObject *controlInfo = reply->removeControlInfo();
83  PingPayload *payload = check_and_cast<PingPayload *>(reply->decapsulate());
84  payload->setControlInfo(controlInfo);
85  delete reply;
86  long originatorId = payload->getOriginatorId();
87  auto i = pingMap.find(originatorId);
88  if (i != pingMap.end())
89  send(payload, "pingOut", i->second);
90  else {
91  EV_INFO << "Received ECHO REPLY has an unknown originator ID: " << originatorId << ", packet dropped." << endl;
92  delete payload;
93  }
94 }
PingMap pingMap
Definition: EchoProtocol.h:36
void inet::EchoProtocol::processEchoRequest ( EchoPacket packet)
protectedvirtual

Referenced by processPacket().

64 {
65  // turn request into a reply
66  EchoPacket *reply = request;
67  reply->setName((std::string(request->getName()) + "-reply").c_str());
68  reply->setType(ECHO_PROTOCOL_REPLY);
69  // swap src and dest
70  // TBD check what to do if dest was multicast etc?
71  INetworkProtocolControlInfo *ctrl = check_and_cast<INetworkProtocolControlInfo *>(reply->getControlInfo());
72  L3Address src = ctrl->getSourceAddress();
73  L3Address dest = ctrl->getDestinationAddress();
74  ctrl->setInterfaceId(-1);
75  ctrl->setSourceAddress(dest);
76  ctrl->setDestinationAddress(src);
77  send(reply, "sendOut");
78 }
Definition: EchoPacket_m.h:53
void inet::EchoProtocol::processPacket ( EchoPacket packet)
protectedvirtual

Referenced by handleMessage().

48 {
49  switch (msg->getType()) {
51  processEchoRequest(msg);
52  break;
53 
55  processEchoReply(msg);
56  break;
57 
58  default:
59  throw cRuntimeError("Unknown type %d", msg->getType());
60  }
61 }
Definition: EchoPacket_m.h:52
virtual void processEchoRequest(EchoPacket *packet)
Definition: EchoProtocol.cc:63
Definition: EchoPacket_m.h:53
virtual void processEchoReply(EchoPacket *packet)
Definition: EchoProtocol.cc:80
void inet::EchoProtocol::sendEchoRequest ( PingPayload packet)
protectedvirtual

Referenced by handleMessage().

97 {
98  cGate *arrivalGate = msg->getArrivalGate();
99  int i = arrivalGate->getIndex();
100  pingMap[msg->getOriginatorId()] = i;
101  cObject *controlInfo = msg->removeControlInfo();
102  INetworkProtocolControlInfo *networkControlInfo = check_and_cast<INetworkProtocolControlInfo *>(controlInfo);
103  // TODO: remove
104  networkControlInfo->setTransportProtocol(IP_PROT_ICMP);
105  EchoPacket *request = new EchoPacket(msg->getName());
106  request->setType(ECHO_PROTOCOL_REQUEST);
107  request->encapsulate(msg);
108  request->setControlInfo(controlInfo);
109  send(request, "sendOut");
110 }
Definition: EchoPacket_m.h:52
Definition: IPProtocolId_m.h:77
PingMap pingMap
Definition: EchoProtocol.h:36

Member Data Documentation

PingMap inet::EchoProtocol::pingMap
protected

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