You are on page 1of 77

System Programming and Computer Control

CE00352-2-SPCC Client-Server Model: Socket Interface

Process-to-Process Delivery: UDP and TCP


Level-2

System Programming and Computer Control

Prepared by: KL First Prepared on: 9-09-07 Last Modified on: Quality checked by: xxx Process process delivery UDP and TCP Technology Copyright 2007 Asia to Pacific Institute of Information

Slide 1

Topic & Structure of the lesson


Process to Process Delivery

User Datagram Protocol (UDP)


Transmission Control Protocol (TCP)

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 2

Learning Outcomes
At the end of this session you should be able to: Understand rationale for the existence of the transport layer the need for process-to-process delivery.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 3

Key Terms you must be able to use


If you have mastered this topic, you should be able to use the following terms correctly in your assignments and exams: Client Client-server paradigm Connection establishment Connection termination Connectionless service Connection-oriented service Ephemeral port number Finite state machine Flow control Keep-alive timer Persistence timer Port number Process-to-process delivery Receiver window

Retransmission timer
Round-trip time (RTT) Segment Sender window

Sequence number
Server Silly windows syndrome

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 4

Key Terms you must be able to use


If you have mastered this topic, you should be able to use the following terms correctly in your assignments and exams:-

Sliding window Socket address State transition diagram

Transmission Control Protocol (TCP) User datagram User Datagram Protocol (UDP) Well-known port numbers

TCP timer
Three-way handshake Time-waited timer

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 5

Position of transport layer

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 6

Transport Layer
The transport layer is the core of the Internet model. It is the fourth layer in the model. This layer receives services from the network layer and provides services to the application layer. Function of transport layer (Duties)
Packetizing

Connection control
Addressing Providing reliability
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 7

Transport layer duties

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 8

Packetizing
The transport layer creates packets out of the message received from the application layer. Packetizing divides a long message into smaller ones and encapsulated into the data field of the transport-layer packet and headers are added.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 9

Connection control
There are two categories: Connection-oriented Delivery
Create virtual connection between sender and receiver The packets are numbered consecutively and communication can take place in both directions.

Connectionless Delivery
Treats each packet independently without connection between them.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 10

Addressing
The packet carrying the request must specify to which server program the request must be delivered.

The request packet must also specify the client program that sent the packet.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 11

Providing reliability
A transport layer can provide reliability for the application program that uses its service.
Flow Control
Performed end to end

Error Control
The entire message arrives at the receiving transport layer without error (damage, loss, or duplication). Error correction is usually achieved through retrasmission.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 12

Process-to-Process Delivery
Node-to-node delivery is responsible for delivery of frames between two neighboring nodes over link.

Host-to-host delivery is responsible for delivery of datagram between two hosts.


Process-to-process delivery communication takes place between two processes (application programs).
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 13

Note: The transport layer is responsible for process-to-process delivery.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 14

Types of data deliveries

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 15

Process-to-Process Delivery
1. 2. 3. 4. 5. Client-Server Paradigm Addressing Multiplexing and Demultiplexing Connectionless/Connection-Oriented Reliable/Unreliable

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 16

Client-server Paradigm
A process on the local host, called a client, needs services from a process usually on the remote host, called a server. Operating system today support both multiuser and multiprogramming environments. A remote computer can run several server programs at the same time, just as local computers can run one or more client programs at the same time.
Local host Local process Remote host Remote process
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 17

Addressing
A transport-layer address, called a port number, to choose among multiple processes running on the destination host.

The destination port number is needed for delivery; the source port number is needed for the reply. Ephemeral port number are 16-bit integers between 0 and 65,535.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 18

Port numbers

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 19

Addressing
The Internet has decided to use universal port numbers for servers; these are called wellknown port numbers. The IP addresses and port numbers play different roles in selecting the final destination of data.

The destination IP address defines the host among the different hosts in the world. After the host been selected, the port number defines one of the processes on this particular host.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 20

IP addresses versus port numbers

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 21

Address IANA Ranges


