ARP request the IP of other subnet

295 views
Skip to first unread message

Haopeng Wang

unread,
Jan 27, 2022, 5:05:14 PM1/27/22
to ns-3-users
Hi, I am trying to ping from a ns3 node to a real computer using fdnetdevice based on "fd-emu-ping.cc", as shown below, node0 has csma device ( 169.254.238.30) and ping app, node1 has csma (169.254.238.31) and emu (169.254.239.22), and my real computer is 169.254.239.21.
But the emu receives the arp"Who has 169.254.238.30, tell 169.254.239.21", which is very weird. Because arp should be Who has 169.254.239.22" tell 169.254.239.21", the arp only works in a subnet, when the destination is in other subnet, it should ask the IP of its gateway.

node0----node1---->>>>client
|csma|----|csma|
                  |emu|---->>>>client
 169.254.238.30----169.254.238.31    
                                   169.254.239.22----->>>>>169.254.239.21#include "ns3/abort.h"

#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/fd-net-device-module.h"
#include "ns3/internet-apps-module.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/csma-module.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("PingEmulationExample");

static void
PingRtt (std::string context, Time rtt)
{
  NS_LOG_UNCOND ("Received Response with RTT = " << rtt);
}


int
main (int argc, char *argv[])
{

  std::string emuMode ("raw");
  GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));

  GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));

  NS_LOG_INFO ("Create Node");
  Ptr<Node> node0 = CreateObject<Node> ();
  Ptr<Node> node1 = CreateObject<Node> ();
  NodeContainer endpointNodes (node0, node1);
 
  NS_LOG_INFO ("Add Internet Stack");
  InternetStackHelper internetStackHelper;
  internetStackHelper.Install (endpointNodes);
 
 
  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", StringValue ("50Mbps"));
  csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
 
  NetDeviceContainer enddevices = csma.Install (endpointNodes);
 
  Ipv4AddressHelper address;    
  address.SetBase ("169.254.238.0", "255.255.255.0","0.0.0.30");
  Ipv4InterfaceContainer endinterfaces = address.Assign (enddevices);
 
  EmuFdNetDeviceHelper emu;
  emu.SetDeviceName ("enp6s0");
  NetDeviceContainer devices = emu.Install (node1);
  Ptr<NetDevice> fdevice = devices.Get (0);
  fdevice->SetAttribute ("Address", Mac48AddressValue (Mac48Address::Allocate ()));
 
 
  Ptr<Ipv4> ipv40 = node0->GetObject<Ipv4> ();
  Ptr<Ipv4> ipv41 = node1->GetObject<Ipv4> ();
 

  uint32_t finterface = ipv41->AddInterface (fdevice);
  Ipv4InterfaceAddress faddress = Ipv4InterfaceAddress (Ipv4Address ("169.254.239.22"), Ipv4Mask ("/24"));
  ipv41->AddAddress (finterface, faddress);
  ipv41->SetMetric (finterface, 1);
  ipv41->SetForwarding (finterface, true);
  ipv41->SetUp (finterface);
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

 Ptr<Ipv4StaticRouting> staticRouting0 = ipv4RoutingHelper.GetStaticRouting (ipv40);
  staticRouting0->AddHostRouteTo(Ipv4Address("169.254.239.21"),Ipv4Address("169.254.238.31"),1,1);

 Ptr<Ipv4StaticRouting> staticRouting1 = ipv4RoutingHelper.GetStaticRouting (ipv41);
  staticRouting1->AddHostRouteTo(Ipv4Address("169.254.239.21"),Ipv4Address("169.254.239.21"),finterface,1);
  staticRouting1->AddHostRouteTo(Ipv4Address("169.254.238.30"),Ipv4Address("169.254.238.30"),1,1);

  NS_LOG_INFO ("Create V4Ping Appliation");
  Ptr<V4Ping> app = CreateObject<V4Ping> ();
  app->SetAttribute ("Remote", Ipv4AddressValue (Ipv4Address("169.254.239.21")));
  app->SetAttribute ("Verbose", BooleanValue (true) );
  node0->AddApplication (app);
  app->SetStartTime (Seconds (1.0));
  app->SetStopTime (Seconds (22.0));

  Names::Add ("app", app);

  Config::Connect ("/Names/app/Rtt", MakeCallback (&PingRtt));

  emu.EnablePcap (emuMode + "-myemu-ping", fdevice, true);
  csma.EnablePcapAll("myPPP");
  Simulator::Stop (Seconds (23.0));
  Simulator::Run ();
  Simulator::Destroy ();
  NS_LOG_INFO ("Done.");
}

Tommaso Pecorella

