Anda di halaman 1dari 48

Lecture 17 (Transport Layer) Outline

„ Elements of transport layer


z Multiplexing/demultiplexing
z Addressing - port number
„ Connectionless transport - UDP
„ Connection-oriented transport - TCP
z Connection management
z Reliable data delivery
z Flow control
z Congestion control

CSC4430 – Data Communication and Computer Networks 1


17.1. Transport Services and Protocols

„ Transport layer protocol is implemented in the


operating systems of the end systems.
„ It only runs in the end systems.

CSC4430 – Data Communication and Computer Networks 2


17.1. Transport Services and Protocols

„ Provide logical or process-to-process communication


between application processes running on different
hosts or end systems.

Domain of network layer protocol

Domain of transport layer protocol

CSC4430 – Data Communication and Computer Networks 3


17.1. Transport Services and Protocols

„ Transport vs network layer services:


z network layer:
data transfer between end systems.
z transport layer:
data transfer between processes.
relies on, enhances, network layer services.

CSC4430 – Data Communication and Computer Networks 4


17.1. Transport Services and Protocols

„ Transport vs data link layer services:


z Data link layer:
Provides its services within a single network.
Controls the physical layer only.
z Transport layer:
Provides its services across an internetwork made of
many networks.
Controls all three of the lower layers.

CSC4430 – Data Communication and Computer Networks 5


17.1. Transport Services and Protocols

„ Elements of transport services:


z Multiplexing.
z Addressing.
z Reliable data delivery.
z Flow control.
z Connection management.

CSC4430 – Data Communication and Computer Networks 6


17.1. Transport Services and Protocols

„ Two types of transport services:


z Connectionless: UDP
Multiplexing and addressing.
No reliable data delivery.
No flow control.
No connection management.
z Connection-oriented: TCP
Multiplexing and addressing.
Reliable data delivery.
Flow control.
Connection management.

CSC4430 – Data Communication and Computer Networks 7


17.1. Transport Services and Protocols

TCP UDP

CSC4430 – Data Communication and Computer Networks 8


17.1. Transport Services and Protocols

„ Transport connection-oriented services:


z connection setup involves only the two end
systems.
z switches within the network unaware of the
transport connection.
„ VC or Network connection-oriented services:
z packet switches along the path between the two
end systems are involved in virtual-circuit setup.
z each packet switch is fully aware of all the VCs
passing through it.

CSC4430 – Data Communication and Computer Networks 9


17.2. Multiplexing and Addressing

multiplexing/
demultiplexing

CSC4430 – Data Communication and Computer Networks 10


17.2. Multiplexing and Addressing

„ A host has only one network service.


z identified by IP address.
„ But can run multiple processes.
z Each process can use different transport services.
z Transport service/entity is identified by the
protocol type
TCP or UDP
z Each transport service multiplexes/demultiplexes
data from different processes.

CSC4430 – Data Communication and Computer Networks 11


17.2.1. Multiplexing/Demultiplexing

„ Multiplexing: gathering data from multiple application


processes, enveloping data with header (later used
for demultiplexing)
„ Demultiplexing: delivering received segments to
correct application layer processes

Transport service Transport service


(multiplexer) (demultiplexer)

CSC4430 – Data Communication and Computer Networks 12


17.2.2. Transport Address

„ Process-to-process communication uses a transport


connection.
„ Each transport connection is uniquely identified by:
z Client IP address + port number = client socket address.
z Server IP address + port number = server socket address.
z Type of transport protocol.
„ IP address + port number is called socket address.
controlled by
application
developer Process Process
socket socket
controlled by Transport Internet Transport
operating system service service
Host or client Host or server

CSC4430 – Data Communication and Computer Networks 13


17.2.2. Transport Address

„ Port number assignments (RFC 1700) by IANA:


z maximum number of ports 65535.
z well-known port: 0 through 1023, reserved for `well-known`
services like telnet and ftp.
z ephemeral port: port number chosen randomly by the
transport layer (e.g. UDP) software running on the local host
port number 1023 through 65535.

CSC4430 – Data Communication and Computer Networks 14


17.2.2. Transport Address

z Theoretically, port number assignment for TCP can be


