Search code examples
omnet++inet

How to decapsulate a packet to get the UDPBasicApp's packet name in AODVRouting.CC?


I'm currently simulating AODV routing and quite confused with the packet encapsulation/decapsulation. In UDPBasicAPP.CC, there is a variable called packetName to define a packet's name(define from INI file)

void UDPBasicApp::initialize(int stage)
{
packetName = par("packetName");
}

So once the packet passed through AODVRouting.CC, it has been encapsulated:

 void AODVRouting::receiveSignal(cComponent *source, simsignal_t signalID, cObject *obj, cObject *details)
{
cPacket *frame = check_and_cast<cPacket *>(obj);
datagram = dynamic_cast<INetworkDatagram *>(frame->getEncapsulatedPacket());
}

I wanted to decapsulate the packet again in order to retrieve the packetName value mentioned above. The code is as follows:

UDPPacket *testData  = check_and_cast<UDPPacket *>(frame->decapsulate());

However, I find that UDPPacket class doesn't have any functions to access/retrieve the packetName value after the packet is decapsulated. I'm not sure what other class that could have provided such function. I need to get the packetName to manipulate some data in AODVRouting.CC. Please enlighten me, thank you.


Solution

  • The parameter packetName is used for creating the name of a payload. Look at UDPBasicApp::sendPacket():

    void UDPBasicApp::sendPacket()
    {
        std::ostringstream str;
        str << packetName << "-" << numSent;
        ApplicationPacket *payload = new ApplicationPacket(str.str().c_str());
        // ...
    

    In order to obtain the name of received packet or message one can use getName() method.