You are on page 1of 100

TRANSPORT LAYER

Introduction

• • 1. 2.

3.
4. 5.

4th layer in the OSI layered structure. Provides logical communication between application processes running on different hosts It is responsible for reliable and cost effective data delivery. i.e. it ensures that packets are delivered error free, in sequence and with no losses or duplications. A high level of error recovery is also provided in this layer. The upper layer protocols depends heavily on the transport layer protocol. Without this layer the whole concept of layered protocols would make little sense. Functions of transport layer: This layer breaks messages into packets. It performs error recovery if the lower layers are not adequately error free. Function of flow control if not done adequately at the network layer. Functions of multiplexing and demultiplexing sessions together. This layer can be responsible for setting up and releasing connections across the network.

2

Introduction

3

transport and application layers is shown in fig. 4 . • The hardware and or software within the transport layer that does the work is called the transport entity.Services provided by Transport Layer • The transport layer makes use of the services provided by the network layer to provide services to the processes in the application layer. The transport entity can be located in the operating system kernel or in a separate user process or in the network interface card. • The relationship of the network.

A connection oriented service provides for the establishment. 3. maintenance and termination of a logical connection between transport service users. . User interface: there is no clear mechanism for user interface with the transport protocol. The transport entity may be capable of routing through secure links or nodes if such a service is available from the transmission facility. error control and sequenced delivery. 4. It provides encryption and decryption of data. Full duplex service must be provided.Services provided by Transport Layer 1. Data transfer: it transfers data between 2 transport entities. Types of service: the transport layer provides 2 types of services connection – oriented and connectionless or datagram service. Security : the transport entity may provide a variety of security services. 5 2. Both user data and control data must be transferred. It allows connection related features such as flow control.

measured over some time interval.Services provided by Transport Layer 5. Following are the transport layer QOS parameters: • Error and loss levels – measures the number of lost or garbled messages as a fraction of the total sent. • Desired average and maximum delay – measures the time between a message being sent by the transport user on the source machine and its being received by the transport user on the destination machine. High priority connections get serviced before low priority ones. • Priority level – provides a way for a transport user to indicate that some of its connection are more important than other ones. • Throughput – measures the number of bytes of user data transferred per second. • Resilience – gives problem of TL termination connection abruptly due to internal problems or congestion 6 . Quality of service: the transport protocol entity should allow the transport service user to specify the quality of transmission service to be provided.

Connection management: if connection oriented service is provided. the transport entity is responsible for establishing and terminating connections. Status reporting : it gives the following information – • Addresses • Performance characteristics of a connection • Class of protocol in use • Current timer values 7 . 7.Services provided by Transport Layer 6.

Transport Service Primitives • To allow users to access the transport services. Each transport service has its own interface. PARAMETER Connection oriented service Used by Transport Service Reliable End Users Network Service Unreliable Only transport layer. • Difference between transport service and network service. a transport service interface is required. 8 .

• When a frame arrives DLL processes the frame header and passes the contents of the frame payload field up to the network entity.Transport Service Primitives TPDU : transport protocol data unit • It is the message sent between transport entities. • The network entity processes the packet header and passes the contents of the packet payload up to the transport entity. • TPDUs are contained in packets which are in turn contained in frames. 9 .

Transport Service Primitives • • • • • • Consider an application with a server and a number of remote clients. It then unblocks the server and sends a CONNECTION ACCEPTED TPDU back to the client. Data can be exchanged using SEND and RECEIVE primitives. This blocks all process in the server until a client turns up. It can then process the TPDU and send a reply. The client’s CONNECT call causes a CONNECTION REQUEST TPDU to be sent to the server. To start with the server executes a LISTEN primitive. When the TPDU arrives the receiver is unblocked. The transport entity carries out this primitive by blocking the caller and sending a packet to the server. As long as both sides can keep track of whose turn it is to send this scheme works fine. When a client wants to talk to the server it executes a CONNECT primitive. When it arrives the transport entity checks to see that the server is blocked on a LISTEN. 10 . Encapsulated in the payload of this packet is a transport layer message for the server’s transport entity. When this TPDU arrives the client is unblocked and the connection is established.

When one side does a DISCONNECT that means it has no more data to send but it is still willing to accept data from its partner. These acknowledgements are managed by the transport entities and are not visible for transport users. which results in a DISCONNECT TPDU being sent to the remote transport entity. 11 . either transport user can issue a DISCONNECT primitive. Disconnection is of 2 types. independently of the other one. In this case a connection is released when both sides have done a DISCONNECT.Transport Service Primitives • • • • • Every data packet sent will also be acknowledged. Also it takes care about timers and retransmissions. When a connection is no longer needed. In the symmetric variant each direction is closed separately. In the asymmetric variant. it must be released to free up table space within the two transport entities. Upon arrival the connection is released. The packets bearing control TPDUs are also acknowledged.