unread,
Jan 28, 2022, 12:00:44 AM1/28/22
to ns-3-users
This line shouldn't be necessary:
uint32_t finterface = ipv41->AddInterface (fdevice);
and it's potentially dangerous, as you'll end up with TWO Ipv4Interfaces in the node. If you need the IP-level interface index, use ipv4->GetInterfaceForDevice().

Moreover, you have "Ipv4GlobalRoutingHelper::PopulateRoutingTables ();", but then you add the routing tables manually which (again) might lead to duplications and (possibly) inconsistencies.

About the specific error, I should try it - but at the moment I don't have a computer to run it. My suggestion is to try to reproduce it using normal nodes (i.e., no emu devices).

Soulimane Mammar

unread,
Jan 28, 2022, 7:12:51 AM1/28/22
to ns-3-users
Hi,
First of all please provide a working code:
 ipv4RoutingHelper is not declared
The second thing is that   Ipv4GlobalRoutingHelper::PopulateRoutingTables (); is doing the job of configuring the routing.
don't forget to configure the default gateway in host with ip 169.254.239.21/24

Tommaso Pecorella

unread,
Jan 28, 2022, 7:51:51 AM1/28/22
to ns-3-users
As a side note... RFC 3927:
> An IPv4 packet whose source and/or destination address is in the
> 169.254/16 prefix MUST NOT be sent to any router for forwarding, and
> any network device receiving such a packet MUST NOT forward it,
> regardless of the TTL in the IPv4 header.  Similarly, a router or
> other host MUST NOT indiscriminately answer all ARP Requests for
> addresses in the 169.254/16 prefix.

So, don't use this address range in the simulations, because we could decide to enforce this RFC. Moreover, the "real" part of this system might as well enforce RFC 3927 - and the result would be that you will not have any connection between the nodes (the real and the emulated one).

Haopeng Wang

unread,
Jan 28, 2022, 12:11:30 PM1/28/22
to ns-3-users
Sorry,  I provided the wrong code, since I have many commented codes, when I deleted them, some necessary codes are deleted.
But I can run the code, and I have set the default gateway (169.254.239.22) in my host,  still get the problem . 

// node0---node1---->>>>>remote
//|ppp|----|PPP|
//         |emu|---->>>>>remote
//169.254.238.30----169.254.238.31    
//                  169.254.239.22----->>>>>169.254.239.21
  //Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
  Ipv4StaticRoutingHelper ipv4RoutingHelper;

  Ptr<Ipv4StaticRouting> staticRouting0 = ipv4RoutingHelper.GetStaticRouting (ipv40);
  staticRouting0->AddHostRouteTo(Ipv4Address("169.254.239.21"),Ipv4Address("169.254.238.31"),1,1);

  Ptr<Ipv4StaticRouting> staticRouting1 = ipv4RoutingHelper.GetStaticRouting (ipv41);
  staticRouting1->AddHostRouteTo(Ipv4Address("169.254.239.21"),Ipv4Address("169.254.239.21"),finterface,1);
  staticRouting1->AddHostRouteTo(Ipv4Address("169.254.238.30"),Ipv4Address("169.254.238.30"),1,1);

  NS_LOG_INFO ("Create V4Ping Appliation");
  Ptr<V4Ping> app = CreateObject<V4Ping> ();
  app->SetAttribute ("Remote", Ipv4AddressValue (Ipv4Address("169.254.239.21")));
  app->SetAttribute ("Verbose", BooleanValue (true) );
  node0->AddApplication (app);
  app->SetStartTime (Seconds (1.0));
  app->SetStopTime (Seconds (22.0));


  Names::Add ("app", app);

  //
  // Hook a trace to print something when the response comes back.
  //

  Config::Connect ("/Names/app/Rtt", MakeCallback (&PingRtt));

  //
  // Enable a promiscuous pcap trace to see what is coming and going on our device.
  //

  emu.EnablePcap (emuMode + "-myemu-ping", fdevice, true);
  csma.EnablePcapAll("myPPP");
  Simulator::Stop (Seconds (23.0));
  Simulator::Run ();
  Simulator::Destroy ();
  NS_LOG_INFO ("Done.");
}

Haopeng Wang

unread,
Jan 28, 2022, 12:14:26 PM1/28/22
to ns-3-users
If everything happens in NS3 without a real computer, it works. But I need to connect to the real world.

Soulimane Mammar

