Top Banner
Simulation with NS-2 and CPN tools Ying-Dar Lin Department of Computer Science, National Chiao Tung University
26

Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

May 01, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

Simulation with NS-2 and CPN tools

Ying-Dar LinDepartment of Computer Science,National Chiao Tung University

Page 2: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

2

Outline

NS-2 simulatorNS-2 basicsBasic syntaxTracing a simple networkMini and term projects

CPN toolsTerminology and operation of CPN toolsInterface of CPN toolsMini and term projects

Page 3: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

3

A brief introduction to NS-2An event simulator for network researchSupport for simulation of TCP, routing, multicast, etc.Have a C++ (simulator) and Object Tcl (OTcl) interpreter

“NS by Example”, Jae Chung and Mark Claypool

User view of NS-2

Page 4: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

4

Class hierarchy in NS-2

C++ implementationfor efficiency in simulationdetailed definition and operation of protocols

OTcl scriptdescription of topology, protocols and applicationsSpecification of the output form

Page 5: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

5

Initialization and termination(1/2)

Initializationset ns [new Simulator]

Opening trace and visualization filesset tracefile1 [open out.tr w]$ns trace-all $tracefile1set namfile [open out.nam w]$ns namtrace-all $namfile

A new variable

Instantiation of class Simulator

Page 6: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

6

Initialization and termination(2/2)

Terminationproc finish {} {

global ns tracefile1 namfile$ns flushtraceclose $tracefile1close $namfileexec nam out.nam &exit 0

}$ns at 125.0 “finish”

Start simulation$ns run

declaration outside the procedure

dump the trace

execute nam for visualization

schedule “finish” at time 125 sec

Page 7: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

7

Definition of a simple network

$n0 $n1 $n2 $n3

1 Mbps10 ms

300 kbps100 ms

2 Mbps5 ms

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

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

$ns simplex-link $n1 $n2 0.3Mb 100ms DropTail

$ns simplex-link $n2 $n1 0.5Mb 50ms DropTail

$ns duplex-link $n2 $n3 2Mb 5ms DropTail

$ns queue-limit $n1 $n2 10 assign queue size (default: 50)

queue management

DropTailREDFQSFQCBQ

500 kbps50 ms

Page 8: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

8

Simulation of FTP over TCP

set tcp [new Agent/TCP]$ns attach-agent $n0 $tcpset sink [new Agent/TCPSink]$ns attach-agent $n4 $sink$ns connect $tcp $sink$tcp set fid_ 1$tcp set packetSize_ 552set ftp [new Application/FTP]$ftp attach-agent $tcp

$ns at 1.0 “ftp start”$ns at 124.0 “ftp stop”

$n0 $n1 $n2 $n3

1 Mbps10 ms

300 kbps100 ms

2 Mbps5 mssource sink

define source

define sink

default:1000set flow id to 1

500 kbps50 ms

Page 9: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

9

Visualization using namGive node position$ns duplex-link-op $no $n2 orient right-downSet color$ns color 1 BlueColor nodes$n0 color redColor links$ns duplex-link-op $n0 $n2 color “green”Add and remove marks$ns at 2.0 “$n2 add-mark m3 blue box”$ns at 30.0 “$n2 delete-mark m3”Add label$ns at 1.2 “$n2 label \”active node\””$ns duplex-link-op $n1 label “TCP input link”Add text$ns at 5 “$ns trace-annotate \”packet drop\””Monitor queue size$ns simplex-link-op $n1 $n2 queuePos 0.5

Page 10: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

10

Tracing

EnqT Queue DeqT Delay TTL RecvT

DrpT Agent/Nulldrop

components for simulation

components for tracing

simplex link

Event Time Fromnode

Tonode

Pkttype

Pktsize Flags Fid Src

addrDstaddr

Seqnum

Pktid

Fields in the trace

Page 11: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

11

Mini-project: TCP simulation 1. Download and install the NS-2 simulator at

http://www.isi.edu/nsnam/ns/ns-build.htmlWe suggest to download the all-in-one version to save your time

2. Refer to the document of “NS simulator for beginners”. Prepare the Tcl script in Table 2.4 “ex1.tcl”.

3. Set up a loss module between $n2 and $n3 (See the code in page 42-43)

4. Set up the parameters as indicated in the questions of the project

(Note: the configuration in each question of the mini-project and term project is tried independently, meaning that you will restore the original configuration after each question and set the configuration as requested in the next.)

Page 12: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

12

Mini-project: questions1. Tune the loss rate between n2 and n3 to 0%, 10% and

20%. See the changes in TCP throughput.2. Increase the UDP traffic (n1 to n5) from 0.01Mb/s to

0.1Mb/s. How is the TCP traffic affected in terms of window size (or throughput)?

3. Add one more link n6 n2. Set three nodes (n0, n1 and n6) to be TCP sources. Compare the window sizes when the queue mechanism is DropTail and RED.

4. Explain your observation in the above questions according to the flow control and congestion control of TCP.

ps. You may set the parameters at will if they are unspecified in the questions.

Page 13: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

13

Term project: random early discardPlease refer to these references when doing this term project.

