author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 25 Feb 2010 14:17:21 +0100 | |
changeset 6068 | a2127017ecb4 |
parent 6065 | 0f012e7d9128 |
parent 6041 | b65c6d6794f8 |
child 6360 | d8975477ff6a |
permissions | -rw-r--r-- |
5271 | 1 |
/* |
2 |
* Copyright (c) 2009 University of Washington |
|
3 |
* |
|
4 |
* This program is free software; you can redistribute it and/or modify |
|
5 |
* it under the terms of the GNU General Public License version 2 as |
|
6 |
* published by the Free Software Foundation; |
|
7 |
* |
|
8 |
* This program is distributed in the hope that it will be useful, |
|
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 |
* GNU General Public License for more details. |
|
12 |
* |
|
13 |
* You should have received a copy of the GNU General Public License |
|
14 |
* along with this program; if not, write to the Free Software |
|
15 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
*/ |
|
17 |
||
18 |
#include <iostream> |
|
19 |
#include <fstream> |
|
20 |
#include <vector> |
|
21 |
#include <string> |
|
22 |
||
23 |
#include "ns3/log.h" |
|
24 |
#include "ns3/callback.h" |
|
25 |
#include "ns3/abort.h" |
|
26 |
#include "ns3/test.h" |
|
27 |
#include "ns3/pcap-file.h" |
|
28 |
#include "ns3/config.h" |
|
29 |
#include "ns3/string.h" |
|
30 |
#include "ns3/uinteger.h" |
|
6065 | 31 |
#include "ns3/double.h" |
5271 | 32 |
#include "ns3/data-rate.h" |
33 |
#include "ns3/inet-socket-address.h" |
|
34 |
#include "ns3/internet-stack-helper.h" |
|
35 |
#include "ns3/ipv4-address-helper.h" |
|
36 |
#include "ns3/tcp-socket-factory.h" |
|
37 |
#include "ns3/yans-wifi-helper.h" |
|
38 |
#include "ns3/propagation-loss-model.h" |
|
39 |
#include "ns3/propagation-delay-model.h" |
|
40 |
#include "ns3/yans-wifi-channel.h" |
|
41 |
#include "ns3/yans-wifi-phy.h" |
|
42 |
#include "ns3/wifi-net-device.h" |
|
43 |
#include "ns3/mobility-helper.h" |
|
44 |
#include "ns3/constant-position-mobility-model.h" |
|
45 |
#include "ns3/nqos-wifi-mac-helper.h" |
|
46 |
#include "ns3/simulator.h" |
|
47 |
||
48 |
NS_LOG_COMPONENT_DEFINE ("WifiInterferenceTestSuite"); |
|
49 |
||
50 |
using namespace ns3; |
|
51 |
||
52 |
class WifiInterferenceTestCase : public TestCase |
|
53 |
{ |
|
54 |
public: |
|
55 |
WifiInterferenceTestCase (); |
|
56 |
virtual ~WifiInterferenceTestCase (); |
|
57 |
||
58 |
private: |
|
59 |
virtual bool DoRun (void); |
|
60 |
void ReceivePacket (Ptr<Socket> socket); |
|
61 |
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval); |
|
62 |
void PrintEndSync (std::string context, uint32_t dataRate, double snr, double per); |
|
63 |
double WifiSimpleInterference (std::string phyMode, double Prss, double Irss, double delta, uint32_t PpacketSize, |
|
64 |
uint32_t IpacketSize, bool verbose, InternetStackHelper internet); |
|
65 |
double m_PER; |
|
66 |
double m_SNR; |
|
67 |
uint32_t m_DataRate; |
|
68 |
}; |
|
69 |
||
70 |
// Add some help text to this case to describe what it is intended to test |
|
71 |
WifiInterferenceTestCase::WifiInterferenceTestCase () |
|
72 |
: TestCase ("Test interference calculation when interfering frame exactly overlaps intended frame") |
|
73 |
{ |
|
74 |
} |
|
75 |
||
76 |
WifiInterferenceTestCase::~WifiInterferenceTestCase () |
|
77 |
{ |
|
78 |
} |
|
79 |
||
80 |
void |
|
81 |
WifiInterferenceTestCase::ReceivePacket (Ptr<Socket> socket) |
|
82 |
{ |
|
83 |
Address addr; |
|
84 |
socket->GetSockName (addr); |
|
85 |
InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr); |
|
86 |
NS_LOG_UNCOND ("Received one packet! Socket: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort ()); |
|
87 |
} |
|
88 |
||
89 |
void |
|
90 |
WifiInterferenceTestCase::GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval) |
|
91 |
{ |
|
92 |
if (pktCount > 0) |
|
93 |
{ |
|
94 |
socket->Send (Create<Packet> (pktSize)); |
|
95 |
Simulator::Schedule (pktInterval, &WifiInterferenceTestCase::GenerateTraffic, socket, pktSize, pktCount-1, pktInterval); |
|
96 |
} |
|
97 |
else |
|
98 |
{ |
|
99 |
socket->Close (); |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
void |
|
104 |
WifiInterferenceTestCase::PrintEndSync (std::string context, uint32_t dataRate, double snr, double per) |
|
105 |
{ |
|
106 |
NS_LOG_UNCOND ("EndSync: Received frame with dataRate=" << dataRate << ", SNR=" << snr << ", PER =" << per); |
|
107 |
m_PER = per; |
|
108 |
m_SNR = snr; |
|
109 |
m_DataRate = dataRate; |
|
110 |
} |
|
111 |
||
112 |
double |
|
113 |
WifiInterferenceTestCase::WifiSimpleInterference (std::string phyMode,double Prss, double Irss, double delta, uint32_t PpacketSize, uint32_t IpacketSize, bool verbose, InternetStackHelper internet) |
|
114 |
{ |
|
115 |
||
116 |
uint32_t numPackets = 1; |
|
117 |
double interval = 1.0; // seconds |
|
118 |
double startTime = 10.0; // seconds |
|
119 |
double distanceToRx = 100.0; // meters |
|
120 |
||
121 |
double offset = 91; // This is a magic number used to set the |
|
122 |
// transmit power, based on other configuration |
|
123 |
||
124 |
m_PER = 0; |
|
125 |
m_SNR = 0; |
|
126 |
m_DataRate = 0; |
|
127 |
||
128 |
// Convert to time object |
|
129 |
Time interPacketInterval = Seconds (interval); |
|
130 |
||
131 |
// disable fragmentation for frames below 2200 bytes |
|
132 |
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200")); |
|
133 |
// turn off RTS/CTS for frames below 2200 bytes |
|
134 |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200")); |
|
135 |
// Fix non-unicast data rate to be the same as that of unicast |
|
136 |
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", |
|
137 |
StringValue (phyMode)); |
|
138 |
||
139 |
NodeContainer c; |
|
140 |
c.Create (3); |
|
141 |
||
142 |
// The below set of helpers will help us to put together the wifi NICs we want |
|
143 |
WifiHelper wifi; |
|
144 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211b); |
|
145 |
||
146 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); |
|
147 |
// This is one parameter that matters when using FixedRssLossModel |
|
148 |
// set it to zero; otherwise, gain will be added |
|
149 |
wifiPhy.Set ("RxGain", DoubleValue (0) ); |
|
150 |
wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0) ); |
|
151 |
||
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5523
diff
changeset
|
152 |
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b |
6041 | 153 |
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); |
5271 | 154 |
|
155 |
YansWifiChannelHelper wifiChannel ; |
|
156 |
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); |
|
157 |
wifiChannel.AddPropagationLoss ("ns3::LogDistancePropagationLossModel"); |
|
158 |
wifiPhy.SetChannel (wifiChannel.Create ()); |
|
159 |
||
160 |
// Add a non-QoS upper mac, and disable rate control |
|
161 |
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default (); |
|
162 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", |
|
163 |
"DataMode",StringValue(phyMode), |
|
164 |
"ControlMode",StringValue(phyMode)); |
|
165 |
// Set it to adhoc mode |
|
166 |
wifiMac.SetType ("ns3::AdhocWifiMac"); |
|
167 |
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c.Get (0)); |
|
168 |
// This will disable these sending devices from detecting a signal |
|
169 |
// so that they do not backoff |
|
170 |
wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (0.0) ); |
|
171 |
wifiPhy.Set ("TxGain", DoubleValue (offset + Prss) ); |
|
172 |
devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (1))); |
|
173 |
wifiPhy.Set ("TxGain", DoubleValue (offset + Irss) ); |
|
174 |
devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (2))); |
|
175 |
||
176 |
// Note that with FixedRssLossModel, the positions below are not |
|
177 |
// used for received signal strength. |
|
178 |
MobilityHelper mobility; |
|
179 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); |
|
180 |
positionAlloc->Add (Vector (0.0, 0.0, 0.0)); |
|
181 |
positionAlloc->Add (Vector (distanceToRx, 0.0, 0.0)); |
|
182 |
positionAlloc->Add (Vector (-1*distanceToRx, 0.0, 0.0)); |
|
183 |
mobility.SetPositionAllocator (positionAlloc); |
|
184 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
|
185 |
mobility.Install (c); |
|
186 |
||
187 |
// InternetStackHelper internet; |
|
188 |
internet.Install (c); |
|
189 |
||
190 |
Ipv4AddressHelper ipv4; |
|
191 |
NS_LOG_INFO ("Assign IP Addresses."); |
|
192 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
|
193 |
Ipv4InterfaceContainer i = ipv4.Assign (devices); |
|
194 |
||
195 |
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); |
|
196 |
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid); |
|
197 |
InetSocketAddress local = InetSocketAddress (Ipv4Address("10.1.1.1"), 80); |
|
198 |
recvSink->Bind (local); |
|
199 |
recvSink->SetRecvCallback (MakeCallback (&WifiInterferenceTestCase::ReceivePacket, this)); |
|
200 |
||
201 |
Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid); |
|
202 |
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80); |
|
203 |
source->Connect (remote); |
|
204 |
||
205 |
// Interferer will send to a different port; we will not see a |
|
206 |
// "Received packet" message |
|
207 |
Ptr<Socket> interferer = Socket::CreateSocket (c.Get (2), tid); |
|
208 |
InetSocketAddress interferingAddr = InetSocketAddress (Ipv4Address ("255.255.255.255"), 49000); |
|
209 |
interferer->Connect (interferingAddr); |
|
210 |
||
211 |
Config::Connect ("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/EndSync", MakeCallback (&WifiInterferenceTestCase::PrintEndSync, this)); |
|
212 |
// Tracing |
|
5369
86beb5869f67
split examples, add examples, tweak test.py to minimize builds
Craig Dowell <craigdo@ee.washington.edu>
parents:
5271
diff
changeset
|
213 |
// wifiPhy.EnablePcap ("wifi-simple-interference", devices.Get (0)); |
5271 | 214 |
|
5523
86e84169c725
Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents:
5369
diff
changeset
|
215 |
Simulator::ScheduleWithContext (source->GetNode ()->GetId (), |
86e84169c725
Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents:
5369
diff
changeset
|
216 |
Seconds (startTime), &GenerateTraffic, |
86e84169c725
Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents:
5369
diff
changeset
|
217 |
source, PpacketSize, numPackets, interPacketInterval); |
5271 | 218 |
|
5523
86e84169c725
Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents:
5369
diff
changeset
|
219 |
Simulator::ScheduleWithContext (interferer->GetNode ()->GetId (), |
86e84169c725
Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents:
5369
diff
changeset
|
220 |
Seconds (startTime + delta/1000000.0), &GenerateTraffic, |
86e84169c725
Call Simulator::ScheduleWithContext from ns3::Channel subclasses when sending packets to other nodes
Guillaume Seguin <guillaume@segu.in>
parents:
5369
diff
changeset
|
221 |
interferer, IpacketSize, numPackets, interPacketInterval); |
5271 | 222 |
|
223 |
Simulator::Run (); |
|
224 |
Simulator::Destroy (); |
|
225 |
||
226 |
return m_PER; |
|
227 |
} |
|
228 |
||
229 |
bool |
|
230 |
WifiInterferenceTestCase::DoRun (void) |
|
231 |
{ |
|
232 |
||
233 |
std::string phyMode ("wifib-1mbs"); |
|
234 |
double Prss = -90; // -dBm |
|
235 |
double Irss = -90; // -dBm |
|
236 |
double delta = 0; // microseconds |
|
237 |
uint32_t PpacketSize = 1000; // bytes |
|
238 |
uint32_t IpacketSize = 1000; // bytes |
|
239 |
bool verbose = false; |
|
240 |
double PER, PER1, PER2; |
|
241 |
InternetStackHelper internet; |
|
242 |
||
243 |
// Compute the packet error rate (PER) when delta=0 microseconds. This |
|
244 |
// means that the interferer arrives at exactly the same time as the |
|
245 |
// intended packet |
|
246 |
PER = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); |
|
247 |
||
248 |
// Now rerun this test case and compute the PER when the delta time between |
|
249 |
// arrival of the intended frame and interferer is 1 microsecond. |
|
250 |
delta = 1; |
|
251 |
PER1 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); |
|
252 |
||
253 |
// Now rerun this test case and compute the PER when the delta time between |
|
254 |
// arrival of the intended frame and interferer is 2 microseconds. |
|
255 |
delta = 2; |
|
256 |
PER2 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet); |
|
257 |
||
258 |
double PERDiff1 = PER - PER1; |
|
259 |
||
260 |
double PERDiff2 = PER1 - PER2; |
|
261 |
||
262 |
NS_TEST_ASSERT_MSG_EQ (PERDiff1, PERDiff2, |
|
263 |
"The PER difference due to 1 microsecond difference in arrival shouldn't depend on absolute arrival"); |
|
264 |
||
265 |
return false; |
|
266 |
} |
|
267 |
||
268 |
class WifiInterferenceTestSuite : public TestSuite |
|
269 |
{ |
|
270 |
public: |
|
271 |
WifiInterferenceTestSuite (); |
|
272 |
}; |
|
273 |
||
274 |
WifiInterferenceTestSuite::WifiInterferenceTestSuite () |
|
275 |
: TestSuite ("ns3-wifi-interference", UNIT) |
|
276 |
{ |
|
277 |
AddTestCase (new WifiInterferenceTestCase); |
|
278 |
} |
|
279 |
||
280 |
WifiInterferenceTestSuite wifiInterferenceTestSuite; |
|
281 |