How to change YansWifiPhy transmission power level during runtime?

1,145 views
Skip to first unread message

Frank Zou

unread,
Feb 23, 2016, 7:58:34 AM2/23/16
to ns-3-users
Hi, everyone!
    I'm getting a problem of changing YansWifiPhy power level during runtime. According to the NS-3 API, I use helper to construct wifi, phy-layer, channel, mac. And I set the TxLevels as two. 

  WifiHelper wifi = WifiHelper::Default();

  wifi.SetStandard(WIFI_PHY_STANDARD_80211a);
  wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode",
                               StringValue("OfdmRate24Mbps"));

  YansWifiChannelHelper wifiChannel; // = YansWifiChannelHelper::Default ();
  wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
  wifiChannel.AddPropagationLoss("ns3::ThreeLogDistancePropagationLossModel");
  wifiChannel.AddPropagationLoss("ns3::NakagamiPropagationLossModel");

  YansWifiPhyHelper wifiPhyHelper = YansWifiPhyHelper::Default();
  wifiPhyHelper.SetChannel(wifiChannel.Create());
  wifiPhyHelper.Set("TxPowerLevels",UintegerValue(2));
  wifiPhyHelper.Set("TxPowerStart", DoubleValue(10));
  wifiPhyHelper.Set("TxPowerEnd", DoubleValue(20));

  NqosWifiMacHelper wifiMacHelper = NqosWifiMacHelper::Default();
  wifiMacHelper.SetType("ns3::AdhocWifiMac");


My scenario is a simple. Two nodes, distance is 200 meters.(Under which setting, with 10 dBm power level, two nodes can't get connected, while with 20 dBm power level, two nodes can be connected.)

But I do not see any difference between this setting and only one power level(10dBm). I tried to follow the code and find that in member function SendPacket of class YansWifiPhy, method GetTxPowerLevel () of class WifiTxVector is used to get transmission power level. Is it possible to change transmission power level through SetTxPowerLevel of class WifiTxVector? How can i get instance of this class? Or other ways to change transmission power level?

Frank Zou

unread,
Feb 24, 2016, 4:01:13 AM2/24/16
to ns-3-users
Hi, everyone!
    After studying ns-3 examples/wireless/power-adaptation-distance.cc, I found these code helpful.

  NetDeviceContainer aps;
  Ptr<NetDevice> device = aps.Get (0);
  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
  Ptr<WifiPhy> phy = wifiDevice->GetPhy ();

 These code get wifiDevice through DynamicCast method, which converts a pointer of base class NetDevice to its subclass WifiNetDevice.
 So I tried the similar way in my code.

  Ptr<NetDevice> device = wifiNetDevices.Get(i);
  Ptr<WifiNetDevice> wifiDevice = DynamicCast<WifiNetDevice> (device);
  Ptr<YansWifiPhy> phy = DynamicCast<YansWifiPhy>(wifiDevice->GetPhy());
  phy->SetTxPowerStart(20);
  phy->SetTxPowerEnd(20);

 And this works for me. It does change the Tx power. 
 To change the transmission power during runtime, these code could be encapsulated as a function scheduled by Simulator::Schedule.

--------------------------------------------------------------------------------------------------------------

 Although it's not a solution of what I proposed before, it can do the similar work. Hope for properer solutions !

Best regards,
Frank 

在 2016年2月23日星期二 UTC+8下午8:58:34,Frank Zou写道:

Tommaso Pecorella

unread,
Feb 24, 2016, 4:15:47 AM2/24/16
to ns-3-users
Hi,

perhaps you should look at stuff like AparfWifiManager. The Constant one is constant in the true sense of terms. Just check the code before doing experiments.

T.

Frank Zou

unread,
Feb 24, 2016, 4:43:34 AM2/24/16
to ns-3-users
Thanks very much for your suggestion ! I will go through it.

Best regards,
Frank

在 2016年2月24日星期三 UTC+8下午5:15:47,Tommaso Pecorella写道:

Hadi Samani

unread,
Jun 7, 2016, 4:31:12 PM6/7/16
to ns-3-users
Hello Frank,

I have the same problem, I set the Txpower to -100000 dbm but my receiver gets also the udp packets. If your problem is solved. Would you please send me your code?
I did what you said, but I have still peoblem with it.
Br
Hadi
Hadi...@gmail.com

Rajkumar S

unread,
Jul 7, 2016, 2:12:59 AM7/7/16
to ns-3-users
Hi Frank , I went through this example code
https://www.nsnam.org/doxygen/power-adaptation-distance_8cc_source.html , for changing the power at run time,
I still doubt if its really getting changed, can you please help.
I am trying to simulate SoftAP or Mobile Hotspot , So in this case I would like to collect the Power usage by the AP and nothing much about the clients.

Thanks
Raj kumar
Reply all
Reply to author
Forward
0 new messages