Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 44

1

DAY 1
SESSION 1

12/08/2021 Xavier’s Institute of Engineering, Mumbai


Session 1 Plan
2

 Basics of Linux
 Introduction to NS-2
 Installation of NS-2
 Simulation System Architecture
 NS-2 Directory Structure
 First Simulation Scenario
 Simulation Script
 Running Simulation
 Flow of Simulation
 Structure of Animation Window
 Second Simulation Scenario
 Orientation of Nodes

12/08/2021
Basics of Linux (1)
3

 Introduction to Linux Environment


 Use of Text editor and terminal
 Basic Linux Commands
 cd : change directory
 Syntax: cd directoryname
 ls : list the files in current directory
 Syntax: ls
 rm : Remove a file from directory
 Syntax: rm filename
 cp : Copy the file to specific directory
 Syntax: cp filename direcroryname

12/08/2021
Basics of Linux (2)
4

 Basic Linux Commands (contd…)


 pwd: For checking current directory
 Syntax: pwd
 ps: For viewing currently running processes on system
 Syntax: ps
 kill: For killing a process
 Syntax: kill processid
 cat: For viewing file contents on terminal
 Syntax: cat filename

12/08/2021
Basics of Linux (3)
5

 Basic Linux Command (contd…)


 gcc: For compliling c and c++ programs.
 Syntax: gcc programname.c
 gedit: Create and open the file in text editor.
 Syntax: gedit filename
 ./ : For running object file.
 Syntax: ./ objectfilename

12/08/2021
Introduction to NS-2
6

 Object Oriented simulator


 Work at packet level
 Widely used in research community
 Use two languages
 TCL
 C++

12/08/2021
Simulation System Architecture
7

NS-2 Shell Simulation Trace files


Results
-------- (.tr)
-------- Otcl : TCL Interpreter with --------
--------
OO Extension --------
-------- --------
-------- --------
-------- --------
-------- --------
-------- --------
--------
Otcl Script
NS Simulator Library
--------
--------
--------
--------
Animation
File (.nam)

12/08/2021
Installation of NS-2 (1)
8

 Installation on Linux
 Copy ns-allinone-2.34.tar_1.gz into /usr/local folder.
 Extract ns-allinone-2.34.tar_1.gz, you will get ns-
allinone-2.34.tar_1.
 Extract ns-allinone-2.34.tar_1, you will get ns-
allinone-2.34 folder
 Go to ns-allinone-2.34 folder and say ./install.
 After installation go to ns-2.34 folder in ns-allinone-
2.34 and say ./validate.

12/08/2021
Installation of NS-2 (2)
9

 Bash file setting


 Open Terminal
 Type on terminal following command
 gedit ~/.bashrc
 Add the TCL library, LD library and ns library path
in .bashrc file.
 Save the changes
 Type on terminal following comand
 source ~/.bashrc
Bash Setting
12/08/2021
NS-2 Directory Structure
10

ns-allinone

Tcl8.0 TK8.0 OTcl tclcl ns-2 nam-1

tcl ... C++ code

ex test lib mcast ...

examples validation tests


OTcl code

12/08/2021
First Simulation Scenario
11

CB
R

UD NUL
P L
Node 1 Mb, 10ms Node
0 1

12/08/2021
Simulation Script (1)
12

#Create a simulator object Other Simulator Commands


set ns [new Simulator]
#Open the nam trace file Other Trace Commands
set nf [open s1.nam w]
$ns namtrace-all $nf
#Open the event trace file
set nf1 [open s1.tr w]
$ns trace-all $nf1

12/08/2021
Simulation Script (2)
13

#Define a 'finish' procedure


 proc finish { }
{
global ns nf nf1
$ns flush-trace
#Close the nam trace file
close $nf
#Close the event trace file
close $nf1
#Execute nam
exec nam s1.nam &
exit 0
}

12/08/2021
Simulation Script (3)
14

# Create two nodes Node Commands


set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes Link Commands
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Create a UDP agent
set udp0 [new Agent/UDP]
#Attach udp agent to node n0
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

12/08/2021
Simulation Script (4)
15

#Create a Null agent (a traffic sink) and attach it to node n1


