Sie sind auf Seite 1von 36

One Week FDP, School of C&IT, REVA University

“Introduction & Demo


on Network Simulator”

by
Dr. Shrikant S. Tangade
Asst. Prof. & Research Scholar, School of ECE, REVA University &
Acknowledgement

Dr. Sunilkumar S. Manvi REVA Dr. Mohit P. Tahiliani


University NITK
Outline
• Introduction to ns-3
• Features of ns-3 Vs. ns-2
• Installation Steps of ns-3
• Examples of ns-3 programs
– Simple ns-3 program
– VANET ns-3 program
– WSN ns-3 program *
• Simulation visualizer
– NetAnim (offline visualizer)
– PyViz (Live visualizer)
• Mobility Generator Tools: MOVE & SUMO
3
Introduction to ns-3

4
Introduction to ns-3
ns History:
1990 2000 2016 2018

1988: REAL (Keshav)


1990s: ns-1 regular
releases
1996: ns-2

1997-2000: DARPA VINT


2001-04: DARPA SAMAN, NSF CONSER
2006: NSF CISE CRI Awards

Inputs: yans,
GTNetS, ns-2 ns-3 core development (2006-08)
June 2008: ns-3.1
October2016: ns-3.26

June (11-15) 2018: 10th Anniversary of the first ns-3 release


5
Introduction to ns-3 (cont.)
What is ns-3:
• ns-3 is an Open Source Network Simulator
• ns-3 is a discrete-event network simulator targeted for
research and educational use

6
Introduction to ns-3 (cont.)
ns-3 is Discrete-event Simulation:
• Simulation time moves in discrete jumps from event
to event
• C++ functions schedule events to occur at specific
simulation times
• A simulation scheduler orders the event execution
• Simulation::Run() executes a single-threaded event
list
• Simulation stops at specific time or when events end

7
Introduction to ns-3 (cont.)
ns-3 Core Internal Structure:
• ns-3 is written in C++
• Provides a set of simulation models implemented as
C++ objects.
• More emphasis on emulation.

8
Introduction to ns-3 (cont.)
ns-3 Sample Models:

9
Introduction to ns-3 (cont.)
Basic ns-3 program architecture:
Application Application
Application Application
Sockets-like
API

Protocol Protocol
Packet(s) stack
stack

NetDevice NetDevice
NetDevice Channel NetDevice
Channel

Node-1 Node-2
10
ns-3
Introduction to ns-3 (cont.)
Publications using ns-3:
A common question is "How many ns-3 papers are there?
• Small survey of 139 paper results from 2013-14 & 1000+
as of now search in the IEEE library (top relevant results)
• Some papers matched multiple categories
• Hot topics:
– LTE/cellular networks (15)
– Wireless routing protocols (14)
– Sensor networks (13)
– Wireless MAC and PHY protocols (11)
– Vehicular Network: VANET

11
Introduction to ns-3 (cont.)
Paper Counts by Topic (sample):
Topic Count Topic Count
LTE/Cellular 15 Network coding 4
Wireless routing protocols 14 Datacenter networks 4
Wireless sensor networks 13 Distributed systems 4
Wireless MAC/PHY 11 Optical links 3
Wireless QoS 9 Misc. physical links 3
Vehicular networks 9 Multicast 3
TCP/congestion control 9 Misc. security 2
Wireless security 9 Wired routers 2
About ns-3 itself 8 Wireless QoS 2
Wifi/mesh networks 7 WiMAX 1
Voice/video apps 6 Mobility 1
Energy/resource consumption 6 Misc. routing 1
DTN and space networks 5 Miscellaneous 1
Misc. wireless 5
12
Features of ns-3 Vs. ns-2

13
Features of ns-3 Vs. ns-2
“ns-3 is a new simulator, without backward compatibility”

Similarities to ns-2:
• C++ software core
• GNU licensing (free software license)

Differences:
• Python scripting or C++ programs replaces OTcl
• most of the core rewritten
• new animators, configuration tools: pyViz
• ns-3 documentation actively maintained but ns-2 is no
longer actively maintained/supported
14
Features of ns-3 Vs. ns-2 (cont.)
• ns-3 documentation actively maintained
• ns-3 Main Website: https://www.nsnam.org

15
Features of ns-3 Vs. ns-2 (cont.)

• The Choice of Programming Language:


“Otcl & C++ in ns-2, C++ or Python in ns-3”

1. Not possible to run a simulation in ns-2 purely from C++.


2. Some components in ns-2 are written in OTcl and some in C+
+.
3. Simulations in ns-3 can be run using purely C++ or in Python.
4. Components in ns-3 are completely written in C++.

16
Features of ns-3 Vs. ns-2 (cont.)
Simulation Output: NAM & NetAnim

1. NAM and Trace files in ns-2, NetAnim and PCAP Trace


files in ns-3
2. Network Animator (NAM) is used as a visualization tool
in ns-2
3. NetAnim is used as a visualization tool in ns-3.
4. ns-2 generates trace files in three different formats.
5. ns-3 uses .pcap trace files as the main trace files.

17
Features of ns-3 Vs. ns-2 (cont.)
• Performance:
“Slow with ns-2, Efficient with ns-3”

1. ns-2 lacks proper memory management strategies.

2. Interfacing OTcl with C++ incurs overhead in ns-2.

3. Yet another overhead is of OTcl interpreter.

4. ns-2 suffers from “downcasting” and “C++ weak base class”

problem
18
Features of ns-3 Vs. ns-2 (cont.)
• Approach for building:
“Complex with ns-2, Simple with ns-3”
‘makefile’ for ns-2, ‘waf’ for ns-3

