A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
spectrum-interference-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 CTTC
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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #include <ns3/object.h>
22 #include <ns3/spectrum-interference.h>
23 #include <ns3/spectrum-error-model.h>
24 #include <ns3/log.h>
25 #include <ns3/test.h>
26 #include <ns3/simulator.h>
27 #include <ns3/packet.h>
28 #include <ns3/ptr.h>
29 #include <iostream>
30 
31 NS_LOG_COMPONENT_DEFINE ("SpectrumInterferenceTest");
32 
33 namespace ns3 {
34 
35 
36 
37 
39 {
40 public:
41  SpectrumInterferenceTestCase (Ptr<SpectrumValue> s, uint32_t txBytes, bool rxCorrect, std::string name);
43  virtual void DoRun (void);
45 
46 private:
48  uint32_t m_txBytes;
51 };
52 
53 
54 
55 SpectrumInterferenceTestCase::SpectrumInterferenceTestCase (Ptr<SpectrumValue> s, uint32_t txBytes, bool rxCorrect, std::string name)
56  : TestCase (name),
57  m_s (s),
58  m_txBytes (txBytes),
59  m_rxCorrectKnownOutcome (rxCorrect),
60  m_mySpectrumModel (s->GetSpectrumModel ())
61 {
62 }
63 
65 {
66 }
67 
68 
69 
70 void
72 {
73  Ptr<SpectrumValue> n = Create<SpectrumValue> (m_mySpectrumModel);
74  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_mySpectrumModel);
75  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_mySpectrumModel);
76  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_mySpectrumModel);
77  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_mySpectrumModel);
78 
79 
80  (*n)[0] = 5.000000000000e-19;
81  (*n)[1] = 4.545454545455e-19;
82 
83  (*i1)[0] = 5.000000000000e-18;
84  (*i2)[0] = 5.000000000000e-16;
85  (*i3)[0] = 1.581138830084e-16;
86  (*i4)[0] = 7.924465962306e-17;
87  (*i1)[1] = 1.437398936440e-18;
88  (*i2)[1] = 5.722388235428e-16;
89  (*i3)[1] = 7.204059965732e-17;
90  (*i4)[1] = 5.722388235428e-17;
91 
92 
94  si.SetErrorModel (CreateObject<ShannonSpectrumErrorModel> ());
96 
97  Time ts = Seconds (1);
98  Time ds = Seconds (1);
99  Time ti1 = Seconds (0);
100  Time di1 = Seconds (3);
101  Time ti2 = Seconds (0.7);
102  Time di2 = Seconds (1);
103  Time ti3 = Seconds (1.2);
104  Time di3 = Seconds (1);
105  Time ti4 = Seconds (1.5);
106  Time di4 = Seconds (0.1);
107 
113 
114  Ptr<Packet> p = Create<Packet> (m_txBytes);
117 
118  Simulator::Run ();
119  // the above will return and after RetrieveTestResults have
120  // been called and after all signals have expired
122 }
123 
124 
125 
126 void
128 {
129  NS_TEST_ASSERT_MSG_EQ (si->EndRx (), m_rxCorrectKnownOutcome, "no message");
130 }
131 
132 
133 
135 {
136 public:
138 };
139 
141  : TestSuite ("spectrum-interference", UNIT)
142 {
143 
144  NS_LOG_INFO ("creating SpectrumInterferenceTestSuite");
145 
147 
148  Bands bands;
149  struct BandInfo bi;
150 
151  bi.fl = 2.400e9;
152  bi.fc = 2.410e9;
153  bi.fh = 2.420e9;
154  bands.push_back (bi);
155 
156  bi.fl = 2.420e9;
157  bi.fc = 2.431e9;
158  bi.fh = 2.442e9;
159  bands.push_back (bi);
160 
161  m = Create<SpectrumModel> (bands);
162 
163 
164  double b; // max deliverable bytes
165 
166  const double e = 1e-5; // max tolerated relative error for
167  // deliverable bytes
168 
169  // Power Spectral Density of the signal of interest = [-46 -48] dBm;
170  Ptr<SpectrumValue> s1 = Create<SpectrumValue> (m);
171  (*s1)[0] = 1.255943215755e-15;
172  (*s1)[1] = 7.204059965732e-16;
173  b = 10067205.5632012;
174  AddTestCase (new SpectrumInterferenceTestCase (s1, 0, true, "sdBm = [-46 -48] tx bytes: 1"), TestCase::QUICK);
175  AddTestCase (new SpectrumInterferenceTestCase (s1, static_cast<uint32_t> (b * 0.5 + 0.5), true, "sdBm = [-46 -48] tx bytes: b*0.5"), TestCase::QUICK);
176  AddTestCase (new SpectrumInterferenceTestCase (s1, static_cast<uint32_t> (b * (1 - e) + 0.5), true, "sdBm = [-46 -48] tx bytes: b*(1-e)"), TestCase::QUICK);
177  AddTestCase (new SpectrumInterferenceTestCase (s1, static_cast<uint32_t> (b * (1 + e) + 0.5), false, "sdBm = [-46 -48] tx bytes: b*(1+e)"), TestCase::QUICK);
178  AddTestCase (new SpectrumInterferenceTestCase (s1, static_cast<uint32_t> (b * 1.5 + 0.5), false, "sdBm = [-46 -48] tx bytes: b*1.5"), TestCase::QUICK);
179  AddTestCase (new SpectrumInterferenceTestCase (s1, 0xffffffff, false, "sdBm = [-46 -48] tx bytes: 2^32-1"), TestCase::QUICK);
180 
181  // Power Spectral Density of the signal of interest = [-63 -61] dBm;
182  Ptr<SpectrumValue> s2 = Create<SpectrumValue> (m);
183  (*s2)[0] = 2.505936168136e-17;
184  (*s2)[1] = 3.610582885110e-17;
185  b = 882401.591840728;
186  AddTestCase (new SpectrumInterferenceTestCase (s2, 1, true, "sdBm = [-63 -61] tx bytes: 1"), TestCase::QUICK);
187  AddTestCase (new SpectrumInterferenceTestCase (s2, static_cast<uint32_t> (b * 0.5 + 0.5), true, "sdBm = [-63 -61] tx bytes: b*0.5"), TestCase::QUICK);
188  AddTestCase (new SpectrumInterferenceTestCase (s2, static_cast<uint32_t> (b * (1 - e) + 0.5), true, "sdBm = [-63 -61] tx bytes: b*(1-e)"), TestCase::QUICK);
189  AddTestCase (new SpectrumInterferenceTestCase (s2, static_cast<uint32_t> (b * (1 + e) + 0.5), false, "sdBm = [-63 -61] tx bytes: b*(1+e)"), TestCase::QUICK);
190  AddTestCase (new SpectrumInterferenceTestCase (s2, static_cast<uint32_t> (b * 1.5 + 0.5), false, "sdBm = [-63 -61] tx bytes: b*1.5"), TestCase::QUICK);
191  AddTestCase (new SpectrumInterferenceTestCase (s2, 0xffffffff, false, "sdBm = [-63 -61] tx bytes: 2^32-1"), TestCase::QUICK);
192 
193 }
194 
196 
197 } // namespace ns3
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
A suite of tests to run.
Definition: test.h:1025
static SpectrumInterferenceTestSuite spectrumInterferenceTestSuite
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
#define NS_LOG_INFO(msg)
Definition: log.h:298
SpectrumInterferenceTestCase(Ptr< SpectrumValue > s, uint32_t txBytes, bool rxCorrect, std::string name)
void AddSignal(Ptr< const SpectrumValue > spd, const Time duration)
notify that a new signal is being perceived in the medium.
encapsulates test code
Definition: test.h:849
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
void StartRx(Ptr< const Packet > p, Ptr< const SpectrumValue > rxPsd)
notify that the PHY is starting a RX attempt
std::vector< BandInfo > Bands
double fc
center frequency
Ptr< SampleEmitter > s
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
double fl
lower limit of subband
Ptr< const SpectrumModel > m_mySpectrumModel
bool EndRx()
notify that the RX attempt has ended.
This class implements a gaussian interference model, i.e., all incoming signals are added to the tota...
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
Fast test.
Definition: test.h:857
NS_LOG_COMPONENT_DEFINE("SpectrumInterferenceTest")
void SetErrorModel(Ptr< SpectrumErrorModel > e)
set the SpectrumErrorModel to be used.
virtual void DoRun(void)
Implementation to actually run this TestCase.
double fh
upper limit of subband
The building block of a SpectrumModel.
void RetrieveTestResult(SpectrumInterference *si)
#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:137