4408
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
|
2 |
/*
|
|
3 |
* Copyright (c) 2009 MIRKO BANCHI
|
|
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: Mirko Banchi <mk.banchi@gmail.com>
|
|
19 |
*/
|
|
20 |
#include "ns3/core-module.h"
|
|
21 |
#include "ns3/simulator-module.h"
|
|
22 |
#include "ns3/node-module.h"
|
|
23 |
#include "ns3/helper-module.h"
|
|
24 |
#include "ns3/global-routing-module.h"
|
|
25 |
#include "ns3/wifi-module.h"
|
|
26 |
#include "ns3/mobility-module.h"
|
|
27 |
|
|
28 |
//This is a simple example in order to show how 802.11n frame aggregation feature (A-MSDU) works.
|
|
29 |
//
|
|
30 |
//Network topology:
|
|
31 |
//
|
|
32 |
// Wifi 192.168.1.0
|
|
33 |
//
|
|
34 |
// AP
|
|
35 |
// * * *
|
|
36 |
// | | |
|
|
37 |
// n1 n2 n3
|
|
38 |
//
|
|
39 |
//Packets in this simulation aren't marked with a QosTag so they are considered
|
|
40 |
//belonging to BestEffort Access Class (AC_BE).
|
|
41 |
|
|
42 |
using namespace ns3;
|
|
43 |
|
|
44 |
NS_LOG_COMPONENT_DEFINE ("SimpleWifiFrameAggregation");
|
|
45 |
|
|
46 |
int main (int argc, char *argv[])
|
|
47 |
{
|
|
48 |
//LogComponentEnable ("EdcaTxopN", LOG_LEVEL_DEBUG);
|
|
49 |
LogComponentEnable ("MsduAggregator", LOG_LEVEL_INFO);
|
|
50 |
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
|
51 |
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
|
|
52 |
|
|
53 |
uint32_t nWifi = 1;
|
|
54 |
CommandLine cmd;
|
|
55 |
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
|
|
56 |
cmd.Parse (argc,argv);
|
|
57 |
|
|
58 |
NodeContainer wifiNodes;
|
|
59 |
wifiNodes.Create (2);
|
|
60 |
NodeContainer wifiApNode;
|
|
61 |
wifiApNode.Create (1);
|
|
62 |
|
|
63 |
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
|
|
64 |
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
|
|
65 |
phy.SetChannel (channel.Create ());
|
|
66 |
|
|
67 |
WifiHelper wifi = WifiHelper::Default ();
|
|
68 |
QosWifiMacHelper mac = QosWifiMacHelper::Default ();
|
|
69 |
wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
|
|
70 |
|
|
71 |
Ssid ssid = Ssid ("ns-3-802.11n");
|
|
72 |
mac.SetType ("ns3::QstaWifiMac",
|
|
73 |
"Ssid", SsidValue (ssid),
|
|
74 |
"ActiveProbing", BooleanValue (false));
|
|
75 |
mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator",
|
|
76 |
"MaxAmsduSize", UintegerValue (3839));
|
|
77 |
|
|
78 |
NetDeviceContainer staDevices;
|
|
79 |
staDevices = wifi.Install (phy, mac, wifiNodes);
|
|
80 |
|
|
81 |
mac.SetType ("ns3::QapWifiMac",
|
|
82 |
"Ssid", SsidValue (ssid),
|
|
83 |
"BeaconGeneration", BooleanValue (true),
|
|
84 |
"BeaconInterval", TimeValue (Seconds (2.5)));
|
|
85 |
mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator",
|
|
86 |
"MaxAmsduSize", UintegerValue (7935));
|
|
87 |
|
|
88 |
NetDeviceContainer apDevice;
|
|
89 |
apDevice = wifi.Install (phy, mac, wifiApNode);
|
|
90 |
|
|
91 |
/* Setting mobility model */
|
|
92 |
MobilityHelper mobility;
|
|
93 |
|
|
94 |
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
|
|
95 |
"MinX", DoubleValue (0.0),
|
|
96 |
"MinY", DoubleValue (0.0),
|
|
97 |
"DeltaX", DoubleValue (5.0),
|
|
98 |
"DeltaY", DoubleValue (10.0),
|
|
99 |
"GridWidth", UintegerValue (3),
|
|
100 |
"LayoutType", StringValue ("RowFirst"));
|
|
101 |
|
|
102 |
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
|
|
103 |
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
|
|
104 |
mobility.Install (wifiNodes);
|
|
105 |
|
|
106 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
|
|
107 |
mobility.Install (wifiApNode);
|
|
108 |
|
|
109 |
/* Internet stack*/
|
|
110 |
InternetStackHelper stack;
|
|
111 |
stack.Install (wifiApNode);
|
|
112 |
stack.Install (wifiNodes);
|
|
113 |
|
|
114 |
Ipv4AddressHelper address;
|
|
115 |
|
|
116 |
address.SetBase ("192.168.1.0", "255.255.255.0");
|
|
117 |
Ipv4InterfaceContainer wifiNodesInterfaces;
|
|
118 |
Ipv4InterfaceContainer apNodeInterface;
|
|
119 |
|
|
120 |
wifiNodesInterfaces = address.Assign (staDevices);
|
|
121 |
apNodeInterface = address.Assign (apDevice);
|
|
122 |
|
|
123 |
/* Setting applications */
|
|
124 |
UdpEchoServerHelper echoServer (9);
|
|
125 |
|
|
126 |
ApplicationContainer serverApps = echoServer.Install (wifiNodes.Get (1));
|
|
127 |
serverApps.Start (Seconds (1.0));
|
|
128 |
serverApps.Stop (Seconds (10.0));
|
|
129 |
|
|
130 |
UdpEchoClientHelper echoClient (wifiNodesInterfaces.GetAddress (1), 9);
|
|
131 |
echoClient.SetAttribute ("MaxPackets", UintegerValue (3));
|
|
132 |
echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.000001)));
|
|
133 |
echoClient.SetAttribute ("PacketSize", UintegerValue (1500));
|
|
134 |
|
|
135 |
ApplicationContainer clientApps =
|
|
136 |
echoClient.Install (wifiNodes.Get (0));
|
|
137 |
clientApps.Start (Seconds (2.0));
|
|
138 |
clientApps.Stop (Seconds (10.0));
|
|
139 |
|
|
140 |
GlobalRouteManager::PopulateRoutingTables ();
|
|
141 |
|
|
142 |
Simulator::Stop (Seconds (10.0));
|
|
143 |
|
|
144 |
YansWifiPhyHelper::EnablePcap ("test-802.11n",
|
|
145 |
wifiNodes.Get (nWifi - 1)->GetId (), 0);
|
|
146 |
|
|
147 |
Simulator::Run ();
|
|
148 |
Simulator::Destroy ();
|
|
149 |
|
|
150 |
return 0;
|
|
151 |
}
|