Hi,
i added IP forwarding to node0
ipv4->SetForwarding (interface, true);
and used static routing in node0
staticRouting->SetDefaultRoute(gateway, interface);
staticRouting->AddHostRouteTo(Ipv4Address("10.1.1.2"),Ipv4Address("10.1.1.2"),1,1);
and also in node1
staticRoutingNode1->SetDefaultRoute(Ipv4Address("10.1.1.1"), 1);
but i get the same result like befor. Node1 can just ping node0 and not the remote ip.
My edited source code
----------------------------------------------------
// Node1 Node0
//+------------+ +-------------------------------+ pc gateway
// I I I EmuFdNetDevice I 192.168.0.172------ 192.168.0.171 ------------------ 192.168.0.1
// +------------+ +-------------------------------+
// I CSMA I I CSMA I
// +------------+ +-------------------------------+
// 10.1.1.2 10.1.1.1
// I I
// =======================
#include "ns3/abort.h"
#include "ns3/core-module.h"
#include "ns3/fd-net-device-module.h"
#include "ns3/internet-apps-module.h"
#include "ns3/internet-module.h"
#include "ns3/ipv4-list-routing-helper.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("PingEmulation");
static void
PingRtt(std::string context, uint16_t seqNo, Time rtt)
{
NS_LOG_UNCOND("Received " << seqNo << " Response with RTT = " << rtt);
}
int
main(int argc, char* argv[])
{
NS_LOG_INFO("Ping Emulation Example");
std::string deviceName("enp6s0");
std::string remote("8.8.8.8");
std::string localAddress("192.168.0.172");
std::string localGateway("192.168.0.1");
std::string emuMode("raw");
Ipv4Address remoteIp(remote.c_str());
Ipv4Address localIp(localAddress.c_str());
Ptr<Ipv4> ipv4Node1 = node1->GetObject<Ipv4>();
Ptr<Ipv4> ipv4 = node0->GetObject<Ipv4>();
uint32_t interface = ipv4->AddInterface(device);
Ipv4InterfaceAddress address = Ipv4InterfaceAddress(localIp, localMask);
ipv4->AddAddress(interface, address);
ipv4->SetMetric(interface, 1);
ipv4->SetForwarding (interface, true);
ipv4->SetUp(interface);
Ipv4Address gateway(localGateway.c_str());
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting(ipv4);
staticRouting->SetDefaultRoute(gateway, interface);
staticRouting->AddHostRouteTo(Ipv4Address("10.1.1.2"),Ipv4Address("10.1.1.2"),1,1);
Ptr<Ipv4StaticRouting> staticRoutingNode1 = ipv4RoutingHelper.GetStaticRouting(ipv4Node1);
staticRoutingNode1->SetDefaultRoute(Ipv4Address("10.1.1.1"), 1);
//Ipv4GlobalRoutingHelper::PopulateRoutingTables ();