ns2 – tcp/ip simulation

28
NS2 – TCP/IP Sim ulation How-Wei Wu How-Wei Wu

Upload: cally-camacho

Post on 13-Mar-2016

63 views

Category:

Documents


3 download

DESCRIPTION

NS2 – TCP/IP Simulation. How-Wei Wu. 網際網路所提供的傳輸服務. 目前網際網路所提供的傳輸服務,就服務的性質而言可分成兩種 : (1) 連接導向的可靠性傳輸服務 (Connection oriented reliable service) ,這個服務主要由 TCP (Transmission Control Protocol) 來提供。 - PowerPoint PPT Presentation

TRANSCRIPT

  • NS2 TCP/IP SimulationHow-Wei Wu

  • : (1) (Connection oriented reliable service)TCP (Transmission Control Protocol) (2) (Connection-less, unreliable data transfer)UDP (User Datagram Protocol)

  • TCP

    1. (Reliable data transfer)TCP (Acknowledge)

    2. (Flow control)

    3. (Congestion control)

  • UDP TCPUDPIPTCPClientServerUDPTCPUDP

  • (Internet protocol stack)

  • Internet protocol stack

  • End-to-End TCPUDP

  • Ns-2Ns-2ns-default.tclns-allinone-2.XX/ns-2.XX/tcl/lib/Ns-2 $ cd ns-allinone-2.31/ns-2.31/tcl/lib/ $ cat ns-default.tcl | more

  • Ns-2Node(Host)(Router)(Switch)Node($nsNs-2) set router [$ns node] NodeNodeLinkBandwidthPropagation DelayQueue-Type $ns duplex-link AgentAgentTrafficTraffic generator set Agent_name [new Agent/]

  • NodeNodeTCP Connection (Figure 3),TCL ScriptFigure 3

  • Example 1 set ns [new Simulator] ;#Create a simulator object set nf [open out.nam w] ;#Open the Nam trace file $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace close $nf ;#Close the trace file exec nam out.nam & exit 0 }

  • Example 1 set node1 [$ns node] ;#Create two nodes, then create a duplex link between the nodes set node2 [$ns node] $ns duplex-link $node1 $node2 10Mb 2ms DropTail #Connect the TCP source with the TCP sink set tcp [$ns create-connection TCP $node1 TCPSink $node2 1] $tcp set window_ 128 ;# Configure the TCP agent set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 0.5 "$ftp start" ;# Schedule events for the FTP agent $ns at 4.5 "$ftp stop" $ns at 5.0 "finish" #Run the simulation $ns run

  • Example 2(n0n1n2n3)n0n2n1n2(bandwidth)2Mbps(propagation delay)10msn2n31.7Mbps20ms DropTail queuen2n310

  • Example 2n0n3FTPFTP TCPTCPn0TCP agenttcpTCPn3TCPsink agentsinkTCP(ACK)TCPagent (connect)TCP1Kbytes

  • Example 2n1n3(Constant Bit RateCBR)CBRUDPn1UDP agentudpUDPn3Null agentsinkn1UDPCBR1Mbps1KbytesCBR0.14.5FTP1.04.0

  • Example 2

  • [Tcl Script] # set ns [new Simulator]#NAM$ns color 1 Blue$ns color 2 Red#NAM trace fileset nf [open out.nam w]$ns namtrace-all $nf#trace fileset nd [open out.tr w]$ns trace-all $nd

  • [Tcl Script]#proc finish {} { global ns nf nd $ns flush-trace close $nf close $nd #NAM exec nam out.nam & exit 0}#set n0 [$ns node]set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]

  • [Tcl Script]#$ns duplex-link $n0 $n2 2Mb 10ms DropTail$ns duplex-link $n1 $n2 2Mb 10ms DropTail$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail#ns2n3Queue Size10$ns queue-limit $n2 $n3 10#NAM$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

  • [Tcl Script]#n2n3queueNAM$ns duplex-link-op $n2 $n3 queuePos 0.5#TCPset tcp [new Agent/TCP]$tcp set class_ 2$ns attach-agent $n0 $tcpset sink [new Agent/TCPSink]$ns attach-agent $n3 $sink$ns connect $tcp $sink#NAMTCP$tcp set fid_ 1#TCPFTPset ftp [new Application/FTP]$ftp attach-agent $tcp$ftp set type_ FTP

  • [Tcl Script]#UDPset udp [new Agent/UDP]$ns attach-agent $n1 $udpset null [new Agent/Null]$ns attach-agent $n3 $null$ns connect $udp $null#NAMUDP$udp set fid_ 2#UDPCBRset cbr [new Application/Traffic/CBR]$cbr attach-agent $udp$cbr set type_ CBR$cbr set packet_size_ 1000$cbr set rate_ 1mb$cbr set random_ false

  • [Tcl Script]#FTPCBR$ns at 0.1 "$cbr start"$ns at 1.0 "$ftp start"$ns at 4.0 "$ftp stop"$ns at 4.5 "$cbr stop"#TCP()$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"#5finish(#5$ns at 5.0 "finish"#$ns run

  • Example 2

  • Example 2out.nam NAM out.trCBR1000bytes0.1 n1n2

  • out.tr

  • out.trr+-d(from nodeto node)a.bab(port number)idtrace filepakcet id0id201000 bytesCBR1.03.10.112

  • http://140.116.72.80/~smallko/ns2/ns2.htmhttp://nsda.ee.ncku.edu.tw/chengrs/ns/index.htm