A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-injection-slash32.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 */
5
6// Test program for this 3-router scenario, using global routing
7//
8// (a.a.a.a/32)A<--x.x.x.0/30-->B<--y.y.y.0/30-->C(c.c.c.c/32)
9
10#include "ns3/applications-module.h"
11#include "ns3/core-module.h"
12#include "ns3/csma-net-device.h"
13#include "ns3/global-router-interface.h"
14#include "ns3/internet-module.h"
15#include "ns3/ipv4-global-routing-helper.h"
16#include "ns3/ipv4-global-routing.h"
17#include "ns3/ipv4-list-routing-helper.h"
18#include "ns3/ipv4-list-routing.h"
19#include "ns3/ipv4-routing-table-entry.h"
20#include "ns3/ipv4-static-routing-helper.h"
21#include "ns3/ipv4-static-routing.h"
22#include "ns3/network-module.h"
23#include "ns3/point-to-point-module.h"
24
25#include <cassert>
26#include <fstream>
27#include <iostream>
28#include <string>
29
30using namespace ns3;
31using std::cout;
32
33NS_LOG_COMPONENT_DEFINE("GlobalRouterInjectionTest");
34
35int
36main(int argc, char* argv[])
37{
38 // Allow the user to override any of the defaults and the above
39 // DefaultValue::Bind ()s at run-time, via command-line arguments
40 CommandLine cmd(__FILE__);
41 cmd.Parse(argc, argv);
42
46
47 NodeContainer c = NodeContainer(nA, nB, nC);
48
50
51 // Point-to-point links
52 NodeContainer nAnB = NodeContainer(nA, nB);
53 NodeContainer nBnC = NodeContainer(nB, nC);
54
55 internet.Install(nAnB);
56 Ipv4ListRoutingHelper staticonly;
57 Ipv4ListRoutingHelper staticRouting;
58 staticonly.Add(staticRouting, 0);
59 internet.SetRoutingHelper(staticonly); // has effect on the next Install ()
60 internet.Install(NodeContainer(nC));
61
62 // We create the channels first without any IP addressing information
64 p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
65 p2p.SetChannelAttribute("Delay", StringValue("2ms"));
66 NetDeviceContainer dAdB = p2p.Install(nAnB);
67
68 NetDeviceContainer dBdC = p2p.Install(nBnC);
69
71 deviceA->SetAddress(Mac48Address::Allocate());
72 nA->AddDevice(deviceA);
73 deviceA->SetQueue(CreateObject<DropTailQueue<Packet>>());
74
76 deviceC->SetAddress(Mac48Address::Allocate());
77 nC->AddDevice(deviceC);
78 deviceC->SetQueue(CreateObject<DropTailQueue<Packet>>());
79
80 // Later, we add IP addresses.
82 ipv4.SetBase("10.1.1.0", "255.255.255.252");
83 Ipv4InterfaceContainer iAiB = ipv4.Assign(dAdB);
84
85 ipv4.SetBase("10.1.1.4", "255.255.255.252");
86 Ipv4InterfaceContainer iBiC = ipv4.Assign(dBdC);
87
88 Ptr<Ipv4> ipv4A = nA->GetObject<Ipv4>();
89 Ptr<Ipv4> ipv4B = nB->GetObject<Ipv4>();
90 Ptr<Ipv4> ipv4C = nC->GetObject<Ipv4>();
91
92 int32_t ifIndexA = ipv4A->AddInterface(deviceA);
93 int32_t ifIndexC = ipv4C->AddInterface(deviceC);
94
95 Ipv4InterfaceAddress ifInAddrA =
96 Ipv4InterfaceAddress(Ipv4Address("172.16.1.1"), Ipv4Mask("255.255.255.255"));
97 ipv4A->AddAddress(ifIndexA, ifInAddrA);
98 ipv4A->SetMetric(ifIndexA, 1);
99 ipv4A->SetUp(ifIndexA);
100
101 Ipv4InterfaceAddress ifInAddrC =
102 Ipv4InterfaceAddress(Ipv4Address("192.168.1.1"), Ipv4Mask("255.255.255.255"));
103 ipv4C->AddAddress(ifIndexC, ifInAddrC);
104 ipv4C->SetMetric(ifIndexC, 1);
105 ipv4C->SetUp(ifIndexC);
106
107 // Create router nodes, initialize routing database and set up the routing
108 // tables in the nodes.
109
110 // Populate routing tables for nodes nA and nB
112 // Inject global routes from Node B, including transit network...
113 Ptr<GlobalRouter> globalRouterB = nB->GetObject<GlobalRouter>();
114 globalRouterB->InjectRoute("10.1.1.4", "255.255.255.252");
115 // ...and the host in network "C"
116 globalRouterB->InjectRoute("192.168.1.1", "255.255.255.255");
117
119 // In addition, nB needs a static route to nC so it knows what to do with stuff
120 // going to 192.168.1.1
121 Ipv4StaticRoutingHelper ipv4RoutingHelper;
122 Ptr<Ipv4StaticRouting> staticRoutingB = ipv4RoutingHelper.GetStaticRouting(ipv4B);
123 staticRoutingB->AddHostRouteTo(Ipv4Address("192.168.1.1"), Ipv4Address("10.1.1.6"), 2);
124
125 // Create the OnOff application to send UDP datagrams of size
126 // 210 bytes at a rate of 448 Kb/s
127 uint16_t port = 9; // Discard port (RFC 863)
128 OnOffHelper onoff("ns3::UdpSocketFactory",
129 Address(InetSocketAddress(ifInAddrC.GetLocal(), port)));
130 onoff.SetConstantRate(DataRate(6000));
131 ApplicationContainer apps = onoff.Install(nA);
132 apps.Start(Seconds(1.0));
133 apps.Stop(Seconds(10.0));
134
135 // Create a packet sink to receive these packets
136 PacketSinkHelper sink("ns3::UdpSocketFactory",
138 apps = sink.Install(nC);
139 apps.Start(Seconds(1.0));
140 apps.Stop(Seconds(10.0));
141
142 AsciiTraceHelper ascii;
143 p2p.EnableAsciiAll(ascii.CreateFileStream("global-routing-injection32.tr"));
144 p2p.EnablePcapAll("global-routing-injection32");
145
148
149 return 0;
150}
a polymophic address class
Definition address.h:90
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Parse command-line arguments.
Class for representing data rates.
Definition data-rate.h:78
A FIFO packet queue that drops tail-end packets on overflow.
An interface aggregated to a node to provide global routing info.
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
static void RecomputeRoutingTables()
Remove all routes that were previously installed in a prior call to either PopulateRoutingTables() or...
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
a class to store IPv4 address information on an interface
Ipv4Address GetLocal() const
Get the local address.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Helper class that adds ns3::Ipv4ListRouting objects.
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
a class to represent an Ipv4 address mask
Helper class that adds ns3::Ipv4StaticRouting objects.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
static Mac48Address Allocate()
Allocate a new Mac48Address.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Build a set of PointToPointNetDevice objects.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold variables of type string.
Definition string.h:45
uint16_t port
Definition dsdv-manet.cc:33
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition wifi-tcp.cc:44