A Discrete-Event Network Simulator
API
pmp-regression.cc
Go to the documentation of this file.
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 #include "ns3/mesh-helper.h"
21 #include "ns3/simulator.h"
22 #include "ns3/random-variable-stream.h"
23 #include "ns3/rng-seed-manager.h"
24 #include "ns3/mobility-helper.h"
25 #include "ns3/double.h"
26 #include "ns3/uinteger.h"
27 #include "ns3/string.h"
28 #include "ns3/yans-wifi-helper.h"
29 #include "ns3/internet-stack-helper.h"
30 #include "ns3/mobility-model.h"
31 #include "ns3/pcap-file.h"
32 #include "ns3/pcap-test.h"
33 #include <sstream>
34 
35 #include "pmp-regression.h"
36 
37 using namespace ns3;
38 
40 const char * const PREFIX = "pmp-regression-test";
41 
43  m_nodes (0),
44  m_time (Seconds (1))
45 {
46 }
47 
49 {
50  delete m_nodes;
51 }
52 
53 void
55 {
56  RngSeedManager::SetSeed (1);
57  RngSeedManager::SetRun (1);
58  CreateNodes ();
59  CreateDevices ();
60 
61  Simulator::Stop (m_time);
62  Simulator::Run ();
63  Simulator::Destroy ();
64 
65  CheckResults ();
66 
67  delete m_nodes, m_nodes = 0;
68 }
69 
70 void
72 {
73  m_nodes = new NodeContainer;
74  m_nodes->Create (2);
76  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
77  "MinX", DoubleValue (0.0),
78  "MinY", DoubleValue (0.0),
79  "DeltaX", DoubleValue (1 /*meter*/),
80  "DeltaY", DoubleValue (0),
81  "GridWidth", UintegerValue (2),
82  "LayoutType", StringValue ("RowFirst"));
83  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
84  mobility.Install (*m_nodes);
85 }
86 
87 void
89 {
90  int64_t streamsUsed = 0;
91  // 1. setup WiFi
92  YansWifiPhyHelper wifiPhy;
93  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
94  Ptr<YansWifiChannel> chan = wifiChannel.Create ();
95  wifiPhy.SetChannel (chan);
96  // 2. setup mesh
97  MeshHelper mesh = MeshHelper::Default ();
98  mesh.SetStackInstaller ("ns3::Dot11sStack");
99  mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1)));
100  mesh.SetNumberOfInterfaces (1);
101  NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes);
102  // Two devices, 10 streams per device (one for mac, one for phy,
103  // two for plugins, five for regular mac wifi DCF, and one for MeshPointDevice)
104  streamsUsed += mesh.AssignStreams (meshDevices, 0);
105  NS_TEST_ASSERT_MSG_EQ (streamsUsed, (meshDevices.GetN () * 10), "Stream assignment mismatch");
106  streamsUsed += wifiChannel.AssignStreams (chan, streamsUsed);
107  // 3. write PCAP if needed
109 }
110 
111 void
113 {
114  for (int i = 0; i < 2; ++i)
115  {
116  NS_PCAP_TEST_EXPECT_EQ (PREFIX << "-" << i << "-1.pcap");
117  }
118 }
119 
void CreateDevices()
Create devices function.
void CheckResults()
Check results function.
void CreateNodes()
Create nodes function.
void DoRun()
Implementation to actually run this TestCase.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
Helper to create IEEE 802.11s mesh networks.
Definition: mesh-helper.h:44
void SetMacType(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: mesh-helper.cc:130
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: mesh-helper.cc:235
NetDeviceContainer Install(const WifiPhyHelper &phyHelper, NodeContainer c) const
Install 802.11s mesh device & protocols on given node list.
Definition: mesh-helper.cc:86
void SetStackInstaller(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: mesh-helper.cc:53
void SetNumberOfInterfaces(uint32_t nInterfaces)
Set a number of interfaces in a mesh network.
Definition: mesh-helper.cc:81
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
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 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 ...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Hold variables of type string.
Definition: string.h:41
encapsulates test code
Definition: test.h:994
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:430
AttributeValue implementation for Time.
Definition: nstime.h:1308
Hold an unsigned integer type.
Definition: uinteger.h:44
manage and create wifi channel objects for the YANS model.
Ptr< YansWifiChannel > Create(void) const
int64_t AssignStreams(Ptr< YansWifiChannel > c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the channel.
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
#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:141
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mobility
Definition: third.py:108
#define NS_PCAP_TEST_EXPECT_EQ(filename)
Test that a pair of reference/new pcap files are equal.
Definition: pcap-test.h:38
const char *const PREFIX
Unique PCAP file name prefix.
double m_time
Definition: qkd_etsi_014.cc:62