Transport Service Primitives

A state diagram for a simple connection management scheme. Transitions labeled in italics are caused by packet arrivals. The solid lines show the client's state sequence. The dashed lines show the server's state sequence.

12

Berkley Sockets
• Another set of transport primitives used in UNIX for TCP. • These primitives are widely used for internet programming. • The first 4 primitives are executed in the same order.
13

Elements of Transport Protocols

• • •

The transport service is implemented by a transport protocol used between the two transport entities. In the DLL, it is not necessary for a router to specify which router it wants to talk to, but In the TL, explicit addressing of destinations is required. Connection set up over the wire of is simple, but in the TL, initial connection establishment is more complicated. A final difference between the DLL and TL is one of amount rather than of kind. Buffering and flow control are needed in both layers, but the presence of a large and dynamically varying number of connections in the transport layer may require a different approach than we used in the data link layer. In DLL, protocols may allocate a fixed number of buffers to each line, so that when a frame arrives a buffer is always available, but In TL, the larger number of connections that must be managed, and dedicating many buffers to each one is less attractive.

16

Elements of Transport Protocols  Addressing  Connection establishment and connection release  Flow control and buffering  Multiplexing  Crash recovery 17 .

 Application processes. both clients and servers can attach themselves to a TSAP to establish a connection to a TSAP. it must specify which one to connect to.Elements of Transport Protocols • Addressing  When an application process wishes to set up a connection to a remote application process. 18 . The method usually used is to define transport addresses to which processes can listen for connection requests.  The analogous end points in the network layer are then called NSAPs. These end points are called as TSAP(transport service access point). These connections run through NSAP’s on each host.

The time server process responds with the current time. The problem with this approach is how does the user process on host1 know that the time of day server is attached to TSAP 1522? In this model services have stable TSAP addresses that are listed in files which lists which servers are permanently attached to which ports. 19 . & issues a CONNECT request specifying TSAP 1208 as the source and TSAP 1522 as the destination. A transport connection is being established between the TL user process on host1 and server1 on host 2. An TL user process on host1 wants to find out the time-of-day. The transport connection is then released.Elements of Transport Protocols • • • • • • • • • A time of day server-process on host2 attaches itself to TSAP 1522 & wait for incoming call. A call such as LISTEN might be used. TL user process then sends over a request for the time.

In this instead of every conceivable server listening at a well known TSAP each machine that wishes to offer services to remote users has a special process server that acts as a proxy for heavily used servers. After it gets the incoming request. If no server is waiting for them. The new server then does the requested work. they get a connection to the process server. Potential users of a service begin by doing a CONNECT request.Elements of Transport Protocols • A better approach is designed called the initial connection protocol. 20 • • . specifying the TSAP address of the service they want. while the process server goes back to listening for new requests. It listens to a set of ports at the same time. the process server allows the requested server to inherit the existing connection with the user. waiting for a connection request.

