A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/wifi-module.h"
22 #include "ns3/mobility-module.h"
23 #include "ns3/csma-module.h"
24 #include "ns3/internet-module.h"
25 
26 // Default Network Topology
27 //
28 // Wifi 10.1.3.0
29 // AP
30 // * * * *
31 // | | | | 10.1.1.0
32 // n5 n6 n7 n0 -------------- n1 n2 n3 n4
33 // point-to-point | | | |
34 // ================
35 // LAN 10.1.2.0
36 
37 using namespace ns3;
38 
39 NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
40 
41 int
42 main (int argc, char *argv[])
43 {
44  bool verbose = true;
45  uint32_t nCsma = 3;
46  uint32_t nWifi = 3;
47 
48  CommandLine cmd;
49  cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
50  cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
51  cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
52 
53  cmd.Parse (argc,argv);
54 
55  if (nWifi > 18)
56  {
57  std::cout << "Number of wifi nodes " << nWifi <<
58  " specified exceeds the mobility bounding box" << std::endl;
59  exit (1);
60  }
61 
62  if (verbose)
63  {
64  LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
65  LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
66  }
67 
68  NodeContainer p2pNodes;
69  p2pNodes.Create (2);
70 
72  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
73  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
74 
75  NetDeviceContainer p2pDevices;
76  p2pDevices = pointToPoint.Install (p2pNodes);
77 
78  NodeContainer csmaNodes;
79  csmaNodes.Add (p2pNodes.Get (1));
80  csmaNodes.Create (nCsma);
81 
82  CsmaHelper csma;
83  csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
84  csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
85 
86  NetDeviceContainer csmaDevices;
87  csmaDevices = csma.Install (csmaNodes);
88 
89  NodeContainer wifiStaNodes;
90  wifiStaNodes.Create (nWifi);
91  NodeContainer wifiApNode = p2pNodes.Get (0);
92 
95  phy.SetChannel (channel.Create ());
96 
98  wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
99 
101 
102  Ssid ssid = Ssid ("ns-3-ssid");
103  mac.SetType ("ns3::StaWifiMac",
104  "Ssid", SsidValue (ssid),
105  "ActiveProbing", BooleanValue (false));
106 
107  NetDeviceContainer staDevices;
108  staDevices = wifi.Install (phy, mac, wifiStaNodes);
109 
110  mac.SetType ("ns3::ApWifiMac",
111  "Ssid", SsidValue (ssid));
112 
113  NetDeviceContainer apDevices;
114  apDevices = wifi.Install (phy, mac, wifiApNode);
115 
116  MobilityHelper mobility;
117 
118  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
119  "MinX", DoubleValue (0.0),
120  "MinY", DoubleValue (0.0),
121  "DeltaX", DoubleValue (5.0),
122  "DeltaY", DoubleValue (10.0),
123  "GridWidth", UintegerValue (3),
124  "LayoutType", StringValue ("RowFirst"));
125 
126  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
127  "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
128  mobility.Install (wifiStaNodes);
129 
130  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
131  mobility.Install (wifiApNode);
132 
134  stack.Install (csmaNodes);
135  stack.Install (wifiApNode);
136  stack.Install (wifiStaNodes);
137 
139 
140  address.SetBase ("10.1.1.0", "255.255.255.0");
141  Ipv4InterfaceContainer p2pInterfaces;
142  p2pInterfaces = address.Assign (p2pDevices);
143 
144  address.SetBase ("10.1.2.0", "255.255.255.0");
145  Ipv4InterfaceContainer csmaInterfaces;
146  csmaInterfaces = address.Assign (csmaDevices);
147 
148  address.SetBase ("10.1.3.0", "255.255.255.0");
149  address.Assign (staDevices);
150  address.Assign (apDevices);
151 
153 
154  ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));
155  serverApps.Start (Seconds (1.0));
156  serverApps.Stop (Seconds (10.0));
157 
158  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
159  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
160  echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
161  echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
162 
164  echoClient.Install (wifiStaNodes.Get (nWifi - 1));
165  clientApps.Start (Seconds (2.0));
166  clientApps.Stop (Seconds (10.0));
167 
169 
170  Simulator::Stop (Seconds (10.0));
171 
172  pointToPoint.EnablePcapAll ("third");
173  phy.EnablePcap ("third", apDevices.Get (0));
174  csma.EnablePcap ("third", csmaDevices.Get (0), true);
175 
176  Simulator::Run ();
178  return 0;
179 }
holds a vector of ns3::Application pointers.
tuple pointToPoint
Definition: first.py:28
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
Definition: csma-helper.cc:69
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
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
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.
NetDeviceContainer Install(NodeContainer c)
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())
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.
NetDeviceContainer Install(Ptr< Node > node) const
This method creates an ns3::CsmaChannel with the attributes configured by CsmaHelper::SetChannelAttri...
Definition: csma-helper.cc:215
Build a set of PointToPointNetDevice objects.
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:88
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.
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
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 NqosWifiMacHelper 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...
create non QoS-enabled MAC layers for a ns3::WifiNetDevice.
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
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
build a set of CsmaNetDevice objects
Definition: csma-helper.h:46
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
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...
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
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...
int main(int argc, char *argv[])
Definition: third.cc:42
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
bool verbose
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
static WifiHelper Default(void)
Definition: wifi-helper.cc:65