[英]How to set the IP address and data of Nodes in NS3?
关于ns-3,我有两个主要问题。
我已经完全构建了拓扑,但是我希望能够设置(更改)NodeContainer中存在的节点的IP地址。 这可能吗?
我在模拟对等流服务时需要设置节点持有的数据。 我不了解如何更改节点保存的数据,甚至看不到数据。
抱歉耽搁了。 这是我用来尝试设置节点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语句检查之后的值,则表明该值从未真正更改过。
这两件事似乎都不是那么困难,但是我尝试了许多方法并在互联网上搜索,但找不到关于此主题的任何内容。
我想出了如何设置节点的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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.