程序代写代做代考 graph FTP DHCP assembly Networks, Security, and Privacy 158.235

Networks, Security, and Privacy 158.235
Dr Hooman Alavizadeh Massey University
1

Transport
Layer
Reading: Chapter 5 in the prescribed textbook
2

Transport Layer
• Layer 4 in the Internet model
• Mainfunction;
– Links application and
network layers
– Responsible for segmentation and reassembly
– Connection Management: end-to-end delivery of messages
Internet Model
Application Transport Network Data Link Physical
3

Outline
• Transport layer functions
– Linking to the application layer
– Segmentation
– Connection Management
4

Linking to Application Layer
• It may serve several Application Layer protocols at the same time
• Which application layer program to send a message to?
• Ports used to identify application (2-byte numbers)
5

Linking to the application layer
• Manysource/destinationportsfollow standards
– Common port standards
• HTTP: TCP port 80
• HTTPS: TCP port 443
• FTP: TCP ports 20 and 21
• SMTP: TCP port 25
• IMAP: TCP port 143
• POP3: TCP port 110 (more commonly TCP port
995 secure version)
• DNS: TCP or UDP port 53 (most commonly UDP)
6

Application Layer Services
7

Outline
• Transport layer functions
– Linking to the application layer
– Segmentation
– Connection Management
8

Segmentation
• Segmenting
– Breaking up large application data into smaller segments (and putting them back together)
– Segments may be passed individually to application layer or after reassembly
– How large are the segments?
• Size depends on the network and data link layer protocols
• Maximum Segment Size (MSS) is negotiated during TCP handshake
9

Transport Layer Functions
Sender
PDU
Receiver
Application
Packet
Transport
Segment
Network
Packet
Data Link
Frame
10

Outline
• Transport layer functions
– Linking to the application layer
– Segmentation
– Connection Management
• Connectionless (UDP)
• Connection-oriented (TCP) • Quality of Service (QoS)
11

Connection Management
• Connectionless Routing is provided by UDP
– Sending packets individually without a virtual connection,
emphasis on reduced latency over reliability
– Each packet is sent independently of one another, and will be routed separately, following different routes and arriving at different times
• Connection Oriented is provided by TCP
– Setting up a virtual connection, or a TCP connection for a
reliable transmission
• Packet deliveries are acknowledged • Used by HTTP, SMTP, FTP
• QoS Routing
– A special kind connection oriented routing with priorities
12

User Datagram Protocol (UDP)
• Operates at the transport layer
• PDU called a segment
• Used in time-sensitive situations, for control messages, or when reliability is handled by the application layer
• 32-64 bits (4-8 bytes) of overhead
• Source port is optional in IPv4 and IPv6, Checksum is optional in IPv4
Source Port (16 bits)
Destination Port (16 bits)
Length (16 bits)
Checksum (16 bits)
User
Data (varies)
13

UDP – User Datagram Protocol
• “No frills”, “bare bones” transport protocol
• “Best Effort” service
– Can be lost or delivered out-of-order to app
• Connectionless messaging
– No handshaking between UDP sender and receiver – Each UDP segment handled independently of others
• UDP: Efficiency before reliability
– Used in time-sensitive situations, for control messages,
or when reliability is handled by the application layer
– Commonly used for application control messages that are usually small, such as DNS, DHCP, RIP and SNMP
– Can also be used for applications where a packet can be lost, such as information rich video/audio
14

UDP segment header
Source Port (16 bits)
Destination Port (16 bits)
Length (16 bits)
Checksum (16 bits)
User
Data (varies)
why is there a UDP?
❖ no connection establishment (which can add delay)
❖ simple: no connection state at sender, receiver
❖ small header size
❖ no congestion control: UDP can blast away as fast as desired
15

Transport Layer Protocols
• Transmission Control Protocol (TCP) – Most common transport layer protocol
– PDU called a segment
– Used for reliable transmission of data
– 160 – 192 bits (20 -24 bytes) of overhead
• Options field is not required
Source Port (16 bits)
Destination Port (16 bits)
Sequence Number (32 bits)
ACK number (32 bits)
Header Length (4 bits)
Unused (6 bits)
Flags (6 bits)
Flow Control (16 bits)
CRC-16 (16 bits)
Urgent Pointer (16 bits)
Options (32 bits)
User
Data (varies)
16

Reliable Data Transfer
Host A
Host B
Packet Packet
❖Sequence number ❖ Acknowledgment ❖ Retransmission
Packet
X
17

Reliable Data Transfer
Host A
Host B
Packet
❖Timer
X
Acknowledgement
18

Reliable Data Transfer
• Sequence Numbers
– byte stream “number” of first byte in segment’s data
• Acknowledgement Numbers
– seq # of next byte expected from other side
– cumulative ACK • Timer
– Ensure acknowledgement has received within the expected time frame
• Retransmission
– Retransmit the data after timeout
19

Host A
User types ‘C’
host ACKs receipt
of echoed ‘C’
Host B
SEQ and ACK
host ACKs receipt of ‘C’, echoes back ‘C’
simple telnet scenario
20

