Accessing a node's IP address

3,744 views
Skip to first unread message

tim@uon

unread,
Mar 1, 2011, 6:27:01 PM3/1/11
to ns-3-users
Hello.

I am new to ns-3, and I am beginning with a simple simulation of
wireless network with on access point and one station. My goal is to
simulate network performance using 802.11g, 802.11n, and 802.11e
protocols with different parameters and channel conditions.

I have started by following the tutorial, in particular the section on
building a wireless network topology (http://www.nsnam.org/docs/
release/3.10/tutorial/singlehtml/index.html#building-a-wireless-
network-topology). I am modifying third.cc to setup UDP echo server
and client applications on the ap and sta respectively. My root
problem is accessing the IP address of the interface connected to the
STA node, when I call the UdpEchoClientHelper constructor.

The example code in the tutorial does this by accessing one of the
elements in an Ipv4InterfaceContainer:

Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);

...

UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma),
9);

Is there a way that I can access the members of the devices and
interfaces that have been installed on a node? I am wondering if there
is a way to do it without keeping a container class for all the things
installed on a node. What I understand from the documentation is that
installing these things on a node is called 'aggregation', and that
aggregated objects can be accessed through a query interface, but I
don't understand how to use the query interface. The documentation on
the query interface that I could find was reasonably brief (http://
www.nsnam.org/docs/architecture.bak2/node11.html)

In the larger scheme of things I am trying to understand intended
usage patterns for the classes in creating simulations, and what are
'best practice' workflows.

Thanks for your help,
Tim

Lalith Suresh

unread,
Mar 2, 2011, 5:57:16 PM3/2/11
to ns-3-...@googlegroups.com
Hello,

Usually, we do something like below. I'll assume you have a NodeContainer named myNodes.

Ptr<Node> node = myNodes.Get (i); // Get pointer to ith node in container
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); // Get Ipv4 instance of the node
Ipv4Address addr = ipv4->GetAddress (x, 0).GetLocal (); // Get Ipv4InterfaceAddress of xth interface.

You can always string the entire sequence together in one line, but the above makes for better clarity.

 

Thanks for your help,
Tim

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Lalith Suresh
Department of Computer Science and Engineering
Instituto Superior Técnico
www.lalith.in

Reply all
Reply to author
Forward
0 new messages