Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Browser
FTP
Transport Layer: Motivation
Client
Web
Server
Transport Transport
Network
Network Network Network Network
Network
Link
Link Link Link Link
Link
Physical
Physical Physical Physical Physical
Physical
FTP
B
A R1 R2 Server
Transport
Network
Network
1
Transport services and protocols Transport vs. network layer
provide logical communication
between app processes running
Household analogy:
application
on different hosts
transport
network
network layer: logical
data link
physical
network
data link communication 12 kids sending letters to
between hosts 12 kids
network physical
transport protocols run in end data link
physical
systems network
data link processes = kids
send side: breaks app
physical network
data link
transport layer: logical app messages = letters
messages into segments, physical
2
Transport Layer Functions Internet transport-layer protocols
Demultiplexing to upper layer -- Obligatory User Datagram Protocol (UDP)
unreliable (“best-effort”),
Deliver an incoming packet to the correct
unordered
application unicast or multicast delivery
Define Delivery Sematics and Implement them no flow, no congestion control
Do not allow sender to overrun receiver’s buffer Stream Control Transport Protocol (SCTP) (will not cover in class)
resources RFC 2960
reliable
Congestion control -- Optional
optional ordering
Do not allow the sender to overrun the network unicast
capacity flow & congestion control
3
Multiplexing/demultiplexing – Why? Demultiplexing: How?
host receives IP datagrams
Why need demultiplexing? P1 P2 P3
Assume you are running 3 network each datagram has source IP
applications all using the same transport transport address, destination IP 32 bits
protocol, e.g., TCP address
• FTP Server, Telnet Client, Web Browser network each datagram carries 1 source port # dest port #
transport-layer segment
When a packet arrives at a host, it moves link
each segment has source, other header fields
up the protocol stack until it reaches the
transport layer, e.g., TCP
physical destination port number
(well-known port numbers for
Demultiplexing specific applications)
Now, the transport layer needs a way to
determine which application the packet P1 P2 P3 Port #s: 16 bits application
needs to be delivered. This is the • 65535 ports data
demultiplexing problem. transport • 0-1023 are called well-known (message)
and are reserved
Recall that all protocol layers perform network – HTTP uses port 80
multiplexing/demultiplexing: – Telnet uses port 23
• e.g., IP needs to determine which transport link TCP/UDP segment format
protocol a given packet needs to be – RFC 1700 lists the reserved
delivered, UDP or TCP? physical ports
Multiplexing
4
UDP: User Datagram Protocol [RFC 768]
“bare bones”, “best effort” Pros:
transport protocol No connection establishment
connectionless: No delay to start
no handshaking between sending/receiving packets
UDP sender, receiver Simple
before packets start no connection state at sender,
being exchanged
UDP: User Datagram Protocol
receiver
each UDP segment Small segment header
handled independently Just 8 bytes of header
of others
Cons:
Just provides
“best effort” transport service
multiplexing/demultiplexing
means, UDP segments may be:
lost
delivered out of order to app
no congestion control: UDP can
blast away as fast as desired
5
UDP more UDP Demultiplexing
Used for
Mux/Demux
often used for streaming
multimedia apps Create sockets with port When host receives
loss tolerant
32 bits numbers: UDP segment:
rate sensitive Length, in source port # dest port # DatagramSocket mySocket1 = new checks destination port
bytes of UDP length checksum
DatagramSocket(6428); number in segment
segment, DatagramSocket mySocket2 = new directs UDP segment to
other UDP uses including DatagramSocket(4567);
socket with that port
header number
DNS
SNMP UDP socket identified by
Application
data two-tuple: IP datagrams with
reliable transfer over UDP: (message) (dest IP address, dest port number) different source IP
add reliability at
addresses and/or
application layer
source port numbers
application-specific UDP segment format
error recovery! directed to same
socket
6
UDP Demultiplexing Example UDP checksum
DatagramSocket serverSocket = new DatagramSocket(6428); Goal: detect “errors” (e.g., flipped bits) in transmitted
segment Receiver:
P P1P compute checksum of received
P
Sender: segment
treat segment contents check if computed checksum
as sequence of 16-bit equals checksum field value:
SP: 6428 SP: 6428
integers NO - error detected
DP: 9157 DP: 5775
checksum: addition (1’s YES - no error detected. But
complement sum) of maybe errors nonetheless?
SP: 9157 SP: 5775 segment contents • Reordered bytes
client DP: 6428 server DP: 6428 Client sender puts checksum
IP: A IP: C IP:B value into UDP checksum
field Why checksum at UDP if LL
provides error checking?
Source Port (SP) provides “return address”: Identifies IP is supposed to run over
the process at the other end of the line ANY LL, so UDP does its own
error checking
7
How to program using the UDP? Socket Creation
Socket Layer
TCP UDP mySock = socket(family, type, protocol);
IP Socket Layer
LL
PL
TCP
IP
UDP
UDP/TCP/IP-specific sockets
LL
PL
8
UDP Client/Server Interaction UDP Client/Server Interaction
9
UDP Client/Server Interaction Specifying Addresses
ServAddr.sin_family = PF_INET; /* Internet address family */ struct sockaddr
ServAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */ {
Generic
ServAddr.sin_port = htons(20000); /* Local port 20000 */ unsigned short sa_family; /* Address family (e.g., PF_INET) */
char sa_data[14]; /* Protocol-specific address information */
if (bind(servSock, (struct sockaddr *) &ServAddr, sizeof(ServAddr)) < 0) };
Error("bind() failed");
struct sockaddr_in
{
IP Specific
1. Create a UDP socket 1. Create a UDP socket struct in_addr sin_addr; /* Internet address (32-bits) */
2. Communicate (send/receive 2. Assign a port to socket char sin_zero[8]; /* Not used */
messages) };
3. Communicate (receive/send
3. When done, close the socket struct in_addr
messages) {
4. When done, close the socket unsigned long s_addr; /* Internet address (32-bits) */
};
10
UDP Client/Server Interaction UDP Client/Server Interaction
struct sockaddr_in peer;
int peerSize = sizeof(peer);
char buffer[65536];
Server is now blocked waiting for a message from a client
recvfrom(servSock, buffer, 65536, 0, (struct sockaddr *)&peer, &peerSize);
11
UDP Client/Server Interaction UDP Client/Server Interaction
12
UDP Client/Server Interaction UDP Client/Server Interaction
// Initialize server’s address and port
struct sockaddr_in server;
server.sin_family = AF_INET; close(clientSock); close(serverSock);
server.sin_addr.s_addr = inet_addr(“10.10.100.37”);
server.sin_port = htons(20000);
13
TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581
application application
writes data reads data
socket socket
door door
TCP TCP
send buffer receive buffer
segment
14
TCP segment structure TCP Connection-oriented demux
32 bits TCP socket identified by 4-tuple:
URG: urgent data counting
source port # dest port # source IP address
(generally not used) by bytes
sequence number source port number
ACK: ACK # of data
(not segments!) dest IP address
valid acknowledgement number
head not dest port number
PSH: push data now len used
UA P R S F Receive window
(generally not used) # bytes
checksum Urg data pnter
rcvr willing
RST, SYN, FIN: to accept receiving host uses all four values to direct segment
Options (variable length)
connection estab to appropriate socket
(setup, teardown
commands)
application
Internet data
checksum (variable length)
(as in UDP)
29 30
15
TCP Demultiplexing Example Typical TCP Transaction
Client Server
A TCP Transaction
P P P P1P
consists of 3 Phases
1. Connection Establishment
Connection Establishment Handshaking between
client and server
SP: 80 SP: 80
DP: 9157 DP: 5775
2. Reliable, In-Order Data
Reliable, In-Order Exchange
SP: 9157 SP: 5775 Data Exchange Recover any lost data
client DP: 80 server DP: 80 Client through retransmissions
IP: A IP: C IP:B and ACKs
31 time time 32
16
TCP Connection Establishment Connection Establishment (cont)
TCP sender, receiver establish “connection” before
Three way handshake: Host A Host B
17
Connection Establishment (cont) TCP Starting Sequence Number Selection
Host A Host B
Why a random starting sequence #? Why not simply
choose 0?
Connection
request To protect against two incarnations of the same connection
Seq. #’s: reusing the same sequence numbers too soon
host ACKs
byte stream “number” of and selects
first byte in segment’s its own
That is, while there is still a chance that a segment from an earlier
initial seq #
data incarnation of a connection will interfere with a later incarnation
ACKs: of the connection
seq # of next byte
host ACKs How?
expected from other side
Client machine seq #0, initiates connection to server with seq #0.
cumulative ACK
Client sends one byte and client machine crashes
Client reboots and initiates connection again
time time
Server thinks new incarnation is the same as old connection
Three-way handshake
35 36
18
TCP Connection Termination TCP Connection Termination
Step 3: client receives FIN, replies
Closing a connection:
with ACK.
client server client server
client closes socket: Enters “timed wait” - will respond
clientSocket.close(); close closing
with ACK to received FINs
Step 1: client end system
sends TCP FIN control
Step 4: server, receives ACK.
Connection closed.
segment to server closing
Data
write Why wait before closing the
Step 2: server receives connection?
FIN, replies with ACK.
Server might send some If the connection were allowed to move
timed wait
timed wait
close
buffered but not sent data to CLOSED state, then another pair of
closed
before closing the application processes might come along
connection. Server then and open the same connection (use the
sends FIN and moves to closed same port #s) and a delayed FIN from closed
Closing state. an earlier incarnation would terminate
the connection.
37 38
19