I have a query that tries to change a point-to-point link data rate during runtime. I tried this solution but SetDeviceAttribute
was 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 );
}
In order to change the data rate of a point-to-point link, the PointToPointNetDevice
installed in a node has to be retrieved. This can be done using the NetDeviceContainer
where the node is associated. The example code is below:
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"));
}