You are on page 1of 8

5

Selective Repeat
1. Selective Repeat
Selective Repeat
( ). Selective Repeat
. Tanenbaum ( 5),
3.4.3, .
, , ,
.
1.1
Go Back N
. ,
.

.
.
,
. 0
MAX_SEQ. ,
MAX_SEQ.
. bit
. ,
.
, .
. ,


.

, Stop and Wait Go Back N.
, ,
. ,
( ) (
). .
,
, .
, /
. , 4 bit
, 0 15.
. ,
1

0 7
8 15, (0
7) (8 15). , Selective Repeat
(MAX_SEQ+1)/2. , 3 bit,
, 4 bit, .
:
;
. ,
,
. 4 bit,
0 7. i i
mod 8.
Selective Repeat
Go Back N .
, () .
.
:
(
).
,
. no_nak Selective Repeat
frame_expected.
,
.
, no_nak
. ,
.
1.2
, , .. lab5.tcl,
. , .
, ,
, .
,
awk. , , script
.
.awk
.
awk.exe.
: 1,
.
*.tcl (File > Save).
(cursor) Command Prompt, Xgraph,
. X ,
File. log off .

.
2

2.
2.1
.
# Create a simulator object
set ns [new Simulator]

,
, (trace files),
.
# Open the nam trace file
set nf [open lab5.nam w]
$ns namtrace-all $nf
set trf [open lab5.tr w]
$ns trace-all $trf

# Define a 'finish' procedure


proc finish {} {
global ns nf trf
$ns flush-trace

# Close the trace file


close $nf
close $trf
exit 0
}

2.2
, n(0) n(1)
, 1.

1 -
3

# Create two nodes


set n(0) [$ns node]
set n(1) [$ns node]

$ns at 0.0 "$n(0) label SRP_sender"


$ns at 0.0 "$n(1) label SRP_receiver"

# Create a duplex link between the nodes


$ns duplex-link $n(0) $n(1) 10Mb 30ms DropTail

# The following line sets the queue limit of the two simplex links that connect node0 and node1 to
the number specified.
$ns queue-limit $n(0) $n(1) 200
$ns queue-limit $n(1) $n(0) 200

2.3
Selective Repeat TCP
SACK (Selective Acknowledgement). TCP
n(0) n(1). :
# Create TCP agent
set tcp0 [new Agent/TCP/Sack1]

# Set window size


$tcp0 set window_ 16

# The initial size of the congestion window on slow-start


$tcp0 set windowInit_ 16

# Disable modelling the initial SYN/SYNACK exchange


$tcp0 set syn_ false

# Set packet size


$tcp0 set packetSize_ 1500

# Attach TCP agent to node n(0)


$ns attach-agent $n(0) $tcp0

# Create TCP sink


set sink0 [new Agent/TCPSink]

# Attach TCP sink to node n(1)


$ns attach-agent $n(1) $sink0

# Connect TCP agent to sink


4

$ns connect $tcp0 $sink0

2.4
,
FTP, 0.5 sec 4.5 sec.
FTP
:
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0

2.5
, :
# Events
$ns at 0.5 "$ftp0 start"
$ns at 4.5 "$ftp0 stop"
$ns at 5.0 "finish"

# Run the simulation


$ns run

, t = 0,5 sec, FTP agent ,


t = 4,5 sec, . ,
ns lab5.tcl. lab5.nam
lab5.tr. nam lab5.nam
. lab5.tr
.

3. (trace file)
,
,
.
3.1 (trace file)
lab5.tr :
r
+
r

0.507432
0.508664
0.508664
0.508664
0.509896

1
0
1
1
0

0
1
0
0
1

ack
tcp
ack
ack
tcp

40 ------- 0
1540 ------40 ------- 0
40 ------- 0
1540 -------

1.0 0.0 1
0 0.0 1.0
1.0 0.0 2
1.0 0.0 2
0 0.0 1.0

5
2 2
6
6
3 3

+
r
+

0.509896
0.509896
0.511232
0.511232

1
1
1
0

0
0
0
1

ack
ack
ack
tcp

40 ------- 0
40 ------- 0
40 ------- 0
1540 -------

1.0 0.0 3
1.0 0.0 3
1.0 0.0 0
0 0.0 1.0

7
7
4
4 8

,
.
. +
, - , r
, d .

. ,

( TCP IP).
.
(flow ID),
. flow ID (IP.port),
(sequence number) (unique number)
.
3.2 awk
, awk
. awk .
BEGIN {}
, .
, , ..

. .
,
. :
/^r/&&/tcp/ {
packets++;
data+=$6;
}

, r
(/^r/) (&&) tcp (/tcp/), packets
1, data ($6)
.
END{}
,
.

3.3
Selective Repeat
.
, .
TCP.
r tcp.
packets ( ) ,
data ( ) .
awk:
BEGIN {
data=0;
packets=0;
}
/^r/&&/tcp/ {
data+=$6;
packets++;
}
END{
printf("Total Data received\t: %d Bytes\n", data);
printf("Total Packets received\t: %d\n", packets);
}

3.4
awk, (interpreter) awk

.
lab5.awk lab5.tr, :
awk.exe -f lab5.awk < lab5.tr

4. Selective Repeat
4.1
()
, 1;
()

, :
( )/( )

TRANSP , (
)/( )
PROP

TRANSA
S


, : S = TRANSP + 2 x PROP + TRANSA

()

;
;

()

awk,
(
). .

()

,
, 40 byte
TCP IP, (ACK) 40 byte.
; , ;

() , ,
.
; (
) .
;
()

(),
,
. ; bits
Selective
Repeat ;

()

(),
.
, .
.

()

Go Back N Selective Repeat


.
; ;

,
.

You might also like