different from UDP.
z But, IANA uses the same assignment.
more info: http://www.iana.org/assignments/port-
numbers
Port Protocol Description
13* Daytime Returns the date and the time
20 FTP, Data File Transfer Protocol (data connection)
21 FTP, Control File Transfer Protocol (control connection)
23 Telnet Terminal Network
25 SMTP Simple Mail Transfer Protocol
53* DNS Domain Name Server
80 HTTP HyperText Transfer Protocol
111* RPC Remote Procedure Call
*can use either TCP or UDP

CSC4430 – Data Communication and Computer Networks 15


17.2.2. Transport Address

„ Finding out port number used by Windows programs,


use netstat command.

protocol client socket server socket


address address

CSC4430 – Data Communication and Computer Networks 16


17.3. UDP: User Datagram Protocol

„ UDP: RFC 768


z “Bare bones” Internet transport protocol.
z Connectionless:
No handshaking between UDP sender, receiver to
establish a connection.
Each UDP segment is handled independently of
others.
z “Best effort” service, UDP segments may be:
Lost - unreliable data transmission.
Delivered out of order to application.

CSC4430 – Data Communication and Computer Networks 17


17.3. UDP: User Datagram Protocol

„ UDP packets are called segments or user datagrams


„ Format:
z Source port number: port number used by the process
running on the source host.
z Destination port number: port number used by the process
running on the destination host.
z Length: the total length of the user datagram (header plus
data).
z Checksum: to detect errors over the entire user datagram
(header plus data).
Application data

CSC4430 – Data Communication and Computer Networks 18


17.3.1. UDP Checksum

„ Goal: to detect “errors” (e.g. flipped bits) in


transmitted segment
„ Sender:
z compute checksum of segment to be sent.
z put the checksum in the checksum field of the segment.
z send the segment.
„ Receiver:
z compute checksum of received segment.
z check if computed checksum equals checksum field value:
NO - error detected.
YES - no error detected. But maybe errors nonetheless?

CSC4430 – Data Communication and Computer Networks 19


17.3.1. UDP Checksum

„ Checksum calculation at sender:


z Add pseudoheader to the UDP user datagram
pseudoheader = part of the header of the IP packet used
to encapsulate the user datagram.

CSC4430 – Data Communication and Computer Networks 20


17.3.1. UDP Checksum

„ Example: checksum calculation for a very small user


datagram with only seven bytes of data (“Testing”)

CSC4430 – Data Communication and Computer Networks 21


17.3.2. UDP Operation

„ UDP only uses the three most basic elements of any


transport service:
z Encapsulation/decapsulation.
z Queuing.
z Multiplexing/demultiplexing.
„ Additional transport service elements, not in UDP,
but in TCP:
z Connection management.
z Flow control.
z Error control.
z Congestion control.
z Others.

CSC4430 – Data Communication and Computer Networks 22


17.3.2.1. Encapsulation/Decapsulation

CSC4430 – Data Communication and Computer Networks 23


17.3.2.1. Encapsulation/Decapsulation

„ Encapsulation at sender:
z Process passes the message to UDP along with a pair of
socket address and length of data.
z UDP adds UDP header to the data.
z UDP passes the user datagram to the IP with the socket
addresses.
z IP adds its own header, using the value 17 in the protocol
field - indicates that the data has come from UDP.
„ Decapsulation at receiver:
z UDP receives the data from the IP software.
z UDP uses the checksum to detect error.
z If no error, UDP passes the message along with the sender
socket address to the process.

CSC4430 – Data Communication and Computer Networks 24


17.3.2.2. Queuing

„ Queues are associated with ports - processes.


z Created by operating system when process requests for a
port number.
z Destroyed when process terminates.
z Two types:
Outgoing queue: temporary store data for transmission
Incoming queue: temporary store data for application to
retrieve

CSC4430 – Data Communication and Computer Networks 25


17.3.2.3. Multiplexing/Demultiplexing

„ Multiplexing/Demultiplexing:
z Needed because there may be several processes that need
to send/receive user datagrams, but there is only one UDP
per host.

CSC4430 – Data Communication and Computer Networks 26


17.4. TCP: Transmission Control Protocol

„ TCP: RFCs: 793, 1122, 1323, 2018, 2581


