Professional Documents
Culture Documents
Outline
5.1 Introduction
Application
Application
- Transport layer: end-to end layer not implemented in the intermediate routers - At sender: receives message from application layer encapsulate it in segment and send to network layer segmentation: breaks application messages into segments (smaller pieces) and passes them to network layer - At receiver: decapsulate segments - deliver messages to application layer
5-1
- The transport layer is responsible for process-to-process data delivery. - Provide logical communication processes running on different hosts between application
- Two processes communicate together - exchange messages between applications (e.g., email, file transfer, the Web) 5 - 2
1- End-to-End Delivery - The network layer treats each packet as an independent entry, even those belonging to a single message. - The transport layer oversees the end-to-end (source-todestination) delivery of an entire message maintains communication streams between applications.
5-3
2- Addressing - MAC address: Data link level protocols need to know which two computers within a network are communicating. - IP address: Network level protocols need to know which two computers within an internet are communicating. - Port number: Transport level protocols need to know which upper-layer protocols are communicating. - Multiple processes may be run at a host must have a unique identifier 3- Flow control - Flow control at this layer is performed end-to-end rather than across a single link. - Prevent the sender from overrunning the receiver
5-4
each process
1- Error Control - Error detection and retransmission. - Unlike error handling at the data link layer: this is end-toend error control 2- Sequence Control - At sender: An application layers messages is divided into segments
5-5
- At receiver: the original message is reassembled - Segments should be properly reassembled at the receiver - Transport layer adds a sequence number at each segment. This number indicates the order for reassembly. - Each segment carries a field that indicates whether it is the final segment or middle segment of a transmission. 3- Loss Control - Sequence numbers allow the receivers transport layer protocol to identify any missing segments and request redelivery. 4- Duplication Control - Sequence numbers allow the receiver to identify and discard duplicate segments.
5-6
5- Multiplexing - Sender may send several segments destined to different processes. Multiplexing: the segments should have enough information to be distributed to the correct processes. - Demultiplexing is needed at the receiver to distribute the segments to the correct processes
Note: - Handling process-to process communication cannot be handled by the data link layer because nodes would not know what happened two or more hops ahead of them, e.g., packets dropped, machine crashed, link failed Only ends can be sure of receipt/non-receipt of a message
5-7
5-8
Motivation: IP layer provides a best-effort service - need to build a reliable layer on top of IP
TCP Applications - Applications require 100% reliable data transfer to be effective all of the sent data arrive at the destination in its original condition, in order for the data to be useful. Any missing data could cause a corrupt communication that is either incomplete or unreadable. - Examples: WWW using HTTP, Electronic mail using SMTP, File transfer using FTP
5-9
2- UDP: User Datagram Protocol - Unreliable (best-effort), unordered data transfer received data can be out of order - corrupted duplicated missing, .. - Connectionless: No connection establishment before data transfer - No flow control and no congestion control - Full duplex
- UDP advantages
- UDP requires less overhead and offers faster performance than TCP - No delay for connection establishment UDP sends data without contacting the end host first - No congestion control: UDP can blast away as fast as desired
5 - 10
- Small packet header size: only 8 bytes - Simple: no connection state at sender and receiver No allocation of buffers, parameters easier to handle many clients at once
UDP Applications
1- Used for applications that can tolerate small amount of packet loss and require low delay to be effective: Multimedia applications, Internet telephony, real-time-video conferencing, Audio - For example, if one or two segments of a video stream fail to arrive, it would only create a momentary disruption in the stream. This may appear as distortion in the image but may not even be noticeable to the user.
5 - 11
2- An application that sends just one message, like Domain Name System (DNs). - TCP sends several packets of overhead before one single useful data message to establish a connection. - This does not mean that applications that use UDP are always unreliable. It simply means that these functions are not provided by the Transport layer protocol and must be implemented elsewhere if required. - DNS will simply retry the request if it does not receive a response, and therefore it does not need TCP to guarantee the message delivery
5 - 12
5 - 13
- Applications on end systems allows for rapid applications development and propagation - The process receives messages from, and sends messages into the network through its socket - A socket is the interface between the application layer and the transport layer within a host. - Sockets are the programming interface used to build network applications over the internet. - Create sockets with port number 6600: DatagramSocket mySocket1 = new DatagramSocket(6600); - Socket API is a library in C functions. - Socket is similar to a file descriptor controls a communication end point - Socket = API (application host or programming interface)
5 - 14
- Socket analogous to door - Sending process shoves message out door and relies on transport infrastructure on other side of door to transport message to socket at receiving process - Programmers can select which transport layer protocol (UDP or TCP) to be used by the application and select few transportlayer parameters (maximum buffer size, Maximum segment size, starting sequence number of segment). - Delivering the data: division of labor - Network: Deliver data packet to the destination host based on the destination IP address - Operating system: Deliver data to the destination socket based on the destination port number - Application: Read data from and write data to the socket
5 - 15
Addressing processes
- A single host may run several processes have identifier process must
- A port address: A unique number assigned to an application process as an address to receive or send data. - When a host receives a message, it needs to know which process should receive the message. - Port numbers are unique on each host cannot use same port number twice with same address, otherwise, the operating system cant demultiplex packets correctly - Port number uniquely identifies the socket - Operating system enforces uniqueness - Port numbers: 16-bit integer
5 - 16
Port numbers are divided in three ranges: 1- Well-known ports (numbers 0 to 1023) Popular applications have well-known ports assigned by the Internet Assigned Numbers Authority (IANA) See http://www.iana.org/assignments/port-numbers - e.g., port 80 for Web and port 25 for e-mail, 53 DNS, 21 FTP, 80 HTTP, 443 Secure HTTP(HTTPS) - Client applications can be programmed to request a connection to one of these ports and its associated service. 2- Registered Ports (numbers 1024 to 49151) - Not controlled by IANA but registers and lists the uses of these ports e.g., 1812 RADIUS Authentication protocol, 1863 MSN messengers
5 - 17
3- Dynamic or private ports (numbers 49152 to 65535) Can be assigned dynamically to client applications when initiating a connection. short-lived ports Client picks an unused ephemeral (i.e., temporary) port - Transport layer at the receiving host delivers data to the socket - There should be a unique identifier for each socket. - Socket identifier is called socket address = IP address and port number, e.g., 192.168.2.12:80 identifies each endpoint of a connection - A socket pair for a TCP connection is the four-tuple that defines the a TCP connection (client IP, client port, server IP, server port) - A socket pair uniquely identifies the traffic between the hosts
5 - 18
- While server processes have static port numbers assigned to them, clients dynamically chooses a port number for each conversation.
listening socket
10.19.0.115 server {*:21, *:*} server child {10.19.0.115:21, 10.3.3.137:49152} server child {10.19.0.115:21, 10.3.3.137:49153} listening socket
connected socket
connected socket
5 - 21
Typical client program:1- Prepare to communicate: create a socket, determine server address and port number, initiate the connection to the server 2- Exchange data with the server: Write data to the socket, read data from the socket 3- Close the socket Typical server program:1- Prepare to communicate: create a socket, associate local address and port with the socket, wait to hear from a client (passive open), accept an incoming connection from a client 2- Exchange data with the client over new socket: Receive data from the socket, do stuff to handle the request (e.g., get a file), send data to the socket 3- Close the socket
5 - 22
5 - 23
5 - 24
- Multiplexing (at the sending node): the process of encapsulating messages from different applications sockets with the header information and pass the segments to the network layer - The header information are later used for demultiplexing - Demultiplexing (at the receiving node): The process of delivering the received data segment to the correct application (socket) - Example: Suppose the following is running on the same computer: - Downloading a web page while transferring data through FTP and two telnet sessions (provide a bidirectional interactive text-oriented communication) are also running - Transport layer receives packets from network layer for all four processes 5 - 25
P4
P5
P6
application
P3
transport transport network link physical network link physical
P2
transport network link physical
P3
server: IP address B
host: IP address A
source IP,port: B,80 dest IP,port: A,9157 source IP,port: A,9157 dest IP, port: B,80
host: IP address C
- Three segments, all destined to IP address: B, destination port: 80 are demultiplexed to different sockets
5 - 27
Port: 6428
application
Port: 9266
application
P3
transport network link physical source port: 6428 dest port: 9157
P1
transport network link physical
P4
transport network link physical source port: 6428 dest port: 9266
- A server application that uses UDP serves only ONE request at a time. - All other requests are stored in a queue waiting for service.
5 - 28
Outline
5.1 Introduction
- A fixed-size header of 8 bytes - Source port: the sending port and the port to reply to if needed. If not used, then it should be zero. - Destination port: the destination port and is required. - Total Length (in bytes) of UDP segment, including header. It is between 8 and 65,535 bytes (8 byte header + 65527 bytes of data). 5 - 30
- Checksum: detect errors (e.g., flipped bits) in the entire UDP segment. Checked at receiver drop packet if error is detected
- Optional: The value sent for the checksum field is all 0s to show that the checksum is not calculated.
Example: The following is a UDP header in hexadecimal format: CB84000D001C001C a. What is the source port number? b. What is the destination port number? c. What is the total length of the user datagram? d. What is the length of the data? e. Is the packet directed from a client to a server or vice versa? 5 - 31
Solution a. The source port number is the first four hexadecimal digits (CB84)16 or 52100. b. The destination port number is the second four hexadecimal digits (000D)16 or 13. c. The third four hexadecimal digits (001C)16 define the length of the whole UDP packet as 28 bytes. d. The length of the data is the length of the whole packet minus the length of the header, or 28 8 = 20 bytes. e. Since the destination port number is 13 (well-known port), the packet is from the client to the server.
5 - 32
Outline
5.1 Introduction
- TCP is a connection-oriented protocol; it creates a virtual connection between two TCPs to send data. - TCP uses flow and error control mechanisms at the transport level. - Byte-stream: source application writes bytes - TCP sends segments destination application reads bytes - Each segment encapsulated in IP datagram - Full duplex: bi-directional data flow in same connection
5 - 33
- Point-to-point one sender, one receiver - Reliable, in-order delivery of a stream of bytes - Flow control: keep sender from overrunning receiver
Receiver limits the amount of data the sender can send at any time
- Congestion control: Prevents the sender from overloading
5 - 34
- Source port (16 bits): identifies the sending port - Destination port (16 bits): identifies the receiving port
5 - 35
- Sequence number field (32 bits): - Contains a number that uniquely identifies the segment - The identifier enables TCP receivers to identify when parts of a communication stream are missing. - Each TCP host self-assigns its own initial sequence number (ISN) - ISN is set during connection establishment. It is the sequence number of the actual first data byte. - For each segment, TCP host updates the sequence numbers to point to the position of the segments first data in the byte stream - Acknowledgement number field (32 bits): indicates the next expected sequence number from the other side of the communications.
5 - 36
TCP Data
TCP HDR
- Sequence Number/Acknowledgement Number Fields are used to be sure each packet has arrived, place segments in order, allow a specific segment to be acknowledged 5 - 37
- Header length (Hlen): header length in 4-byte words - value ranges from 5 to 15 - Checksum (16 bits): - The checksum is computed on the contents of the TCP header and data - Enables receiver to check if there is an error in the segment. - Window size (16 bits): - Advertised window size in bytes. Space remaining in receivers buffer and willing to accept. Number of bytes sender can send before receiving an ACK. - A window size of zero indicates that a sender should stop transmitting the receivers TCP buffer is full
5 - 38
Six 1-bit flags: play an important role in establishing, maintaining, and terminating a connection - URG (urgent pointer): The urgent pointer should be examined - ACK(acknowledgment): ACK sequence number is valid - PSH (push request): Do not delay delivery of data Inform receiver to send data to application as soon as possible bypass buffering and pass data to upper layer. - RST(Reset Request): Reset the connection (reject or abnormal termination) - SYN (Synchronization Request): Synchronize segment for setup - synchronize sequence numbers during connection. - FIN: Final segment for teardown - sender at end of byte stream - End of Transmission Marker
5 - 39
5 - 40
- Urgent pointer (16 bits): if the URG flag is set, then this 16-bit field is an offset from the sequence number indicating the last urgent data byte. - Options and padding: Rarely used - Padding (or dummy bits) may be needed to bring options to 32-bit boundary - up to 40 bytes of options. - Maximum segment (MSS) Option: the maximum amount of data receiver is willing to accept in each TCP segment - Window Scale Option - maximum window is 65,535 bytes (corresponding field in TCP header occupies 16 bits) -it can be scaled (left-shifted) by 0-14 bits providing a maximum of 65,535 * 214 bytes (one gigabyte) - Needed for high-speed connections or long delay paths
5 - 41
A
time
5 - 42
1- Connection request
5 - 43
1- Connection request message: - Objectives: 1- Ensure the destination host is available, has an active service and is accepting requests on the destination port number 2- Tells the destination that the initiator wants to open a connection and its initial sequence number and port number - Connection request from A to B, send a self-assigned initial sequence number (e.g., 8000) - SYN = 1 (remaining flags are 0) - Source port (e.g., 2352), destination port (e.g., 80 for http) 2- Connection confirmation message: - B tells A it accepts, and is ready to hear the next byte, Bs Initial Sequence Number
5 - 44
- Upon receiving this packet, A can start sending data with As initial sequence number + 1 - ACK for message 1 (ACK flag = 1), ACK sequence= 8000+1 - Connection request from B to A (SYN = 1) - Send initial sequence number (e.g., 1500) - The acknowledgement number is that of the next segment expected - it implicitly acknowledges all segments with smaller numbers (cumulative ACK) 3- Acknowledgement of confirmation message: - A tells B it is ok to start sending - Upon receiving this message, B can start sending data with Bs initial sequence number +1 - ACK for message 2 (ACK flag = 1), ACK sequence =1500+1 - The message may contain data
5 - 45
- Client: connection initiator - user clicks on a hypertext link - browser creates a socket and does a connect to trigger the operating system to transmit a SYN
Socket clientSocket = new Socket("hostname", "port number");
- What if the SYN packet gets lost, e.g., packet is lost inside the network, or server rejects the packet (e.g., listen queue is full)? No SYN-ACK arrives: sender sets a timer and wait for the SYN-ACK and retransmits the SYN if needed - How should the TCP sender set the timer? Sender has no idea how far away the receiver is - hard to guess a reasonable length of time to wait - some TCPs use a 5 - 46 default of 3 or 6 seconds
2- Data Transfer
5 - 47
- Sender: TCP transfers data as a continuous stream of bytes. - Receiver: TCP checks that data has been received. -Receiver: sends an acknowledgement giving the sequence number of the byte that it expects next.
Segment sent when: 1. Segment full (MSS bytes, default 352), 2. Not full, but times out, or 3. Pushed by application.
5 - 48
3- Connection termination
Using three-way handshaking
Requesting computer Responding computer
A
Disconnection request
Acknowledgement of confirmation
closed
5 - 49
1- Disconnection request message: (from A to B) - Client closes socket by invoking: clientSocket.close(); - Once client has sent all of the outstanding bytes, it sends TCP FIN control segment to server with finish flag (FIN) =1 - The FIN segment consumes one sequence number if it does not carry data. - Finish (FIN) to close and receive remaining bytes - Reset (RST) to close and not receive remaining bytes 2- Disconnection confirmation message: (from B to A) - ACK = 1, FIN = 1 - The segment consumes one sequence number if it does not carry data. 3- Acknowledgement of confirmation: from B to A, ACK = 1
5 - 50
Half-close
- A sends all its data and closes the connection - B closes it later after finishing data transmission
5 - 51
Failure Recovery
- When the system that the transport entity is running on fails and subsequently restarts, the state information of all active connections is lost - Affected connections become half open because the side that did not fail does not realize the problem - Still active side of a half-open connection can close the connection using a keep-alive timer - In some cases, reset (RST) segments can be used to close connections quickly (an abnormal termination). - Out of order segments could cause the FIN segment to arrive before the last data segment a connection may be closed before finishing data transfer - To avoid this, the next sequence number after the last one is assigned to FIN - each side must acknowledge the FIN of the other using this sequence number. 5 - 52
Netstat
- Shows protocol, local address and port number, foreign address and port number. - Unexpected connections may mean there is a security problem.
5 - 53
Sliding window
5 - 54
Receivers buffer:
- RcvBuffer: size of TCP Receive buffer - RcvWindow: amount of spare room in buffer - Application process may remove data from TCP socket buffer slower than the TCP receiver is delivering (sender is sending) - Or receiver host may be shared by many processes and cannot consume data received at the rate that sender host sends. - Speed-matching service: matching the sending rate to the receiving applications drain rate 5 - 55
- Receiver: explicitly informs sender of (dynamically changing) amount of free buffer space RcvWindow field in TCP ACK segment - Sender: keeps the amount of transmitted and unACKed data less than most recently received RcvWindow - Guarantees receiving buffer doesnt overflow - RcvWindow: Defines the amount of data that can be transmitted without receiving an acknowledgement. - Receiver can controls how many bytes are sent The receiver can increase or decrease the size of the sender window. - Sliding window at the transport layer is byte oriented rather than frame oriented. - The initial window size is determined during the session startup via the three-way handshake.
5 - 56
- An acknowledgment can expand the size of the sender window based on the sequence number of the acknowledged data segment. - The senders window size is dynamic and controllable by receiver. - Flow control is achieved by forcing the sender to wait for an acknowledgment Receiver Side
Advertised Window: Shrinks as data arrives and grows as the application consumes data
5 - 57
Q: What is the value of the receiver window (RcvWindow) for host A if the receiver, host B, has a buffer size of 5000 bytes and 1000 bytes of received and unprocessed data? A: The value of RcvWindow = 5000 1000 = 4000. Host B can receive only 4000 bytes of data before overflowing its buffer. Host B advertises this value in its next segment to A Flow Control can improve reliability and performance of TCP transmission 1- Prevent buffer overflow Reduce the chance of dropping segments at destination if the buffer is full avoid waste of resources 2- reduce the retransmissions in retransmissions avoid waste of resources
Flow Control Congestion control congestion control is about preventing too many 5 - 58 losses inside the network
- The receiver can temporarily shut down the window - Window size = 0 receiver asks the sender to stop transmitting data
5 - 59