Host A
Retransmission
Host B
Host B
Host A SendBase=92
X
SendBase=100 SendBase=120
SendBase=120
lost ACK scenario
premature timeout
21
timeout
timeout

Retransmission
Host A
Host B
X
cumulative ACK
22
timeout

Connection Management
• Before exchanging data, sender/receiver “handshake”:
• Agree to establish connection (each knowing the other willing to establish connection)
• Agree on connection parameters
23

Establish a connection
2-way handshake:
Let’s talk OK
ESTAB
Q: will 2-way handshake always work in network?
• can’t “see” other side
• variable delays
• retransmitted messages (e.g. req_conn(x)) due to message loss
• message reordering
24
ESTAB
choose x
ESTAB
req_conn(x) acc_conn(x)
ESTAB

Establish a connection
2-way handshake failure scenarios:
choose x
retransmit req_conn(x)
ESTAB
client terminates
req_conn(x)
ESTAB
choose x
retransmit req_conn(x)
ESTAB
retransmit data(x+1)
client terminates
req_conn(x)
ESTAB
accept data(x+1)
server forgets x
ESTAB
accept data(x+1)
acc_conn(x) req_conn(x)
acc_conn(x) data(x+1)
connection x completes
server forgets x
ESTAB
req_conn(x) data(x+1)
connection x completes
half open connection! (no client!)
25

client state
LISTEN
SYNSENT
choose init seq num, x send TCP SYN msg
server state
LISTEN
SYN RCVD
TCP3-way handshake
SYNbit=1, Seq=x
SYNbit=1, Seq=y ACKbit=1; ACKnum=x+1
ACKbit=1, ACKnum=y+1
choose init seq num, y send TCP SYNACK msg, acking SYN
ESTAB
received SYNACK(x) indicates server is live; send ACK for SYNACK;
this segment may contain client-to-server data
received ACK(y) indicates client is live
ESTAB
26

Closing a connection
❖client, server each close their side of connection
▪ send TCP segment with FIN bit = 1 ❖respond to received FIN with ACK
▪ on receiving FIN, ACK can be combined with own FIN
❖simultaneous FIN exchanges can be handled
27

TCP 4-way handshake
client state
ESTAB
server state
ESTAB CLOSE_WAIT
LAST_ACK
CLOSED
FIN_WAIT_1 FIN_WAIT_2
TIMED_WAIT
can no longer send but can receive data
wait for server close
FINbit=1, seq=x ACKbit=1; ACKnum=x+1
FINbit=1, seq=y ACKbit=1; ACKnum=y+1
can still send data
clientSocket.close()
can no longer send data
CLOSED
timed wait for 2*max
segment lifetime
28

Setting up and Tearing down TCP Connections
A
SYN_SENT
ESTABLISHED
B
Listen SYN_RSVD
ESTABLISHED
Connection Establishment Phase
(via TCP 3-way handshake)
Data Transfer Phase
ACK
DATA
DATA
FIN
ACK
Connection Termination Phase
(via TCP 4-way handshake)
FIN_WAIT1
FIN_WAIT2 TIME_WAIT
CLOSED
ACK
FIN
CLOSE_WAIT LAST_ACK
CLOSED
29

Setting up and Tearing down TCP Connections
A
B
Requests a virtual circuit (TCP connection) and negotiates packet size with B
TCP 3-way handshake
Sends data packets one by one (in order)
SYN (Seq: 0, Ack: 0)
SYN + ACK (Seq: 0, Ack: 1)
ACK (Seq: 1, Ack: 1)
A can’t send data anymore, but can still accept
B can’t send data anymore
Closes connection
4-way handshake
Data (Seq: 1, Ack: 1, Len: 1460) Data (Seq: 1461, Ack: 1, Len: 1460)
Data (Seq: 1, Ack: 2921, Len 702)
Data 3 (Seq: 2921, Ack: 703, Len: 1460) Ack (Seq: 703, Ack: 4381)
FIN (Seq: 4381, Ack: 703)
ACK (Seq: 703, Ack: 4382)
FIN + ACK (Seq: 703, Ack: 4382) ACK (Seq: 4382, Ack: 704)
30

QoS – Quality of Service
• QoS defines and assigns priorities to “classes of service”
• Timeliness – timely delivery of packets
– Packets be delivered within a certain period of time (to
produce a smooth, continuous output)
– Required by some applications, especially real time applications (e.g., voice and video frames)
• QoS routing
– Defines classes of service, each with a different priority: • Real-time applications such as VoIP- highest
• A graphical file for a Web page – a lower priority
• E-mail – lowest (can wait a long time before delivery)
31

Protocols Supporting QoS
• TCP/IP protocol suite
– Resource Reservation Protocol (RSVP)
• Sets up virtual circuits for general purpose real-time applications
– Real-Time Streaming Protocol (RTSP)
• Sets up virtual circuits for audio-video applications
– Real-Time Transport Protocol (RTP)
• Used after a virtual connection setup by RSVP or RTSP
• Adds a sequence number and a timestamp for helping applications to synchronize delivery
• Uses UDP (because of its small header) as transport 32
RSVP
RTP
UDP
RTSP
IP

END
33