z Point-to-point:
one sender, one receiver.
z Connection-oriented:
handshaking (exchange of control messages)
initializes sender, receiver state before data
exchange.
z Full duplex data:
bi-directional data flow in same connection.
z Reliable, in-order byte stream:
no “message boundaries”.

CSC4430 – Data Communication and Computer Networks 27


17.4. TCP: Transmission Control Protocol

„ TCP:
z Includes all UDP service elements:
encapsulation/decapsulation.
queuing.
multiplexing/demultiplexing.
z Plus additional service elements:
connection management
error control: recover lost/damaged segments
flow control: sender will not overwhelm the receiver
congestion control: sender will not overwhelm the
network

CSC4430 – Data Communication and Computer Networks 28


17.4. TCP: Transmission Control Protocol

„ TCP packets are called segments

CSC4430 – Data Communication and Computer Networks 29


17.4. TCP: Transmission Control Protocol

„ Format:
z Source port number: port number used by the process
running on the source host.
z Destination port number: port number used by the process
running on the destination host.
z Sequence number: the number assigned to the first byte of
data contained in this segment.
TCP is a stream protocol - to ensure connectivity, each
byte is numbered.
For example:
the sequence number for segment N is 2367 and the
segment carries 1,000 bytes
the sequence number for segment N+1 is 2367+1000 =
3367
Used for checking lost segments and flow control
CSC4430 – Data Communication and Computer Networks 30
17.4. TCP: Transmission Control Protocol

„ Format:
z Acknowledgement number: defines the number of the next
byte of data expected from the source.
For example:
byte number x has successfully received, then the receiver
will defines x+1 as the acknowledgement number.
it then piggybacks the number in the data it sends to the
source of the segment.
z Header length: indicates the number of four-byte words in
the header.
Header length can be between 20-60 bytes.
So the value of the field range 5-15.
z Reserved: this field is reserved for future use.

CSC4430 – Data Communication and Computer Networks 31


17.4. TCP: Transmission Control Protocol

„ Format:
z Control: defines six different control bits or flags.
URG: urgent data (generally not used)
ACK: acknowledgement is valid
PSH: push data now (generally not used)
RST: reset the connection
SYN: synchronize sequence numbers during connection
FIN: terminate the connection
RST, SYN, FIN are used for connection management

CSC4430 – Data Communication and Computer Networks 32


17.4. TCP: Transmission Control Protocol

„ Format:
z Window size: defines the size of receiver window, in bytes
Maximum size of the window is 65,535 bytes = maximum
TCP segment
z Checksum: contains the checksum
TCP checksum is mandatory, cf. UDP checksum is
optional.
Operates in the same way as UDP checksum.
z Urgent pointer: used when the segment contains urgent
data, i.e. when URG flag is set.
z Option: allows optional information to be conveyed to the
receiver.

CSC4430 – Data Communication and Computer Networks 33


17.4.1. TCP Operation

„ TCP:
z Basic service elements operate in the same way
as UDP
encapsulation/decapsulation
queuing
multiplexing/demultiplexing
z Additional service elements:
connection management
error control: recover lost/damaged segments
flow control: sender will not overwhelm the receiver
congestion control: sender will not overwhelm the
network

CSC4430 – Data Communication and Computer Networks 34


17.4.2. Connection Management

„ TCP is a connection-oriented protocol


„ TCP has three phases of data communications:
z connection establishment:
establishes a virtual path between the source and
destination
z data transmission:
all of the segments belonging to a message are sent
over this virtual path
facilitates acknowledgement and retransmission of
lost/damaged segments
z connection termination

CSC4430 – Data Communication and Computer Networks 35


17.4.2. Connection Management

„ TCP connection uses full-duplex mode


z each party can send and receive segments simultaneously.
z implies that each party need to get approval from the other
party before they can send data
„ Connection establishment:
c Host A sends request to setup connection to Host B.
d Host B accepts the request.
e Host B sends its own request to setup connection to Host A.
f Host A accepts the request.
z Step 2 and 3 can be combined in one message, results in
three-way handshaking
needs only three segments to be send

CSC4430 – Data Communication and Computer Networks 36


17.4.2.1. Connection Establishment

„ Three-way handshaking:
Host A Host B

CSC4430 – Data Communication and Computer Networks 37


