ns3 Lecture Notes
ns3 Lecture Notes
Data communications
▪ Installation (slide 5)
▪ Starting with Ubuntu installation (slide 6)
▪ Starting with ns-3 installation (slide 30)
2
Introduction
▪ The goal of this lecture is to experience a simulator
▪ There are no annoying coding and debugging assignments
(just run the scripts)
▪ The ns-3 simulator is a discrete-event network simulator
▪ ns-3 is an open source project
▪ ns-3 is not an officially supported software product of any
company
▪ ns-3 is designed as a set of libraries that can be combined
together and also with other external software libraries
▪ ns-3 is primarily used on Linux or macOS systems
3
Resources
▪ Main web site
▪ https://www.nsnam.org
▪ Tutorial ★
▪ https://www.nsnam.org/docs/release/3.36/tutorial/html/index.html
▪ Manual (Release 3.36)
▪ https://www.nsnam.org/docs/release/3.36/manual/singlehtml/index.html
▪ API documentation ★ ★
▪ https://www.nsnam.org/docs/release/3.36/doxygen/index.html
▪ Git
▪ https://gitlab.com/nsnam/ns-3-dev
▪ Google groups (You can check Q&A history)
▪ https://groups.google.com/g/ns-3-users
▪ TA email
▪ [email protected]
4
Installation
▪ Ubuntu installation for Windows users
▪ Those who are ready for the Ubuntu environment can move on to slide 34
☞ For Mac users, refer https://www.nsnam.org/wiki/Installation#macOS
▪ Ubuntu
▪ One of the popular Linux distributions
▪ https://releases.ubuntu.com/20.04/
▪ VirtualBox
▪ Powerful tool that can virtualize almost any operating system (OS)
▪ https://www.virtualbox.org/wiki/Downloads
5
Installation
▪ Ubuntu 20.04 https://releases.ubuntu.com/20.04/
▪ Download Ubuntu 20.04 desktop image
▪ It takes up 4.2GB of memory and takes a long time (7+ minutes)
to download
6
Installation
▪ VirtualBox https://www.virtualbox.org/wiki/Downloads/
▪ Download VirtualBox for Windows hosts
7
Installation
▪ VirtualBox
▪ Executes the VirtualBox setup file
▪ ‘Press Next’ is all you need until the successful installation
8
Installation
▪ VirtualBox setting
▪ Executes the VirtualBox after the installation
▪ Then, press the New (새로 만들기) button
9
Installation
▪ VirtualBox setting
▪ Type anything you want in the name field
▪ Select Linux and version Ubuntu 20.04 LTS
▪ Press the Next button
10
Installation
▪ VirtualBox setting
▪ Allocate sufficient RAM and processors for the virtual machine
▪ If you give it less, it will slow down
▪ Press the Next button
11
Installation
▪ VirtualBox setting
▪ Allocate sufficient memory for the virtual machine, then press the
Next button
12
Installation
▪ VirtualBox setting
▪ Finish
13
Installation
▪ VirtualBox setting
▪ After the basic settings, select the newly created virtual machine
and click the Start button
14
Installation
▪ VirtualBox setting
▪ It’s time to plug-in the Ubuntu ISO image
▪ Press the dropdown button
15
Installation
▪ VirtualBox setting
▪ Find & select the iso image
▪ Then, press the mount and retry boot button
16
Installation
▪ Ubuntu setup
▪ This screen appears a few moments later
▪ Let’s press the install Ubuntu
17
Installation
▪ Ubuntu setup
▪ Press the Continue button
18
Installation
▪ Ubuntu setup
▪ Select the Minimal installation option, Download update while
installing Ubuntu, and then press the Continue button
19
Installation
▪ Ubuntu setup
▪ Press the Install Now
20
Installation
▪ Ubuntu setup
▪ Press the Continue button
21
Installation
▪ Ubuntu setup
▪ Who are you?
22
Installation
▪ Ubuntu setup
▪ Welcome to Ubuntu… It takes a long time (10+ minutes) to
complete the installation
23
Installation
▪ Ubuntu setup
▪ Congratulations. You have completed the Ubuntu installation.
▪ Restart now
24
Installation
▪ Ubuntu setup
▪ Just press ENTER after restarting
25
Installation
▪ Ubuntu setup
▪ Log-in
26
Installation
▪ Ubuntu setup
▪ Skip all the suggestions
27
Installation
▪ Ubuntu setup
▪ If you see a pop-up window like this, press the Ask Me Later
28
Installation
▪ Optional
▪ You can open display settings by right-clicking the background
29
Installation
▪ ns-3 installation
▪ Open Firefox web browser on the left side
30
Installation
▪ ns-3 installation
▪ Visit to nsnam.org
31
Installation
▪ ns-3 installation
▪ Press the Download button
32
Installation
▪ ns-3 installation
▪ Select the ‘ns-3.36’, and then, Press the word ‘this link’ in the
Download section
33
Installation
▪ ns-3 installation
▪ Select the Save file option and press the OK
34
Installation
▪ ns-3 installation
▪ When the download is complete, open the Downloads directory
35
Installation
▪ ns-3 installation
▪ Right-click on the blank space in the Downloads directory and
press "Open in Terminal"
36
Installation
▪ ns-3 installation
▪ Type tar xjf ns-allinone-3.36.1.tar.bz2 in the terminal
▪ Tip: Type up to tar xjfs ns and press Tab key to complete the
filename automatically.
37
Installation
▪ ns-3 installation
▪ Type mv ns-allinone-3.36.1 ../Desktop/ in the terminal
▪ This command will move (mv) ns-3 directory to Desktop directory
▪ .. stands for the parent directory
▪ Tip: Type up to mv ns and press Tab key to complete the
filename automatically.
38
Installation
▪ ns-3 installation
▪ Type cd ../Desktop/ns-allinone-3.36.1/ns-3.36.1/
▪ The command cd means change directory, so it will change your
working directory to the ns-3.36.1 directory
▪ Note that I changed directory to ns-3.36.1, not ns-allinone-3.36.1
39
Installation
▪ ns-3 installation
▪ Download minimal requirements to run ns-3
▪ Type sudo apt install python3 g++ cmake
▪ sudo means run the command with super user authority, and apt install
command is used for download the packages
▪ g++ is a c++ compiler and cmake is a tool for build, test and package
software
▪ Then enter your login password
40
Installation
▪ ns-3 installation
▪ Type these two commands
▪ ./ns3 clean
▪ ./ns3 means execute ns3 file in the current working directory (./)
▪ clean for clean out the previous build is not usually strictly necessary, but
is a good practice
▪ ./ns3 configure -–enable-test -–enable-examples
▪ configure is for change the build configuration of ns-3 projects, such as
logging options and compiler optimization (details are in the ns-3 manual)
▪ Further, You can use the --enable-test and example options to build a
project that includes examples and tests
▪ Then type ./ns3 build to build the ns-3 project
▪ It takes a long long time (30+ minutes)
41
Installation
▪ When the build is complete, enter the command below
./ns3 run hello-simulator
42
Installation
▪ Optional
▪ It is recommended that you use your favorite text editor or IDE
▪ Popular text editors
▪ Vim https://www.vim.org/
▪ Emacs https://www.gnu.org/software/emacs/
▪ Sublime text https://www.sublimetext.com/
▪ Nano https://www.nano-editor.org/
▪ IDE
▪ VS code https://code.visualstudio.com/
▪ CLion https://www.jetbrains.com/clion/
▪ This lecture uses Sublime text
43
Installation
▪ Optional
▪ Sublime text installation
44
Installation
▪ Optional
▪ Sublime text installation
45
Installation
▪ Optional
▪ Sublime text installation
46
Installation
▪ Optional
▪ Sublime text installation
47
Installation
▪ Optional
▪ Sublime text installation
48
Brief tutorial
▪ ns-3 key abstraction
▪ Node
▪ A computing device that connects to a network
▪ Application
▪ ns-3 applications run on ns-3 Nodes to drive simulations in the
simulated world
▪ Basic abstraction for a user program that generates some activity
▪ Channel
▪ The media over which data flows in the network
▪ NetDevice
▪ It can be regarded as a network interface card (NIC)
▪ A net device is “installed” in a Node in order to enable the Node to
communicate with other Nodes in the simulation via Channels
▪ Topology helpers
▪ It provides many convenient operations, such as create a NetDevice,
add a MAC address, assigning IP address, connect the NetDevice to a
Channel, etc. 49
Brief tutorial
▪ Tutorial script
▪ From now on, ns-allinone-3.36.1/ns-3.36.1 is considered as a base directory
▪ You can find tutorial scripts in the examples/tutorial directory
51
Brief tutorial
▪ first.cc
▪ Namespace declaration
▪ After this declaration, you will not have to type ns3:: scope
resolution operator before all of the ns-3 code in order to use it
▪ If you are not familiar with the concept of the namespace in C++, please
visit this site: https://www.cplusplus.com/doc/oldtutorial/namespaces/
▪ Log component define
▪ These two lines of code enable debug logging at the INFO level for
echo clients and servers
▪ Details about logging are discussed later
▪ Node container
▪ It will install an Internet Stack (TCP, UDP, IP, etc.) on each of the
nodes in the node container.
54
Brief tutorial
▪ first.cc
▪ Ipv4AddressHelper
55
Brief tutorial
▪ first.cc
▪ UdpEchoServerHelper
56
Brief tutorial
▪ first.cc
▪ UdpEchoClientHelper
58
Brief tutorial
▪ Building your first script
▪ Let’s copy (cp) examples/tutorial/first.cc into the scratch directory
▪ The command is executed in the base directory
▪ You can see the logging component on the echo client indicate that it has sent
a 1024 bytes packet to the Echo Server on 10.1.1.2
▪ You can also see the logging component on the echo server say that it has
received the 1024 bytes from 10.1.1.1
▪ The echo server silently echoes the packet and you can see the echo client log
that it has received its packet back from the server
59
Brief tutorial
▪ Logging
▪ ns-3 supports some kind of message logging facility
▪ ns-3 provide a selectable, multi-level (7) approach to message logging
▪ LOG_ERROR: log error messages
▪ LOG_WARN: log warning messages
▪ LOG_DEBUG: log debugging messages
▪ LOG_INFO: Log informational messages about program progress
▪ LOG_FUNCTION: Log a message describing each function called
▪ LOG_LOGIC: Log messages describing logical flow within a function
▪ LOG_ALL: Log everything mentioned above
▪ ns-3 also provides an unconditional logging macro that is always displayed
▪ NS_LOG_UNCOND
▪ Recall that myfirst.cc script contains the code below:
▪ We can increase the logging level and get more information without
changing the script and recompiling by setting the NS_LOG environment
variable like this:
60
▪ export NS_LOG=UdpEchoClientApplication=level_all
Brief tutorial
▪ Logging
▪ Now, let’s run myfirst.cc script again:
▪ You can see that additional debug information provided by the application
▪ Let's find out what log information UdpEchoClientApplication provides
▪ command finds every .cc (‘*.cc’) file from current directory (.)
find . –name ‘*.cc’
▪ The following command after pipeline (|) gets result of the find command as an
input and check if there is a word UdpEchoClientApplication in the input file
and display the word if it exists 61
Brief tutorial
▪ Logging
▪ If you search NS_LOG in the script using ctrl+F command, you can find
many logging code in it
62
Brief tutorial
▪ Logging
▪ From now, let's add logging code to myfirst script
▪ Open myfirst.cc script and then, add lnfo level logging code in line 43 (and save)
▪ build myfirst script again and reset the NS_LOG variable again
63
▪ You can see the log you just made!
Homework 3
Introduction
▪ Homework-3 is about the radio resource management
▪ In the environments where multiple APs are adjacent to each
other, APs may use the same channel due to the scarcity of
radio resource, giving severe contention and interference to
each other
▪ In this case, appropriate channel allocation and transmission
power control play important roles in making efficient use of
limited radio resources
▪ Let's evaluate the performance according to the radio
resource management, and gain insight through simulation
65
Simulation setting
▪ Downlink traffic rate: 70 Mbps
▪ Ideal rate control 2 3
▪ Problem 2
▪ With the default transmit power and scenario, find the channel
combination with the best throughput and the channel combination
with the worst throughput, and describe the results
67
Report
▪ Problem 3 2 3
▪ Problem 4
AP Station
▪ Find the best channel and power combination in the scenario 2, and
then describe the results
68
rrm.cc
▪ Usage
▪ Tunable parameters
69
rrm.cc
70
rrm.cc
71
rrm.cc
Node containers that contain APs and Stas
Positions of APs
72
rrm.cc
73
rrm.cc
YansWifiChannelHelper
helps you configure the
channel model
74
rrm.cc
Setting data rate control algorithm
and protocol of the AP
tx power allocation
75
rrm.cc
IP addresses assignment
76
rrm.cc