Top Banner

of 63

Chapter5_p1

Jun 04, 2018

Download

Documents

radeeyjd
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/13/2019 Chapter5_p1

    1/63

    Chapter 5: Transport LayerECE 610 Winter 2013

    Dr. Mohamed Mahmoud

    Department of Electrical and Computer Engineering

    University of Waterloo

    http://ece.uwaterloo.ca/~mmabdels/

    [email protected]

  • 8/13/2019 Chapter5_p1

    2/63

    Outline

    5.1 Introduction

    5.2 Connectionless transport: UDP

    5.3 Connection-oriented transport: TCP

  • 8/13/2019 Chapter5_p1

    3/63

    - Transport layer: end-to end layer not implemented in theintermediate 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

    Application Application

    5 - 1

  • 8/13/2019 Chapter5_p1

    4/63

    - The transport layer is responsible for process-to-process

    data delivery.

    - Provide logical communication between application

    processes running on different hosts

    - Two processes communicate together - exchange messages

    between applications (e.g., email, file transfer, the Web)

    Types of data deliveries

    5 - 2

  • 8/13/2019 Chapter5_p1

    5/63

    Duties of the transport layer

    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-to-

    destination) delivery of an entire message maintains

    communication streams between applications.

    5 - 3

  • 8/13/2019 Chapter5_p1

    6/63

    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 each processmust 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

  • 8/13/2019 Chapter5_p1

    7/63

    1- Error Control

    - Error detection and retransmission.

    - Unlike error handling at the data link layer: this is end-to-end error control

    2- Sequence Control

    - At sender: An application layers messages is divided intosegments

    4- Reliable Delivery:

    - Aspects of reliable data transfer

    5 - 5

  • 8/13/2019 Chapter5_p1

    8/63

    - 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 thefinal segment or middle segment of a transmission.

    3- Loss Control

    - Sequence numbers allow the receivers transport layerprotocol to identify any missing segments and request

    redelivery.

    4- Duplication Control

    - Sequence numbers allow the receiver to identify and discard

    duplicate segments.

    5 - 6

  • 8/13/2019 Chapter5_p1

    9/63

    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

    5 - 7

    Note:

    - Handling process-to process communication cannot be

    handled by the data link layer becausenodes 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 ofa message

  • 8/13/2019 Chapter5_p1

    10/63

    Internet transport-layer protocols: TCP, UDP

    1- TCP Transmission Control Protocol

    - Reliable, in-order delivery - TCP uses acknowledgements

    and retransmissions detect corrupted and missing data -

    makes sure all packets are successfully received

    - Congestion control: throttle sender when network

    overloaded

    - Flow control: sender wont overwhelm receiver

    - Connection-oriented: establish connection before data

    transfer

    - Full-Duplex: data can flow in both directions simultaneously

    - Segmentation and re-assemble segments in the right order

    - Stream-of-bytes service: sends and receives a stream of

    bytes not messages 5 - 8

  • 8/13/2019 Chapter5_p1

    11/63

    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 beeffective 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

  • 8/13/2019 Chapter5_p1

    12/63

    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 asdesired 5 - 10

  • 8/13/2019 Chapter5_p1

    13/63

    - 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

  • 8/13/2019 Chapter5_p1

    14/63

    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 arealways 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

  • 8/13/2019 Chapter5_p1

    15/63

    Creating a network application

    -Write programs that run on end systems.

    - Process: An instance of a program in execution.

    - Processes on two hosts communicate over network by

    Processes communicating across network

    sending and receiving

    messages, e.g., web serversoftware communicates with

    browser software

    - No need to write softwarefor network-core devices

    application

    - Network-core devices donot run user applications

    5 - 13

  • 8/13/2019 Chapter5_p1

    16/63

    - 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

  • 8/13/2019 Chapter5_p1

    17/63

    - 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 transport-

    layer 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

  • 8/13/2019 Chapter5_p1

    18/63

    Addressing processes

    - A single host may run several processes process must

    have identifier

    - 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 sameport 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

  • 8/13/2019 Chapter5_p1

    19/63

    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 aconnection 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

    messengers5 - 17

  • 8/13/2019 Chapter5_p1

    20/63

    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 thesocket

    - There should be a unique identifier for each socket.

    - Socket identifier is called socket address = IP address andport 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 thatdefines the a TCP connection (client IP, client port, server IP,

    server port)

    - A socket pair uniquely identifies the traffic between thehosts 5 - 18

    While server processes have static port numbers assigned

  • 8/13/2019 Chapter5_p1

    21/63

    - While server processes have static port numbers assigned

    to them, clients dynamically chooses a port number for each

    conversation.

    1) TCP server (ftp) with a passive open on port 21

    2) Connection request from client to server

    server{*:21, *:*}

    10.19.0.115

    listening socket

    client

    {10.3.3.137:49152,10.19.0.115:21}

    10.3.3.137

    server

    {*:21, *:*}

    10.19.0.115

    listening socketconnection request to10.19.0.115, port 21

    5 - 19

  • 8/13/2019 Chapter5_p1

    22/63

    3) Concurrent server has child handle client.

    client

    {10.3.3.137:49152, 10.19.0.115:21}

    10.3.3.137

    server

    {*:21, *:*}

    10.19.0.115

    listening socket

    serverchild

    {10.19.0.115:21,10.3.3.137:49152}

    connected socket

    Main server spawns a child to handle each new connection

    5 - 20

  • 8/13/2019 Chapter5_p1

    23/63

    4) Second client connection with same server.

    client

    {10.3.3.137:49152,10.19.0.115:21}

    10.3.3.137

    {*:21, *:*}

    10.19.0.115

    listening socket

    server

    child{10.19.0.115:21,10.3.3.137:49152}

    client

    {10.3.3.137:49153, 10.19.0.115:21}

    server

    child{10.19.0.115:21,10.3.3.137:49153}

    connected socket

    connected socket

    server

    5 - 21

    T i l li t

  • 8/13/2019 Chapter5_p1

    24/63

    Typical client program:-

    1- Prepare to communicate: create a socket, determine

    server address and port number, initiate the connection tothe 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 client2- 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 socket3- Close the socket 5 - 22

  • 8/13/2019 Chapter5_p1

    25/63

    Servers differ from clients

    - Passive open- Prepare to accept connections

    - but dont actually establish

    - until hearing from a client

    - Hearing from multiple clients

    - Allowing a backlog of waiting clients- ... in case several try to communicate at once

    - Create a socket for each client

    - Upon accepting a new client

    - create a new socket for the communication

    5 - 23

    l l d d l l

  • 8/13/2019 Chapter5_p1

    26/63

    Multiplexing and demultiplexing

    5 - 24

    Multiplexing (at the sending node): the process of

  • 8/13/2019 Chapter5_p1

    27/63

    - Multiplexing (at the sending node): the process of

    encapsulating messages from different applications sockets

    with the header information and pass the segments to thenetwork 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 throughFTP and two telnet sessions (provide a bidirectional

    interactive text-oriented communication) are also running

    - Transport layer receives packets from network layer for allfour processes 5 - 25

    How demultiplexing works

  • 8/13/2019 Chapter5_p1

    28/63

    How demultiplexing works

    - Each IP datagram has source IP address, destination IP

    address, and one transport-layer segment. Each segment

    has source and destination port numbers.

    - Host uses IP addresses & port numbers to direct segment toappropriate socket

    - TCP socket is identified by 4-tuple: (source IP address,

    source port number, dest IP address, dest port number)

    receiving host uses all four values to direct segment to

    appropriate socket

    - UDP: directs segment to socket with that the segments port

    number IP datagrams with same destination port number,

    but different source IP addresses and/or source portnumbers will be directed to same socket at destination 5 - 26

    Connection-oriented demultiplexing: example

  • 8/13/2019 Chapter5_p1

    29/63

    transport

    application

    physical

    linknetwork

    P3transport

    application

    physical

    link

    P4

    transport

    application

    physical

    linknetwork

    P2

    source IP,port: A,9157

    dest IP, port: B,80

    source IP,port: B,80dest IP,port: A,9157

    host: IP

    address A

    host: IP

    address C

    network

    P6P5P3

    source IP,port: C,5775dest IP,port: B,80

    source IP,port: C,9157dest IP,port: B,80

    server: IP

    address B

    Connection-oriented demultiplexing: example

    - Three segments, all destined to IP address: B, destinationport: 80 are demultiplexed to different sockets

    5 - 27

    Connectionless demultiplexing: example

  • 8/13/2019 Chapter5_p1

    30/63

    transport

    application

    physical

    link

    network

    P3transport

    application

    physical

    link

    network

    P1

    transport

    application

    physical

    link

    network

    P4

    source port: 9157

    dest port: 6428

    source port: 6428dest port: 9157

    source port: 6428dest port: 9266

    source port: 9266

    dest port: 6428

    - A server application that uses UDP serves only ONE request

    at a time.- All other requests are stored in a queue waiting for service.

    Connectionless demultiplexing: example

    Port: 9157

    Port: 6428

    Port: 9266

    5 - 28

  • 8/13/2019 Chapter5_p1

    31/63

    Outline

    5.1 Introduction

    5.2 Connectionless transport: UDP

    5.3 Connection-oriented transport: TCP

    UDP: User Datagram Protocol

  • 8/13/2019 Chapter5_p1

    32/63

    UDP: User Datagram Protocol

    - Unreliable best effort service has no flow and error control

    - A UDP segment can be lost, arrive out of order,

    duplicated, or corrupted

    - Reliable transfer over UDP: add reliability at application layer- Application writes a message to a UDP socket

    - which is then encapsulated in a UDP datagram

    - which is then sent to destination

    - Connectionless: no handshaking between sender and

    receiver - each segment is handled independently of others- It does not add anything to the services of IP except to

    provide process-to-process communication.

    - UDP runs up to 40% faster than TCP, under some conditions,because it does nothing 5 - 29

    User datagram format

  • 8/13/2019 Chapter5_p1

    33/63

    User datagram format

    - 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 bytesof data). 5 - 30

    - Checksum: detect errors (e g flipped bits) in the entire

  • 8/13/2019 Chapter5_p1

    34/63

    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: CB84000D001C001Ca. 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 viceversa? 5 - 31

    Solution

  • 8/13/2019 Chapter5_p1

    35/63

    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 packetminus 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

    O tli

  • 8/13/2019 Chapter5_p1

    36/63

    Outline

    5.1 Introduction

    5.2 Connectionless transport: UDP

    5.3 Connection-oriented transport: TCP

    - TCP is a connection-oriented protocol; it creates a virtual

  • 8/13/2019 Chapter5_p1

    37/63

    connection between two TCPs to send data.

    - TCP uses flow and error control mechanisms at the transportlevel.

    - 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

  • 8/13/2019 Chapter5_p1

    38/63

    p ,

    - 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

    network switches and routers

    - Allows two application programs to form a connection, senddata in either direction, and then terminate the connection.

    - TCP is reliable byte stream protocol that can create a

    connection between any pair of processes on any pair ofInternet hosts

    5 - 34

    5.3.1 TCP segment format

  • 8/13/2019 Chapter5_p1

    39/63

    5.3.1 TCP segment format

    5 - 35

    - Source port (16 bits): identifies the sending port

    - Destination port (16 bits): identifies the receiving port

    - Sequence number field (32 bits):

  • 8/13/2019 Chapter5_p1

    40/63

    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 sequencenumber (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

    H t A

  • 8/13/2019 Chapter5_p1

    41/63

    Host A

    Host B

    TCP Data

    TCP Data

    TCPHDR

    TCPHDR

    ISN (initial sequence number)

    Sequencenumber = 1st

    byte Ack sequencenumber = nextexpected byte

    - Sequence Number/Acknowledgement Number Fields are

    used to be sure each packet has arrived, place segments inorder, allow a specific segment to be acknowledged

    5 - 37

    - Header length (Hlen): header length in 4-byte words - value

  • 8/13/2019 Chapter5_p1

    42/63

    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

    - Reserved (6 bits): for future use and should be set to zero5 - 38

    Six 1-bit flags: play an important role in establishing,

  • 8/13/2019 Chapter5_p1

    43/63

    5 - 39

    maintaining, and terminating a connection

    - URG (urgent pointer): The urgent pointer should beexamined

    - 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 segmentfor setup - synchronize sequence numbers during

    connection.

    - FIN: Final segment for teardown - sender at end ofbyte stream - End of Transmission Marker

  • 8/13/2019 Chapter5_p1

    44/63

    5 - 40

    - Urgent pointer (16 bits): if the URG flag is set, then this

  • 8/13/2019 Chapter5_p1

    45/63

    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 paths5 - 41

    5.3.2 Connection management

  • 8/13/2019 Chapter5_p1

    46/63

    - Connection-oriented data delivery has three stages:1- Connection establishment: ensure that both hosts are

    ready and know the initial sequence numbers.

    2- Data transfer

    3- Connection termination: When data transfer is finished,

    the hosts send signals to end the connection.

    timeA

    B

    Connectionestablishment

    Datatransfer

    Connectiontermination

    5 - 42

    1- TCP Connection establishment

  • 8/13/2019 Chapter5_p1

    47/63

    - Three-way handshaking

    Requesting computerResponding computer

    1- Connection

    request

    2- Connectionconfirmation

    3- Acknowledgementof confirmation

    A B

    5 - 43

    1- Connection request message:

  • 8/13/2019 Chapter5_p1

    48/63

    - 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 aconnection 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 Number5 - 44

    - Upon receiving this packet, A can start sending data with As

    initi l eq en e n mbe + 1

  • 8/13/2019 Chapter5_p1

    49/63

    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 data5 - 45

    - Client: connection initiator - user clicks on a hypertext link

    - browser creates a socket and does a connect to trigger

  • 8/13/2019 Chapter5_p1

    50/63

    browser creates a socket and does a connect to trigger

    the operating system to transmit a SYN

    Socket clientSocket = new Socket("hostname", "port number");

    - Server: contacted by client

    Socket connectionSocket = welcomeSocket.accept();

    - 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 adefault of 3 or 6 seconds 5 - 46

    2- Data Transfer

  • 8/13/2019 Chapter5_p1

    51/63

    The next expectedbyte

    The seq.number of the

    first byte in thepacket

    ACK the datareceiver fromthe server

    5 - 47

    - Sender: TCP transfers data as a continuous stream of

    bytes

  • 8/13/2019 Chapter5_p1

    52/63

    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

  • 8/13/2019 Chapter5_p1

    53/63

    Using three-way handshaking

    Disconnectionrequest

    Disconnection

    confirmation

    Acknowledgementof confirmation

    Requesting computerResponding computer

    AB

    closing

    closing

    closed

    closed

    5 - 49

    1- Disconnection request message: (from A to B)

    Cli l k b i ki li S k l ()

  • 8/13/2019 Chapter5_p1

    54/63

    - 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 = 15 - 50

    Half-close

  • 8/13/2019 Chapter5_p1

    55/63

    5 - 51- A sends all its data and closes the connection- B closes it later after finishing data transmission

    Failure Recovery

    - When the system that the transport entity is running on fails

  • 8/13/2019 Chapter5_p1

    56/63

    - When the system that the transport entity is running on fails

    and subsequently restarts, the state information of all activeconnections 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 closeconnections quickly (an abnormal termination).

    - Out of order segments could cause the FIN segment to

    arrive before the last data segment a connection may beclosed 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 theother using this sequence number. 5 - 52

    Netstat

  • 8/13/2019 Chapter5_p1

    57/63

    - Shows protocol, local address and port number, foreign

    address and port number.

    - Unexpected connections may mean there is a securityproblem. 5 - 53

    5.3.3 TCP flow control

  • 8/13/2019 Chapter5_p1

    58/63

    Sliding window

    - Flow control: sender wont overrun receivers buffer by

    transmitting too much, too fast

    - A sliding window is used to make data transmission more

    efficient (pipelining see chapter 3) and to control the flow of

    data so that the receiver does not become overwhelmed.

    5 - 54

    Receivers buffer:

  • 8/13/2019 Chapter5_p1

    59/63

    5 - 55

    - 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 andcannot consume data received at the rate that sender host

    sends.

    - Speed-matching service: matching the sending rate to thereceiving applications drain rate

    - Receiver: explicitly informs sender of (dynamically

    changing) amount of free buffer space RcvWindow field in

  • 8/13/2019 Chapter5_p1

    60/63

    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

  • 8/13/2019 Chapter5_p1

    61/63

    data segment.

    - The senders window size is dynamic and controllable by

    receiver.

    - Flow control is achieved by forcing the sender to wait foran acknowledgment

    Receiver Side

    Advertised Window: Shrinks as data arrives and grows asthe 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

  • 8/13/2019 Chapter5_p1

    62/63

    5 - 58

    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 Congestion control

    congestion control is about preventing too manylosses inside the network

    Flow Control can improve reliability and performance of TCP

    transmission

    1- Prevent buffer overflow Reduce the chance of droppingsegments at destination if the buffer is full avoid waste of

    resources

    2- reduce the retransmissions avoid waste of resourcesin retransmissions

  • 8/13/2019 Chapter5_p1

    63/63

    - The receiver can temporarily shut down the window

    - Window size = 0 receiver asks the sender to stoptransmitting data 5 - 59