clase15-TCP HTML
clase15-TCP HTML
clase15-TCP HTML
Nivel de transporte
TCP UDP
Nivel de red
IP
Nivel de enlace
Co
físico
enlace
m
• Los protocolos de transporte funcionan red físico
un
enlace
i
ca
físico
en los end sistems
ci
ón
red
Emisor: separa los mensajes en
ló
enlace
gi
físico red
c
segmentos, los pasa al nivel de
a
enlace
ex
físico
red
tr
em
red
o
Receptor: reensambla los enlace
a
ex
físico
segmentos en mensajes, los pasa
tr
e
m
al nivel de aplicación
o
aplicación
transporte
• Más de un protocolo de transporte red
enlace
disponible para las aplicaciones físico
• Flujo de datos:
Stream de bytes
Ordenados
Full-duplex
MSS: Maximum
Segment Size
17 Nov TCP 4/56
Contenido
• Multiplexación y demultiplexación en TCP
• Gestión de conexiones TCP
Establecimiento y liberación
• Transferencia fiable y control de flujo:
Ventana deslizante
• Formato del segmento TCP
SP: 5775
DP: 80
S-IP: B
D-IP:C
SP: 5775
DP: 80
S-IP: B
D-IP:C
• En el mismo segmento el
servidor indica su deseo de
establecer la conexión (SYN)
• El segmento no tiene datos, solo
cabecera
• Un extremo envía un
segmento solicitando el cierre
de la conexión
• El segmento no tiene datos,
solo cabecera
• FIN
Paso 2:
• El otro extremo confirma FIN
Paso 3:
• El otro extremo envía un FIN
FIN
• El segmento no tiene datos,
solo cabecera
Paso 4:
• Confirmación de ese segundo FIN
FIN
ACK
• Por si ese último ACK se
FIN
pierde el que lo envió espera
un tiempo (podría tener que
time wait
ACK
volverlo a enviar)
• Conexión cerrada cerrada
cerrada
ESTABLISHED
Close, snd FIN rcv FIN / snd ACK
CLOSE
WAIT
rcv FIN /
FIN snd ACK Close, snd FIN
CLOSING
WAIT-1
rcv FIN, ACK / LASTACK
rcv ACK snd ACK rcv ACK
rcv ACK
FIN
TIMEWAIT CLOSED
WAIT-2 rcv FIN / Timeout 2xMSL
snd ACK
ESTABLISHED
Close, snd FIN rcv FIN / snd ACK
ACK
. CLOSE
. rcv FIN /
WAIT
FIN
TIMEWAIT CLOSED
WAIT-2 rcv FIN / Timeout 2xMSL
snd ACK
ESTABLISHED
Close, snd FIN rcv FIN / snd ACK
ACK
. CLOSE
. rcv FIN /
WAIT
CLOSED CLOSED
Close Close
LISTEN LISTEN
SYN rcv SYN / snd ACK SYN SYN rcv SYN / snd ACK SYN
RCVD SENT RCVD SENT
rcv ACK rcv SYN, ACK / rcv ACK rcv SYN, ACK /
Close, snd FIN snd ACK Close, snd FIN snd ACK
ESTABLISHED ESTABLISHED
Close, snd FIN rcv FIN / snd ACK Close, snd FIN rcv FIN / snd ACK
CLOSE CLOSE
WAIT WAIT
rcv FIN / rcv FIN /
FIN snd ACK Close, snd FIN FIN snd ACK Close, snd FIN
CLOSING CLOSING
WAIT-1 WAIT-1
rcv FIN, ACK / LASTACK rcv FIN, ACK / LASTACK
rcv ACK snd ACK rcv ACK rcv ACK snd ACK rcv ACK
rcv ACK rcv ACK
FIN FIN
TIMEWAIT CLOSED TIMEWAIT CLOSED
WAIT-2 rcv FIN / WAIT-2 rcv FIN /
Timeout 2xMSL Timeout 2xMSL
snd ACK snd ACK
Aplicación Aplicación
Transporte
Canal fiable
Aplicación Aplicación
Transporte
Canal fiable
Red
Canal no fiable
3 Datos
3
ACK
Ventana
Buffer de recepción
Receptor
Entregados a la App
Recibidos y confirmados Ventana que anuncia
17 Nov TCP 34/56
Ventana deslizante
• La aplicación receptor lee bytes del stream (la ventana
se abre en el emisor, se desliza en el receptor)...
Buffer de recepción
Receptor
Entregados a la App
Recibidos y confirmados Ventana que anuncia
17 Nov TCP 35/56
Ventana deslizante
• La aplicación receptor lee bytes del stream (la ventana
se abre en el emisor, se desliza en el receptor)
Buffer de recepción
Receptor
Entregados a la App
Recibidos y confirmados Ventana que anuncia
17 Nov TCP 36/56
Ventana deslizante
• Se reciben más confirmaciones
• Se confirma siempre el último dato recibido consecutivo (sin
huecos)
• La ventana se desliza en el emisor...
Ventana anunciada por el receptor
Emisor
Buffer de recepción
Receptor
Entregados a la App
Recibidos y confirmados Ventana que anuncia
17 Nov TCP 37/56
Ventana deslizante
• Se reciben más confirmaciones
• Se confirma siempre el último dato recibido consecutivo (sin
huecos)
• La ventana se desliza en el emisor
Ventana anunciada por el receptor
Emisor
Buffer de recepción
Receptor
Entregados a la App
Recibidos y confirmados Ventana que anuncia
17 Nov TCP 38/56
Tamaño de la ventana
• Caso Stop&Wait, el tiempo de propagación y el de transmisión de la
confirmación no se aprovecha
• Caso de ventana deslizante: ¿qué tamaño mínimo debe tener la ventana para
aprovechar ese tiempo?...
Ventana=BWxRTT
RTT
RTT
timer
write() write()
• tcpdump en el emisor
0 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: S 0:0(0) win 32120 <mss 1460>
0.000211954 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: S 0:0(0) ack 1 win 32120 <mss 1460>
0.000458002 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 1 win 32120
0.00218892 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 1:1449(1448) ack 1 win 32120
0.00224495 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 1449:2897(1448) ack 1 win 32120
0.00646901 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 1449 win 31856
0.00651395 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 2897:4345(1448) ack 1 win 32120
0.00652695 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 4345:5793(1448) ack 1 win 32120
0.00855601 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 4345 win 31856
0.00858796 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 5793:7241(1448) ack 1 win 32120
0.00859892 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 7241:8689(1448) ack 1 win 32120
0.00860894 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 8689:10137(1448) ack 1 win 32120
0.016923 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 5793 win 30408
0.016958 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 10137:11585(1448) ack 1 win 32120
0.0169699 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 11585:13033(1448) ack 1 win 32120
0.0180379 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 8689 win 28960
0.0180709 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 13033:14481(1448) ack 1 win 32120
0.018082 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 14481:15929(1448) ack 1 win 32120
0.0180919 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 15929:17377(1448) ack 1 win 32120
...
17 Nov TCP 45/56
Ejemplo (cont.)
...
0.159851 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 52129 win 5792
0.159884 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 56473:57921(1448) ack 1 win 32120
0.160865 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 55025 win 4344
0.160898 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 57921:59369(1448) ack 1 win 32120
0.166768 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 57921 win 2896
0.166797 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 59369:60817(1448) ack 1 win 32120
0.173574 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 60817 win 1448
0.173606 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 60817:62265(1448) ack 1 win 32120
0.191377 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 62265 win 0
...
2.01157 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 62265 win 1448
2.0116 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 62265:63713(1448) ack 1 win 32120
2.01395 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 63713 win 1448
2.01399 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 63713:65161(1448) ack 1 win 32120
2.21217 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 63713:65161(1448) ack 1 win 32120
2.21372 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 65161 win 0
...
17 Nov TCP 46/56
Ejemplo (cont.)
...
3.02153 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 65161 win 1448
3.02155 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 65161:66609(1448) ack 1 win 32120
3.0216 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 65161 win 2896
3.02162 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 66609:68057(1448) ack 1 win 32120
3.0217 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 65161 win 5792
3.02616 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 65161 win 11584
3.02623 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 65161 win 23168
3.02835 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 68057 win 31856
3.02838 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 68057:69505(1448) ack 1 win 32120
3.02839 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 69505:70953(1448) ack 1 win 32120
3.02841 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 70953:72401(1448) ack 1 win 32120
3.03392 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 70953 win 31856
3.03395 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: . 72401:73849(1448) ack 1 win 32120
3.03396 eth0 > 1.1.1.13.1510 > 1.1.1.12.2704: P 73849:75297(1448) ack 1 win 32120
3.03761 eth0 < 1.1.1.12.2704 > 1.1.1.13.1510: . 1:1(0) ack 73849 win 31856