TCP - Transmission Connection Protocol

 

TCP in OSI

TCP Port Numbers

TCP Header

Three way handshake

UDP - User Datagram Protocol

UDP Header

IP – Internet Protocol

IP Header

 

 

TCP in OSI

 

Transport Layer + Network Layer = TCP Stack

 

TCP Port Numbers

 

The header of each TCP packet includes two port numbers: a source and a destination port. Each of them has a length of 16 bits (see TCP packet header).

Ports aren’t physical doors; there are logical entities defined by the TCP stack software. There are 56 535 different TCP ports (216-1), port 0 is reserved and not used.

The “well-known” port numbers are spelled out in RFC 1700.

 

TCP Header

 

Like pictured below the TCP header has a length of 32 Bits and consists of:

 

TCP Source Port

Contains the port number from where the packet was sent, is dynamically assigned by TCP Stack.

TCP Destination Port

Contains the port number where the packet should be routed by TCP Stack @ the destination.

Often it is a “well-known” port which is associated with a server application.

Sequence Number

Number for session initializing in TCP (see three way handshake).

Acknowledgment Number

Number for session initializing in TCP (see three way handshake).

Data Offset

This field describes where in the TCP packet the header ends and the data starts. It is equal to the TCP header in 32-bit words.

Reserved

This field is reserved for the future.

Control Bits

 

·        URG (Urgent)

The Urgent pointer in the TCP Header field is significant.

·        ACK (Acknowledge)

The Acknowledgement field is significant. This packet is used to acknowledge earlier packets.

·        PSH (Push Function)

This is the push function, used to flush data through the TCP layer.

·        RST (Reset)

The connection should be reset, due to error or other interruption.

·        SYN (Synchronize)

The system should synchronise sequence numbers. This code bit is use during session establishment.

·        FIN (Finish)

There is no mire data from the sender. Therefore, the session should be torn down.

           

Window

This field is used to control the number of outstanding packets sent between systems. It gives each side of the communication a way to control the flow of the packets from the other side to make sure that all packets are received properly and acknowledgement appropriately before new packets are sent.

Checksum

It is used to verify that the TCP packet (header and data) was not corrupted in its journey across the network.

Urgent Pointer

This field has a Pointer into the data of the packet to indicate where urgent information is located.

Options (Optional)

This set of variable length fields can indicate additional information about the TCP processing capabilities of either side of the connection. For example, if a TCP layer can handle only TCP packet of a given maximum size, the System can indicate this limitation in the TCP Options.

Padding

This field includes enough bits set to zero to extend the length of the TCP header so that it ends on a 32-bit boundary. It’s just fluff included in the header to make sure everything lines up evenly.

Data fields

Fields for Data (or urgent Data)

 

Three way handshake

 

Suppose a machine called Alice has some data to send to a system named BOB. Alice starts the three-way handshake by sending form a dynamically assigned port a TCP packet to BOB with SYN control bit set to one and the sequence number set to some initial value (known as the initial sequence number, which is dynamically assigned by the TCP Layer and is unique for this connection)ISNA. BOB receives this packet form Alice. If the destination port of the packet is open on BOB, BOB will sends back a single packet with ACK and SYN bits set to one, Acknowledgement number field filled with the Sequence number ISNA(sequence number form Alice) and  the sequence number field with a ISNB. With this response, BOB essentially says, “ALICE, I ACKnoledge your session establishment request and initial sequence number A, and I will SYNchronize with you using this initial sequence number B”. Upon ALICE receiving BOB’s response, ALICE will complete the three-way handshake by sending a packet with the ACK code bit set, and an Acknowledgement to ISNB.

