A Discrete-Event Network Simulator
API
brite-test-topology.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  */
16 
17 #include "ns3/brite-module.h"
18 #include "ns3/core-module.h"
19 #include "ns3/internet-module.h"
20 #include "ns3/network-module.h"
21 #include "ns3/on-off-helper.h"
22 #include "ns3/packet-sink-helper.h"
23 #include "ns3/packet-sink.h"
24 #include "ns3/point-to-point-module.h"
25 #include "ns3/random-variable-stream.h"
26 #include "ns3/test.h"
27 
28 #include <fstream>
29 #include <iostream>
30 #include <string>
31 
32 using namespace ns3;
33 
43 {
44  public:
47 
48  private:
49  void DoRun() override;
50 };
51 
53  : TestCase("Test that two brite topologies created with same seed value produce same graph "
54  "(not an exact test)")
55 {
56 }
57 
59 {
60 }
61 
62 void
64 {
65  std::string confFile = "src/brite/test/test.conf";
66 
67  SeedManager::SetRun(1);
68  SeedManager::SetSeed(1);
70  bthA.AssignStreams(1);
71 
72  SeedManager::SetRun(1);
73  SeedManager::SetSeed(1);
75  bthB.AssignStreams(1);
76 
78 
81 
82  int numAsA = bthA.GetNAs();
83  int numAsB = bthB.GetNAs();
84 
85  // numAs should be 2 for the conf file in /src/brite/test/test.conf
86  NS_TEST_ASSERT_MSG_EQ(numAsA, 2, "Number of AS for this topology must be 2");
87  NS_TEST_ASSERT_MSG_EQ(numAsA, numAsB, "Number of AS should be same for both test topologies");
89  bthB.GetNNodesTopology(),
90  "Total number of nodes for each topology should be equal");
92  bthB.GetNEdgesTopology(),
93  "Total number of edges for each topology should be equal");
94 
95  for (unsigned int i = 0; i < bthA.GetNAs(); ++i)
96  {
98  bthB.GetNLeafNodesForAs(i),
99  "Total number of leaf nodes different for AS " << i);
100  }
101 }
102 
111 {
112  public:
115 
116  private:
117  void DoRun() override;
118 };
119 
121  : TestCase("Test that packets can be send across a BRITE topology using UDP")
122 {
123 }
124 
126 {
127 }
128 
129 void
131 {
132  std::string confFile = "src/brite/test/test.conf";
134 
138 
139  address.SetBase("10.0.0.0", "255.255.255.0");
140 
141  bth.BuildBriteTopology(stack);
142  bth.AssignIpv4Addresses(address);
143 
144  NodeContainer source;
146 
147  source.Create(1);
148  stack.Install(source);
149 
150  // install source node on last leaf node of AS 0
151  int numNodesInAsZero = bth.GetNNodesForAs(0);
152  source.Add(bth.GetNodeForAs(0, numNodesInAsZero - 1));
153 
154  sink.Create(1);
155  stack.Install(sink);
156 
157  // install sink node on last leaf node on AS 1
158  int numNodesInAsOne = bth.GetNNodesForAs(1);
159  sink.Add(bth.GetNodeForAs(1, numNodesInAsOne - 1));
160 
161  p2p.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
162  p2p.SetChannelAttribute("Delay", StringValue("2ms"));
163 
164  NetDeviceContainer p2pSourceDevices;
165  NetDeviceContainer p2pSinkDevices;
166 
167  p2pSourceDevices = p2p.Install(source);
168  p2pSinkDevices = p2p.Install(sink);
169 
170  address.SetBase("10.1.0.0", "255.255.0.0");
171  Ipv4InterfaceContainer sourceInterfaces;
172  sourceInterfaces = address.Assign(p2pSourceDevices);
173 
174  address.SetBase("10.2.0.0", "255.255.0.0");
175  Ipv4InterfaceContainer sinkInterfaces;
176  sinkInterfaces = address.Assign(p2pSinkDevices);
177 
178  uint16_t port = 9;
179 
180  OnOffHelper onOff("ns3::UdpSocketFactory",
181  Address(InetSocketAddress(sinkInterfaces.GetAddress(0), port)));
182  onOff.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
183  onOff.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
184  onOff.SetAttribute("DataRate", DataRateValue(DataRate(6000)));
185 
186  ApplicationContainer apps = onOff.Install(source.Get(0));
187 
188  apps.Start(Seconds(1.0));
189  apps.Stop(Seconds(10.0));
190 
191  PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
192  Address(InetSocketAddress(Ipv4Address::GetAny(), port)));
193  apps = sinkHelper.Install(sink.Get(0));
194 
195  apps.Start(Seconds(1.0));
196  apps.Stop(Seconds(10.0));
197 
198  Ipv4GlobalRoutingHelper::PopulateRoutingTables();
199 
200  Simulator::Stop(Seconds(10.0));
201  Simulator::Run();
202 
203  Ptr<PacketSink> sink1 = DynamicCast<PacketSink>(apps.Get(0));
204  // NS_TEST_ASSERT_MSG_EQ (sink1->GetTotalRx (), 6656, "Not all packets received from source");
205 
206  Simulator::Destroy();
207 }
208 
214 class BriteTestSuite : public TestSuite
215 {
216  public:
218  : TestSuite("brite-testing", UNIT)
219  {
220  AddTestCase(new BriteTopologyStructureTestCase, TestCase::QUICK);
221  AddTestCase(new BriteTopologyFunctionTestCase, TestCase::QUICK);
222  }
223 };
224 
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:101
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.
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.
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.
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.
Definition: on-off-helper.h:44
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
Build a set of PointToPointNetDevice objects.
Hold variables of type string.
Definition: string.h:56
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
uint16_t port
Definition: dsdv-manet.cc:44
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:327
#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:144
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
address
Definition: first.py:47
stack
Definition: first.py:44
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:55