teto / pacing

Ns3 simulation code for article ....
0 stars 0 forks source link

I can not set static-routing for my NS3 #1

Open qazxswedc123654 opened 5 years ago

qazxswedc123654 commented 5 years ago
my design is as followed: R1

R0 | \ | \ | \ R1 ___ R3

I can't set a static route(R1----R3---R0). it is Directly from R1 to R0.

My code :

/ -- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -- / /*

// Test program for this 3-router scenario, using static routing // // (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)

include

include

include

include

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/ipv4-static-routing-helper.h"

include "ns3/netanim-module.h"

using namespace ns3; NS_LOG_COMPONENT_DEFINE ("StaticRoutingSlash32Test"); int main (int argc, char *argv[]) { // Allow the user to override any of the defaults and the above // DefaultValue::Bind ()s at run-time, via command-line arguments CommandLine cmd; cmd.Parse (argc, argv); NodeContainer nodes; nodes.Create (4); Ptr n0 =nodes.Get (0); Ptr n1 =nodes.Get (1); Ptr n2 =nodes.Get (2); Ptr n3 =nodes.Get (3); InternetStackHelper internet; internet.Install (nodes); // Point-to-point links NodeContainer n0n1 = NodeContainer (n0, n1); NodeContainer n0n2 = NodeContainer (n0, n2); NodeContainer n1n3 = NodeContainer (n1, n3); NodeContainer n0n3 = NodeContainer (n0, n3); // We create the channels first without any IP addressing information PointToPointHelper p2p; p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps")); p2p.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer d0d1 = p2p.Install (n0n1); NetDeviceContainer d0d2 = p2p.Install (n0n2); NetDeviceContainer d1d3 = p2p.Install (n1n3); NetDeviceContainer d0d3 = p2p.Install (n0n3); // Later, we add IP addresses. Ipv4AddressHelper ipv4; ipv4.SetBase ("10.1.1.0", "255.255.255.252"); Ipv4InterfaceContainer i0i1 = ipv4.Assign (d0d1); ipv4.SetBase ("10.1.1.4", "255.255.255.252"); Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2); ipv4.SetBase ("10.1.1.8", "255.255.255.252"); Ipv4InterfaceContainer i1i3 = ipv4.Assign (d1d3); ipv4.SetBase ("10.1.1.12", "255.255.255.252"); Ipv4InterfaceContainer i0i3 = ipv4.Assign (d0d3); Ptr ipv40 = n0->GetObject (); Ptr ipv41 = n1->GetObject (); Ptr ipv42 = n2->GetObject (); Ptr ipv43 = n3->GetObject (); Ipv4StaticRoutingHelper ipv4RoutingHelper; Ptr staticRouting1 = ipv4RoutingHelper.GetStaticRouting (ipv41); Ptr staticRouting3 = ipv4RoutingHelper.GetStaticRouting (ipv43); Ptr staticRouting0 = ipv4RoutingHelper.GetStaticRouting (ipv40); // Create static routes from 1 to 0 //1 to 3 // The ifIndex for this outbound route is 1; the first p2p link added staticRouting1->AddHostRouteTo (Ipv4Address ("10.1.1.13"), Ipv4Address ("10.1.1.10"), 1); //3 to 0 // The ifIndex we want on node B is 2; 0 corresponds to loopback, and 1 to the first point to point link staticRouting3->AddHostRouteTo (Ipv4Address ("10.1.1.13"), Ipv4Address ("10.1.1.13"), 1); // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s uint16_t port = 9; // Discard port (RFC 863) OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.1.1.13"), port))); onoff.SetConstantRate (DataRate (6000)); ApplicationContainer apps = onoff.Install (n1); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); // Create a packet sink to receive these packets PacketSinkHelper sink ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address::GetAny (), port))); apps = sink.Install (n0); apps.Start (Seconds (1.0)); apps.Stop (Seconds (10.0)); AsciiTraceHelper ascii; p2p.EnableAsciiAll (ascii.CreateFileStream ("PT.tr")); p2p.EnablePcapAll ("PT"); AnimationInterface anim("PT.xml"); anim.SetConstantPosition(nodes.Get(0), 0.0, 20.0); anim.SetConstantPosition(nodes.Get(1), 0.0, 40.0); anim.SetConstantPosition(nodes.Get(2), 0.0, 0.0); anim.SetConstantPosition(nodes.Get(3), 20.0, 40.0); Simulator::Run (); Simulator::Destroy (); return 0; } I also can not understand the following code: 1) OnOffHelper onoff ("ns3::UdpSocketFactory", Address (InetSocketAddress (Ipv4Address ("10.1.1.13"), port)));what is in the Address(InetSocketAddress()) 2)staticRouting1->AddHostRouteTo (Ipv4Address ("10.1.1.13"), Ipv4Address ("10.1.1.10"), 1); Ipv4Address ("10.1.1.13")is destination,Ipv4Address ("10.1.1.10") is next hop ,So what does 1 mean? 3)OnOffHelper onoff2 ("ns3::UdpSocketFactory",InetSocketAddress (i6i9.GetAddress (1), port2)); so what is i6i9.GetAddress (1) and port2 mean?

qazxswedc123654 commented 5 years ago

Looking forward to your reply. my mail address is shenqi1006@gmail.com or 1430874835@qq.com(China)。thanks so much.

qazxswedc123654 commented 5 years ago
sorry,it is R2

R0 | \ | \ | \ R1 ___ R3

teto commented 5 years ago

Hi, Are you using this repository's code ? The code you quote is not from this repo it seems.

qazxswedc123654 commented 5 years ago

I'm not using this repository's code.I changed something according to my own topology.

teto commented 5 years ago

hi could you share the code ? from a git repository for instance. What version of ns3 do you use ? Could you compile this repo without modification ?

qazxswedc123654 commented 5 years ago

This is the complete code (I haven't done it yet), I just need to complete a simple Ns3 topology (using global and static routes at different nodes) the version is3-28

qazxswedc123654 commented 5 years ago

It seems that it does not go R1---R3---R0 during the running process ( R0 R1 R3 has a P2P link connection with each other), and it is (R1----R0), What is the reason?

qazxswedc123654 commented 5 years ago

Hello, I don't know if you are still there, can you give me some advice?

qazxswedc123654 commented 5 years ago

hi could you share the code ? from a git repository for instance. What version of ns3 do you use ? Could you compile this repo without modification ? Hello, I don't know if you are still there, can you give me some advice? I want to know how to determine the value of 1 in sstaticRouting1->AddHostRouteTo (Ipv4Address ("10.1.1.13"), Ipv4Address ("10.1.1.10"), 1); Because I am a newbie, I don't know anything about this code.

teto commented 5 years ago

You an have a look at the documentation: https://www.nsnam.org/doxygen/classns3_1_1_ipv4_static_routing.html#ae96452233179689167e57b49b4339005 the third parameter is the interface address.

Please answer these basic questions:

qazxswedc123654 commented 5 years ago

You an have a look at the documentation: https://www.nsnam.org/doxygen/classns3_1_1_ipv4_static_routing.html#ae96452233179689167e57b49b4339005 the third parameter is the interface address.

Please answer these basic questions:

  • which version of ns3 ?
  • what are you trying to achieve ?
  • if possible, point me at the code please

thanks

qazxswedc123654 commented 5 years ago

thanks