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.");
}