change channel loss during runtime

37 views
Skip to first unread message

Boyang Yan

unread,
Mar 7, 2023, 8:45:49 PM3/7/23
to ns-3-users
Hello All,

Good day to you.

I am using MatrixPropagationLossModel binding with the wifi channel to set the channel loss. The code below is for setting the Loss Model binding with the wifi channel.

```c++
//Create propagation loss matrix
Ptr<MatrixPropagationLossModel> lossModel = CreateObject<MatrixPropagationLossModel>();

lossModel->SetDefaultLoss(10); // set default loss to 200 dB (no link)
wifiChannel->SetPropagationLossModel(lossModel);
wifiChannel->SetPropagationDelayModel(CreateObject<ConstantSpeedPropagationDelayModel>());
wifiPhy.SetChannel(wifiChannel);
```

But, I want to change the loss during runtime.
 
I created a Schedule to make changes. However, I found below code does not work during runtime. How could I change the loss during runtime? 

```c++
    Simulator::Schedule(Seconds(2.0), &setLoss);
```

```c++
static void setLoss() {
    std::cout << "Function called at " << Simulator::Now().GetSeconds() << " seconds" << std::endl;
    // set symmetric loss 0 <-> 1 to 200 dB (no link)
    lossModel->SetLoss(UAVs.Get(0)->GetObject<MobilityModel>(),
                       UAVs.Get(1)->GetObject<MobilityModel>(),
                       200, true);
    wifiChannel->SetPropagationLossModel(lossModel);
    wifiPhy.SetChannel(wifiChannel);
    return;
}
```
Anyone know how to change channel loss during runtime?

Thanks for your helps,
Boyang

Li, Ye

unread,
Mar 7, 2023, 11:18:54 PM3/7/23
to ns-3-...@googlegroups.com
Hi Boyang,

Here is an example I have used to change packet loss rate during the simulation for point-to-point NetDevice. Basically, you may need to find out the path to the attribute of the error model, and then schedule a function to change it at your desired time.


Hope it helps.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/950949b7-ef8a-4c50-b3d1-1eb9d2f1c80fn%40googlegroups.com.


--
LI, Ye
School of Information Science and Technology
Nantong University
Nantong 226019, Jiangsu Province, China
Reply all
Reply to author
Forward
0 new messages