A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
brite-test-topology.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 */
5
6#include "ns3/brite-module.h"
7#include "ns3/core-module.h"
8#include "ns3/internet-module.h"
9#include "ns3/network-module.h"
10#include "ns3/on-off-helper.h"
11#include "ns3/packet-sink-helper.h"
12#include "ns3/packet-sink.h"
13#include "ns3/point-to-point-module.h"
14#include "ns3/random-variable-stream.h"
15#include "ns3/test.h"
16
17#include <fstream>
18#include <iostream>
19#include <string>
20
21using namespace ns3;
22
23/**
24 * @ingroup brite-tests
25 *
26 * @brief BRITE topology structure Test
27 *
28 * Test that two brite topologies created with same seed value
29 * produce same graph (not an exact test)
30 */
32{
33 public:
36
37 private:
38 void DoRun() override;
39};
40
42 : TestCase("Test that two brite topologies created with same seed value produce same graph "
43 "(not an exact test)")
44{
45}
46
50
51void
53{
54 std::string confFile = "src/brite/test/test.conf";
55
58 BriteTopologyHelper bthA(confFile);
59 bthA.AssignStreams(1);
60
63 BriteTopologyHelper bthB(confFile);
64 bthB.AssignStreams(1);
65
67
68 bthA.BuildBriteTopology(stack);
69 bthB.BuildBriteTopology(stack);
70
71 int numAsA = bthA.GetNAs();
72 int numAsB = bthB.GetNAs();
73
74 // numAs should be 2 for the conf file in /src/brite/test/test.conf
75 NS_TEST_ASSERT_MSG_EQ(numAsA, 2, "Number of AS for this topology must be 2");
76 NS_TEST_ASSERT_MSG_EQ(numAsA, numAsB, "Number of AS should be same for both test topologies");
78 bthB.GetNNodesTopology(),
79 "Total number of nodes for each topology should be equal");
81 bthB.GetNEdgesTopology(),
82 "Total number of edges for each topology should be equal");
83
84 for (unsigned int i = 0; i < bthA.GetNAs(); ++i)
85 {
87 bthB.GetNLeafNodesForAs(i),
88 "Total number of leaf nodes different for AS " << i);
89 }
90}
91
92/**
93 * @ingroup brite-tests
94 *
95 * @brief BRITE topology function Test
96 *
97 * Test that packets can be send across a BRITE topology using UDP
98 */
100{
101 public:
104
105 private:
106 void DoRun() override;
107};
108
110 : TestCase("Test that packets can be send across a BRITE topology using UDP")
111{
112}
113
117
118void
120{
121 std::string confFile = "src/brite/test/test.conf";
122 BriteTopologyHelper bth(confFile);
123
126 Ipv4AddressHelper address;
127
128 address.SetBase("10.0.0.0", "255.255.255.0");
129
130 bth.BuildBriteTopology(stack);
131 bth.AssignIpv4Addresses(address);
132
133 NodeContainer source;
135
136 source.Create(1);
137 stack.Install(source);
138
139 // install source node on last leaf node of AS 0
140 int numNodesInAsZero = bth.GetNNodesForAs(0);
141 source.Add(bth.GetNodeForAs(0, numNodesInAsZero - 1));
142
143 sink.Create(1);
144 stack.Install(sink);
145
146 // install sink node on last leaf node on AS 1
147 int numNodesInAsOne = bth.GetNNodesForAs(1);
148 sink.Add(bth.GetNodeForAs(1, numNodesInAsOne - 1));
149
150 p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
151 p2p.SetChannelAttribute("Delay", StringValue("2ms"));
152
153 NetDeviceContainer p2pSourceDevices;
154 NetDeviceContainer p2pSinkDevices;
155
156 p2pSourceDevices = p2p.Install(source);
157 p2pSinkDevices = p2p.Install(sink);
158
159 address.SetBase("10.1.0.0", "255.255.0.0");
160 Ipv4InterfaceContainer sourceInterfaces;
161 sourceInterfaces = address.Assign(p2pSourceDevices);
162
163 address.SetBase("10.2.0.0", "255.255.0.0");
164 Ipv4InterfaceContainer sinkInterfaces;
165 sinkInterfaces = address.Assign(p2pSinkDevices);
166
167 uint16_t port = 9;
168
169 OnOffHelper onOff("ns3::UdpSocketFactory",
170 Address(InetSocketAddress(sinkInterfaces.GetAddress(0), port)));
171 onOff.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
172 onOff.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
173 onOff.SetAttribute("DataRate", DataRateValue(DataRate(6000)));
174
175 ApplicationContainer apps = onOff.Install(source.Get(0));
176
177 apps.Start(Seconds(1));
178 apps.Stop(Seconds(10));
179
180 PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
182 apps = sinkHelper.Install(sink.Get(0));
183
184 apps.Start(Seconds(1));
185 apps.Stop(Seconds(10));
186
188
191
193 // NS_TEST_ASSERT_MSG_EQ (sink1->GetTotalRx (), 6656, "Not all packets received from source");
194
196}
197
198/**
199 * @ingroup brite-tests
200 *
201 * @brief BRITE TestSuite
202 */
204{
205 public:
207 : TestSuite("brite-testing", Type::UNIT)
208 {
209 AddTestCase(new BriteTopologyStructureTestCase, TestCase::Duration::QUICK);
210 AddTestCase(new BriteTopologyFunctionTestCase, TestCase::Duration::QUICK);
211 }
212};
213
214/// Static variable for test initialization
static BriteTestSuite g_briteTestSuite
Static variable for test initialization.
BRITE TestSuite.
BRITE topology function Test.
void DoRun() override
Implementation to actually run this TestCase.
BRITE topology structure Test.
void DoRun() override
Implementation to actually run this TestCase.
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.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
ApplicationContainer Install(NodeContainer c)
Install an application on each node of the input container configured with all the attributes set wit...
void SetAttribute(const std::string &name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Interface with BRITE, the Boston university Representative Internet Topology gEnerator.
void AssignStreams(int64_t streamNumber)
Assigns stream number to UniformRandomVariable used to generate brite seed file.
uint32_t GetNAs() const
Returns the number of AS created in the topology.
uint32_t GetNNodesTopology() const
Returns the number of nodes created within the topology.
void BuildBriteTopology(InternetStackHelper &stack)
Create NS3 topology using information generated from BRITE.
uint32_t GetNLeafNodesForAs(uint32_t asNum)
Returns the number of router leaf nodes for a given AS.
uint32_t GetNEdgesTopology() const
Returns the number of edges created within the topology.
Class for representing data rates.
Definition data-rate.h:78
AttributeValue implementation for DataRate.
Definition data-rate.h:285
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.
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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 SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
uint16_t port
Definition dsdv-manet.cc:33
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:134
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition wifi-tcp.cc:44