AL-TL InterfacesTransport Layer
TCPUDP
Transport Layer
Mahalingam RamkumarMississippi State University, MS
February 28, 2018
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Sockets
Interfaces for networked processes/applications
A socket is identified by a protocol (TCP/UDP), IP address,and port number
A socket is actually the interface between an application andthe transport layer
TCP: assured delivery in the right order
UDP: best effort for each datagram. no ACKs
UDP does not provide much on top of IP. IP layer identifieshosts. UDP header has port number info to identify process inthe host.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Sockets
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
UDP Client and Server
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP Client and Server
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Listening and Connected Sockets
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Transport Layer Services
Provides service to application layer
by making the network layer easier to use
Service can be connection oriented or connectionless
Example TCP (connection oriented) UDP (connectionless)over IP.
Port numbers are access points for transport service
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Connection Oriented Service
Reliable delivery of data
In the right order
Acknowledged delivery
Hide implementation details from top layer
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Interface Provided to Application Layer
listen(), accept()
connect()
send()
recv()
close()
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Transport Ports
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Port Inversion
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Connection Establishment in TCP
Client sends connection request
Server acknowledges
Issues due to unreliable lower layer?
Packets can get lost, delayed, duplicated
FLAGS and seq/ack numbers (for counting bytessent/received) on TCP header.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Interpretation of SYN/ACK/FIN flags, seq/ack number
If SYN flag set: sequence number is the starting sequencenumber
If SYN is not set: sequence number is the byte count for firstdata byte included the packet
If ACK flag is set acknowledgement number is valid; indicatesnext byte expected
FIN set for closing a connection
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Three-Way Handshake
For establishing a connection
SYN and ACK flags; seq and ack numbers
Both sender and receiver choose initial sequence number
Connection request (SYN, seq no x) from initiator (client)
SYN-ACK (SYN, seq y , ACK, x + 1) response (from server)
ACK (ACK, y + 1) from client.
SYN — SYN/ACK — ACK sequence.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
3-Way Handshake
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Four-Way Handshake
For tearing down two unidirectional connections
What if one side is not ready to disconnect (not finishedsending)?
Four-way handshake
A→ B: FINB → A: ACK, ack number (next byte expected + 1)B → A: FINA→ B: ACK, ack number (next byte expected + 1)
FIN — ACK, FIN — ACK (four packets) or
FIN — ACK/FIN — ACK (three packets)
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
4-Way Handshake
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Diving TCP Payload
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Sequence and ACK numbers
To keep track of application data bytes sent/received
Client C , server S
C → S : seq 1+ packet with 1000 application bytes (1000byte payload)
S → C : ack 1001 (the next byte I am expecting from you is1001).
C → S : seq 1001+ packet with 500 application bytes
S → C : ack 1501 (the next byte expected is 1501).
C → S : seq 1501+ packet with 200 application bytes.
S → C : ack 1501 (the next byte expected is 1501 probablybecause it did not receive the third packet from the client).
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Both ways at the same time!
C → S : seq 1 + 100 payload bytes
S → C : seq 1 ack 101, 1500 payload bytes
C → S : seq 101 ack 1501, 200 payload bytes
S → C : seq 1501 ack 301, 1500 payload bytes
C → S : ack 3001 (no payload)
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
ACK/SEQ numbers Offset by starting sequence numbers
C , qc , S , qs
C → S : SYN, seq qc
S → C : SYN, seq qs ,ACK, ack qc + 1
C → S : ACK, ack qs + 1 (completes 3-way handshake)
C → S : seq qc + 1 + 100 payload bytes
S → C : seq qs + 1 ack 101, +1500 payload bytes
C → S : seq qc + 101 ack qs + 1501, +200 payload bytes
S → C : seq qs + 1501 ack qc + 301, +1500 payload bytes
C → S : ack qs + 3001 (no payload)
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
SYN/ACK Flags with SEQ/ACK numbers
CLIENT SERVER
→ SYN, seq(qc)
← SYN, seq(qs), ACK, ack(qc + 1)
→ seq(qc + 1), ACK, ack(qs + 1)→ seq(qc + 1), ACK, ack(qs + 1), 100 data bytes
← seq(qs + 1), ACK, ack(qc + 101), 1500 data bytes
→ seq(qc + 101), ACK, ack(qs + 1501)← seq(qs + 1501), ACK, ack(qc + 101), 1400 data bytes
→ seq(qc + 101), ACK, ack(qs + 2901), FIN
← seq(qc + 2901), ACK, ack(qc + 102), 1200 data bytes
→ ACK, ack(qs + 4101)
← seq(qs + 4101), ACK, ack(qc + 102), FIN
→ ACK, ack(qs + 4102)
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
All together
CLIENT SERVER
→ SYN, seq(qc)
← SYN, seq(qs), ACK, ack(qc + 1)
→ seq(qc + 1), ACK, ack(qs + 1)→ seq(qc + 1), ACK, ack(qs + 1), 100 data bytes
← seq(qs + 1), ACK, ack(qc + 101), 1500 data bytes
→ seq(qc + 101), ACK, ack(qs + 1501)← seq(qs + 1501), ACK, ack(qc + 101), 1400 data bytes
→ seq(qc + 101), ACK, ack(qs + 2901), FIN
← seq(qc + 2901), ACK, ack(qc + 102), 1200 data bytes
→ ACK, ack(qs + 4101)
← seq(qs + 4101), ACK, ack(qc + 102), FIN
→ ACK, ack(qs + 4102)
connect()accept()
.
.
.
send() recv()
shutdown(WR)
send()recv()
recv()
close()
close()
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Header
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Header Fields
Source port and destination port
Sequence Number - chosen randomly for the first packet(connection establishment). In subsequent packets containingdata, it indicates the offset of the first (application data) byteincluded in the packet.
Acknowledgment number indicates next byte expected (offsetby the sequence number).
A’s ack. to B offset by B’s initial sequence number
Header length (4 bits) - in number of 32 bit words. Actuallyindicates start of application data.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Header - FLAGS
Six unused bits
8 flags, 6 old ones URG, ACK, PSH, RST, SYN, FIN + 2 new(CWR,ECE)
PSH, URG are not used a lot in practice (and therefore theurgent pointer too)
SYN used for connection establishment
FIN used for disconnect
ACK is used during connection setting-up, acknowledgementof data received, and during connection-tearing-up
RST used to indicate rejection of connection
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Header - Window Size
16 bits.
Window size is the number of bytes the receiver is willing toaccept.
Window size in A’s TCP packet to B says the maximumwindow size B can use for sending data to A (and vice-versa)
The receiver determines the window size for each one-wayconnection (A to B and B to A)
Window size is dynamic.
Window size 0 indicates “stop sending data - I’m swamped”
Could later send another packet with a larger window size toresume sending.
If A has advertised a window size of 500 and the lastacknowledged byte is 1000, B cannot send beyond byte 1500to A.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Header - Checksum
Checksum of header, data and a ”conceptual pseudo-header”
Includes Source and Dest IP addresses, TCP segment length,IP protocol field.
32 Bits
Source address
Destination address
0 0 0 0 0 0 0 0 Protocol = 6 TCP segment length
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Checksum - Some Finer Points
TCP segment does not include length
IP layer (in the final destination) passes this info to TCPlayer, along with the entire TCP packet
TCP layer is also provided with the Source and Dest IPaddresses by the IP layer
All three needed to validate checksum
Violates protocol hierarchy
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Header - Options
Specify maximum TCP payload - used very frequently.
SRP instead of GBN - possibility of including NACKs beforesending ACK - RFC 1106
Scaling Window size
For high bandwidth / high delay (or both) 64-kB window isnot sufficient.On a T3 line 12msec to output 64kBIf RTT is 50 msec, nothing can be sent for 38 msec.RFC 1323Allows left shift of window size upto 14 bits - max window size230.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
PSH and URG
PSH - a way for applications to request TCP layer to stopbuffering packets and just send the data out.
A set PSH flag indicates to the receiver that the packetshould be delivered immediately to the application above.
URG and Urgent pointer. Very similar to push conceptually.
But can specify a particular byte offset in a TCP packet thatneeds to be attended to urgently - like a software interrupt.
Urgent pointer indicates offset.
Once again, at the receiver side, the TCP layer delivers thedata to the application ASAP and indicates the offset.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
PSH Flag
PSH flag is actually used a lot in telnet
How many bytes are exchanged between A and B for sendingone character?
For each character, 20 bytes IP header + 20 bytes TCPheader + 1 = 41 bytes!
Each way
Two ACKs each way if we type real slow - 40 + 40 = 80 bytes
Total of 162 bytes for sending a single character
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Window Management
Client A, server B
Client has reserved a 10000 byte buffer for the connection
Client indicates this by setting window size 10000 in the SYNpacket
Server B allocates 4000 bytes. Indicates this by settingwindow size 4000 in the SYN-ACK packet.
Window size indicates how many bytes beyond the lastacknowledged byte can be sent.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Window Management ...
After connection establishment, A sends 1000 bytes to B
B stores the bytes in the buffer - has only 3000 bytes of freebuffer.
B sends an ACK with window size 3000.
A sends another 3000 bytes
B sends ack with window size 0
A waits.
B’s TCP layer passes the data to the application layer. Bufferis now empty. B sends a new “window advertisement” to Awith window size 4000.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Window Management
Application does a 2K write
Application does a 2K write
Application reads 2K
Sender is blocked
Sender may send up to 2K
Receiver's buffer
0 4K
2K
2K
Empty
Full
2K SEQ = 0
2K SEQ = 2048
1K SEQ = 4096
ACK = 2048 WIN = 2048
ACK = 4096 WIN = 0
ACK = 4096 WIN = 2048
2 K1K
Sender Receiver
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Silly Window Syndrome
Application reads 1 byte
Window update segment sent
New byte arrives
Header
Header
Receiver's buffer is full
Receiver's buffer is full
Room for one more byte
1 Byte
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Specifications
Apart from the header protocol, TCP specifies very little
Example, defaults
Everything else is implementation dependent
Some of them may ignore PSH. Most do not support URG
TCP does not specify when ACKs should be sent or howmany bytes to buffer.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Fast Retransmission
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Retranmission Scenario 1
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Retranmission Scenario 2
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Retranmission Scenario 3
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Congestion Control
Hosts realize that there is congestion when packets are notacknowledged
Could occur due to two reasons1 Low capacity receiver at the other end2 Network congestion
The first is handled during the connection establishmentprocess - using window sizes
The second?
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Congestion Window
Every sending host chooses an additional window size
Congestion Window
Initially set to the maximum packet size the host can handle(MTU 1500 for Ethernet based hosts).
The window size chosen is the minimum of Congestion windowWC and the advertised window size by the other side Wa.
First packet sent is up to MTU size
Assume Wa is very large
If successful in sending first packet (ack received before timergoes off) congestion window size doubled to 2 MTUs
On success, doubled to 4 MTU and so on till failure happens -then window size is halved.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Congestion Window
Failure is detected if 3 duplicate ACKs received or time outoccurs.
Additional parameter, threshold Window size, initially set to64 kB
Exponential increase, only till the threshold is released.
After this increase is linear, for example 64 MTU to 65, 66and so on.
Whenever failure occurs (say at N MTUs), threshold is halved(in both TCP Tahoe and TCP Reno)
And WC set to N/2 MTU (TCP Tahoe, fast recovery) or 1MTU (TCP Reno, slow recovery)
ICMP source quench packets (we will see this later in thenetwork layer) are also treated as time-outs for this purpose.
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Slow Start
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Tahoe and Reno
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP AIMD
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
ECN - Explicit Congestion Notification
RFC 3168. ECN requires explicit cooperation between TCPand IP layers
Router experiencing congestion sets some ECN bits in the IPheader
Receiving host (at the other end of the TCP connection)echoes this to the sender in the header of a TCP ACKsegment
TCP sender reduces congestion window size by half, sets CWR(congestion window reduced) bit in the next TCP packet
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Explicit Congestion Notification
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
TCP Timers
Retransmission Timer - decides timeout
How? Need to estimate RTT. Chicken and Egg Problem?
Not really - use a large timeout initially!
T T1 T20.3
0.2
0.1
00 10 20
Round-trip time (msec)
(a) (b)
Pro
babi
lity
0.3
0.2
0.1
0
Pro
babi
lity
30 40 50 0 10 20Round-trip time (msec)
30 40 50
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Estimating Round-Trip Time (RTT)
Jacobson’s algorithm1 Time for receiving acknowledgement M2 RTT = αRTT + (1− α)RTT3 α = 7/8. Timeout is βRTT . How do we choose β?4 β should be based on the standard deviation of the RTT
estimate.5 Estimate of standard deviation
D = αD + (1− α) | RTT −M |.6 Timeout = RTT + 4× D
What happens when time outs occur? Is the ACK for theoriginal or for the re-transmission?
Making a wrong judgment here could affect the estimate verybadly!
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Karn’s Algorithm
Do not update RTT for segments that have beenretransmitted
Whenever timeout occurs double RTT
Keep doing it till timeout does not occur!
Used in most TCP implementations (TCP does not specifywhat to do).
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
TCP HeaderCongestion ControlTimer Management
Two more Timers!
TCP uses 3 timers - retransmission, persistence andkeep-alive
Persistence Timer - for prevention of deadlock if windowsize re-advertisement is lost.
When persistence times goes off, sender transmits a probe(even though receiver had previously informed the sender tostop sending by advertising window size 0), and receiver sendsthe window size as response.
Keep-alive Timer - Connections may be idle for a long time(telnet connections). On expiry of keep-alive timer a probe issent to detect if the other side is still alive. If so timer isstarted again (else connection is terminated).
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
UDP
Does very little over what IP does
Provides port numbers
No flow control, error control, retransmission
Applications have to do everything
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
UDP
Checksum similar to TCP
DNS
RPC (Remote procedure calls). eg gethostbyname()
The need for 3 packets for establishing connection and 3 or 4for tearing them down makes TCP very expensive for manyapplications
Especially when networks are often highly reliable.
Multicasting - TCP cannot be used.
UDP is used for RTP (real-time transport protocol)
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Transactional TCP
TCP has high overhead for scenarios where the transaction issimple (small request, small response, like DNS)
UDP is efficient but highly insecure
Even servers that did not actually receive the query canpretend to have received, and send a “response”
Transaction TCP is actually a different way of using TCP
Query and responses are sent with connection request packets
Three-way handshake simultaneously completes connectionestablishment, acknowledged delivery of data and termination!
Ramkumar TL
AL-TL InterfacesTransport Layer
TCPUDP
Transactional TCP
Client Server
SYN
SYN, ACK(SYN) 2
6
2
7
8
3
1
345
9
1
ACK(SYN)
ACK(FIN)
Time
Client Server
SYN, request, FIN
ACK(FIN)
(a) (b)
SYN, ACK(FIN), reply, FIN
Timerequest
FIN
ACK(request + FIN)
FIN
reply
Ramkumar TL