TransportLayer TCP UDP

download TransportLayer TCP UDP

of 29

Transcript of TransportLayer TCP UDP

  • 8/11/2019 TransportLayer TCP UDP

    1/29

    1

    The Transport LayerThe Internet Transport Protocols

    TCP and UDP

  • 8/11/2019 TransportLayer TCP UDP

    2/29

    2

    Overview

    Intro

    The TCP Service Model

    The TCP Protocol

    The TCP Segment Header TCP Connection Management

    TCP Transmission Policy

    TCP Congestion control TCP Timer management

    UDP

  • 8/11/2019 TransportLayer TCP UDP

    3/29

    3

    Transport Layer in the Internet

    The Internet has two main protocolsin the transport layer a connectionorientedprotocol, and aconnectionlessone. We will study

    both of them. The connection oriented protocol is

    TCP.

    The connectionless is UDP. Because UDP is basically just IP with

    a short header added, we will focus

    on TCP.

  • 8/11/2019 TransportLayer TCP UDP

    4/29

    4

    Intro

    TCP (Transmission Control Protocol)wasspecifically designed to provide a reliableend-to-end byte streamover an unreliableinternetwork.

    An internetwork differs from a singlenetwork because different parts may havequite different topologies, bandwidth,delays, packet sizes, and otherparameters. TCP was designed todynamically adaptto properties of theinternetwork and to be robustin the faceof many kinds of failures.

  • 8/11/2019 TransportLayer TCP UDP

    5/29

    5

    Intro Each machine supporting TCP has TCP transport

    entity, either a user process or part of the kernel,which manages TCP streams and interfaces tothe IP layer.

    A TCP entity accepts user data streams fromlocal processes, breaks them up into pieces not

    exceeding 64K bytes, and sends each piece as aseparate IP datagram.

    When IP datagrams containing TCP data arrive ata machine, they are given to the TCP entity,which reconstructs the original byte streams.

    The IP gives not guaranteethat datagrams willbe delivered properly, so it is up the TCPto timeout and retransmit them as need be. Datagramsthat do arrive may well be in the wrong order; itis also up to the TCP to reassemble them intomessages in proper sequence.

  • 8/11/2019 TransportLayer TCP UDP

    6/29

    6

    The TCP Service Model TCP Service is obtained by having both the

    sender and receiver create end points,called sockets. Each socket has a socketnumber (address)consisting of the IPaddress of the host and a 16-bit number

    local to that host, calleda port. To obtain TCP service,a connection must

    be explicitly established between a socketon the sending machine and a socket on

    the receiving machine. A socket may be used for multiple

    connections at the same time. In otherwords, two or more connections may

    terminate at the same socket.

  • 8/11/2019 TransportLayer TCP UDP

    7/29

    7

    The TCP Service Model Port numbers below 1024are called well-known

    portsand are reserved for standard services. For

    example, any process wishing to establish aconnection to a host to transfer a file using FTPcan connect to the destination hosts port 21 tocontact its FTP daemon/service. Similarly, toestablish a remote login session using TELNET, port

    23 is used. Port 80 is used for HTTP, port 443 isused for SSL, etc.

    Ports between 1024 and 5000are called ephemeraland are free to use (not reserved). The clients

    socket would use such port. All TCP connections are full-duplexand point-to-

    point. Full duplex means that traffic can go in bothdirections at the same time. Point-to-point meansthat each connection has exactly two end points.

    TCP does not support multicasting or broadcasting.

  • 8/11/2019 TransportLayer TCP UDP

    8/29

    8

    A TCP connection is byte stream, not amessage stream. Message boundaries arenot preserved end to end.

    For example, if the sending process doesfour 512-byte writes to a TCP stream,these data may be delivered to thereceiving process as four 512-bytechunks, or two 1024-byte chunks, or one2048-byte chunk, or some other way.

    When an application passes data to TCP,TCP maysend it immediately or bufferit(in order to collect a larger amount tosend at once), at its discretion.

    The TCP Service Model

  • 8/11/2019 TransportLayer TCP UDP

    9/29

    9

    The TCP Protocol

    Every byte on a TCP connection has its own 32-

    bit sequence number. The sending and receiving TCP entities exchange

    data in the form of segments. A segmentconsists of a fixed 20-byte header (plus an

    optional part) followed by 0 or more data bytes.The TCP software decides how big segmentsshould be. It can accumulate data from severalwrites into one segment or split data from onewrite over multiple segments.

    Two limits restrict the segment size: Each segment, including the TCP header, must fit in the

    64K byte IPpayload

    Each network has a maximum transfer unitor MTU, andeach segment must fit in the MTU.

  • 8/11/2019 TransportLayer TCP UDP

    10/29

    10

    The TCP Protocol A segment that is too large for a network that it

    must transit can be broken up into multiple

    segments by a router. Each new segment gets itson IP header (20 bytes), so fragmentation byrouters increases the total overhead.

    The basic protocol used by TCP entities is the

    sliding window protocol: when a sender transmits a segment, it also starts a

    timer

    when the segment arrives at the destination, the

    receiving TCP entity sends back a segment bearingan acknowledgmentnumber equal to the nextsequence number it expects to receive

    if the senders timer goes off before theacknowledgment is received, the sender transmitsthe segment again

  • 8/11/2019 TransportLayer TCP UDP

    11/29

    11

    The TCP Protocol Although this protocol sounds simple, there

    are some details/issuesto be addressed: Since segments can be fragmented, it is possible

    that part of a transmitted segment arrives butthe rest is lost and never arrives.

    Segments can also arrive out of order, for

    example, bytes 3072-4095 can arrive but cannotbe acknowledged because bytes 2048-3071 havenot come yet.

    Segments can also be delayed so long in transitthat the sender times out and retransmits them.

    If a retransmitted segment takes a differentroute than the original, and is fragmenteddifferently, bits and pieces of both the originaland the duplicate can arrive sporadically,requiring careful administration to achieve areliable byte stream.

  • 8/11/2019 TransportLayer TCP UDP

    12/29

    12

    The TCP Protocol

    Finally, with so many networks making up the

    Internet, it is possible that a segment mayoccasionally hit a congested (or broken) networkalong its path.

    TCP must be prepared to deal with theseproblems and solve them in an efficientway.

    A considerable effort has gone intooptimizing the performance of TCP streams,even in the face of network problems. Wewill discuss some algorithms next.

  • 8/11/2019 TransportLayer TCP UDP

    13/29

    13

    The TCP Segment Header

    Every segment begins with a fixed-format

    20-byte header. The fixed header may be followed by header

    options.

    After the options, if any, up to 65,535 2020 = 65, 495 data bytes may follow,where the first 20 refers to the IP headerand the second to the TCP header.

    Segments without any data are legal andare commonly used for acknowledgmentsand control messages.

  • 8/11/2019 TransportLayer TCP UDP

    14/29

    14

    Fig. 1. The TCP header

    The TCP Segment Header

  • 8/11/2019 TransportLayer TCP UDP

    15/29

    15

    Source portand Destination portidentify the

    local end points of the connection. Sequence numberand acknowledgement number

    (specifies the next sequence number expected)

    TCP header lengthtells now many 32-bit wordsare contained in the TCP header (becauseOptions field is of variable length)

    Next comes a 6-bit field that is not used.

    Next come 6 1-bit flags: URGis set to 1 if the Urgent pointer is in use. The

    Urgent Pointer is used to indicate a byte offset (from thecurrent sequence number) at which urgent data islocated

    ACKis set to 1 to indicate that the acknowledgementnumber field is valid. Otherwise, if set to 0, then thissegment does not contain an acknowledgment

    The TCP Segment Header

  • 8/11/2019 TransportLayer TCP UDP

    16/29

    16

    PSHbit indicates PUSHed data. The receiver hereby

    kindly requested to deliver the data to the applicationupon arrival and not buffer it (done for efficiency)

    RSTbit is used to reset a connection that has becomeconfused due to a host crash or some other reason. It isalso used to reject an invalid segment or refuse an

    attempt to open a connection. SYNbit is used to establish connections. SYN=1 and

    ACK=0 connection request, SYN=1 and ACK=1 connection accepted.

    FINbut is used to release a connection. It specifies that

    the sender has no more data to transmit.

    Window sizefield tells how many bytes may besent starting at the byte acknowledged.

    The TCP Segment Header

  • 8/11/2019 TransportLayer TCP UDP

    17/29

    17

    A Checksumis also provided for extreme

    reliability it checksums the header andthe data.

    Optionsfield was designed to provide away to add extra facilities not covered bythe regular header. For example, alloweach host to specify the maximum TCP

    payload it is willing to accept. (using largesegments is more efficient than usingsmall ones)

    The TCP Segment Header

  • 8/11/2019 TransportLayer TCP UDP

    18/29

    18

    TCP Connection Management

    Connections are established in TCPusing a three-way handshake: Host 1 chooses a sequence number, x, and

    sends a CONNECTION REQUEST containing it

    to host 2. Host 2 replies with CONNECTION ACCEPTED

    acknowledgment x, and announcing its owninitial sequence number, y.

    Finally Host 1 acknowledges host 2s choice ofan initial sequence number in the first datathat it sends.

  • 8/11/2019 TransportLayer TCP UDP

    19/29

    19

    Fig. 2. TCP connection

    establishment

    TCP Connection Management

    To establish a connection, one

    side, say a server, passivelywaits for an incomingconnection by executingLISTEN and ACCEPT primitives

    The other side, say a client,

    executes a CONNECT primitive,specifying the IP address andport to which it wants toconnect, and the max TCPsegment size it is willing toaccept

    The CONNECT primitive sendsa TCP segment with the SYNbit = 1 and ACK = 0 and waitsfor a response

  • 8/11/2019 TransportLayer TCP UDP

    20/29

    20

    When this segment arrivesat the destination, the TCPentity there checks to see ifthere is a process that hasdone a LISTEN on the portgiven in the Destination portfield. If not, it sends a reply

    with the RST bit on to rejectthe connection.

    If some process is listeningon the port, that process isgiven the incoming TCP

    segment. It can eitheraccept or reject theconnection. If it accepts, anacknowledgment segment issent back.

    TCP Connection Management

    TCP Transmission Polic

  • 8/11/2019 TransportLayer TCP UDP

    21/29

    21

    TCP Transmission Policy Window management in TCP is not tied to

    acknowledgments as it is in most data linkprotocols.

    For example: suppose that the receiver has a 4095-byte buffer.

    If the sender transmits a 2048-byte segment that iscorrectly received, the receiver will acknowledge thesegment.

    However, since it now has only 2048 of buffer space (untilthe application removes some data from the buffer), it willadvertise a window of 2048 starting a the next byteexpected.

    Now the sender transmits another 2048 bytes, which are

    acknowledged, but the advertised window is 0. The sender must stop until the application process on the

    receiving side has removed some data from the buffer.Then, TCP can advertise a larger window.

    There are two exceptions: urgent data may be sent (ex. toallow user to kill the process), or send 1 byte to make thereceiver re-announce the window (in case it was lost)

  • 8/11/2019 TransportLayer TCP UDP

    22/29

    22

    When the load offered to any networks is

    more than it can handle, congestion buildsup. The Internet is no exception.

    Algorithms have been developed over thepast decade to deal with congestion.

    Although the network layer also tries to

    manage congestion, most of the heavylifting is done by TCP because the realsolution to congestion is to slow down thedata rate.

    TCP Congestion Control

    TCP C ti C t l

  • 8/11/2019 TransportLayer TCP UDP

    23/29

    23

    TCP Congestion Control

    Fig. 3. (a) A fast network feeding a low capacity receiver

    (b) A slow network feeding a high capacity receiver

  • 8/11/2019 TransportLayer TCP UDP

    24/29

    24

    In theory congestion can be dealt with by

    employing a principle borrowed fromphysics: the law of conservation ofpackets. The idea is not to inject a newpacket into the network until an old oneleaves (i.e. is delivered). TCP attempts toachieve this goal by dynamicallymanipulating the Window size.

    TCP Congestion Control

  • 8/11/2019 TransportLayer TCP UDP

    25/29

    25

    TCP Timer Management

    TCP uses multiple timers (at least conceptually)

    to do its work.

    The most important of these is theretransmission timer. When a segment is sent, a

    retransmission timer is started. If the segment isacknowledged before the timer expires, the timeris stopped. If, on the other hand, the timer goesoff before the acknowledgment comes in the

    segment is retransmitted (and the timer startedagain).

    The question that arises is: How long should the

    timeout interval be?

  • 8/11/2019 TransportLayer TCP UDP

    26/29

    26

    TCP Timer Management

    This problem is much more difficult in the

    Internet transport layer than in thegeneric data link protocols, where thedelay is very predictable.

    The solution is to use a highly dynamicstatistical algorithmthat constantlyadjusts the timeout interval based on

    continuous measurements of networkperformance. This algorithm was proposedby Jacobsonin 1988.

  • 8/11/2019 TransportLayer TCP UDP

    27/29

    27

    UDP The Internet protocol suite also supports a

    connectionlesstransport protocol, UDP(User Data Protocol)

    UDP provides a way for applications to

    send encapsulated raw IP datagrams andsend them without having to establish aconnection.

    Many client-server applications that have1 request and 1 response use UDP ratherthan go to the trouble of establishing andlater releasing a connection.

  • 8/11/2019 TransportLayer TCP UDP

    28/29

    28

    UDP

    A UDP segment consists of an 8-byte headerfollowed by the data.

    Fig. 4. The UDP header

  • 8/11/2019 TransportLayer TCP UDP

    29/29

    29

    UDP

    The two portsserve the same function as

    they do in TCP: to identify the end pointswithin the source and destinationmachines.

    The UDP lengthfield includes the 8-byteheader and the data.

    The UDP checksumis used to verify thesize of header and data.