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?

CKE
  • 1,533
  • 19
  • 18
  • 29
Farzan Badakhshan
  • 373
  • 1
  • 5
  • 19

1 Answers1

1

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();
Jerzy D.
  • 6,707
  • 2
  • 16
  • 22
  • Thanks, the error has gone now, however, this doesn't work either. The `if` condition is false. That is, the `MacAddressInd` tag cannot be found. – Farzan Badakhshan Jul 18 '18 at 20:24
  • 1
    It is because the radio layer does not look for a MAC address in received frame. The **MAC layer** recognizes the addresses. Try to run any `IEEE 802.11` example form `INET` and look at packets that are interchanged between these layers using object inspector. – Jerzy D. Jul 18 '18 at 21:06