The IANA (Internet Assigned Number Authority) has divided the port numbers into three ranges:
Well-known ports. The port ranging from 0 to 1023 are assigned and controlled by IANA. Registered ports. The ports ranging 1024 to 49,151 are not assigned or controlled by IANA. They can only be registered with IANA to prevent duplication. Dynamic ports. The ports ranging from 49,152 to 65,535 are neither controlled nor registered. They can be used by any process.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 22

IANA ranges

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 23

Socket address

The combination of an IP address and a port number is called a socket address.


A transport-layer protocol needs a pair of socket addresses: the client socket address and the server socket address. The UDP and TCP header contains the port numbers.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 24

Multiplexing and demultiplexing


The addressing mechanism allows multiplexing and demultiplexing by the transport layer. Multiplexing: At the sender site, there may be several processes that need to send packets. The protocol accepts message from different processes. After adding the header, the transport layer passes the packet to the network layer.

Demultiplexing: At the receiver site, the transport layer delivers each message to the appropriate process based on the port number.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 25

Multiplexing and demultiplexing

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 26

Connectionless vs Connection-Oriented
A transport-layer protocol can either be connectionless or connection-oriented. Connectionless Service The packets are sent from one party to another with no need for connection establishment or connection release.

The packets are not numbered; they may be delayed, or arrive out of sequence.
There is no acknowledgment either. Example UDP.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 27

Connection Oriented Service


A connection is first established between the sender and the receiver. Data are transferred. At the end, the connection is released. Example: TCP is a connection-oriented protocol.
1. Host A sends a packet to announce its wish for connection and includes its initialization information about traffic from A to B. 2. Host B send a packet to acknowledge (confirm) the request of A. 3. Host B sends a packet that includes its initialization information about traffic from B to A. 4. Host A sends a packet to acknowledge (confirm) the request of B.

Connection Establishment

This connection establishment implies four steps. However, since steps 2 and 3 can occur at the same time, they can be combined into one step.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 28

Connection establishment

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 29

Connection Termination
Connection in one direction is terminated, the other party can continue sending data in the other direction. Therefore, four actions needed to close the connections in both directions:
1. Host A sends a packet announcing its wish for connection termination. 2. Host B sends a segment acknowledging (confirming) the request of A. After this, the connection is closed in one direction, but not in the other. Host B can continue sending data to A. 3. When host B has finished sending its own data, it sends a segment to indicate that it wants to close the connection.

4. Host A acknowledges (confirms) the request of B.

The four-step connection termination cannot be reduced to three steps because the two parties may not wish to terminate at the same time. In other words, connection termination is asymmetric.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 30

Connection termination

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 31

Reliable vs Unreliable
The transport-layer service can be reliable or unreliable. If the application-layer program needs reliability, we use a reliable transport-layer protocol by implementing flow and error control at the transport layer. This mean a slower and more complex service. UDP is connectionless and unreliable TCP is connection-oriented and reliable. These two can respond to the demands of the application-layer programs.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 32

Error control

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 33

User Datagram Protocol (UDP)


1. Port Numbers 2. User Datagram 3. Applications
UDP does not add anything to the services of IP except for providing process-toprocess communication instead of host-to-host communication. Also, it performs very limited error checking. UDP is very simple protocol with a minimum of overhead.

UDP is a convenient protocol for multimedia and multicasting applications.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 34

Note:

UDP is a connectionless, unreliable protocol that has no flow and error control. It uses port numbers to multiplex data from the application layer.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 35

Well-known ports used by UDP


Port 7 9 11 13 17 19 53 67 68 69 111 123 161 162
System Programming and Computer Control

Protocol Echo Discard Users Daytime Quote Chargen Nameserver Bootps Bootpc TFTP RPC NTP SNMP SNMP

Description Echoes a received datagram back to the sender Discards any datagram that is received Active users Returns the date and the time Returns a quote of the day Returns a string of characters Domain Name Service Server port to download bootstrap information Client port to download bootstrap information Trivial File Transfer Protocol Remote Procedure Call Network Time Protocol Simple Network Management Protocol Simple Network Management Protocol (trap)
Process to process delivery UDP and TCP

Slide 36

User Datagram Format


Source port number. This is the port number used by the process running on the source host. Destination port number. This is the port number used by the process running on the destination host. Length. This is a 16-bit field that defines the total length of the user datagram, header plus data. Checksum. This field is used to detect errors over the entire user datagram (header plus data). This ensures that those fields have not been changed from the source to the destination. The calculation of the checksum and its inclusion in a user datagram are option. If the checksum is not calculated, the field is filled with 0s.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 37

