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"
|
|
31 |
#include "ns3/data-rate.h"
|
|
32 |
#include "ns3/inet-socket-address.h"
|
|
33 |
#include "ns3/internet-stack-helper.h"
|
|
34 |
#include "ns3/ipv4-address-helper.h"
|
|
35 |
#include "ns3/tcp-socket-factory.h"
|
|
36 |
#include "ns3/yans-wifi-helper.h"
|
|
37 |
#include "ns3/propagation-loss-model.h"
|
|
38 |
#include "ns3/propagation-delay-model.h"
|
|
39 |
#include "ns3/yans-wifi-channel.h"
|
|
40 |
#include "ns3/yans-wifi-phy.h"
|
|
41 |
#include "ns3/wifi-net-device.h"
|
|
42 |
#include "ns3/mobility-helper.h"
|
|
43 |
#include "ns3/constant-position-mobility-model.h"
|
|
44 |
#include "ns3/nqos-wifi-mac-helper.h"
|
|
45 |
#include "ns3/simulator.h"
|
|
46 |
|
|
47 |
NS_LOG_COMPONENT_DEFINE ("WifiInterferenceTestSuite");
|
|
48 |
|
|
49 |
using namespace ns3;
|
|
50 |
|
|
51 |
class WifiInterferenceTestCase : public TestCase
|
|
52 |
{
|
|
53 |
public:
|
|
54 |
WifiInterferenceTestCase ();
|
|
55 |
virtual ~WifiInterferenceTestCase ();
|
|
56 |
|
|
57 |
private:
|
|
58 |
virtual bool DoRun (void);
|
|
59 |
void ReceivePacket (Ptr<Socket> socket);
|
|
60 |
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval);
|
|
61 |
void PrintEndSync (std::string context, uint32_t dataRate, double snr, double per);
|
|
62 |
double WifiSimpleInterference (std::string phyMode, double Prss, double Irss, double delta, uint32_t PpacketSize,
|
|
63 |
uint32_t IpacketSize, bool verbose, InternetStackHelper internet);
|
|
64 |
double m_PER;
|
|
65 |
double m_SNR;
|
|
66 |
uint32_t m_DataRate;
|
|
67 |
};
|
|
68 |
|
|
69 |
// Add some help text to this case to describe what it is intended to test
|
|
70 |
WifiInterferenceTestCase::WifiInterferenceTestCase ()
|
|
71 |
: TestCase ("Test interference calculation when interfering frame exactly overlaps intended frame")
|
|
72 |
{
|
|
73 |
}
|
|
74 |
|
|
75 |
WifiInterferenceTestCase::~WifiInterferenceTestCase ()
|
|
76 |
{
|
|
77 |
}
|
|
78 |
|
|
79 |
void
|
|
80 |
WifiInterferenceTestCase::ReceivePacket (Ptr<Socket> socket)
|
|
81 |
{
|
|
82 |
Address addr;
|
|
83 |
socket->GetSockName (addr);
|
|
84 |
InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (addr);
|
|
85 |
NS_LOG_UNCOND ("Received one packet! Socket: " << iaddr.GetIpv4 () << " port: " << iaddr.GetPort ());
|
|
86 |
}
|
|
87 |
|
|
88 |
void
|
|
89 |
WifiInterferenceTestCase::GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, uint32_t pktCount, Time pktInterval)
|
|
90 |
{
|
|
91 |
if (pktCount > 0)
|
|
92 |
{
|
|
93 |
socket->Send (Create<Packet> (pktSize));
|
|
94 |
Simulator::Schedule (pktInterval, &WifiInterferenceTestCase::GenerateTraffic, socket, pktSize, pktCount-1, pktInterval);
|
|
95 |
}
|
|
96 |
else
|
|
97 |
{
|
|
98 |
socket->Close ();
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
void
|
|
103 |
WifiInterferenceTestCase::PrintEndSync (std::string context, uint32_t dataRate, double snr, double per)
|
|
104 |
{
|
|
105 |
NS_LOG_UNCOND ("EndSync: Received frame with dataRate=" << dataRate << ", SNR=" << snr << ", PER =" << per);
|
|
106 |
m_PER = per;
|
|
107 |
m_SNR = snr;
|
|
108 |
m_DataRate = dataRate;
|
|
109 |
}
|
|
110 |
|
|
111 |
double
|
|
112 |
WifiInterferenceTestCase::WifiSimpleInterference (std::string phyMode,double Prss, double Irss, double delta, uint32_t PpacketSize, uint32_t IpacketSize, bool verbose, InternetStackHelper internet)
|
|
113 |
{
|
|
114 |
|
|
115 |
uint32_t numPackets = 1;
|
|
116 |
double interval = 1.0; // seconds
|
|
117 |
double startTime = 10.0; // seconds
|
|
118 |
double distanceToRx = 100.0; // meters
|
|
119 |
|
|
120 |
double offset = 91; // This is a magic number used to set the
|
|
121 |
// transmit power, based on other configuration
|
|
122 |
|
|
123 |
m_PER = 0;
|
|
124 |
m_SNR = 0;
|
|
125 |
m_DataRate = 0;
|
|
126 |
|
|
127 |
// Convert to time object
|
|
128 |
Time interPacketInterval = Seconds (interval);
|
|
129 |
|
|
130 |
// disable fragmentation for frames below 2200 bytes
|
|
131 |
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
|
|
132 |
// turn off RTS/CTS for frames below 2200 bytes
|
|
133 |
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
|
|
134 |
// Fix non-unicast data rate to be the same as that of unicast
|
|
135 |
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
|
|
136 |
StringValue (phyMode));
|
|
137 |
|
|
138 |
NodeContainer c;
|
|
139 |
c.Create (3);
|
|
140 |
|
|
141 |
// The below set of helpers will help us to put together the wifi NICs we want
|
|
142 |
WifiHelper wifi;
|
|
143 |
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
|
|
144 |
|
|
145 |
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
|
|
146 |
// This is one parameter that matters when using FixedRssLossModel
|
|
147 |
// set it to zero; otherwise, gain will be added
|
|
148 |
wifiPhy.Set ("RxGain", DoubleValue (0) );
|
|
149 |
wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0) );
|
|
150 |
|
|
151 |
// ns-3 support RadioTap and Prism tracing extensions for 802.11b
|
|
152 |
wifiPhy.SetPcapFormat (YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
|
|
153 |
|
|
154 |
YansWifiChannelHelper wifiChannel ;
|
|
155 |
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
|
|
156 |
wifiChannel.AddPropagationLoss ("ns3::LogDistancePropagationLossModel");
|
|
157 |
wifiPhy.SetChannel (wifiChannel.Create ());
|
|
158 |
|
|
159 |
// Add a non-QoS upper mac, and disable rate control
|
|
160 |
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
|
|
161 |
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
|
|
162 |
"DataMode",StringValue(phyMode),
|
|
163 |
"ControlMode",StringValue(phyMode));
|
|
164 |
// Set it to adhoc mode
|
|
165 |
wifiMac.SetType ("ns3::AdhocWifiMac");
|
|
166 |
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c.Get (0));
|
|
167 |
// This will disable these sending devices from detecting a signal
|
|
168 |
// so that they do not backoff
|
|
169 |
wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (0.0) );
|
|
170 |
wifiPhy.Set ("TxGain", DoubleValue (offset + Prss) );
|
|
171 |
devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (1)));
|
|
172 |
wifiPhy.Set ("TxGain", DoubleValue (offset + Irss) );
|
|
173 |
devices.Add (wifi.Install (wifiPhy, wifiMac, c.Get (2)));
|
|
174 |
|
|
175 |
// Note that with FixedRssLossModel, the positions below are not
|
|
176 |
// used for received signal strength.
|
|
177 |
MobilityHelper mobility;
|
|
178 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
|
|
179 |
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
|
|
180 |
positionAlloc->Add (Vector (distanceToRx, 0.0, 0.0));
|
|
181 |
positionAlloc->Add (Vector (-1*distanceToRx, 0.0, 0.0));
|
|
182 |
mobility.SetPositionAllocator (positionAlloc);
|
|
183 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
|
|
184 |
mobility.Install (c);
|
|
185 |
|
|
186 |
// InternetStackHelper internet;
|
|
187 |
internet.Install (c);
|
|
188 |
|
|
189 |
Ipv4AddressHelper ipv4;
|
|
190 |
NS_LOG_INFO ("Assign IP Addresses.");
|
|
191 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
|
192 |
Ipv4InterfaceContainer i = ipv4.Assign (devices);
|
|
193 |
|
|
194 |
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
|
|
195 |
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
|
|
196 |
InetSocketAddress local = InetSocketAddress (Ipv4Address("10.1.1.1"), 80);
|
|
197 |
recvSink->Bind (local);
|
|
198 |
recvSink->SetRecvCallback (MakeCallback (&WifiInterferenceTestCase::ReceivePacket, this));
|
|
199 |
|
|
200 |
Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
|
|
201 |
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
|
|
202 |
source->Connect (remote);
|
|
203 |
|
|
204 |
// Interferer will send to a different port; we will not see a
|
|
205 |
// "Received packet" message
|
|
206 |
Ptr<Socket> interferer = Socket::CreateSocket (c.Get (2), tid);
|
|
207 |
InetSocketAddress interferingAddr = InetSocketAddress (Ipv4Address ("255.255.255.255"), 49000);
|
|
208 |
interferer->Connect (interferingAddr);
|
|
209 |
|
|
210 |
Config::Connect ("/NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/EndSync", MakeCallback (&WifiInterferenceTestCase::PrintEndSync, this));
|
|
211 |
// Tracing
|
|
212 |
wifiPhy.EnablePcap ("wifi-simple-interference", devices.Get (0));
|
|
213 |
|
|
214 |
Simulator::Schedule (Seconds (startTime), &GenerateTraffic,
|
|
215 |
source, PpacketSize, numPackets, interPacketInterval);
|
|
216 |
|
|
217 |
Simulator::Schedule (Seconds (startTime + delta/1000000.0), &GenerateTraffic,
|
|
218 |
interferer, IpacketSize, numPackets, interPacketInterval);
|
|
219 |
|
|
220 |
Simulator::Run ();
|
|
221 |
Simulator::Destroy ();
|
|
222 |
|
|
223 |
return m_PER;
|
|
224 |
}
|
|
225 |
|
|
226 |
bool
|
|
227 |
WifiInterferenceTestCase::DoRun (void)
|
|
228 |
{
|
|
229 |
|
|
230 |
std::string phyMode ("wifib-1mbs");
|
|
231 |
double Prss = -90; // -dBm
|
|
232 |
double Irss = -90; // -dBm
|
|
233 |
double delta = 0; // microseconds
|
|
234 |
uint32_t PpacketSize = 1000; // bytes
|
|
235 |
uint32_t IpacketSize = 1000; // bytes
|
|
236 |
bool verbose = false;
|
|
237 |
double PER, PER1, PER2;
|
|
238 |
InternetStackHelper internet;
|
|
239 |
|
|
240 |
// Compute the packet error rate (PER) when delta=0 microseconds. This
|
|
241 |
// means that the interferer arrives at exactly the same time as the
|
|
242 |
// intended packet
|
|
243 |
PER = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet);
|
|
244 |
|
|
245 |
// Now rerun this test case and compute the PER when the delta time between
|
|
246 |
// arrival of the intended frame and interferer is 1 microsecond.
|
|
247 |
delta = 1;
|
|
248 |
PER1 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet);
|
|
249 |
|
|
250 |
// Now rerun this test case and compute the PER when the delta time between
|
|
251 |
// arrival of the intended frame and interferer is 2 microseconds.
|
|
252 |
delta = 2;
|
|
253 |
PER2 = WifiSimpleInterference (phyMode,Prss,Irss,delta,PpacketSize,IpacketSize,verbose,internet);
|
|
254 |
|
|
255 |
double PERDiff1 = PER - PER1;
|
|
256 |
|
|
257 |
double PERDiff2 = PER1 - PER2;
|
|
258 |
|
|
259 |
NS_TEST_ASSERT_MSG_EQ (PERDiff1, PERDiff2,
|
|
260 |
"The PER difference due to 1 microsecond difference in arrival shouldn't depend on absolute arrival");
|
|
261 |
|
|
262 |
return false;
|
|
263 |
}
|
|
264 |
|
|
265 |
class WifiInterferenceTestSuite : public TestSuite
|
|
266 |
{
|
|
267 |
public:
|
|
268 |
WifiInterferenceTestSuite ();
|
|
269 |
};
|
|
270 |
|
|
271 |
WifiInterferenceTestSuite::WifiInterferenceTestSuite ()
|
|
272 |
: TestSuite ("ns3-wifi-interference", UNIT)
|
|
273 |
{
|
|
274 |
AddTestCase (new WifiInterferenceTestCase);
|
|
275 |
}
|
|
276 |
|
|
277 |
WifiInterferenceTestSuite wifiInterferenceTestSuite;
|
|
278 |
|