S. Floyd and V. Jacobson, “Random Early Detection Gateways for Congestion Avoidance,” IEEE/ACM Trans. Networking, vol. 1, no. 4, Aug 1993.RED Queue Management,http://www.icir.org/floyd/red.htmlChapter 6, NS simulator for beginners, http://www-sop.inria.fr/maestro/personnel/Eitan.Altman/COURS-NS/n3.pdf

Build the simulation model of “Drop tail buffer” and “RED buffer” as listed in Table 6.1 and Table 6.2.

Simulation model for this project

10 Mbps, 1ms delay 700 kbps,

20ms delayFTP

Page 14: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

14

Term project: questions1. Repeat the experiments as indicated in Fig. 6.3 and

Fig. 6.6. Make sure your models coincide with their results.

2. Add one more UDP link to n2 as described in Table 2.4 “ex1.tcl”. How does the UDP traffic affect the window size in DropTail and RED?

3. Suppose one of the links from S(i) to n2 is upgraded to 100Mb/s. How will the other links to n2 (10 Mb/s) affected (in terms of window size)?

4. How about one source S[i] with RED rather than DropTail (Change from DropTail to RED in one of the duplex-links from s(i) to n2)?

5. Design your reconfiguration of the model. Tell why you have the reconfiguration and what you want to watch.

Page 15: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

15

Important references

Homepage of NS-2 simulatorhttp://www.isi.edu/nsnam/ns/

NS simulator for beginnershttp://www-sop.inria.fr/maestro/personnel/Eitan.Altman/COURS-NS/n3.pdf

Tutorial for the network simulator “ns”http://www.isi.edu/nsnam/ns/tutorial/index.html

Page 16: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

16

What is Colored Petri Nets (CPN) tools?

A graphical modeling language to build an executable model.For design, specification, simulation and verification systems.Typical target applications (distributed systems with communication and synchronization)

Communication protocolsData networksDistributed algorithmsEmbedded systemsWorkflow modelingAgent systems

Page 17: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

17

Terminology in CPN modeling

transition/event

place/state

arc

inscription

marking(tokens/token values (colors))

states of network

states of sender

states of receiver

initial marking

Page 18: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

18

Transitions

Packetsto

Send

SendPacket

NextSend

(n,d)

n

1`1

1`(1,”COL”)++2`(2,”OUR”)++…

n is bound to 1

n is bound to 1d is bound to “COL”

initial marking

initial marking

Transition enabled

ps. the marking in both places are unchanged due to the double-headed arcs

i.e., retransmission is possible

A(n,d) The token (1,”COL”)

also goes to place A (i.e., the network)

Page 19: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

19

An example of transitions

step 0step 1step 2step 3step 4step 5step 6step 7step 8step 9

Page 20: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

20

Basic syntax in CPN tools

Data Type (color set)colset DATA = string;colset NOxDATA = product NO * DATA;

Multi-setSix packets: 1`(1,"COL")++1`(2,"OUR")++1`(3,"ED ")++1`(4,"PET")++1`(5,"RI ")++1`(6,"NET")‘: number of appearances of some element++: Union of two multi-sets

Page 21: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

21

Interface of CPN tools

Index

Binder(A set of sheets

in the tabs)

Page 22: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

22

Installation of CPN toolsDownload the CPN tools from the Web site: http://www.daimi.au.dk/~cpntools/bin/license/cpntools_setup.php

username: pclin_cis_nctu_edu_twpassword: JSG8304

Install the tool in the Windows (note: your computer must support OpenGL to run CPN tools.Read “Getting started with CPN tools” after installationhttp://wiki.daimi.au.dk/cpntools-help/getting_started_with_cpn_.wiki

Page 23: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

23

Mini project: simple protocol1. Launch CPN tools2. Load the net from <installation

path>/Samples/SimpleProtocol/SimpleProtocol.cpn3. Drag the “simulation palette” from Toolbox Simulation to

the workspace. (See the “Tool box” section from ““Getting started with CPN tools”)

4. Press the button of “Executes a transition”, move the mouse cursor to the binder of the Net, and Click on it.

5. Click again and again. See how the tokens are moved in the net.

simulation palette

executes a transition

Page 24: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

24

Mini project: questions1. What token will Place A receive after the

first transition? Explain why.2. How does the network guarantee the

packets are transmitted in order?3. Modify the model of simple protocol so that

the sender can send two packets (tokens) before receiving a ACK, but the receiver responds with a ACK for every packet.

4. (optional/bonus) Design a model to simulate UDP transmission without a ACK.

Page 25: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

25

Term project: dining philosophers

Load and execute the CPN of dining philosophers under <installation path>/Samples/DiningPhilosophers/DiningPhilosophers_COMM_Mon.cpnCheck whether a deadlock will occur in this model. If a deadlock occurs, please explain how.

Page 26: Simulation with NS-2 and CPN toolsspeed.cis.nctu.edu.tw/~ydlin/course/cn/nsd2009/Simulation.pdf · 1. Tune the loss rate between n2 and n3 to 0%, 10% and 20%. See the changes in TCP

26

Important references

Homepage of CPN toolshttp://wiki.daimi.au.dk/cpntools/cpntools.wikihttp://www.informatik.uni-hamburg.de/TGI/PetriNets/http://www.daimi.au.dk/designCPN/