Nodes

advertisement
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.
2.
3.
4.
5.
6.
Course basics and first NS2 steps.
Manipulating results and adding modules
TCP/IP in NS2
Routing and network Dynamics
Wireless Networking Simulation
Wired & Wireless
[ aug. 28 ]
[ aug. 29 ]
[ aug. 31 ]
[ sept. 4 ]
[ sept. 5 ]
[ sept. 12 ]
[sept. 21] backup lecture date.
3
Assignments & Lab sessions
1.
2.
3.
4.
Learning to handle NS2
Setting up a new module in NS2
TCP/IP
Wireless networking
[ sept. 4 ]
[ sept. 11 ]
[ oct. 2]
[oct. 16 ]
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
4
of Sept. the 4th.
Lab Groups and Project Teams
IMPORTANT
 For the Labs you MUST:
 Select a lab partner
 DEADLINE:
TUESDAY, Sept. 4
5
Project
 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.
6
Project Deliverables
-Details on the course website
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
7
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
$ns
$ns
ns [new Simulator]
at 1 “puts \“Hello World!\””
at 1.5 “exit”
run
$
$ ns hello.tcl
Hello World!
$ |
11
Tcl programming fundamentals 1/4

# This is a comment,the tcl interpreter will not “see” it

set b 0

set x $a

assigns to b the value 0
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]"

exec xgraph data &
to get the correct result
Executes the unix program
xgraph with input the file data.
the & is used for background running
13
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
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/
17
Basic scripting: initialization & termination
1. Create a Simulator object
3. The finish procedure:
set ns [new Simulator]
Flushing & closing the traces
2. Output Traces:
proc finish{} {
global ns trc_file nam_file
$ns flush-trace
close trc_file
close nam_file
exec nam out.nam &
exit 0
}
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
18
Definition of nodes & links

Create nodes
set n0 [$ns node]
set n1 [$ns node]

Link the nodes
Format 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
Check: ns-default.tcl
Find there default value
21
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/udp

TCP
set
set
$ns
$ns
$ns

tcp [new Agent/TCP]
tcpsink [new Agent/TCPSink]
attach-agent $n0 $tcp
attach-agent $n1 $tcpsink
connect $tcp $tcpsink
n1
UDP
set
set
$ns
$ns
$ns
n0
udp [new Agent/UDP]
null [new Agent/NULL]
attach-agent $n0 $udp
attach-agent $n1 $null
connect $udp $null
sink
23
Basic Scripts

Generating Traffic

FTP
set ftp [new Application/FTP]
$ftp attach-agent $tcp

Telnet
set telnet [new Application/Telnet]
$telnet attach-agent $tcp

CBR
set src [new Application/Traffic/CBR]

Exponential, or Pareto on-off
ftp
tcp
n0
n1
sink
set src [new Application/Traffic/Exponential]
set src [new Application/Traffic/Pareto]
.........
24
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

Remember this:
27
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
$ns
$ns
$ns

duplex-link-op
duplex-link-op
duplex-link-op
duplex-link-op
$n(0)
$n(1)
$n(2)
$n(3)
$n(1)
$n(2)
$n(3)
$n(4)
orient
orient
orient
orient
right
right
right
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
#
#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
34
Visualizing NAM
35
Example 3
#Create a simulator object
set ns [new Simulator]
#Define different colors for data
flows
$ns color 1 Blue
$ns color 2 Red
#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 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 n0
set udp0 [new Agent/UDP]
$udp0 set class_ 1
$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 four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
36
Example 3
#Create a UDP agent and attach it to node n1
set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1
# Create a CBR traffic source and attach it to udp1
set 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 n3
set 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 object
set ns [new Simulator]
#Tell the simulator to use dynamic routing
$ns rtproto DV
#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 seven nodes
for {set i 0} {$i < 7} {incr i} {
set n($i) [$ns node]
}
#Create links between the nodes
for {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 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 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
#Create links between the nodes
$ns run
for {set i 0} {$i < 7} {incr i} {
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}
39
40
Download