I need to construct an AODV network that exchanges UDP packets. One of its hosts should be able to replay the packet it receives, so I'm modifying udpBasicApp.cc
in omnet++
inet framework. I'm trying to refer to a particular host inside the class udpBasicApp
to specify a certain behavior for host[3] when it receives a packet.
e.g.:
if(host->getIndex()== 3)
{ //replay the received packet }
Apparently, I cannot refer to any element of my network in the previous simple matter. There's no function inside udpBasicApp.cc
that can get the index of the current host. I was advised to use hook mechanism to be able to access the index of the current host using the application: udpBasicApp
How to do this using hook mechanism?
Second related question, If I cannot refer to the host index inside udpBasicApp.cc
, how can I compare the IP address of the current host at least to the IP address I'm trying to refer to?
IPXAddress srcAddr;
if (srcAddr=="host[3]")
is not comparable as the error shows.
1.To obtain the index of a StandardHost
from vector you should refer to the parent module of udpApp
:
if (getParentModule()->getIndex() == 3) {
// ...
}
2.The IPv4 address of current host may be obtained using L3AddressResolver
class:
#include "inet/networklayer/common/L3AddressResolver.h"
// ...
L3Address layer3addr = L3AddressResolver().addressOf(getParentModule(),
L3AddressResolver::ADDR_IPv4);
IPv4Address ownaddr = layer3addr.toIPv4();