Both Sides have agreed upon a set of sequence numbers that will be used in the communication. All packets going from ALICE to BOB will have incrementally higher sequence numbers, with the number increasing by one for each octet of data going from ALICE to BOB, starting at ISNA. Likewise all packets going form BOB back to ALICE will have sequence numbers starting at ISNB and going up for each octet of data. Additionally, the packets will include acknowledgement numbers based on the sequence numbers of packets received so far. With this careful exchange and agreement upon sequence numbers, TCP can now make sure all packets in the session arrive in the proper order. If two packets get reversed in transmission (because, for example a later packet took a shorter path than an earlier packet), the TCP layer can discover the problem and resequence the packets before passing them to the application. Likewise, if a packet is lost during transmission, TCP can discover the problem by looking at the sequence and acknowledgement numbers and retransmit the missing packet. Therefore, the “three-way” and the sequence numbers that result from it allow TCP to have reliable, sequenced transmissions. While the ACK and SYN code bits are heavily used to establish a session, the FIN code is used to tear down a session. Each side sends a packet with the FIN code bit set to indicate the session should be ended. The RST code bit is used to stop connections and free up the sequence numbers in use. If a machine receives a packet that is not expecting (such as a packet that includes ACK bit set when no session has been established), it will respond with a packet that has the RST bit set.

The URG and PSH code bit are used less often then the other four code bits. The URG code bit means that the data stream includes some urgent data. If the URG cod bit is set to one, the Urgent Pointer field will indicate where in the data stream the really urgent data is located. TCP doesn’t specify how the urgent data should be handled by the application; it merely allows the application on one side of a connection to flag the urgent data flag the other side of the connection. The PSH code bit means that the TCP layer should flush the packet through the stack quickly, not queuing it up for later delivery.

 

UDP - User Datagram Protocol

 

UDP is connectionless – the Protocol doesn’t know or remember the state of a connection. It doesn’t have any concept of session initiation, acknowledgement, tear down, or anything else. Furthermore UDP itself does not retransmit lost packets, nor does it put them in the proper order. So if packet 1, packet 2 and packet 3 are sent out, the destination may receive packet 2, packet 1, and another copy of packet 1. Packet 1 is lost and packet 1 was somehow transmitted twice. UDP is inherently unreliable. It may loss packets or sent them out of order. But sometimes unreliable is OK, particularly when it cans buy your speed. Some applications are much more interested in getting packets across the network quickly, and don’t need super-high reliability. Such applications do not want the overhead of a three way handshake, sequence numbers on every packet, acknowledgement, etc. Instead ,for some applications simplicity and speed are the requirements.

UDP Header

 

The UDP header shown below illustrates the simplicity of UDP. Essentially, one a source and a destination port are included, together with the massage length and a checksum. No sequence numbers or code bits are required.

UDP has 16-bit port numbers, so there are 65 535 possible UDP ports.

IP – Internet Protocol

Once the TCP or UDP layer generates a packet, it must be send across the network. The Transport layer (TCP or UDP) will pass the packet to the Network layer for end-to-end packet delivery.

 

Upon receiving information form the Transport layer, the IP layer generates a header, shown in the picture below, which includes the source and destination IP addresses. The header is added to the front of the TCP packet to create a resulting IP packet which will be used to carry the entire contents (IP header, TCP header and application-level data) across the network.

 

IP Header

 

·        Version

These bits describe which version of the Internet Protocol is in use. IP Version 4 is the one in widespread use all over the Internet.

·        IHL (Internet Header Length)

This field is the Internet Header Length, the total length of the IP header.

·        Service Type

This field is associated with quality of service QOS, indicating to network elements how sensitive the traffic might be to delays.

·        Total Length

This Identifies the total length of the IP packet, including the IP header and its data.

·        Identification

This field is used to support fragments reassembly.

·        Flags

This 2 are the “Don’t Fragment” bit, and the “More Fragments” bit:

 

Flag Bit1 (the don’t fragment bit):0=may fragment, 1=don’t fragment

Flag Bit2 (the more Fragment bit):0=last fragment, 1=more fragments.

·        Fragment Offset

This field is used to indicate where this fragment fits into the overall packet.

·        Time to Live (TTL)

This field is used to indicate the maximum number of router-to-router hops the packet should take as it crosses the network.

·        Protocol

This field describes the protocol (TCP/UDP) that is being carried by IP packet.

·        Header Checksum

This information is used to make sure the header dies not get corrupted. It is recalculated at each router hop.

·        Source IP Address

This field indicates the network and host where the packet is from.

·        Destination IP Address

This field indicates the network and host where the packet is going to.

·        Options

These variables length fields indicate extended information for the IP Layer. In particular, it is used in source routing.

·        Padding

This catch-all field is used to round out the length of the IP header so that it lines up on a 32-bit boundary.