|
INET Framework for OMNeT++/OMNEST
|
Generates ping requests and calculates the packet loss and round trip parameters of the replies.
More...
#include <PingApp.h>
|
| virtual void | initialize (int stage) override |
| |
| virtual int | numInitStages () const override |
| |
| virtual void | handleMessageWhenUp (cMessage *msg) override |
| |
| virtual void | handleSelfMessage (cMessage *msg) |
| |
| virtual void | finish () override |
| |
| virtual void | refreshDisplay () const override |
| |
| virtual void | parseDestAddressesPar () |
| |
| virtual void | startSendingPingRequests () |
| |
| virtual void | scheduleNextPingRequest (simtime_t previous, bool withSleep) |
| |
| virtual void | cancelNextPingRequest () |
| |
| virtual bool | isEnabled () |
| |
| virtual std::vector< L3Address > | getAllAddresses () |
| |
| virtual void | sendPingRequest () |
| |
| virtual void | processPingResponse (int identifier, int seqNumber, Packet *packet) |
| |
| virtual void | countPingResponse (int bytes, long seqNo, simtime_t rtt, bool isDup) |
| |
| virtual void | handleStartOperation (LifecycleOperation *operation) override |
| |
| virtual void | handleStopOperation (LifecycleOperation *operation) override |
| |
| virtual void | handleCrashOperation (LifecycleOperation *operation) override |
| |
| virtual void | socketDataArrived (INetworkSocket *socket, Packet *packet) override |
| |
| virtual void | socketClosed (INetworkSocket *socket) override |
| |
| virtual bool | isInitializeStage (int stage) const override |
| |
| virtual bool | isModuleStartStage (int stage) const override |
| |
| virtual bool | isModuleStopStage (int stage) const override |
| |
| 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 () |
| |
Generates ping requests and calculates the packet loss and round trip parameters of the replies.
See NED file for detailed description of operation.
◆ PingApp()
| inet::PingApp::PingApp |
( |
| ) |
|
◆ ~PingApp()
| inet::PingApp::~PingApp |
( |
| ) |
|
|
virtual |
71 cancelAndDelete(
timer);
◆ cancelNextPingRequest()
| void inet::PingApp::cancelNextPingRequest |
( |
| ) |
|
|
protectedvirtual |
◆ countPingResponse()
| void inet::PingApp::countPingResponse |
( |
int |
bytes, |
|
|
long |
seqNo, |
|
|
simtime_t |
rtt, |
|
|
bool |
isDup |
|
) |
| |
|
protectedvirtual |
486 EV_INFO <<
"Ping reply #" << seqNo <<
" arrived, rtt=" << (rtt == SIMTIME_ZERO ?
"unknown" : rtt.str().c_str()) << (isDup ?
", duplicated" :
"") <<
"\n";
495 if (rtt > SIMTIME_ZERO && !isDup) {
505 EV_DETAIL <<
"Jump in seq numbers, assuming pings since #" <<
expectedReplySeqNo <<
" got lost\n";
518 EV_DETAIL <<
"Arrived out of order (too late)\n";
520 if (!isDup && rtt > SIMTIME_ZERO)
Referenced by processPingResponse().
◆ finish()
| void inet::PingApp::finish |
( |
| ) |
|
|
overrideprotectedvirtual |
568 EV_DETAIL << getFullPath() <<
": No pings sent, skipping recording statistics and printing results.\n";
580 cout <<
"--------------------------------------------------------" << endl;
581 cout <<
"\t" << getFullPath() << endl;
582 cout <<
"--------------------------------------------------------" << endl;
585 cout <<
"round-trip min/avg/max (ms): " << (
rttStat.getMin() * 1000.0) <<
"/"
586 << (
rttStat.getMean() * 1000.0) <<
"/" << (
rttStat.getMax() * 1000.0) << endl;
587 cout <<
"stddev (ms): " << (
rttStat.getStddev() * 1000.0) <<
" variance:" <<
rttStat.getVariance() << endl;
588 cout <<
"--------------------------------------------------------" << endl;
◆ getAllAddresses()
| std::vector< L3Address > inet::PingApp::getAllAddresses |
( |
| ) |
|
|
protectedvirtual |
529 std::vector<L3Address> result;
531 int lastId = getSimulation()->getLastComponentId();
533 for (
int i = 0; i <= lastId; i++) {
534 IInterfaceTable *ift =
dynamic_cast<IInterfaceTable *
>(getSimulation()->getModule(i));
536 for (
int j = 0; j < ift->getNumInterfaces(); j++) {
537 NetworkInterface *ie = ift->getInterface(j);
538 if (ie && !ie->isLoopback()) {
539 #ifdef INET_WITH_IPv4
540 auto ipv4Data = ie->findProtocolData<Ipv4InterfaceData>();
541 if (ipv4Data !=
nullptr) {
542 Ipv4Address address = ipv4Data->getIPAddress();
543 if (!address.isUnspecified())
544 result.push_back(L3Address(address));
546 #endif // ifdef INET_WITH_IPv4
547 #ifdef INET_WITH_IPv6
548 auto ipv6Data = ie->findProtocolData<Ipv6InterfaceData>();
549 if (ipv6Data !=
nullptr) {
550 for (
int k = 0;
k < ipv6Data->getNumAddresses();
k++) {
551 Ipv6Address address = ipv6Data->getAddress(
k);
552 if (!address.isUnspecified() && address.isGlobal())
553 result.push_back(L3Address(address));
556 #endif // ifdef INET_WITH_IPv6
Referenced by parseDestAddressesPar().
◆ getPid()
| int inet::PingApp::getPid |
( |
| ) |
const |
|
inline |
◆ handleCrashOperation()
◆ handleMessageWhenUp()
| void inet::PingApp::handleMessageWhenUp |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
Implements inet::OperationalMixin< cSimpleModule >.
212 if (msg->isSelfMessage())
217 socket->processMessage(msg);
219 throw cRuntimeError(
"Unaccepted message: %s(%s)", msg->getName(), msg->getClassName());
◆ handleSelfMessage()
| void inet::PingApp::handleSelfMessage |
( |
cMessage * |
msg | ) |
|
|
protectedvirtual |
144 srcAddr = L3AddressResolver().resolve(par(
"srcAddr"));
159 const Protocol *networkProtocol =
nullptr;
160 const char *networkProtocolAsString = par(
"networkProtocol");
161 if (*networkProtocolAsString)
172 const Protocol *icmp =
l3Echo.at(networkProtocol);
175 socket.second->close();
183 currentSocket =
new L3Socket(networkProtocol, gate(
"socketOut"));
190 ASSERT2(msg->getKind() ==
PING_SEND,
"Unknown kind in self message.");
Referenced by handleMessageWhenUp().
◆ handleStartOperation()
◆ handleStopOperation()
◆ initialize()
| void inet::PingApp::initialize |
( |
int |
stage | ) |
|
|
overrideprotectedvirtual |
◆ isEnabled()
| bool inet::PingApp::isEnabled |
( |
| ) |
|
|
protectedvirtual |
◆ numInitStages()
| virtual int inet::PingApp::numInitStages |
( |
| ) |
const |
|
inlineoverrideprotectedvirtual |
◆ parseDestAddressesPar()
| void inet::PingApp::parseDestAddressesPar |
( |
| ) |
|
|
protectedvirtual |
125 srcAddr = L3AddressResolver().resolve(par(
"srcAddr"));
126 const char *destAddrs = par(
"destAddr");
127 if (!strcmp(destAddrs,
"*")) {
131 cStringTokenizer tokenizer(destAddrs);
134 while ((token = tokenizer.nextToken()) !=
nullptr) {
135 L3Address addr = L3AddressResolver().resolve(token);
Referenced by handleSelfMessage().
◆ processPingResponse()
| void inet::PingApp::processPingResponse |
( |
int |
identifier, |
|
|
int |
seqNumber, |
|
|
Packet * |
packet |
|
) |
| |
|
protectedvirtual |
447 const auto& pingPayload = packet->peekDataAt(
B(0), packet->getDataLength());
448 if (originatorId !=
pid) {
449 EV_WARN <<
"Received response was not sent by this application, dropping packet\n";
454 L3Address src = packet->getTag<
L3AddressInd>()->getSrcAddress();
456 auto& msgHopCountTag = packet->findTag<HopLimitInd>();
457 int msgHopCount = msgHopCountTag ? msgHopCountTag->getHopLimit() : -1;
463 simtime_t rtt = SIMTIME_ZERO;
473 cout << getFullPath() <<
": reply of " << packet->getByteLength()
474 <<
" bytes from " << src
475 <<
" icmp_seq=" << seqNo <<
" ttl=" << msgHopCount
476 <<
" time=" << (rtt * 1000) <<
" msec"
477 <<
" (" << packet->getName() <<
")" << endl;
Referenced by socketDataArrived().
◆ refreshDisplay()
| void inet::PingApp::refreshDisplay |
( |
| ) |
const |
|
overrideprotectedvirtual |
286 getDisplayString().setTagArg(
"t", 0, buf);
◆ scheduleNextPingRequest()
| void inet::PingApp::scheduleNextPingRequest |
( |
simtime_t |
previous, |
|
|
bool |
withSleep |
|
) |
| |
|
protectedvirtual |
◆ sendPingRequest()
| void inet::PingApp::sendPingRequest |
( |
| ) |
|
|
protectedvirtual |
375 Packet *outPacket =
new Packet(name);
376 auto payload = makeShared<ByteCountChunk>(
B(
packetSize));
380 #ifdef INET_WITH_IPv4
381 const auto& request = makeShared<IcmpEchoRequest>();
382 request->setIdentifier(
pid);
384 outPacket->insertAtBack(payload);
386 outPacket->insertAtFront(request);
390 throw cRuntimeError(
"INET compiled without Ipv4");
394 #ifdef INET_WITH_IPv6
395 const auto& request = makeShared<Icmpv6EchoRequestMsg>();
396 request->setIdentifier(
pid);
398 outPacket->insertAtBack(payload);
400 outPacket->insertAtFront(request);
404 throw cRuntimeError(
"INET compiled without Ipv6");
409 #ifdef INET_WITH_NEXTHOP
410 const auto& request = makeShared<EchoPacket>();
411 request->setChunkLength(
B(8));
413 request->setIdentifier(
pid);
415 outPacket->insertAtBack(payload);
417 outPacket->insertAtFront(request);
421 throw cRuntimeError(
"INET compiled without Next Hop Forwarding");
425 throw cRuntimeError(
"Unaccepted destination address type: %d (address: %s)", (
int)
destAddr.
getType(),
destAddr.
str().c_str());
428 auto addressReq = outPacket->addTag<L3AddressReq>();
429 addressReq->setSrcAddress(
srcAddr);
430 addressReq->setDestAddress(
destAddr);
433 EV_INFO <<
"Sending ping request #" <<
sendSeqNo <<
" to lower layer.\n";
Referenced by handleSelfMessage().
◆ socketClosed()
◆ socketDataArrived()
Implements inet::INetworkSocket::ICallback.
227 #ifdef INET_WITH_IPv4
229 const auto& icmpHeader = packet->popAtFront<IcmpHeader>();
231 const auto& echoReply =
CHK(dynamicPtrCast<const IcmpEchoReply>(icmpHeader));
241 #ifdef INET_WITH_IPv6
243 const auto& icmpHeader = packet->popAtFront<Icmpv6Header>();
245 const auto& echoReply =
CHK(dynamicPtrCast<const Icmpv6EchoReplyMsg>(icmpHeader));
255 #ifdef INET_WITH_NEXTHOP
257 const auto& icmpHeader = packet->popAtFront<EchoPacket>();
269 throw cRuntimeError(
"Unaccepted packet: %s(%s)", packet->getName(), packet->getClassName());
◆ startSendingPingRequests()
| void inet::PingApp::startSendingPingRequests |
( |
| ) |
|
|
protectedvirtual |
◆ continuous
| bool inet::PingApp::continuous = false |
|
protected |
◆ count
| int inet::PingApp::count = 0 |
|
protected |
◆ crcMode
◆ currentSocket
◆ destAddr
◆ destAddresses
| std::vector<L3Address> inet::PingApp::destAddresses |
|
protected |
◆ destAddrIdx
| int inet::PingApp::destAddrIdx = -1 |
|
protected |
◆ expectedReplySeqNo
| long inet::PingApp::expectedReplySeqNo = 0 |
|
protected |
◆ hopLimit
| int inet::PingApp::hopLimit = 0 |
|
protected |
◆ l3Echo
◆ lastStart
| simtime_t inet::PingApp::lastStart |
|
protected |
◆ lossCount
| long inet::PingApp::lossCount = 0 |
|
protected |
◆ nodeStatus
◆ numDuplicatedPongs
| long inet::PingApp::numDuplicatedPongs = 0 |
|
protected |
◆ numLostSignal
| simsignal_t inet::PingApp::numLostSignal = registerSignal("numLost") |
|
staticprotected |
◆ numOutOfOrderArrivalsSignal
| simsignal_t inet::PingApp::numOutOfOrderArrivalsSignal = registerSignal("numOutOfOrderArrivals") |
|
staticprotected |
◆ numPongs
| long inet::PingApp::numPongs = 0 |
|
protected |
◆ outOfOrderArrivalCount
| long inet::PingApp::outOfOrderArrivalCount = 0 |
|
protected |
◆ packetSize
| int inet::PingApp::packetSize = 0 |
|
protected |
◆ pid
| int inet::PingApp::pid = 0 |
|
protected |
◆ pingRxSeqSignal
| simsignal_t inet::PingApp::pingRxSeqSignal = registerSignal("pingRxSeq") |
|
staticprotected |
◆ pingTxSeqSignal
| simsignal_t inet::PingApp::pingTxSeqSignal = registerSignal("pingTxSeq") |
|
staticprotected |
◆ pongReceived
◆ printPing
| bool inet::PingApp::printPing = false |
|
protected |
◆ rttSignal
| simsignal_t inet::PingApp::rttSignal = registerSignal("rtt") |
|
staticprotected |
◆ rttStat
| cStdDev inet::PingApp::rttStat |
|
protected |
◆ sendIntervalPar
| cPar* inet::PingApp::sendIntervalPar = nullptr |
|
protected |
◆ sendSeqNo
| long inet::PingApp::sendSeqNo = 0 |
|
protected |
◆ sendTimeHistory
◆ sentCount
| long inet::PingApp::sentCount = 0 |
|
protected |
◆ sleepDurationPar
| cPar* inet::PingApp::sleepDurationPar = nullptr |
|
protected |
◆ socketMap
◆ srcAddr
◆ startTime
| simtime_t inet::PingApp::startTime |
|
protected |
◆ stopTime
| simtime_t inet::PingApp::stopTime |
|
protected |
◆ timer
| cMessage* inet::PingApp::timer = nullptr |
|
protected |
The documentation for this class was generated from the following files:
#define CHK(x)
Definition: INETDefs.h:87
@ MODULEID
Definition: L3Address.h:40
@ ECHO_PROTOCOL_REQUEST
Definition: EchoPacket_m.h:58
static void insertCrc(CrcMode crcMode, const Ptr< Icmpv6Header > &icmpHeader, Packet *packet)
Definition: Icmpv6.cc:333
cStdDev rttStat
Definition: PingApp.h:66
State operationalState
Definition: OperationalMixin.h:23
@ PING_CHANGE_ADDR
Definition: PingApp_m.h:54
long numDuplicatedPongs
Definition: PingApp.h:76
simtime_t lastStart
Definition: PingApp.h:57
static const Protocol ipv4
Definition: Protocol.h:93
virtual void parseDestAddressesPar()
Definition: PingApp.cc:123
static const Protocol * getProtocol(int id)
Definition: Protocol.cc:50
static const Protocol ipv6
Definition: Protocol.h:94
virtual void close()=0
Closes this socket releasing all resources.
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
static const Protocol icmpv4
Definition: Protocol.h:71
virtual void startSendingPingRequests()
Definition: PingApp.cc:295
long expectedReplySeqNo
Definition: PingApp.h:59
std::string str() const
Definition: L3Address.cc:88
L3Address destAddr
Definition: PingApp.h:36
static void insertCrc(CrcMode crcMode, const Ptr< IcmpHeader > &icmpHeader, Packet *payload)
Definition: Icmp.cc:351
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
cPar * sleepDurationPar
Definition: PingApp.h:41
CrcMode parseCrcMode(const char *crcModeString, bool allowDisable)
Definition: CrcMode.cc:14
void deleteSockets()
Deletes the socket objects.
Definition: SocketMap.cc:44
long lossCount
Definition: PingApp.h:73
@ PING_SEND
Definition: PingApp_m.h:55
int hopLimit
Definition: PingApp.h:42
virtual void send(Packet *packet)=0
static const Protocol nextHopForwarding
Definition: Protocol.h:128
@ IPv4
Definition: L3Address.h:35
@ MODULEPATH
Definition: L3Address.h:39
static simsignal_t numOutOfOrderArrivalsSignal
Definition: PingApp.h:69
bool pongReceived[PING_HISTORY_SIZE]
Definition: PingApp.h:61
bool isUnspecified() const
Definition: L3Address.cc:138
virtual void countPingResponse(int bytes, long seqNo, simtime_t rtt, bool isDup)
Definition: PingApp.cc:484
ISocket * findSocketFor(cMessage *msg)
Finds the socket for the given message.
Definition: SocketMap.cc:19
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
static simsignal_t pingRxSeqSignal
Definition: PingApp.h:71
static simsignal_t numLostSignal
Definition: PingApp.h:68
void addSocket(ISocket *socket)
Adds the given socket.
Definition: SocketMap.cc:28
intscale< b, 1, 8 > B
Definition: Units.h:1168
virtual void processPingResponse(int identifier, int seqNumber, Packet *packet)
Definition: PingApp.cc:445
@ ICMPv6_ECHO_REPLY
Definition: Icmpv6Header_m.h:90
virtual void handleSelfMessage(cMessage *msg)
Definition: PingApp.cc:141
simtime_t startTime
Definition: PingApp.h:45
unsigned int size() const
Returns the number of sockets stored.
Definition: SocketMap.h:52
INetworkSocket * currentSocket
Definition: PingApp.h:53
std::map< int, ISocket * > & getMap()
Returns the socket map.
Definition: SocketMap.h:57
simtime_t sendTimeHistory[PING_HISTORY_SIZE]
Definition: PingApp.h:60
removed HopLimitReq
Definition: IUdp-gates.txt:11
int destAddrIdx
Definition: PingApp.h:44
long numPongs
Definition: PingApp.h:75
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
virtual std::vector< L3Address > getAllAddresses()
Definition: PingApp.cc:527
static const char * getTypeName(AddressType t)
Definition: L3Address.cc:389
@ PING_FIRST_ADDR
Definition: PingApp_m.h:53
cMessage * timer
Definition: PingApp.h:55
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
long outOfOrderArrivalCount
Definition: PingApp.h:74
const double k
Definition: Qam1024Modulation.cc:14
long sendSeqNo
Definition: PingApp.h:58
simtime_t stopTime
Definition: PingApp.h:46
int count
Definition: PingApp.h:43
@ IPv6
Definition: L3Address.h:36
static const Protocol icmpv6
Definition: Protocol.h:72
@ ECHO_PROTOCOL_REPLY
Definition: EchoPacket_m.h:59
virtual void delayActiveOperationFinish(simtime_t timeout)
Definition: OperationalMixinImpl.h:161
virtual void startActiveOperationExtraTimeOrFinish(simtime_t extraTime)
Definition: OperationalMixinImpl.h:179
static simsignal_t pingTxSeqSignal
Definition: PingApp.h:70
CrcMode crcMode
Definition: PingApp.h:47
L3Address srcAddr
Definition: PingApp.h:37
virtual void cancelNextPingRequest()
Definition: PingApp.cc:358
static const std::map< const Protocol *, const Protocol * > l3Echo
Definition: PingApp.h:63
virtual void scheduleNextPingRequest(simtime_t previous, bool withSleep)
Definition: PingApp.cc:344
SocketMap socketMap
Definition: PingApp.h:52
virtual void sendPingRequest()
Definition: PingApp.cc:368
static simsignal_t rttSignal
Definition: PingApp.h:67
int pid
Definition: PingApp.h:54
bool printPing
Definition: PingApp.h:48
virtual void destroy()=0
Notify the protocol that the owner of ISocket has destroyed the socket.
bool continuous
Definition: PingApp.h:49
AddressType getType() const
Definition: L3Address.cc:51
virtual void refreshDisplay() const override
Definition: OperationalMixinImpl.h:200
int packetSize
Definition: PingApp.h:39
cPar * sendIntervalPar
Definition: PingApp.h:40
virtual void bind(const Protocol *protocol, L3Address localAddress)=0
Binds this socket to the given protocol and local address.
virtual void setCallback(ICallback *callback)=0
Sets a callback object, to be used with processMessage().
ISocket * removeSocket(ISocket *socket)
Removes the given socket.
Definition: SocketMap.cc:34
#define PING_HISTORY_SIZE
Definition: PingApp.h:24
@ ICMP_ECHO_REPLY
Definition: IcmpHeader_m.h:85
std::vector< L3Address > destAddresses
Definition: PingApp.h:38
long sentCount
Definition: PingApp.h:72
virtual bool isEnabled()
Definition: PingApp.cc:363
static const Protocol echo
Definition: Protocol.h:125