User datagram format

UDP Packets, called user datagrams, have a fixed-size header of 8 bytes.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 38

Note: The calculation of checksum and its inclusion in the user datagram are optional.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 39

Application of UDP
UDP is suitable for a process that requires simple request-response communication with little concern for flow and error control. It is not usually used for a process that needs to send bulk data, such FTP. Internal flow and error control mechanisms. Multicasting capabilities are embedded in the UDP software but not in the TCP software. UDP is used for some route updating protocols such as Routing Information Protocol (RIP) UDP is used in conjunction with the Real Time Transport Protocol (RTP) to provide a transport-layer mechanism for real-time data.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 40

Note:

UDP is a convenient transport-layer protocol for applications that provide flow and error control. It is also used by multimedia applications.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 41

Transmission Control Protocol (TCP)


TCP is called a stream connection-oriented and reliable transport protocol. Port Numbers Services Sequence Numbers Segments Connection Transition Diagram Flow and Error Control Silly Window Syndrome
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 42

Port Numbers
Like UDP, TCP uses port numbers as tranportlayer addresses. If an application can use both UDP and TCP, the same port number is assigned to this application.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 43

Well-known ports used by TCP


Port 7 9 Protocol Echo Discard Description Echoes a received datagram back to the sender Discards any datagram that is received

11
13 17 19 20 21 23 25 53

Users
Daytime Quote Chargen FTP, Data FTP, Control TELNET SMTP DNS

Active users
Returns the date and the time Returns a quote of the day Returns a string of characters File Transfer Protocol (data connection) File Transfer Protocol (control connection) Terminal Network Simple Mail Transfer Protocol Domain Name Server

67
79 80 111

BOOTP
Finger HTTP RPC

Bootstrap Protocol
Finger Hypertext Transfer Protocol
Process to process delivery UDP and TCP

System Programming and Computer Control

Remote Procedure Call

Slide 44

Stream delivery
TCP, is steam-oriented protocol. In UDP, a process (an application program) sends a chunk of bytes to UDP for delivery. UDP adds its own header to this chunk of data, which is now called a user datagram, and delivers it to IP for transmission. The process may deliver several chunks of data to the UDP, but UDP treats each chunk independently without seeing any connection between them. TCP, on the other hand, allows the sending process to deliver data as a stream of bytes and the receiving process to obtain data as a stream of bytes. TCP creates an environment in which the two processes seem to be connected by an imaginary. tube that carries their data across the Internet.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 45

Stream delivery

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 46

Sending and receiving buffers


The sending and the receiving processes may not produce and consume data at the same speed. TCP needs buffers for storage.

There are two buffers, the sending buffer and the receiving buffer, for each direction.
One way to implement a buffer is to use a circular array of 1-byte locations.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 47

Sending and receiving buffers

At the sending site, the buffer has three types of locations. The white section contains empty locations that can be filled by the sending process. The blue area hold bytes that have been sent but not yet acknowledged. The bytes in blue locations area acknowledged, the location is recycled and available for use by the sending process. After both processes have no data left to send and the buffers are empty, the two TCPs destroy their buffers.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 48

TCP segments
TCP groups a number of bytes together into a packet called a segment. TCP adds a header to each segment and delivers the segment to the IP layer for transmission. The segments are encapsulated in an IP datagram and transmitted.

The segments are not necessarily the same size. In reality segments carry hundreds, if not thousands, of bytes.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 49

TCP segments

There is no field for a segment number value. Instead, there are two field called the sequence number and the acknowledgment number. These two fields refer to the byte number, not the segment number.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 50

Byte Numbers
TCP numbers all data bytes that are transmitted in a connection. Numbering is independent in each direction.

When TCP receives bytes of data from the process and stores them in the sending buffer, it numbers them. The numbering does not necessary start from 0; it starts with a randomly generated number between 0 and 232 1.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 51

Note: The bytes of data being transferred in each connection are numbered by TCP. The numbering starts with a randomly generated number.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 52

