A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tc-regression-test.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Pavel Boyko <boyko@iitp.ru>
19  */
20 
21 #include "tc-regression-test.h"
22 #include "ns3/simulator.h"
23 #include "ns3/random-variable-stream.h"
24 #include "ns3/rng-seed-manager.h"
25 #include "ns3/boolean.h"
26 #include "ns3/double.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/string.h"
29 #include "ns3/pcap-test.h"
30 #include "ns3/pcap-file.h"
31 #include "ns3/olsr-helper.h"
32 #include "ns3/internet-stack-helper.h"
33 #include "ns3/point-to-point-helper.h"
34 #include "ns3/ipv4-address-helper.h"
35 #include "ns3/abort.h"
36 #include "ns3/yans-wifi-helper.h"
37 #include "ns3/mobility-helper.h"
38 #include "ns3/nqos-wifi-mac-helper.h"
39 
40 namespace ns3
41 {
42 namespace olsr
43 {
44 
45 const char * const TcRegressionTest::PREFIX = "olsr-tc-regression-test";
46 
47 TcRegressionTest::TcRegressionTest() :
48  TestCase ("Test OLSR Topology Control message generation"),
49  m_time (Seconds (20)),
50  m_step (120)
51 {
52 }
53 
54 TcRegressionTest::~TcRegressionTest()
55 {
56 }
57 
58 void
60 {
63  CreateNodes ();
64 
66  Simulator::Run ();
68 
69  CheckResults ();
70 }
71 
72 void
74 {
75  // create 3 nodes
76  NodeContainer c;
77  c.Create (3);
78 
79  // place nodes in the chain
80  MobilityHelper mobility;
81  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
82  "MinX", DoubleValue (0.0),
83  "MinY", DoubleValue (0.0),
84  "DeltaX", DoubleValue (m_step),
85  "DeltaY", DoubleValue (0),
86  "GridWidth", UintegerValue (3),
87  "LayoutType", StringValue ("RowFirst"));
88  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
89  mobility.Install (c);
90 
91  // install TCP/IP & OLSR
92  OlsrHelper olsr;
93  InternetStackHelper internet;
94  internet.SetRoutingHelper (olsr);
95  internet.Install (c);
96  int64_t streamsUsed = olsr.AssignStreams (c, 0);
97  NS_TEST_EXPECT_MSG_EQ (streamsUsed, 3, "Should have assigned 2 streams");
98 
99  // create wifi channel & devices
101  wifiMac.SetType ("ns3::AdhocWifiMac");
104  wifiPhy.SetChannel (wifiChannel.Create ());
105  // This test suite output was originally based on YansErrorRateModel
106  wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
109  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", StringValue ("2200"));
110  NetDeviceContainer nd = wifi.Install (wifiPhy, wifiMac, c);
111 
112  // setup IP addresses
113  Ipv4AddressHelper ipv4;
114  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
115  ipv4.Assign (nd);
116 
117  // setup PCAP traces
118  wifiPhy.EnablePcapAll (CreateTempDirFilename(PREFIX));
119 }
120 
121 void
123 {
124  for (uint32_t i = 0; i < 3; ++i)
125  {
126  NS_PCAP_TEST_EXPECT_EQ (PREFIX << "-" << i << "-1.pcap");
127  }
128 }
129 
130 }
131 }
void CreateNodes()
Create & configure test network.
void SetErrorRateModel(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:68
hold variables of type string
Definition: string.h:19
Make it easy to create and manage PHY objects for the yans model.
static YansWifiChannelHelper Default(void)
void CheckResults()
Compare traces with reference ones.
void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
static void Run(void)
Definition: simulator.cc:157
int64_t AssignStreams(NodeContainer c, int64_t stream)
Definition: olsr-helper.cc:87
aggregate IP/TCP/UDP functionality to existing Nodes.
Helper class that adds OLSR routing to nodes.
Definition: olsr-helper.h:38
static const char *const PREFIX
Unique PCAP files prefix for this test.
static YansWifiPhyHelper Default(void)
helps to create WifiNetDevice objects
Definition: wifi-helper.h:92
static void SetRun(uint64_t run)
Set the run number of simulation.
NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:97
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
Hold an unsigned integer type.
Definition: uinteger.h:46
holds a vector of ns3::NetDevice pointers
void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:91
static NqosWifiMacHelper Default(void)
create non QoS-enabled MAC layers for a ns3::WifiNetDevice.
static void Destroy(void)
Definition: simulator.cc:121
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
manage and create wifi channel objects for the yans model.
static void SetSeed(uint32_t seed)
set the seed it will duplicate the seed value 6 times
Helper class used to assign positions and mobility models to nodes.
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
static void Stop(void)
Definition: simulator.cc:164
const Time m_time
Total simulation time.
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 SetPositionAllocator(Ptr< PositionAllocator > allocator)
Hold an floating point type.
Definition: double.h:41
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
const double m_step
Distance between nodes in meters, 0.8 of RX range is recommended.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
static WifiHelper Default(void)
Definition: wifi-helper.cc:60