unread,
Jan 28, 2022, 4:07:01 PM1/28/22
to ns-3-users
Hi,
Just compiled and  run your script on my computer and it works fine.
I just changed the addresses and enabled global routing
=========================================================
PING 192.168.2.21 - 56 bytes of data - 84 bytes including ICMP and IPv4 headers.
Received Response with RTT = +1.73845e+07ns
64 bytes from 192.168.2.21: icmp_seq=0 ttl=63 time=+17.3845ms
Received Response with RTT = +1.38888e+06ns
64 bytes from 192.168.2.21: icmp_seq=1 ttl=63 time=+1.38888ms
Received Response with RTT = +1.14188e+06ns
64 bytes from 192.168.2.21: icmp_seq=2 ttl=63 time=+1.14188ms
Received Response with RTT = +1.25488e+06ns
64 bytes from 192.168.2.21: icmp_seq=3 ttl=63 time=+1.25488ms
Received Response with RTT = +1.08188e+06ns
64 bytes from 192.168.2.21: icmp_seq=4 ttl=63 time=+1.08188ms
Received Response with RTT = +1.22188e+06ns
64 bytes from 192.168.2.21: icmp_seq=5 ttl=63 time=+1.22188ms
Received Response with RTT = +1.21488e+06ns
64 bytes from 192.168.2.21: icmp_seq=6 ttl=63 time=+1.21488ms
Received Response with RTT = +1.18288e+06ns
64 bytes from 192.168.2.21: icmp_seq=7 ttl=63 time=+1.18288ms
Received Response with RTT = +1.14788e+06ns
64 bytes from 192.168.2.21: icmp_seq=8 ttl=63 time=+1.14788ms


=========================================================
address.SetBase ("192.168.1.0", "255.255.255.0","0.0.0.30");
Ipv4InterfaceContainer endinterfaces = address.Assign (enddevices);
EmuFdNetDeviceHelper emu;
emu.SetDeviceName ("eth0");
NetDeviceContainer devices = emu.Install (node1);
Ptr<NetDevice> fdevice = devices.Get (0);
fdevice->SetAttribute ("Address", Mac48AddressValue (Mac48Address::Allocate ()));
Ptr<Ipv4> ipv40 = node0->GetObject<Ipv4> ();
Ptr<Ipv4> ipv41 = node1->GetObject<Ipv4> ();

uint32_t finterface = ipv41->AddInterface (fdevice);
Ipv4InterfaceAddress faddress = Ipv4InterfaceAddress (Ipv4Address ("192.168.2.22"), Ipv4Mask ("/24"));
ipv41->AddAddress (finterface, faddress);
ipv41->SetMetric (finterface, 1);
ipv41->SetForwarding (finterface, true);
ipv41->SetUp (finterface);
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
// Ipv4StaticRoutingHelper ipv4RoutingHelper;

// Ptr<Ipv4StaticRouting> staticRouting0 = ipv4RoutingHelper.GetStaticRouting (ipv40);
// staticRouting0->AddHostRouteTo(Ipv4Address("192.168.2.21"),Ipv4Address("192.168.1.31"),1,1);

// Ptr<Ipv4StaticRouting> staticRouting1 = ipv4RoutingHelper.GetStaticRouting (ipv41);
// staticRouting1->AddHostRouteTo(Ipv4Address("169.254.239.21"),Ipv4Address("169.254.239.21"),finterface,1);
// staticRouting1->AddHostRouteTo(Ipv4Address("169.254.238.30"),Ipv4Address("169.254.238.30"),1,1);

NS_LOG_INFO ("Create V4Ping Appliation");
Ptr<V4Ping> app = CreateObject<V4Ping> ();
app->SetAttribute ("Remote", Ipv4AddressValue (Ipv4Address("192.168.2.21")));
app->SetAttribute ("Verbose", BooleanValue (true) );
node0->AddApplication (app);
app->SetStartTime (Seconds (1.0));
app->SetStopTime (Seconds (22.0));


Names::Add ("app", app);

//
// Hook a trace to print something when the response comes back.
//

Config::Connect ("/Names/app/Rtt", MakeCallback (&PingRtt));

//
// Enable a promiscuous pcap trace to see what is coming and going on our device.
//

emu.EnablePcap (emuMode + "-myemu-ping", fdevice, true);
csma.EnablePcapAll("myPPP");
Simulator::Stop (Seconds (23.0));
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}

Haopeng Wang

unread,
Jan 28, 2022, 7:37:30 PM1/28/22
to ns-3-users
I tried you IP, but still got the problem, as shown in attached pcap file, the ubuntu host running ns3 has the enp6s0:

