400 likes | 583 Views
CMPT 371. Data Communications and Networking Principles of reliable data transfer. Transport Layer. Common protocols TCP and UDP UDP is best effort, no reliable delivery TCP insures reliable delivery
E N D
CMPT 371 Data Communications and Networking Principles of reliable data transfer
Transport Layer • Common protocols TCP and UDP • UDP is best effort, no reliable delivery • TCP insures reliable delivery • Remember the Transport layer is above a network layer that does provides an unreliable transmission channel (when IP is used) • TCP must compensate for the underlying unreliable channel to provide reliable transmission. This makes TCP much more complicated
Delivery • No flow control (UDP, best effort transmission): • Send data and hope receiver can process fast enough or buffer (with no overruns) • Packets are lost when queues/buffers overrun. • Slowing send speed enough to ensure reception will reduce utilization (efficiency) of the link • Flow control (TCP, reliable delivery) • TCP manages how fast packets are sent so that packet do not • Arrive faster than they can be processed • Overrun buffers / overwrite data
The transport layer • Processes use a transport protocol to communicate end to end. (reliably using TCP or best effort using UDP) • Data-link and network layer protocols communicate hop by hop, forming a communications channel for the transport layer • The transport layer shields the application processes from the details of the underlying communications channel • The transport layer specifies a particular application process as the source or destination. Lower layers specify at most the protocol in the next layer up
Transport layer protocols • Provide a logical (conceptual) link directly from the source to the receiver. • Applications using the transport layer interface see transport layer services that appear to connect them directly with applications on the destination host • The transport layer uses an interface to the network layer to initiate the physical transfer from host to host through the network to the destination. The details of these host to host transfers are not part of the transport layer. • The transport layer segments pass through multiple hosts on the way to the destination but the transport layer itself need not be directly aware of this since it is handled by lower layers in the protocol stack.
Using a relay (router) application application transport transport network network Data link Data link Network Physical Physical Data link Physical
Relay through intermediate hosts • As the packet travels from the source to the destination it will be processed by intermediate hosts. • Intermediate hosts may be other systems (computers) that use a full protocol stack • Only some layers in the stack will be used to relay the packet to its next destination along its path to the destination • The transport and application layers will be used only for packets who originate or are destined for the host
Using a relay (switch) application application transport transport network network Data link Data link Physical Physical Data link Physical
Relay through intermediate hosts • As the packet travels from the source to the destination it will be processed by intermediate hosts. • Intermediate hosts may be routers, switches, or hubs • Such devices will have only a partial protocol stack (only the layers needed to relay the packet) • Routers and network level switches will include the network layer and all layers below it. • Link layer switches and hubs will include only the link and physical layers
Transport layer protocols • May provide best effort delivery of packets (UDP) • Application accepts responsibility for reliability, connectionless • May provide a connection oriented reliable communication channel (TCP) either • On top of a best effort packet switched network (IP with unacknowledged connectionless link layer) • On top of a reliable network service (IP with acknowledged connectionless services in link layer)
Transport layer protocols • Support multiplexing • Combine multiple low rate flows through 1 port • Spread high rate flow between multiple ports
Responsibilities: transport level protocols • Addressing • Multiplexing • Flow control • Logical connection establishment • Logical connection maintenance • Logical connection termination • error control • ordered delivery to the application Connection oriented only Connection oriented and connectionless
Addressing • User specified by: • User identification • Specify Host and Port (socket or communication endpoint in TCP or UDP) • Port represents particular process or protocol, or a particular connection inside a process with more than one connection • Host is specified by an IP address • Several processes on a given machine may be multiplexed together and use a single protocol port
Addressing • Each port is identified by an integer • usually one port for of each protocol type (HTTP, FTP …). • Note that many of these ports will use TCP or UDP since many of the messages from application level protocols are transported using TCP or UDP
Responsibilities: transport layer protocols • Addressing • Multiplexing • Flow control (for TCP only, none for UDP) • Logical connection management (TCP only) • Error control If underlying network is best effort • Assure ordered delivery to the application if the underlying network is packet oriented
Multiplexing: application layer • Each connection is made between two sockets (communications endpoints) that each consist of a port:IP address pair. To describe the connection we need two port:IP address pairs. • Usually one port is used for of each application level protocol type on each host. So all segments for the particular application level protocol will pass through the same port (even if they are destined for different processes). • Determining which process (and connection within process) is done by the server for that process in the application layer of the host
Multiplexing: transport layer to application layer • Within the transport layer the UDP (or TCP) segments all arrive at the protocol process that processes UDP (or TCP) segments. • This process (part of the protocol stack) will demultiplex (separate) the TCP segments or UDP packets by port (protocol) • The segments or packets can then be sent to the correct server for the particular application level protocol. (sent through the correct port to the application layer)
Multiplexing: Arriving UDP packets are sent to the correct application or protocol implementation based on port # Protocol 1 Port A Application X Port B Protocol 3 Port C Application layer Transport layer UDP process in protocol stack Network layer
Multiplexing: transport layer to application layer • Many application level protocols are transported using UDP (or TCP). When segments arrive in the transport layer by UDP (or TCP) the port number may indicate that contents of the segment are destined for a particular application protocol. • Usually one port is used for of each application level protocol type on each host. So all segments for the particular application level protocol will leave the transport layer through the same port
Finding Port Addresses: 1 • Static configuration: • Know address ahead of time • Universal assignment: • Central authority (IANA) assigns port numbers to common protocols. The list is published • All software should use this list of protocols/ports • Any host receiving a particular application layer protocol will have a server process for that protocol running in its application layer. This server can be accessed through the assigned protocol port number • Ports 0-1023 are reserved for this IANA list • Ports 1024-49151 are registered (use list exists) not reserved
Finding Port Addresses: 2 • Name server: Server on a well known port can be queried to determine the port for the particular application. Name servers are generally used for providing different kinds of directory service
TCP server (Python) for socket import * serverPort = 1200 serverSocket = socket.socket(AF_INET, SOCK_STREAM) serverSocket.bind((‘ ‘,serverPort)) serverSocket.listen(1) print ‘The server is ready to receive’ while 1; connectionSocket.addr = serverSocket.accept() sentence = connetionSocket.recv(1024) capitalizedSentence = sentence.upper() connectionSocket.send(capitalizedSentence) connection Socket.close() :
TCP client (Python) from socket import * serverName = ‘servername’ serverPort = 1200 clientSocket = socket.socket(AF_INET, SOCK_STREAM) clientSocket.connect (serverName,serverPort) clientSocket.send (sentence) modifiedSentence = clientSocket.recv(1024) clientSocket.close;
Sequential server: • Server on a well know port that will process one request at a time. Requests will be queued as they arrive at the server. Useful for applications with low CPU needs or infrequent usage • timeserver, just returns the present time, low cpuusage
Instance or threaded server • Connect to Server through a well know port • Server creates an instance of itself to service the request • Server returns the appropriate port for the client to attach to that instance. • Many instances created by the instance server may run simultaneously. • Useful for heavily used applications and applications with significant processing needs • One example: FTP server, each instance may run for a significant length of time if it transfers a large file
12.106.32.254 Ephemeral port 1500, or 1501 is assigned by the protocol’s software server 206.168.112.219 *:21 *:* client1 206.168.112.2.19.: 1500 12.106.32.254 :21 Child server 12.106.32.254 :21 206.168.112.2.19.: 1500 client2 Child server 206.168.112.2.19.: 1501 12.106.32.254 :21 12.106.32.254 :21 206.168.112.2.19.: 1501
Responsibilities: transport layer protocols • Addressing • Multiplexing • Flow control (for TCP only, none for UDP) • Logical connection management (TCP only) • Error controlIf underlying network is best effort • Assure ordered delivery to the application if the underlying network is packet oriented
Error control • Error control includes the list of rules that tell us what to do if a packet contains an error. • Can we correct the error • If so correct the error and continue, otherwise • If the packet contains an error it should not be forwarded • The error may be in the address, it may get to the wrong destination
Error control • Error control includes the list of rules that tell us what to do if a packet contains an error. • Should we request that the source host retransmit the packet so we can obtain a correct copy of the packet • A good approach for reliable transport but not necessary for best effort transport • may be more complicated than it first appears • Should we just drop the packet • OK for best effort transport
Error detection • Before we can approach error control we need to know how to determine if there has been an error introduced into our packet during transmission • In the transport layer we use a checksum to determine if out packet contains errors. • The checksum is calculated at the source, and placed in the header of the packet • The packet is transmitted • The checksum is recalculated and compared with the checksum from inside the packet. If they match our packet usually does not contain errors.
Error detection • The mathematical theory behind the checksum allows us to assume that if the checksum is unchanged at the destination then the packet does not contain errors • a good assumption but in rare cases it can be false
Why Checksum in Transport layer • Error detection is used by Ethernet, in the data link layer, to check that packets are not corrupted as they travel between hosts • Other protocols in the data link layer may or may not use error detection • Therefore it is possible that some links are not error checked. • Also errors can occur after reception as when the packet is stored in the routers memory
Structure of a TCP packet SOURCE PORT DESTINATION PORT CHECKSUM Comer 2000: fig 13.7
The pseudo header: UDP, TCP • The constructed pseudo header is prepended to the TCP segment or UDP datagram before the checksum is calculated • The pseudo header is used to check that the segment has arrived at the correct address on the correct connection • Protocol can be TCP (6) or UDP (17) • Length is the length of the TCP segment including the TCP header or the UDP packet including header
Header + Pseudoheader • The TCP or UDP Header is transmitted with the datagram. The Pseudo header is not transmitted. • The checksum is the ones complement sum of all the 16 bit words in the datagram (data header and pseudo header) • Information in the pseudo header is calculated from information in the header, and from the IP address of the source and receiver from the IP layer (encapsulation?)
CheckSum • The checksum for a TCP segment is calculated in the same manner as the checksum for a UDP packet • The fields in the TCP or UDP header and pseudo header are divided into 16 bit words. These 16 bit words start on all 16 bit boundaries in the pseudo header the header and the data • A ones complement sum of all the 16 bit words in the packet header, the data, and the packet pseudo header is calculated • While this sum is being calculated the contents of the checksum field in the TCP header is set to 0 • The ones complement of the ones complement sum is inserted into the checksum field
the ones complement sum (1) • To find the ones complement sum of a series of binary numbers • Do a binary addition 1110 0011 1000 1110 0101 0101 0101 0101 10011 1000 1110 0011 • Shift the sum 16 places to the right (gives 1 for this example)
the ones complement sum (2) • Add the shifted value (1 in this case) to the binary sum • 10011100011100011 + 1 = 10011100011100100 • Take the least significant 16 digits to give the ones complement sum 0011100011100100 • The ones complement of this ones complement sum is the checksum 1100011100011011