set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 “finish”
#Run the simulation
$ns run Full Simulation Script
1
12/08/2021
Running the Simulation Script
16

 Save the simulation script in specific folder.


 Open the terminal and go up to specific folder.
 Run the simulation script,
 ns: command to run simulation script.
 Syntax: ns filename.tcl
 e.g. ns First_script_wired.tcl
 Run the nam file,
 nam: command to run animation file
 Syntax: nam filename.nam
 e.g. nam s1.nam

12/08/2021
Flow of Simulation (NS-Node)
17

n0 n1

Port Port
Classifier Classifier
Addr Addr
Classifier Classifier
0 dmux_ 1 dmux_
entry_ 1 entry_ 0
classifier_ classifier_

set n0 [$ns node]


set n1 [$ns node]
12/08/2021
Flow of Simulation(Network Topology – Link)

18

n0 n1

n1 entry_

head_
rcv
enqT_ queue_ deqT_ link_ ttl_
T_

drophead_ drpT_

$ns duplex-link $n0 $n1 1Mb 10ms DropTail


12/08/2021
Flow of Simulation (Routing)
19

n0 n1

Port Port
Classifier Classifier
Addr Addr
Classifier Classifier
0 dmux_ 1 dmux_
Link n0-n1
entry_ 1 entry_ 0
classifier_ classifier_

Link n1-n0

12/08/2021
Flow of Simulation (Transport)
20

n0 n1

Port Port
Classifier dst_=1.0 Classifier dst_=0.0
Addr Agent/TCP Addr Agent/TCPSink
0 0
Classifier Classifier
agents_ agents_
0 dmux_ 1 dmux_
Link n0-n1
entry_ 1 entry_ 0
classifier_ classifier_

Link n1-n0
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp 12/08/2021
Flow of Simulation (Application)
21

n0 n1

Port Application/FTP Port


Classifier Classifier
Addr Agent/TCP Addr Agent/TCPSink
0 0
Classifier Classifier
agents_ agents_
0 dmux_ 1 dmux_
Link n0-n1
entry_ 1 entry_ 0
classifier_ classifier_

Link n1-n0
set ftp [new Application/FTP]
$tcp attach-agent $ftp 12/08/2021
Flow of Simulation (Packet Flow)
22

n0 n1

Port Application/FTP Port


Classifier dst_=1.0 Classifier dst_=0.0
Addr Agent/TCP Addr Agent/TCPSink
0 0
Classifier Classifier
0 1
Link n0-n1
entry_ 1 entry_ 0

Link n1-n0

12/08/2021
Structure of Animation Window
23

12/08/2021
Second Simulation Scenario
24

FTP TCP 0 4 TCPSin


2 Mb, 10ms
0.5 Mb, 40ms k
0.3 Mb, 100ms
2 3

2 Mb, 10ms 0.5 Mb, 30ms


CB UD 1 5 Null
R P

12/08/2021
Simulation Script 2 (1)
25

# Create Simulator Object


set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Event trace files
set file1 [open out.tr w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
12/08/2021
Simulation Script 2 (2)
26

#Define a 'finish' procedure


proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0 }
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
12/08/2021
Simulation Script 2 (3)
27

#Label to the node n1 and node n2


$ns at 0.1 "$n1 label \"CBR\""
$ns at 1.0 "$n0 label \"FTP\“”
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
12/08/2021
Simulation Script 2 (4)
28

#Give node position (for NAM) Node Orientation


$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns simplex-link-op $n2 $n3 orient right
$ns simplex-link-op $n3 $n2 orient left
$ns duplex-link-op $n3 $n4 orient right-up
$ns duplex-link-op $n3 $n5 orient right-down
#Set Queue Size of link (n2-n3) to 40
$ns queue-limit $n2 $n3 40
12/08/2021
Simulation Script 2 (5)
29

#Setup a TCP connection


set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP

12/08/2021
Simulation Script 2 (6)
30

#Setup a UDP connection


set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false

12/08/2021
Simulation Script 2 (7)
31

# Scheduling the event


