简体   繁体   English

如何在NS3中设置节点的IP地址和数据?

[英]How to set the IP address and data of Nodes in NS3?

I have two main questions about ns-3. 关于ns-3,我有两个主要问题。

  1. I have my topology fully built but I want to be able to set(change) the IP addresses of nodes that exists within a NodeContainer. 我已经完全构建了拓扑,但是我希望能够设置(更改)NodeContainer中存在的节点的IP地址。 Is this possible and how if so? 这可能吗?

  2. I need to set the data a node is holding as I am simulating a peer to peer streaming service. 我在模拟对等流服务时需要设置节点持有的数据。 I do not understand how to change the data a node holds or even see the data. 我不了解如何更改节点保存的数据,甚至看不到数据。

Sorry for the delay. 抱歉耽搁了。 Here is the snippet of code I use to try to set the IP address of a node. 这是我用来尝试设置节点IP地址的代码段。 Where csmaTopLeftParentToTopLeft is a NodeContainer 其中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);

This runs but if I check the value after with print statements then it shows the value was never actually changed. 这会运行,但是如果我在使用print语句检查之后的值,则表明该值从未真正更改过。

Both these things do not seem like they should be this difficult to do but I have tried many ways and search the internet and could not find anything on this topic. 这两件事似乎都不是那么困难,但是我尝试了许多方法并在互联网上搜索,但找不到关于此主题的任何内容。

I figured out how to set an IP Address of a node. 我想出了如何设置节点的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM