A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
brite-test-topology.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  */
17 
18 #include <string>
19 #include "ns3/core-module.h"
20 #include "ns3/network-module.h"
21 #include "ns3/internet-module.h"
22 #include "ns3/point-to-point-module.h"
23 #include "ns3/packet-sink-helper.h"
24 #include "ns3/packet-sink.h"
25 #include "ns3/random-variable-stream.h"
26 #include "ns3/on-off-helper.h"
27 #include "ns3/brite-module.h"
28 #include "ns3/test.h"
29 #include <iostream>
30 #include <fstream>
31 
32 namespace ns3 {
33 
35 {
36 public:
39 
40 private:
41  virtual void DoRun (void);
42 
43 };
44 
45 BriteTopologyStructureTestCase::BriteTopologyStructureTestCase ()
46  : TestCase ("Test that two brite topologies created with same seed value produce same graph (not an exact test)")
47 {
48 }
49 
50 BriteTopologyStructureTestCase::~BriteTopologyStructureTestCase ()
51 {
52 }
53 
55 {
56 
57  std::string confFile = "src/brite/test/test.conf";
58 
61  BriteTopologyHelper bthA (confFile);
62  bthA.AssignStreams (1);
63 
66  BriteTopologyHelper bthB (confFile);
67  bthB.AssignStreams (1);
68 
69  InternetStackHelper stack;
70 
71  bthA.BuildBriteTopology (stack);
72  bthB.BuildBriteTopology (stack);
73 
74  int numAsA = bthA.GetNAs ();
75  int numAsB = bthB.GetNAs ();
76 
77  //numAs should be 2 for the conf file in /src/brite/test/test.conf
78  NS_TEST_ASSERT_MSG_EQ (numAsA, 2, "Number of AS for this topology must be 2");
79  NS_TEST_ASSERT_MSG_EQ (numAsA, numAsB, "Number of AS should be same for both test topologies");
80  NS_TEST_ASSERT_MSG_EQ (bthA.GetNNodesTopology (), bthB.GetNNodesTopology (), "Total number of nodes for each topology should be equal");
81  NS_TEST_ASSERT_MSG_EQ (bthA.GetNEdgesTopology (), bthB.GetNEdgesTopology (), "Total number of edges for each topology should be equal");
82 
83  for (unsigned int i = 0; i < bthA.GetNAs (); ++i)
84  {
85  NS_TEST_ASSERT_MSG_EQ (bthA.GetNLeafNodesForAs (i), bthB.GetNLeafNodesForAs (i), "Total number of leaf nodes different for AS " << i);
86  }
87 }
88 
90 {
91 public:
94 
95 private:
96  virtual void DoRun (void);
97 
98 };
99 
100 BriteTopologyFunctionTestCase::BriteTopologyFunctionTestCase ()
101  : TestCase ("Test that packets can be send across a BRITE topology using UDP")
102 {
103 }
104 
105 BriteTopologyFunctionTestCase::~BriteTopologyFunctionTestCase ()
106 {
107 }
108 
110 {
111 
112  std::string confFile = "src/brite/test/test.conf";
113  BriteTopologyHelper bth (confFile);
114 
115  PointToPointHelper p2p;
116  InternetStackHelper stack;
117  Ipv4AddressHelper address;
118 
119  address.SetBase ("10.0.0.0", "255.255.255.0");
120 
121  bth.BuildBriteTopology (stack);
122  bth.AssignIpv4Addresses (address);
123 
124  NodeContainer source;
125  NodeContainer sink;
126 
127  source.Create (1);
128  stack.Install (source);
129 
130  //install source node on last leaf node of AS 0
131  int numNodesInAsZero = bth.GetNNodesForAs (0);
132  source.Add (bth.GetNodeForAs (0, numNodesInAsZero - 1));
133 
134  sink.Create (1);
135  stack.Install (sink);
136 
137  //install sink node on last leaf node on AS 1
138  int numNodesInAsOne = bth.GetNNodesForAs (1);
139  sink.Add (bth.GetNodeForAs (1, numNodesInAsOne - 1));
140 
141  p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
142  p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
143 
144  NetDeviceContainer p2pSourceDevices;
145  NetDeviceContainer p2pSinkDevices;
146 
147  p2pSourceDevices = p2p.Install (source);
148  p2pSinkDevices = p2p.Install (sink);
149 
150  address.SetBase ("10.1.0.0", "255.255.0.0");
151  Ipv4InterfaceContainer sourceInterfaces;
152  sourceInterfaces = address.Assign (p2pSourceDevices);
153 
154  address.SetBase ("10.2.0.0", "255.255.0.0");
155  Ipv4InterfaceContainer sinkInterfaces;
156  sinkInterfaces = address.Assign (p2pSinkDevices);
157 
158  uint16_t port = 9;
159 
160  OnOffHelper onOff ("ns3::UdpSocketFactory",
161  Address (InetSocketAddress (sinkInterfaces.GetAddress (0), port)));
162  onOff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
163  onOff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
164  onOff.SetAttribute ("DataRate", DataRateValue (DataRate (6000)));
165 
166  ApplicationContainer apps = onOff.Install (source.Get (0));
167 
168  apps.Start (Seconds (1.0));
169  apps.Stop (Seconds (10.0));
170 
171  PacketSinkHelper sinkHelper ("ns3::UdpSocketFactory",
173  apps = sinkHelper.Install (sink.Get (0));
174 
175  apps.Start (Seconds (1.0));
176  apps.Stop (Seconds (10.0));
177 
179 
180  Simulator::Stop (Seconds (10.0));
181  Simulator::Run ();
182 
183  Ptr<PacketSink> sink1 = DynamicCast<PacketSink> (apps.Get (0));
184  //NS_TEST_ASSERT_MSG_EQ (sink1->GetTotalRx (), 6656, "Not all packets received from source");
185 
187 
188 }
189 
190 class BriteTestSuite : public TestSuite
191 {
192 public:
193  BriteTestSuite () : TestSuite ("brite-testing", UNIT)
194  {
195  AddTestCase (new BriteTopologyStructureTestCase, TestCase::QUICK);
196  AddTestCase (new BriteTopologyFunctionTestCase, TestCase::QUICK);
197  }
198 } g_briteTestSuite;
199 
200 } // namespace ns3
holds a vector of ns3::Application pointers.
virtual void DoRun(void)
Implementation to actually run this test case.
an Inet address class
static Ipv4Address GetAny(void)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation. Makes all nodes in the simulation into routers.
hold variables of type string
Definition: string.h:19
NetDeviceContainer Install(NodeContainer c)
A suite of tests to run.
Definition: test.h:962
static void Run(void)
Definition: simulator.cc:157
uint32_t GetNAs(void) const
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
encapsulates test code
Definition: test.h:834
void SetDeviceAttribute(std::string name, const AttributeValue &value)
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
Definition: test.cc:354
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:41
static void SetRun(uint64_t run)
Set the run number of simulation.
a polymophic address class
Definition: address.h:86
Class for representing data rates.
Definition: data-rate.h:71
void AssignIpv4Addresses(Ipv4AddressHelper &address)
holds a vector of ns3::NetDevice pointers
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
static void Destroy(void)
Definition: simulator.cc:121
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
virtual void DoRun(void)
Implementation to actually run this test case.
void Install(std::string nodeName) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
void SetChannelAttribute(std::string name, const AttributeValue &value)
static void SetSeed(uint32_t seed)
set the seed it will duplicate the seed value 6 times
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
hold objects of type ns3::DataRate
static void Stop(void)
Definition: simulator.cc:164
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
ApplicationContainer Install(NodeContainer c) const
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetAttribute(std::string name, const AttributeValue &value)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const