2011 1
Simulation of WLAN using ns-3
Izabela Mielczarek, Andrzej Stelter
Abstract—The article presents the network simulator ns-3, II. NS-3
which is a useful tool for simulation of wireless networks. There
Ns-3 is a discrete-event network simulator. It is publicly
are discussed the ways by which students can use ns-3 to develop
their WLAN projects. The example of IEEE 802.11s network available, free software, which can be used for research and
simulation is described. education. Ns-3 is developed within the ns-3 project [1],
started in 2006. The aim of the project is to maintain an open
Index Terms—ns-3, simulation, WLAN environment for researchers to contribute and share their
software. Ns-3 is primarily developed for Linux platforms, but
it can also run in Windows, using Linux emulation
I. INTRODUCTION environment called Cygwin, or virtual machine [2].
N ETWORK simulator is a computer program which allows
to model a communication network by specifying the
structure and operation of network nodes and behavior of
The ns-3 software is built on C++, i.e. it is a library
containing a set of network simulation modules implemented
as C++ objects [3]. Simulation scripts, which interact with this
communication channels. Network simulators are mainly used library, can be written in C++ or Python. The existing library
in research but they are also very useful in education. of modules allows to simulate popular wireless networks (e.g.
In this paper we focus on wireless local area network WiFi, WiMax) in a simple way, by writing a simulation script.
(WLAN) simulation. We are interested mainly in simulation Thanks to the availability of the source code of existing
of network layer and data link layer protocols. The simulation modules, it is possible to modify the operation of any module
is to be performed by students within WLAN course projects. from the library. It is also possible to create new modules,
The first problem that needs to be resolved is the selection of implementing algorithms or protocols not present in the
appropriate platform on which students would develop their existing library.
WLAN projects. One option is to use a custom network Key objects in the simulator are Nodes and Channels [2],
simulator developed from scratch by students. Unfortunately, [5]. A Node represents a network element. It is a device (e.g.
to investigate a selected network protocol, e.g. MAC protocol, computer) to which Applications, Protocol Stack, and
students would have to create a model of the entire network NetDevices can be added (Fig. 1). Applications are like
which would be too complex and time-consuming task, taking processes in a normal system. They are packet generators or
into account the time scheduled to complete the project. sinks which run on a Node. The interface between an
Another option (chosen by us) is to use a well-known Application and a Protocol Stack is called a Socket. A
simulation platform, which provides software environment for NetDevice is a network card which can be plugged into a
simulation of WLANs. We took into account only the publicly Node in order to enable the Node to communicate with other
available, open source simulators, mainly ns-2, ns-3, and Nodes in the network. Nodes communicate via Channels.
OMNeT++. Eventually, we chose network simulator 3 (ns-3). Similarly to a real network device, which may contain
The following arguments determined our choice: well- separate interface for Ethernet, WiFi, WiMax, etc., an ns-3
organized, free source code, already existing library of basic Node may contain many NetDevices. Currently, in the ns-3
WLAN modules, both a library and simulation scripts written library, there are available both wireless interfaces (e.g.
in C++ language, realistic environment (real IP/MAC
addresses, real packets, BSD-like sockets, multiple interfaces
per node, etc.).
The purpose of this paper is to show the usefulness of ns-3
as a simulation platform for students doing WLAN projects.
The rest of the paper is organized as follows. Section II
contains a short description of ns-3. Section III presents the
possible areas of applications of ns-3 in WLAN simulation.
Section IV presents the example of IEEE 802.11s network
simulation in ns-3 environment. Finally, Section V concludes
the paper.
Fig. 1. The basic model of a network in ns-3.
2
WifiNetDevice, WimaxNetDevice, LteNetDevice) and wired network layer: various routing protocols (AODV, OLSR,
ones (e.g. CsmaNetDevice, PointToPointNetDevice). A DSDV),
Channel is a physical connector between a set of NetDevices. data link layer: MAC protocols (802.11-DCF, 802.11e-
A Node may be connected to more than one Channel through EDCA), layer-2 routing protocol (802.11s-HWMP), various
multiple NetDevices. rate control algorithms,
To create a network of nodes which exchange higher layers’ physical layer: 802.11a/b/g physical layer models, various
data, the protocol stack have to be installed in each Node. propagation loss models (e.g. Jakes, TwoRayGround,
Ns-3 is a simulator intended primarily for Internet systems, Nakagami, Friis, LogDistance, ThreeLogDistance,
therefore the Internet Stack is used. Ns-3 provides FixedRss, Random, etc.).
implementation of such TCP/IP related components like IPv4, A more advanced use of ns-3 is testing custom algorithms
ARP, UDP, TCP, IPv6, etc. or protocols. It requires the creation of new modules and their
A wireless node’s specification may comprise a mobility integration with already available modules. To do this, in
model. Various mobility models are available in ns-3, e.g. addition to the knowledge of C++, students must also
constant position, constant velocity, constant acceleration, demonstrate some knowledge of Unix (e.g. sockets) and some
Gauss Markov, or random direction 2D. familiarity with object-oriented simulation of discrete-event
Ns-3 is the command line software. It does not contain any systems. Because the ns-3 code is well organized, students are
graphical interface. On the other hand ns-3 is oriented for usually able to quickly understand the code and make their
cooperation with other open source software like Wireshark or own modifications of existing modules or write new ones
Gnuplot. which replace one protocol with another at a selected layer in
A notable feature of ns-3 is its ability to cooperate with the the network stack.
real devices and applications. Packets sent in ns-3 should have Multi-radio multi-channel MAC protocol is the example of
the same format as packets sent in real networks. This allows a new protocol for WLAN, which can by studied using ns-3.
ns-3 simulation to send data on a real network. Therefore ns-3
can be easily integrated into testbed and virtual machine
environments [3]. Traffic in simulated network can be easily IV. SIMULATION OF THE IEEE 802.11S NETWORK
analyzed by means of popular traffic analyzers, like
The IEEE 802.11s is an amendment adding wireless mesh
Wireshark.
capabilities to the existing IEEE 802.11 WLAN standard. An
The main purpose of a simulation is to generate output data
important feature of IEEE 802.11s is the fact that the mesh
for further study. There are two basic methods to generate data
network is implemented in the data link layer. Hybrid
in ns-3 [2]. The first method is to use a predefined bulk output
Wireless Mesh Protocol (HWMP) is a mandatory path
mechanism. When using this method it is necessary to write a
discovery mechanism in IEEE 802.11s draft [6]. HWMP can
script parsing the content of the output file to extract required
operate in two modes: on-demand reactive mode and tree-
information from data gathered during simulation. The second
based proactive mode.
method of data generation is tracing. The ns-3 tracing system
The ns-3 library contains some modules which allow to
is built on the concept of independent tracing sources and
simulate the 802.11s mesh WLAN. In this section, it is shown
tracing sinks [4]. The tracing mechanism gives a possibility to
how students, using ns-3, can investigate the operation and
reduce the amount of data outputted by the simulator, by
performance of IEEE 802.11s network. For this purpose, two
tracing only required events. Moreover, output data can be
exemplary ns-3 simulations of 802.11s network are described.
formatted directly into required form, acceptable by programs
The simulations were performed with ns-3 ver. 3.9, using
used to analyze these data. Ns-3 generates two formats of trace
solely modules from its library.
files: pcap and ascci. The pcap (packet capture) format is used
by many traffic analyzers, e.g. Wireshark. The simulation A. The throughput of mesh WLAN
results generated by ns-3 can be easily formatted according to The first experiment consisted in studying the throughput of
requirements of Gnuplot. a mesh network. The throughput was defined here as the
number of correctly transmitted bits per unit of time. The
experiment was carried out in a network whose topology is
III. USING NS-3 IN EDUCATION shown in Fig. 2. Five mesh stations (STAs) were located in a
Ns-3 is a useful educational tool for a simulation of line, at a distance of 120 m from each other. The transmission
communication networks, especially wireless ones. range of each station was 140m and it covered the
The easiest way to use ns-3 by students is to simulate a immediately neighboring stations.
network consisting of modules stored in the simulator library. For each station, the required transmission range was set by
Modules currently available in ns-3 allow for the simulation of configuring the following parameters of the physical layer:
such wireless networks as WiFi, WiMax, and LTE. In order to Energy Detection Threshold, Transmission gain, and
simulate the network, a student has to write a simulation Reception gain. The model of a physical layer, proper to the
script, which requires C++ programming skills only. This mesh station, is implemented in YansWifiPhy class. The
way, among other things, the following WLAN issues can be locations of the mesh stations were set using the
studied: GridPositionAllocator class.
3
The simulation script implemented a function that
determined the throughput on the basis of the sum of the bytes
received. The function saved the throughput result to an output
file. The simulation script was run multiple times for varying
datagram sizes and varying hop numbers. As a result, it could
be determined how the throughput depends on the number of
Fig. 2. Topology of the network under study, experiment I hops and datagram length, as shown in Fig. 3.
The mesh STA1 was configured to receive data. To this B. The path discovery mechanism in 802.11s
end, the PacketSink application was installed on the station The aim of the second experiment was to analyze network
with the task of receiving UDP traffic. All the remaining traffic, study the operation of HWMP, and check whether the
stations were transmitting stations, each running the OnOff protocol implemented in ns-3 operates in compliance with
application. This application is a traffic generator, which 802.11s draft.
follows an On/Off pattern, i.e. On and Off states alternates. In The experiment was run for the network whose architecture
the On state, data packets of a predetermined fixed size are is shown in Fig. 4. The arrows show which stations in the
generated, while in the Off state, the generation of the packets simulation connected to each other. The stations were located
is suspended. In the case under study, OnOff application statically, and the distances were deliberately selected. The
generated UDP traffic directed at mesh STA1 with a fixed locations of the mesh stations were determined using the
intensity of 54 Mbps. ListPositionAllocator class. Like in the previous scenario, the
During the experiment, HWMP was operating in the OnOff application was used to generate UDP traffic. This
reactive mode. The measurements were carried out for four time, it was run on mesh STA1. Mesh STA5 was the receiving
datagram lengths – 100B, 800B, 1500B and 2300B – with a station; the PacketSink application was run on this station.
different number of hops between the end stations. The mesh Ns-3 makes it possible to save all the packets generated and
STA1 was the recipient station while the transmitting station received by the stations to a pcap file. This allows one to
changed with each increase in the number of hops, i.e. for one analyze the network traffic, and thereby to study the process of
hop, the mesh STA2 was the source; for two hops, the mesh mesh network creation and path discovery. From the PREQ
STA3 was the source; for three hops, the mesh STA4 was the and PREP packets exchanged in mesh network during the path
source; and for four hops, the mesh STA5 was the source. discovery process, the metric values, corresponding to
To determine the throughput, an ns-3 tracing system was individual connections, can be read. The Wireshark program
used. First, information on the number of bytes received was used to read the pcap file containing the frames
correctly by mesh STA1 was gathered. To achieve this, the transmitted in the mesh network.
RxOk trace source was used. This source reports that the PHY Packets transmitted in an ns-3 simulated network are just
layer has correctly received a packet, and makes the contents like packets transmitted in a real network. The analysis
of the packet available. A trace sink attached to the RxOk performed using Wireshark showed that, for path discovery,
trace source processed the received packets. This processing the frames exchanged both in the proactive and reactive mode
consisted in checking for packet type. If the received packet of HWMP match the frame format specified in the 802.11s
was a data packet, its size was recorded. The sizes of all recommendation. The subsequent stages of mesh network
correctly received packets were summed throughout the creation and path discovery using the HWMP protocol also
duration of the measurement. follow the solutions recommended in the 802.11s draft.
Missing fields were only found in packets exchanged during
the process of the establishing of connections between the
mesh stations (the Peer Link Open and Peer Link Confirm
frames), which should have carried information on the
connection parameters.
In mesh network simulation, it is possible to generate an
xml report for each mesh station. This report contains statistics
for the HWMP routing protocol and the Mesh Peer Link
Management (MPLM) protocol. The report contains
information on the number and size of the generated, sent and
received packets of each type, information on whether a given
station functions as a root, the parameters of the connections
that the stations have established with neighbouring stations,
and the metric values for each connection.
Based on the information contained in the report, it can be
verified whether the stations established connections as
predicted by the user, whether and how often the connections
Fig. 3. Throughput as a function of datagram length and number of hops,
determined for the mesh network shown in Fig. 2, HWMP reactive mode.
were broken, and what metric values were set. The reports
4
Fig. 5. Possible paths established using the HWMP operating in the reactive
Fig. 4. Topology of the network under study, experiment II. mode.
obtained for the network under study show that the stations V. CONCLUSIONS
established connections as shown in Fig. 4.
The ns-3 is an useful educational tool for simulation of
In the scenario under study, mesh STA1 and mesh STA5
WLAN. By writing relatively simple simulation scripts,
could communicate using four different paths, plotted using
students can evaluate the standard protocols of IEEE 802.11
different line styles in Fig. 5. Above the lines, the metric
network. They can also modify existing protocols or replace
values for each connection are shown, which were read from
them with their own solutions.
the reports for each station after the simulation was completed.
The example in Fig. 5 refers to the situation in which none of
the stations functioned as a root, and the paths were
REFERENCES
determined using the reactive mode of HWMP. As the figure
[1] [Link]
shows, in some cases the stations set different metric values
[2] Ns-3 Tutorial, Release ns-3.12, Available: [Link]
for the same connection. For example, the metric value for the 12/documentation/
connection between mesh STA2 and mesh STA1 set by mesh [3] Ns-3 Model library, Release ns-3.12, Available: [Link]
STA2 was 24, while that set by mesh STA1 was 29. ns-3-12/documentation/
[4] Ns-3 Manual, Release ns-3.12, Available: [Link]
The continuous line arrows in Fig. 5 denote the path with 12/documentation/
the smallest number of hops. The traffic analysis demonstrated [5] T. Henderson, M. Lacage, “ns-3 toutorial”, Workshop on ns-3, March
that the data travelled between the end stations using a path 2009
[6] IEEE 80211sTP/D3.0, IEEE Draft Standard for Information Technology
with the lowest cost according to the metric values contained – Telecommunications and information exchange between systems –
in the reports. One can thus conclude that the model of Local and metropolitan area networks – Specific requirements – PART
HWMP implemented in ns-3 operates in compliance with the 11: Wireless LAN Medium Access Control (MAC) and Physical Layer
(PHY) specifications – Amendmet 10: Mesh Networking, 2009
802.11s recommendation. [7] I.A. Akyildiz, X. Wang, “Wireless Mesh Networks”, Wiley 2009
C. Modifications of routing protocol in 802.11s
The 802.11s draft defines the Airtime Link metric, which
may be used by a path selection protocol to identify the best
path [6]. The draft does not prevent other metrics from being
used, i.e. the recommended metric may be replaced with any
path selection metric. There are proposed many metric
calculation algorithms [7]. Using ns-3, one can test one’s own
algorithms of determining a metric. To do so, one needs to
write a class whose functionality will determine the value of
the metric.