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

Consumes and prints packets received from the IP module. More...

#include <IPvXTrafSink.h>

Inheritance diagram for inet::IPvXTrafSink:
inet::ILifecycle

Protected Member Functions

virtual void printPacket (cPacket *msg)
 
virtual void processPacket (cPacket *msg)
 
virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void refreshDisplay () const override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Protected Attributes

int numReceived
 
bool isOperational
 

Static Protected Attributes

static simsignal_t rcvdPkSignal = registerSignal("rcvdPk")
 

Additional Inherited Members

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

Detailed Description

Consumes and prints packets received from the IP module.

See NED for more info.

Member Function Documentation

void inet::IPvXTrafSink::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
52 {
53  if (!isOperational) {
54  EV_ERROR << "Module is down, received " << msg->getName() << " message dropped\n";
55  delete msg;
56  return;
57  }
58  processPacket(check_and_cast<cPacket *>(msg));
59 }
bool isOperational
Definition: IPvXTrafSink.h:37
virtual void processPacket(cPacket *msg)
Definition: IPvXTrafSink.cc:102
bool inet::IPvXTrafSink::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

69 {
70  Enter_Method_Silent();
71  if (dynamic_cast<NodeStartOperation *>(operation))
72  isOperational = true;
73  else if (dynamic_cast<NodeShutdownOperation *>(operation))
74  isOperational = false;
75  else if (dynamic_cast<NodeCrashOperation *>(operation))
76  isOperational = false;
77  else
78  throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName());
79  return true;
80 }
bool isOperational
Definition: IPvXTrafSink.h:37
void inet::IPvXTrafSink::initialize ( int  stage)
overrideprotectedvirtual
34 {
35  cSimpleModule::initialize(stage);
36 
37  if (stage == INITSTAGE_LOCAL) {
38  numReceived = 0;
39  WATCH(numReceived);
40  }
41  else if (stage == INITSTAGE_APPLICATION_LAYER) {
42  int protocol = par("protocol");
43  IPSocket ipSocket(gate("ipOut"));
44  ipSocket.registerProtocol(protocol);
45 
46  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
47  isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
48  }
49 }
int numReceived
Definition: IPvXTrafSink.h:36
uint8_t protocol
Definition: TCP_NSC.cc:88
bool isOperational
Definition: IPvXTrafSink.h:37
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
Initialization of applications.
Definition: InitStages.h:106
Definition: NodeStatus.h:40
virtual int inet::IPvXTrafSink::numInitStages ( ) const
inlineoverrideprotectedvirtual
45 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::IPvXTrafSink::printPacket ( cPacket *  msg)
protectedvirtual

Referenced by processPacket().

83 {
84  L3Address src, dest;
85  int protocol = -1;
86 
87  INetworkProtocolControlInfo *ctrl = dynamic_cast<INetworkProtocolControlInfo *>(msg->getControlInfo());
88 
89  if (ctrl != nullptr) {
90  src = ctrl->getSourceAddress();
91  dest = ctrl->getDestinationAddress();
92  protocol = ctrl->getTransportProtocol();
93  }
94 
95  EV_INFO << msg << endl;
96  EV_INFO << "Payload length: " << msg->getByteLength() << " bytes" << endl;
97 
98  if (ctrl != nullptr)
99  EV_INFO << "src: " << src << " dest: " << dest << " protocol=" << protocol << endl;
100 }
uint8_t protocol
Definition: TCP_NSC.cc:88
void inet::IPvXTrafSink::processPacket ( cPacket *  msg)
protectedvirtual

Referenced by handleMessage().

103 {
104  emit(rcvdPkSignal, msg);
105  EV_INFO << "Received packet: ";
106  printPacket(msg);
107  delete msg;
108  numReceived++;
109 }
int numReceived
Definition: IPvXTrafSink.h:36
static simsignal_t rcvdPkSignal
Definition: IPvXTrafSink.h:38
virtual void printPacket(cPacket *msg)
Definition: IPvXTrafSink.cc:82
void inet::IPvXTrafSink::refreshDisplay ( ) const
overrideprotectedvirtual
62 {
63  char buf[32];
64  sprintf(buf, "rcvd: %d pks", numReceived);
65  getDisplayString().setTagArg("t", 0, buf);
66 }
int numReceived
Definition: IPvXTrafSink.h:36

Member Data Documentation

bool inet::IPvXTrafSink::isOperational
protected
int inet::IPvXTrafSink::numReceived
protected
simsignal_t inet::IPvXTrafSink::rcvdPkSignal = registerSignal("rcvdPk")
staticprotected

Referenced by processPacket().


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