Changing a ChannelNumber of SpectrumWifiPhy with Simulator::Schedule

328 views
Skip to first unread message

Michael Rademacher

unread,
Mar 15, 2017, 12:38:26 PM3/15/17
to ns-3-users
Dear all, 

I am kind of stuck at the moment and any help is highly appreciated.
My goal is to set the ChannelNumber of a SpetrumWiFiPhy during the runtime of the simulation to dynamically react to changing interference conditions.
Since this is part of a larger project, I am working with snippets in the following. If a minimal example can be helpful, let me know. 

I am using SpectrumWifiPhy and the MultiModelSpectrumChannel.

....
SpectrumWifiPhyHelper spectrumPhy = SpectrumWifiPhyHelper::Default ();
Ptr<MultiModelSpectrumChannel> spectrumChannel = CreateObject<MultiModelSpectrumChannel> ();
spectrumPhy.SetChannel (spectrumChannel);
....

I setup my topology and (everything else) forming a multi-hop WiFi scenario with several nodes. 
I sort the devices for each link into separate NetDeviceContainer, for example called deviceslink0 for the first link.

I have implement the following function to change the channel on two particular WifiNetDevice's of a link:

void ChangeFrequencyLocal
(NetDeviceContainer deviceslink, uint16_t channel){
  for (uint32_t i = 0; i < deviceslink.GetN (); i++)
    {
      Ptr<WifiNetDevice> wifidevice = DynamicCast<WifiNetDevice> (deviceslink.Get(i));
      Ptr<SpectrumWifiPhy> phy0 = DynamicCast<SpectrumWifiPhy>(wifidevice->GetPhy());
      phy0->SetChannelNumber (channel);
      std::cout << "Changed Frequency to: " << channel << std::endl;
    }
}

If I call this function "normally" before the simulation starts:

ChangeFrequencyLocal(deviceslink0, 40);

everything is fine and the channels on that link are changed, really good. 

If I do the following:

Simulator::Schedule(Seconds(1), &ChangeFrequencyLocal, deviceslink0, 40);

I get the following assert:

assert failed. cond="m_spectrumModel == x.m_spectrumModel", file=../src/spectrum/model/spectrum-value.cc, line=170

I found the AddOperationalChannel function of the SpectrumWifiPhy class.
From the description, it seems to be relevant for WiFi roaming. So I added the desired channels. However, the same assert fires. 

I am on ns-3.26. 

With kind regards, 
Michael


Michael Rademacher

unread,
Mar 16, 2017, 7:05:45 AM3/16/17
to ns-3-users
I think I found a hint to the problem, in the description of the SpectrumValue class:

@warning the intended use if that sm points to a static object
   * which will be there for the whole simulation. This is reasonable
   * since the set of frequencies which are to be used in the
   * simulation is normally known before the simulation starts.

However, SpectrumWifiPhy provides a function SpectrumWifiPhy::DoChannelSwitch (uint16_t nch)

This function seems perfectly fine since at some point it conducts a channel switch like this:

m_rxSpectrumModel = WifiSpectrumValueHelper::GetSpectrumModel (GetFrequency (), GetChannelWidth ());

Did somebody successfully used this function during run-time of the simulation?
 

Tommaso Pecorella

unread,
Mar 16, 2017, 7:01:37 PM3/16/17
to ns-3-users
Hi,

I never tested it, but I guess that the problem is in the on-air packets.
By best guess is that the error comes from packets that are being received (i.e., in between StartRx and EndRx).

Mind that it is also possible that you found an use-case that is not yet possible to simulate. In this case, please add an enhancement request in our Bugzilla.
However... why don't you use SpectrumWifiPhy::DoChannelSwitch () ?

Cheers,

T.

Michael Rademacher

unread,
Mar 17, 2017, 9:28:19 AM3/17/17
to ns-3-users

Hi Tommasso,


Thanks for the answer. I further analyzed the source. Here is what I found out for future reference:


- The SpecrumWiFiPhy differentiates between the receiving and the transmitting channel

- For the receiving channel, there is an “adaptor” class called WifiSpectrumPhyInterface

- The problem is related to the receiving channel

- When the WiFi Device is created a dedicated spectrum model is created:

DEBUG_LOG: 0s 1 SpectrumWifiPhy:GetRxSpectrumModel(): Creating spectrum model from frequency/width pair of (5180, 20)”

- The set channel methods actually calls the SpectrumWifiPhy::DoChannelSwitch () which overwrites a dummy Method in WiFiPhy

- When calling it during run time, the channel switch on the devices is actually conducted:


DEBUG_LOG: 1s -1 SpectrumWifiPhy:DoChannelSwitch(): switching channel 36 -> 40

DEBUG_LOG: 1s -1 WifiPhy:SetChannelNumber(): Setting frequency to 5200; width to 20


- However there is no call to create a new receiving channel on the phy using the new frequency/width

