tnk092: network simulation - nätverkssimulering lecture #1: course basics and a first taste of ns2...
TRANSCRIPT
TNK092: Network Simulation - Nätverkssimulering
Lecture #1: Course basics and a first taste of NS2
Vangelis Angelakis Ph.D.
Basic Course Information
Examiner: Prof. Di Yuan Seminars: Dr. Vangelis Angelakis Labs: Ms. Qing He
6 ECTS, Load distribution: Lab assignments: 2/6 Project work: 4/6
Subscribe to the course mailing list!! Webpage at: www.itn.liu.se/~vanan11/TNK092
2
Lectures
1. Course basics and first NS2 steps.
2. Manipulating results and adding modules
3. TCP/IP in NS2
4. Routing and network Dynamics
5. Wireless Networking Simulation
6. Wired & Wireless
[sept. 21] backup lecture date.
3
[ aug. 28 ]
[ aug. 29 ]
[ aug. 31 ]
[ sept. 4 ]
[ sept. 5 ]
[ sept. 12 ]
Assignments & Lab sessions
1. Learning to handle NS2
2. Setting up a new module in NS2
3. TCP/IP
4. Wireless networking
4 (+1) Lab sessions: Give you assistance on given assignment The 2 first give you hints & the basic steps on
how to proceed with it what to expect
The 2 last expect you to have done most of the job by then
assistive role. At the end of a lab session you DELIVER the report on the previous lab assignment
i.e.: on the session of Tue. Sept. 11th, you are expected to deliver a report on the lab assignment discussed in the session
of Sept. the 4th.
4
[ sept. 4 ]
[ sept. 11 ]
[ oct. 2]
[oct. 16 ]
Lab Groups and Project Teams
For the Labs you MUST: Select a lab partner
DEADLINE:
TUESDAY, Sept. 4
5
I M P O R T A N T
Project
6
Implementation of (recent) research papers, with simulatory results
Available on the course webpage from Tuesday, Sept. 11th
By Tuesday SEP. 18 23:59 email the course list (+ me) stating:
The names of TWO (2) students forming a project group A list of 2-3 papers that the group is interested in IN ORDER OF PREFERENCE
Assignment of papers will be done in a first-come-first served manner,
BUT: Some groups may be assigned the same paper
Such groups MUST work separately Reports and codes of these groups will be compared to identify integrity issues.
Project Deliverables
7
1. Project PROPOSAL
By TUESDAY SEP. 30: NO extensions a brief summary identifying the paper’s KEY IDEA and the MAIN
RESULT a list of the key points to implement that will illustrate them a list of the key system parameters, as the ones contained in the paper
along with potential added assumptions
2. FINAL Report
By SUNDAY OCT. 21: NO extensions NS2 Implementation Written 5-page (double-column) report
If FAIL deadlines for project resubmission (retake): Jan. 20, 2013 Aug. 25, 2013
-Details on the course website
Other timeslots
1. lab time exceeding the assignments:One extra session [ Oct. 16]
2. Project tutorial sessions
on a project group need-to-do basis
i.e. BY EMAIL APPOINTMENT!
Sept 21: 8:15-10:15 Oct. 3: 17:15-19:15 Oct. 9: 13:15-17:15
Further tutorial may be arranged (upon availability only) by further email arrangements
8
Some resources
NS simulator for beginners:
http://www-sop.inria.fr/members/Eitan.Altman/ns.htm
http://www-sop.inria.fr/members/Eitan.Altman/COURS-NS/n3.pdf
NS by example:
http://nile.wpi.edu/NS/
The ns-2 wiki, user information: http://nsnam.isi.edu/nsnam/index.php/User_Information
Getting started with ns-2: http://nsnam.isi.edu/nsnam/index.php/Getting_Started_with_NS-2
9
Installation For Linux (Redhat, Ubuntu), FreeBSD, or other,
gcc needed download ns-allinone software package, unzip (tar) building ns from the sources (./install) remember the enviromental variables (.bashrc in your own directory)
For Windows using Vmware Player (Free)
will be the one used later on for the Lab download the ubuntu image for vmware, and install ns on your
linux system:
DETAILED INSTRUCTIONS ON THE COURSE WEB-PAGE using Cygwin (Free)
install Cygwin (www.cygwin.com), install all the packages if you don’t know which one you need instead of the defaut one
download nsallinonesoftware package, unzip (tar) to one directory build ns source (./install) remember the enviromental variable (.bashrc)
See Lab instructions or NS2 homepage for detailed information
10
NS2
Hello World! (hello.tcl)
set ns [new Simulator]$ns at 1 “puts \“Hello World!\”” $ns at 1.5 “exit”$ns run
$ $ ns hello.tclHello World!$ |
11
Tcl programming fundamentals 1/4
# This is a comment,the tcl interpreter will not “see” it
set b 0 assigns to b the value 0
set x $a assigns to variable ‘x’ the value of variable ‘a’ To use the value assigned to a variable, we use the $ sign
before the variable.
set x [expr $a + $b] A mathematical operation is done using the expr(ession)
command.
set myFilePtr [open my_filename w]
opens my_filename for writing and
gives you the pointer myFilePtr 12
Tcl programming fundamentals 2/4
puts $myFilePtr "text" each time the puts command is used, a new line is started. To avoid new line, one has to add -nonewline after puts Tabulating is done by inserting \t
puts "[expr 1/60]" will print ‘0’ on the screen In Tcl the variables have no specific type, so a variable can be
a string or an integer depending on the value you assign to it.
puts "[expr 1 .0/60 .0]" to get the correct result
exec xgraph data & Executes the unix program xgraph with input the file data.
the & is used for background running13
Tcl programming fundamentals 3/4
if { expression } {<execute some commands>
} else {<execute some commands>
} The “if” command can be nested with other “if”s and with
“else”s that can appear in the ”<execute some commands>” part
To test for equality, we use == For inequality, we use !=
for {set i 0} {$i < 5} {incr i} {<execute some commands>
}
14
Tcl programming fundamentals 4/4
proc blue { par1 par2 . . . } {global var1 var2<commands>return $something
}
This procedure is called by typing: blue x y in our tcl script
The values of x and y will be used by the procedure for par1 and par2. If par1 and par2 are changed within the procedure, this will not affect the values of x and y at the caller level (…“by value” argument passing)
On the other hand, if we wish the procedure to be able to affect directly variables external to it, we have to declare these variables as "global". In the above example these are var1 and var2
15
TCL basic #1
16
TCL basic #2
17
fmod: Return the remainder after
dividing expression x by expression y.
break: could be used here...
Notice there is a TCL commands wiki at:
http://wiki.tcl.tk/
Basic scripting: initialization & termination
1. Create a Simulator objectset ns [new Simulator]
18
3. The finish procedure:Flushing & closing the traces
proc finish{} { global ns trc_file nam_file $ns flush-trace close trc_file close nam_file exec nam out.nam & exit 0}
2. Output Traces:
set file1 [open out.tr w]$ns trace-all $trc_file
Data trace for all links
set file2 [open out.nam w]$ns nametrace-all $nam_file
Visual trace using the nam file format
Definition of nodes & links
Create nodes
set n0 [$ns node]
set n1 [$ns node]
Link the nodesFormat follows: duplex-link $n0 $n1 <bandwidth> <propdelay> <queue_type>
e.g.:$ns duplex-link $n0 $n1 1Mb 10ms
19
Definition of nodes & links: a simplex link
20
An example
Create nodes
21
Check: ns-default.tcl
Find there default value
Basic networking scripts
An ”automated” topology example
for {set i 0} {$i < 7} {incr i} { set n($i) [$ns node]
}
for {set i 0} {$i < 7} {incr i} { $ns duplex-link $n($i) $n([expr($i+1)%7]) 1Mb 10ms RED
}
22
Agents and applications
Creating Data Connections
TCP
set tcp [new Agent/TCP]
set tcpsink [new Agent/TCPSink]$ns attach-agent $n0 $tcp$ns attach-agent $n1 $tcpsink$ns connect $tcp $tcpsink
UDP
set udp [new Agent/UDP]
set null [new Agent/NULL]$ns attach-agent $n0 $udp$ns attach-agent $n1 $null$ns connect $udp $null
23
n1
n0
tcp/udp
sink
Basic Scripts
Generating Traffic FTP
set ftp [new Application/FTP]
$ftp attach-agent $tcp
Telnet
set telnet [new Application/Telnet]
$telnet attach-agent $tcp
CBRset src [new Application/Traffic/CBR]
Exponential, or Pareto on-off
set src [new Application/Traffic/Exponential]
set src [new Application/Traffic/Pareto]
.........
24
n1
n0
tcp
ftp
sink
Basic Scripts
Insert Link dynamics Creating Error Module
set loss_module[new ErrorModel]
$loss_moduleset rate_ 0.01$loss_moduleunit pkt$loss_module ranvar[new
RandomVariable/Uniform]$loss_moduledrop-target [new Agent/Null]
Inserting an Error Module$ns lossmodel $loss_module$n0 $n1
25
Basic Scripts
Schedule Events and Run Simulation Schedule Events
$ns at <time> <event>
<event>: any legitimate ns/tcl command
$ns at 0.5 “$cbr start”
$ns at 4.5 “$cbr stop”
Call ‘finish’
$ns at 5.0 “finish”
Run the simulation$ns run
26
Visualizing NAM
27
Remember this:
Visualizing NAM
28
Visualizing NAM
Nodes Color
$node color red
Shape (can’t be changed after simulation starts)$node shape box (circle, box, hexagon)
Label (single string)$ns at 1.1 “$n0 label \”web cache 0\””
29
Visualizing NAM
Links Color
$ns duplex-link-op $n0 $n1 color "green”
Label$ns duplex-link-op $n0 $n1 label “backbone"
30
Visualizing NAM
Layout “Manual” layout: specify everything
$ns duplex-link-op $n(0) $n(1) orient right
$ns duplex-link-op $n(1) $n(2) orient right$ns duplex-link-op $n(2) $n(3) orient right$ns duplex-link-op $n(3) $n(4) orient 60deg
If anything missing automatic layout
31
Example 1
32
Example 1
33
Example 2#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
34
#
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$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
#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
Visualizing NAM
35
Example 3#Create a simulator objectset ns [new Simulator]
#Define different colors for data flows
$ns color 1 Blue$ns color 2 Red
#Open the nam trace fileset nf [open out.nam w]$ns namtrace-all $nf
#Define a 'finish' procedureproc finish {} { global ns nf $ns flush-trace
#Close the trace file close $nf
#Execute nam on the trace file exec nam out.nam & exit 0}
#Create four nodesset n0 [$ns node]set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]
36
#Create links between the nodes$ns duplex-link $n0 $n2 1Mb 10ms DropTail$ns duplex-link $n1 $n2 1Mb 10ms DropTail$ns duplex-link $n3 $n2 1Mb 10ms SFQ
$ns duplex-link-op $n0 $n2 orient right-down$ns duplex-link-op $n1 $n2 orient right-up$ns duplex-link-op $n2 $n3 orient right
#Monitor the queue for the link between node 2 and node 3$ns duplex-link-op $n2 $n3 queuePos 0.5
#Create a UDP agent and attach it to node n0set udp0 [new Agent/UDP]$udp0 set class_ 1$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0set cbr0 [new Application/Traffic/CBR]$cbr0 set packetSize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0
Example 3#Create a UDP agent and attach it to node n1set udp1 [new Agent/UDP]$udp1 set class_ 2$ns attach-agent $n1 $udp1
# Create a CBR traffic source and attach it to udp1set cbr1 [new Application/Traffic/CBR]$cbr1 set packetSize_ 500$cbr1 set interval_ 0.005$cbr1 attach-agent $udp1
#Create a Null agent (a traffic sink) and attach it to node n3set null0 [new Agent/Null]$ns attach-agent $n3 $null0
#Connect the traffic sources with the traffic sink$ns connect $udp0 $null0 $ns connect $udp1 $null0
#Schedule events for the CBR agents$ns at 0.5 "$cbr0 start"$ns at 1.0 "$cbr1 start"$ns at 4.0 "$cbr1 stop"$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 37
38
Example 4
#Create a simulator objectset ns [new Simulator]
#Tell the simulator to use dynamic routing$ns rtproto DV
#Open the nam trace fileset nf [open out.nam w]$ns namtrace-all $nf
#Define a 'finish' procedureproc finish {} { global ns nf $ns flush-trace
#Close the trace file close $nf
#Execute nam on the trace file exec nam out.nam & exit 0}
#Create seven nodesfor {set i 0} {$i < 7} {incr i} { set n($i) [$ns node]}
#Create links between the nodesfor {set i 0} {$i < 7} {incr i} { $ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail}
39
#Create links between the nodesfor {set i 0} {$i < 7} {incr i} {$ns duplex-link $n($i) $n([expr($i+1)%7]) 1Mb 10ms DropTail}
#Create a UDP agent and attach it to node n(0)set udp0 [new Agent/UDP]$ns attach-agent $n(0) $udp0
# Create a CBR traffic source and attach it to udp0set cbr0 [new Application/Traffic/CBR]$cbr0 set packetSize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) #and attach it to node n(3)set null0 [new Agent/Null]$ns attach-agent $n(3) $null0
#Connect the traffic source with the traffic sink$ns connect $udp0 $null0
#Schedule events for the CBR agent # and the network dynamics$ns at 0.5 "$cbr0 start"$ns rtmodel-at 1.0 down $n(1) $n(2)$ns rtmodel-at 2.0 up $n(1) $n(2)$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
40