6622
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
|
2 |
/*
|
|
3 |
* Copyright (c) 2009 University of Washington
|
|
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: Leonard Tracy <lentracy@gmail.com>
|
|
19 |
*/
|
|
20 |
|
|
21 |
#include "ns3/uan-net-device.h"
|
|
22 |
#include "ns3/uan-channel.h"
|
|
23 |
#include "ns3/uan-mac-aloha.h"
|
|
24 |
#include "ns3/uan-phy-gen.h"
|
|
25 |
#include "ns3/uan-transducer-hd.h"
|
|
26 |
#include "ns3/uan-prop-model-ideal.h"
|
|
27 |
#include "ns3/constant-position-mobility-model.h"
|
|
28 |
#include "ns3/simulator.h"
|
|
29 |
#include "ns3/test.h"
|
|
30 |
#include "ns3/node.h"
|
|
31 |
#include "ns3/object-factory.h"
|
|
32 |
#include "ns3/pointer.h"
|
|
33 |
#include "ns3/callback.h"
|
|
34 |
|
|
35 |
using namespace ns3;
|
|
36 |
|
|
37 |
class UanTest : public TestCase
|
|
38 |
{
|
|
39 |
public:
|
|
40 |
UanTest ();
|
|
41 |
|
|
42 |
virtual bool DoRun (void);
|
|
43 |
private:
|
|
44 |
Ptr<UanNetDevice> CreateNode (Vector pos, Ptr<UanChannel> chan);
|
|
45 |
bool DoPhyTests ();
|
|
46 |
uint32_t DoOnePhyTest (Time t1, Time t2, uint32_t r1, uint32_t r2, Ptr<UanPropModel> prop, uint32_t mode1 = 0, uint32_t mode2 = 0);
|
|
47 |
bool RxPacket (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender);
|
|
48 |
void SendOnePacket (Ptr<UanNetDevice> dev, uint32_t mode);
|
|
49 |
ObjectFactory m_phyFac;
|
|
50 |
uint32_t m_bytesRx;
|
|
51 |
|
|
52 |
};
|
|
53 |
|
|
54 |
|
|
55 |
UanTest::UanTest () : TestCase ("UAN")
|
|
56 |
{
|
|
57 |
|
|
58 |
}
|
|
59 |
|
|
60 |
bool
|
|
61 |
UanTest::RxPacket (Ptr<NetDevice> dev, Ptr<const Packet> pkt, uint16_t mode, const Address &sender)
|
|
62 |
{
|
|
63 |
m_bytesRx += pkt->GetSize ();
|
|
64 |
return true;
|
|
65 |
}
|
|
66 |
void
|
|
67 |
UanTest::SendOnePacket (Ptr<UanNetDevice> dev, uint32_t mode)
|
|
68 |
{
|
|
69 |
Ptr<Packet> pkt = Create<Packet> (17);
|
|
70 |
dev->Send (pkt, dev->GetBroadcast (), mode);
|
|
71 |
|
|
72 |
}
|
|
73 |
Ptr<UanNetDevice>
|
|
74 |
UanTest::CreateNode (Vector pos, Ptr<UanChannel> chan)
|
|
75 |
{
|
|
76 |
|
|
77 |
|
|
78 |
Ptr<UanPhy> phy = m_phyFac.Create<UanPhy> ();
|
|
79 |
Ptr<Node> node = CreateObject<Node> ();
|
|
80 |
Ptr<UanNetDevice> dev = CreateObject<UanNetDevice> ();
|
|
81 |
Ptr<UanMacAloha> mac = CreateObject<UanMacAloha> ();
|
|
82 |
Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
|
|
83 |
|
|
84 |
Ptr<UanTransducerHd> trans = CreateObject<UanTransducerHd> ();
|
|
85 |
|
|
86 |
mobility->SetPosition (pos);
|
|
87 |
node->AggregateObject (mobility);
|
|
88 |
mac->SetAddress (UanAddress::Allocate ());
|
|
89 |
|
|
90 |
dev->SetPhy (phy);
|
|
91 |
dev->SetMac (mac);
|
|
92 |
dev->SetChannel (chan);
|
|
93 |
dev->SetTransducer (trans);
|
|
94 |
node->AddDevice (dev);
|
|
95 |
|
|
96 |
return dev;
|
|
97 |
}
|
|
98 |
|
|
99 |
|
|
100 |
uint32_t
|
|
101 |
UanTest::DoOnePhyTest (Time txTime1,
|
|
102 |
Time txTime2,
|
|
103 |
uint32_t r1,
|
|
104 |
uint32_t r2,
|
|
105 |
Ptr<UanPropModel> prop,
|
|
106 |
uint32_t mode1,
|
|
107 |
uint32_t mode2)
|
|
108 |
{
|
|
109 |
|
|
110 |
Ptr<UanChannel> channel = CreateObject<UanChannel> ();
|
|
111 |
channel->SetAttribute ("PropagationModel", PointerValue (prop));
|
|
112 |
|
|
113 |
Ptr<UanNetDevice> dev0 = CreateNode (Vector (r1,50,50), channel);
|
|
114 |
Ptr<UanNetDevice> dev1 = CreateNode (Vector (0,50,50), channel);
|
|
115 |
Ptr<UanNetDevice> dev2 = CreateNode (Vector (r1 + r2, 50, 50), channel);
|
|
116 |
|
|
117 |
dev0->SetReceiveCallback (MakeCallback (&UanTest::RxPacket, this));
|
|
118 |
|
|
119 |
Simulator::Schedule (txTime1, &UanTest::SendOnePacket, this, dev1, mode1);
|
|
120 |
Simulator::Schedule (txTime2, &UanTest::SendOnePacket, this, dev2, mode2);
|
|
121 |
|
|
122 |
m_bytesRx = 0;
|
|
123 |
Simulator::Stop (Seconds (20.0));
|
|
124 |
Simulator::Run ();
|
|
125 |
Simulator::Destroy ();
|
|
126 |
|
|
127 |
return m_bytesRx;
|
|
128 |
}
|
|
129 |
|
|
130 |
|
|
131 |
bool
|
|
132 |
UanTest::DoPhyTests ()
|
|
133 |
{
|
|
134 |
// Phy Gen / Default PER / Default SINR
|
|
135 |
AttributeList phyList;
|
|
136 |
UanModesList mList;
|
|
137 |
UanTxMode mode = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode");
|
|
138 |
mList.AppendMode (UanTxMode (mode));
|
|
139 |
Ptr<UanPhyPerGenDefault> perDef = CreateObject<UanPhyPerGenDefault> ();
|
|
140 |
Ptr<UanPhyCalcSinrDefault> sinrDef = CreateObject<UanPhyCalcSinrDefault> ();
|
|
141 |
TypeId phyId = TypeId::LookupByName ("ns3::UanPhyGen");
|
|
142 |
m_phyFac.SetTypeId (phyId);
|
|
143 |
phyList.SetWithTid (phyId, "PerModel", PointerValue (perDef));
|
|
144 |
phyList.SetWithTid (phyId, "SinrModel", PointerValue (sinrDef));
|
|
145 |
phyList.SetWithTid (phyId, "SupportedModes", UanModesListValue (mList));
|
|
146 |
|
|
147 |
m_phyFac.Set (phyList);
|
|
148 |
|
|
149 |
Ptr<UanPropModelIdeal> prop = CreateObject<UanPropModelIdeal> ();
|
|
150 |
|
|
151 |
// No collision (Get 2 packets)
|
|
152 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (3.001), 50, 50, prop),
|
|
153 |
34, "Should have received 34 bytes from 2 disjoint packets");
|
|
154 |
|
|
155 |
// Collision (Lose both packets)
|
|
156 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop),
|
|
157 |
0, "Expected collision resulting in loss of both packets");
|
|
158 |
|
|
159 |
|
|
160 |
// Phy Gen / FH-FSK SINR check
|
|
161 |
|
|
162 |
Ptr<UanPhyCalcSinrFhFsk> sinrFhfsk = CreateObject <UanPhyCalcSinrFhFsk> ();
|
|
163 |
phyList.Reset ();
|
|
164 |
phyList.SetWithTid (phyId, "PerModel", PointerValue (perDef));
|
|
165 |
phyList.SetWithTid (phyId, "SinrModel", PointerValue (sinrFhfsk));
|
|
166 |
phyList.SetWithTid (phyId, "SupportedModes", UanModesListValue (mList));
|
|
167 |
m_phyFac.Set (phyList);
|
|
168 |
|
|
169 |
#ifdef UAN_PROP_BH_INSTALLED
|
|
170 |
Ptr<UanPropModelBh> prop = CreateObject<UanPropModelBh> ();
|
|
171 |
#endif // UAN_PROP_BH_INSTALLED
|
|
172 |
|
|
173 |
// No collision (Get 2 packets)
|
|
174 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (3.001), 50, 50, prop),
|
|
175 |
34, "Should have received 34 bytes from 2 disjoint packets");
|
|
176 |
|
|
177 |
// Should correctly receive first arriving packet
|
|
178 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (1.0126), 50, 50, prop),
|
|
179 |
17, "Should have recieved 17 bytes from first arriving packet");
|
|
180 |
|
|
181 |
// Packets should collide and both be lost
|
|
182 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (1.0 + 7.01 * (13.0 / 80.0)), 50, 50, prop),
|
|
183 |
0, "Packets should collide, but received data");
|
|
184 |
|
|
185 |
// Phy Dual
|
|
186 |
UanTxMode mode00 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode00");
|
|
187 |
UanTxMode mode10 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 11000, 4000, 2, "TestMode10");
|
|
188 |
UanTxMode mode20 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 15000, 4000, 2, "TestMode20");
|
|
189 |
UanTxMode mode01 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 10000, 4000, 2, "TestMode01");
|
|
190 |
UanTxMode mode11 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 11000, 4000, 2, "TestMode11");
|
|
191 |
UanTxMode mode21 = UanTxModeFactory::CreateMode (UanTxMode::FSK, 80, 80, 15000, 4000, 2, "TestMode21");
|
|
192 |
|
|
193 |
UanModesList m0;
|
|
194 |
m0.AppendMode (mode00);
|
|
195 |
m0.AppendMode (mode10);
|
|
196 |
m0.AppendMode (mode20);
|
|
197 |
UanModesList m1;
|
|
198 |
m1.AppendMode (mode01);
|
|
199 |
m1.AppendMode (mode11);
|
|
200 |
m1.AppendMode (mode21);
|
|
201 |
|
|
202 |
phyId = TypeId::LookupByName ("ns3::UanPhyDual");
|
|
203 |
m_phyFac.SetTypeId (phyId);
|
|
204 |
phyList.Reset ();
|
|
205 |
phyList.SetWithTid (phyId, "SupportedModesPhy1", UanModesListValue (m0));
|
|
206 |
phyList.SetWithTid (phyId, "SupportedModesPhy2", UanModesListValue (m1));
|
|
207 |
m_phyFac.Set (phyList);
|
|
208 |
|
|
209 |
// No collision (Get 2 packets)
|
|
210 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (3.01), 50, 50, prop),
|
|
211 |
34, "Expected no collision");
|
|
212 |
|
|
213 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop, 0, 0),
|
|
214 |
0, "Expected collision with both packets lost");
|
|
215 |
|
|
216 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop, 0, 2),
|
|
217 |
17, "Expected collision with only one packets lost");
|
|
218 |
|
|
219 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop, 0, 5),
|
|
220 |
34, "Expected no collision");
|
|
221 |
|
|
222 |
NS_TEST_ASSERT_MSG_EQ (DoOnePhyTest (Seconds (1.0), Seconds (2.99), 50, 50, prop, 2, 3),
|
|
223 |
34, "Expected no collision");
|
|
224 |
|
|
225 |
return false;
|
|
226 |
}
|
|
227 |
|
|
228 |
bool
|
|
229 |
UanTest::DoRun (void)
|
|
230 |
{
|
|
231 |
|
|
232 |
Ptr<UanPhyPerUmodem> per = CreateObject<UanPhyPerUmodem> ();
|
|
233 |
Ptr<Packet> pkt = Create<Packet> (1000);
|
|
234 |
double error = per->CalcPer (pkt, 9, UanPhyGen::GetDefaultModes ()[0]);
|
|
235 |
NS_TEST_ASSERT_MSG_EQ_TOL (error, 0.539, 0.001, "Got PER outside of tolerance");
|
|
236 |
|
|
237 |
#ifdef UAN_PROP_BH_INSTALLED
|
|
238 |
// Correct DB lookup for BH prop.
|
|
239 |
Ptr<UanPropModelBh> propBh = CreateObject<UanPropModelBh> ();
|
|
240 |
BellhopResp resp = propBh->GetResp (10000, 50, 50, 1000);
|
|
241 |
|
|
242 |
NS_TEST_ASSERT_MSG_EQ_TOL (resp.GetPathLossDb (), -44.1753, 0.001, "Got BH Pathloss outside of tolerance");
|
|
243 |
|
|
244 |
NS_TEST_ASSERT_MSG_EQ_TOL (resp.GetPdp ().GetTap (4).GetAmp (), 0.14159, 0.001, "Got BH arrival outside of tolerance");
|
|
245 |
|
|
246 |
#endif // UAN_PROP_BH_INSTALLED
|
|
247 |
|
|
248 |
return DoPhyTests ();
|
|
249 |
|
|
250 |
}
|
|
251 |
|
|
252 |
|
|
253 |
class UanTestSuite : public TestSuite
|
|
254 |
{
|
|
255 |
public:
|
|
256 |
UanTestSuite ();
|
|
257 |
};
|
|
258 |
|
|
259 |
UanTestSuite::UanTestSuite ()
|
|
260 |
: TestSuite ("devices-uan", UNIT)
|
|
261 |
{
|
|
262 |
AddTestCase (new UanTest);
|
|
263 |
}
|
|
264 |
|
|
265 |
UanTestSuite g_uanTestSuite;
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|