17.4.2.1. Connection Establishment

„ Three-way handshaking:
c Host A sends a SYN segment - initialization message.
contains Host A initialization sequence number (ISN)
ISN is used for numbering the bytes of data send by Host A.
Host A and Host B may have different ISN.
can also include maximum segment size (MSS) it can
receive from Host B.
d Host B sends a SYN+ACK segment.
acknowledges the receipt of SYN segment from Host A
using the ACK flag and acknowledgement number field.
acknowledgement number = Host A ISN + 1
sends its own initialization parameters to Host A.
 Host A sends an ACK segment.
acknowledges the receipt of SYN segment from Host B
can also include data
CSC4430 – Data Communication and Computer Networks 38
17.4.2.2. Connection Termination

„ TCP connection uses full-duplex mode


z if connection in one direction is terminated, the other party
can continue sending data.
z implies that we need to close the connection in both
directions.
„ Connection termination:
c Host A sends request to terminate connection to Host B.
d Host B accepts the request and closes the connection in
one direction.
Host B can continue sending data to Host A.
e Host B sends its request to terminate connection to Host A.
f Host A accepts the request.
z Step 2 and 3 can not be combined in one message, results
in four-way handshaking
CSC4430 – Data Communication and Computer Networks 39
17.4.2.2. Connection Termination

„ Four-way handshaking:
Host A Host B

closing

closing
timed wait

closed
closed

CSC4430 – Data Communication and Computer Networks 40


17.4.2.2. Connection Termination

„ Four-way handshaking:
c Host A sends a FIN segment and closes the connection.
d Host B sends an ACK segment.
acknowledges the receipt of FIN segment from Host A
using the ACK flag and acknowledgement number field.
Host B can continue sending data to Host A.
e Host B sends a FIN segment and closes the connection.
acknowledges the receipt of FIN segment from Host A
using the ACK flag and acknowledgement number field.
f Host A sends an ACK segment
acknowledges the receipt of FIN segment from Host B
enters “time-wait” - allows it to send out
acknowledgement if it receives FINs from Host B.

CSC4430 – Data Communication and Computer Networks 41


17.4.2.3. State Transition Diagram

„ TCP software is implemented as a finite state


machine (FSM).
„ Finite state machine is a machine that
z goes through a limited number of states.
z can only be in one of the states at any moment.

z remains in that state until an event happens.

The event can take the machine to a new state or make


it perform some actions.
event causing state transition input
state: when in this “state” actions taken on state transition output
next state uniquely
determined by next state
state
event 1 event
2
actions

CSC4430 – Data Communication and Computer Networks 42


17.4.2.3. State Transition Diagram

z For example:
The client TCP starts in the CLOSED state.
If it receive an active open request from the client
application program:
it sends a SYN segment to server TCP.
it goes to the SYN-SENT state.

Active open from client application


Send SYN

CLOSED SYN-SENT

CSC4430 – Data Communication and Computer Networks 43


17.4.2.3. State Transition Diagram

„ States for TCP:


State Description
CLOSED There is no connection
LISTEN The server is waiting for calls from the client
SYN-SENT A connection request is sent; waiting for
acknowledgement
SYN-RCVD A Connection request is received
ESTABLISHED Connection is established
FIN-W AIT-1 The application has requested the closing of the
connection
FIN-W AIT-2 The other side has accepted the closing of the
connection
CLOSING Both sides have decided to close simultaneously
TIME-W AIT W aiting for retransmitted segments to die
CLOSE-W AIT The server is waiting for the application to close
LAST-ACK The server is waiting for the last acknowledgemnt

CSC4430 – Data Communication and Computer Networks 44


17.4.2.3. State Transition Diagram

„ TCP client lifecycle:

CSC4430 – Data Communication and Computer Networks 45


17.4.2.3. State Transition Diagram

„ TCP server lifecycle:

CSC4430 – Data Communication and Computer Networks 46


17.4.2.3. State Transition Diagram

„ Finding out TCP state, use netstat command

TCP states

CSC4430 – Data Communication and Computer Networks 47


Next Lecture

TCP Operation (continued)


(Forouzan Chapter 22,
Section 24.6 – 24.7)

48

Anda mungkin juga menyukai