Example 1
Imagine a TCP connection is transferring a file of 6000 bytes. The first byte is numbered 10010. What are the sequence numbers for each segment if data are sent in five segments with the first four segments carrying 1000 bytes and the last segment carrying 2000 bytes?

Solution
The following shows Segment 1 ==> Segment 2 ==> Segment 3 ==> Segment 4 ==> Segment 5 ==>
System Programming and Computer Control

the sequence number for each segment: sequence number: 10,010 (range: 10,010 sequence number: 11,010 (range: 11,010 sequence number: 12,010 (range: 12,010 sequence number: 13,010 (range: 13,010 sequence number: 14,010 (range: 14,010
Process to process delivery UDP and TCP

to 11,009) to 12,009) to 13,009) to 14,009) to 16,009)

Slide 53

Note:

The value of the sequence number field in a segment defines the number of the first data byte contained in that segment.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 54

Note:
The value of the acknowledgment field in a segment defines the number of the next byte a party expects to receive. The acknowledgment number is cumulative.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 55

TCP segment format


The unit of data transfer between two devices using TCP is a segment. The segment consist of a 20- to 60-byte header, followed by data from the application program. The header is 20 bytes if there are no options and up to 60 bytes if it contains options.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 56

TCP segment format

Next slide discuss the above header fields


System Programming and Computer Control Process to process delivery UDP and TCP

Slide 57

Header
Source port address: This is a 16-bit field that defines the port number of the application program in the host that is sending the segment. Destination port address: receiving the segment. Sequence number: defines the number assigned to the first byte of data contained in this segment (range 232). To ensure connectivity, each byte to be transmitted is numbered. The sequence number tells the destination which bytes in this sequence comprises the first byte in the segment.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 58

Header
Acknowledgment number: This 32-bit field defines the byte number that the sender of the segment is expecting to receive from the other party. If the byte numbered x has been successful received, x+1 is the acknowledgment number. Header length: This 4-bit field indicates the number of 4-byte words in the TCP header. The length of the header can be between 20 and 60 bytes. Therefore, the value of this field can be between 5 (5x4 = 20) and 15 (15x4 =60). Reserved: This field defines 6 different control bits or flags which can be set at a time. These bits enable flow control, connection establishment and termination, and the mode of data transfer in TCP.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 59

Control field

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 60

Description of flags in the control field

Flag
URG ACK PSH RST SYN FIN

Description
The value of the urgent pointer field is valid. The value of the acknowledgment field is valid. Push the data. The connection must be reset. Synchronize sequence numbers during connection. Terminate the connection.

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 61

Three-step connection establishment

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 62

Four-step connection termination

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 63

States for TCP


State CLOSED LISTEN SYN-SENT SYN-RCVD There is no connection. The server is waiting for calls from the client. A connection request is sent; waiting for acknowledgment. A connection request is received. Description

ESTABLISHED Connection is established. FIN-WAIT-1 FIN-WAIT-2 TIME-WAIT CLOSE-WAIT


System Programming and Computer Control

The application has requested the closing of the connection. The other side has accepted the closing of the connection. Waiting for retransmitted segments to die. The server is waiting for the application to close.
Process to process delivery UDP and TCP

Slide 64

State transition diagram

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 65

Note: A sliding window is used to make transmission more efficient as well as to control the flow of data so that the destination does not become overwhelmed with data. TCPs sliding windows are byte-oriented.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 66

Sender buffer

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 67

Receiver window

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 68

Sender buffer and sender window

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 69

Sliding the sender window

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 70

Expanding the sender window

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 71

Shrinking the sender window

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 72

Note: In TCP, the sender window size is totally controlled by the receiver window value (the number of empty locations in the receiver buffer). However, the actual window size can be smaller if there is congestion in the network.
System Programming and Computer Control Process to process delivery UDP and TCP

Slide 73

Note: Some points about TCPs sliding windows:


The source does not have to send a full windows worth of data.
The size of the window can be increased or decreased by the destination. The destination can send an acknowledgment at any time.
Process to process delivery UDP and TCP

System Programming and Computer Control

Slide 74

Lost segment

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 75

Lost acknowledgment

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 76

TCP timers

System Programming and Computer Control

Process to process delivery UDP and TCP

Slide 77

You might also like