c++ - How to change pointopoint link datarate during run time in NS3
问题描述
I'm new to NS3. I have a query in changing the pointtopoint link datarate during the runtime. I tried a solution which is mentioned in https://stackoverflow.com/a/65514090/13121848. But here SetDeviceAttribute is not resolved for me.
void
ModifyLinkRate(PointToPointNetDevice *dev) {
dev->SetDeviceAttribute("DataRate", StringValue ("1Mbps"));
//dev->SetAttribute("DataRate", StringValue ("1Mbps"));
}
int
main (int argc, char *argv[])
{
...
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue (linkRate));
...
Simulator::Schedule(Seconds(2.0), &ModifyLinkRate, &pointToPoint );
}
解决方案
为了改变点对点链路的数据速率,必须检索安装在节点中的 PointToPointNetDevice。这可以使用与节点关联的 NetDeviceContainer 来完成。示例代码如下,
void
ModifyLinkRate(NetDeviceContainer *ptp, DataRate lr) {
StaticCast<PointToPointNetDevice>(ptp->Get(0))->SetDataRate(lr);
}
int
main (int argc, char *argv[])
{
...
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue (linkRate));
...
NetDeviceContainer p2pDevices = pointToPoint.Install (p2pNodes);
...
Simulator::Schedule(Seconds(2.0), &ModifyLinkRate, &p2pDevices,DataRate("20Mbps"));
}
推荐阅读
- html - 如何根据ionic 3中的特定页面更改应用程序中的选项卡内容
- go - 去构建单个或单独的缓存目录
- php - Laravel 扩展包中的类
- java - JUnit 测试 MongoDB SpringBoot
- angular - 验证不适用于具有多个控件的 formArray
- python - 在 django 网页中显示 ip camera live feed
- qlikview - QlikView 表达式忽略某些选择并包含显式值
- rotation - Createjs:如何在不旋转 sourcerect 的情况下使用 sourcerect 旋转位图并裁剪它?
- angular - 如何在角度刷新页面后不丢失搜索结果
- angular - 存储在内存中的样式表的多个副本(泄漏)