A Discrete-Event Network Simulator
API
phy-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008, 2009 INRIA, UDcast
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  * Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  * <amine.ismail@udcast.com>
20  */
21 #include "ns3/log.h"
22 #include "ns3/test.h"
23 #include "ns3/simulator.h"
24 #include "ns3/node-container.h"
25 #include "ns3/net-device-container.h"
26 #include "ns3/wimax-helper.h"
27 #include "ns3/snr-to-block-error-rate-manager.h"
28 
29 using namespace ns3;
30 
31 NS_LOG_COMPONENT_DEFINE ("WimaxPhyTest");
32 
33 /*
34  * Configure a network with 3 SS and 1 BS
35  * Install a SIMPLE OFDM PHY layer on all nodes and check that all SSs
36  * could register with the BS
37  *
38  */
39 
41 {
42 public:
44  virtual ~Ns3WimaxSimpleOFDMTestCase ();
45 
46 private:
47  virtual void DoRun (void);
48  bool DoRunOnce (double);
49 
50 };
51 
53  : TestCase ("Test the Phy model with different frame durations")
54 {
55 }
56 
58 {
59 }
60 
61 bool
63 {
64  WimaxHelper::SchedulerType scheduler = WimaxHelper::SCHED_TYPE_SIMPLE;
65  NodeContainer ssNodes;
66  NodeContainer bsNodes;
67  ssNodes.Create (3);
68  bsNodes.Create (1);
69 
70  WimaxHelper wimax;
71 
72  NetDeviceContainer ssDevs, bsDevs;
73 
74  ssDevs = wimax.Install (ssNodes, WimaxHelper::DEVICE_TYPE_SUBSCRIBER_STATION,
75  WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler, FrameDuration);
76  bsDevs = wimax.Install (bsNodes, WimaxHelper::DEVICE_TYPE_BASE_STATION,
77  WimaxHelper::SIMPLE_PHY_TYPE_OFDM, scheduler, FrameDuration);
78 
79  Simulator::Stop (Seconds (1));
80  Simulator::Run ();
81  for (int i = 0; i < 3; i++)
82  {
83  if (ssDevs.Get (i)->GetObject<SubscriberStationNetDevice> ()->IsRegistered ()
84  == false)
85  {
86  NS_LOG_DEBUG ("SS[" << i << "] not registered");
87  return true; // Test fail because SS[i] is not registered
88  }
89  }
90  Simulator::Destroy ();
91  return (false); // Test was ok, all the SSs are registered
92 
93 }
94 
95 void
97 {
98 
99  double
100  frameDuratioTab[7] = { 0.0025, 0.004, 0.005, 0.008, 0.01, 0.0125, 0.02 };
101  for (int i = 0; i < 7; i++)
102  {
103  NS_LOG_DEBUG ("Frame Duration = " << frameDuratioTab[i]);
104  if (DoRunOnce (frameDuratioTab[i]) != false)
105  {
106  return;
107  }
108  }
109 }
110 
111 /*
112  * Test the SNr tom block error rate module
113  */
114 
116 {
117 public:
119  virtual ~Ns3WimaxSNRtoBLERTestCase ();
120 
121 private:
122  virtual void DoRun (void);
123  bool DoRunOnce (uint8_t);
124 
125 };
126 
128  : TestCase ("Test the SNR to block error rate module")
129 {
130 }
131 
133 {
134 }
135 
136 bool Ns3WimaxSNRtoBLERTestCase::DoRunOnce (uint8_t modulationType)
137 {
138 
139  SNRToBlockErrorRateManager l_SNRToBlockErrorRateManager;
140  l_SNRToBlockErrorRateManager.LoadTraces ();
141  SNRToBlockErrorRateRecord * BLERRec;
142 
143  for (double i = -5; i < 40; i += 0.1)
144  {
145  BLERRec = l_SNRToBlockErrorRateManager.GetSNRToBlockErrorRateRecord (i,
146  modulationType);
147  delete BLERRec;
148  }
149  return false;
150 }
151 
152 void
154 {
155  for (int i = 0; i < 7; i++)
156  {
157  DoRunOnce (i);
158  }
159 }
160 
161 /*
162  * The test suite
163  */
165 {
166 public:
168 };
170  : TestSuite ("wimax-phy-layer", UNIT)
171 {
172  AddTestCase (new Ns3WimaxSNRtoBLERTestCase, TestCase::QUICK);
173  AddTestCase (new Ns3WimaxSimpleOFDMTestCase, TestCase::QUICK);
174 
175 }
176 
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
A suite of tests to run.
Definition: test.h:1333
SchedulerType
Scheduler Type Different implementations of uplink/downlink scheduler.
Definition: wimax-helper.h:85
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
encapsulates test code
Definition: test.h:1147
NetDeviceContainer Install(NodeContainer c, NetDeviceType type, PhyType phyType, SchedulerType schedulerType)
virtual ~Ns3WimaxSNRtoBLERTestCase()
Definition: phy-test.cc:132
This class represents a record (handled by SnrToBlockErrorRate manager) that keeps a mapping between ...
SNRToBlockErrorRateRecord * GetSNRToBlockErrorRateRecord(double SNR, uint8_t modulation)
returns a record of type SNRToBlockErrorRateRecord corresponding to a given modulation and SNR value ...
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
holds a vector of ns3::NetDevice pointers
bool DoRunOnce(double)
Definition: phy-test.cc:62
virtual ~Ns3WimaxSimpleOFDMTestCase()
Definition: phy-test.cc:57
void LoadTraces(void)
Loads the traces form the repository specified in the constructor or setted by SetTraceFilePath funct...
static Ns3WimaxPhyTestSuite ns3WimaxPhyTestSuite
Definition: phy-test.cc:177
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: phy-test.cc:153
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition: phy-test.cc:96
helps to manage and create WimaxNetDevice objects
Definition: wimax-helper.h:58
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
This class handles the SNR to BlcER traces.
bool DoRunOnce(uint8_t)
Definition: phy-test.cc:136