0% found this document useful (0 votes)
30 views

ns3 Lecture Notes

ns3 lecture notes

Uploaded by

james010401
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

ns3 Lecture Notes

ns3 lecture notes

Uploaded by

james010401
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 78

ns-3 simulator

Data communications

Mobile Computing & Communications Lab.


SNU
Outline
▪ Introduction (slide 3)

▪ Installation (slide 5)
▪ Starting with Ubuntu installation (slide 6)
▪ Starting with ns-3 installation (slide 30)

▪ Brief tutorial (slide 49)

▪ Homework-3 (slide 64)

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

▪ Enter y, if the question below appears

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

Congratulations! You are now an ns-3 user

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

▪ In this lecture, we will study one tutorial script


▪ Let’s open the first.cc with a sublime text (or with your favorite editor)
subl first.cc

Note: ls (list segment), allows to list directory


subl (sublime text), open file or directory with the sublime text editor
50
Brief tutorial
▪ first.cc
▪ Module includes

▪ ns-3 provides many modules to make it much easier for users to


write simulation scripts
▪ Each of the ns-3 include files is placed in a /build/include/ns3 directory
▪ You can take a look at the contents of these files

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

▪ This line declares a logging component called FirstScriptExample that


allows you to enable and disable console message logging by
reference to the name
▪ Details about logging are discussed later
▪ Time resolution setting

▪ This line sets the time resolution to one nanosecond


▪ The resolution is the smallest time value that can be represented
52
Brief tutorial
▪ first.cc
▪ Enable two logging components

▪ 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

▪ The NodeContainer topology helper provides a convenient way to


create, manage and access any Node objects
▪ PointToPointHelper

▪ The first line instantiates a PointToPoint Helper object to configure and


connect PointToPointNetDevice and PointToPointChannel objects
▪ The second line tells the PointToPointHelper object to use the value
“5Mbps” as the “DataRate” when it creates a PointToPointNetDevice object 53
Brief tutorial
▪ first.cc
▪ The third line tells the PointToPoint Helper to use the value “2ms” as the
value of the propagation delay of when it creates PointToPointChannel
▪ NetDeivceContainer

▪ The Install method of the PointToPoint Helper takes a NodeContainer as a


parameter, and creates NetDeviceContainer
▪ For each node in the NodeContainer a PointToPointNetDevice is created
▪ A PointToPointChannel is created and the two PointToPointNetDevices are
attached
▪ After executing the PointToPoint.Install (nodes) call, we will have two
nodes, each with an installed point-to-point net device and a single
point-to-point channel between them
▪ InternetStackHelper

▪ 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

▪ We need to associate the devices on our nodes with IP addresses


▪ The code above declares an address helper object and tell it that it
should begin allocating IP addresses from the network 10.1.1.0 using
the mask 255.255.255.0

▪ address.Assign performs the address assignment


▪ It makes the association between an IP address and a device using an
Ipv4Interface object
▪ To contain a list of Ipv4Interface objects for future reference, we use
Ipv4InterfaceContainer

55
Brief tutorial
▪ first.cc
▪ UdpEchoServerHelper

▪ The first line, declares an UdpEchoServerHelper and gets a port


number 9 as a parameter
▪ The Install method takes a NodeContainter as a parameter just as the
other Install methods
▪ Install will return a container that holds pointers to all of the
applications created by the helper
▪ Applications require a time to “start” and may take an optional time to
“stop”
▪ We set the echo server application to Start (enable itself) at one
second into the simulation and to Stop (disable itself) at ten seconds
into the simulation.

56
Brief tutorial
▪ first.cc
▪ UdpEchoClientHelper

▪ The first line, declares an UdpEchoClientHelper and gets IP address


