0

I have been modifying AODV protocol to add extra information in the data packet.GPSR option is a straightforward example so I created a class inherits from TlvOptionBase , set my variables & inserted it in the ipv4 header as mentioned in GPSR protocol.

Why can TlvOption cannot be found in the datagram

Here's a part of my code:

void Aodv::setCBFOptionOnNetworkDatagram(Packet *packet, const Ptr<const NetworkHeaderBase>& networkHeader, CBFOption *cbfOption)
{
    packet->trimFront();
    if (dynamicPtrCast<const Ipv4Header>(networkHeader)) {
        auto ipv4Header = removeNetworkProtocolHeader<Ipv4Header>(packet);
        cbfOption->setType(IPOPTION_TLV_GPSR);
        B oldHlen = ipv4Header->calculateHeaderByteLength();
        EV_INFO << "old header length "<<oldHlen << endl;
        ASSERT(ipv4Header->getHeaderLength() == oldHlen);
        ipv4Header->addOption(cbfOption);
        B newHlen = ipv4Header->calculateHeaderByteLength();
        EV_INFO << "new header length "<<newHlen << endl;
        ipv4Header->setHeaderLength(newHlen);
        ipv4Header->addChunkLength(newHlen - oldHlen);
        ipv4Header->setTotalLengthField(ipv4Header->getTotalLengthField() + newHlen - oldHlen);
        insertNetworkProtocolHeader(packet, Protocol::ipv4, ipv4Header);
    }
}

const CBFOption *Aodv::getCBFOptionFromNetworkDatagram(const Ptr<const NetworkHeaderBase>& networkHeader) const
{
    const CBFOption *cbfOption = findCBFOptionInNetworkDatagram(networkHeader);
    if (cbfOption == nullptr)
        throw cRuntimeError("Tlvoption not found in datagram");
    return cbfOption;
}

CBFOption *Aodv::findCBfOptionInNetworkDatagramForUpdate(const Ptr<NetworkHeaderBase>& networkHeader)
{
    CBFOption *cbfOption = nullptr;
if (auto ipv4Header = dynamicPtrCast<Ipv4Header>(networkHeader)) {
        cbfOption = check_and_cast_nullable<CBFOption *>(ipv4Header->findMutableOptionByType(IPOPTION_TLV_GPSR));
}   
 return cbfOption;
} 

INetfilter::IHook::Result Aodv::ensureRouteForDatagram(Packet *datagram)
{........
        CBFOption *cbfOption = createCBFOption(networkHeader->getDestinationAddress());
        setCBFOptionOnNetworkDatagram(datagram, networkHeader, cbfOption);
        auto cOption = const_cast<CBFOption *>(getCBFOptionFromNetworkDatagram(networkHeader));

I am using INET veins-5.1-i2

tlv options exists in packet structure After running debug mode enter image description here

Dalia Adly
  • 53
  • 6
  • Have you checked Using the GUI the packet structure after the Ipv4Header is added? It would be helpful to know other debugging steps you've taken. Have you run the simulation in debug mode? Is `ipv4Header` in `findAODVOption...` actually populated? – EdL Oct 06 '21 at 09:37
  • I checked the packet structure and ran the simulation in the debug mode and still don't know what is wrong? I added screenshots to my question – Dalia Adly Oct 23 '21 at 05:01
  • So, I can clearly see that it is being added correctly. You next need to step into the `TlvOptions::findByType()` in `TlvOptions.cc:58`. The `cOption` value in the second screenshot is not helpful because it is just initialized with random data since getCBFOptionFromNetworkDatagram has not returned yet. – EdL Oct 26 '21 at 09:01

0 Answers0