librelist archives

« back to archive

ns3 + click - simulation hangs

ns3 + click - simulation hangs

From:
rajat kandoi
Date:
2014-05-29 @ 14:42
Hello,

I am newbie to both ns3 and click. I'm having trouble with a simulation
scenario. The simulation runs fine (all the required packets are seen with
the Print() logs) but the simulation does not terminate and no pcap traces
are written (except src and dst nodes). I can see that the cpu usage hits
100%. I wonder where I'm going wrong.

The scenario is as follows:

-------ns3 router B-------|
src ---- click ------ |          |---click-------dst
         Router A    |         |   Router D
                  -------ns3 router C-------|

I've configured static routing on all 4 routers.

I'm attaching the scripts for the click router A and ns3 script as well. I
apologize for the long email. Will appreciate any help. Thank you!

Best regards,
Rajat


Click-Router-A

elementclass IPRouter {
 $myaddr1, $hw1, $myaddr2, $hw2, $myaddr3, $hw3 |

// Shared IP input path and routing table
ip :: Strip(14)
    -> CheckIPHeader2
    -> rt :: StaticIPLookup(
        10.2.1.2/32 192.168.1.2 0,
        10.2.1.3/32 192.168.1.4 1,
        0.0.0.0/0.0.0.0 2,
        );
c0 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
c1 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
c2 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);

FromSimDevice(eth0,SNAPLEN 4096) -> Print(a-fromdev0) -> c0;
FromSimDevice(eth1,SNAPLEN 4096) -> Print(a-fromdev1) -> c1;
FromSimDevice(eth2,SNAPLEN 4096) -> Print(a-fromdev2) -> c2;

ar0 :: ARPResponder(eth0);
ar1 :: ARPResponder(eth1);
ar2 :: ARPResponder(eth2);

aq0 :: ARPQuerier(eth0);
aq1 :: ARPQuerier(eth1);
aq2 :: ARPQuerier(eth2);

out0 :: Queue(200) -> Print(a-todev0) -> todevice0 :: ToSimDevice(eth0);
out1 :: Queue(200) -> Print(a-todev1) -> todevice1 :: ToSimDevice(eth1);
out2 :: Queue(200) -> Print(a-todev2) -> todevice2 :: ToSimDevice(eth2);

//ARP requests
c0[0] -> ar0 -> out0
c1[0] -> ar1 -> out1
c2[0] -> ar2 -> out2

aq0 -> out0;
aq1 -> out1;
aq2 -> out2;

c0[1] -> [1]aq0;
c1[1] -> [1]aq1;
c2[1] -> [1]aq2;

c0[2] -> Paint(1) -> ip;
c1[2] -> Paint(2) -> ip;
c2[2] -> Paint(3) -> ip;

c0[3] -> Print(a-DISCARD0) -> Discard;
c1[3] -> Print(a-DISCARD1) -> Discard;
c2[3] -> Print(a-DISCARD2) ->Discard;
//arpt[3] -> Discard;


rt[0] -> DropBroadcasts
      -> gio0 :: IPGWOptions($myaddr1)
      -> FixIPSrc($myaddr1)
      -> dt0 :: DecIPTTL
      -> IPPrint(a-inRT0)
      -> [0]aq0;

rt[1] -> DropBroadcasts
      -> gio1 :: IPGWOptions($myaddr2)
      -> FixIPSrc($myaddr2)
      -> dt1 :: DecIPTTL
      -> IPPrint(a-inRT1)
      -> [0]aq1;

rt[2] -> DropBroadcasts
      -> gio2 :: IPGWOptions($myaddr3)
      -> FixIPSrc($myaddr3)
      -> dt2 :: DecIPTTL
      -> IPPrint(a-inRT2)
      -> [0]aq2;
}

a :: IPRouter(eth0, eth0, eth1, eth1, eth2, eth2);


---------------------------------------------------------------------------------------

ns3 script

#include <iostream>
#include <fstream>
#include <string>
#include <cassert>

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/csma-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/click-internet-stack-helper.h"

