Stop and Wait Protocol Using NS2

download Stop and Wait Protocol Using NS2

of 7

Transcript of Stop and Wait Protocol Using NS2

  • 7/25/2019 Stop and Wait Protocol Using NS2

    1/7

    "Stop-and-Wait" protocol using NS2

    1. Background

    "stop-n-wait"(sometimes known as "positive acknowledgement with

    retransmission") is the fundamental technique to provide reliable transferunder unreliable packet delivery system.

    2. How this protocol works..

    1) Normal operation

    After transmitting one packet, the sender waits

    for anacknowledgment (ACK)

    from thereceiver before transmitting the next one. Inthis way, the sender can recognie that theprevious packet is transmitted successfuly andwe could say !stop"n"wait! guarantees reliabletransfer between nodes.#o support this feature, the sender keeps arecord of each packet it sends.Also, to avoid confusion caused by delayed orduplicated A$%s, !stop"n"wait! sends eachpackets with unique sequence numbers and

    receives that numbers in each A$%s.

    2) Timeout

  • 7/25/2019 Stop and Wait Protocol Using NS2

    2/7

    If the sender doesn&treceive A$% forprevious sent packetafter a certain periodof time, the

    sendertimesout and retransmitsthat packet again.#here are two caseswhen the senderdoesn&t receive A$%'ne is when theA$% is lost and theother is when theframe itself is nottransmitted.

    #o support thisfeature, the senderkeeps timer per eachpacket.

    3. How it is shown in nam (network animator)..

    !stop"n"wait! protocol can be shown as below in nam.

    . *acket+ is sent and A$%+ is received

  • 7/25/2019 Stop and Wait Protocol Using NS2

    3/7

    -. *acket+ is sent and A$%+ is received

  • 7/25/2019 Stop and Wait Protocol Using NS2

    4/7

    . *acket+- will be sent and be received and so on..

    4. Shortcoming

  • 7/25/2019 Stop and Wait Protocol Using NS2

    5/7

    #he main shortcoming of the stop"and"wait algorithm is that it allows thesender to have only one outstanding frame on the link at a time. #he sendershould wait till it gets an A$% of previous frame before it sends next frame. Asa result, it wastes a substantial amount of network bandwidth. #o improveefficiency while providing reliability, !sliding window! protocol is appeared.

    Stop-n-Wait ns script

    / stop and wait protocol in normal situation/ features 0 labeling, annotation, nam"graph, and window sie monitoring

    set ns 1new 2imulator3

    set n 14ns node3set n 14ns node3

    4ns at . !4n label 2ender!4ns at . !4n label 5eceiver!

    set nf 1open A"stop"n"wait.nam w34ns namtrace"all 4nfset f 1open A"stop"n"wait.tr w34ns trace"all 4f

    4ns duplex"link 4n 4n .-6b -ms 7rop#ail4ns duplex"link"op 4n 4n orient right

    4ns queue"limit 4n 4n

    Agent8#$* set nam+tracevar+ true

    set tcp 1new Agent8#$*34tcp set window+ 4tcp set maxcwnd+ 4ns attach"agent 4n 4tcp

    set sink 1new Agent8#$*2ink3

    4ns attach"agent 4n 4sink

    4ns connect 4tcp 4sink

    set ftp 1new Application89#*34ftp attach"agent 4tcp

  • 7/25/2019 Stop and Wait Protocol Using NS2

    6/7

    4ns add"agent"trace 4tcp tcp4ns monitor"agent"trace 4tcp4tcp tracevar cwnd+

    4ns at . !4ftp start!

    4ns at . !4ns detach"agent 4n 4tcp ' 4ns detach"agent 4n 4sink!4ns at .: !finish!

    4ns at . !4ns trace"annotate ;!2top and ? !4ns trace"annotate ;!5eceive Ack+;!!4ns at .?? !4ns trace"annotate ;!2end *acket+-;!!4ns at .- !4ns trace"annotate ;!5eceive Ack+- ;!!4ns at .@ !4ns trace"annotate ;!2end *acket+;!!4ns at .=> !4ns trace"annotate ;!5eceive Ack+;!!4ns at . !4ns trace"annotate ;!2end *acket+@;!!4ns at -. !4ns trace"annotate ;!5eceive Ack+@;!!4ns at -.- !4ns trace"annotate ;!2end *acket+:;!!4ns at -.:: !4ns trace"annotate ;!5eceive Ack+: ;!!4ns at -.>: !4ns trace"annotate ;!2end *acket+=;!!

    4ns at -.?? !4ns trace"annotate ;!5eceive Ack+=;!!

    4ns at . !4ns trace"annotate ;!9#* stops;!!

    proc finish BC Bglobal ns nf4ns flush"traceclose 4nf

    puts !filtering...!

    exec tclsh ..8ns"allinone"-.b:8nam".a>8bin8namfilter.tcl A"stop"n"wait.namputs !running nam...!exec nam A"stop"n"wait.nam D

    exit C

    4ns run

  • 7/25/2019 Stop and Wait Protocol Using NS2

    7/7