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

TODO. More...

#include <EchoProtocol.h>

Inheritance diagram for inet::EchoProtocol:

Protected Member Functions

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

Detailed Description

TODO.

Member Function Documentation

◆ handleMessage()

void inet::EchoProtocol::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
30 {
31  cGate *arrivalGate = msg->getArrivalGate();
32  if (!strcmp(arrivalGate->getName(), "ipIn"))
33  processPacket(check_and_cast<Packet *>(msg));
34 }

◆ initialize()

void inet::EchoProtocol::initialize ( int  stage)
overrideprotectedvirtual
22 {
23  cSimpleModule::initialize(stage);
24  if (stage == INITSTAGE_NETWORK_LAYER) {
25  registerProtocol(Protocol::echo, gate("ipOut"), gate("ipIn"));
26  }
27 }

◆ numInitStages()

virtual int inet::EchoProtocol::numInitStages ( ) const
inlineoverrideprotectedvirtual
28 { return NUM_INIT_STAGES; }

◆ processEchoReply()

void inet::EchoProtocol::processEchoReply ( Packet packet)
protectedvirtual
80 {
81  delete reply;
82 }

Referenced by processPacket().

◆ processEchoRequest()

void inet::EchoProtocol::processEchoRequest ( Packet packet)
protectedvirtual
54 {
55  // turn request into a reply
56  const auto& echoReq = request->popAtFront<EchoPacket>();
57  Packet *reply = new Packet((std::string(request->getName()) + "-reply").c_str());
58  const auto& echoReply = makeShared<EchoPacket>();
59  echoReply->setChunkLength(echoReq->getChunkLength());
60  echoReply->setType(ECHO_PROTOCOL_REPLY);
61  echoReply->setIdentifier(echoReq->getIdentifier());
62  echoReply->setSeqNumber(echoReq->getSeqNumber());
63  reply->insertAtBack(echoReply);
64  reply->insertAtBack(request->peekData());
65  auto addressInd = request->getTag<L3AddressInd>();
66 
67  // swap src and dest
68  // TODO check what to do if dest was multicast etc?
69  auto addressReq = reply->addTag<L3AddressReq>();
70  addressReq->setSrcAddress(addressInd->getDestAddress());
71  addressReq->setDestAddress(addressInd->getSrcAddress());
72 
73  reply->addTag<DispatchProtocolReq>()->setProtocol(request->getTag<NetworkProtocolInd>()->getProtocol());
74  reply->addTag<PacketProtocolTag>()->setProtocol(&Protocol::echo);
75  send(reply, "ipOut");
76  delete request;
77 }

Referenced by processPacket().

◆ processPacket()

void inet::EchoProtocol::processPacket ( Packet packet)
protectedvirtual
37 {
38  const auto& echoHdr = msg->peekAtFront<EchoPacket>();
39  switch (echoHdr->getType()) {
41  processEchoRequest(msg);
42  break;
43 
45  processEchoReply(msg);
46  break;
47 
48  default:
49  throw cRuntimeError("Unknown type %d", echoHdr->getType());
50  }
51 }

Referenced by handleMessage().


The documentation for this class was generated from the following files:
inet::ECHO_PROTOCOL_REQUEST
@ ECHO_PROTOCOL_REQUEST
Definition: EchoPacket_m.h:58
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
inet::INITSTAGE_NETWORK_LAYER
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
L3AddressInd
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
PacketProtocolTag
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
inet::EchoProtocol::processEchoReply
virtual void processEchoReply(Packet *packet)
Definition: EchoProtocol.cc:79
inet::EchoProtocol::processPacket
virtual void processPacket(Packet *packet)
Definition: EchoProtocol.cc:36
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::ECHO_PROTOCOL_REPLY
@ ECHO_PROTOCOL_REPLY
Definition: EchoPacket_m.h:59
inet::EchoProtocol::processEchoRequest
virtual void processEchoRequest(Packet *packet)
Definition: EchoProtocol.cc:53
inet::registerProtocol
void registerProtocol(const Protocol &protocol, cGate *gate, ServicePrimitive servicePrimitive)
Registers a protocol primitive (PDU processing) at the given gate.
Definition: IProtocolRegistrationListener.cc:83
inet::Protocol::echo
static const Protocol echo
Definition: Protocol.h:125