and port number of the server as a parameter
▪ Recall that we used an Ipv4InterfaceContainer to keep track of the IP
addresses we assigned to our devices
▪ SetAttribute
▪ MaxPackets: maximum number of packets we allow client to send
▪ Interval: it tells the client how long to wait between packets
▪ PacketSize: it tells how large client’s packet payloads should be
▪ As with the UdpServer case, we set the start and end times for the
UdpClient application
57
Brief tutorial
▪ first.cc
▪ Simulator
▪ Running the simulation is done by using the global function Simulator::Run

▪ Recall that we scheduled events in the 1, 2 and 10 seconds


(with UdpEcho Client & Server applications)
▪ When Simulator::Run is called, the system will begin looking through the
list of scheduled events and
▪ The act of sending the packet to the server will trigger a chain of
events that will be automatically scheduled executing them
▪ When there are no further events to process, Simulator::Run returns

▪ Finally, Simulator::Destroy calls will deal with the hard part of


destroying all created objects

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

▪ Then, build your first example script using ns3:

▪ You can now run the example:

▪ 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

▪ The result shows that UdpEchoClientApplication log component is defined


in ./src/applications/model/udp-echo-client.cc. Lets take a look at the file:

▪ 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

▪ Recall that myfirst.cc log component is defined as FirstScriptExample


▪ Enable the FirstScriptExample logging level into LOG_INFO and run the script:

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

☞ This is not a programming homework

65
Simulation setting
▪ Downlink traffic rate: 70 Mbps
▪ Ideal rate control 2 3

▪ Dual slope path loss channel model


▪ 4 APs and 1 associate station per AP
▪ Available channel number = {1, 5, 9}
▪ Default transmission power = 20 dBm
0 1
▪ Simulation time: 1 second
▪ Metric: Average throughput for all APs
(Mbps)
AP Station

• The number above the AP indicates


the index of the AP (ex. 0 for AP0)

► Source code can be obtained from ETL


(Place the script file in the scratch directory)
66
Report
▪ Problem 1
▪ With the default channel and scenario, compare and explain the
simulation results when the transmit power are 10 dBm, 20dBm, and 30
dBm

▪ 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

▪ Change the number of associated stations as


shown in the right figure, {3, 2, 1, 1}, and
find the best channel combination with the
default transmit power and scenario 0 1

▪ 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

Random seed setting to get the same


results on different computers

The number of APs

Default values of tunable parameters.


channelNumbers will be parsed later

Get parameter values from the command


line and log with NS_LOG_UNCOND

70
rrm.cc

Parse channel numbers and assign them to an array

scenario 1: 1 station (STA) per AP


scenario 2: AP0, AP1, AP2, and AP3 are associated
with 3, 2, 1, and 1 STAs, respectively

UDP packet size: 700 bytes

71
rrm.cc
Node containers that contain APs and Stas

Creates APs and STAs nodes

staVec is used to divide the created STAs


according to the associated APs

The position does not change after assignment

Positions of APs

UDP packet size: 700 bytes

72
rrm.cc

The position of the STA is determined by the


uniform distribution around the associated APs.

The code snippet here actually installs


the nodes in the assigned positions.

UDP packet size: 700 bytes

73
rrm.cc

YansWifiChannelHelper
helps you configure the
channel model

Propagation speed is the speed of light


and the path loss model has two slopes

Install InternetProtocolStack on nodes and


set base of IP address and subnet mask
You can regard the NetDevice as a
network interface card

74
rrm.cc
Setting data rate control algorithm
and protocol of the AP

Setting service set identifier (SSID) of the AP

tx power allocation

Channel allocation (channel, bandwidth, band, i)


i: index of the center frequency(related with channel bonding )

Associates Wi-Fi channel with the NetDevices


No probe request

75
rrm.cc
IP addresses assignment

Install applications that generate traffics at a constant rate

76
rrm.cc

Starts the simulation

Throughput calculation using the number of


received packets during the simulation
▪ Q&A
[email protected]
Starts the simulation

Throughput calculation using the number of


received packets during the simulation

You might also like