Left: | ||
Right: |
LEFT | RIGHT |
---|---|
(no file at all) | |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | |
2 /* | |
3 * Copyright (c) 2017 | |
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: Sebastien Deronne <sebastien.deronne@gmail.com> | |
19 */ | |
20 | |
21 #include "ns3/core-module.h" | |
22 #include "ns3/applications-module.h" | |
23 #include "ns3/wifi-module.h" | |
24 #include "ns3/mobility-module.h" | |
25 #include "ns3/internet-module.h" | |
Tom Henderson
2018/03/31 23:27:02
based on 'include less' principle of the other rec
S. Deronne
2018/04/01 15:03:51
Right remark Tom, but I have not refactored exampl
| |
26 | |
27 // This is a simple example in order to show the frames exchanged in 802.11 PCF. | |
28 // It is possible to enable/disable PCF capabilities and to change the cfpMaxDur ation parameter. | |
29 | |
Tom Henderson
2018/03/31 23:27:02
Can you say more about the interesting combination
S. Deronne
2018/04/01 15:03:51
I will provide more information.
| |
30 using namespace ns3; | |
31 | |
32 NS_LOG_COMPONENT_DEFINE ("WifiPcf"); | |
33 | |
34 uint64_t m_countBeacon; | |
35 uint64_t m_countCfPoll; | |
36 uint64_t m_countCfPollAck; | |
37 uint64_t m_countCfPollData; | |
38 uint64_t m_countCfPollDataAck; | |
39 uint64_t m_countCfEnd; | |
40 uint64_t m_countCfEndAck; | |
41 uint64_t m_countDataNull; | |
42 uint64_t m_countData; | |
43 | |
44 void TxCallback (std::string context, Ptr<const Packet> p) | |
45 { | |
46 WifiMacHeader hdr; | |
47 p->PeekHeader(hdr); | |
48 if (hdr.IsBeacon ()) | |
49 { | |
50 m_countBeacon++; | |
51 } | |
52 else if (hdr.IsCfPoll ()) | |
53 { | |
54 if (hdr.IsCfAck () && hdr.HasData ()) | |
55 { | |
56 m_countCfPollDataAck++; | |
57 } | |
58 else if (!hdr.IsCfAck () && hdr.HasData ()) | |
59 { | |
60 m_countCfPollData++; | |
61 } | |
62 else if (hdr.IsCfAck () && !hdr.HasData ()) | |
63 { | |
64 m_countCfPollAck++; | |
65 } | |
66 else | |
67 { | |
68 m_countCfPoll++; | |
69 } | |
70 } | |
71 else if (hdr.IsCfEnd ()) | |
72 { | |
73 if (hdr.IsCfAck ()) | |
74 { | |
75 m_countCfEndAck++; | |
76 } | |
77 else | |
78 { | |
79 m_countCfEnd++; | |
80 } | |
81 } | |
82 else if (hdr.IsData ()) | |
83 { | |
84 if (!hdr.HasData ()) | |
85 { | |
86 m_countDataNull++; | |
87 } | |
88 else | |
89 { | |
90 m_countData++; | |
91 } | |
92 } | |
93 } | |
94 | |
95 int main (int argc, char *argv[]) | |
96 { | |
97 uint32_t nWifi = 1; | |
98 bool enablePcap = false; | |
99 bool enablePcf = true; | |
100 bool withData = true; | |
101 bool enableRts = 0; | |
102 uint64_t cfpMaxDurationUs = 65536; //microseconds | |
103 double simulationTime = 10; //seconds | |
104 | |
105 CommandLine cmd; | |
106 cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi); | |
107 cmd.AddValue ("enablePcf", "Enable/disable PCF mode", enablePcf); | |
108 cmd.AddValue ("withData", "Enable/disable UDP data packets generation", withDa ta); | |
109 cmd.AddValue ("enableRts", "Enable RTS/CTS for DCF", enableRts); | |
110 cmd.AddValue ("cfpMaxDuration", "CFP max duration in microseconds", cfpMaxDura tionUs); | |
111 cmd.AddValue ("simulationTime", "Simulation time in seconds", simulationTime); | |
112 cmd.AddValue ("enablePcap", "Enable/disable PCAP output", enablePcap); | |
113 cmd.Parse (argc, argv); | |
114 | |
115 m_countBeacon = 0; | |
116 m_countCfEnd = 0; | |
117 m_countCfEndAck = 0; | |
118 m_countCfPoll = 0; | |
119 m_countCfPollAck = 0; | |
120 m_countCfPollData = 0; | |
121 m_countCfPollDataAck = 0; | |
122 m_countDataNull = 0; | |
123 m_countData = 0; | |
124 m_countDataNull = 0; | |
125 m_countData = 0; | |
126 | |
127 if(enableRts == false) | |
128 { | |
129 Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", Stri ngValue ("999999")); | |
130 } | |
131 else | |
132 { | |
133 Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", Stri ngValue ("0")); | |
134 } | |
135 | |
136 NodeContainer wifiStaNodes; | |
137 wifiStaNodes.Create (nWifi); | |
138 | |
139 NodeContainer wifiApNode; | |
140 wifiApNode.Create(1); | |
141 | |
142 YansWifiChannelHelper channel = YansWifiChannelHelper::Default (); | |
143 YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); | |
144 phy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO); | |
145 phy.SetChannel (channel.Create()); | |
146 ·· | |
147 WifiHelper wifi; | |
148 WifiMacHelper mac; | |
149 | |
150 Ssid ssid = Ssid ("wifi-pcf"); | |
151 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", Stri ngValue("OfdmRate54Mbps"), "ControlMode", StringValue("OfdmRate24Mbps")); | |
152 ···· | |
153 NetDeviceContainer staDevices; | |
154 mac.SetType ("ns3::StaWifiMac", | |
155 "Ssid", SsidValue (ssid), | |
156 "ActiveProbing", BooleanValue (false), | |
157 "PcfSupported", BooleanValue (enablePcf)); | |
Tom Henderson
2018/03/31 23:27:02
what about 'PcfMode' or 'PcfEnabled' (boolean valu
S. Deronne
2018/04/01 15:03:51
I used the same principale as for Qos, Ht, Vht, ..
| |
158 staDevices = wifi.Install (phy, mac, wifiStaNodes); | |
159 ·· | |
160 mac.SetType ("ns3::ApWifiMac", | |
161 "Ssid", SsidValue (ssid), | |
162 "BeaconGeneration", BooleanValue (true), | |
163 "PcfSupported", BooleanValue (enablePcf), | |
164 "CfpMaxDuration", TimeValue (MicroSeconds (cfpMaxDurationUs))); | |
165 | |
166 NetDeviceContainer apDevice; | |
167 apDevice = wifi.Install (phy, mac, wifiApNode); | |
168 | |
169 MobilityHelper mobility; | |
170 | |
171 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); | |
172 | |
173 for (uint32_t i = 0; i < nWifi; i++) | |
174 { | |
175 positionAlloc->Add (Vector (1.0, 0.0, 0.0)); | |
176 } | |
177 positionAlloc->Add (Vector (0.0, 0.0, 0.0)); | |
178 mobility.SetPositionAllocator (positionAlloc); | |
179 | |
180 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); | |
181 | |
182 mobility.Install (wifiApNode); | |
183 mobility.Install (wifiStaNodes); | |
184 | |
185 InternetStackHelper stack; | |
186 stack.Install (wifiApNode); | |
187 stack.Install (wifiStaNodes); | |
188 | |
189 Ipv4AddressHelper address; | |
190 | |
191 address.SetBase ("10.1.1.0", "255.255.255.0"); | |
192 Ipv4InterfaceContainer StaInterface; | |
193 StaInterface = address.Assign (staDevices); | |
194 Ipv4InterfaceContainer ApInterface; | |
195 ApInterface = address.Assign (apDevice); | |
196 | |
197 ApplicationContainer sourceApplications, sinkApplications; | |
198 if (withData) | |
199 { | |
200 uint32_t portNumber = 9; | |
201 for (uint8_t index = 0; index < nWifi; ++index) | |
202 { | |
203 auto ipv4 = wifiApNode.Get (0)->GetObject<Ipv4> (); | |
204 const auto address = ipv4->GetAddress (1, 0).GetLocal (); | |
205 InetSocketAddress sinkSocket (address, portNumber++); | |
206 OnOffHelper onOffHelper ("ns3::UdpSocketFactory", sinkSocket); | |
207 onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomV ariable[Constant=1]")); | |
208 onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandom Variable[Constant=0]")); | |
209 onOffHelper.SetAttribute ("DataRate", DataRateValue (50000000 / nWifi) ); | |
210 onOffHelper.SetAttribute ("PacketSize", UintegerValue (1472)); //bytes | |
211 sourceApplications.Add (onOffHelper.Install (wifiStaNodes.Get (index)) ); | |
212 PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", sinkSocket ); | |
213 sinkApplications.Add (packetSinkHelper.Install (wifiApNode.Get (0))); | |
214 } | |
215 sinkApplications.Start (Seconds (0.0)); | |
216 sinkApplications.Stop (Seconds (simulationTime + 1)); | |
217 sourceApplications.Start (Seconds (1.0)); | |
218 sourceApplications.Stop (Seconds (simulationTime + 1)); | |
219 } | |
220 | |
221 Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiP hy/PhyTxBegin", MakeCallback (&TxCallback)); | |
222 | |
223 if (enablePcap) | |
224 { | |
225 phy.EnablePcap ("wifi_pcf", apDevice.Get (0)); | |
226 } | |
227 | |
228 Simulator::Stop (Seconds (simulationTime + 1)); | |
229 | |
230 Simulator::Run (); | |
231 Simulator::Destroy (); | |
232 | |
233 double throughput = 0; | |
234 for (unsigned index = 0; index < sinkApplications.GetN (); ++index) | |
235 { | |
236 uint64_t totalPacketsThrough = DynamicCast<PacketSink> (sinkApplications.G et (index))->GetTotalRx (); | |
237 throughput += ((totalPacketsThrough * 8) / (simulationTime * 1000000.0)); //Mbit/s | |
238 } | |
239 std::cout << "Throughput: " << throughput << " Mbit/s" << std::endl; | |
240 | |
241 std::cout<<"# tx beacons: "<<m_countBeacon<<std::endl; | |
242 std::cout<<"# tx CF-END: "<<m_countCfEnd<<std::endl; | |
243 std::cout<<"# tx CF-END-ACK: "<<m_countCfEndAck<<std::endl; | |
244 std::cout<<"# tx CF-POLL: "<<m_countCfPoll<<std::endl; | |
245 std::cout<<"# tx CF-POLL-ACK: "<<m_countCfPollAck<<std::endl; | |
246 std::cout<<"# tx CF-POLL-DATA: "<<m_countCfPollData<<std::endl; | |
247 std::cout<<"# tx CF-POLL-DATA-ACK: "<<m_countCfPollDataAck<<std::endl; | |
248 std::cout<<"# tx DATA-NULL: "<<m_countDataNull<<std::endl; | |
249 std::cout<<"# tx DATA: "<<m_countData<<std::endl; | |
250 | |
251 return 0; | |
252 } | |
LEFT | RIGHT |