enp6s0: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
        inet 192.168.2.22  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::27fb:14ec:17d8:9b4c  prefixlen 64  scopeid 0x20<link>
        ether b8:85:84:b3:74:cc  txqueuelen 1000  (Ethernet)
        RX packets 6580  bytes 748248 (748.2 KB)
        RX errors 0  dropped 102  overruns 0  frame 0
        TX packets 215  bytes 23059 (23.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19 

and the configuration of my another host is
unnamed.png
raw-myemu-ping-1-2.pcap

Tommaso Pecorella

unread,
Jan 29, 2022, 12:08:08 AM1/29/22
to ns-3-users

Again (and I don't like to repeat myself). You are installing TWO EmuFdNetDevice on the same node. Enough said.

Haopeng Wang

unread,
Jan 29, 2022, 12:36:47 AM1/29/22
to ns-3-users
Hi, I do not think I have two EmuFdNetDevice on one node. I only install one EmuFdNetdevice and one CSMA on one node.

Soulimane Mammar

unread,
Jan 29, 2022, 3:46:52 AM1/29/22
to ns-3-users
Hi,
I think you didn't get it right ! 
Node 0 : one interface with ip 192.168.1.30/24
Node 1 : two interfaces with ip 192.168.1.31:24 (csma) and 192.168.2.22/24 (emu)
The host ip (the windows one): one interface with ip 192.168.2.21/24 and gateway 192.168.2.22 (your configuration is correct)
The linux box (where the simulation resides): enp6s0 IT MUST NOT HAVE ANY IP ADDRESS and furthermore it must be set to promiscuous mode  (ifconfig enp6s0 up ,  ifconfig enp6s0 promisc )
And that's it 
Regards

Haopeng Wang

unread,
Jan 30, 2022, 1:23:24 PM1/30/22
to ns-3-users
Screenshot from 2022-01-30 13-15-25.png
I still have the same problem after setting enp6s0 without IP. The route table of my windows host is also shown. Screenshot 2022-01-30 132026.png

  emu.SetDeviceName ("enp6s0");
  NetDeviceContainer devices = emu.Install (node1);
  Ptr<NetDevice> fdevice = devices.Get (0);
  fdevice->SetAttribute ("Address", Mac48AddressValue (Mac48Address::Allocate ()));
 
 
  Ptr<Ipv4> ipv40 = node0->GetObject<Ipv4> ();
  Ptr<Ipv4> ipv41 = node1->GetObject<Ipv4> ();
 

  uint32_t finterface = ipv41->AddInterface (fdevice);
  Ipv4InterfaceAddress faddress = Ipv4InterfaceAddress (Ipv4Address ("192.168.2.22"), Ipv4Mask ("/24"));
  ipv41->AddAddress (finterface, faddress);
  ipv41->SetMetric (finterface, 1);
  ipv41->SetForwarding (finterface, true);
  ipv41->SetUp (finterface);
 
  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
  //Ipv4StaticRoutingHelper ipv4RoutingHelper;
  //Ptr<Ipv4StaticRouting> staticRouting0 = ipv4RoutingHelper.GetStaticRouting (ipv40);
  //staticRouting0->AddHostRouteTo(Ipv4Address("1192.168.2.21"),Ipv4Address("192.168.1.31"),1,1);

  //Ptr<Ipv4StaticRouting> staticRouting1 = ipv4RoutingHelper.GetStaticRouting (ipv41);
  //staticRouting1->AddHostRouteTo(Ipv4Address("169.254.239.21"),Ipv4Address("169.254.239.21"),finterface,1);
  //staticRouting1->AddHostRouteTo(Ipv4Address("169.254.238.30"),Ipv4Address("169.254.238.30"),1,1);


  NS_LOG_INFO ("Create V4Ping Appliation");
  Ptr<V4Ping> app = CreateObject<V4Ping> ();
  app->SetAttribute ("Remote", Ipv4AddressValue (Ipv4Address("192.168.2.21")));
  app->SetAttribute ("Verbose", BooleanValue (true) );
  node0->AddApplication (app);
  app->SetStartTime (Seconds (1.0));
  app->SetStopTime (Seconds (22.0));


  Names::Add ("app", app);

  //
  // Hook a trace to print something when the response comes back.
  //
  Config::Connect ("/Names/app/Rtt", MakeCallback (&PingRtt));

  //
  // Enable a promiscuous pcap trace to see what is coming and going on our device.
  //
  emu.EnablePcap (emuMode + "-myemu-ping", fdevice, true);
  csma.EnablePcapAll("myPPP");
  Simulator::Stop (Seconds (23.0));
  Simulator::Run ();
  Simulator::Destroy ();
  NS_LOG_INFO ("Done.");
}

Soulimane Mammar

unread,
Jan 30, 2022, 2:47:36 PM1/30/22
to ns-3-users
Hi,
Your windows machine contains a default route to 10.192.16.1 (I think your ping replies get lost through this router). Try to remove it

Haopeng Wang

unread,
Jan 31, 2022, 9:03:33 PM1/31/22
to ns-3-users
Finally, it works, I removed other default routes and disabled other adapters.

Really appreciate your help.

Haopeng 

Vadim Hapanchak

unread,
Feb 17, 2022, 1:48:30 AM2/17/22
to ns-3-users
Hi, 
Is there a downside to having two EmuFdNetDevice on the same node? 
(Not for this particular scenario, but in general)

суббота, 29 января 2022 г. в 05:08:08 UTC, Tommaso Pecorella:

Soulimane Mammar

unread,
Feb 17, 2022, 1:17:26 PM2/17/22
to ns-3-users
Hi,
As long as they are connected to different physical devices, I don't see any downside

Muhammad Nauman Chattha

unread,
Jul 23, 2022, 6:03:56 PM7/23/22
to ns-3-users
Hi,
I am facing a similar issue. I am trying the emu-fd-ping example and I am unable to ping the server running on the same machine. It would be great if you can give me some pointers on what I am doing wrong. Here is my code.

#include "ns3/abort.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/fd-net-device-module.h"
#include "ns3/internet-apps-module.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("PingEmulationExample");

static void
PingRtt (std::string context, Time rtt)
{
NS_LOG_UNCOND ("Received Response with RTT = " << rtt);
}

int
main (int argc, char *argv[])
{
NS_LOG_INFO ("Ping Emulation Example");

std::string deviceName ("enp0s25");
std::string remote ("10.0.0.1");
std::string localAddress ("192.168.0.100");
std::string localGateway ("192.168.0.1");
std::string emuMode ("raw");

Ipv4Address remoteIp (remote.c_str ());
Ipv4Address localIp (localAddress.c_str ());
NS_ABORT_MSG_IF (localIp == "1.2.3.4", "You must change the local IP address before running this example");

Ipv4Mask localMask ("255.255.255.0");

GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));

GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));


NS_LOG_INFO ("Create Node");
Ptr<Node> node = CreateObject<Node> ();

NS_LOG_INFO ("Create Device");

EmuFdNetDeviceHelper* helper = new EmuFdNetDeviceHelper;
helper->SetDeviceName(deviceName);

NetDeviceContainer devices = helper->Install (node);
Ptr<NetDevice> device = devices.Get (0);
device->SetAttribute ("Address", Mac48AddressValue (Mac48Address::Allocate ()));

//
// Add a default internet stack to the node. This gets us the ns-3 versions
// of ARP, IPv4, ICMP, UDP and TCP.
//
NS_LOG_INFO ("Add Internet Stack");
InternetStackHelper internetStackHelper;
internetStackHelper.Install (node);

NS_LOG_INFO ("Create IPv4 Interface");
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
uint32_t interface = ipv4->AddInterface (device);
Ipv4InterfaceAddress address = Ipv4InterfaceAddress (localIp, localMask);
ipv4->AddAddress (interface, address);
ipv4->SetMetric (interface, 1);
ipv4->SetUp (interface);

Ipv4Address gateway (localGateway.c_str ());
NS_ABORT_MSG_IF (gateway == "1.2.3.4", "You must change the gateway IP address before running this example");

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Ipv4StaticRoutingHelper ipv4RoutingHelper;
// Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
// staticRouting->SetDefaultRoute (gateway, interface);


NS_LOG_INFO ("Create V4Ping Appliation");
Ptr<V4Ping> app = CreateObject<V4Ping> ();
app->SetAttribute ("Remote", Ipv4AddressValue (remoteIp));
app->SetAttribute ("Verbose", BooleanValue (true) );
node->AddApplication (app);
app->SetStartTime (Seconds (1.0));
app->SetStopTime (Seconds (22.0));

//
// Give the application a name. This makes life much easier when constructing
// config paths.
//
Names::Add ("app", app);

//
// Hook a trace to print something when the response comes back.
//
Config::Connect ("/Names/app/Rtt", MakeCallback (&PingRtt));

//
// Enable a promiscuous pcap trace to see what is coming and going on our device.
//
helper->EnablePcap (emuMode + "-emu-ping", device, true);

//
// Now, do the actual emulation.
//
NS_LOG_INFO ("Run Emulation in " << emuMode << " mode.");
Simulator::Stop (Seconds (23.0));
Simulator::Run ();
Simulator::Destroy ();
delete helper;
NS_LOG_INFO ("Done.");
}

Reply all
Reply to author
Forward
0 new messages