Search code examples
c++wifisimulatorns-3

Accessing WiFiPhy from a recevied callback in NS3


I want to access the WiFiPhy inside the reception callback of NetDevice with signature.

typedef Callback< bool, Ptr<NetDevice>, Ptr<const Packet>, uint16_t, const Address & > ReceiveCallback;

Inside the callback, i'm the the casting the NetDevice to WiFiDevice like to WiFiPhy functions.

Ptr<WifiNetDevice> wifiNetDevice = DynamicCast<WifiNetDevice>(device);
Ptr<WifiPhy> wifiPhyDev = wifiNetDevice->GetPhy();

But I am getting a segmentation fault during the run ? What actually im doing wrong here?

Thanks


Solution

  • Ok i found it.. when you create a NetDeviceContainer the object is of type NetDevice which does not have any WifiPhy. The solution is to DynamicCast it into WifiNetDevice and send the frame.

    Ptr<WifiNetDevice> wifiNetDevice = DynamicCast<WifiNetDevice>(netDevice);