- Flow Control: a mechanism that enables the communicating hosts to negotiate how much data is transmitted each time with sliding window.
- Reliability service: a mechanism that guarantee the delivery of each packet by using sequence numbers and acknowledgments.
UDP is a connectionless and unacknowledged protocol. UDP only transmitts messages with "best effort", it does not check the delivery for segments. UDP depends on upper-layer protocols for reliability. Note that broadcast and unicast messages are carried by UDP. The protocols that use UDP include TFTP, SNMP, NFS and DNS.
The following is UPD segment structure.
|bits||0 - 15||16 - 31|
|0||Source Port||Destination Port|
The UDP header consists of only 4 fields. The use of two of those is optional (pink background in table). The following list is a brief explaination of the UDP header fields, here is the detailed explaination.
- Source port -- ID of the calling port.
- Destination port -- ID of the called port.
- Length -- Length of UDP header and UDP data.
- Checksum -- Calculated checksum of the header and data fields.
TCP is a connection-oriented, reliable protocol. TCP must establish a connection (a virtual circuit) between both ends user applications before transfer of information can begin. The services provided by TCP is running in the host computers at either end of a connection, not in the network. Therefore, TCP is a protocol for managing end-to-end connections. TCP is responsible for
- breaking a message passed down from the session layer into multiple segments,
- attaching a sequence number to each segment,
- passing the segments down to the network layer at the source station,
- veryfying each segment passed up from the network layer at the destination station,
- reassembling received segments into a message,
- and finally passing the message up to the session layer.
For a connection to be established, the two end stations must synchronize on each other's initial TCP sequence numbers. This initial exchange ensures that lost data can be recovered.
The following steps are followed in this initial synchronization:
- A --> B SYN - My sequence number is X
- A <-- B ACK - Your sequence number is X -1; expect X + 1 next
- A <-- B SYN - My sequence number is Y
- A --> B ACK - Your sequence number is Y -1; expect Y + 1 next
Because step 2 and 3 are combined into one message, it is called a three-way handshake. The following diagram might better illustrate this process.
TCP will return an acknowledgment to the sender upon receipt of one or more segments. There is a field called Acknowledgment number in the TCP segment. The receiving TCP use this field to tell the sending TCP which segment to receiving TCP expecting to receive next.
In case the sender transmitting too fast, the receiver will use a TCP flow control mechanism.
- Drop the segments: Failed acknowledgments alert the sender to slow down or stop sending.
- Set a smaller window size: Each TCP acknowledgement contains a field called window Size, which specifies the number of bytes that the receiving TCP is currently prepared to receive. Setting the window size to a smaller value allows less data to be processed in the future. More specific, the widow size is the number of data segments the sender is allowed to send before getting acknoledgment from the receiver. A smaller window size means the sending TCP has to wait for more acknowledgement in order to send the same amount of data, as a result, the time cause by these extra acknowledgment slows down the data transmission process.
TCP segment structure
|0||Source port||Destination port|
|96||Data offset||Reserved||CWR||ECE||URG||ACK||PSH||RST||SYN||FIN||Window Size|
The TCP header consists of 11 fields, of which only 10 are required. The eleventh field is optional (pink background in table) and is aptly named "options". The following list is a brief explaination of the TCP header fields, here is the detailed explaination.
- Source port (16 bits) – identifies the sending port
- Destination port (16 bits) – identifies the receiving port
- Sequence number (32 bits) – used to ensure correct sequencing of the arriving data
- Acknowledgment number (32 bits) – next expected TCP octet.
- Reserved (4 bits) – for future use and should be set to zero
- Flags (8 bits) (aka Control bits) – contains 8 1-bit flags
- Window (16 bits) – specifies the number of bytes that the receiver is currently willing to receive
- Checksum (16 bits) – The 16-bit checksum field is used for error-checking of the header and data
- Urgent pointer (16 bits) – Indicates the end of urgent data
- Options (Variable 0-320 bits, divisible by 32) – The length of this field is determined by the data offset field. Options 0 and 1 are a single byte (8 bits) in length. The remaining options indicate the total length of the option (expressed in bytes) in the second byte.
UDP vs. TCP
As seen in the above TCP and UDP segment diagrams, both use port numbers in the source and destination fields, not IP addresses. These port numbers are used to pass information to upper layers and also to keep track of different simultaneous network conversations. Port numbers identify the upper layer protocol that is using the transport.
IANA controlled some well-known port numbers which programmers agree to use. In the above example, some of the famous well known ports are displayed. port 21 for FTP, port 23 for Telnet, port 25 for SMPT, port 53 for DNS, port 69 for TFTP and port 161 for SNMP.
There are many difference between TCP and UDP.
- Guaranteed delivery
- Error detection and recovery: Sequence numbers and acknowledgments cover discarding duplicate packets, retransmission of lost packets, and ordered-data transfer. To assure correctness a checksum field is included.
- Windowing: the receiver specifies in the receive window field the amount of additional received data (in bytes) that it is willing to buffer for the connection. The sending host can send only up to that amount of data before it must wait for an acknowledgment and window update from the receiving host.
- Connection-oriented: use three-way handshake (SYN, SYN/ACK, ACK)
- no broadcasting and unicasting service
- best-effort delivery
- No error detection and recovery
- No windowing
- support broadcasting and multicasting
ICND1 and ICND2 break down