关于ns-3我有两个主要问题。
很抱歉让您久等了。下面是我用来设置节点IP地址的代码片段。其中csmaTopLeftParentToTopLeft是NodeContainer
node = csmaTopLeftParentToTopLeft.Get(2);
ipv4 = node->GetObject<Ipv4> (); // Get Ipv4 instance of the node
addr = ipv4->GetAddress (0, 0).GetLocal (); // Get Ipv4InterfaceAddress of xth interface.
IPAddress = Ip.c_str();
addr.Set(IPAddress);这将运行,但是如果我在使用print语句之后检查该值,它将显示该值从未被实际更改。
这两件事似乎都不应该这么难做,但我尝试了很多方法,在互联网上搜索,却找不到关于这个话题的任何东西。
发布于 2018-03-10 18:15:40
我想出了如何设置一个节点的IP地址。
Ptr<Node> node;
Ptr<Ipv4> ipv4;
Ipv4InterfaceAddress addr;
Ipv4Address addressIp;
const char * IPAddress;
IPAddress = Ip.c_str();
Ptr<NetDevice> device = devices.Get(counter);
node = device->GetNode();
ipv4 = node->GetObject<Ipv4>(); // Get Ipv4 instance of the node
int32_t interface = ipv4->GetInterfaceForDevice (device);
if (interface == -1) {
interface = ipv4->AddInterface (device);
}
Ipv4InterfaceAddress ipv4Addr = Ipv4InterfaceAddress (Ipv4Address(IPAddress), Ipv4Mask ("/16"));
ipv4->AddAddress (interface, ipv4Addr);
ipv4->SetMetric (interface, 1);
ipv4->SetUp (interface);https://stackoverflow.com/questions/49090264
复制相似问题