Академический Документы
Профессиональный Документы
Культура Документы
CSC 450/550
Summary
Part A: Introduction
Part B: Socket
Part C: TCP
Part D: UDP
CSC 450/550
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.
CSC 450/550
2. Multiplexing (1)
The network layer provides communication between two
hosts.
CSC 450/550
5. TPDU
Nesting of Transport Protocol Data Unit (TPDU),
packets, and frames.
CSC 450/550
6. Connection Establishment
How a user process in host 1 establishes a
connection with a timeofday server in
host 2.
CSC 450/550
7. Transport Service Primitives
The primitives for a simple transport service.
CSC 450/550
8. Transport Service Primitives
The primitives for a simple transport service.
CSC 450/550
Node
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
CSC 450/550
PART B: SOCKET
• Software interface designed to communicate
between the user program and TCP/IP protocol
stack
• Implemented by a set of library function calls
• Socket is a data structure inside the program
• Both client and server programs communicate
via a pair of sockets
CSC 450/550
2. Socket Framework
Application Program User Space
TCP UDP
IP
Physical Network
CSC 450/550 (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)
CSC 450/550
4. Type of Socket
• Stream (SOCK_STREAM) Uses TCP
protocol. Connectionoriented service
• Datagram (SOCK_DGRAM) Uses UDP
protocol. Connectionless service
• Raw (SOCK_RAW) Used for testing
CSC 450/550
5. Creating a Socket
#include <sys/types.h>
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
b in d a p o rt to th e
s o c k e t
C L IE N T
lis t e n f o r in c o m in g
C re a te s o c k e t
c o n n e c tio n s
a c c e p t a n
c o n n e c t t o s e r v e r 's
in c o m in g
p o rt
c o n n e c tio n
re a d fro m th e w r it e t o t h e
c o n n e c tio n c o n n e c tio n
lo o p lo o p
w r ite to th e re a d fro m th e
c o n n e c tio n c o n n e c tio n
c lo s e c o n n e c tio n
CSC 450/550
7. TCP Server
Sequence of calls
close() shutdown
CSC 450/550
8. TCP Client
Sequence of calls
close() Shutdown
CSC 450/550
9. Server Side Socket Details
SERVER
C re a te s o c k e t
in t s o c k e t ( in t d o m a in , in t t y p e , in t p r o t o c o l)
s o c k fd = s o c k e t(P F _ IN E T , S O C K _ S T R E A M , 0 );
b in d a p o r t to th e in t b in d ( in t s o c k f d , s t r u c t s o c k a d d r * s e r v e r _ a d d r , s o c k le n _ t le n g t h )
socket
b in d ( s o c k f d , & s e r v e r , s iz e o f ( s e r v e r ) ) ;
lis t e n fo r in c o m in g in t lis te n ( in t s o c k f d , in t n u m _ q u e u e d _ r e q u e s ts )
c o n n e c t io n s
lis t e n ( s o c k f d , 5 ) ;
accept an
in c o m in g
in t a c c e p t ( in t s o c k f d , s t r u c t s o c k a d d r * in c o m in g _ a d d r e s s , s o c k le n _ t le n g t h )
c o n n e c t io n n e w f d = a c c e p t ( s o c k f d , & c lie n t , s iz e o f ( c lie n t ) ) ; / * B L O C K S * /
re a d fro m th e in t r e a d ( in t s o c k f d , v o id * b u f f e r , s iz e _ t b u f f e r _ s iz e )
c o n n e c t io n
r e a d ( n e w f d , b u f f e r , s iz e o f ( b u f f e r ) ) ;
w r ite to th e in t w r it e ( in t s o c k f d , v o id * b u f f e r , s iz e _ t b u f f e r _ s iz e )
c o n n e c t io n
w r ite ( n e w f d , b u f f e r , s iz e o f ( b u f f e r ) ) ;
CSC 450/550
10. Client Side Socket Details
C L IE N T
C re a te s o c k e t
in t s o c k e t ( in t d o m a in , in t t y p e , in t p r o t o c o l)
s o c k fd = s o c k e t(P F _ IN E T , S O C K _ S T R E A M , 0 );
c o n n e c t to S e rv e r in t c o n n e c t ( in t s o c k f d , s t r u c t s o c k a d d r * s e r v e r _ a d d r e s s , s o c k le n _ t le n g t h )
socket
c o n n e c t ( s o c k f d , & s e r v e r , s iz e o f ( s e r v e r ) ) ;
w r ite to th e in t w r it e ( in t s o c k f d , v o id * b u f f e r , s iz e _ t b u f f e r _ s iz e )
c o n n e c tio n
w r ite ( s o c k f d , b u f f e r , s iz e o f ( b u f f e r ) ) ;
re a d fro m th e in t r e a d ( in t s o c k f d , v o id * b u f f e r , s iz e _ t b u f f e r _ s iz e )
c o n n e c tio n
r e a d ( s o c k f d , b u f f e r , s iz e o f ( b u f f e r ) ) ;
CSC 450/550
11. UDP Clients and Servers
Connectionless clients and servers create a socket using
SOCK_DGRAM instead of SOCK_STREAM
Connectionless servers do not call listen() or accept(), and usually do
not call connect()
Since connectionless communications lack a sustained connection,
several methods are available that allow you to specify a
destination address with every call:
• sendto(sock, buffer, buflen, flags, to_addr, tolen);
• recvfrom(sock, buffer, buflen, flags, from_addr,
fromlen);
CSC 450/550
12. UDP Server
Sequence of calls
close() Shutdown
CSC 450/550
13. UDP Client
Sequence of calls
close() Shutdown
CSC 450/550
14. Socket
Programming
Example:
Internet File
Server
6-6-1
Client code using
sockets.
CSC 450/550
15. Socket
Programming
Example:
Internet File
Server (2)
Server code using
sockets.
CSC 450/550
PART C: TCP
CSC 450/550
2. Introduction
• connection oriented.
• full duplex.
TCP Services:
• Reliable transport
• Flow control
• Congestion control
CSC 450/550
3. Flow of TCP Segments
CSC 450/550
4. TCP Services (1)
TCP converts the unreliable, best effort service of IP into a
reliable service, i.e., it ensures that each segment is
delivered correctly, only once, and in order.
CSC 450/550
6. TCP Header
CSC 450/550
7. Sample TCP Packet
CSC 450/550
8. TCP Connection Establishment
Active participant Passive participant
(client) (server)
SYN,
Sequ
ence
Num
=x
C K , y , t =x+1
A =men
SYN+ ncew Nlu
emdg
q uek n o
Se Ac
ACK,
Ackn
owled
gmen
t =y+
1
CSC 450/550
9. Closing a TCP Connection (1)
client server
client closes socket:
clientSocket.close(); close
FIN
Step 1: client end system
sends TCP FIN control
ACK
segment to server close
FIN
Step 2: server receives FIN,
replies with ACK. Closes
timed wait
connection, sends FIN. A CK
closed
CSC 450/550
10. Closing a TCP Connection (2)
Step 3: client receives FIN, replies
with ACK. client server
• Enters “timed wait” will closing
respond with ACK to FIN
received FINs
Step 4: server, receives ACK. ACK
closing
Connection closed.
FIN
Note: with small modification, can
handle simultaneous FINs.
timed wait
A CK
closed
closed
CSC 450/550
11. TCP Transmission Policy
CSC 450/550
Window management in TCP.
12. Flow Control and Congestion Control
(1)
In a network, it is often desirable to limit the rate at which a
source can send traffic into the subnet.
CSC 450/550
13. Flow Control and Congestion
Control (2)
Two different factors can limit the rate at which a
source sends data.
CSC 450/550
14. Flow Control and Congestion
Control (3)
Flow control and congestion control can be addressed at the
transport layer, but may also be addressed at other layers.
CSC 450/550
15. Congestion (1)
Congestion arises when the total load on the network becomes too large. This
leads to queues building up and to long delays (recall the M/G/1 model).
If
sources retransmit messages, then this can lead to even more congestion and
eventually to congestion collapse. This is illustrated in the figure below.
Notice, as the offered load increase, the number of packets delivered at first
increases, but at high enough loads, this rapidly decreases.
CSC 450/550
16. Congestion (2)
Notice, as the offered load increase, the number of packets delivered at
first increases, but at high enough loads, this rapidly decreases.
CSC 450/550
17. Approaches to Congestion Control
(1)
Congestion control may be addressed at both the
network level and the transport layer.
CSC 450/550
19. Approaches to Congestion Control
(3)
An approach that can be used at either the network or
transport layers is
CSC 450/550
20. Approaches to Congestion Control
(4)
These approaches can be classified as either
"congestion avoidance" approaches, if they try to
prevent congestion from ever occurring, or as
"congestion recovery" approaches, if they wait until
congestion occurs and then react to it. In general, “better
to prevent than to recover."
CSC 450/550
22. TCP Flow control versus Congestion Control
CSC 450/550
23. Slow Start
Initial CW = 1. sender receiver
After each ACK, CW += 1;
one segm
Continue until: ent
RTT
• Loss occurs OR
two segm
ents
• CW > slow start
threshold
Then switch to congestion avoidance four segm
ents
If we detect loss, cut CW in half
Exponential increase in window size
per RTT
time
CSC 450/550
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.
CSC 450/550
25. How are losses recovered?
Say packet is lost (data or ACK!) sender receiver
Coarsegrained Timeout: Seq=9
2, 8 b y te
• Sender does not receive ACK after s data
some period of time
timeout
• Event is called a retransmission = 100
ACK
timeout (RTO)
• RTO value is based on estimated
X
loss
roundtrip time (RTT)
Seq=9
• RTT is adjusted over time using 2, 8 b
y t es da
exponential weighted moving ta
average:
RTT = (1x)*RTT + (x)*sample
=100
(x is typically 0.1) AC K
time
First done in TCP Tahoe lost ACK scenario
CSC 450/550
26. Fast Retransmit
Receiver expects N, gets N+1:
sender receiver
• Immediately sends ACK(N)
• This is called a duplicate ACK ACK 3000
• Does NOT delay ACKs here!
SEQ=300
• Continue sending dup ACKs for each 0 , size=100
0
subsequent packet (not N)
SEQ=400 X
0
SEQ=500
0
Sender gets 3 duplicate ACKs: SEQ=600
0
• Infers N is lost and resends
• 3 chosen so outoforder packets don’t ACK 3000
trigger Fast Retransmit accidentally ACK 3000
• Called “fast” since we don’t need to wait ACK 3000
for a full RTT SEQ=300
0 , size=100
0
time
Introduced in TCP Reno
CSC 450/550
TCP Connection Management Modeling
The states used in the TCP connection management
finite state machine.
CSC 450/550
TCP Connection Management Modeling (2)
CSC 450/550
PART D: UDP
UDP (User Datagram Protocol)
unreliable, connectionless; No TCP’s flow
control; applications where prompt
delivery more important than accurate
delivery (speech, video, …)
(Metaphor: postal service)
CSC 450/550
2. UDP (2)
CSC 450/550
3. UDP Packet
Basically all UDP provides is a multiplexing capability on top of IP.
The length field gives the length of the entire packet including the header.
CSC 450/550