split examples, add examples, tweak test.py to minimize builds
This commit is contained in:
231
examples/routing/dynamic-global-routing.cc
Normal file
231
examples/routing/dynamic-global-routing.cc
Normal file
@@ -0,0 +1,231 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Contributed by: Luis Cortes (cortes@gatech.edu)
|
||||
*/
|
||||
|
||||
|
||||
// This script exercises global routing code in a mixed point-to-point
|
||||
// and csma/cd environment
|
||||
//
|
||||
// Network topology
|
||||
//
|
||||
// n0
|
||||
// \ p-p
|
||||
// \ (shared csma/cd)
|
||||
// n2 -------------------------n3
|
||||
// / | |
|
||||
// / p-p n4 n5 ---------- n6
|
||||
// n1 p-p
|
||||
// | |
|
||||
// ----------------------------------------
|
||||
// p-p
|
||||
//
|
||||
// - at time 1 CBR/UDP flow from n1 to n6's IP address on the n5/n6 link
|
||||
// - at time 10, start similar flow from n1 to n6's address on the n1/n6 link
|
||||
//
|
||||
// Order of events
|
||||
// At pre-simulation time, configure global routes. Shortest path from
|
||||
// n1 to n6 is via the direct point-to-point link
|
||||
// At time 1s, start CBR traffic flow from n1 to n6
|
||||
// At time 2s, set the n1 point-to-point interface to down. Packets
|
||||
// will start to be dropped
|
||||
// At time 3s, call RecomputeRoutingTables() and traffic will
|
||||
// start flowing again on the alternate path
|
||||
// At time 4s, re-enable the n1/n6 interface to up. Will not change routing
|
||||
// At time 5s, call RecomputeRoutingTables() and traffic will start flowing
|
||||
// again on the original path
|
||||
// At time 6s, set the n6-n1 point-to-point Ipv4 interface to down (note, this
|
||||
// keeps the point-to-point link "up" from n1's perspective). Packets
|
||||
// will traverse the link and be dropped at n6 upon receipt. These drops
|
||||
// are not visible in the pcap trace but in the ascii trace.
|
||||
// At time 7s, call RecomputeRoutingTables() and traffic will flow again
|
||||
// through the path n1-n2-n5-n6
|
||||
// At time 8s, bring the interface back up.
|
||||
// At time 9s, call RecomputeRoutingTables() and traffic will flow again
|
||||
// through the path n1-n6
|
||||
// At time 10s, stop the first flow.
|
||||
// At time 11s, start a new flow, but to n6's other IP address (the one
|
||||
// on the n1/n6 p2p link)
|
||||
// At time 12s, bring the n1 interface down between n1 and n6. Packets
|
||||
// will start to be dropped
|
||||
// At time 13s, call RecomputeRoutingTables() and traffic will
|
||||
// start flowing again on the alternate path
|
||||
// At time 14s, re-enable the n1/n6 interface to up. This will change
|
||||
// routing back to n1-n6 since the interface up notification will cause
|
||||
// a new local interface route, at higher priority than global routing
|
||||
// At time 15s, call RecomputeRoutingTables(), but there is no effect
|
||||
// since global routing is lower in priority than static routing
|
||||
// At time 16s, stop the second flow.
|
||||
|
||||
// - Tracing of queues and packet receptions to file "dynamic-global-routing.tr"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("DynamicGlobalRoutingExample");
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
// Allow the user to override any of the defaults and the above
|
||||
// Bind ()s at run-time, via command-line arguments
|
||||
CommandLine cmd;
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
NS_LOG_INFO ("Create nodes.");
|
||||
NodeContainer c;
|
||||
c.Create (7);
|
||||
NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
|
||||
NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
|
||||
NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6));
|
||||
NodeContainer n1n6 = NodeContainer (c.Get (1), c.Get (6));
|
||||
NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5));
|
||||
|
||||
InternetStackHelper internet;
|
||||
internet.Install (c);
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
NS_LOG_INFO ("Create channels.");
|
||||
PointToPointHelper p2p;
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer d0d2 = p2p.Install (n0n2);
|
||||
NetDeviceContainer d1d6 = p2p.Install (n1n6);
|
||||
|
||||
NetDeviceContainer d1d2 = p2p.Install (n1n2);
|
||||
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
|
||||
NetDeviceContainer d5d6 = p2p.Install (n5n6);
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
CsmaHelper csma;
|
||||
csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer d2345 = csma.Install (n2345);
|
||||
|
||||
// Later, we add IP addresses.
|
||||
NS_LOG_INFO ("Assign IP Addresses.");
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
||||
ipv4.Assign (d0d2);
|
||||
|
||||
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
|
||||
ipv4.Assign (d1d2);
|
||||
|
||||
ipv4.SetBase ("10.1.3.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6);
|
||||
|
||||
ipv4.SetBase ("10.250.1.0", "255.255.255.0");
|
||||
ipv4.Assign (d2345);
|
||||
|
||||
ipv4.SetBase ("172.16.1.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i1i6 = ipv4.Assign (d1d6);
|
||||
|
||||
// Create router nodes, initialize routing database and set up the routing
|
||||
// tables in the nodes.
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
// Create the OnOff application to send UDP datagrams of size
|
||||
// 210 bytes at a rate of 448 Kb/s
|
||||
NS_LOG_INFO ("Create Applications.");
|
||||
uint16_t port = 9; // Discard port (RFC 863)
|
||||
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
||||
InetSocketAddress (i5i6.GetAddress (1), port));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
onoff.SetAttribute ("DataRate", StringValue ("2kbps"));
|
||||
onoff.SetAttribute ("PacketSize", UintegerValue (50));
|
||||
|
||||
ApplicationContainer apps = onoff.Install (c.Get (1));
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
// Create a second OnOff application to send UDP datagrams of size
|
||||
// 210 bytes at a rate of 448 Kb/s
|
||||
OnOffHelper onoff2 ("ns3::UdpSocketFactory",
|
||||
InetSocketAddress (i1i6.GetAddress (1), port));
|
||||
onoff2.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff2.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
onoff2.SetAttribute ("DataRate", StringValue ("2kbps"));
|
||||
onoff2.SetAttribute ("PacketSize", UintegerValue (50));
|
||||
|
||||
ApplicationContainer apps2 = onoff2.Install (c.Get (1));
|
||||
apps2.Start (Seconds (11.0));
|
||||
apps2.Stop (Seconds (16.0));
|
||||
|
||||
// Create an optional packet sink to receive these packets
|
||||
PacketSinkHelper sink ("ns3::UdpSocketFactory",
|
||||
Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
|
||||
apps = sink.Install (c.Get (6));
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
PacketSinkHelper sink2 ("ns3::UdpSocketFactory",
|
||||
Address (InetSocketAddress (Ipv4Address::GetAny (), port)));
|
||||
apps2 = sink2.Install (c.Get (6));
|
||||
apps2.Start (Seconds (11.0));
|
||||
apps2.Stop (Seconds (16.0));
|
||||
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("dynamic-global-routing.tr", std::ios_base::binary | std::ios_base::out);
|
||||
PointToPointHelper::EnablePcapAll ("dynamic-global-routing");
|
||||
PointToPointHelper::EnableAsciiAll (ascii);
|
||||
CsmaHelper::EnablePcapAll ("dynamic-global-routing", false);
|
||||
CsmaHelper::EnableAsciiAll (ascii);
|
||||
InternetStackHelper::EnableAsciiAll (ascii);
|
||||
|
||||
Ptr<Node> n1 = c.Get (1);
|
||||
Ptr<Ipv4> ipv41 = n1->GetObject<Ipv4> ();
|
||||
// The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
|
||||
// then the next p2p is numbered 2
|
||||
uint32_t ipv4ifIndex1 = 2;
|
||||
|
||||
Simulator::Schedule (Seconds (2),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
|
||||
Simulator::Schedule (Seconds (3),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
|
||||
Simulator::Schedule (Seconds (4),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
|
||||
Simulator::Schedule (Seconds (5),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
|
||||
|
||||
Ptr<Node> n6 = c.Get (6);
|
||||
Ptr<Ipv4> ipv46 = n6->GetObject<Ipv4> ();
|
||||
// The first ifIndex is 0 for loopback, then the first p2p is numbered 1,
|
||||
// then the next p2p is numbered 2
|
||||
uint32_t ipv4ifIndex6 = 2;
|
||||
Simulator::Schedule (Seconds (6),&Ipv4::SetDown,ipv46, ipv4ifIndex6);
|
||||
Simulator::Schedule (Seconds (7),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
|
||||
Simulator::Schedule (Seconds (8),&Ipv4::SetUp,ipv46, ipv4ifIndex6);
|
||||
Simulator::Schedule (Seconds (9),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
|
||||
|
||||
Simulator::Schedule (Seconds (12),&Ipv4::SetDown,ipv41, ipv4ifIndex1);
|
||||
Simulator::Schedule (Seconds (13),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
|
||||
Simulator::Schedule (Seconds (14),&Ipv4::SetUp,ipv41, ipv4ifIndex1);
|
||||
Simulator::Schedule (Seconds (15),&Ipv4GlobalRoutingHelper::RecomputeRoutingTables);
|
||||
|
||||
NS_LOG_INFO ("Run Simulation.");
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
NS_LOG_INFO ("Done.");
|
||||
}
|
||||
158
examples/routing/global-injection-slash32.cc
Normal file
158
examples/routing/global-injection-slash32.cc
Normal file
@@ -0,0 +1,158 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
// Test program for this 3-router scenario, using global 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 <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "ns3/csma-net-device.h"
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
#include "ns3/ipv4-static-routing.h"
|
||||
#include "ns3/ipv4-global-routing.h"
|
||||
#include "ns3/ipv4-list-routing.h"
|
||||
#include "ns3/ipv4-routing-table-entry.h"
|
||||
#include "ns3/global-router-interface.h"
|
||||
|
||||
using namespace ns3;
|
||||
using std::cout;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("GlobalRouterInjectionTest");
|
||||
|
||||
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);
|
||||
|
||||
Ptr<Node> nA = CreateObject<Node> ();
|
||||
Ptr<Node> nB = CreateObject<Node> ();
|
||||
Ptr<Node> nC = CreateObject<Node> ();
|
||||
|
||||
NodeContainer c = NodeContainer (nA, nB, nC);
|
||||
|
||||
InternetStackHelper internet;
|
||||
|
||||
// Point-to-point links
|
||||
NodeContainer nAnB = NodeContainer (nA, nB);
|
||||
NodeContainer nBnC = NodeContainer (nB, nC);
|
||||
|
||||
internet.Install (nAnB);
|
||||
Ipv4ListRoutingHelper staticonly;
|
||||
Ipv4ListRoutingHelper staticRouting;
|
||||
staticonly.Add(staticRouting, 0);
|
||||
internet.SetRoutingHelper(staticonly);
|
||||
internet.Install(NodeContainer(nC));
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
PointToPointHelper p2p;
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer dAdB = p2p.Install (nAnB);
|
||||
|
||||
NetDeviceContainer dBdC = p2p.Install (nBnC);;
|
||||
|
||||
Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
|
||||
deviceA->SetAddress (Mac48Address::Allocate ());
|
||||
nA->AddDevice (deviceA);
|
||||
|
||||
Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
|
||||
deviceC->SetAddress (Mac48Address::Allocate ());
|
||||
nC->AddDevice (deviceC);
|
||||
|
||||
// Later, we add IP addresses.
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.252");
|
||||
Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
|
||||
|
||||
ipv4.SetBase ("10.1.1.4", "255.255.255.252");
|
||||
Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
|
||||
|
||||
Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
|
||||
Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> ();
|
||||
Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
|
||||
|
||||
int32_t ifIndexA = ipv4A->AddInterface (deviceA);
|
||||
int32_t ifIndexC = ipv4C->AddInterface (deviceC);
|
||||
|
||||
Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
|
||||
ipv4A->AddAddress (ifIndexA, ifInAddrA);
|
||||
ipv4A->SetMetric (ifIndexA, 1);
|
||||
ipv4A->SetUp (ifIndexA);
|
||||
|
||||
Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
|
||||
ipv4C->AddAddress (ifIndexC, ifInAddrC);
|
||||
ipv4C->SetMetric (ifIndexC, 1);
|
||||
ipv4C->SetUp (ifIndexC);
|
||||
|
||||
// Create router nodes, initialize routing database and set up the routing
|
||||
// tables in the nodes.
|
||||
|
||||
// Populate routing tables for nodes nA and nB
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
// Inject global routes from Node B, including transit network...
|
||||
Ptr<GlobalRouter> globalRouterB = nB->GetObject<GlobalRouter> ();
|
||||
globalRouterB->InjectRoute ("10.1.1.4", "255.255.255.252");
|
||||
// ...and the host in network "C"
|
||||
globalRouterB->InjectRoute ("192.168.1.1", "255.255.255.255");
|
||||
|
||||
Ipv4GlobalRoutingHelper::RecomputeRoutingTables();
|
||||
// In addition, nB needs a static route to nC so it knows what to do with stuff
|
||||
// going to 192.168.1.1
|
||||
Ipv4StaticRoutingHelper ipv4RoutingHelper;
|
||||
Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting(ipv4B);
|
||||
staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"),2);
|
||||
|
||||
// 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 (ifInAddrC.GetLocal(), port)));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
|
||||
ApplicationContainer apps = onoff.Install (nA);
|
||||
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 (nC);
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("global-routing-injection32.tr", std::ios_base::binary | std::ios_base::out);
|
||||
PointToPointHelper::EnablePcapAll ("global-routing-injection32");
|
||||
PointToPointHelper::EnableAsciiAll (ascii);
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
131
examples/routing/global-routing-slash32.cc
Normal file
131
examples/routing/global-routing-slash32.cc
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
// Test program for this 3-router scenario, using global 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 <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "ns3/csma-net-device.h"
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("GlobalRouterSlash32Test");
|
||||
|
||||
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);
|
||||
|
||||
Ptr<Node> nA = CreateObject<Node> ();
|
||||
Ptr<Node> nB = CreateObject<Node> ();
|
||||
Ptr<Node> nC = CreateObject<Node> ();
|
||||
|
||||
NodeContainer c = NodeContainer (nA, nB, nC);
|
||||
|
||||
InternetStackHelper internet;
|
||||
internet.Install (c);
|
||||
|
||||
// Point-to-point links
|
||||
NodeContainer nAnB = NodeContainer (nA, nB);
|
||||
NodeContainer nBnC = NodeContainer (nB, nC);
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
PointToPointHelper p2p;
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer dAdB = p2p.Install (nAnB);
|
||||
|
||||
NetDeviceContainer dBdC = p2p.Install (nBnC);;
|
||||
|
||||
Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
|
||||
deviceA->SetAddress (Mac48Address::Allocate ());
|
||||
nA->AddDevice (deviceA);
|
||||
|
||||
Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
|
||||
deviceC->SetAddress (Mac48Address::Allocate ());
|
||||
nC->AddDevice (deviceC);
|
||||
|
||||
// Later, we add IP addresses.
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.252");
|
||||
Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
|
||||
|
||||
ipv4.SetBase ("10.1.1.4", "255.255.255.252");
|
||||
Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
|
||||
|
||||
Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
|
||||
Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
|
||||
|
||||
int32_t ifIndexA = ipv4A->AddInterface (deviceA);
|
||||
int32_t ifIndexC = ipv4C->AddInterface (deviceC);
|
||||
|
||||
Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("255.255.255.255"));
|
||||
ipv4A->AddAddress (ifIndexA, ifInAddrA);
|
||||
ipv4A->SetMetric (ifIndexA, 1);
|
||||
ipv4A->SetUp (ifIndexA);
|
||||
|
||||
Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("255.255.255.255"));
|
||||
ipv4C->AddAddress (ifIndexC, ifInAddrC);
|
||||
ipv4C->SetMetric (ifIndexC, 1);
|
||||
ipv4C->SetUp (ifIndexC);
|
||||
|
||||
// Create router nodes, initialize routing database and set up the routing
|
||||
// tables in the nodes.
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
// 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 (ifInAddrC.GetLocal(), port)));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
|
||||
ApplicationContainer apps = onoff.Install (nA);
|
||||
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 (nC);
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("global-routing-slash32.tr", std::ios_base::binary | std::ios_base::out);
|
||||
PointToPointHelper::EnablePcapAll ("global-routing-slash32");
|
||||
PointToPointHelper::EnableAsciiAll (ascii);
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
135
examples/routing/mixed-global-routing.cc
Normal file
135
examples/routing/mixed-global-routing.cc
Normal file
@@ -0,0 +1,135 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
// This script exercises global routing code in a mixed point-to-point
|
||||
// and csma/cd environment
|
||||
//
|
||||
// Network topology
|
||||
//
|
||||
// n0
|
||||
// \ p-p
|
||||
// \ (shared csma/cd)
|
||||
// n2 -------------------------n3
|
||||
// / | |
|
||||
// / p-p n4 n5 ---------- n6
|
||||
// n1 p-p
|
||||
//
|
||||
// - CBR/UDP flows from n0 to n6
|
||||
// - Tracing of queues and packet receptions to file "mixed-global-routing.tr"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("MixedGlobalRoutingExample");
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
|
||||
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
|
||||
|
||||
// Allow the user to override any of the defaults and the above
|
||||
// Bind ()s at run-time, via command-line arguments
|
||||
CommandLine cmd;
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
NS_LOG_INFO ("Create nodes.");
|
||||
NodeContainer c;
|
||||
c.Create (7);
|
||||
NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
|
||||
NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
|
||||
NodeContainer n5n6 = NodeContainer (c.Get (5), c.Get (6));
|
||||
NodeContainer n2345 = NodeContainer (c.Get (2), c.Get (3), c.Get (4), c.Get (5));
|
||||
|
||||
InternetStackHelper internet;
|
||||
internet.Install (c);
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
NS_LOG_INFO ("Create channels.");
|
||||
PointToPointHelper p2p;
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer d0d2 = p2p.Install (n0n2);
|
||||
|
||||
NetDeviceContainer d1d2 = p2p.Install (n1n2);
|
||||
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
|
||||
NetDeviceContainer d5d6 = p2p.Install (n5n6);
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
CsmaHelper csma;
|
||||
csma.SetChannelAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer d2345 = csma.Install (n2345);
|
||||
|
||||
// Later, we add IP addresses.
|
||||
NS_LOG_INFO ("Assign IP Addresses.");
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
||||
ipv4.Assign (d0d2);
|
||||
|
||||
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
|
||||
ipv4.Assign (d1d2);
|
||||
|
||||
ipv4.SetBase ("10.1.3.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i5i6 = ipv4.Assign (d5d6);
|
||||
|
||||
ipv4.SetBase ("10.250.1.0", "255.255.255.0");
|
||||
ipv4.Assign (d2345);
|
||||
|
||||
// Create router nodes, initialize routing database and set up the routing
|
||||
// tables in the nodes.
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
// Create the OnOff application to send UDP datagrams of size
|
||||
// 210 bytes at a rate of 448 Kb/s
|
||||
NS_LOG_INFO ("Create Applications.");
|
||||
uint16_t port = 9; // Discard port (RFC 863)
|
||||
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
||||
InetSocketAddress (i5i6.GetAddress (1), port));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
onoff.SetAttribute ("DataRate", StringValue ("300bps"));
|
||||
onoff.SetAttribute ("PacketSize", UintegerValue (50));
|
||||
|
||||
ApplicationContainer apps = onoff.Install (c.Get (0));
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("mixed-global-routing.tr");
|
||||
PointToPointHelper::EnablePcapAll ("mixed-global-routing");
|
||||
PointToPointHelper::EnableAsciiAll (ascii);
|
||||
CsmaHelper::EnablePcapAll ("mixed-global-routing", false);
|
||||
CsmaHelper::EnableAsciiAll (ascii);
|
||||
|
||||
|
||||
NS_LOG_INFO ("Run Simulation.");
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
NS_LOG_INFO ("Done.");
|
||||
}
|
||||
114
examples/routing/nix-simple.cc
Normal file
114
examples/routing/nix-simple.cc
Normal file
@@ -0,0 +1,114 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
/*
|
||||
* Simple point to point links:
|
||||
*
|
||||
* n0 -- n1 -- n2 -- n3
|
||||
*
|
||||
* n0 has UdpEchoClient
|
||||
* n3 has UdpEchoServer
|
||||
*
|
||||
* n0 IP: 10.1.1.1
|
||||
* n1 IP: 10.1.1.2, 10.1.2.1
|
||||
* n2 IP: 10.1.2.2, 10.1.3.1
|
||||
* n3 IP: 10.1.3.2
|
||||
*
|
||||
*/
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
||||
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
|
||||
|
||||
NodeContainer nodes12;
|
||||
nodes12.Create (2);
|
||||
|
||||
NodeContainer nodes23;
|
||||
nodes23.Add (nodes12.Get (1));
|
||||
nodes23.Create (1);
|
||||
|
||||
NodeContainer nodes34;
|
||||
nodes34.Add(nodes23.Get (1));
|
||||
nodes34.Create (1);
|
||||
|
||||
PointToPointHelper pointToPoint;
|
||||
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
|
||||
NodeContainer allNodes = NodeContainer (nodes12, nodes23.Get (1), nodes34.Get (1));
|
||||
|
||||
// NixHelper to install nix-vector routing
|
||||
// on all nodes
|
||||
Ipv4NixVectorHelper nixRouting;
|
||||
Ipv4StaticRoutingHelper staticRouting;
|
||||
|
||||
Ipv4ListRoutingHelper list;
|
||||
list.Add (staticRouting, 0);
|
||||
list.Add (nixRouting, 10);
|
||||
|
||||
InternetStackHelper stack;
|
||||
stack.SetRoutingHelper (list);
|
||||
stack.Install (allNodes);
|
||||
|
||||
NetDeviceContainer devices12;
|
||||
NetDeviceContainer devices23;
|
||||
NetDeviceContainer devices34;
|
||||
devices12 = pointToPoint.Install (nodes12);
|
||||
devices23 = pointToPoint.Install (nodes23);
|
||||
devices34 = pointToPoint.Install (nodes34);
|
||||
|
||||
Ipv4AddressHelper address1;
|
||||
address1.SetBase ("10.1.1.0", "255.255.255.0");
|
||||
Ipv4AddressHelper address2;
|
||||
address2.SetBase ("10.1.2.0", "255.255.255.0");
|
||||
Ipv4AddressHelper address3;
|
||||
address3.SetBase ("10.1.3.0", "255.255.255.0");
|
||||
|
||||
address1.Assign (devices12);
|
||||
address2.Assign (devices23);
|
||||
Ipv4InterfaceContainer interfaces = address3.Assign (devices34);
|
||||
|
||||
UdpEchoServerHelper echoServer (9);
|
||||
|
||||
ApplicationContainer serverApps = echoServer.Install (nodes34.Get (1));
|
||||
serverApps.Start (Seconds (1.0));
|
||||
serverApps.Stop (Seconds (10.0));
|
||||
|
||||
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
|
||||
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
|
||||
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
|
||||
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
|
||||
|
||||
ApplicationContainer clientApps = echoClient.Install (nodes12.Get (0));
|
||||
clientApps.Start (Seconds (2.0));
|
||||
clientApps.Stop (Seconds (10.0));
|
||||
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
return 0;
|
||||
}
|
||||
458
examples/routing/nms-p2p-nix.cc
Normal file
458
examples/routing/nms-p2p-nix.cc
Normal file
@@ -0,0 +1,458 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
// DARPA NMS Campus Network Model
|
||||
//
|
||||
// - This topology replicates the original NMS Campus Network model
|
||||
// with the exception of chord links (which were never utilized in the
|
||||
// original model)
|
||||
// - Link Bandwidths and Delays may not be the same as the original
|
||||
// specifications
|
||||
//
|
||||
// (c)2009, GTech Systems, Inc. - Alfred Park <park@gtech-systems.com>
|
||||
|
||||
// for timing functions
|
||||
#include <cstdlib>
|
||||
#include <sys/time.h>
|
||||
#include <fstream>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
#include "ns3/global-routing-module.h"
|
||||
#include "ns3/onoff-application.h"
|
||||
#include "ns3/packet-sink.h"
|
||||
#include "ns3/point-to-point-net-device.h"
|
||||
#include "ns3/simulator.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace ns3;
|
||||
|
||||
typedef struct timeval TIMER_TYPE;
|
||||
#define TIMER_NOW(_t) gettimeofday(&_t,NULL);
|
||||
#define TIMER_SECONDS(_t) ((double)(_t).tv_sec + (_t).tv_usec*1e-6)
|
||||
#define TIMER_DIFF(_t1, _t2) (TIMER_SECONDS(_t1)-TIMER_SECONDS(_t2))
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("CampusNetworkModel");
|
||||
|
||||
void Progress ()
|
||||
{
|
||||
Time now = Simulator::Now ();
|
||||
Simulator::Schedule (Seconds (0.1), Progress);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
//Config::SetDefault ("ns3::Simulator::SchedulerType", StringValue ("ns3::CalendarScheduler"));
|
||||
TIMER_TYPE t0, t1, t2;
|
||||
TIMER_NOW(t0);
|
||||
cout << " ==== DARPA NMS CAMPUS NETWORK SIMULATION ====" << endl;
|
||||
LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
|
||||
|
||||
//RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
|
||||
|
||||
int nCN = 2, nLANClients = 42;
|
||||
bool nix = true;
|
||||
|
||||
CommandLine cmd;
|
||||
cmd.AddValue ("CN", "Number of total CNs [2]", nCN);
|
||||
cmd.AddValue ("LAN", "Number of nodes per LAN [42]", nLANClients);
|
||||
cmd.AddValue ("NIX", "Toggle nix-vector routing", nix);
|
||||
cmd.Parse (argc,argv);
|
||||
|
||||
if (nCN < 2)
|
||||
{
|
||||
cout << "Number of total CNs (" << nCN << ") lower than minimum of 2"
|
||||
<< endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << "Number of CNs: " << nCN << ", LAN nodes: " << nLANClients << endl;
|
||||
|
||||
NodeContainer nodes_net0[nCN][3], nodes_net1[nCN][6], nodes_netLR[nCN],
|
||||
nodes_net2[nCN][14], nodes_net2LAN[nCN][7][nLANClients],
|
||||
nodes_net3[nCN][9], nodes_net3LAN[nCN][5][nLANClients];
|
||||
PointToPointHelper p2p_2gb200ms, p2p_1gb5ms, p2p_100mb1ms;
|
||||
InternetStackHelper stack;
|
||||
Ipv4InterfaceContainer ifs, ifs0[nCN][3], ifs1[nCN][6], ifs2[nCN][14],
|
||||
ifs3[nCN][9], ifs2LAN[nCN][7][nLANClients],
|
||||
ifs3LAN[nCN][5][nLANClients];
|
||||
Ipv4AddressHelper address;
|
||||
std::ostringstream oss;
|
||||
p2p_1gb5ms.SetDeviceAttribute ("DataRate", StringValue ("1Gbps"));
|
||||
p2p_1gb5ms.SetChannelAttribute ("Delay", StringValue ("5ms"));
|
||||
p2p_2gb200ms.SetDeviceAttribute ("DataRate", StringValue ("2Gbps"));
|
||||
p2p_2gb200ms.SetChannelAttribute ("Delay", StringValue ("200ms"));
|
||||
p2p_100mb1ms.SetDeviceAttribute ("DataRate", StringValue ("100Mbps"));
|
||||
p2p_100mb1ms.SetChannelAttribute ("Delay", StringValue ("1ms"));
|
||||
|
||||
// Setup NixVector Routing
|
||||
Ipv4NixVectorHelper nixRouting;
|
||||
Ipv4StaticRoutingHelper staticRouting;
|
||||
|
||||
Ipv4ListRoutingHelper list;
|
||||
list.Add (staticRouting, 0);
|
||||
list.Add (nixRouting, 10);
|
||||
|
||||
if (nix)
|
||||
{
|
||||
stack.SetRoutingHelper (list);
|
||||
}
|
||||
|
||||
// Create Campus Networks
|
||||
for (int z = 0; z < nCN; ++z)
|
||||
{
|
||||
cout << "Creating Campus Network " << z << ":" << endl;
|
||||
// Create Net0
|
||||
cout << " SubNet [ 0";
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
nodes_net0[z][i].Create (1);
|
||||
stack.Install (nodes_net0[z][i]);
|
||||
}
|
||||
nodes_net0[z][0].Add (nodes_net0[z][1].Get (0));
|
||||
nodes_net0[z][1].Add (nodes_net0[z][2].Get (0));
|
||||
nodes_net0[z][2].Add (nodes_net0[z][0].Get (0));
|
||||
NetDeviceContainer ndc0[3];
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
ndc0[i] = p2p_1gb5ms.Install (nodes_net0[z][i]);
|
||||
}
|
||||
// Create Net1
|
||||
cout << " 1";
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
nodes_net1[z][i].Create (1);
|
||||
stack.Install (nodes_net1[z][i]);
|
||||
}
|
||||
nodes_net1[z][0].Add (nodes_net1[z][1].Get (0));
|
||||
nodes_net1[z][2].Add (nodes_net1[z][0].Get (0));
|
||||
nodes_net1[z][3].Add (nodes_net1[z][0].Get (0));
|
||||
nodes_net1[z][4].Add (nodes_net1[z][1].Get (0));
|
||||
nodes_net1[z][5].Add (nodes_net1[z][1].Get (0));
|
||||
NetDeviceContainer ndc1[6];
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
if (i == 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ndc1[i] = p2p_1gb5ms.Install (nodes_net1[z][i]);
|
||||
}
|
||||
// Connect Net0 <-> Net1
|
||||
NodeContainer net0_1;
|
||||
net0_1.Add (nodes_net0[z][2].Get (0));
|
||||
net0_1.Add (nodes_net1[z][0].Get (0));
|
||||
NetDeviceContainer ndc0_1;
|
||||
ndc0_1 = p2p_1gb5ms.Install (net0_1);
|
||||
oss.str("");
|
||||
oss << 10 + z << ".1.252.0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndc0_1);
|
||||
// Create Net2
|
||||
cout << " 2";
|
||||
for (int i = 0; i < 14; ++i)
|
||||
{
|
||||
nodes_net2[z][i].Create (1);
|
||||
stack.Install (nodes_net2[z][i]);
|
||||
}
|
||||
nodes_net2[z][0].Add (nodes_net2[z][1].Get (0));
|
||||
nodes_net2[z][2].Add (nodes_net2[z][0].Get (0));
|
||||
nodes_net2[z][1].Add (nodes_net2[z][3].Get (0));
|
||||
nodes_net2[z][3].Add (nodes_net2[z][2].Get (0));
|
||||
nodes_net2[z][4].Add (nodes_net2[z][2].Get (0));
|
||||
nodes_net2[z][5].Add (nodes_net2[z][3].Get (0));
|
||||
nodes_net2[z][6].Add (nodes_net2[z][5].Get (0));
|
||||
nodes_net2[z][7].Add (nodes_net2[z][2].Get (0));
|
||||
nodes_net2[z][8].Add (nodes_net2[z][3].Get (0));
|
||||
nodes_net2[z][9].Add (nodes_net2[z][4].Get (0));
|
||||
nodes_net2[z][10].Add (nodes_net2[z][5].Get (0));
|
||||
nodes_net2[z][11].Add (nodes_net2[z][6].Get (0));
|
||||
nodes_net2[z][12].Add (nodes_net2[z][6].Get (0));
|
||||
nodes_net2[z][13].Add (nodes_net2[z][6].Get (0));
|
||||
NetDeviceContainer ndc2[14];
|
||||
for (int i = 0; i < 14; ++i)
|
||||
{
|
||||
ndc2[i] = p2p_1gb5ms.Install (nodes_net2[z][i]);
|
||||
}
|
||||
NetDeviceContainer ndc2LAN[7][nLANClients];
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".4." << 15 + i << ".0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
for (int j = 0; j < nLANClients; ++j)
|
||||
{
|
||||
nodes_net2LAN[z][i][j].Create (1);
|
||||
stack.Install (nodes_net2LAN[z][i][j]);
|
||||
nodes_net2LAN[z][i][j].Add (nodes_net2[z][i+7].Get (0));
|
||||
ndc2LAN[i][j] = p2p_100mb1ms.Install (nodes_net2LAN[z][i][j]);
|
||||
ifs2LAN[z][i][j] = address.Assign (ndc2LAN[i][j]);
|
||||
}
|
||||
}
|
||||
// Create Net3
|
||||
cout << " 3 ]" << endl;
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
nodes_net3[z][i].Create (1);
|
||||
stack.Install(nodes_net3[z][i]);
|
||||
}
|
||||
nodes_net3[z][0].Add (nodes_net3[z][1].Get (0));
|
||||
nodes_net3[z][1].Add (nodes_net3[z][2].Get (0));
|
||||
nodes_net3[z][2].Add (nodes_net3[z][3].Get (0));
|
||||
nodes_net3[z][3].Add (nodes_net3[z][1].Get (0));
|
||||
nodes_net3[z][4].Add (nodes_net3[z][0].Get (0));
|
||||
nodes_net3[z][5].Add (nodes_net3[z][0].Get (0));
|
||||
nodes_net3[z][6].Add (nodes_net3[z][2].Get (0));
|
||||
nodes_net3[z][7].Add (nodes_net3[z][3].Get (0));
|
||||
nodes_net3[z][8].Add (nodes_net3[z][3].Get (0));
|
||||
NetDeviceContainer ndc3[9];
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
ndc3[i] = p2p_1gb5ms.Install (nodes_net3[z][i]);
|
||||
}
|
||||
NetDeviceContainer ndc3LAN[5][nLANClients];
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".5." << 10 + i << ".0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.255");
|
||||
for (int j = 0; j < nLANClients; ++j)
|
||||
{
|
||||
nodes_net3LAN[z][i][j].Create (1);
|
||||
stack.Install (nodes_net3LAN[z][i][j]);
|
||||
nodes_net3LAN[z][i][j].Add (nodes_net3[z][i+4].Get (0));
|
||||
ndc3LAN[i][j] = p2p_100mb1ms.Install (nodes_net3LAN[z][i][j]);
|
||||
ifs3LAN[z][i][j] = address.Assign (ndc3LAN[i][j]);
|
||||
}
|
||||
}
|
||||
cout << " Connecting Subnets..." << endl;
|
||||
// Create Lone Routers (Node 4 & 5)
|
||||
nodes_netLR[z].Create (2);
|
||||
stack.Install (nodes_netLR[z]);
|
||||
NetDeviceContainer ndcLR;
|
||||
ndcLR = p2p_1gb5ms.Install (nodes_netLR[z]);
|
||||
// Connect Net2/Net3 through Lone Routers to Net0
|
||||
NodeContainer net0_4, net0_5, net2_4a, net2_4b, net3_5a, net3_5b;
|
||||
net0_4.Add (nodes_netLR[z].Get (0));
|
||||
net0_4.Add (nodes_net0[z][0].Get (0));
|
||||
net0_5.Add (nodes_netLR[z].Get (1));
|
||||
net0_5.Add (nodes_net0[z][1].Get (0));
|
||||
net2_4a.Add (nodes_netLR[z].Get (0));
|
||||
net2_4a.Add (nodes_net2[z][0].Get (0));
|
||||
net2_4b.Add (nodes_netLR[z].Get (1));
|
||||
net2_4b.Add (nodes_net2[z][1].Get (0));
|
||||
net3_5a.Add (nodes_netLR[z].Get (1));
|
||||
net3_5a.Add (nodes_net3[z][0].Get (0));
|
||||
net3_5b.Add (nodes_netLR[z].Get (1));
|
||||
net3_5b.Add (nodes_net3[z][1].Get (0));
|
||||
NetDeviceContainer ndc0_4, ndc0_5, ndc2_4a, ndc2_4b, ndc3_5a, ndc3_5b;
|
||||
ndc0_4 = p2p_1gb5ms.Install (net0_4);
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".1.253.0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndc0_4);
|
||||
ndc0_5 = p2p_1gb5ms.Install (net0_5);
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".1.254.0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndc0_5);
|
||||
ndc2_4a = p2p_1gb5ms.Install (net2_4a);
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".4.253.0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndc2_4a);
|
||||
ndc2_4b = p2p_1gb5ms.Install (net2_4b);
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".4.254.0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndc2_4b);
|
||||
ndc3_5a = p2p_1gb5ms.Install (net3_5a);
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".5.253.0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndc3_5a);
|
||||
ndc3_5b = p2p_1gb5ms.Install (net3_5b);
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".5.254.0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndc3_5b);
|
||||
// Assign IP addresses
|
||||
cout << " Assigning IP addresses..." << endl;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".1." << 1 + i << ".0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs0[z][i] = address.Assign (ndc0[i]);
|
||||
}
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
if (i == 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".2." << 1 + i << ".0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs1[z][i] = address.Assign (ndc1[i]);
|
||||
}
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".3.1.0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndcLR);
|
||||
for (int i = 0; i < 14; ++i)
|
||||
{
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".4." << 1 + i << ".0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs2[z][i] = address.Assign (ndc2[i]);
|
||||
}
|
||||
for (int i = 0; i < 9; ++i)
|
||||
{
|
||||
oss.str ("");
|
||||
oss << 10 + z << ".5." << 1 + i << ".0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs3[z][i] = address.Assign (ndc3[i]);
|
||||
}
|
||||
}
|
||||
// Create Ring Links
|
||||
if (nCN > 1)
|
||||
{
|
||||
cout << "Forming Ring Topology..." << endl;
|
||||
NodeContainer nodes_ring[nCN];
|
||||
for (int z = 0; z < nCN-1; ++z)
|
||||
{
|
||||
nodes_ring[z].Add (nodes_net0[z][0].Get (0));
|
||||
nodes_ring[z].Add (nodes_net0[z+1][0].Get (0));
|
||||
}
|
||||
nodes_ring[nCN-1].Add (nodes_net0[nCN-1][0].Get (0));
|
||||
nodes_ring[nCN-1].Add (nodes_net0[0][0].Get (0));
|
||||
NetDeviceContainer ndc_ring[nCN];
|
||||
for (int z = 0; z < nCN; ++z)
|
||||
{
|
||||
ndc_ring[z] = p2p_2gb200ms.Install (nodes_ring[z]);
|
||||
oss.str ("");
|
||||
oss << "254.1." << z + 1 << ".0";
|
||||
address.SetBase (oss.str ().c_str (), "255.255.255.0");
|
||||
ifs = address.Assign (ndc_ring[z]);
|
||||
}
|
||||
}
|
||||
|
||||
// Create Traffic Flows
|
||||
cout << "Creating TCP Traffic Flows:" << endl;
|
||||
Config::SetDefault ("ns3::OnOffApplication::MaxBytes", UintegerValue (500000));
|
||||
Config::SetDefault ("ns3::OnOffApplication::OnTime",
|
||||
RandomVariableValue (ConstantVariable (1)));
|
||||
Config::SetDefault ("ns3::OnOffApplication::OffTime",
|
||||
RandomVariableValue (ConstantVariable (0)));
|
||||
Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (512));
|
||||
|
||||
UniformVariable urng;
|
||||
int r1;
|
||||
double r2;
|
||||
for (int z = 0; z < nCN; ++z)
|
||||
{
|
||||
int x = z + 1;
|
||||
if (z == nCN - 1)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
// Subnet 2 LANs
|
||||
cout << " Campus Network " << z << " Flows [ Net2 ";
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
for (int j = 0; j < nLANClients; ++j)
|
||||
{
|
||||
// Sinks
|
||||
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
|
||||
InetSocketAddress (Ipv4Address::GetAny (), 9999));
|
||||
ApplicationContainer sinkApp = sinkHelper.Install (
|
||||
nodes_net2LAN[z][i][j].Get (0));
|
||||
sinkApp.Start (Seconds (100.0));
|
||||
// Sources
|
||||
r1 = 2 + (int)(4 * urng.GetValue ());
|
||||
r2 = 100 + (10 * urng.GetValue ());;
|
||||
OnOffHelper client ("ns3::TcpSocketFactory", Address ());
|
||||
AddressValue remoteAddress(InetSocketAddress (
|
||||
ifs2LAN[z][i][j].GetAddress (0), 9999));
|
||||
client.SetAttribute ("Remote", remoteAddress);
|
||||
ApplicationContainer clientApp;
|
||||
clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
|
||||
clientApp.Start (Seconds (r2));
|
||||
}
|
||||
}
|
||||
// Subnet 3 LANs
|
||||
cout << "Net3 ]" << endl;
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
for (int j = 0; j < nLANClients; ++j)
|
||||
{
|
||||
// Sinks
|
||||
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory",
|
||||
InetSocketAddress (Ipv4Address::GetAny (), 9999));
|
||||
ApplicationContainer sinkApp = sinkHelper.Install (
|
||||
nodes_net3LAN[z][i][j].Get (0));
|
||||
sinkApp.Start (Seconds (100.0));
|
||||
// Sources
|
||||
r1 = 2 + (int)(4 * urng.GetValue ());
|
||||
r2 = 100 + (10 * urng.GetValue ());;
|
||||
OnOffHelper client ("ns3::TcpSocketFactory", Address ());
|
||||
AddressValue remoteAddress (InetSocketAddress (
|
||||
ifs2LAN[z][i][j].GetAddress (0), 9999));
|
||||
client.SetAttribute ("Remote", remoteAddress);
|
||||
ApplicationContainer clientApp;
|
||||
clientApp.Add (client.Install (nodes_net1[x][r1].Get (0)));
|
||||
clientApp.Start (Seconds (r2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Created " << NodeList::GetNNodes () << " nodes." << endl;
|
||||
TIMER_TYPE routingStart;
|
||||
TIMER_NOW (routingStart);
|
||||
|
||||
if (nix)
|
||||
{
|
||||
// Calculate routing tables
|
||||
cout << "Using Nix-vectors..." << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Calculate routing tables
|
||||
cout << "Populating Global Static Routing Tables..." << endl;
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
}
|
||||
|
||||
TIMER_TYPE routingEnd;
|
||||
TIMER_NOW (routingEnd);
|
||||
cout << "Routing tables population took "
|
||||
<< TIMER_DIFF (routingEnd, routingStart) << endl;
|
||||
#if 0
|
||||
std::ofstream ascii;
|
||||
ascii.open("nms_p2p_nix.tr");
|
||||
PointToPointHelper::EnableAsciiAll(ascii);
|
||||
CsmaHelper::EnableAsciiAll(ascii);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
PointToPointHelper::EnablePcapAll("nms_p2p");
|
||||
CsmaHelper::EnablePcapAll("nms_csma");
|
||||
#endif
|
||||
|
||||
Simulator::ScheduleNow (Progress);
|
||||
cout << "Running simulator..." << endl;
|
||||
TIMER_NOW (t1);
|
||||
Simulator::Stop (Seconds (200.0));
|
||||
Simulator::Run ();
|
||||
TIMER_NOW (t2);
|
||||
cout << "Simulator finished." << endl;
|
||||
Simulator::Destroy ();
|
||||
|
||||
double d1 = TIMER_DIFF (t1, t0), d2 = TIMER_DIFF (t2, t1);
|
||||
cout << "-----" << endl << "Runtime Stats:" << endl;
|
||||
cout << "Simulator init time: " << d1 << endl;
|
||||
cout << "Simulator run time: " << d2 << endl;
|
||||
cout << "Total elapsed time: " << d1+d2 << endl;
|
||||
return 0;
|
||||
}
|
||||
166
examples/routing/simple-alternate-routing.cc
Normal file
166
examples/routing/simple-alternate-routing.cc
Normal file
@@ -0,0 +1,166 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
//
|
||||
// Network topology
|
||||
//
|
||||
// n0
|
||||
// \ 5 Mb/s, 2ms
|
||||
// \ 1.5Mb/s, 10ms
|
||||
// n2 ------------------------n3
|
||||
// / /
|
||||
// / 5 Mb/s, 2ms /
|
||||
// n1--------------------------
|
||||
// 1.5 Mb/s, 100ms
|
||||
//
|
||||
// this is a modification of simple-global-routing to allow for
|
||||
// a single hop but higher-cost path between n1 and n3
|
||||
//
|
||||
// - Tracing of queues and packet receptions to file "simple-rerouting.tr"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("SimpleAlternateRoutingExample");
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
// Users may find it convenient to turn on explicit debugging
|
||||
// for selected modules; the below lines suggest how to do this
|
||||
#if 0
|
||||
LogComponentEnable("GlobalRoutingHelper", LOG_LOGIC);
|
||||
LogComponentEnable("GlobalRouter", LOG_LOGIC);
|
||||
#endif
|
||||
|
||||
|
||||
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
|
||||
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("300b/s"));
|
||||
|
||||
// The below metric, if set to 3 or higher, will cause packets between
|
||||
// n1 and n3 to take the 2-hop route through n2
|
||||
|
||||
CommandLine cmd;
|
||||
//
|
||||
// Additionally, we plumb this metric into the default value / command
|
||||
// line argument system as well, for exemplary purposes. This means
|
||||
// that it can be resettable at the command-line to the program,
|
||||
// rather than recompiling
|
||||
// e.g. waf --run "simple-alternate-routing --AlternateCost=5"
|
||||
uint16_t sampleMetric = 1;
|
||||
cmd.AddValue ("AlternateCost",
|
||||
"This metric is used in the example script between n3 and n1 ",
|
||||
sampleMetric);
|
||||
|
||||
// Allow the user to override any of the defaults and the above
|
||||
// DefaultValue::Bind ()s at run-time, via command-line arguments
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
// Here, we will explicitly create four nodes. In more sophisticated
|
||||
// topologies, we could configure a node factory.
|
||||
NS_LOG_INFO ("Create nodes.");
|
||||
NodeContainer c;
|
||||
c.Create (4);
|
||||
NodeContainer n0n2 = NodeContainer (c.Get (0), c.Get (2));
|
||||
NodeContainer n1n2 = NodeContainer (c.Get (1), c.Get (2));
|
||||
NodeContainer n3n2 = NodeContainer (c.Get (3), c.Get (2));
|
||||
NodeContainer n1n3 = NodeContainer (c.Get (1), c.Get (3));
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
NS_LOG_INFO ("Create channels.");
|
||||
PointToPointHelper p2p;
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer d0d2 = p2p.Install (n0n2);
|
||||
|
||||
NetDeviceContainer d1d2 = p2p.Install (n1n2);
|
||||
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
|
||||
NetDeviceContainer d3d2 = p2p.Install (n3n2);
|
||||
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("100ms"));
|
||||
NetDeviceContainer d1d3 = p2p.Install (n1n3);
|
||||
|
||||
InternetStackHelper internet;
|
||||
internet.Install (c);
|
||||
|
||||
// Later, we add IP addresses. The middle two octets correspond to
|
||||
// the channel number.
|
||||
NS_LOG_INFO ("Assign IP Addresses.");
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.0.0.0", "255.255.255.0");
|
||||
ipv4.Assign (d0d2);
|
||||
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
|
||||
|
||||
ipv4.SetBase ("10.2.2.0", "255.255.255.0");
|
||||
ipv4.Assign (d3d2);
|
||||
|
||||
ipv4.SetBase ("10.3.3.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i1i3 = ipv4.Assign (d1d3);
|
||||
|
||||
i1i3.SetMetric (0, sampleMetric);
|
||||
i1i3.SetMetric (1, sampleMetric);
|
||||
|
||||
// Create router nodes, initialize routing database and set up the routing
|
||||
// tables in the nodes.
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
// Create the OnOff application to send UDP datagrams
|
||||
NS_LOG_INFO ("Create Application.");
|
||||
uint16_t port = 9; // Discard port (RFC 863)
|
||||
|
||||
// Create a flow from n3 to n1, starting at time 1.1 seconds
|
||||
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
||||
Address (InetSocketAddress (i1i2.GetAddress (0), port)));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
|
||||
ApplicationContainer apps = onoff.Install (c.Get (3));
|
||||
apps.Start (Seconds (1.1));
|
||||
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 (c.Get (1));
|
||||
apps.Start (Seconds (1.1));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("simple-alternate-routing.tr");
|
||||
PointToPointHelper::EnablePcapAll ("simple-alternate-routing");
|
||||
PointToPointHelper::EnableAsciiAll (ascii);
|
||||
|
||||
NS_LOG_INFO ("Run Simulation.");
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
NS_LOG_INFO ("Done.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
173
examples/routing/simple-global-routing.cc
Normal file
173
examples/routing/simple-global-routing.cc
Normal file
@@ -0,0 +1,173 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* ns-2 simple.tcl script (ported from ns-2)
|
||||
* Originally authored by Steve McCanne, 12/19/1996
|
||||
*/
|
||||
|
||||
// Port of ns-2/tcl/ex/simple.tcl to ns-3
|
||||
//
|
||||
// Network topology
|
||||
//
|
||||
// n0
|
||||
// \ 5 Mb/s, 2ms
|
||||
// \ 1.5Mb/s, 10ms
|
||||
// n2 -------------------------n3
|
||||
// /
|
||||
// / 5 Mb/s, 2ms
|
||||
// n1
|
||||
//
|
||||
// - all links are point-to-point links with indicated one-way BW/delay
|
||||
// - CBR/UDP flows from n0 to n3, and from n3 to n1
|
||||
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
|
||||
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
|
||||
// (i.e., DataRate of 448,000 bps)
|
||||
// - DropTail queues
|
||||
// - Tracing of queues and packet receptions to file "simple-global-routing.tr"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
// Users may find it convenient to turn on explicit debugging
|
||||
// for selected modules; the below lines suggest how to do this
|
||||
#if 0
|
||||
LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
|
||||
#endif
|
||||
|
||||
// Set up some default values for the simulation. Use the
|
||||
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
|
||||
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
|
||||
|
||||
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
|
||||
|
||||
// Allow the user to override any of the defaults and the above
|
||||
// DefaultValue::Bind ()s at run-time, via command-line arguments
|
||||
CommandLine cmd;
|
||||
bool enableFlowMonitor = false;
|
||||
cmd.AddValue("EnableMonitor", "Enable Flow Monitor", enableFlowMonitor);
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
// Here, we will explicitly create four nodes. In more sophisticated
|
||||
// topologies, we could configure a node factory.
|
||||
NS_LOG_INFO ("Create nodes.");
|
||||
NodeContainer c;
|
||||
c.Create (4);
|
||||
NodeContainer n0n2 = NodeContainer (c.Get(0), c.Get (2));
|
||||
NodeContainer n1n2 = NodeContainer (c.Get(1), c.Get (2));
|
||||
NodeContainer n3n2 = NodeContainer (c.Get(3), c.Get (2));
|
||||
|
||||
InternetStackHelper internet;
|
||||
internet.Install (c);
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
NS_LOG_INFO ("Create channels.");
|
||||
PointToPointHelper p2p;
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer d0d2 = p2p.Install (n0n2);
|
||||
|
||||
NetDeviceContainer d1d2 = p2p.Install (n1n2);
|
||||
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
|
||||
NetDeviceContainer d3d2 = p2p.Install (n3n2);
|
||||
|
||||
// Later, we add IP addresses.
|
||||
NS_LOG_INFO ("Assign IP Addresses.");
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i0i2 = ipv4.Assign (d0d2);
|
||||
|
||||
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i1i2 = ipv4.Assign (d1d2);
|
||||
|
||||
ipv4.SetBase ("10.1.3.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i3i2 = ipv4.Assign (d3d2);
|
||||
|
||||
// Create router nodes, initialize routing database and set up the routing
|
||||
// tables in the nodes.
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
// Create the OnOff application to send UDP datagrams of size
|
||||
// 210 bytes at a rate of 448 Kb/s
|
||||
NS_LOG_INFO ("Create Applications.");
|
||||
uint16_t port = 9; // Discard port (RFC 863)
|
||||
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
||||
Address (InetSocketAddress (i3i2.GetAddress (0), port)));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
ApplicationContainer apps = onoff.Install (c.Get (0));
|
||||
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 (c.Get (3));
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
|
||||
onoff.SetAttribute ("Remote",
|
||||
AddressValue (InetSocketAddress (i1i2.GetAddress (0), port)));
|
||||
apps = onoff.Install (c.Get (3));
|
||||
apps.Start (Seconds (1.1));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
// Create a packet sink to receive these packets
|
||||
apps = sink.Install (c.Get (1));
|
||||
apps.Start (Seconds (1.1));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("simple-global-routing.tr");
|
||||
PointToPointHelper::EnablePcapAll ("simple-global-routing");
|
||||
PointToPointHelper::EnableAsciiAll (ascii);
|
||||
|
||||
// Flow Monitor
|
||||
Ptr<FlowMonitor> flowmon;
|
||||
if (enableFlowMonitor)
|
||||
{
|
||||
FlowMonitorHelper flowmonHelper;
|
||||
flowmon = flowmonHelper.InstallAll ();
|
||||
}
|
||||
|
||||
NS_LOG_INFO ("Run Simulation.");
|
||||
Simulator::Stop (Seconds (11));
|
||||
Simulator::Run ();
|
||||
NS_LOG_INFO ("Done.");
|
||||
|
||||
if (enableFlowMonitor)
|
||||
{
|
||||
flowmon->SerializeToXmlFile ("simple-global-routing.flowmon", false, false);
|
||||
}
|
||||
|
||||
Simulator::Destroy ();
|
||||
return 0;
|
||||
}
|
||||
173
examples/routing/simple-point-to-point-olsr.cc
Normal file
173
examples/routing/simple-point-to-point-olsr.cc
Normal file
@@ -0,0 +1,173 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* ns-2 simple.tcl script (ported from ns-2)
|
||||
* Originally authored by Steve McCanne, 12/19/1996
|
||||
*/
|
||||
|
||||
// Port of ns-2/tcl/ex/simple.tcl to ns-3
|
||||
//
|
||||
// Network topology
|
||||
//
|
||||
// n0
|
||||
// \ 5 Mb/s, 2ms
|
||||
// \ 1.5Mb/s, 10ms
|
||||
// n2 -------------------------n3---------n4
|
||||
// /
|
||||
// / 5 Mb/s, 2ms
|
||||
// n1
|
||||
//
|
||||
// - all links are point-to-point links with indicated one-way BW/delay
|
||||
// - CBR/UDP flows from n0 to n3, and from n3 to n1
|
||||
// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec.
|
||||
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
|
||||
// (i.e., DataRate of 448,000 bps)
|
||||
// - DropTail queues
|
||||
// - Tracing of queues and packet receptions to file "simple-point-to-point-olsr.tr"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("SimpleGlobalRoutingExample");
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
// Users may find it convenient to turn on explicit debugging
|
||||
// for selected modules; the below lines suggest how to do this
|
||||
#if 0
|
||||
LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
|
||||
#endif
|
||||
|
||||
// Set up some default values for the simulation. Use the
|
||||
|
||||
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
|
||||
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
|
||||
|
||||
//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);
|
||||
|
||||
// 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);
|
||||
|
||||
// Here, we will explicitly create four nodes. In more sophisticated
|
||||
// topologies, we could configure a node factory.
|
||||
NS_LOG_INFO ("Create nodes.");
|
||||
NodeContainer c;
|
||||
c.Create (5);
|
||||
NodeContainer n02 = NodeContainer (c.Get(0), c.Get (2));
|
||||
NodeContainer n12 = NodeContainer (c.Get(1), c.Get (2));
|
||||
NodeContainer n32 = NodeContainer (c.Get(3), c.Get (2));
|
||||
NodeContainer n34 = NodeContainer (c.Get (3), c.Get (4));
|
||||
|
||||
// Enable OLSR
|
||||
NS_LOG_INFO ("Enabling OLSR Routing.");
|
||||
OlsrHelper olsr;
|
||||
|
||||
Ipv4StaticRoutingHelper staticRouting;
|
||||
|
||||
Ipv4ListRoutingHelper list;
|
||||
list.Add (staticRouting, 0);
|
||||
list.Add (olsr, 10);
|
||||
|
||||
InternetStackHelper internet;
|
||||
internet.SetRoutingHelper (list);
|
||||
internet.Install (c);
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
NS_LOG_INFO ("Create channels.");
|
||||
PointToPointHelper p2p;
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer nd02 = p2p.Install (n02);
|
||||
NetDeviceContainer nd12 = p2p.Install (n12);
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
|
||||
NetDeviceContainer nd32 = p2p.Install (n32);
|
||||
NetDeviceContainer nd34 = p2p.Install (n34);
|
||||
|
||||
// Later, we add IP addresses.
|
||||
NS_LOG_INFO ("Assign IP Addresses.");
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i02 = ipv4.Assign (nd02);
|
||||
|
||||
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i12 = ipv4.Assign (nd12);
|
||||
|
||||
ipv4.SetBase ("10.1.3.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i32 = ipv4.Assign (nd32);
|
||||
|
||||
ipv4.SetBase ("10.1.4.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i34 = ipv4.Assign (nd34);
|
||||
|
||||
// Create the OnOff application to send UDP datagrams of size
|
||||
// 210 bytes at a rate of 448 Kb/s
|
||||
NS_LOG_INFO ("Create Applications.");
|
||||
uint16_t port = 9; // Discard port (RFC 863)
|
||||
|
||||
OnOffHelper onoff ("ns3::UdpSocketFactory",
|
||||
InetSocketAddress (i34.GetAddress (1), port));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
|
||||
ApplicationContainer apps = onoff.Install (c.Get (0));
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
// Create a packet sink to receive these packets
|
||||
PacketSinkHelper sink ("ns3::UdpSocketFactory",
|
||||
InetSocketAddress (Ipv4Address::GetAny (), port));
|
||||
|
||||
apps = sink.Install (c.Get (3));
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
|
||||
onoff.SetAttribute ("Remote",
|
||||
AddressValue (InetSocketAddress (i12.GetAddress (0), port)));
|
||||
apps = onoff.Install (c.Get (3));
|
||||
apps.Start (Seconds (1.1));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
// Create a packet sink to receive these packets
|
||||
apps = sink.Install (c.Get (1));
|
||||
apps.Start (Seconds (1.1));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("simple-point-to-point-olsr.tr");
|
||||
PointToPointHelper::EnablePcapAll ("simple-point-to-point-olsr");
|
||||
PointToPointHelper::EnableAsciiAll (ascii);
|
||||
|
||||
Simulator::Stop (Seconds (30));
|
||||
|
||||
NS_LOG_INFO ("Run Simulation.");
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
NS_LOG_INFO ("Done.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
164
examples/routing/simple-routing-ping6.cc
Normal file
164
examples/routing/simple-routing-ping6.cc
Normal file
@@ -0,0 +1,164 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2008-2009 Strasbourg University
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: David Gross <david.gross@eturs.u-strasbg.fr>
|
||||
* Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
|
||||
*/
|
||||
|
||||
// Network topology
|
||||
// //
|
||||
// // n0 r n1
|
||||
// // | _ |
|
||||
// // ====|_|====
|
||||
// // router
|
||||
// //
|
||||
// // - Tracing of queues and packet receptions to file "simple-routing-ping6.tr"
|
||||
|
||||
#include <fstream>
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/helper-module.h"
|
||||
|
||||
#include "ns3/ipv6-routing-table-entry.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("SimpleRoutingPing6Example");
|
||||
|
||||
/**
|
||||
* \class StackHelper
|
||||
* \brief Helper to set or get some IPv6 information about nodes.
|
||||
*/
|
||||
class StackHelper
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \brief Add an address to a IPv6 node.
|
||||
* \param n node
|
||||
* \param interface interface index
|
||||
* \param address IPv6 address to add
|
||||
*/
|
||||
inline void AddAddress (Ptr<Node>& n, uint32_t interface, Ipv6Address address)
|
||||
{
|
||||
Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
|
||||
ipv6->AddAddress (interface, address);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Print the routing table.
|
||||
* \param n the node
|
||||
*/
|
||||
inline void PrintRoutingTable (Ptr<Node>& n)
|
||||
{
|
||||
Ptr<Ipv6StaticRouting> routing = 0;
|
||||
Ipv6StaticRoutingHelper routingHelper;
|
||||
Ptr<Ipv6> ipv6 = n->GetObject<Ipv6> ();
|
||||
uint32_t nbRoutes = 0;
|
||||
Ipv6RoutingTableEntry route;
|
||||
|
||||
routing = routingHelper.GetStaticRouting (ipv6);
|
||||
|
||||
std::cout << "Routing table of " << n << " : " << std::endl;
|
||||
std::cout << "Destination\t\t\t\t" << "Gateway\t\t\t\t\t" << "Interface\t" << "Prefix to use" << std::endl;
|
||||
|
||||
nbRoutes = routing->GetNRoutes ();
|
||||
for (uint32_t i = 0 ; i < nbRoutes ; i++)
|
||||
{
|
||||
route = routing->GetRoute (i);
|
||||
std::cout << route.GetDest () << "\t"
|
||||
<< route.GetGateway () << "\t"
|
||||
<< route.GetInterface () << "\t"
|
||||
<< route.GetPrefixToUse () << "\t"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
#if 0
|
||||
LogComponentEnable ("Ipv6L3Protocol", LOG_LEVEL_ALL);
|
||||
LogComponentEnable ("Icmpv6L4Protocol", LOG_LEVEL_ALL);
|
||||
LogComponentEnable ("Ipv6StaticRouting", LOG_LEVEL_ALL);
|
||||
LogComponentEnable ("Ipv6Interface", LOG_LEVEL_ALL);
|
||||
LogComponentEnable ("Ping6Application", LOG_LEVEL_ALL);
|
||||
#endif
|
||||
|
||||
CommandLine cmd;
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
StackHelper stackHelper;
|
||||
|
||||
NS_LOG_INFO ("Create nodes.");
|
||||
Ptr<Node> n0 = CreateObject<Node> ();
|
||||
Ptr<Node> r = CreateObject<Node> ();
|
||||
Ptr<Node> n1 = CreateObject<Node> ();
|
||||
|
||||
NodeContainer net1 (n0, r);
|
||||
NodeContainer net2 (r, n1);
|
||||
NodeContainer all (n0, r, n1);
|
||||
|
||||
NS_LOG_INFO ("Create IPv6 Internet Stack");
|
||||
InternetStackHelper internetv6;
|
||||
internetv6.Install (all);
|
||||
|
||||
NS_LOG_INFO ("Create channels.");
|
||||
CsmaHelper csma;
|
||||
csma.SetChannelAttribute ("DataRate", DataRateValue (5000000));
|
||||
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
|
||||
NetDeviceContainer d1 = csma.Install (net1);
|
||||
NetDeviceContainer d2 = csma.Install (net2);
|
||||
|
||||
NS_LOG_INFO ("Create networks and assign IPv6 Addresses.");
|
||||
Ipv6AddressHelper ipv6;
|
||||
ipv6.NewNetwork (Ipv6Address ("2001:1::"), 64);
|
||||
Ipv6InterfaceContainer i1 = ipv6.Assign (d1);
|
||||
i1.SetRouter (1, true);
|
||||
ipv6.NewNetwork (Ipv6Address ("2001:2::"), 64);
|
||||
Ipv6InterfaceContainer i2 = ipv6.Assign (d2);
|
||||
i2.SetRouter (0, true);
|
||||
|
||||
stackHelper.PrintRoutingTable(n0);
|
||||
|
||||
/* Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r */
|
||||
uint32_t packetSize = 1024;
|
||||
uint32_t maxPacketCount = 5;
|
||||
Time interPacketInterval = Seconds (1.);
|
||||
Ping6Helper ping6;
|
||||
|
||||
ping6.SetLocal (i1.GetAddress (0, 1));
|
||||
ping6.SetRemote (i2.GetAddress (1, 1));
|
||||
|
||||
ping6.SetAttribute ("MaxPackets", UintegerValue (maxPacketCount));
|
||||
ping6.SetAttribute ("Interval", TimeValue (interPacketInterval));
|
||||
ping6.SetAttribute ("PacketSize", UintegerValue (packetSize));
|
||||
ApplicationContainer apps = ping6.Install (net1.Get (0));
|
||||
apps.Start (Seconds (2.0));
|
||||
apps.Stop (Seconds (20.0));
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("simple-routing-ping6.tr");
|
||||
CsmaHelper::EnablePcapAll (std::string ("simple-routing-ping6"), true);
|
||||
CsmaHelper::EnableAsciiAll (ascii);
|
||||
|
||||
NS_LOG_INFO ("Run Simulation.");
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
NS_LOG_INFO ("Done.");
|
||||
}
|
||||
|
||||
106
examples/routing/simple-routing-ping6.py
Normal file
106
examples/routing/simple-routing-ping6.py
Normal file
@@ -0,0 +1,106 @@
|
||||
#
|
||||
# Copyright (c) 2008-2009 Strasbourg University
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License version 2 as
|
||||
# published by the Free Software Foundation;
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Author: David Gross <david.gross@eturs.u-strasbg.fr>
|
||||
# Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
|
||||
#
|
||||
|
||||
#
|
||||
# Network topology:
|
||||
#
|
||||
# n0 r n1
|
||||
# | _ |
|
||||
# ====|_|====
|
||||
# router
|
||||
#
|
||||
|
||||
import ns3;
|
||||
|
||||
def main(argv):
|
||||
|
||||
cmd = ns3.CommandLine();
|
||||
|
||||
cmd.Parse(argv);
|
||||
|
||||
# Create nodes
|
||||
print "Create nodes"
|
||||
n0 = ns3.Node();
|
||||
r = ns3.Node();
|
||||
n1 = ns3.Node();
|
||||
|
||||
net1 = ns3.NodeContainer();
|
||||
net1.Add(n0);
|
||||
net1.Add(r);
|
||||
net2 = ns3.NodeContainer();
|
||||
net2.Add(r);
|
||||
net2.Add(n1);
|
||||
all = ns3.NodeContainer();
|
||||
all.Add(n0);
|
||||
all.Add(r);
|
||||
all.Add(n1);
|
||||
|
||||
# Create IPv6 Internet Stack
|
||||
internetv6 = ns3.InternetStackHelper();
|
||||
internetv6.Install(all);
|
||||
|
||||
# Create channels
|
||||
csma = ns3.CsmaHelper();
|
||||
csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)));
|
||||
csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)));
|
||||
d1 = csma.Install(net1);
|
||||
d2 = csma.Install(net2);
|
||||
|
||||
# Create networks and assign IPv6 Addresses
|
||||
print "Addressing"
|
||||
ipv6 = ns3.Ipv6AddressHelper();
|
||||
ipv6.NewNetwork(ns3.Ipv6Address("2001:1::"), ns3.Ipv6Prefix(64));
|
||||
i1 = ipv6.Assign(d1);
|
||||
i1.SetRouter(1, True);
|
||||
ipv6.NewNetwork(ns3.Ipv6Address("2001:2::"), ns3.Ipv6Prefix(64));
|
||||
i2 = ipv6.Assign(d2);
|
||||
i2.SetRouter(0, True);
|
||||
|
||||
# Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r
|
||||
print "Application"
|
||||
packetSize = 1024;
|
||||
maxPacketCount = 5;
|
||||
interPacketInterval = ns3.Seconds(1.);
|
||||
ping6 = ns3.Ping6Helper();
|
||||
|
||||
ping6.SetLocal(i1.GetAddress(0, 1));
|
||||
ping6.SetRemote(i2.GetAddress(1, 1));
|
||||
|
||||
ping6.SetAttribute("MaxPackets", ns3.UintegerValue(maxPacketCount));
|
||||
ping6.SetAttribute("Interval", ns3.TimeValue(interPacketInterval));
|
||||
ping6.SetAttribute("PacketSize", ns3.UintegerValue(packetSize));
|
||||
|
||||
apps = ping6.Install(ns3.NodeContainer(net1.Get(0)));
|
||||
apps.Start(ns3.Seconds(2.0));
|
||||
apps.Stop(ns3.Seconds(20.0));
|
||||
|
||||
print "Tracing"
|
||||
ascii = ns3.ofstream("simple-routing-ping6.tr");
|
||||
ns3.CsmaHelper.EnableAsciiAll(ascii);
|
||||
ns3.CsmaHelper.EnablePcapAll("simple-routing-ping6", True);
|
||||
|
||||
# Run Simulation
|
||||
ns3.Simulator.Run();
|
||||
ns3.Simulator.Destroy();
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
main(sys.argv)
|
||||
|
||||
136
examples/routing/static-routing-slash32.cc
Normal file
136
examples/routing/static-routing-slash32.cc
Normal file
@@ -0,0 +1,136 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
// 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 <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include "ns3/csma-net-device.h"
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/simulator-module.h"
|
||||
#include "ns3/node-module.h"
|
||||
#include "ns3/helper-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);
|
||||
|
||||
Ptr<Node> nA = CreateObject<Node> ();
|
||||
Ptr<Node> nB = CreateObject<Node> ();
|
||||
Ptr<Node> nC = CreateObject<Node> ();
|
||||
|
||||
NodeContainer c = NodeContainer (nA, nB, nC);
|
||||
|
||||
InternetStackHelper internet;
|
||||
internet.Install (c);
|
||||
|
||||
// Point-to-point links
|
||||
NodeContainer nAnB = NodeContainer (nA, nB);
|
||||
NodeContainer nBnC = NodeContainer (nB, nC);
|
||||
|
||||
// We create the channels first without any IP addressing information
|
||||
PointToPointHelper p2p;
|
||||
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
||||
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
||||
NetDeviceContainer dAdB = p2p.Install (nAnB);
|
||||
|
||||
NetDeviceContainer dBdC = p2p.Install (nBnC);;
|
||||
|
||||
Ptr<CsmaNetDevice> deviceA = CreateObject<CsmaNetDevice> ();
|
||||
deviceA->SetAddress (Mac48Address::Allocate ());
|
||||
nA->AddDevice (deviceA);
|
||||
|
||||
Ptr<CsmaNetDevice> deviceC = CreateObject<CsmaNetDevice> ();
|
||||
deviceC->SetAddress (Mac48Address::Allocate ());
|
||||
nC->AddDevice (deviceC);
|
||||
|
||||
// Later, we add IP addresses.
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.252");
|
||||
Ipv4InterfaceContainer iAiB = ipv4.Assign (dAdB);
|
||||
|
||||
ipv4.SetBase ("10.1.1.4", "255.255.255.252");
|
||||
Ipv4InterfaceContainer iBiC = ipv4.Assign (dBdC);
|
||||
|
||||
Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4> ();
|
||||
Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4> ();
|
||||
Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4> ();
|
||||
|
||||
int32_t ifIndexA = ipv4A->AddInterface (deviceA);
|
||||
int32_t ifIndexC = ipv4C->AddInterface (deviceC);
|
||||
|
||||
Ipv4InterfaceAddress ifInAddrA = Ipv4InterfaceAddress (Ipv4Address ("172.16.1.1"), Ipv4Mask ("/32"));
|
||||
ipv4A->AddAddress (ifIndexA, ifInAddrA);
|
||||
ipv4A->SetMetric (ifIndexA, 1);
|
||||
ipv4A->SetUp (ifIndexA);
|
||||
|
||||
Ipv4InterfaceAddress ifInAddrC = Ipv4InterfaceAddress (Ipv4Address ("192.168.1.1"), Ipv4Mask ("/32"));
|
||||
ipv4C->AddAddress (ifIndexC, ifInAddrC);
|
||||
ipv4C->SetMetric (ifIndexC, 1);
|
||||
ipv4C->SetUp (ifIndexC);
|
||||
|
||||
Ipv4StaticRoutingHelper ipv4RoutingHelper;
|
||||
// Create static routes from A to C
|
||||
Ptr<Ipv4StaticRouting> staticRoutingA = ipv4RoutingHelper.GetStaticRouting (ipv4A);
|
||||
// The ifIndex for this outbound route is 1; the first p2p link added
|
||||
staticRoutingA->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.2"), 1);
|
||||
Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting (ipv4B);
|
||||
// The ifIndex we want on node B is 2; 0 corresponds to loopback, and 1 to the first point to point link
|
||||
staticRoutingB->AddHostRouteTo (Ipv4Address ("192.168.1.1"), Ipv4Address ("10.1.1.6"), 2);
|
||||
// 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 (ifInAddrC.GetLocal (), port)));
|
||||
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
||||
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
||||
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
|
||||
ApplicationContainer apps = onoff.Install (nA);
|
||||
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 (nC);
|
||||
apps.Start (Seconds (1.0));
|
||||
apps.Stop (Seconds (10.0));
|
||||
|
||||
std::ofstream ascii;
|
||||
ascii.open ("static-routing-slash32.tr");
|
||||
PointToPointHelper::EnablePcapAll ("static-routing-slash32");
|
||||
PointToPointHelper::EnableAsciiAll (ascii);
|
||||
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
examples/routing/waf
vendored
Executable file
1
examples/routing/waf
vendored
Executable file
@@ -0,0 +1 @@
|
||||
exec "`dirname "$0"`"/../../waf "$@"
|
||||
46
examples/routing/wscript
Normal file
46
examples/routing/wscript
Normal file
@@ -0,0 +1,46 @@
|
||||
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
||||
|
||||
def build(bld):
|
||||
obj = bld.create_ns3_program('dynamic-global-routing',
|
||||
['point-to-point', 'csma', 'internet-stack', 'global-routing'])
|
||||
obj.source = 'dynamic-global-routing.cc'
|
||||
|
||||
obj = bld.create_ns3_program('static-routing-slash32',
|
||||
['point-to-point', 'internet-stack', 'global-routing'])
|
||||
obj.source = 'static-routing-slash32.cc'
|
||||
|
||||
obj = bld.create_ns3_program('global-routing-slash32',
|
||||
['point-to-point', 'internet-stack', 'global-routing'])
|
||||
obj.source = 'global-routing-slash32.cc'
|
||||
|
||||
obj = bld.create_ns3_program('global-injection-slash32',
|
||||
['point-to-point', 'internet-stack', 'global-routing'])
|
||||
obj.source = 'global-injection-slash32.cc'
|
||||
|
||||
obj = bld.create_ns3_program('simple-global-routing',
|
||||
['point-to-point', 'internet-stack', 'global-routing'])
|
||||
obj.source = 'simple-global-routing.cc'
|
||||
|
||||
obj = bld.create_ns3_program('simple-alternate-routing',
|
||||
['point-to-point', 'internet-stack', 'global-routing'])
|
||||
obj.source = 'simple-alternate-routing.cc'
|
||||
|
||||
obj = bld.create_ns3_program( 'mixed-global-routing',
|
||||
['point-to-point', 'internet-stack', 'global-routing' , 'csma-cd'])
|
||||
obj.source = 'mixed-global-routing.cc'
|
||||
|
||||
obj = bld.create_ns3_program('simple-point-to-point-olsr',
|
||||
['point-to-point', 'internet-stack', 'olsr'])
|
||||
obj.source = 'simple-point-to-point-olsr.cc'
|
||||
|
||||
obj = bld.create_ns3_program('nix-simple',
|
||||
['point-to-point', 'internet-stack', 'nix-vector-routing'])
|
||||
obj.source = 'nix-simple.cc'
|
||||
|
||||
obj = bld.create_ns3_program('nms-p2p-nix',
|
||||
['point-to-point', 'internet-stack', 'nix-vector-routing'])
|
||||
obj.source = 'nms-p2p-nix.cc'
|
||||
|
||||
obj = bld.create_ns3_program('simple-routing-ping6',
|
||||
['csma', 'internet-stack'])
|
||||
obj.source = 'simple-routing-ping6.cc'
|
||||
Reference in New Issue
Block a user