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 
39 /// Unique PCAP file name prefix
40 const char * const PREFIX = "pmp-regression-test";
41 
PeerManagementProtocolRegressionTest()42 PeerManagementProtocolRegressionTest::PeerManagementProtocolRegressionTest () : TestCase ("PMP regression test"),
43                                                                                 m_nodes (0),
44                                                                                 m_time (Seconds (1))
45 {
46 }
47 
~PeerManagementProtocolRegressionTest()48 PeerManagementProtocolRegressionTest::~PeerManagementProtocolRegressionTest ()
49 {
50   delete m_nodes;
51 }
52 
53 void
DoRun()54 PeerManagementProtocolRegressionTest::DoRun ()
55 {
56   RngSeedManager::SetSeed (12345);
57   RngSeedManager::SetRun (7);
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
CreateNodes()71 PeerManagementProtocolRegressionTest::CreateNodes ()
72 {
73   m_nodes = new NodeContainer;
74   m_nodes->Create (2);
75   MobilityHelper mobility;
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
CreateDevices()88 PeerManagementProtocolRegressionTest::CreateDevices ()
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, nine streams per device (one for mac, one for phy,
103   // two for plugins, five for regular mac wifi DCF)
104   streamsUsed += mesh.AssignStreams (meshDevices, 0);
105   NS_TEST_ASSERT_MSG_EQ (streamsUsed, (meshDevices.GetN () * 9), "Stream assignment mismatch");
106   streamsUsed += wifiChannel.AssignStreams (chan, streamsUsed);
107   // 3. write PCAP if needed
108   wifiPhy.EnablePcapAll (CreateTempDirFilename (PREFIX));
109 }
110 
111 void
CheckResults()112 PeerManagementProtocolRegressionTest::CheckResults ()
113 {
114   for (int i = 0; i < 2; ++i)
115     {
116       NS_PCAP_TEST_EXPECT_EQ (PREFIX << "-" << i << "-1.pcap");
117     }
118 }
119 
120