A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nix-double-wifi.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 NITK Surathkal
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * This example is inspired from examples/tutorial/third.cc by
18 * substituting the CSMA network with another WiFi network.
19 *
20 * Author: Ameya Deshpande <ameyanrd@outlook.com>
21 */
22
23#include "ns3/applications-module.h"
24#include "ns3/core-module.h"
25#include "ns3/csma-module.h"
26#include "ns3/internet-module.h"
27#include "ns3/mobility-module.h"
28#include "ns3/network-module.h"
29#include "ns3/nix-vector-routing-module.h"
30#include "ns3/point-to-point-module.h"
31#include "ns3/ssid.h"
32#include "ns3/wifi-module.h"
33
83using namespace ns3;
84
85NS_LOG_COMPONENT_DEFINE("NixDoubleWifiExample");
86
87int
88main(int argc, char* argv[])
89{
90 bool useIpv6 = false;
91 bool enableNixLog = false;
92
93 CommandLine cmd(__FILE__);
94 cmd.AddValue("useIPv6", "Use IPv6 instead of IPv4", useIpv6);
95 cmd.AddValue("enableNixLog", "Enable NixVectorRouting logging", enableNixLog);
96 cmd.Parse(argc, argv);
97
98 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
99 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
100 if (enableNixLog)
101 {
102 LogComponentEnable("NixVectorRouting", LOG_LEVEL_LOGIC);
103 }
104
106 p2pNodes.Create(2);
107
109 pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
110 pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
111
113 p2pDevices = pointToPoint.Install(p2pNodes);
114
115 NodeContainer wifiStaNodes1;
116 wifiStaNodes1.Create(3);
117 NodeContainer wifiApNode1 = p2pNodes.Get(0);
118
119 NodeContainer wifiStaNodes2;
120 wifiStaNodes2.Create(3);
121 NodeContainer wifiApNode2 = p2pNodes.Get(1);
122
125 phy.SetChannel(channel.Create());
126
128
130 Ssid ssid = Ssid("ns-3-ssid-first");
131 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
132
133 NetDeviceContainer staDevices1;
134 staDevices1 = wifi.Install(phy, mac, wifiStaNodes1);
135
136 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
137
138 NetDeviceContainer apDevices1;
139 apDevices1 = wifi.Install(phy, mac, wifiApNode1);
140
141 ssid = Ssid("ns-3-ssid-second");
142 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
143
144 NetDeviceContainer staDevices2;
145 staDevices2 = wifi.Install(phy, mac, wifiStaNodes2);
146
147 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
148
149 NetDeviceContainer apDevices2;
150 apDevices2 = wifi.Install(phy, mac, wifiApNode2);
151
153
154 mobility.SetPositionAllocator("ns3::GridPositionAllocator",
155 "MinX",
156 DoubleValue(0.0),
157 "MinY",
158 DoubleValue(0.0),
159 "DeltaX",
160 DoubleValue(5.0),
161 "DeltaY",
162 DoubleValue(10.0),
163 "GridWidth",
164 UintegerValue(3),
165 "LayoutType",
166 StringValue("RowFirst"));
167
168 mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel",
169 "Bounds",
170 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");
198 p2pInterfaces = address.Assign(p2pDevices);
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 =
208 Create<OutputStreamWrapper>("nix-double-wifi-ipv4.routes", std::ios::out);
209 nixRouting.PrintRoutingPathAt(Seconds(7),
210 wifiStaNodes1.Get(2),
211 staDevicesInterfaces2.GetAddress(2),
212 routingStream);
213 }
214 else
215 {
217 Ipv6NixVectorHelper nixRouting;
218 stack.SetRoutingHelper(nixRouting);
219 stack.Install(wifiApNode1);
220 stack.Install(wifiStaNodes1);
221 stack.Install(wifiApNode2);
222 stack.Install(wifiStaNodes2);
223
225
226 address.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
227 address.Assign(staDevices1);
228 address.Assign(apDevices1);
229
230 address.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
232 p2pInterfaces = address.Assign(p2pDevices);
233
234 address.SetBase(Ipv6Address("2001:3::"), Ipv6Prefix(64));
235 Ipv6InterfaceContainer staDevicesInterfaces2;
236 staDevicesInterfaces2 = address.Assign(staDevices2);
237 address.Assign(apDevices2);
238
239 udpServerAddress = staDevicesInterfaces2.GetAddress(2, 1);
240
241 Ptr<OutputStreamWrapper> routingStream =
242 Create<OutputStreamWrapper>("nix-double-wifi-ipv6.routes", std::ios::out);
243 nixRouting.PrintRoutingPathAt(Seconds(7),
244 wifiStaNodes1.Get(2),
245 staDevicesInterfaces2.GetAddress(2, 1),
246 routingStream);
247 }
248
250
251 ApplicationContainer serverApps = echoServer.Install(wifiStaNodes2.Get(2));
252 serverApps.Start(Seconds(1.0));
253 serverApps.Stop(Seconds(10.0));
254
255 UdpEchoClientHelper echoClient(udpServerAddress, 9);
256 echoClient.SetAttribute("MaxPackets", UintegerValue(1));
257 echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
258 echoClient.SetAttribute("PacketSize", UintegerValue(1024));
259
260 ApplicationContainer clientApps = echoClient.Install(wifiStaNodes1.Get(2));
261 clientApps.Start(Seconds(2.0));
262 clientApps.Stop(Seconds(10.0));
263
265
268 return 0;
269}
a polymophic address class
Definition: address.h:100
holds a vector of ns3::Application pointers.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Parse command-line arguments.
Definition: command-line.h:232
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a 2d rectangle
Definition: rectangle.h:35
AttributeValue implementation for Rectangle.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Hold variables of type string.
Definition: string.h:56
AttributeValue implementation for Time.
Definition: nstime.h:1423
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:45
helps to create WifiNetDevice objects
Definition: wifi-helper.h:325
create MAC layers for a ns3::WifiNetDevice.
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
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:202
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
ns echoServer
Definition: first.py:46
ns serverApps
Definition: first.py:48
ns echoClient
Definition: first.py:53
ns clientApps
Definition: first.py:58
ns address
Definition: first.py:40
ns stack
Definition: first.py:37
ns pointToPoint
Definition: first.py:31
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:305
@ LOG_LEVEL_LOGIC
LOG_LOGIC and above.
Definition: log.h:113
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:107
ns cmd
Definition: second.py:33
ns p2pNodes
Definition: second.py:43
ns p2pDevices
Definition: second.py:54
ns p2pInterfaces
Definition: second.py:68
ns wifi
Definition: third.py:88
ns ssid
Definition: third.py:86
ns mac
Definition: third.py:85
ns channel
Definition: third.py:81
ns mobility
Definition: third.py:96
ns phy
Definition: third.py:82