- Therefore, the first attempt to receive on packet on that phy fails since since the spectrum model is not updated


cond="m_spectrumModel == x.m_spectrumModel"


I could try to find implement a fix for this by my own but I am a little afraid that this could be dead-end. I see two different possibilities:


- Creating a SpectrumModel before the start of the simulation for each desired frequency/width combination (computational ineffective, a work-around)

- Creating a new receiving spectrumModel during the channel switch. However, I really do not know if this is conceptional possible.


Perhaps somebody can comment on these two possible fixes? Any hints are more than appreciated


I will also look into the Bugzilla. 


With kind regards,

Michael

Tommaso Pecorella

unread,
Mar 17, 2017, 9:50:05 AM3/17/17
to ns-3-users
Hi Michael,

you could have spotted a bug, indeed.
Please provide us a small test example (the smallest you can think of) and we'll take a look.

Cheers,

T.

Michael Rademacher

unread,
Mar 17, 2017, 11:18:54 AM3/17/17
to ns-3-users
Hi Tommaso, 

Thanks for quick reply. As an attachment to this post you find a small test example. It is based on the wifi-spectrum-per-example.cc file provided in the examples directory of ns-3.26 

Since this functionality is a very important aspects of my current research, please let me know if I can be helpful somehow. 

With kind regards, 
Michael
channel-switch-minimal.cc

Tom Henderson

unread,
Mar 17, 2017, 1:04:08 PM3/17/17
to ns-3-...@googlegroups.com
On 03/17/2017 08:18 AM, Michael Rademacher wrote:
> Hi Tommaso,
>
> Thanks for quick reply. As an attachment to this post you find a small
> test example. It is based on the wifi-spectrum-per-example.cc file
> provided in the examples directory of ns-3.26
>
> Since this functionality is a very important aspects of my current
> research, please let me know if I can be helpful somehow.
>
> With kind regards,
> Michael

Michael, thanks for the detailed bug report and test case; I opened an
issue in our tracker here:
https://www.nsnam.org/bugzilla/show_bug.cgi?id=2673

and will try to take a look sometime soon.

- Tom

Michael Rademacher

unread,
Mar 20, 2017, 7:10:08 AM3/20/17
to ns-3-users
Dear Tom, 

Thank you very much for acknowledging the potential issue. I will monitor the bugzilla page. 

With kind regards, 
Michael

Manish Puraswani

unread,
Mar 20, 2017, 8:36:29 AM3/20/17
to ns-3-users
Hi Michael

during working on your query , I found something which may be helpful for you


On Friday, 17 March 2017 18:58:19 UTC+5:30, Michael Rademacher wrote:

Hi Tommasso,


Thanks for the answer. I further analyzed the source. Here is what I found out for future reference:


- The SpecrumWiFiPhy differentiates between the receiving and the transmitting channel

- For the receiving channel, there is an “adaptor” class called WifiSpectrumPhyInterface

- The problem is related to the receiving channel

- When the WiFi Device is created a dedicated spectrum model is created:

DEBUG_LOG: 0s 1 SpectrumWifiPhy:GetRxSpectrumModel(): Creating spectrum model from frequency/width pair of (5180, 20)”


The code line executing after this debug message is :-


 

- The set channel methods actually calls the SpectrumWifiPhy::DoChannelSwitch () which overwrites a dummy Method in WiFiPhy

- When calling it during run time, the channel switch on the devices is actually conducted:


DEBUG_LOG: 1s -1 SpectrumWifiPhy:DoChannelSwitch(): switching channel 36 -> 40

DEBUG_LOG: 1s -1 WifiPhy:SetChannelNumber(): Setting frequency to 5200; width to 20


- However there is no call to create a new receiving channel on the phy using the new frequency/width



The Call is present in  SpectrumWifiPhy:DoChannelSwitch() method

 

- Therefore, the first attempt to receive on packet on that phy fails since since the spectrum model is not updated


cond="m_spectrumModel == x.m_spectrumModel"




I hope that problem is still somewhere else , I will  try to find it , but requesting you to please post the solution ,if found , on BUG tracker and here too

Regrads
Manish
 

Michael Rademacher

unread,
Mar 20, 2017, 8:59:42 AM3/20/17
to ns-3-users
Dear Manish, 

Thank your for the reply.  

I have seen that the call to WifiSpectrumValueHelper::GetSpectrumModel is indeed present in the DoChannelSwitch method.

As described, the DoChannelSwitch method is working fine before the the actual simulation starts.  
However, the problem occurs when calling the method during runtime for example using "Simulator::Schedule".   I have not figured out yet why it makes a difference for this 
function to be called during runtime or before the simulation. I think understanding this difference is the key for a possible fix.

Have you seen the minimal example I posted? When you run it, the ASSERT fires. 

I will be very happy to expect a solution here and on the bug tracker.  

With kind regards, 
Michael
Reply all
Reply to author
Forward
0 new messages