A Discrete-Event Network Simulator
API
third.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16 
17 #include "ns3/core-module.h"
18 #include "ns3/point-to-point-module.h"
19 #include "ns3/network-module.h"
20 #include "ns3/applications-module.h"
21 #include "ns3/mobility-module.h"
22 #include "ns3/csma-module.h"
23 #include "ns3/internet-module.h"
24 #include "ns3/yans-wifi-helper.h"
25 #include "ns3/ssid.h"
26 
27 // Default Network Topology
28 //
29 // Wifi 10.1.3.0
30 // AP
31 // * * * *
32 // | | | | 10.1.1.0
33 // n5 n6 n7 n0 -------------- n1 n2 n3 n4
34 // point-to-point | | | |
35 // ================
36 // LAN 10.1.2.0
37 
38 using namespace ns3;
39 
40 NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
41 
42 int
43 main (int argc, char *argv[])
44 {
45  bool verbose = true;
46  uint32_t nCsma = 3;
47  uint32_t nWifi = 3;
48  bool tracing = false;
49 
50  CommandLine cmd (__FILE__);
51  cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
52  cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
53  cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
54  cmd.AddValue ("tracing", "Enable pcap tracing", tracing);
55 
56  cmd.Parse (argc,argv);
57 
58  // The underlying restriction of 18 is due to the grid position
59  // allocator's configuration; the grid layout will exceed the
60  // bounding box if more than 18 nodes are provided.
61  if (nWifi > 18)
62  {
63  std::cout << "nWifi should be 18 or less; otherwise grid layout exceeds the bounding box" << std::endl;
64  return 1;
65  }
66 
67  if (verbose)
68  {
69  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
70  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
71  }
72 
74  p2pNodes.Create (2);
75 
77  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
78  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
79 
81  p2pDevices = pointToPoint.Install (p2pNodes);
82 
84  csmaNodes.Add (p2pNodes.Get (1));
85  csmaNodes.Create (nCsma);
86 
88  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
89  csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
90 
92  csmaDevices = csma.Install (csmaNodes);
93 
95  wifiStaNodes.Create (nWifi);
97 
100  phy.SetChannel (channel.Create ());
101 
103  wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
104 
106  Ssid ssid = Ssid ("ns-3-ssid");
107  mac.SetType ("ns3::StaWifiMac",
108  "Ssid", SsidValue (ssid),
109  "ActiveProbing", BooleanValue (false));
110 
112  staDevices = wifi.Install (phy, mac, wifiStaNodes);
113 
114  mac.SetType ("ns3::ApWifiMac",
115  "Ssid", SsidValue (ssid));
116 
118  apDevices = wifi.Install (phy, mac, wifiApNode);
119 
121 
122  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
123  "MinX", DoubleValue (0.0),
124  "MinY", DoubleValue (0.0),
125  "DeltaX", DoubleValue (5.0),
126  "DeltaY", DoubleValue (10.0),
127  "GridWidth", UintegerValue (3),
128  "LayoutType", StringValue ("RowFirst"));
129 
130  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
131  "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
132  mobility.Install (wifiStaNodes);
133 
134  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
135  mobility.Install (wifiApNode);
136 
138  stack.Install (csmaNodes);
139  stack.Install (wifiApNode);
140  stack.Install (wifiStaNodes);
141 
143 
144  address.SetBase ("10.1.1.0", "255.255.255.0");
146  p2pInterfaces = address.Assign (p2pDevices);
147 
148  address.SetBase ("10.1.2.0", "255.255.255.0");
151 
152  address.SetBase ("10.1.3.0", "255.255.255.0");
153  address.Assign (staDevices);
154  address.Assign (apDevices);
155 
157 
159  serverApps.Start (Seconds (1.0));
160  serverApps.Stop (Seconds (10.0));
161 
163  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
164  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
165  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
166 
168  echoClient.Install (wifiStaNodes.Get (nWifi - 1));
169  clientApps.Start (Seconds (2.0));
170  clientApps.Stop (Seconds (10.0));
171 
173 
174  Simulator::Stop (Seconds (10.0));
175 
176  if (tracing)
177  {
178  phy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
179  pointToPoint.EnablePcapAll ("third");
180  phy.EnablePcap ("third", apDevices.Get (0));
181  csma.EnablePcap ("third", csmaDevices.Get (0), true);
182  }
183 
184  Simulator::Run ();
186  return 0;
187 }
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::YansWifiChannelHelper::Default
static YansWifiChannelHelper Default(void)
Create a channel helper in a default working state.
Definition: yans-wifi-helper.cc:41
ns3::YansWifiPhyHelper
Make it easy to create and manage PHY objects for the YANS model.
Definition: yans-wifi-helper.h:161
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
third.staDevices
staDevices
Definition: third.py:103
ns3::BooleanValue
AttributeValue implementation for Boolean.
Definition: boolean.h:37
ns3::LOG_LEVEL_INFO
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
second.p2pInterfaces
p2pInterfaces
Definition: second.py:75
tracing
bool tracing
Flag to enable/disable generation of tracing files.
Definition: wifi-bianchi.cc:85
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiHelper
helps to create WifiNetDevice objects
Definition: wifi-helper.h:327
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::UdpEchoClientHelper
Create an application which sends a UDP packet and waits for an echo of this packet.
Definition: udp-echo-helper.h:107
ns3::RectangleValue
AttributeValue implementation for Rectangle.
Definition: rectangle.h:97
third.channel
channel
Definition: third.py:92
ns3::LogComponentEnable
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
ns3::WifiPhyHelper::DLT_IEEE802_11_RADIO
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:180
third.mac
mac
Definition: third.py:99
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::SsidValue
AttributeValue implementation for Ssid.
Definition: ssid.h:105
ns3::CsmaHelper
build a set of CsmaNetDevice objects
Definition: csma-helper.h:47
ns3::Ssid
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
third.apDevices
apDevices
Definition: third.py:106
third.wifi
wifi
Definition: third.py:96
ns3::Ipv4GlobalRoutingHelper::PopulateRoutingTables
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Definition: ipv4-global-routing-helper.cc:61
first.stack
stack
Definition: first.py:41
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
ns3::NanoSeconds
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1313
second.csmaInterfaces
csmaInterfaces
Definition: second.py:78
second.p2pNodes
p2pNodes
Definition: second.py:50
ns3::Ipv4InterfaceContainer
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Definition: ipv4-interface-container.h:55
verbose
bool verbose
Definition: openflow-switch.cc:50
first.address
address
Definition: first.py:44
third.wifiApNode
wifiApNode
Definition: third.py:90
second.cmd
cmd
Definition: second.py:35
second.p2pDevices
p2pDevices
Definition: second.py:61
ns3::Rectangle
a 2d rectangle
Definition: rectangle.h:35
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
first.echoClient
echoClient
Definition: first.py:56
first.clientApps
clientApps
Definition: first.py:61
second.nCsma
nCsma
Definition: second.py:36
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
first.serverApps
serverApps
Definition: first.py:52
third.ssid
ssid
Definition: third.py:100
first.pointToPoint
pointToPoint
Definition: first.py:35
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
ns3::PointToPointHelper
Build a set of PointToPointNetDevice objects.
Definition: point-to-point-helper.h:45
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
third.nWifi
nWifi
Definition: third.py:43
third.wifiStaNodes
wifiStaNodes
Definition: third.py:88
second.csmaDevices
csmaDevices
Definition: second.py:67
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
second.csmaNodes
csmaNodes
Definition: second.py:53
ns3::YansWifiChannelHelper
manage and create wifi channel objects for the YANS model.
Definition: yans-wifi-helper.h:37
ns3::WifiMacHelper
create MAC layers for a ns3::WifiNetDevice.
Definition: wifi-mac-helper.h:48
ns3::UdpEchoServerHelper
Create a server application which waits for input UDP packets and sends them back to the original sen...
Definition: udp-echo-helper.h:38
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
second.csma
csma
Definition: second.py:63
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
third.mobility
mobility
Definition: third.py:108
first.echoServer
echoServer
Definition: first.py:50
third.phy
phy
Definition: third.py:93