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
34/**
35 * This example demonstrates how Nix works with
36 * two Wifi networks on the same channel.
37 *
38 * IPv4 Network Topology
39 * \verbatim
40 Wifi 10.1.1.0/24
41 AP
42 * * * *
43 | | | | 10.1.2.0/24
44 n5 n6 n7 n0 -------------- n1 n2 n3 n4
45 point-to-point | | | |
46 * * * *
47 AP
48 Wifi 10.1.3.0/24
49 \endverbatim
50 *
51 * \verbatim
52 Wifi 2001:1::/64
53 AP
54 * * * *
55 | | | | 2001:2::/64
56 n5 n6 n7 n0 -------------- n1 n2 n3 n4
57 point-to-point | | | |
58 * * * *
59 AP
60 Wifi 2001:3::/64
61 \endverbatim
62 *
63 * Expected Outputs:
64 * IPv4:
65 * \verbatim
66 Time: +7s, Nix Routing
67 Route path from Node 4 to Node 7, Nix Vector: 100011 (6 bits left)
68 10.1.1.3 (Node 4) ----> 10.1.1.4 (Node 0)
69 10.1.2.1 (Node 0) ----> 10.1.2.2 (Node 1)
70 10.1.3.4 (Node 1) ----> 10.1.3.3 (Node 7)
71 \endverbatim
72 *
73 * IPv6:
74 * \verbatim
75 Time: +7s, Nix Routing
76 Route path from Node 4 to Node 7, Nix Vector: 100011 (6 bits left)
77 2001:1::200:ff:fe00:5 (Node 4) ----> fe80::200:ff:fe00:6 (Node 0)
78 fe80::200:ff:fe00:1 (Node 0) ----> fe80::200:ff:fe00:2 (Node 1)
79 fe80::200:ff:fe00:a (Node 1) ----> 2001:3::200:ff:fe00:9 (Node 7)
80 \endverbatim
81 */
82
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 {
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 {
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:101
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:49
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:455
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.
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:77
a 2d rectangle
Definition: rectangle.h:35
AttributeValue implementation for Rectangle.
Definition: rectangle.h:125
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Definition: ssid.h:96
Hold variables of type string.
Definition: string.h:56
AttributeValue implementation for Time.
Definition: nstime.h:1406
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:324
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:1319
ns echoServer
Definition: first.py:52
ns serverApps
Definition: first.py:54
ns echoClient
Definition: first.py:59
ns clientApps
Definition: first.py:64
ns address
Definition: first.py:47
ns stack
Definition: first.py:44
ns pointToPoint
Definition: first.py:38
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:302
@ LOG_LEVEL_LOGIC
LOG_LOGIC and above.
Definition: log.h:110
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition: log.h:104
ns cmd
Definition: second.py:40
ns p2pNodes
Definition: second.py:50
ns p2pDevices
Definition: second.py:61
ns p2pInterfaces
Definition: second.py:75
ns wifi
Definition: third.py:95
ns ssid
Definition: third.py:93
ns mac
Definition: third.py:92
ns channel
Definition: third.py:88
ns mobility
Definition: third.py:105
ns phy
Definition: third.py:89