1. No “ns” executable in ns-3.

2. Recompiling of ns-2 involves several steps.

3. Recompiling of ns-3 easier with waf

19
Features of ns-3 Vs. ns-2 (cont.)
• Community Support:
“Good for ns-2, New & Improved for ns-3”

1. ns-2 has a more diverse set of contributed modules than


does ns-3

2. A lot of documentation exists for ns-2


3. ns-3 has more detailed models for WSN, MANET, VANET, LTE
and also for upcoming networks like 5G, etc.

20
Installation Steps of ns-3

21
Installation Steps of ns-3
• Installing and Testing ns-3 with NetAnim on Ubuntu 14.04
• ns-3 version considered: ns-allinone-3.20

Part-A: Downloading ns-3

Part-B: Installing Prerequisite Packages

Part-C: Installing ns-3


Part-D: Testing ns-3 & NetAnim

22
Installation Steps of ns-3 (cont.)
• ns-3 version considered: ns-allinone-3.20

• Part-A: Downloading ns-3

• ns-3 can be downloaded in at least two different ways:


1) Method -1 (Recommended for beginners): Downloading a
ns-3 tarball i.e., a zipped folder (We follow this method
here)
Go to following link to download ns-allinone-3.20 tarball:
https://www.nsnam.org/release/ns-allinone-3.20.tar.bz2
(Recent ns-3 Release is: 3.28)
2) Method-2: Downloading through *bake* 23
Installation Steps of ns-3 (cont.)
•Part-B: Installing Prerequisite Packages
List of Prerequisite Packages to be installed:
1.gcc, g++, python
2.python-dev (Optional: If you want to use Python as the main language for
network configuration)
3.qt4-dev-tools (Optional: If you want to install *NetAnim* (animator for ns-3)
along with ns-3)
4.tcpdump (Optional: Required for analyzing packet capture files (.pcap)
generated by ns-3)
5.wireshark (Optional: Alternative to tcpdump. You can use anyone of these)
6.gnuplot (Optional: Required for plotting high quality graphs through *.dat* files
generated by ns-3)
24
Installation Steps of ns-3 (cont.)
• Part-C: Installing ns-3
• ns-3 can be installed in three different ways [2]:

Method 1: by using build.py (We follow this method)

Method 2: by using bake


Method 3: by using Waf

25
Installation Steps of ns-3 (cont.)
• Part-C: Installing ns-3 (cont.)
• Installation ns-3 using Method 1: by using build.py
Step -1: Unzip the “ns-allinone-3.20.tar.bz2” tarball
tar xjf ns-allinone-3.20.tar.bz2 (through terminal)
Step-2: Go in “ns-allinone-3.20” folder and give the following
command for installation
./build.py - - enable-examples - - enable-tests
• After a while, you may see the following message on screen

“ Leaving directory './ns-3.20‘ ”


• which indicates that ns-3 is installed !!!
26
Installation Steps of ns-3 (cont.)
• Part-D: Testing ns-3
• To test whether all modules of ns-3 are installed successfully,
follow the procedure as given below:

Step -1: Go to “ns-allinone-3.20/ns-3.20” folder and give the


following command:
./test.py -c core (through terminal)

• Note: Some tests may be skipped while testing but that should
not bother you if your module is not among those that were
skipped!
27
Installation Steps of ns-3 (cont.)
• Part-D: Testing NetAnim
• only for those users who installed qt4-dev-tools package before
ns-3 installation):

• To test whether NetAnim is installed successfully, follow the


procedure given below:
Step -1: Go to ns-allinone-3.20/netanim-3.105 and give the
following command:
./NetAnim (through terminal)

• If it is successfully installed, a window as shown next should open


28
Installation Steps of ns-3 (cont.)
•Part-D: Testing NetAnim (cont.)
•If it is successfully installed, a window as shown next should open

29
Examples of ns-3 programs

30
Examples of ns-3 Programs
Organization of Program
• Any ns-3 program organization contains following Key-
Abstractions:
– Node
– Application
– Net device
– Channel
• Each abstraction have their separate module to implement in
ns-3

31
Examples of ns-3 Programs (cont.)
Modules
• Each modules has 'Attributes‘

• Functionalities of modules are provided by different C++


member functions in C++ classes called as helper classes

• It is easy extend module to add new features/functionalities

• It is also easy to add new module

• API calls are used in the program to do the necessary


simulation

32
Examples of ns-3 Programs (cont.)
General Structure of ns-3 Program
• For our simulation, we need to write a simulation program
which is a C++ program.

• To this program the ns-3 library is linked to build & execute


our simulation

• The “General Structure/Steps of ns-3 program” are:


(next slide)

33
Examples of ns-3 Programs (cont.)
General Structure of ns-3 Program (cont.)
• The “General Structure/Steps of ns-3 program” are:
1) Include necessary header files
2) Use appropriate name space
3) Enable logging for different modules (Optional)
4) Create nodes
5) Create net devices with MAC and PHY
6) Attach Net devices to nodes and set interconnections
7) Install protocol stack in nodes
8) Set network address for interfaces
9) Install applications in nodes
10) Setup tracing (Optional)
11) Set application start and stop time
12) Set simulation start time
13) Run simulation
14) Release resources at end of simulation

34
Examples of ns-3 Programs (cont.)
Example-1: Simple ns-3 Simulation Program
• A simple “Hello ns-3”
• Refer Program

35
Examples of ns-3 Programs (cont.)
Example-2: VANET ns-3 Simulation Program
• Using ns-3 VANET “WAVE Module” for V2V/V2I communications
• Refer Program

36