routing problem in ns3 rip

178 views
Skip to first unread message

李楠

unread,
Jul 13, 2016, 11:39:03 PM7/13/16
to ns-3-users
I create a network like this               =========1----------2---------3==========
                                            csma1     |     |      |        p2p        p2p       |    |    |    |    csma2
                                                           4    5     6                                  7   8   9  10

I set up node 1,2,3 as routers and install RIP in them.
I set up node 4~10 as hosts and install default internet stack in them.
Then, I make node 4 send upd packets to node 7,but node 7 has never received the data.

And, if I install RIP in each node, it works.

Why?   Please give me some advice or hints. Thanks!

The next is my code:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.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 ("Rip-test");


int main (int argc, char **argv)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

CommandLine cmd;
cmd.Parse (argc, argv);

uint32_t np2p = 3;
uint32_t ncsma1 =3;
uint32_t ncsma2 =4;

NodeContainer p2pNodes;
p2pNodes.Create (np2p);

RipHelper ripRouting;
  Ipv4ListRoutingHelper RHlist;
  RHlist.Add (ripRouting, 1);


  InternetStackHelper stack1;
  stack1.SetRoutingHelper (RHlist);
  stack1.Install (p2pNodes);

  PointToPointHelper p2pHelper;
    p2pHelper.SetDeviceAttribute ("DataRate", StringValue ("50Mbps"));
    p2pHelper.SetChannelAttribute ("Delay", StringValue ("1ms")); 


  NetDeviceContainer p2pDevices1 = p2pHelper.Install (p2pNodes.Get(0) , p2pNodes.Get(1)); 
NetDeviceContainer p2pDevices2 = p2pHelper.Install (p2pNodes.Get(1) , p2pNodes.Get(2));


Ipv4AddressHelper ipv4;
ipv4.SetBase (Ipv4Address ("10.0.0.0"), Ipv4Mask ("255.255.255.0"));
Ipv4InterfaceContainer p2p1 = ipv4.Assign (p2pDevices1);
ipv4.SetBase (Ipv4Address ("10.0.1.0"), Ipv4Mask ("255.255.255.0"));
Ipv4InterfaceContainer p2p2 = ipv4.Assign (p2pDevices2);




NodeContainer csma1Nodes;
  csma1Nodes.Create (ncsma1);

  NodeContainer csma2Nodes;
csma2Nodes.Create (ncsma2);

InternetStackHelper stack2;
  stack2.Install (csma1Nodes);
  stack2.Install (csma2Nodes);

  csma1Nodes.Add (p2pNodes.Get (0));
  csma2Nodes.Add (p2pNodes.Get (np2p - 1));

  CsmaHelper csmaHelper;
  csmaHelper.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));  
  csmaHelper.SetChannelAttribute ("Delay", TimeValue (MicroSeconds (5)));

  NetDeviceContainer csma1Devices = csmaHelper.Install (csma1Nodes);
  NetDeviceContainer csma2Devices = csmaHelper.Install (csma2Nodes);

  ipv4.SetBase (Ipv4Address ("10.0.2.0"), Ipv4Mask ("255.255.255.0"));
  Ipv4InterfaceContainer csma1 = ipv4.Assign (csma1Devices);
  ipv4.SetBase (Ipv4Address ("10.0.3.0"), Ipv4Mask ("255.255.255.0"));
  Ipv4InterfaceContainer csma2 = ipv4.Assign (csma2Devices);


  UdpEchoServerHelper echoServer (9);
  ApplicationContainer serverApps = echoServer.Install (csma1Nodes.Get (0));
  serverApps.Start (Seconds (10.0));
  serverApps.Stop (Seconds (500.0));

  UdpEchoClientHelper echoClient (csma1.GetAddress (0), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (500));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1)));
  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

  ApplicationContainer clientApps = echoClient.Install (csma2Nodes.Get (0));
  clientApps.Start (Seconds (50.0));
  clientApps.Stop (Seconds (500.0));

  Simulator::Run ();
  Simulator::Destroy ();

  return 0;


}


李楠

unread,
Jul 14, 2016, 3:53:41 AM7/14/16
to ns-3-users
ok.I find the answer,we should set the default route for host.
I add some codes,it works.

   Ptr<Ipv4StaticRouting> staticRouting;
  staticRouting = Ipv4RoutingHelper::GetRouting <Ipv4StaticRouting> (csma2Nodes.Get (0)->GetObject<Ipv4> ()->GetRoutingProtocol ());
  staticRouting->SetDefaultRoute ("10.0.3.5", 1 );
  staticRouting = Ipv4RoutingHelper::GetRouting <Ipv4StaticRouting> (csma1Nodes.Get (0)->GetObject<Ipv4> ()->GetRoutingProtocol ());
  staticRouting->SetDefaultRoute ("10.0.2.4", 1 );

在 2016年7月14日星期四 UTC+8上午11:39:03,李楠写道:

Tommaso Pecorella

unread,
Jul 14, 2016, 4:48:50 AM7/14/16
to ns-3-users
Please check the rip example in "examples/routing/rip-simple-network.cc", the answer is there.
Shortly put: you forgot to install a default route in the nodes (the routers doesn't need it).

T.

李楠

unread,
Jul 14, 2016, 7:34:00 AM7/14/16
to ns-3-users
Thanks !

在 2016年7月14日星期四 UTC+8下午4:48:50,Tommaso Pecorella写道:
Reply all
Reply to author
Forward
0 new messages