Computer Systems

Transport Layer

Transport Layer

Table of Contents

Reading

Presentation Layer

Session Layer

Transport Layer Services

Application needs:

Network provides:

transport_entity

transport_layer_encapsulation

TCP/UDP Service Models

Multiplexing and Demultiplexing

mux_demux

Transport Layer Addressing

Some well-known ports

Port Number Application
21 FTP
22 SSH
23 Telnet
25 SMTP
80 HTTP
110 POP3

Port scanning

Multiplexing UDP

UDP

DNS

SNMP

VoIP

RPC

rpc

RTP

rtp_streaming

RTP sits above UDP and below application rtp_udp_example

RTP Header

rtp_header

RTCP: Real-time transport control protocol

RTP Playback

rtp_playback

UDP Segment Structure

udp_segment

DDoS

Multiplexing TCP

TCP Service Primitives

Primitive Packet sent Meaning
LISTEN (none) Block until something tries to connect
CONNECT CONNECTION REQ Actively attempt to establish a connection
SEND DATA Send information
RECEIVE (none) Block until DATA packet arrives
DISCONNECT DISCONNECTION REQ This side wants to release the connection

tcp_state_diagram Simplified TCP state diagram

Connection Establishment Complications

TCP Service Model

tcp_service_model

Establishing a TCP connection

Web servers and TCP

tcp_clients

web_server_tcp

TCP Connection features

TCP Properties

tcp_buffers TCP send and receive buffers

TCP Header

tcp_header

Three-way handshake

three_way_handshake a. normal operation b. simultaneous connection attempts: two attempts result in only one connection

TCP segments

Synchronisation

Retransmission

Closing TCP connection

closing_tcp_connection

SYN flooding

Reliable Data Transfer

Mechanisms for reliable data transfer

Mechanism Use, comments
Checksum Detect bit errors in transmitted packet
Timer Timeout/retransmit a packet. Duplicate packets may be received
Sequence number Allow detection of duplicate packets and lost packets
Acknowledgement Indicates packet referenced by sequence number has been received correctly
Negative Acknowledgement Indicate packet referenced by sequence number was not received correctly
Window, pipelining Restrict sender to send only packets with sequence numbers in a given range. Increased network utilisation over stop-and-wait.
Packet life Packet cannot live in network beyond time limit. Ensures prevention of overlapping sequence numbers

pipelined_data_transfer

Socket Programming

socket_addresses

Berkeley Sockets

Using sockets

using_sockets

Socket Primitives

State Description
SOCKET Creates a new communication endpoint (1/2 socket: no connection yet)
BIND Associate a local address with a socket
LISTEN Announce willingness to accept connections; give queue size
ACCEPT Passively establish an incoming connection
CONNECT Actively attempt to establish a connection
SEND Send some data over a connection (write())
RECEIVE Receive some data from the connection (read())
CLOSE Release the connection

Simple Connection Management

state_diagram_connection_management

Socket Finite State Machine

State Description
CLOSED No connection active/pending
LISTEN Server waiting for incoming call
SYN RCVD Connection request has arrived; wait for ACK
SYN SENT Application has started to open connection
ESTABLISHED normal data transfer state
FIN WAIT 1 application has said it’s finished
FIN WAIT 2 other side has agreed to release
TIME WAIT Wait for all packets to die off
CLOSING Both sides have tried to close simultaneously
CLOSE WAIT Other side has initiated release
LAST ACK wait or all packets to die off

socket_fsm

Sockets in C

// Headers
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>   

// Variables
int listenfd = 0; // listen file descriptor
int connfd = 0;   // connection file descriptor
char sendBuff[1025]; // send buffer
struct sockaddr_in serv_addr; // server address

// create socket
listenfd = socket(AF_INET, SOCK_STREAM, 0); 
// initialise server address (fill with zeros)
memset(&serv_addr, '0', sizeof(serv_addr)); 
// initialise send buffer with 0s
memset(sendBuff, '0', sizeof(sendBuff));

// IPv4 address
serv_addr.sin_family = AF_INET; 
// Listen on any IP address
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);  
// listen on port 5000
serv_addr.sin_port = htons(5000);

// bind and listen
bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
listen(listenfd, 10);   // maximum number of client connections to queue

// Accept, send, close
connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);  // -1 if no-one, else file descriptor
snprintf(sendBuff, sizeof(sendBuff), "Hello World!");  // snprintf: print no more than n bytes
write(connfd, sendBuff, strlen(sendBuff));

close(connfd);

client side

// connect
connect(connfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));

// receive: process data that's arrived so far; repeat while loop later if there is
// more data
while ((n = read(connfd, recvBuff, sizeof(recvBuff)-1)) > 0) {
    // process received buffer
}

UDP Sockets

UDP Sockets

UDP Server Client Implementation C

udp-server-client-sockets

Multi-threaded web server

Dispatcher thread

while (TRUE) {
  get_next_request(&buf);
  handoff_word(&buf);
}

Worker thread

while (TRUE) {
  wait_for_work(&buf);
  look_for_page_in_cache(&buf, &page);
  if (page_not_in_cache(&page)) {
    read_page_from_disk(&buf, &page);
  }
  return_page(&page);
}

Round-Trip Time estimation and Timeout

Estimating round trip time

sample_rtt_and_estimated_RTT

Timeout interval

\[TimeoutInterval = EstimatedRTT + 4 DevRtt\]

TCP Reliable data transfer

Fast retransmit

tcp_fast_retransmit

TCP Flow Control

tcp_receive_window

TCP Sliding window

tcp_sliding_window

tcp_sliding_window_eg

Avoiding Deadlock

Congestion Control

Congestion Control Principles

Approaches to congestion control

TCP Congestion control

LastByteSent - LastByteAcked <= min(cwnd, rwnd)

Original Approach

tcp_history Source

Principles

tcp_congestion_fsm

tcp_behaviour

Slow Start

Congestion Avoidance

Fast recovery

tcp_congestion_window_reno_tahoe

Additive Increase, Multiplicative Decrease

tcp_congestion_aimd

Further Optimisations to TCP

tcp_selective_ack

Estimating the size of the congestion window

Fairness

tcp_congestion_fairness

tcp_congestion_throughput

\[\frac{W}{RTT}\approx\frac{1}{RTT}\sqrt{\frac{2}{p}}\]

Edit this page.