How can a real applications installed on PC connect to nodes in NS-3?

62 views
Skip to first unread message

sen

unread,
Jun 18, 2017, 12:34:23 PM6/18/17
to ns-3-users
I modified the code of the example(ns-allinone-3.19\ns-3.19\src\fd-net-device\examples\fd-tap-ping.cc) 
to create a tap0 (ip:192.168.202.1) by using the TapFdNetDeviceHelper.
I also create a node0 (ip:192.168.202.2)
Now i can ping the tap0 and node0 successfully on the PC(eth0: 192.168.203.150)
If i create another tap0 (ip:192.168.202.3) and node1 (ip:192.168.202.4) using the similar way, i ping the tap1
successfully. But i can not connect the node1. How?

In a word, my problem is: 
How can a real applications installed on PC connect to node0 and node1 (node0 and node1 are in the same wlan) in NS-3?

I don't understand the TapFdNetDevice. 
Any node should install a FdNetDevice if they want to connect to a "real" host?


part of my code:
std::string network ("192.168.202.0");
std::string mask ("255.255.255.0");
Ipv4Address tapNetwork (network.c_str ());
Ipv4Mask tapMask (mask.c_str ());
Ipv4AddressHelper addresses;
addresses.SetBase (tapNetwork, tapMask);

std::string deviceName ("tap0");
TapFdNetDeviceHelper helper;
helper.SetDeviceName (deviceName);
helper.SetModePi (modePi);
NodeContainer nodes;
nodes.Create (2);
  
Ipv4Address tapIp = addresses.NewAddress ();
helper.SetTapIpv4Address (tapIp);
helper.SetTapIpv4Mask (tapMask);

NetDeviceContainer devices = helper.Install (nodes.Get(0));
Ptr<NetDevice> device = devices.Get (0);
// Add an address to the ns-3 device in the same network than one assigned to the TAP.
Ptr<Ipv4> ipv4 = nodes.Get(0)->GetObject<Ipv4> ();
uint32_t interface = ipv4->AddInterface (device);
Ipv4Address devIp = addresses.NewAddress ();
Ipv4InterfaceAddress address = Ipv4InterfaceAddress (devIp, tapMask);
ipv4->AddAddress (interface, address);
ipv4->SetMetric (interface, 1);
ipv4->SetUp (interface);
////------------------------
std::string deviceName2 ("tap1");
TapFdNetDeviceHelper helper2;
helper2.SetDeviceName (deviceName2);
helper2.SetModePi (modePi);
Ipv4Address tapIp2 = addresses.NewAddress ();
helper2.SetTapIpv4Address (tapIp2);
helper2.SetTapIpv4Mask (tapMask);
  
NetDeviceContainer devices2 = helper2.Install (nodes.Get(1));
Ptr<NetDevice> device2 = devices2.Get (0);
// Add an address to the ns-3 device in the same network than one assigned to the TAP.
Ptr<Ipv4> ipv42 = nodes.Get(1)->GetObject<Ipv4> ();
uint32_t interface2 = ipv42->AddInterface (device2);
Ipv4Address devIp2 = addresses.NewAddress ();
Ipv4InterfaceAddress address2 = Ipv4InterfaceAddress (devIp2, tapMask);
ipv42->AddAddress (interface2, address2);
ipv42->SetMetric (interface2, 1);
ipv42->SetUp (interface2);

sen

unread,
Jun 18, 2017, 12:42:56 PM6/18/17
to ns-3-users

network topology that looks like below:

|wifi node0
real app on pc<-------->NS-3|wifi node1
|wifi node2

在 2017年6月19日星期一 UTC+8上午12:34:23,sen写道:

Tommaso Pecorella

unread,
Jul 11, 2017, 5:50:41 PM7/11/17
to ns-3-users
Hi,

only ONE node should have the FdNetDevice, and it will be the gateway between ns-3 and your PC.
You could install more than one, but they'll need to be in different subnets (on the external part).

As a side note, upgrade to 3.26, you have no reasons to use 3.19 (and we can not provide help on that version).

T.
Reply all
Reply to author
Forward
0 new messages