using namespace ns3;

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

  Ptr<Node> routerA = CreateObject<Node>();
  Ptr<Node> routerB = CreateObject<Node>();
  Ptr<Node> routerC = CreateObject<Node>();
  Ptr<Node> routerD = CreateObject<Node>();
  Ptr<Node> hostSrc = CreateObject<Node>();
  Ptr<Node> hostDst = CreateObject<Node>();

  NodeContainer clickRouters = NodeContainer(routerA, routerD);
  NodeContainer routers  = NodeContainer(routerB, routerC);
  NodeContainer hosts = NodeContainer(hostSrc, hostDst);

  ClickInternetStackHelper clickinternet;
  clickinternet.SetClickFile (routerA, "scratch/nsclick-ip-routerA.click");
  clickinternet.SetClickFile (routerD, "scratch/nsclick-ip-routerD.click");
  clickinternet.SetRoutingTableElement (routerA, "a/rt");
  clickinternet.SetRoutingTableElement (routerD, "d/rt");
  clickinternet.Install (clickRouters);

  InternetStackHelper internet;
  internet.Install(routers);
  internet.Install(hosts);

  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", StringValue("5Mbps"));
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
  csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));

  NetDeviceContainer rArB = csma.Install(NodeContainer(routerA,routerB));
  NetDeviceContainer rArC = csma.Install(NodeContainer(routerA,routerC));
  NetDeviceContainer rBrD = csma.Install(NodeContainer(routerB,routerD));
  NetDeviceContainer rCrD = csma.Install(NodeContainer(routerC,routerD));
  NetDeviceContainer hSrA = csma.Install(NodeContainer(hostSrc,routerA));
  NetDeviceContainer rDhD = csma.Install(NodeContainer(routerD,hostDst));

  Ipv4AddressHelper ipv4;
  ipv4.SetBase("192.168.1.0", "255.255.255.0");
  ipv4.Assign(rArB);
  ipv4.Assign(rArC);
  ipv4.Assign(rBrD);
  ipv4.Assign(rCrD);

  ipv4.SetBase("10.1.1.0", "255.255.255.0");
  ipv4.Assign(hSrA);
  ipv4.SetBase("10.2.1.0", "255.255.255.0");
  ipv4.Assign(rDhD);

  Ptr<CsmaNetDevice> netDevice = CreateObject<CsmaNetDevice>();
  netDevice->SetAddress(Mac48Address::Allocate());
  hostDst->AddDevice(netDevice);

  Ptr<Ipv4> ipv4HostDst = hostDst->GetObject<Ipv4>();
  int32_t ifIndex = ipv4HostDst->AddInterface(netDevice);
  Ipv4InterfaceAddress ifInAddr =
Ipv4InterfaceAddress(Ipv4Address("10.2.1.3"), Ipv4Mask("/24"));
  ipv4HostDst->AddAddress(ifIndex, ifInAddr);
  ipv4HostDst->SetMetric(ifIndex, 1);
  ipv4HostDst->SetUp(ifIndex);

  Ipv4StaticRoutingHelper ipv4RoutingHelper;

  Ptr<Ipv4> ipv4Src = hostSrc->GetObject<Ipv4>();
  Ptr<Ipv4StaticRouting> staticRoutingSrc =
ipv4RoutingHelper.GetStaticRouting(ipv4Src);
  staticRoutingSrc->AddHostRouteTo(Ipv4Address("10.2.1.2"),
Ipv4Address("10.1.1.2"), 1);
  staticRoutingSrc->AddHostRouteTo(Ipv4Address("10.2.1.3"),
Ipv4Address("10.1.1.2"), 1);

  Ptr<Ipv4> ipv4B = routerB->GetObject<Ipv4>();
  Ptr<Ipv4StaticRouting> staticRoutingB =
ipv4RoutingHelper.GetStaticRouting(ipv4B);
  staticRoutingB->AddHostRouteTo(Ipv4Address("10.2.1.2"),
Ipv4Address("192.168.1.6"), 2);

  Ptr<Ipv4> ipv4C = routerC->GetObject<Ipv4>();
  Ptr<Ipv4StaticRouting> staticRoutingC =
