A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ht-wifi-network.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 ("DataRates");
45 
46 double rxBytessum=0;
47 double throughput=0;
48 
49 
50 //===========================================================================
51 //Set position of the nodes
52 //===========================================================================
53 static void
54 SetPosition (Ptr<Node> node, Vector position)
55 {
56  Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
57  mobility->SetPosition (position);
58 }
59 
60 //==========================================================================
61 //==========================================================================
62 
63 int main (int argc, char *argv[])
64 {
65  std::cout << "DataRate" <<" " << "Throughput" << '\n';
66  bool udp = true;
67  int i=2;
68  for (;i <= 2; i++)
69  {
70  uint32_t nWifi = 1;
71  CommandLine cmd;
72  cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
73  cmd.Parse (argc,argv);
74  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("990000"));
75  // disable rts cts all the time.
76  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("99000"));
77  NodeContainer wifiNodes;
78  wifiNodes.Create (1);
79  NodeContainer wifiApNode;
80  wifiApNode.Create (1);
81 
84  phy.SetChannel (channel.Create ());
85  if (i ==3 || i == 4)
86  phy.Set ("ShortGuardEnabled",BooleanValue(true));
87  //phy.Set ("GreenfieldEnabled",BooleanValue(true));
88 
92 
93 
94  Ssid ssid = Ssid ("ns380211n");
95  double datarate = 0;
97  if (i==0)
98  {
99  DataRate = StringValue("OfdmRate6_5MbpsBW20MHz");
100  datarate = 6.5;
101  }
102  else if (i==1)
103  {
104  DataRate = StringValue("OfdmRate58_5MbpsBW20MHz");
105  datarate = 58.5;
106  }
107  else if (i == 2)
108  {
109  DataRate = StringValue("OfdmRate65MbpsBW20MHz");
110  datarate = 65;
111  }
112  else if (i == 3)
113  {
114  DataRate = StringValue("OfdmRate57_8MbpsBW20MHz");
115  datarate = 57.8;
116  }
117  else if (i == 4)
118  {
119  DataRate = StringValue("OfdmRate72_2MbpsBW20MHz");
120  datarate = 72.2;
121  }
122 
123  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode", DataRate,
124  "ControlMode", DataRate);
125  mac.SetType ("ns3::StaWifiMac",
126  "Ssid", SsidValue (ssid),
127  "ActiveProbing", BooleanValue (false));
128 
129  NetDeviceContainer staDevices;
130  staDevices = wifi.Install (phy, mac, wifiNodes);
131 
132  mac.SetType ("ns3::ApWifiMac",
133  "Ssid", SsidValue (ssid));
134 
135  NetDeviceContainer apDevice;
136  apDevice = wifi.Install (phy, mac, wifiApNode);
137  /* Ptr<WifiRemoteStationManager> apStationManager =
138  DynamicCast<WifiNetDevice>(apDevice.Get (0))->GetRemoteStationManager ();
139  apStationManager->AddBasicMode (WifiMode ("OfdmRate13MbpsBW20MHz"));
140  apStationManager->AddBasicMode (WifiMode ("OfdmRate19_5MbpsBW20MHz"));
141  apStationManager->AddBasicMode (WifiMode ("OfdmRate26MbpsBW20MHz"));
142  apStationManager->AddBasicMode (WifiMode ("OfdmRate39MbpsBW20MHz"));
143  Ptr<WifiRemoteStationManager> staStationManager =
144  DynamicCast<WifiNetDevice> (staDevices.Get (0))->GetRemoteStationManager ();
145  staStationManager->AddBasicMode (WifiMode ("OfdmRate13MbpsBW20MHz"));
146  staStationManager->AddBasicMode (WifiMode ("OfdmRate19_5MbpsBW20MHz"));
147  staStationManager->AddBasicMode (WifiMode ("OfdmRate26MbpsBW20MHz"));
148  staStationManager->AddBasicMode (WifiMode ("OfdmRate39MbpsBW20MHz"));*/
149 
150  // mobility.
151  MobilityHelper mobility;
152  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
153  mobility.Install (wifiNodes);
154  mobility.Install (wifiApNode);
155 
156  SetPosition (wifiNodes.Get(0), Vector (1.0,0.0,0.0));
157  SetPosition (wifiApNode.Get(0), Vector (0.0,0.0,0.0));
158 
159 
160  /* Internet stack*/
162  stack.Install (wifiApNode);
163  stack.Install (wifiNodes);
164 
166 
167  address.SetBase ("10.1.3.0", "255.255.255.0");
168  Ipv4InterfaceContainer wifiNodesInterfaces;
169  Ipv4InterfaceContainer apNodeInterface;
170 
171  wifiNodesInterfaces = address.Assign (staDevices);
172  apNodeInterface = address.Assign (apDevice);
173 
175 
176  double t=10;
177 
178  /* Setting applications */
179  if (udp)
180  {
181  UdpServerHelper myServer (9);
182  serverApps = myServer.Install (wifiNodes.Get (0));
183  serverApps.Start (Seconds (0.0));
184  serverApps.Stop (Seconds (t));
185 
186  UdpClientHelper myClient (wifiNodesInterfaces.GetAddress (0), 9);
187  myClient.SetAttribute ("MaxPackets", UintegerValue (64707202));
188  myClient.SetAttribute ("Interval", TimeValue (Time ("0.00002")));
189  myClient.SetAttribute ("PacketSize", UintegerValue (1500));
190 
191  ApplicationContainer clientApps = myClient.Install (wifiApNode.Get (0));
192  clientApps.Start (Seconds (0.0));
193  clientApps.Stop (Seconds (t));
194  }
195  else
196  {
197 
198  //TCP flow
199  uint16_t port = 50000;
200  Address apLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
201  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", apLocalAddress);
202  sink1App = packetSinkHelper.Install (wifiNodes.Get (0));
203 
204  sink1App.Start (Seconds (0.0));
205  sink1App.Stop (Seconds (t));
206 
207  OnOffHelper onoff ("ns3::TcpSocketFactory",Ipv4Address::GetAny ());
208  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable(30)));//in seconds
209  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable(0)));
210  onoff.SetAttribute ("PacketSize", UintegerValue (1500-30));//1024
211  onoff.SetAttribute ("DataRate", DataRateValue (100000000));//51200
213 
214  AddressValue remoteAddress (InetSocketAddress (wifiNodesInterfaces.GetAddress(0), port));
215  onoff.SetAttribute ("Remote", remoteAddress);
216  apps.Add (onoff.Install (wifiApNode.Get (0)));
217  apps.Start (Seconds (0.0));
218  apps.Stop (Seconds (t));
219  }
220 
221 
223 
224  Simulator::Stop (Seconds (t));
225  Simulator::Run ();
227 
228  //UDP
229  if (udp)
230  {
231  uint32_t totalPacketsThrough = DynamicCast<UdpServer>(serverApps.Get (0))->GetReceived ();
232  throughput=totalPacketsThrough*1500*8/(t*1000000.0);
233  }
234  else
235  {
236  //TCP
237  uint32_t totalPacketsThrough = DynamicCast<PacketSink>(sink1App.Get (0))->GetTotalRx ();
238  throughput=totalPacketsThrough*8/((t-3)*1000000.0);
239  }
240 
241  std::cout << datarate <<" " << throughput << '\n';
242  }
243  return 0;
244 }
holds a vector of ns3::Application pointers.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
an Inet address class
static Ipv4Address GetAny(void)
create HT-enabled MAC layers for a ns3::WifiNetDevice.
A random variable that returns a constantClass ConstantVariable defines a random number generator tha...
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.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
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.
int main(int argc, char *argv[])
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
void Set(std::string name, const AttributeValue &v)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
hold objects of type ns3::RandomVariable
helps to create WifiNetDevice objects
Definition: wifi-helper.h:88
double rxBytessum
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
a 3d vector
Definition: vector.h:31
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:102
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:86
tuple clientApps
Definition: first.py:53
static HtWifiMacHelper Default(void)
Create a mac helper in a default working state.
Class for representing data rates.
Definition: data-rate.h:71
Keep track of the current position and velocity of an object.
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
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
Vector3D Vector
Definition: vector.h:118
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:96
Create a server application which waits for input UDP packets and uses the information carried into t...
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 serverApps
Definition: first.py:44
void SetAttribute(std::string name, const AttributeValue &value)
Record an attribute to be set in each Application after it is is created.
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
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())
manage and create wifi channel objects for the yans model.
void SetPosition(const Vector &position)
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.
hold objects of type ns3::Address
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...
ApplicationContainer Install(NodeContainer c)
Create one UDP server application on each of the Nodes in the NodeContainer.
double throughput
hold objects of type ns3::DataRate
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
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
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.
static void SetPosition(Ptr< Node > node, Vector position)
tuple address
Definition: first.py:37
Ptr< T > GetObject(void) const
Definition: object.h:361
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static WifiHelper Default(void)
Definition: wifi-helper.cc:65