store and duplicate packets. a sequence number incremented for each connection established) chosen by the initiating party and put in each TPDU including the one requesting the connection. In this approach each time a transport address is required. to see if it belonged to a previously released connection.Elements of Transport Protocols • Connection Establishment  When a communication link is made over a network (internet) problems can arise. it will no longer know which connection identifiers have already been used. If a machine crashes and loses its memory.  Another solution is to give each connection a connection identifier(i. 21 .  The drawback of this method is it requires each transport entity to maintain a certain amount of history information indefinitely. a new one is generated.e. When a connection is released the address is discarded and never used again.  Also a better possible solution is to not allow packets to live longer than known time in the subnet. Whenever a connection request comes in. it could be checked against the table.  One solution to the problem is to use throw – away transport addresses. After each connection is released each transport entity could update a table listing obsolete connections as pairs. The network can lose.

with the routers agreeing to discard any packet older than some agreed upon time. The network protocol simply discards any packet whose hop counter becomes zero. Timestamping each packet  The first method includes any method that prevents packets from looping. combined with some way of bounding congestion delay over the longest possible path. Putting a hop counter in each packet 3.  The second method consists of having the hop count initialised to some appropriate value and decremented each time the packet is forwarded.  The thirdmethod requires each packet to bear the time it was created. 22 . Restricted subnet design 2. This method requires the router clocks to be synchronised which is difficult to achieve.Elements of Transport Protocols • Connection Establishment  Packet lifetime can be restricted to a known maximum time using one or more of the following techniques: 1.

23 .  If a time T is waited after a packet has been sent.  Clock – binary counter – lSBs sequence no. it can be assured that all traces of it are gone and neither it nor its acknowledgements will appear suddenly. The multiple is protocol dependent and simply has the effect of making T longer.Elements of Transport Protocols • Connection Establishment  It is required to guarantee that a packet is dead and also all its acknowledgements are also dead.  Consider T as some small multiple of the true maximum packet lifetime.

Elements of Transport Protocols • Connection Establishment Three protocol scenarios for establishing a connection using a three-way handshake. CR denotes CONNECTION REQUEST. (b) Old CONNECTION REQUEST appearing out of nowhere. (c) Duplicate CONNECTION REQUEST and duplicate ACK. 24 . (a) Normal operation.

Elements of Transport Protocols • Connection Release 25 .

26 . (a) Normal case of a three-way handshake. (b) final ACK lost.Elements of Transport Protocols • Connection Release Four protocol scenarios for releasing a connection.

Elements of Transport Protocols • Connection Release 27 .

Elements of Transport Protocols • Flow control and buffering • Multiplexing • Crash control 28 .

The example Service primitives The example transport entity The example as a finite state machine. 29 .A simple Transport Protocol • A simple transport layer is discussed.

The Example Service Primitives
• CONNECT: a procedure that can be called with appropriate parameters necessary to establish a connection. The parameters are the local and remote TSAP’s. During the call, the caller is blocked while the transport entity tries to set up the connection. If the connection succeeds, caller is unblocked and can start transmitting data. • LISTEN: when a process wants to be able to accept incoming calls, it calls LISTEN specifying a particular TSAP to listen to. The process then blocks until some remote process attempt to establish a connection to its TSAP. • This model is asymmetric. One side is passive executing LISTEN and waiting until something happens where as the other side is active and initiates the connection. • Solution : -have the connection attempt fail if there is no listener at the remote TSAP. -have the initiator block until a listener appears. • The example uses the strategy of holding the connection request at the receiving end for a certain time interval. If a process on that host calls LISTEN before the timer goes off, the connection is established otherwise rejected and the caller is unblocked.

30

The Example Service Primitives
• DISCONNECT: procedure used to release connection. Symmetric disconnection is used in this model. • SEND and RECEIVE: used for data transmission. Data transmission is done similar to connection establishment. • Therefore there are 5 service primitives used. Each primitive corresponds to a library procedure that executes the primitive. • The parameters for the service primitives and library procedures are as follows: - connum = LISTEN (local) - connum = CONNECT (local,remote) - status = SEND (connum,buffer,bytes) - status = RECEIVE (connum,buffer,bytes) - status = DISCONNECT(connum)

31

The Example Transport Entity
• The transport layer makes use of the network service primitives to send and receive TPDUs. • A connection oriented network is chosen. It includes connection establishment, connection release and management. • In general transport entity may be part of host OS or some package of library routines in users space. Here it is considered to be a package of routines. • Interface to NL can be through procedures : to_net or from_net. • Each procedure has 6 parameters: 1.connection identifier 2. Q=1=>control message, 3. M=1 =>more data from this message follow next packet. 4. packet types: given above 5. pointer to data, 6.integer =>gives no. of data bytes.

33

• Sliding window protocols will be used. the transport entity fills in all the parameters for the NL to read. If the destination window doesn’t have space for a next/new packet then the transport entity is suspended till there is space for new /next packet. the NL organizes the incoming packet for the transport entity. 34 . • Also transport entity executes sleep and wakeup procedures. The procedure sleep is executed when the transport entity is logically blocked waiting for an arrival of a packet. • Network layer virtual circuit numbers are used as connection identifiers.The Example Transport Entity • When to_net is executed . • When from_ net is executed.

6. Idle – Connection not established yet. a packet arrives or the timer expires. 5. Waiting – CONNECT has been executed. 35 . Queued – A CALL REQUEST has arrived. 4. 2. no LISTEN yet. 3. DISCONNECTING – a DISCONNECT has been done locally. CALL REQUEST sent. • Trasnsitions between states occur when any of the following events occur : a primitive is executed.The Example Transport Entity • Each connection is in one of seven states: 1. 7. Receiving – A RECEIVE has been done. Sending – The user is waiting for permission to send a packet. Established – The connection has been established.

the NL is instructed to send a CALL REQUEST packet to the remote machine and the user is put to sleep. When SEND is called the transport entity checks to see if a credit has arrived on the specified connection. If not CALL REQUEST is queued for time out. • If so the message is sent and the credit is decremented else the transport entity goes to sleep mode till a credit arrives.The Example Transport Entity • When the user calls CONNECT. • If a LISTEN is done within this period. • When the CALL REQUEST packet arrives at the the other side . (go through the program from text) 36 . the transport entity is interrupted to run packet arrival procedure to check whether the local user is listening on the specified address. • As a result in this method data is transferred only when both hosts are ready and buffers are free to store the received data. the connection is established else it is rejected. • If so a CALL ACCEPTED packet is sent back and the remote user is awakened. • When a user calls RECEIVE a special credit message is sent to the transport entity on the sending machine and is recorded.

Columns represent the states and rows are the 12 events. 37 • • • • • • . an optional action. 5 primitives+6incoming packets+1Clock=12 events.The Example as a Finite State Machine • To reduce the chance of making an error. it is often useful to represent the state of the protocol as a finite state machine. Each entry has an optional predicate. The tilde indicates that no major action is taken. An overbar above a predicate indicate the negation of the predicate. and the new state. Blank entries correspond to impossible or invalid events.

The Example as a Finite State Machine 38 .

• UDP is a simple protocol and used in applications like client server interactions and multimedia. • In applications like internet where reliable and sequenced delivery is required TCP is used.Internet Transport Protocols • The internet has two main protocols in the transport layer. a connectionless protocol and a connection oriented protocol. 40 . • The connection oriented protocol is TCP – transmission control protocol. • The connectionless protocol is UDP – user datagram protocol.

Internet Transport Protocols . a user process or part of the kernel. • TCP checks for right sequence of datagrams an puts in right order. • A TCP entity accepts user data streams from local processes. When datagrams containing TCP data arrive at a machine. 41 . It was designed to dynamically adapt to properties of the internetwork and to be robust in case of failures. It also checks if any datagrams are lost and does retransmission. they are given to the TCP entity which reconstructs the original byte stream. In all cases it manages TCP streams and interfaces to the IP layer.TCP • TCP was specifically designed to provide a reliable end – to – end byte stream over an unreliable internetwork. either a library procedure. • Each machine supporting TCP has a TCP transport entity. breaks them into pieces not exceeding 64kb and sends each piece as a separate IP datagram.

A port is the TCP name for a TSAP. • Each socket has a socket number(address) consisting of IP address of the host and a 16 bit number local to that host called port. 42 . • For TCP service to be obtained.TCP. a connection must be explicitly established between a socket on the sending machine and a socket on the receiving machine.Service Model • TCP service is obtained by both the sender and receiver creating end points called sockets.

e (socket1. Connections are identified by the socket identifiers at both ends (i.TCP. Port 21 23 25 69 79 80 110 Protocol FTP Telnet SMTP TFTP Finger HTTP POP-3 Use File transfer Remote login E-mail Trivial file transfer protocol Lookup information about a user World wide web Remote email access 119 NNTP USENET news Some assigned ports 43 .Service Model • A socket may be used for multiple connections at the same time. No virtual circuit numbers are used. • Port numbers below 1024 are called well known ports and are reserved for standard services.socket2)).

A TCP connection is a byte stream. TCP does not support multicasting or broadcasting. not a message stream. these data may be delivered to the receiving process as four 512 byte chunks.TCP. • • • (a) Four 512-byte segments sent as separate IP datagrams. (b) The 2048 bytes of data delivered to the application in a single READ CALL. one 2048 byte chunk or some other way. Message boundaries are not preserved end to end.Service Model • All TCP connections are full duplex and point-to-point. two 1024 byte chunks. For ex: if the sending process does 4. Full duplex means that traffic can go in both directions at the same time. There is no way for the receiver to detect the units in which data were written. 512 byte writes to a TCP stream. 44 . Point-to-point means that each connection has exactly two end points.

However sometimes the application may really want the data to be sent immediately.TCP. • Sender can use URGENT flag to have TCP send data immediately and have the receiver TCP signal the receiver application that there is data to be read. TCP may immediately send or buffer data. 45 .Service Model • When an application passess data to TCP. • In such case sender can use a PUSH flag to instruct TCP not to buffer or delay but to send.

TCP – Service Model TCP Stream delivery TCP Sending & Receiving process TCP Segments 46 .

It may accumulate data from several writes in to one segment or split data from one write into several segments.TCP . Separate 32 bit sequence numbers are used for acknowledgements and for window mechanism. 47 . Second each network has a maximum transfer unit or MTU and each segment must fit in the MTU (generally MTU is 1500 bytes). segments may be lost or delayed. First a segment must fit in a single IP payload. Sending and receiving entities exchange data in segments.protocol • • • • • • Every byte on a TCP connection has its own 32 bit sequence number. Two limits restrict the segment size. Segments may reach on time but acknowledgements may not. Each TCP segment consists of 20 byte header and data (total up to 64K) TCP software decides how big segments should be. retransmissions may be different from that transferred earlier…hence it is TCP’s task to monitor all these problems and fix it.

535 .20 = 65. 48 . The fixed header may be followed by header options.495 data bytes may follow. 20byte header. • After the options. • Segments without any data are legal and are commonly used for acknowledgements and control messages. the first 20 refer to the IP header and the second to the TCP header.TCP – Segment Header • Every segment begins with a fixed-format.20 . up to 65. if any.

TCP – Segment Header 49 .

A port plus its host's IP address forms a 48bit unique end point. • The sequence & Acknowledgement number: Ack. Both are 32 bits long because every byte of data is numbered in a TCP stream. not the last byte correctly received.TCP – Segment Header • The Source & Destination port fields: give the local end points of the connection. indictes the next byte expected. No. 50 . The source and destination end points together identify the connection.

It indicates the start of the data • Next 6-bit field is not used. This is required because options field is of variable length. of 32-bit words that are contained in the TCP header.TCP – Segment Header • The TCP header length: gives no. • Then comes six 1-bit flags. 51 .

is valid. indicates to reset a connection that has become confused due to a host crash or some other reason.TCP Header flags • URG – urgent pointer in use indicates a byte offset from the current sequence number at which urgent data are to be found. No. • The PSH bit=1. 52 . ACK=0=> the segment does not have an ACK so the Ack. indicates PUSHed data. The receiver is hereby kindly requested to deliver the data to the application upon arrival and not buffer it until a full buffer has been received (which it might otherwise do for efficiency). It is also used to reject an invalid segment or refuse an attempt to open a connection. • The RST bit=1.no. field is ignored. • The ACK bit=1 to indicate that the Ack.

The connection reply does bear an acknowledgement. CONNECTION REQUEST . the closing process may continue to receive data indefinitely. CONNECTION ACCEPTED . after closing a connection. Both SYN and FIN segments have sequence numbers and are thus guaranteed to be processed in the correct order. The FIN bit is used to release a connection. However.TCP Header flags • • • The SYN bit is used to establish connections. Thus the SYN bit is used to denote CONNECTION REQUEST and CONNECTION ACCEPTED. so it has SYN = 1 and ACK = 1. with the ACK bit used to distinguish between those two possibilities. • 53 .The connection request has SYN = 1 and ACK = 0 to indicate that the piggyback acknowledgement field is not in use. It specifies that the sender has no more data to transmit.

a variablesized window) gives additional flexibility.1 have been received. In effect. The Window size field tells how many bytes may be sent starting at the byte acknowledged. In TCP. • • • • 54 . a receiver can say: I have received bytes up through k but I do not want any more just now. but that the receiver currently doesn’t want to receive anymore data. The receiver can later grant permission to send by transmitting a segment with the same Acknowledgement number and a nonzero Window size field.TCP – Segment Header • Window size field : Flow control in TCP is handled using a variable-sized sliding window. This decoupling (in fact. acknowledgements and permission to send additional data are completely decoupled. A Window size field of 0 is legal and indicates that bytes up to and including Acknowledgement number .

and the conceptual pseudo header. • 55 . It checksums the header. The checksum algorithm is simply to add up all the 16-bit words in one's complement and then to take the one's complement of the sum. When performing this computation.TCP – Segment Header • • A Checksum is also provided for extra reliability. including the Checksum field. when the receiver performs the calculation on the entire segment. the TCP Checksum field is set to zero and the data field is padded out with an additional zero byte if its length is an odd number. As a consequence. the result should be 0. the data.

• Options field: provides a way to add extra facilities not covered by the regular header. 56 . • It defines the number that must be added to the sequence number to obtain the number of the last urgent byte in the data section of the segment. • The most important option is the one that allows each host to specify the maximum TCP payload it is willing to accept.TCP – Segment Header • Urgent pointer: this 16 bit field is valid if the urgent flag is set and used when the segment contains urgent data.

57 . the protocol number for TCP (6) and the byte count for the TCP segment. • Including pseudoheader in the TCP checksum computation helps detect misdelivered packets. • UDP also uses same pseudoheader for its checksum.TCP Pseudoheader • It contains the 32 bit IP addresses of the source and destination machines.

The server program tells its TCP that it is ready to accept a connection. A client that wishes to connect to an open server tells its TCP that it needs to be connected to that particular server. This is called a request for a passive open. • The client program issues a request for an active open.TCP – Connection Establishment • Connections are established in TCP by means of the three way handshake. • The process starts with the server. 58 . server waits for an incoming connection by executing the LISTEN and ACCEPT primitives. Although the server TCP is ready to accept any connection from any machine it cannot make the connection itself. • Initially to set up a connection.

• and optionally some user data (e. 59 .(arbitrary/random) to initailize the first byte sent from client to server. • Sends Seq. the client issues a CONNECT primitive tells its TE: is active open to connect to a particular server • Specifies the IP address and port to which it wants to connect.TCP – Connection Establishment 1. • The CONNECT primitive sends a TCP segment with the SYN=1. a password). no. The other side.g. ACK=0 and waits for a response.. • the maximum TCP segment size it is willing to accept.

• If some process is listening to the port. the destination TE checks to see if there is a process that has done a LISTEN on the port given in the Destination port field. • It can then either accept or reject the connection. When this segment arrives. it sends a reply with the RST bit on to reject the connection. • If server accepts. no: initializes the first byte sent from server to client • It also defines the receive window used (to be used by client: for flow control) 60 .TCP – Connection Establishment 2. • SYN => connection segment • Seq. • If not.ACK=1 is sent back. then segment with SYN=1. that process is given the incoming TCP segment.

Does not use any new seq.TCP – Connection Establishment 3. • It also defines its receiving window size (to be used by server for sending) Simulataneous open: when both client & server try to establish connection with each other by sending Syn segments. • Acks the 2nd segment with ACK=1 and ack. single connection is established. No • Seq. no is same as the 1st segment. nos. Client accepts. and sends back 3rd segment: ACK segment. 61 .

• • • • • • • • • • • 63 .TCP – Data transfer (after connection is established) • • Can Bidirectional data transfer : piggybacked Data segment can have PSH set so that server tries to deliver data to server process as soon as it receives Pushing of data: TE maintains buffer for sending and receiving from remote m/c Queue is not be to used then there is flexibility for that using flag PSH Urgent data: As tcp is stream oriented Each byte has position in stream For situation where AL process has to send some urgent bytes Uses URG bit set in flags Puts them at the start of segment followed by normal data Hence uses offset : urgent offset The std TCP implemented does not ever deliver any data out of order.

TCP – State Diagram • • • • • The FSMs used by TCP client and server The first string on lines is i/p. 64 . solid lines: client Coloured lines: special conditions The common value for MSL is between 30 seconds and 1 minute. and second is O/P Dashed lines: by server.

The FIN + ACK segment consumes one sequence number if it does not carry data Send FIN segment : can include last chunk of data. or control segment that consumes one sequence number if it does not carry data. to confirm FIN segment rcd from server. The server informs its process abt FIN segment. : It carries no data and consumes no SN 65 . announces passive close(other direction) : also consumes 1 SN The client TCP sends ACK segment.TCP – Connection Termination • • • • • The FIN segment consumes one sequence number if it does not carry data. It uses ACK SN=last rcd SN in FIN segment from server+1. sends FIN+ACK (with last chunk of data or without data) to confirm.

TCP – Connection Termination Half Close: 66 .

001 (range: 10.000) Segment 4 ➡ Sequence Number: 13.001 (range: 12.000) TCP/IP Protocol Suite 67 . What are the sequence numbers for each segment if data is sent in five segments.000) Segment 2 ➡ Sequence Number: 11.001 to 11. The first byte is numbered 10001.001 (range: 11.001 to 15.000) Segment 5 ➡ Sequence Number: 14.001 to 14.001 (range: 14. each carrying 1000 bytes? Solution The following shows the sequence number for each segment: Segment 1 ➡ Sequence Number: 10.Suppose a TCP connection is transferring a file of 5000 bytes.000) Segment 3 ➡ Sequence Number: 12.001 to 13.001 (range: 13.001 to 12.

• • Uses a protocol similar to go back n and selective repeat.TCP – Flow Control • • • • • 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. Sender window size = minimum value of receiver window size or congestion window size. Go back n . Receiver window size is the value or the no. Uses byte oriented sliding window and variable size. TCP’s sliding windows are byte oriented. of bytes the receiver can accept. as no NAKs and selective repeat as out of order segments are not discarded. 68 . Window is open closed or shrunk. Congestion window value is given by network to avoid congestion.

The acknowledgment value.The server receives a packet with an ack value of 202 and an rwnd of 9. the window can slide over them. Show the new window. The value of cwnd is still 20. and 205. The host has already sent bytes 203. Solution: The window closes from the left and opens from the right by an equal number of bytes. the size of the window has not been changed. declares that bytes 200 and 201 have been received and the sender needs not worry about them. TCP/IP Protocol Suite 69 . 204. 202.

The host has not sent any new bytes. Show the new window. the size of the window has increased. so the size of the window is 12. The window has been opened from the right by 7 and closed from the left by 4. TCP/IP Protocol Suite 70 . Solution: The value of rwnd is less than cwnd.Now if the sender receives a packet with an ack value of 206 and an rwnd of 12. The value of cwnd is still 20.

Although the sender has not sent bytes 215 to 217. and 209. Show the new window. (An example on window shrinking) Solution: The value of rwnd is less than cwnd. TCP/IP Protocol Suite 71 . The host has sent bytes 206.Now the host receives a packet with an acknowledgment value of 210 and an rwnd of 5. 207. the receiver does not know this. so the size of the window is 5. 208. The value of cwnd is still 20.

If we add the acknowledgment number to rwnd we get the byte number following the right wall. TCP/IP Protocol Suite 72 . new ack + new rwnd ≥ last ack + last rwnd or new rwnd ≥ (last ack + last rwnd) − new ack • To avoid shrinking the sender window. the receiver must wait until more space is available in its buffer. If we want to prevent the right wall from moving to the left (shrinking). we must always have the following relationship.How can the receiver avoid shrinking the window in the previous example? Solution: The receiver needs to keep track of the last acknowledgment number and the last rwnd.

The Rx tells the next byte expected to receive. • Out-of-Order Segments: using SACK 73 .TCP – Error control • Checksum: used to check corrupt segment • Acknowledgment: data and control segments are acknowledged. rcd out of order. it reports extra info abt block of segment that is duplicated. It uses along with ACK defined above. a retransmission occurs if the RTO timer or 3-duplicate ACK segments have arrived. • Acknowledgment Type: • Cumulative ACK: uses ACK field only when ACK flag is set. but ACK segments are not acknowledged. TCP format doesn’t have provision hence uses an OPTION field • Retransmission: Common implementations. • Selective ACK(SACK): Recently used as TCP do not discard out of order.

TCP – Error control Normal operation 74 .

TCP – Error control Lost segment 75 .

TCP – Error control Fast retransmission 76 .

TCP – Error control Lost acknowledgements (a) before timer 77 .

Slow start phase 2. Congestion detection 78 . Congestion avoidance 3.TCP – Congestion control • Congestion policy: 1.

79 . the size of the congestion window increases exponentially until it reaches a threshold. Std threshold value is 65.TCP – Congestion control Slow start.exponential increase In the slow start algorithm.535 bytes.

TCP – Congestion control Congestion control – additive increase In the congestion avoidance algorithm the size of the congestion window increases additively until congestion is detected. 80 .

congestion 81 . ACKs. is by time-out.TCP – Congestion control Congestion detection – multiplicative decrease Most implementations react differently to congestion detection: • • If If detection starts. three a new a slow new start phase detection is by avoidance phase starts.

TCP – Congestion control Congestion example 82 .

• Persistence timer: used to deal with a zero window size advertisement. • Keepalive timer: used to prevent a long idle connection between 2 tcp’s. • Time –wait timer: used during connection termination.TCP timers • Retransmission timer: used to transmit lost segments. (refer TCP/IP protocol suite by behrouz forouzan for this topic) 83 . TCP needs another timer.

TCP timers • In TCP. smoothed RTTS Initially: after 1st transmission : RTTS =RTTM . RTT deviation: RTTD = (1-b) RTTD +(b) [RTTS .RTTD .RTTM]. there can be only be one RTT measurement in progress at any time. RTT deviation: RTTD = RTTM/2 After each transmission : RTTS =(a) RTTM +(1-a) RTTS . where (b=1/4) Retransmission Time out: RTO = RTTS +4. Measured RTTM . where (a=1/8) .

The RTO timer expires after 4.74 seconds. • This time an ACK is received before the time-out. We wait until we send a new segment and receive the ACK for it before recalculating the RTO Use earlier equation for RTO calculation . but lost. twice the previous value of RTO. • The segment is retransmitted and the timer is set to 9.Karn’s algorithm • The first segment in the figure is sent.48.

because it does not consume a sequence number and there is no time-out.625 RTTD = 3/4 (7.5) + 1/4 |1.74 • • • The sender does not start an RTT measurement when it sends the ACK segment.78 RTO = 1.5 RTTS = 1.75 = 4.5| = 0. No RTT measurement starts for the second data segment because a measurement is already in progress. .5) + 1/8 (2. TCP does not consider the RTT of a retransmitted segment in its calculation of a new RTO.5 RTTS = 7/8 (1.5 RTTD = 1.78) = 4.5 RTTM = 2. 0.5 / 2 = 0.5) = 1.625 + 4 (0.5 + 4 .75 RTO = 1.Congestion Example RTTM = 1.625 − 2.

• UDP is a very simple protocol using a minimum of overhead. unreliable transport protocol. • Sending a small message by using UDP takes much less interaction between the sender and receiver than using TCP or SCTP(stream control transmission protocol). • 87 .Internet Transport Protocols:UDP • It is a connectionless. • It also performs limited error checking. • UDP packets are called user datagrams and have a fixedsize header of 8 bytes. If a process wants to send a small message and does not care much about reliability it can use UDP. • It does not add anything to the services of IP except to provide process to process communication.

UDP Header 88 .

It is also 16 bits long. • Destination port number: this is the port number used by the process running on the destination host. 89 . which means that the port number can range from 0 to 65535. It is 16 bits long.UDP Header • Source port number: this is the port number used by the process running on the source host.

UDP length = IP length − IP header’s length Checksum: this field is used to detect errors over the entire user datagram. the UDP header. UDP checksum calculation is different from the one for IP and ICMP.UDP Header • Length : this is a 16 bit field that defines the total length of the user datagram. • • • 90 . Here the checksum includes three sections: a pseudoheader. and the data coming from the application layer. The 16 bits can define a total length of 0 to 65535 bytes. header and data.

91 .UDP . It is not delivered to the wrong host.Pseudoheader for checksum calculation • The pseudaheader is the part of the header of the IP packet in which the user datagram is to be encapsulated with some fields filled with 0’s. • The value of UDP in the protocol field is 17. • The protocol field is added to ensure that the packet belongs to UDP and not to other transport layer protocols. if the value is changed during transmission the checksum calculation at the receiver will detect it and UDP drops the packet.

UDP – checksum calculation 92 .

UDP – Operation • • • • • Connectionless service Flow and error control Encapsulation and decapsulation Congestion control Multiplexing and demultiplexing 93 .

which means each datagram can travel in different paths. There is no relationship between the different user datagrams even if they are coming from the same source process and going to the same destination process.UDP – connectionless service • Each datagram sent by UDP is an independent datagram. • The user datagrams are not numbered. • Also there is no connection establishment and no connection termination. 94 .

The receiver may overflow with incoming messages. unreliable transport protocol. 95 . • There is error control mechanism in UDP except for the checksum. This means that the sender doesn’t know whether a message is lost or duplicated. There is no flow control and hence no window mechanism. When the receiver detects an error through the checksum.UDP – flow and error control • UDP is a very simple. the user datagram is silently dsicarded.

UDP – encapsulation & decapsulation To send a message from one process to another. 96 . the UDP protocol encapsulates and decapsulates messages in an IP datagram.

It then passes the user datagram to IP with the socket addresses. • • • • 97 . It is then passed to the DLL. The DLL receives the IP datagram adds its own header and passes it to the physical layer.UDP – encapsulation & decapsulation • When a process has a message to send through UDP. IP adds its own header using the value 17 in the protocol field indicationg that the data has come from UDP. it passes the message to UDP along with a pair of socket addresses and the length of data. UDP receives the data and adds the UDP header. The physical layer encodes the bits into electrical or optical signals and sends it to the remote machine.

The IP does its own checking. 98 • • • .UDP – encapsulation & decapsulation • When the message arrives at the destination. UDP uses the checksum to check the entire user datagram. the header and trailer are dropped and the datagram is passed to the IP. the physical layer decodes the signals into bits and passes it to the DLL. The DLL uses the header to check the data. If there is no error. If there is no error the header is dropped and the user datagram is sent to UDP with the sender and receiver IP addresses. the header is dropped and the application data along with the sender socket address is passed to the process. If there is no error.

99 .UDP – congestion control • Since UDP is a connectionless protocol. UDP assumes that the packets sent are small and cannot create congestion in the network. it does not provide congestion control.

UDP – multiplexing & demultiplexing 100 .

• UDP accepts messages from different processes with different port numbers. 101 . UDP passes the user datagram to IP. After adding the header.UDP – multiplexing & demultiplexing • At the sender site there may be several processes that need to send user datagrams. However there is only one UDP. Hence multiplexing is required.

However there may be many processes that can receive user datagrams. • UDP receives user datagrams from IP. hence demultiplexing is required.UDP .demultiplexing • At the receiver site there is only one UDP. After error checking and dropping of the header. UDP delivers each message to the appropriate process based on the port numbers. 102 .

UDP Design 103 .

port number and corresponding queue number. • Output module: responsible for creating and sending user datagrams. • Input module: receives a user datagram from the IP. If the entry is found the module . input queues. process ID. • Control block table: used to keep track of the open ports. input module and output module. Each entry in this table has a minimum of 4 fields: the state (FREE or INUSE). If the entry is not found. • Control block module: responsible for the management of the control block table. it generates an ICMP message.UDP design • A UDP package involves 5 components: control block table. 104 . control block module. • Input queues: used one for each process. It searches the control block table to find an entry having the same port number as this user datagram.uses the information in the entry to enqueue the data.

• Refer to forouzan for problems 107 .