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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * This example is inspired from examples/tutorial/third.cc by
7 * substituting the CSMA network with another WiFi network.
8 *
9 * Author: Ameya Deshpande <ameyanrd@outlook.com>
10 */
11
12#include "ns3/applications-module.h"
13#include "ns3/core-module.h"
14#include "ns3/csma-module.h"
15#include "ns3/internet-module.h"
16#include "ns3/mobility-module.h"
17#include "ns3/network-module.h"
18#include "ns3/nix-vector-routing-module.h"
19#include "ns3/point-to-point-module.h"
20#include "ns3/ssid.h"
21#include "ns3/wifi-module.h"
22
23/**
24 * This example demonstrates how Nix works with
25 * two Wifi networks on the same channel.
26 *
27 * IPv4 Network Topology
28 * \verbatim
29 Wifi 10.1.1.0/24
30 AP
31 * * * *
32 | | | | 10.1.2.0/24
33 n5 n6 n7 n0 -------------- n1 n2 n3 n4
34 point-to-point | | | |
35 * * * *
36 AP
37 Wifi 10.1.3.0/24
38 \endverbatim
39 *
40 * \verbatim
41 Wifi 2001:1::/64
42 AP
43 * * * *
44 | | | | 2001:2::/64
45 n5 n6 n7 n0 -------------- n1 n2 n3 n4
46 point-to-point | | | |
47 * * * *
48 AP
49 Wifi 2001:3::/64
50 \endverbatim
51 *
52 * Expected Outputs:
53 * IPv4:
54 * \verbatim
55 Time: +7s, Nix Routing
56 Route path from Node 4 to Node 7, Nix Vector: 100011 (6 bits left)
57 10.1.1.3 (Node 4) ----> 10.1.1.4 (Node 0)
58 10.1.2.1 (Node 0) ----> 10.1.2.2 (Node 1)
59 10.1.3.4 (Node 1) ----> 10.1.3.3 (Node 7)
60 \endverbatim
61 *
62 * IPv6:
63 * \verbatim
64 Time: +7s, Nix Routing
65 Route path from Node 4 to Node 7, Nix Vector: 100011 (6 bits left)
66 2001:1::200:ff:fe00:5 (Node 4) ----> fe80::200:ff:fe00:6 (Node 0)
67 fe80::200:ff:fe00:1 (Node 0) ----> fe80::200:ff:fe00:2 (Node 1)
68 fe80::200:ff:fe00:a (Node 1) ----> 2001:3::200:ff:fe00:9 (Node 7)
69 \endverbatim
70 */
71
72using namespace ns3;
73
74NS_LOG_COMPONENT_DEFINE("NixDoubleWifiExample");
75
76int
77main(int argc, char* argv[])
78{
79 bool useIpv6 = false;
80 bool enableNixLog = false;
81
82 CommandLine cmd(__FILE__);
83 cmd.AddValue("useIPv6", "Use IPv6 instead of IPv4", useIpv6);
84 cmd.AddValue("enableNixLog", "Enable NixVectorRouting logging", enableNixLog);
85 cmd.Parse(argc, argv);
86
87 LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
88 LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
89 if (enableNixLog)
90 {
91 LogComponentEnable("NixVectorRouting", LOG_LEVEL_LOGIC);
92 }
93
95 p2pNodes.Create(2);
96
98 pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));
99 pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));
100
102 p2pDevices = pointToPoint.Install(p2pNodes);
103
104 NodeContainer wifiStaNodes1;
105 wifiStaNodes1.Create(3);
106 NodeContainer wifiApNode1 = p2pNodes.Get(0);
107
108 NodeContainer wifiStaNodes2;
109 wifiStaNodes2.Create(3);
110 NodeContainer wifiApNode2 = p2pNodes.Get(1);
111
114 phy.SetChannel(channel.Create());
115
117
119 Ssid ssid = Ssid("ns-3-ssid-first");
120 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
121
122 NetDeviceContainer staDevices1;
123 staDevices1 = wifi.Install(phy, mac, wifiStaNodes1);
124
125 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
126
127 NetDeviceContainer apDevices1;
128 apDevices1 = wifi.Install(phy, mac, wifiApNode1);
129
130 ssid = Ssid("ns-3-ssid-second");
131 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
132
133 NetDeviceContainer staDevices2;
134 staDevices2 = wifi.Install(phy, mac, wifiStaNodes2);
135
136 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
137
138 NetDeviceContainer apDevices2;
139 apDevices2 = wifi.Install(phy, mac, wifiApNode2);
140
142
143 mobility.SetPositionAllocator("ns3::GridPositionAllocator",
144 "MinX",
145 DoubleValue(0.0),
146 "MinY",
147 DoubleValue(0.0),
148 "DeltaX",
149 DoubleValue(5.0),
150 "DeltaY",
151 DoubleValue(10.0),
152 "GridWidth",
153 UintegerValue(3),
154 "LayoutType",
155 StringValue("RowFirst"));
156
157 mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel",
158 "Bounds",
159 RectangleValue(Rectangle(-50, 50, -50, 50)));
160 mobility.Install(wifiStaNodes1);
161 mobility.Install(wifiStaNodes2);
162
163 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
164 mobility.Install(wifiApNode1);
165 mobility.Install(wifiApNode2);
166
167 Address udpServerAddress;
168
169 if (!useIpv6)
170 {
173 stack.SetRoutingHelper(nixRouting);
174 stack.Install(wifiApNode1);
175 stack.Install(wifiStaNodes1);
176 stack.Install(wifiApNode2);
177 stack.Install(wifiStaNodes2);
178
180
181 address.SetBase("10.1.1.0", "255.255.255.0");
182 address.Assign(staDevices1);
183 address.Assign(apDevices1);
184
185 address.SetBase("10.1.2.0", "255.255.255.0");
187 p2pInterfaces = address.Assign(p2pDevices);
188
189 address.SetBase("10.1.3.0", "255.255.255.0");
190 Ipv4InterfaceContainer staDevicesInterfaces2;
191 staDevicesInterfaces2 = address.Assign(staDevices2);
192 address.Assign(apDevices2);
193
194 udpServerAddress = staDevicesInterfaces2.GetAddress(2);
195
196 Ptr<OutputStreamWrapper> routingStream =
197 Create<OutputStreamWrapper>("nix-double-wifi-ipv4.routes", std::ios::out);
198 nixRouting.PrintRoutingPathAt(Seconds(7),
199 wifiStaNodes1.Get(2),
200 staDevicesInterfaces2.GetAddress(2),
201 routingStream);
202 }
203 else
204 {
207 stack.SetRoutingHelper(nixRouting);
208 stack.Install(wifiApNode1);
209 stack.Install(wifiStaNodes1);
210 stack.Install(wifiApNode2);
211 stack.Install(wifiStaNodes2);
212
214
215 address.SetBase(Ipv6Address("2001:1::"), Ipv6Prefix(64));
216 address.Assign(staDevices1);
217 address.Assign(apDevices1);
218
219 address.SetBase(Ipv6Address("2001:2::"), Ipv6Prefix(64));
221 p2pInterfaces = address.Assign(p2pDevices);
222
223 address.SetBase(Ipv6Address("2001:3::"), Ipv6Prefix(64));
224 Ipv6InterfaceContainer staDevicesInterfaces2;
225 staDevicesInterfaces2 = address.Assign(staDevices2);
226 address.Assign(apDevices2);
227
228 udpServerAddress = staDevicesInterfaces2.GetAddress(2, 1);
229
230 Ptr<OutputStreamWrapper> routingStream =
231 Create<OutputStreamWrapper>("nix-double-wifi-ipv6.routes", std::ios::out);
232 nixRouting.PrintRoutingPathAt(Seconds(7),
233 wifiStaNodes1.Get(2),
234 staDevicesInterfaces2.GetAddress(2, 1),
235 routingStream);
236 }
237
239
240 ApplicationContainer serverApps = echoServer.Install(wifiStaNodes2.Get(2));
241 serverApps.Start(Seconds(1.0));
242 serverApps.Stop(Seconds(10.0));
243
244 UdpEchoClientHelper echoClient(udpServerAddress, 9);
245 echoClient.SetAttribute("MaxPackets", UintegerValue(1));
246 echoClient.SetAttribute("Interval", TimeValue(Seconds(1.0)));
247 echoClient.SetAttribute("PacketSize", UintegerValue(1024));
248
249 ApplicationContainer clientApps = echoClient.Install(wifiStaNodes1.Get(2));
250 clientApps.Start(Seconds(2.0));
251 clientApps.Stop(Seconds(10.0));
252
254
257 return 0;
258}
a polymophic address class
Definition address.h:90
holds a vector of ns3::Application pointers.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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.
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.
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.
a 2d rectangle
Definition rectangle.h:24
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
Hold variables of type string.
Definition string.h:45
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:34
helps to create WifiNetDevice objects
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:191
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
echoClient
Definition first.py:48
address
Definition first.py:36
serverApps
Definition first.py:43
pointToPoint
Definition first.py:27
echoServer
Definition first.py:41
clientApps
Definition first.py:53
stack
Definition first.py:33
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:291
@ LOG_LEVEL_LOGIC
LOG_LOGIC and above.
Definition log.h:99
@ LOG_LEVEL_INFO
LOG_INFO and above.
Definition log.h:93
p2pNodes
Definition second.py:39
p2pInterfaces
Definition second.py:64
p2pDevices
Definition second.py:50
ssid
Definition third.py:82
channel
Definition third.py:77
mac
Definition third.py:81
wifi
Definition third.py:84
mobility
Definition third.py:92
phy
Definition third.py:78