A Discrete-Event Network Simulator
API
nix-double-wifi.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2021 NITK Surathkal
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 * This example is inspired from examples/tutorial/third.cc by
19 * substituting the CSMA network with another WiFi network.
20 *
21 * Author: Ameya Deshpande <ameyanrd@outlook.com>
22 */
23
24#include "ns3/core-module.h"
25#include "ns3/point-to-point-module.h"
26#include "ns3/network-module.h"
27#include "ns3/applications-module.h"
28#include "ns3/mobility-module.h"
29#include "ns3/csma-module.h"
30#include "ns3/internet-module.h"
31#include "ns3/wifi-module.h"
32#include "ns3/ssid.h"
33#include "ns3/nix-vector-routing-module.h"
34
84using namespace ns3;
85
86NS_LOG_COMPONENT_DEFINE ("NixDoubleWifiExample");
87
88int
89main (int argc, char *argv[])
90{
91 bool useIpv6 = false;
92 bool enableNixLog = false;
93
94 CommandLine cmd (__FILE__);
95 cmd.AddValue ("useIPv6", "Use IPv6 instead of IPv4", useIpv6);
96 cmd.AddValue ("enableNixLog", "Enable NixVectorRouting logging", enableNixLog);
97 cmd.Parse (argc,argv);
98
99 LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
100 LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
101 if (enableNixLog)
102 {
103 LogComponentEnable ("NixVectorRouting", LOG_LEVEL_LOGIC);
104 }
105
107 p2pNodes.Create (2);
108
110 pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
111 pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
112
114 p2pDevices = pointToPoint.Install (p2pNodes);
115
116 NodeContainer wifiStaNodes1;
117 wifiStaNodes1.Create (3);
118 NodeContainer wifiApNode1 = p2pNodes.Get (0);
119
120 NodeContainer wifiStaNodes2;
121 wifiStaNodes2.Create (3);
122 NodeContainer wifiApNode2 = p2pNodes.Get (1);
123
124 YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
126 phy.SetChannel (channel.Create ());
127
129
131 Ssid ssid = Ssid ("ns-3-ssid-first");
132 mac.SetType ("ns3::StaWifiMac",
133 "Ssid", SsidValue (ssid),
134 "ActiveProbing", BooleanValue (false));
135
136 NetDeviceContainer staDevices1;
137 staDevices1 = wifi.Install (phy, mac, wifiStaNodes1);
138
139 mac.SetType ("ns3::ApWifiMac",
140 "Ssid", SsidValue (ssid));
141
142 NetDeviceContainer apDevices1;
143 apDevices1 = wifi.Install (phy, mac, wifiApNode1);
144
145 ssid = Ssid ("ns-3-ssid-second");
146 mac.SetType ("ns3::StaWifiMac",
147 "Ssid", SsidValue (ssid),
148 "ActiveProbing", BooleanValue (false));
149
150 NetDeviceContainer staDevices2;
151 staDevices2 = wifi.Install (phy, mac, wifiStaNodes2);
152
153 mac.SetType ("ns3::ApWifiMac",
154 "Ssid", SsidValue (ssid));
155
156 NetDeviceContainer apDevices2;
157 apDevices2 = wifi.Install (phy, mac, wifiApNode2);
158
160
161 mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
162 "MinX", DoubleValue (0.0),
163 "MinY", DoubleValue (0.0),
164 "DeltaX", DoubleValue (5.0),
165 "DeltaY", DoubleValue (10.0),
166 "GridWidth", UintegerValue (3),
167 "LayoutType", StringValue ("RowFirst"));
168
169 mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
170 "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
171 mobility.Install (wifiStaNodes1);
172 mobility.Install (wifiStaNodes2);
173
174 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
175 mobility.Install (wifiApNode1);
176 mobility.Install (wifiApNode2);
177
178 Address udpServerAddress;
179
180 if (!useIpv6)
181 {
183 Ipv4NixVectorHelper nixRouting;
184 stack.SetRoutingHelper (nixRouting);
185 stack.Install (wifiApNode1);
186 stack.Install (wifiStaNodes1);
187 stack.Install (wifiApNode2);
188 stack.Install (wifiStaNodes2);
189
191
192 address.SetBase ("10.1.1.0", "255.255.255.0");
193 address.Assign (staDevices1);
194 address.Assign (apDevices1);
195
196 address.SetBase ("10.1.2.0", "255.255.255.0");
199
200 address.SetBase ("10.1.3.0", "255.255.255.0");
201 Ipv4InterfaceContainer staDevicesInterfaces2;
202 staDevicesInterfaces2 = address.Assign (staDevices2);
203 address.Assign (apDevices2);
204
205 udpServerAddress = staDevicesInterfaces2.GetAddress (2);
206
207 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("nix-double-wifi-ipv4.routes", std::ios::out);
208 nixRouting.PrintRoutingPathAt (Seconds (7), wifiStaNodes1.Get (2), staDevicesInterfaces2.GetAddress (2), routingStream);
209 }
210 else
211 {
213 Ipv6NixVectorHelper nixRouting;
214 stack.SetRoutingHelper (nixRouting);
215 stack.Install (wifiApNode1);
216 stack.Install (wifiStaNodes1);
217 stack.Install (wifiApNode2);
218 stack.Install (wifiStaNodes2);
219
221
222 address.SetBase (Ipv6Address ("2001:1::"), Ipv6Prefix (64));
223 address.Assign (staDevices1);
224 address.Assign (apDevices1);
225
226 address.SetBase (Ipv6Address ("2001:2::"), Ipv6Prefix (64));
229
230 address.SetBase (Ipv6Address ("2001:3::"), Ipv6Prefix (64));
231 Ipv6InterfaceContainer staDevicesInterfaces2;
232 staDevicesInterfaces2 = address.Assign (staDevices2);
233 address.Assign (apDevices2);
234
235 udpServerAddress = staDevicesInterfaces2.GetAddress (2, 1);
236
237 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("nix-double-wifi-ipv6.routes", std::ios::out);
238 nixRouting.PrintRoutingPathAt (Seconds (7), wifiStaNodes1.Get (2), staDevicesInterfaces2.GetAddress (2, 1), routingStream);
239 }
240
242
243 ApplicationContainer serverApps = echoServer.Install (wifiStaNodes2.Get (2));
244 serverApps.Start (Seconds (1.0));
245 serverApps.Stop (Seconds (10.0));
246
247 UdpEchoClientHelper echoClient (udpServerAddress, 9);
248 echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
249 echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
250 echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
251
252 ApplicationContainer clientApps = echoClient.Install (wifiStaNodes1.Get (2));
253 clientApps.Start (Seconds (2.0));
254 clientApps.Stop (Seconds (10.0));
255
256 Simulator::Stop (Seconds (10.0));
257
258 Simulator::Run ();
259 Simulator::Destroy ();
260 return 0;
261}
a polymophic address class
Definition: address.h:91
holds a vector of ns3::Application pointers.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Parse command-line arguments.
Definition: command-line.h:229
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Helper class to auto-assign global IPv6 unicast addresses.
Describes an IPv6 address.
Definition: ipv6-address.h:50
Keep track of a set of IPv6 interfaces.
Ipv6Address GetAddress(uint32_t i, uint32_t j) const
Get the address for the specified index.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Helper class that adds Nix-vector routing to nodes.
void PrintRoutingPathAt(Time printTime, Ptr< Node > source, IpAddress dest, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing path for a source and destination at a particular time.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Build a set of PointToPointNetDevice objects.
a 2d rectangle
Definition: rectangle.h:35
AttributeValue implementation for Rectangle.
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Hold variables of type string.
Definition: string.h:41
AttributeValue implementation for Time.
Definition: nstime.h:1308
Create an application which sends a UDP packet and waits for an echo of this packet.
Create a server application which waits for input UDP packets and sends them back to the original sen...
Hold an unsigned integer type.
Definition: uinteger.h:44
helps to create WifiNetDevice objects
Definition: wifi-helper.h:323
create MAC layers for a ns3::WifiNetDevice.
manage and create wifi channel objects for the YANS model.
Make it easy to create and manage PHY objects for the YANS model.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
echoClient
Definition: first.py:56
address
Definition: first.py:44
serverApps
Definition: first.py:52
pointToPoint
Definition: first.py:35
echoServer
Definition: first.py:50
clientApps
Definition: first.py:61
stack
Definition: first.py:41
Every class exported by the ns3 library is enclosed in the ns3 namespace.
@ LOG_LEVEL_LOGIC
LOG_LOGIC and above.
Definition: log.h:113
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:361
p2pNodes
Definition: second.py:50
p2pInterfaces
Definition: second.py:75
p2pDevices
Definition: second.py:61
cmd
Definition: second.py:35
ssid
Definition: third.py:97
channel
Definition: third.py:92
mac
Definition: third.py:96
wifi
Definition: third.py:99
mobility
Definition: third.py:107
phy
Definition: third.py:93