Some TCP experiments We can ‘tweak’ the behavior of our

advertisement
Some TCP experiments
We can ‘tweak’ the behavior of our
Linux networking subsystem to
clarify a protocol’s operations
Data-transfer overview
How does the ‘sender’ decide what amount of data to transmit?
process
A
application layer
application layer
process
B
write
read
buffer for outgoing data
buffer for incoming data
… port P …
TCP
to the IP layer
… port Q …
transport layer
data link
transport layer
TCP
from the IP layer
Recall the TCP Header
32-bits
source port address
destination port address
sequence number
acknowledgment number
Header
Length
reserved
U A P R S F
R C S S Y I
G K H T N N
checksum
options and padding …
window size
urgent pointer
TYPE
3
LEN
3
‘Sender’ saw this information during initial 3-way handshake
window
scale
option
Turn off ‘window scaling’?
• Linux provides a way for system manager
to ‘disable’ the window-scaling feature
root#
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
• In this case the ‘window size’ (advertised
by the receiver during its ACK handshake)
lets the sender know the storage-capacity
of its buffer for any incoming data
/proc/sys/net/ipv4
TCP window-size
• With ‘window scaling’ disabled, we can do
a timing experiment that will show the role
played by the TCP Header’s ‘window-size’
• Our ‘nanowait.cpp’ demo-program shows
the programming syntax that we can use
for introducing ‘fine grained’ timing-delays
one second equals one-thousand milliseconds
one millisecond equals one-thousand microseconds
one microsecond equals one-thousand nanoseconds
Observing TCP’s timing
• We can modify our tcpclient’s writing loop
so a time-delay occurs after it writes each
character to its communication socket, in
order to exceed the Delayed ACK timeout
and so observe the ‘piggybacking’ failures
#include <time.h>
struct timespec myts = { seconds, nanoseconds };
…
if ( nanosleep( &myts, NULL ) < 0 ) { perror( “nanosleep” ); }
…
Our‘slow-motion’ demo
TCP client
transmits
its data
with a
delay
between
successive
bytes
timeline
TCP server
‘peeks’ at
arriving
data
but
leaves it
in the
recv-buffer
Watching data arrive…
• If we replace ‘read()’ with ‘recv()’, we can
utilize the MSG_PEEK ‘flags’ parameter
and thereby watch our TCP packet-data
arriving byte-by-byte in slow-motion when
it’s being sent out with ‘timed’ delays
char
buf[ 80 ] = { 0 };
for (int k = 0; k < 72; k++)
{
if ( recv( sock, buf+k, 1, MSG_PEEK ) == 0 ) break;
printf( “ %s \r”, buf );
sleep( 1 );
}
Intermission
Timeout to watch this in-class demonstration
TCP ‘sliding window
socket’s buffer for outgoing data
bytes ready to go,
but not yet sent
bytes already sent,
but not yet ACK’d
bytes already
sent and ACK’d
window
socket’s buffer for outgoing data
bytes ready to go,
but not yet sent
bytes already sent,
but not yet ACK’d
window
bytes already
sent and ACK’d
Website animation
• You can watch and experiment with this
graphical animation depicting the TCP
protocol’s ‘sliding window’ algorithm
< http://www2.rad.com/networks/2004/sliding_window/demo.html >
Thanks to RAD Data Communications, Ltd. for this online demo
Download