$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 624.0 "$ftp stop"
$ns at 624.5 "$cbr stop“
# Trace Congestion Window and RTT
set file [open cwnd_rtt.tr w]
$tcp attach $file
$tcp trace cwnd_
$tcp trace rtt_
# Call finish procedure
$ns at 625.0 “finish”
# Run the simulation Full Simulation Script 2
$ns run
12/08/2021
Node Orientation
32

Up
Left-Up Right-
Up

Lef Node Righ


t t

Left-Down Right-Down
Down

Back

12/08/2021
40

DAY 1
SESSION 2
12/08/2021 Xavier’s Institute of Engineering, Mumbai
Session 2 Plan
41

 Third Simulation Scenario


 Error Model
 Queue Types
 TCP and UDP Parameters
 TCP Agents
 Other Application Agents
 Practice and Assignments

12/08/2021
Third Simulation Scenario (1)
42

FTP
TCPSin
0.5 Mb, 30ms
2 Mb, 10ms k
0 1 6 8
2 Mb, 10ms
TCP 0.5 Mb, 40ms

0.3 Mb, 100ms


4 5

2 Mb, 10ms 0.5 Mb, 30ms


UD 2 3 7 9
2 Mb, 10ms
P 0.5 Mb, 30ms

Null

CB
R
12/08/2021
Third Simulation Scenario (2)
43

# Create Simulator Object


set ns [new Simulator]
#Define different colours for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Event trace files
set file1 [open out.tr w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
12/08/2021
Third Simulation Scenario (3)
44

# Define a 'finish' procedure


proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0 }
#Create ten nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set n6 [$ns node]
set n7 [$ns node]
set n8 [$ns node]
set n9 [$ns node] 12/08/2021
Third Simulation Scenario (4)
45

#Label to the node n1 and node n2


$ns at 0.1 "$n1 label \"CBR\""
$ns at 1.0 "$n0 label \"FTP\“”
#Create links between the nodes Queue Types
$ns duplex-link $n0 $n1 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 2Mb 10ms DropTail
$ns duplex-link $n1 $n4 2Mb 10ms DropTail
$ns duplex-link $n3 $n4 2Mb 10ms DropTail
$ns simplex-link $n4 $n5 0.3Mb 100ms DropTail
$ns simplex-link $n5 $n4 0.3Mb 100ms DropTail
$ns duplex-link $n5 $n6 0.5Mb 40ms DropTail
$ns duplex-link $n6 $n8 0.5Mb 40ms DropTail
$ns duplex-link $n5 $n7 0.5Mb 30ms DropTail
$ns duplex-link $n7 $n9 0.5Mb 30ms DropTail
12/08/2021
Third Simulation Scenario (5)
46

#Set Queue Size of link (n4-n5) to 10


$ns queue-limit $n4 $n5 10
#Set error model on link n4 to n5. Error Models

set loss_module [new ErrorModel]


$loss_module set rate_ 0.2
$loss_module ranvar [new RandomVariable/Uniform]
$loss_module drop-target [new Agent/Null]
$ns lossmodel $loss_module $n4 $n5

12/08/2021
Third Simulation Scenario (6)
47

#Setup a TCP connection TCP Other Agents


set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n8 $sink
$ns connect $tcp $sink TCP Parameters
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection Other Application Agents
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
12/08/2021
Third Simulation Scenario (7)
48

#Setup a UDP connection


set udp [new Agent/UDP]
$ns attach-agent $n2 $udp
set null [new Agent/Null]
$ns attach-agent $n9 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
12/08/2021
Third Simulation Scenario (8)
49

# Scheduling the event


$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 624.0 "$ftp stop"
$ns at 624.5 "$cbr stop“
# Trace Congestion Window and RTT
set file [open cwnd_rtt.tr w]
$tcp attach $file
$tcp trace cwnd_
$tcp trace rtt_
# Call finish procedure
$ns at 625.0 “finish”
# Run the simulation
Full_Simulation_Script
$ns run 3
12/08/2021
Assignment and Practice (1)
58

 Task 1

FTP TCP 0 1 2 3

4 5 6 7

8 9 10 11 TCPSink

12/08/2021
Assignment and Practice (2)
59

 Task 2
 Design Bus, Ring and Mesh Topology of 10 nodes.
Create TCP traffic from node0 to node9.
 Do assignments in group of 3 or 4.

12/08/2021

You might also like