Module 4
Module 4
Layer
Summary
Part A: Introduction
Part B: Socket
Part C: TCP
Part D: UDP
Part A: Introduction
The transport layer is an end-to-end layer – this means
that nodes within the subnet do not participate in
transport layer protocols – only the end hosts.
As with other layers, transport layer protocols send data
as a sequence of packets (segments).
2. Multiplexing (1)
The network layer provides communication between two
hosts.
The transport layer provides communication between
two processes running on different hosts.
A process is an instance of a program that is running on a
host.
There may be multiple processes communicating between
two hosts – for example, there could be a FTP session
and a Telnet session between the same two hosts.
3. Multiplexing (2)
The transport layer provides a way to multiplex /
demultiplex communication between various processes.
To provide multiplexing, the transport layer adds an
address to each segment indicating the source and
destination processes.
Note these addresses need only be unique locally on
a given host.
In TCP/IP these transport layer addresses are called
port-numbers.
4. Multiplexing (3)
The 5-tuple: (sending port, sending IP address, destination
port, destination IP address, transport layer protocol) uniquely
identifies a process-to-process connection in the Internet.
5. TPDU
• Nesting of Transport Protocol Data
Unit (TPDU), packets, and frames.
6. Connection Establishment
Application
9. Protocol Stacks
AP Creates a new end point; allocates
table space for it within the transport
layer
Socket
interface
Identification of application (port #)
Transport
Network Identifies the node
Data Link Frames
NA
TCP UDP
IP
Physical Network
(driver)
3. Socket Families
There are several significant socket
domain families:
Internet Domain Sockets (AF_INET)
-implemented via IP addresses
and port numbers
Unix Domain Sockets (AF_UNIX)
-implemented via filenames (think
“named pipe”)
Novell IPX (AF_IPX)
AppleTalk DDS (AF_APPLETALK)
4. Type of Socket
C re a t e s o c k e t
b in d a p o rt t o t h e
socket
C L IE N T
lis t e n f o r in c o m in g
C re a t e s o c k e t
c o n n e c t io n s
accept an
c o n n e c t t o s e rv e r's
in c o m in g
p o rt
c o n n e c t io n
re a d f ro m t h e w rit e t o t h e
c o n n e c t io n c o n n e c t io n
lo o p lo o p
w rit e t o t h e re a d f ro m t h e
c o n n e c t io n c o n n e c t io n
c lo s e c o n n e c t io n
7. TCP Server
• Sequence of calls
close() shutdown
8. TCP Client
• Sequence of calls
close() Shutdown
9. Server Side Socket Details
SERVER
C reate socket
int socket(int dom ain, int type, int protocol)
sockfd = socket(P F _IN E T , S O C K _S T R E A M , 0);
bind a port to the int bind(int sockfd, struct sockaddr *server_addr, socklen_t length)
socket
bind(sockfd, & server, sizeof(server));
listen for incom ing int listen( int sockfd, int num _queued_requests)
connections
listen( sockfd, 5);
accept an
incom ing
int accept(int sockfd, struct sockaddr *incom ing_address, socklen_t length)
connection new fd = accept(sockfd, & client, sizeof(client)); /* B LO C K S */
read from the int read(int sockfd, void * buffer, size_t buffer_size)
connection
read(new fd, buffer, sizeof(buffer));
C reate socket
int socket(int dom ain, int type, int protocol)
sockfd = socket(P F _IN E T , S O C K _S T R E A M , 0);
connect to S erver int connect(int sockfd, struct sockaddr *server_address, socklen_t length)
socket
connect(sockfd, & server, sizeof(server));
read from the int read(int sockfd, void * buffer, size_t buffer_size)
connection
read(sockfd, buffer, sizeof(buffer));
11. UDP Clients and Servers
• Connectionless clients and servers create a socket using
SOCK_DGRAM instead of SOCK_STREAM
close() Shutdown
13. UDP Client
• Sequence of calls
close() Shutdown
14. Socket
Programming
Example:
Internet File
Server
6-6-1
• Client code
using sockets.
15. Socket
Programming
Example:
Internet File
Server (2)
• Server code
using
PART C: TCP
2. Introduction
• connection oriented.
• full duplex.
TCP Services:
• Reliable transport
• Flow control
• Congestion control
u m= y,
q ue nceN
CK , Se nt = x+1
A e
SYN+ ow le dgm
Ackn
ACK,
Ackno
wledg
ment =y+1
9. Closing a TCP Connection (1)
client server
• client closes socket:
close
FIN
clientSocket.close();
received FINs
• Step 4: server, receives ACK. ACK
closing
Connection closed.
FIN
• Note: with small modification,
can handle simultaneous FINs.
timed wait
ACK
closed
closed
11. TCP Transmission Policy
•
23. Slow Start
• Initial CW = 1. sender receiver
• After each ACK, CW += 1;
• Continue until: one s e gm
ent
RTT
– Loss occurs OR
– CW > slow start two segm
en ts
threshold
• Then switch to congestion
four segm
avoidance ents
• If we detect loss, cut CW in half
• Exponential increase in window
size per RTT
time
24. Congestion Avoidance
Until (loss) {
after CW packets ACKed:
CW += 1;
}
ssthresh = CW/2;
Depending on loss type:
SACK/Fast Retransmit:
CW/= 2; continue;
Course grained timeout:
CW = 1; go to slow start.
timeout
=1 00
– RTO value is based on estimated ACK
round-trip time (RTT) X
– RTT is adjusted over time using loss
exponential weighted moving Seq=9
average: 2, 8 b
y t es d
at a
RTT = (1-x)*RTT + (x)*sample
(x is typically 0.1)
=10 0
First done in TCP Tahoe ACK
time
lost ACK scenario
26. Fast Retransmit
• Receiver expects N, gets N+1:
time
Introduced in TCP Reno
TCP Connection Management Modeling
The length field gives the length of the entire packet including the header.