A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
simple-wifi-frame-aggregation.cc
Go to the documentation of this file.
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/network-module.h"
22 #include "ns3/applications-module.h"
23 #include "ns3/wifi-module.h"
24 #include "ns3/mobility-module.h"
25 #include "ns3/ipv4-global-routing-helper.h"
26 #include "ns3/internet-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 
65  phy.SetChannel (channel.Create ());
66 
69  wifi.SetRemoteStationManager ("ns3::AarfWifiManager", "FragmentationThreshold", UintegerValue (2500));
70 
71  Ssid ssid = Ssid ("ns-3-802.11n");
72  mac.SetType ("ns3::StaWifiMac",
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::ApWifiMac",
82  "Ssid", SsidValue (ssid));
83  mac.SetMsduAggregatorForAc (AC_BE, "ns3::MsduStandardAggregator",
84  "MaxAmsduSize", UintegerValue (7935));
85 
86  NetDeviceContainer apDevice;
87  apDevice = wifi.Install (phy, mac, wifiApNode);
88 
89  /* Setting mobility model */
90  MobilityHelper mobility;
91 
92  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
93  "MinX", DoubleValue (0.0),
94  "MinY", DoubleValue (0.0),
95  "DeltaX", DoubleValue (5.0),
96  "DeltaY", DoubleValue (10.0),
97  "GridWidth", UintegerValue (3),
98  "LayoutType", StringValue ("RowFirst"));
99 
100  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
101  "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
102  mobility.Install (wifiNodes);
103 
104  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
105  mobility.Install (wifiApNode);
106 
107  /* Internet stack*/
109  stack.Install (wifiApNode);
110  stack.Install (wifiNodes);
111 
113 
114  address.SetBase ("192.168.1.0", "255.255.255.0");
115  Ipv4InterfaceContainer wifiNodesInterfaces;
116  Ipv4InterfaceContainer apNodeInterface;
117 
118  wifiNodesInterfaces = address.Assign (staDevices);
119  apNodeInterface = address.Assign (apDevice);
120 
121  /* Setting applications */
123 
124  ApplicationContainer serverApps = echoServer.Install (wifiNodes.Get (1));
125  serverApps.Start (Seconds (1.0));
126  serverApps.Stop (Seconds (10.0));
127 
128  UdpEchoClientHelper echoClient (wifiNodesInterfaces.GetAddress (1), 9);
129  echoClient.SetAttribute ("MaxPackets", UintegerValue (3));
130  echoClient.SetAttribute ("Interval", TimeValue (Seconds (0.000001)));
131  echoClient.SetAttribute ("PacketSize", UintegerValue (1500));
132 
134  echoClient.Install (wifiNodes.Get (0));
135  clientApps.Start (Seconds (2.0));
136  clientApps.Stop (Seconds (10.0));
137 
139 
140  Simulator::Stop (Seconds (10.0));
141 
142  phy.EnablePcap ("test-802.11n",
143  wifiNodes.Get (nWifi - 1)->GetId (), 0);
144 
145  Simulator::Run ();
147 
148  return 0;
149 }
holds a vector of ns3::Application pointers.
Hold a bool native type.
Definition: boolean.h:38
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
holds a vector of std::pair of Ptr and interface index.
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:73
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
hold variables of type string
Definition: string.h:19
Make it easy to create and manage PHY objects for the yans model.
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Set the underlying type of the MAC and its attributes.
tuple echoServer
Definition: first.py:42
Create an application which sends a UDP packet and waits for an echo of this packet.
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
void SetMsduAggregatorForAc(AcIndex ac, std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue())
Set the class, type and attributes for the Msdu aggregator.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:88
Best Effort.
Definition: qos-utils.h:38
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:102
tuple clientApps
Definition: first.py:53
ApplicationContainer Install(Ptr< Node > node) const
Create a UdpEchoServerApplication on the specified Node.
hold objects of type ns3::Rectangle
void SetChannel(Ptr< YansWifiChannel > channel)
Create a server application which waits for input UDP packets and sends them back to the original sen...
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
hold objects of type ns3::Time
Definition: nstime.h:961
Hold an unsigned integer type.
Definition: uinteger.h:46
holds a vector of ns3::NetDevice pointers
static QosWifiMacHelper Default(void)
Create a mac helper in a default working state.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:152
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
tuple echoClient
Definition: first.py:48
tuple serverApps
Definition: first.py:44
create QoS-enabled MAC layers for a ns3::WifiNetDevice.
int main(int argc, char *argv[])
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
manage and create wifi channel objects for the yans model.
tuple stack
Definition: first.py:34
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
Helper class used to assign positions and mobility models to nodes.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
uint32_t GetId(void) const
Definition: node.cc:104
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:408
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
hold objects of type ns3::Ssid
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
tuple address
Definition: first.py:37
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Hold a floating point type.
Definition: double.h:41
a 2d rectangle
Definition: rectangle.h:33
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static WifiHelper Default(void)
Definition: wifi-helper.cc:65