ipv4RoutingHelper.GetStaticRouting(ipv4C);
  staticRoutingC->AddHostRouteTo(Ipv4Address("10.2.1.3"),
Ipv4Address("192.168.1.8"), 2);

  Ptr<Ipv4> ipv4Dst = hostDst->GetObject<Ipv4>();
  uint16_t port = 9;   // Discard port(RFC 863)

  OnOffHelper onoff("ns3::UdpSocketFactory",
Address(InetSocketAddress(ipv4Dst->GetAddress(1,0).GetLocal(), port));
  onoff.SetConstantRate(DataRate(6000));
  OnOffHelper onoff2("ns3::UdpSocketFactory",
Address(InetSocketAddress(ipv4Dst->GetAddress(2,0).GetLocal(), port)));
  onoff2.SetConstantRate(DataRate(6000));

  ApplicationContainer apps = onoff.Install(hostSrc);
  ApplicationContainer apps2 = onoff2.Install(hostSrc);
  apps.Start(Seconds(1.0));
  apps.Stop(Seconds(10.0));
  apps2.Start(Seconds(1.0));
  apps2.Stop(Seconds(10.0));

  PacketSinkHelper sink("ns3::UdpSocketFactory",
Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
  apps = sink.Install(hostDst);
  apps.Start(Seconds(1.0));
  apps.Stop(Seconds(10.0));

  csma.EnablePcap("staticRouting-nsclick",routers,false);
  csma.EnablePcap("staticRouting-ns3click",clickRouters,false);
  csma.EnablePcap("staticRouting-ns3click",hosts,false);

  Simulator::Run();
  std::cout << "Ending Simulation\n";
  Simulator::Destroy();

  return 0;
}

Re: [click] ns3 + click - simulation hangs

From:
sri
Date:
2014-05-30 @ 17:28
On the CPU usage 100%, it is because of click keeps the CPU scheduler busy
by running it all along the click's task queue.

~Sri


On Thu, May 29, 2014 at 8:12 PM, rajat kandoi <rajatkandoi@gmail.com> wrote:

> Hello,
>
> I am newbie to both ns3 and click. I'm having trouble with a simulation
> scenario. The simulation runs fine (all the required packets are seen with
> the Print() logs) but the simulation does not terminate and no pcap traces
> are written (except src and dst nodes). I can see that the cpu usage hits
> 100%. I wonder where I'm going wrong.
>
> The scenario is as follows:
>
> -------ns3 router B-------|
> src ---- click ------ |          |---click-------dst
>          Router A    |         |   Router D
>                   -------ns3 router C-------|
>
> I've configured static routing on all 4 routers.
>
> I'm attaching the scripts for the click router A and ns3 script as well. I
> apologize for the long email. Will appreciate any help. Thank you!
>
> Best regards,
> Rajat
>
>
> Click-Router-A
>
> elementclass IPRouter {
>  $myaddr1, $hw1, $myaddr2, $hw2, $myaddr3, $hw3 |
>
> // Shared IP input path and routing table
> ip :: Strip(14)
>     -> CheckIPHeader2
>     -> rt :: StaticIPLookup(
>         10.2.1.2/32 192.168.1.2 0,
>         10.2.1.3/32 192.168.1.4 1,
>         0.0.0.0/0.0.0.0 2,
>         );
> c0 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
> c1 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
> c2 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
>
> FromSimDevice(eth0,SNAPLEN 4096) -> Print(a-fromdev0) -> c0;
> FromSimDevice(eth1,SNAPLEN 4096) -> Print(a-fromdev1) -> c1;
> FromSimDevice(eth2,SNAPLEN 4096) -> Print(a-fromdev2) -> c2;
>
> ar0 :: ARPResponder(eth0);
> ar1 :: ARPResponder(eth1);
> ar2 :: ARPResponder(eth2);
>
> aq0 :: ARPQuerier(eth0);
> aq1 :: ARPQuerier(eth1);
> aq2 :: ARPQuerier(eth2);
>
> out0 :: Queue(200) -> Print(a-todev0) -> todevice0 :: ToSimDevice(eth0);
> out1 :: Queue(200) -> Print(a-todev1) -> todevice1 :: ToSimDevice(eth1);
> out2 :: Queue(200) -> Print(a-todev2) -> todevice2 :: ToSimDevice(eth2);
>
> //ARP requests
> c0[0] -> ar0 -> out0
> c1[0] -> ar1 -> out1
> c2[0] -> ar2 -> out2
>
> aq0 -> out0;
> aq1 -> out1;
> aq2 -> out2;
>
> c0[1] -> [1]aq0;
> c1[1] -> [1]aq1;
> c2[1] -> [1]aq2;
>
> c0[2] -> Paint(1) -> ip;
> c1[2] -> Paint(2) -> ip;
> c2[2] -> Paint(3) -> ip;
>
> c0[3] -> Print(a-DISCARD0) -> Discard;
> c1[3] -> Print(a-DISCARD1) -> Discard;
> c2[3] -> Print(a-DISCARD2) ->Discard;
> //arpt[3] -> Discard;
>
>
> rt[0] -> DropBroadcasts
>       -> gio0 :: IPGWOptions($myaddr1)
>       -> FixIPSrc($myaddr1)
>       -> dt0 :: DecIPTTL
>       -> IPPrint(a-inRT0)
>       -> [0]aq0;
>
> rt[1] -> DropBroadcasts
>       -> gio1 :: IPGWOptions($myaddr2)
>       -> FixIPSrc($myaddr2)
>       -> dt1 :: DecIPTTL
>       -> IPPrint(a-inRT1)
>       -> [0]aq1;
>
> rt[2] -> DropBroadcasts
>       -> gio2 :: IPGWOptions($myaddr3)
>       -> FixIPSrc($myaddr3)
>       -> dt2 :: DecIPTTL
>       -> IPPrint(a-inRT2)
>       -> [0]aq2;
> }
>
> a :: IPRouter(eth0, eth0, eth1, eth1, eth2, eth2);
>
>
> 
---------------------------------------------------------------------------------------
>
> ns3 script
>
> #include <iostream>
> #include <fstream>
> #include <string>
> #include <cassert>
>
> #include "ns3/core-module.h"
> #include "ns3/network-module.h"
> #include "ns3/internet-module.h"
> #include "ns3/point-to-point-module.h"
> #include "ns3/csma-module.h"
> #include "ns3/applications-module.h"
> #include "ns3/ipv4-static-routing-helper.h"
> #include "ns3/click-internet-stack-helper.h"
>
> using namespace ns3;
>
> int main(int argc, char *argv[]) {
>
>   Ptr<Node> routerA = CreateObject<Node>();
>   Ptr<Node> routerB = CreateObject<Node>();
>   Ptr<Node> routerC = CreateObject<Node>();
>   Ptr<Node> routerD = CreateObject<Node>();
>   Ptr<Node> hostSrc = CreateObject<Node>();
>   Ptr<Node> hostDst = CreateObject<Node>();
>
>   NodeContainer clickRouters = NodeContainer(routerA, routerD);
>   NodeContainer routers  = NodeContainer(routerB, routerC);
>   NodeContainer hosts = NodeContainer(hostSrc, hostDst);
>
>   ClickInternetStackHelper clickinternet;
>   clickinternet.SetClickFile (routerA, "scratch/nsclick-ip-routerA.click");
>   clickinternet.SetClickFile (routerD, "scratch/nsclick-ip-routerD.click");
>   clickinternet.SetRoutingTableElement (routerA, "a/rt");
>   clickinternet.SetRoutingTableElement (routerD, "d/rt");
>   clickinternet.Install (clickRouters);
>
>   InternetStackHelper internet;
>   internet.Install(routers);
>   internet.Install(hosts);
>
>   CsmaHelper csma;
>   csma.SetChannelAttribute ("DataRate", StringValue("5Mbps"));
>   csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
>   csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
>
>   NetDeviceContainer rArB = csma.Install(NodeContainer(routerA,routerB));
>   NetDeviceContainer rArC = csma.Install(NodeContainer(routerA,routerC));
>   NetDeviceContainer rBrD = csma.Install(NodeContainer(routerB,routerD));
>   NetDeviceContainer rCrD = csma.Install(NodeContainer(routerC,routerD));
>   NetDeviceContainer hSrA = csma.Install(NodeContainer(hostSrc,routerA));
>   NetDeviceContainer rDhD = csma.Install(NodeContainer(routerD,hostDst));
>
>   Ipv4AddressHelper ipv4;
>   ipv4.SetBase("192.168.1.0", "255.255.255.0");
>   ipv4.Assign(rArB);
>   ipv4.Assign(rArC);
>   ipv4.Assign(rBrD);
>   ipv4.Assign(rCrD);
>
>   ipv4.SetBase("10.1.1.0", "255.255.255.0");
>   ipv4.Assign(hSrA);
>   ipv4.SetBase("10.2.1.0", "255.255.255.0");
>   ipv4.Assign(rDhD);
>
>   Ptr<CsmaNetDevice> netDevice = CreateObject<CsmaNetDevice>();
>   netDevice->SetAddress(Mac48Address::Allocate());
>   hostDst->AddDevice(netDevice);
>
>   Ptr<Ipv4> ipv4HostDst = hostDst->GetObject<Ipv4>();
>   int32_t ifIndex = ipv4HostDst->AddInterface(netDevice);
>   Ipv4InterfaceAddress ifInAddr =
> Ipv4InterfaceAddress(Ipv4Address("10.2.1.3"), Ipv4Mask("/24"));
>   ipv4HostDst->AddAddress(ifIndex, ifInAddr);
>   ipv4HostDst->SetMetric(ifIndex, 1);
>   ipv4HostDst->SetUp(ifIndex);
>
>   Ipv4StaticRoutingHelper ipv4RoutingHelper;
>
>   Ptr<Ipv4> ipv4Src = hostSrc->GetObject<Ipv4>();
>   Ptr<Ipv4StaticRouting> staticRoutingSrc =
> ipv4RoutingHelper.GetStaticRouting(ipv4Src);
>   staticRoutingSrc->AddHostRouteTo(Ipv4Address("10.2.1.2"),
> Ipv4Address("10.1.1.2"), 1);
>   staticRoutingSrc->AddHostRouteTo(Ipv4Address("10.2.1.3"),
> Ipv4Address("10.1.1.2"), 1);
>
>   Ptr<Ipv4> ipv4B = routerB->GetObject<Ipv4>();
>   Ptr<Ipv4StaticRouting> staticRoutingB =
> ipv4RoutingHelper.GetStaticRouting(ipv4B);
>   staticRoutingB->AddHostRouteTo(Ipv4Address("10.2.1.2"),
> Ipv4Address("192.168.1.6"), 2);
>
>   Ptr<Ipv4> ipv4C = routerC->GetObject<Ipv4>();
>   Ptr<Ipv4StaticRouting> staticRoutingC =
> ipv4RoutingHelper.GetStaticRouting(ipv4C);
>   staticRoutingC->AddHostRouteTo(Ipv4Address("10.2.1.3"),
> Ipv4Address("192.168.1.8"), 2);
>
>   Ptr<Ipv4> ipv4Dst = hostDst->GetObject<Ipv4>();
>   uint16_t port = 9;   // Discard port(RFC 863)
>
>   OnOffHelper onoff("ns3::UdpSocketFactory",
> Address(InetSocketAddress(ipv4Dst->GetAddress(1,0).GetLocal(), port));
>   onoff.SetConstantRate(DataRate(6000));
>   OnOffHelper onoff2("ns3::UdpSocketFactory",
> Address(InetSocketAddress(ipv4Dst->GetAddress(2,0).GetLocal(), port)));
>   onoff2.SetConstantRate(DataRate(6000));
>
>   ApplicationContainer apps = onoff.Install(hostSrc);
>   ApplicationContainer apps2 = onoff2.Install(hostSrc);
>   apps.Start(Seconds(1.0));
>   apps.Stop(Seconds(10.0));
>   apps2.Start(Seconds(1.0));
>   apps2.Stop(Seconds(10.0));
>
>   PacketSinkHelper sink("ns3::UdpSocketFactory",
> Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
>   apps = sink.Install(hostDst);
>   apps.Start(Seconds(1.0));
>   apps.Stop(Seconds(10.0));
>
>   csma.EnablePcap("staticRouting-nsclick",routers,false);
>   csma.EnablePcap("staticRouting-ns3click",clickRouters,false);
>   csma.EnablePcap("staticRouting-ns3click",hosts,false);
>
>   Simulator::Run();
>   std::cout << "Ending Simulation\n";
>   Simulator::Destroy();
>
>   return 0;
> }
>
>
>


-- 
--
 Krishna Mohan B

Re: [click] ns3 + click - simulation hangs

From:
rajat kandoi
Date:
2014-05-30 @ 18:03
Thank Sri.

The issue was quite simple (and I might add that I was quite foolish to
miss it). The ns-3 script required a "Simulator::Stop (Seconds (20.0));"
statement.


On Fri, May 30, 2014 at 8:28 PM, sri <bskmohan@gmail.com> wrote:

> On the CPU usage 100%, it is because of click keeps the CPU scheduler busy
> by running it all along the click's task queue.
>
> ~Sri
>
>
> On Thu, May 29, 2014 at 8:12 PM, rajat kandoi <rajatkandoi@gmail.com>
> wrote:
>
>> Hello,
>>
>> I am newbie to both ns3 and click. I'm having trouble with a simulation
>> scenario. The simulation runs fine (all the required packets are seen with
>> the Print() logs) but the simulation does not terminate and no pcap traces
>> are written (except src and dst nodes). I can see that the cpu usage hits
>> 100%. I wonder where I'm going wrong.
>>
>> The scenario is as follows:
>>
>> -------ns3 router B-------|
>> src ---- click ------ |          |---click-------dst
>>          Router A    |         |   Router D
>>                   -------ns3 router C-------|
>>
>> I've configured static routing on all 4 routers.
>>
>> I'm attaching the scripts for the click router A and ns3 script as well.
>> I apologize for the long email. Will appreciate any help. Thank you!
>>
>> Best regards,
>> Rajat
>>
>>
>> Click-Router-A
>>
>> elementclass IPRouter {
>>  $myaddr1, $hw1, $myaddr2, $hw2, $myaddr3, $hw3 |
>>
>> // Shared IP input path and routing table
>> ip :: Strip(14)
>>     -> CheckIPHeader2
>>     -> rt :: StaticIPLookup(
>>         10.2.1.2/32 192.168.1.2 0,
>>         10.2.1.3/32 192.168.1.4 1,
>>         0.0.0.0/0.0.0.0 2,
>>         );
>> c0 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
>> c1 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
>> c2 :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
>>
>> FromSimDevice(eth0,SNAPLEN 4096) -> Print(a-fromdev0) -> c0;
>> FromSimDevice(eth1,SNAPLEN 4096) -> Print(a-fromdev1) -> c1;
>> FromSimDevice(eth2,SNAPLEN 4096) -> Print(a-fromdev2) -> c2;
>>
>> ar0 :: ARPResponder(eth0);
>> ar1 :: ARPResponder(eth1);
>> ar2 :: ARPResponder(eth2);
>>
>> aq0 :: ARPQuerier(eth0);
>> aq1 :: ARPQuerier(eth1);
>> aq2 :: ARPQuerier(eth2);
>>
>> out0 :: Queue(200) -> Print(a-todev0) -> todevice0 :: ToSimDevice(eth0);
>> out1 :: Queue(200) -> Print(a-todev1) -> todevice1 :: ToSimDevice(eth1);
>> out2 :: Queue(200) -> Print(a-todev2) -> todevice2 :: ToSimDevice(eth2);
>>
>> //ARP requests
>> c0[0] -> ar0 -> out0
>> c1[0] -> ar1 -> out1
>> c2[0] -> ar2 -> out2
>>
>> aq0 -> out0;
>> aq1 -> out1;
>> aq2 -> out2;
>>
>> c0[1] -> [1]aq0;
>> c1[1] -> [1]aq1;
>> c2[1] -> [1]aq2;
>>
>> c0[2] -> Paint(1) -> ip;
>> c1[2] -> Paint(2) -> ip;
>> c2[2] -> Paint(3) -> ip;
>>
>> c0[3] -> Print(a-DISCARD0) -> Discard;
>> c1[3] -> Print(a-DISCARD1) -> Discard;
>> c2[3] -> Print(a-DISCARD2) ->Discard;
>> //arpt[3] -> Discard;
>>
>>
>> rt[0] -> DropBroadcasts
>>       -> gio0 :: IPGWOptions($myaddr1)
>>       -> FixIPSrc($myaddr1)
>>       -> dt0 :: DecIPTTL
>>       -> IPPrint(a-inRT0)
>>       -> [0]aq0;
>>
>> rt[1] -> DropBroadcasts
>>       -> gio1 :: IPGWOptions($myaddr2)
>>       -> FixIPSrc($myaddr2)
>>       -> dt1 :: DecIPTTL
>>       -> IPPrint(a-inRT1)
>>       -> [0]aq1;
>>
>> rt[2] -> DropBroadcasts
>>       -> gio2 :: IPGWOptions($myaddr3)
>>       -> FixIPSrc($myaddr3)
>>       -> dt2 :: DecIPTTL
>>       -> IPPrint(a-inRT2)
>>       -> [0]aq2;
>> }
>>
>> a :: IPRouter(eth0, eth0, eth1, eth1, eth2, eth2);
>>
>>
>> 
---------------------------------------------------------------------------------------
>>
>> ns3 script
>>
>> #include <iostream>
>> #include <fstream>
>> #include <string>
>> #include <cassert>
>>
>> #include "ns3/core-module.h"
>> #include "ns3/network-module.h"
>> #include "ns3/internet-module.h"
>> #include "ns3/point-to-point-module.h"
>> #include "ns3/csma-module.h"
>> #include "ns3/applications-module.h"
>> #include "ns3/ipv4-static-routing-helper.h"
>> #include "ns3/click-internet-stack-helper.h"
>>
>> using namespace ns3;
>>
>> int main(int argc, char *argv[]) {
>>
>>   Ptr<Node> routerA = CreateObject<Node>();
>>   Ptr<Node> routerB = CreateObject<Node>();
>>   Ptr<Node> routerC = CreateObject<Node>();
>>   Ptr<Node> routerD = CreateObject<Node>();
>>   Ptr<Node> hostSrc = CreateObject<Node>();
>>   Ptr<Node> hostDst = CreateObject<Node>();
>>
>>   NodeContainer clickRouters = NodeContainer(routerA, routerD);
>>   NodeContainer routers  = NodeContainer(routerB, routerC);
>>   NodeContainer hosts = NodeContainer(hostSrc, hostDst);
>>
>>   ClickInternetStackHelper clickinternet;
>>   clickinternet.SetClickFile (routerA,
>> "scratch/nsclick-ip-routerA.click");
>>   clickinternet.SetClickFile (routerD,
>> "scratch/nsclick-ip-routerD.click");
>>   clickinternet.SetRoutingTableElement (routerA, "a/rt");
>>   clickinternet.SetRoutingTableElement (routerD, "d/rt");
>>   clickinternet.Install (clickRouters);
>>
>>   InternetStackHelper internet;
>>   internet.Install(routers);
>>   internet.Install(hosts);
>>
>>   CsmaHelper csma;
>>   csma.SetChannelAttribute ("DataRate", StringValue("5Mbps"));
>>   csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
>>   csma.SetDeviceAttribute ("Mtu", UintegerValue (1400));
>>
>>   NetDeviceContainer rArB = csma.Install(NodeContainer(routerA,routerB));
>>   NetDeviceContainer rArC = csma.Install(NodeContainer(routerA,routerC));
>>   NetDeviceContainer rBrD = csma.Install(NodeContainer(routerB,routerD));
>>   NetDeviceContainer rCrD = csma.Install(NodeContainer(routerC,routerD));
>>   NetDeviceContainer hSrA = csma.Install(NodeContainer(hostSrc,routerA));
>>   NetDeviceContainer rDhD = csma.Install(NodeContainer(routerD,hostDst));
>>
>>   Ipv4AddressHelper ipv4;
>>   ipv4.SetBase("192.168.1.0", "255.255.255.0");
>>   ipv4.Assign(rArB);
>>   ipv4.Assign(rArC);
>>   ipv4.Assign(rBrD);
>>   ipv4.Assign(rCrD);
>>
>>   ipv4.SetBase("10.1.1.0", "255.255.255.0");
>>   ipv4.Assign(hSrA);
>>   ipv4.SetBase("10.2.1.0", "255.255.255.0");
>>   ipv4.Assign(rDhD);
>>
>>   Ptr<CsmaNetDevice> netDevice = CreateObject<CsmaNetDevice>();
>>   netDevice->SetAddress(Mac48Address::Allocate());
>>   hostDst->AddDevice(netDevice);
>>
>>   Ptr<Ipv4> ipv4HostDst = hostDst->GetObject<Ipv4>();
>>   int32_t ifIndex = ipv4HostDst->AddInterface(netDevice);
>>   Ipv4InterfaceAddress ifInAddr =
>> Ipv4InterfaceAddress(Ipv4Address("10.2.1.3"), Ipv4Mask("/24"));
>>   ipv4HostDst->AddAddress(ifIndex, ifInAddr);
>>   ipv4HostDst->SetMetric(ifIndex, 1);
>>   ipv4HostDst->SetUp(ifIndex);
>>
>>   Ipv4StaticRoutingHelper ipv4RoutingHelper;
>>
>>   Ptr<Ipv4> ipv4Src = hostSrc->GetObject<Ipv4>();
>>   Ptr<Ipv4StaticRouting> staticRoutingSrc =
>> ipv4RoutingHelper.GetStaticRouting(ipv4Src);
>>   staticRoutingSrc->AddHostRouteTo(Ipv4Address("10.2.1.2"),
>> Ipv4Address("10.1.1.2"), 1);
>>   staticRoutingSrc->AddHostRouteTo(Ipv4Address("10.2.1.3"),
>> Ipv4Address("10.1.1.2"), 1);
>>
>>   Ptr<Ipv4> ipv4B = routerB->GetObject<Ipv4>();
>>   Ptr<Ipv4StaticRouting> staticRoutingB =
>> ipv4RoutingHelper.GetStaticRouting(ipv4B);
>>   staticRoutingB->AddHostRouteTo(Ipv4Address("10.2.1.2"),
>> Ipv4Address("192.168.1.6"), 2);
>>
>>   Ptr<Ipv4> ipv4C = routerC->GetObject<Ipv4>();
>>   Ptr<Ipv4StaticRouting> staticRoutingC =
>> ipv4RoutingHelper.GetStaticRouting(ipv4C);
>>   staticRoutingC->AddHostRouteTo(Ipv4Address("10.2.1.3"),
>> Ipv4Address("192.168.1.8"), 2);
>>
>>   Ptr<Ipv4> ipv4Dst = hostDst->GetObject<Ipv4>();
>>   uint16_t port = 9;   // Discard port(RFC 863)
>>
>>   OnOffHelper onoff("ns3::UdpSocketFactory",
>> Address(InetSocketAddress(ipv4Dst->GetAddress(1,0).GetLocal(), port));
>>   onoff.SetConstantRate(DataRate(6000));
>>   OnOffHelper onoff2("ns3::UdpSocketFactory",
>> Address(InetSocketAddress(ipv4Dst->GetAddress(2,0).GetLocal(), port)));
>>   onoff2.SetConstantRate(DataRate(6000));
>>
>>   ApplicationContainer apps = onoff.Install(hostSrc);
>>   ApplicationContainer apps2 = onoff2.Install(hostSrc);
>>   apps.Start(Seconds(1.0));
>>   apps.Stop(Seconds(10.0));
>>   apps2.Start(Seconds(1.0));
>>   apps2.Stop(Seconds(10.0));
>>
>>   PacketSinkHelper sink("ns3::UdpSocketFactory",
>> Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
>>   apps = sink.Install(hostDst);
>>   apps.Start(Seconds(1.0));
>>   apps.Stop(Seconds(10.0));
>>
>>   csma.EnablePcap("staticRouting-nsclick",routers,false);
>>   csma.EnablePcap("staticRouting-ns3click",clickRouters,false);
>>   csma.EnablePcap("staticRouting-ns3click",hosts,false);
>>
>>   Simulator::Run();
>>   std::cout << "Ending Simulation\n";
>>   Simulator::Destroy();
>>
>>   return 0;
>> }
>>
>>
>>
>
>
> --
> --
>  Krishna Mohan B
>