Search code examples
c++omnet++mac-addressinetdata-link-layer

OMNET++: How to obtain frame's source MAC Address in INET 4.0?


I am using INET Framework 4.0 with OMNET++. I have customised my Ieee80211ScalarRadio module to read signal power and source MAC Address of the beacons received from various APs in my AdhocHost.
Here is my custom CIeee80211ScalarRadio.ned file:

import inet.physicallayer.ieee80211.packetlevel.Ieee80211ScalarRadio;

module CIeee80211ScalarRadio extends Ieee80211ScalarRadio
{
    @class(inet::physicallayer::CIeee80211ScalarRadio);
}

And here is the corresponding CIeee80211ScalarRadio.cc file:

#include "inet/physicallayer/ieee80211/packetlevel/Ieee80211Radio.h"
#include "inet/physicallayer/common/packetlevel/SignalTag_m.h"
#include "inet/linklayer/common/MacAddressTag_m.h"


#include <omnetpp.h>
#include <string>

#include <cmath>
#include <iostream>

namespace inet{
namespace physicallayer{
class CIeee80211ScalarRadio : public Ieee80211Radio{
protected:
   virtual void sendUp(Packet *macFrame) override;
};

Define_Module(CIeee80211ScalarRadio);

void CIeee80211ScalarRadio::sendUp(Packet *macFrame)
{
    if (macFrame->findTag<SignalPowerInd>() != nullptr) {
           auto signalPowerInd = macFrame->getTag<SignalPowerInd>();
           auto rxPower = signalPowerInd->getPower().get();
           double pdBm = 10*log10(rxPower)+30;
           EV_INFO << "RX power = " << pdBm << " dBm" << endl;
    }
    if(macFrame->findTag<MacAddress>() != nullptr){
        auto macAddress = macFrame->getTag<MacAddress>();
        EV_INFO << "Mac Address = " << macAddress << endl;
    }

    Radio::sendUp(macFrame);
}
}//namespace physicallayer
}//namespace inet

As you can see, I am overriding Ieee80211ScalarRadio's sendUp() method to obtain the values I want from the macFrame.
I can extract the RxPower successfully, however, when I do the same thing for MacAddress, I get the following compiler error in INET's own source code:

../inet4/src/inet/common/packet/tag/TagSet.h:123:36: error: static_cast from 'std::__1::__vector_base<omnetpp::cObject *, std::__1::allocator<omnetpp::cObject *> >::value_type' (aka 'omnetpp::cObject *') to 'inet::MacAddress *', which are not related by inheritance, is not allowed

How can I get the MacAddress value without any error?


Solution

  • The proper name of tag which contains MAC address is MacAddressInd, not MacAddress. It is declared in MacAddressTag_m.h which you have included.

    EDIT
    Additional remark: the MacAddressInd contains two addresses: source and destination. So you should precise which one you want to obtain, for example:

    auto macAddress = macFrame->getTag<MacAddressInd>()->getSrcAddress();