explaining tcp/ip

TCP/IP Header

UDP Header

UDP Header

UDP Header Terms Explanation

  • Source port : Sender’s port number, for de/multiplexing
  • Destination port : Receiver’s port number, for de/multiplexing
  • Length : Length in bytes including UDP header and UDP data
  • Checksum :
    1. Adding 16 bits Source port , Destination port , Length , 16 bits data(padding with 0 if necessary)
    2. Wrap around in case of overflow(not in the end, but in the whole process)
    3. Return 1’s complement
  • DATA : Data from application layer

TCP Header

TCP Header

TCP Header Terms Explanation

  • Source port : Sender’s port number, for de/multiplexing
  • Destination port : Receiver’s port number, for de/multiplexing
  • Sequence number : Indicating the sequence number of this segment(sequence number of the first byte)
  • Acknowledgment number : The next expected segment sequence number from the other side(ex. I have received segment 1 and 2. I expect to receive segment 3 from you. In this case, the Acknowledgment number is 3)
  • Header Length : Length of the header in 32-bit words. Because Options field is variant.
  • Reserved : Unused yet
  • URG : Indicating data in this segment is urgent, location of the urgent data is specified by urgent data pointer.
  • ACK: Indicating that this is an ACK segment, and the value in Acknowledgment number field is valid
  • PSH : Indicate that this segment is high priority, the receiver should send it to upper layer immediately
  • RST : Reject TCP connection request
  • SYN : Request to establish TCP connection
  • FIN : Ready to close the TCP connection
  • Window : It’s used for flow control. It indicate the receive buffer size of this segment sender.
  • TCP checksum : Checksum of data and psudoheader
  • Urgent data pointer : When URG is turn on, it will point to the location of urgent data
  • Options :
    • Maximum segment size
    • Window scale
    • Selective Acknowledgement permitted.
    • Timestamp
  • DATA : Data from application layer

If you got confused with the terms above, please refer to this Internet protocol header quick reference

TCP/UDP Multiplexing and Demultiplexing

UDP De/Multiplexing

The de/multiplexing of UDP protocol is done by recognizing 2 tuples:

1. Destination IP
2. Destination Port Number

When a segment is received by the receiver’s transport layer. It will be direct to the socket which bind on the destination port. Note that in principle, one process(may have multiple thread and multiple sockets) can only bind on one port.

TCP De/Multiplexing

The de/multiplexing of TCP protocol is done by recognizing 4 tuples:

1. Source IP
2. Source Port Number
3. Destination IP
4. Destination Port Number

The TCP protocol will create a distinct socket for each connection with different 4 tuples. This characteristic has been used by web browsers to download web page objects in parallel. When a segment is received by the receiver’s transport layer. It will be direct to the socket whose 4 tuples match the 4 tuples of the segment.

Web Browser Scenario

In this scenario, we are going to show how web browsers download web page objects in parallel.

UDP Header

As can be seen from the image, n sockets are binding on port 80. All of these sockets are belong to the web service process of the server. While in the client side, the web browser process created multiple threads which each has its own socket. If you are careful enough, you can notice that the only difference between the n TCP headers is the Source port field. This is how the parallel downloading works. In words, the client side create multi-thread at the first step. Then it establish multiple TCP connections by changing only the source port number field.

TCP Connection Establishment and Tear Down

TCP Connection Establish

The TCP connection establishment procedure is also referred as three-way handshake.

Step 1. (SYN segment)

//Client Side
//Set “SYN” header field
SYN = 1
//Choose an initial sequence number “client_initialSequenceNum”
client_initialSequenceNum = random()
//Set “Sequence number” header field
Sequence number = client_initialSequenceNum
//Fill the other fields and send the packet

Step 2. (SYNACK segment)

//Server Side
//Allocate buffers and variables for the connection
//Set “SYN” header field
SYN = 1
//Set “Acknowledgment number” header field
Acknowledgment number = client_initialSequenceNum + 1
//Choose an initial sequence number “server_initialSequenceNum”
server_initialSequenceNum = random()
//Set “Sequence number” header field
Sequence number = server_initialSequenceNum
//Fill the other fields and send the packet

Step 3. (ACK segment)

//Client Side
//Set “SYN” header field
SYN = 0
//Set “Acknowledgment number” header field
Acknowledgment number = server_initialSequenceNum + 1
//Set “Sequence number” header field
Sequence number = client_initialSequenceNum
//Fill the other fields and send the packet

TCP Connection Tear Down

This image is already self explanatory.

TCP Connection Tear Down

TCP Connection Reject

If there is no socket binding on the destination port or the application bound on the port reject to serve the host. The server will reply a packet with

RST = 1

Mechanism used in TCP

Timer

Timeout interval is set by

EstimateRoundTripTime = (1-a)EstimateRoundTripTime + a SampleRoundTripTime

DeviateRoundTripTime = (1-b)DeviateRoundTripTime + b |SampleRoundTripTime-EstimateRoundTripTime|

TimeoutInterval = EstimateRoundTripTime + 4 * DeviateRoundTripTime

Where a and b are parameters specified by users(network administrator). Round-trip time (RTT) is the length of time it takes for a signal to be sent plus the length of time it takes for an acknowledgement of that signal to be received.

Sequence Number

Acknowledgment

Receive Window

Sliding Window

Why Why Why of TCP/IP

Why Three-way Handshake