Professional Documents
Culture Documents
2
Some network apps
e-mail voice over IP (e.g.,
web Skype)
text messaging real-time video
remote login
conferencing
P2P file sharing
social networking
multi-user network
search
games …
streaming stored video …
(YouTube, Hulu,
Netflix)
clients:
communicate with server
may be intermittently
client/server
connected
may have dynamic IP
addresses
do not communicate directly
with each other
transport transport
network network controlled
link by OS
link Internet
physical physical
Application
2-12 Layer
Internet transport protocols services
TCP service: UDP service:
reliable transport unreliable data transfer
between sending and between sending and
receiving process receiving process
flow control: sender does not provide:
won’t overwhelm reliability, flow control,
receiver
congestion control, timing,
congestion control: throughput guarantee,
throttle sender when security, or connection
network overloaded
setup,
does not provide: timing,
minimum throughput
guarantee, security Q: why bother? Why is
connection-oriented: there a UDP?
setup required between
client and server
processes
Application
2-13 Layer
Internet apps: application, transport protocols
application underlying
application layer protocol transport protocol
Application
2-14 Layer
Securing TCP
Application
2-15 Layer
Lecture 04: Roadmap
Chapter 02:
2.1 Principles of network applications
2.2 Web and HTTP
16
Web and HTTP
First, a review…
web page consists of objects
object can be HTML file, JPEG image, Java
applet, audio file,…
web page consists of base HTML-file which
includes several referenced objects
each object is addressable by a URL, e.g.,
www.someschool.edu/someDept/pic.gif
time
21
Nonpersistent HTTP (cont.)
22
Non-persistent HTTP: response time
Application
2-23 Layer
Persistent HTTP
~
~ entity body ~
~ body
Application
2-26 Layer
Uploading form input
POST method:
web page often
includes form input
input is uploaded to
server in entity body
URL method:
uses GET method
input is uploaded in
URL field of request
line: www.somesite.com/animalsearch?monkeys&banana
HTTP/1.0: HTTP/1.1:
GET GET, POST, HEAD
POST PUT
HEAD ❖ uploads file in
❖ asks server to leave entity body to path
requested object specified in URL
out of response field
DELETE
❖ deletes file
specified in the
URL field
Application Layer 2-28
HTTP response message
status line
(protocol
status code HTTP/1.1 200 OK\r\n
status phrase) Date: Sun, 26 Sep 2010 20:09:20 GMT\r\n
Server: Apache/2.0.52 (CentOS)\r\n
Last-Modified: Tue, 30 Oct 2007 17:00:02 GMT\r\n
ETag: "17dc6-a5c-bf716880"\r\n
header Accept-Ranges: bytes\r\n
Content-Length: 2652\r\n
lines
Keep-Alive: timeout=10, max=100\r\n
Connection: Keep-Alive\r\n
Content-Type: text/html; charset=ISO-8859-1\r\n
\r\n
data data data data data ...
data, e.g.,
requested
HTML file
Application
2-29 Layer
HTTP response status codes
❖ status code appears in 1st line in server-to-
client response message.
❖ some sample codes:
200 OK
❖ request succeeded, requested object later in this msg
301 Moved Permanently
❖ requested object moved, new location specified later in this
msg (Location:)
400 Bad Request
❖ request msg not understood by server
404 Not Found
❖ requested document not found on this server
505 HTTP Version Not Supported
Application Layer 2-30
Review
What is
❖ Client-server ❖ Put method
❖ Peer-to-peer ❖ Head method
❖ TCP ❖ Delete method
❖ UDP ❖ Http Non-persistent
❖ Socket ❖ Http Persistent
❖ SSL
❖ http
❖ Post method
❖ Get method
31
Lecture 05
Cookies, FTP,
Electronic Mail & DNS
2
User-server state: cookies
many Web sites use cookies example:
❖ Susan always access Internet
four components:
from PC
1) cookie header line of
❖ visits specific e-commerce
HTTP response
site for first time
message
❖ when initial HTTP requests
2) cookie header line in arrives at site, site creates:
next HTTP request
message ▪ unique ID
▪ entry in backend
3) cookie file kept on
database for ID
user’s host, managed
by user’s browser
4) back-end database at
Web site
Application Layer2-3
Cookies: keeping “state” (cont.)
client server
ebay 8734
usual http request msg Amazon server
cookie file creates ID
usual http response
1678 for user create backend
ebay 8734
set-cookie: 1678 entry database
amazon 1678
usual http request msg
cookie: 1678 cookie- access
specific
usual http response msg action
Application Layer2-5
Web caches (proxy server)
goal: satisfy client request without involving origin server
Application Layer2-6
More about Web caching
❖ cache acts as both why Web caching?
client and server ❖ reduce response time
▪ server for original for client request
requesting client
▪ client to origin server ❖ reduce traffic on an
❖ typically cache is institution’s access link
installed by ISP ❖ Internet dense with
(university, company, caches: enables “poor”
residential ISP) content providers to
effectively deliver
content (so too does
P2P file sharing)
Application Layer2-7
Conditional GET
client server
❖ Goal: don’t send object if
cache has up-to-date
cached version HTTP request msg
object
If-modified-since: <date>
▪ no object transmission not
delay modified
▪ lower link utilization HTTP response
before
HTTP/1.0
❖ cache: specify date of 304 Not Modified <date>
cached copy in HTTP
request
If-modified-since:
<date> HTTP request msg
❖ server: response contains If-modified-since: <date> object
modified
no object if cached copy after
HTTP response
is up-to-date: HTTP/1.0 200 OK <date>
HTTP/1.0 304 Not <data>
Modified
Application Layer2-8
Lecture 05: Roadmap
Chapter 2:
❖ 2.2 Web and HTTP
❖ 2.3 FTP
❖ 2.4 Electronic Mail
▪ SMTP, POP3, IMAP
❖ 2.5 DNS
9
FTP: the file transfer protocol
file transfer
FTP FTP FTP
user client server
interface
user
at host remote file
local file system
system
Application Layer2-11
FTP commands, responses
sample commands: sample return codes
❖ sent as ASCII text over ❖ status code and phrase (as
control channel in HTTP)
❖ USER username ❖ 331 Username OK,
❖ PASS password password required
❖ LIST return list of file in ❖ 125 data
current directory connection
already open;
❖ RETR filename transfer starting
retrieves (gets) file ❖ 425 Can’t open
❖ STOR filename stores data connection
(puts) file onto remote ❖ 452 Error writing
host file
Application Layer2-12
Lecture 05: Roadmap
Chapter 2:
❖ 2.2 Web and HTTP
❖ 2.3 FTP
❖ 2.4 Electronic Mail
▪ SMTP, POP3, IMAP
❖ 2.5 DNS
13
Electronic mail outgoing
message queue
user mailbox
Three major components: user
❖ user agents agent
Application Layer2-14
Electronic mail: mail servers
mail servers: user
agent
❖ mailbox contains incoming
messages for user mail user
server
❖ message queue of outgoing agent
Application Layer2-15
Electronic Mail: SMTP [RFC 2821]
❖ uses TCP to reliably transfer email message from
client to server, port 25
❖ direct transfer: sending server to receiving
server
❖ three phases of transfer
▪ handshaking (greeting)
▪ transfer of messages
▪ closure
❖ command/response interaction (like HTTP, FTP)
▪ commands: ASCII text
▪ response: status code and phrase
❖ messages must be in 7-bit ASCI
Application Layer2-16
Scenario: Alice sends message to Bob
1) Alice uses UA to compose 4) SMTP client sends Alice’s
message “to” message over the TCP
bob@someschool.edu connection
2) Alice’s UA sends message 5) Bob’s mail server places the
to her mail server; message message in Bob’s mailbox
placed in message queue 6) Bob invokes his user agent
3) client side of SMTP opens to read message
TCP connection with Bob’s
mail server
Application Layer2-18
SMTP: final words
❖ SMTP uses persistent comparison with HTTP:
connections
❖ HTTP: pull
❖ SMTP requires message
(header & body) to be in ❖ SMTP: push
7-bit ASCII ❖ both have ASCII
❖ SMTP server uses command/response
CRLF.CRLF to interaction, status codes
determine end of message
❖ HTTP: each object
encapsulated in its own
response msg
❖ SMTP: multiple objects
sent in one msg
Application Layer2-19
Mail message format
Application Layer2-20
Mail access protocols
user
mail access user
SMTP SMTP protocol
agent agent
(e.g., POP,
IMAP)
Application Layer2-21
POP3 protocol
S: +OK POP3 server ready
C: user bob
authorization phase S:
C:
+OK
pass hungry
❖ client commands: S: +OK user successfully logged on
▪ user: declare username
▪ pass: password C: list
S: 1 498
❖ server responses
S: 2 912
▪ +OK S: .
▪ -ERR C: retr 1
transaction phase, client: S:
S:
<message 1 contents>
.
❖ list: list message numbers C: dele 1
❖ retr: retrieve message by C: retr 2
number S: <message 1 contents>
❖ dele: delete S: .
❖ quit C: dele 2
C: quit
S: +OK POP3 server signing off
Application Layer2-22
POP3 (more) and IMAP
more about POP3 IMAP
❖ previous example uses ❖ keeps all messages in one
POP3 “download and place: at server
delete” mode ❖ allows user to organize
▪ Bob cannot re-read e- messages in folders
mail if he changes ❖ keeps user state across
client sessions:
❖ POP3 “download-and- ▪ names of folders and
keep”: copies of messages mappings between
on different clients message IDs and folder
❖ POP3 is stateless across name
sessions
Application Layer2-23
Lecture 05: Roadmap
Chapter 2:
❖ 2.2 Web and HTTP
❖ 2.3 FTP
❖ 2.4 Electronic Mail
▪ SMTP, POP3, IMAP
❖ 2.5 DNS
24
DNS: domain name system
people: many identifiers: Domain Name System:
▪ SSN, name, passport # ❖ distributed database
Internet hosts, routers: implemented in hierarchy of
▪ IP address (32 bit) - many name servers
used for addressing ❖ application-layer protocol: hosts,
datagrams name servers communicate to
▪ “name”, e.g., resolve names (address/name
www.yahoo.com - translation)
used by humans ▪ note: core Internet function,
Q: how to map between IP implemented as application-
layer protocol
address and name, and
vice versa ? ▪ complexity at network’s
“edge”
Application Layer2-25
DNS: services, structure
DNS services why not centralize DNS?
❖ hostname to IP address ❖ single point of failure
translation ❖ traffic volume
❖ host aliasing ❖ distant centralized database
▪ canonical, alias names ❖ maintenance
❖ mail server aliasing
❖ load distribution A: doesn’t scale!
▪ replicated Web
servers: many IP
addresses correspond
to one name
Application Layer2-26
DNS: a distributed, hierarchical database
Root DNS Servers
… …
Application Layer2-27
DNS: root name servers
❖ contacted by local name server that can not resolve name
❖ root name server:
▪ contacts authoritative name server if name mapping not known
▪ gets mapping
▪ returns mapping to local name server
Application Layer2-28
TLD, authoritative servers
top-level domain (TLD) servers:
▪ responsible for com, org, net, edu, aero, jobs, museums,
and all top-level country domains, e.g.: uk, fr, ca, jp
▪ Network Solutions maintains servers for .com TLD
▪ Educause for .edu TLD
authoritative DNS servers:
▪ organization’s own DNS server(s), providing
authoritative hostname to IP mappings for organization’s
named hosts
▪ can be maintained by organization or service provider
Application Layer2-29
Local DNS name server
❖ does not strictly belong to hierarchy
❖ each ISP (residential ISP, company, university) has one
▪ also called “default name server”
❖ when host makes DNS query, query is sent to its local DNS server
▪ has local cache of recent name-to-address translation pairs (but may be out
of date!)
▪ acts as proxy, forwards query into hierarchy
Application Layer2-30
DNS name root DNS server
resolution example
2
❖ host at cis.poly.edu 3
TLD DNS server
wants IP address for 4
gaia.cs.umass.edu
5
gaia.cs.umass.edu
Application Layer2-31
DNS name root DNS server
resolution example
2 3
recursive query: 7
6
❖ puts burden of name TLD DNS
server
resolution on
contacted name local DNS server
server dns.poly.edu 5 4
gaia.cs.umass.edu
Application Layer2-32
DNS: caching, updating records
❖ once (any) name server learns mapping, it caches
mapping
▪ cache entries timeout (disappear) after some time (TTL)
▪ TLD servers typically cached in local name servers
• thus root name servers not often visited
❖ cached entries may be out-of-date (best effort
name-to-address translation!)
▪ if name host changes IP address, may not be known
Internet-wide until all TTLs expire
❖ update/notify mechanisms proposed IETF standard
▪ RFC 2136
Application Layer2-33
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name, value, type, ttl)
type=A type=CNAME
▪ name is hostname ▪ name is alias name for some
▪ value is IP address “canonical” (the real) name
type=NS ▪ www.ibm.com is really
▪ name is domain (e.g., servereast.backup2.ibm.com
foo.com) ▪ value is canonical name
▪ value is hostname of
authoritative name type=MX
server for this domain ▪ value is name of mailserver
associated with name
Application Layer2-34
Inserting records into DNS
❖ example: new startup “Network Utopia”
❖ register name networkuptopia.com at DNS registrar
(e.g., Network Solutions)
▪ provide names, IP addresses of authoritative name server
(primary and secondary)
▪ registrar inserts two RRs into .com TLD server:
(networkutopia.com, dns1.networkutopia.com, NS)
(dns1.networkutopia.com, 212.212.212.1, A)
❖ create authoritative server type A record for
www.networkuptopia.com; type MX record for
networkutopia.com
Application Layer2-35
Review
❖ What is ▪ TLD DNS Server
▪ Cookie ▪ Authoritative DNS Server
▪ Web Proxy ▪ Local DNS Server
▪ FTP ▪ DNS Records
▪ Dual Band Channel in FTP ▪ MX
▪ SMTP Server ▪ CNAME
▪ SMTP Client ▪ NS
▪ User Agent ▪ DNS Query
▪ POP3 ▪ DNS Response
▪ IMAP
▪ DNS
▪ Root DNS Server
Application Layer2-36
Transport Layer
Socket programming
2
Socket programming
goal: learn how to build client/server applications that
communicate using sockets
socket: door between application process and end-
end-transport protocol
application application
socket controlled by
process process app developer
transport transport
network network controlled
link by OS
link Internet
physical physical
Application Example:
1. Client reads a line of characters (data) from its
keyboard and sends the data to the server.
2. The server receives the data and converts
characters to uppercase.
3. The server sends the modified data to the client.
4. The client receives the modified data and displays
the line on its screen.
Application Layer 2-4
Socket programming with UDP
UDP: no “connection” between client & server
❖ no handshaking before sending data
❖ sender explicitly attaches IP destination address and
port # to each packet
❖ rcvr extracts sender IP address and port# from
received packet
UDP: transmitted data may be lost or received
out-of-order
Application viewpoint:
❖ UDP provides unreliable transfer of groups of bytes
(“datagrams”) between client and server
write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket
Application 2-6
Example app: UDP client Python version 2
Python UDPClient
include Python’s socket
library
from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for clientSocket = socket(AF_INET, SOCK_DGRAM)
server
Python UDPServer
from socket import *
serverPort = 12000
create UDP socket serverSocket = socket(AF_INET, SOCK_DGRAM)
bind socket to local port
number 12000
serverSocket.bind(('', serverPort))
print “The server is ready to receive”
loop forever while 1:
Read from UDP socket into message, clientAddress = serverSocket.recvfrom(2048)
message, getting client’s
address (client IP and port) modifiedMessage = message.upper()
send upper case string serverSocket.sendto(modifiedMessage, clientAddress)
back to this client
write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
Python TCPClient
from socket import *
serverName = ’servername’
create TCP socket for
serverPort = 12000
server, remote port 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input(‘Input lowercase sentence:’)
No need to attach server clientSocket.send(sentence)
name, port
modifiedSentence = clientSocket.recv(1024)
print ‘From Server:’, modifiedSentence
clientSocket.close()
Python TCPServer
from socket import *
create TCP welcoming serverPort = 12000
socket serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind((‘’,serverPort))
server begins listening for
incoming TCP requests serverSocket.listen(1)
print ‘The server is ready to receive’
loop forever
while 1:
server waits on accept()
for incoming requests, new
connectionSocket, addr = serverSocket.accept()
socket created on return
sentence = connectionSocket.recv(1024)
read bytes from socket (but
not address as in UDP) capitalizedSentence = sentence.upper()
close connection to this connectionSocket.send(capitalizedSentence)
client (but not welcoming
socket) connectionSocket.close()
Application Layer 2-12
Example app: UDP client Python version 3
Python UDPClient
from socket import *
serverName = 'localhost'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_DGRAM)
Python UDPServer
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('localhost', serverPort))
print ('The server is ready to receive')
while 1:
message, clientAddress = serverSocket.recvfrom(2048)
modifiedMessage = message.upper()
print('Message from client',message)
print('Message answer for client',modifiedMessage)
serverSocket.sendto(modifiedMessage, clientAddress)
Application Layer 2-14
Example app: TCP client Python version 3
Python TCPClient
from socket import *
serverName = 'localhost'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = input('Input lowercase sentence: ')
clientSocket.send(sentence.encode())
modifiedSentence = clientSocket.recv(1024)
print('Answer From Server: ', modifiedSentence.decode())
clientSocket.close()
Python TCPServer
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind(('localhost',serverPort))
serverSocket.listen(1)
sentence = connectionSocket.recv(1024)
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence)
connectionSocket.close() Application Layer 2-16
Chapter 2: summary
our study of network apps now complete!
❖ application architectures ❖ specific protocols:
▪ client-server ▪ HTTP
▪ P2P ▪ FTP
❖ application service
requirements: ▪ SMTP, POP3, IMAP
▪ reliability, bandwidth, delay ▪ DNS
❖ Internet transport service ▪ P2P
model ❖ socket programming: TCP,
▪ connection-oriented, UDP sockets
reliable: TCP
▪ unreliable, datagrams: UDP
1
Lecture 07: Roadmap
❖ 3.1 Transport-layer services
❖ 3.2 Multiplexing and demultiplexing
❖ 3.3 Connectionless transport: UDP
❖ 3.4 Connection-oriented transport: TCP
▪ segment structure
▪ reliable data transfer
▪ flow control
▪ connection management
2
Transport services and protocols
❖ provide logical communication application
Transport Layer3-3
Transport vs. network layer
❖ network layer: logical household analogy:
communication
between hosts 12 kids in Ann’s house sending
letters to 12 kids in Bill’s
❖ transport layer: house:
logical ❖ hosts = houses
communication ❖ processes = kids
Transport Layer3-4
Internet transport-layer protocols
application
❖ reliable, in-order transport
network
network
▪ delay guarantees
▪ bandwidth guarantees
Transport Layer3-5
Multiplexing/demultiplexing
multiplexing at sender:
handle data from multiple demultiplexing at receiver:
sockets, add transport header (later use header info to deliver
used for demultiplexing) received segments to correct
socket
application
Transport Layer3-6
How demultiplexing works
❖ host receives IP datagrams 32 bits
▪ each datagram has source IP
source port # dest port #
address, destination IP
address
▪ each datagram carries one other header fields
transport-layer segment
▪ each segment has source,
destination port number application
data
❖ host uses IP addresses & (payload)
port numbers to direct
segment to appropriate
socket TCP/UDP segment format
Transport Layer3-7
Connectionless demultiplexing
❖ recall: created socket has ❖ recall: when creating
host-local port #: datagram to send into
clientSocket=socket(AF_INET, UDP socket, must specify
SOCK_DGRAM)
▪ destination IP address
▪ destination port #
Transport Layer3-8
Connectionless demux: example
serverSocket=socket
clientSocket=sock mySocket1=socket(A
et(AF_INET,
(AF_INET, F_INET,
SOCK_DGRAM) SOCK_DGRAM) SOCK_DGRAM)
clientSocket.bind serverSocket.bind(( mySocket1.bind((‘’
((‘’,9157)) ‘’,6428)) ,5775))
application
application application
P1
P3 P4
transport
transport transport
network
network link network
link physical link
physical physical
Transport Layer3-10
Connection-oriented demux: example
application
application P4 P5 P6 application
P3 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: IP physical
address B
Transport Layer3-12
UDP: User Datagram Protocol [RFC 768]
❖ “no frills,” “bare bones” ❖ UDP use:
Internet transport ▪ streaming multimedia
protocol apps (loss tolerant, rate
❖ “best effort” service, sensitive)
UDP segments may be: ▪ DNS
▪ lost ▪ SNMP
▪ delivered out-of-order ❖ reliable transfer over
to app
UDP:
❖ connectionless:
▪ add reliability at
▪ no handshaking application layer
between UDP sender,
receiver ▪ application-specific error
recovery!
▪ each UDP segment
handled independently
of others
Transport Layer3-13
UDP: segment header
length, in bytes of
32 bits UDP segment,
source port # dest port # including header
length checksum
why is there a UDP?
❖ no connection
application establishment (which can
data add delay)
(payload) ❖ simple: no connection
state at sender, receiver
❖ small header size
UDP segment format ❖ no congestion control:
UDP can blast away as
fast as desired
Transport Layer3-14
UDP checksum
Goal: detect “errors” (e.g., flipped bits) in transmitted
segment
sender: receiver:
❖ treat segment contents, ❖ compute checksum of
including header fields, received segment
as sequence of 16-bit ❖ check if computed
integers
checksum equals checksum
❖ checksum: addition field value:
(one’s complement
sum) of segment ▪ NO - error detected
contents ▪ YES - no error detected.
❖ sender puts checksum But maybe errors
value into UDP nonetheless? More later
checksum field ….
Transport Layer3-15
Internet checksum: example
example: add two 16-bit integers
1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
Transport Layer3-16
TCP: Overview RFCs: 793,1122,1323, 2018, 2581
Transport Layer3-17
TCP segment structure
32 bits
URG: urgent data counting
(generally not used) source port # dest port #
by bytes
sequence number of data
ACK: ACK #
valid acknowledgement number (not segments!)
head not
PSH: push data now len used
UAP R S F receive window
(generally not used) # bytes
checksum Urg data pointer
rcvr willing
RST, SYN, FIN: to accept
options (variable length)
connection estab
(setup, teardown
commands)
application
Internet data
checksum (variable length)
(as in UDP)
Transport Layer3-18
TCP seq. numbers, ACKs
outgoing segment from sender
sequence numbers: source port # dest port #
sequence number
▪byte stream “number” of acknowledgement number
data
checksum urg pointer
window size
acknowledgements: N
Transport Layer3-19
TCP seq. numbers, ACKs
Host A Host B
User
types
‘C’ Seq=42, ACK=79, data = ‘C’
host ACKs
receipt of
‘C’, echoes
Seq=79, ACK=43, data = ‘C’ back ‘C’
host ACKs
receipt
of echoed
‘C’ Seq=43, ACK=80
Transport Layer3-20
Review
❖ What is ▪ Connection Oriented
▪ TCP ▪ Connectionless
▪ UDP ▪ Three-way Handshake
▪ TCP Window ▪ TCP Sequence Number
▪ Congestion Control ▪ TCP Acknowledgement Number
▪ Flow Control ▪ Maximum Segment Size
▪ Multiplexing ▪ TCP Socket
▪ Demultiplexing ▪ UDP Socket
▪ TCP Timeout Interval ▪ Checksum
Transport Layer3-21
Exercises 01
Consider a TCP connection between host A and host B.
Suppose that the TCP segments traveling from host A to
host B have source port number x and destination port
number y. What are the source and destination port
numbers for the segments traveling from host B to host A?
Transport Layer3-22
Exercises 02
Suppose that a Web server runs in host C on port 80.
Suppose this Web server uses persistent connections, and is
currently receiving requests from two different hosts: A and
B. Are all of the requests being sent through the same socket
at host C? If they are being passed through different sockets,
do both of the sockets have port 80? Discuss and explain.
Transport Layer3-23
Exercise 03
Suppose you have the following two bytes: 00110101 and
01101001. What is the 1s complement of these two bytes?
Transport Layer3-24
Exercise 04
Suppose a process in host C has a UDP socket with port
number 787. Suppose host A and host B, each send a UDP
segment to host C with destination port number 787. Will
both of these segments be directed to the same socket at
host C? If so, how will the process at host C know that these
segments originated from two different hosts?
Transport Layer3-25
Lecture 07
Transport Layer
Penjelasan
TCP ACK generation [RFC 1122, RFC 2581]
1
TCP ACK generation [RFC 1122, RFC 2581]
RULE 1
RULE 2
RULE 3
Transport Layer 3-5
TCP ACK generation [RFC 1122, RFC 2581]
event at receiver
arrival of segment that
partially or completely fills gap
RULE 4
Transport Layer 3-6
Lecture 08
1
Lecture 08: Roadmap
❖ 3.4 Connection-oriented transport: TCP
▪ segment structure
▪ reliable data transfer
▪ flow control
▪ connection management
❖ 3.5 TCP congestion control
2
TCP reliable data transfer
❖ TCP creates rdt service
on top of IP’s unreliable
service
▪ pipelined segments
▪ cumulative acks let’s initially consider
▪ single retransmission simplified TCP sender:
timer ▪ ignore duplicate acks
❖ retransmissions ▪ ignore flow control,
triggered by: congestion control
▪ timeout events
▪ duplicate acks
Transport Layer3-3
TCP sender events:
data rcvd from app: timeout:
❖ create segment with ❖ retransmit segment
seq # that caused timeout
❖ seq # is byte-stream ❖ restart timer
number of first data ack rcvd:
byte in segment ❖ if ack acknowledges
❖ start timer if not previously unacked
already running segments
▪ think of timer as for ▪ update what is known
oldest unacked to be ACKed
segment
▪ start timer if there are
▪ expiration interval: still unacked segments
TimeOutInterval
Transport Layer3-4
TCP: retransmission scenarios
Host A Host B Host A Host B
SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data
timeout
ACK=100
X
ACK=100
ACK=120
SendBase=120
ACK=100
X
ACK=120
cumulative ACK
Transport Layer3-6
TCP ACK generation [RFC 1122, RFC 2581]
Transport Layer3-7
TCP fast retransmit
❖ time-out period often
relatively long: TCP fast retransmit
▪ long delay before if sender receives 3
resending lost packet ACKs for same data
❖ detect lost segments (“triple duplicate ACKs”),
via duplicate ACKs. resend unacked
▪ sender often sends segment with smallest
many segments back- seq #
to-back
▪ likely that unacked
▪ if segment is lost, there segment lost, so don’t
will likely be many wait for timeout
duplicate ACKs.
Transport Layer3-8
TCP fast retransmit
Host A Host B
ACK=100
timeout
ACK=100
ACK=100
ACK=100
Seq=100, 20 bytes of data
IP
flow control code
receiver controls sender, so
sender won’t overflow
receiver’s buffer by transmitting from sender
too much, too fast
receiver protocol stack
Transport Layer3-10
TCP flow control
❖ receiver “advertises” free
buffer space by including to application process
rwnd value in TCP header
of receiver-to-sender
segments RcvBuffer buffered data
▪ RcvBuffer size set via
socket options (typical default rwnd free buffer space
is 4096 bytes)
▪ many operating systems
autoadjust RcvBuffer TCP segment payloads
❖ sender limits amount of
unacked (“in-flight”) data to receiver-side buffering
receiver’s rwnd value
❖ guarantees receive buffer
will not overflow
Transport Layer3-11
Connection Management
before exchanging data, sender/receiver “handshake”:
❖ agree to establish connection (each knowing the other willing
to establish connection)
❖ agree on connection parameters
application application
network network
Transport Layer3-12
TCP 3-way handshake
Transport Layer3-13
TCP: 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
Transport Layer3-14
TCP: closing a connection
client state server state
ESTAB ESTAB
clientSocket.close()
FIN_WAIT_1 can no longer FINbit=1, seq=x
send but can
receive data CLOSE_WAIT
ACKbit=1; ACKnum=x+1
can still
FIN_WAIT_2 wait for server send data
close
LAST_ACK
FINbit=1, seq=y
TIMED_WAIT can no longer
send data
ACKbit=1; ACKnum=y+1
timed wait
for 2*max CLOSED
segment lifetime
CLOSED
Transport Layer3-15
TCP congestion control: additive increase
multiplicative decrease
❖ approach: sender increases transmission rate (window
size), probing for usable bandwidth, until loss occurs
▪ additive increase: increase cwnd by 1 MSS every
RTT until loss detected
▪ multiplicative decrease: cut cwnd in half after loss
additively increase window size …
…. until loss occurs (then cut window in half)
time
Transport Layer3-16
Chapter 3: summary
❖ principles behind
transport layer services:
▪ multiplexing,
demultiplexing next:
❖ leaving the
▪ reliable data transfer
network “edge”
▪ flow control (application,
▪ congestion control transport layers)
❖ instantiation, ❖ into the network
implementation in the “core”
Internet
▪ UDP
▪ TCP
Transport Layer3-17
Review
❖ What is TCP ▪ Fast Retransmit
▪ Pipeline ▪ Congestion Window
▪ Cumulative Ack
▪ Single Retransmission Timer
▪ Timeout Interval
▪ Duplicate ACK
▪ Flow Control
▪ Premature timeout
Transport Layer3-18
Exercise 01
Consider sending a large file from one host to another over a TCP
connection that has no loss.
❖ Suppose TCP uses AIMD (Additive Increase multiple decrease) for its
congestion control without slow start. Assuming CWND (Congestion
Window) increases by 1 MSS every time an ACK is received and assuming
approximately constant round-trip times, how long does it take for CWND to
increase from 1 MSS to 5 MSS (assuming no loss events and constant RTT)?
❖ What is the average throughput (in terms of MSS and RTT) for this connection
up through time = 4 RTT?
Transport Layer3-19
Exercise 02 (1/2)
Host A and B are communicating over a
TCP connection, and Host B has already
received from A all bytes up through byte
144. Suppose that Host A then sends two
segments to Host B back-to-back. The first
and second segments contain 20 and 40
bytes of data, respectively. In the first
segment, the sequence number is 145,
source port number is 303, and the
destination port number is 80. Host B
sends an acknowledgement whenever it
receives a segment from Host A.
Transport Layer3-20
Exercise 02 (2/2)
a) In the second segment sent from Host A to B, what are the
sequence number, source port number, and destination port
number?
b) If the first segment arrives before the second segment, in the
acknowledgement of the first arriving segment, what is the
acknowledgment number, the source port number, and the
destination port number?
c) If the second segment arrives before the first segment, in the
acknowledgement of the first arriving segment, what is the
acknowledgment number?
d) Suppose the two segments sent by A arrive in order at B. The first
acknowledgement is lost and the second segment arrives after the
first timeout interval, as shown in the figure below. Complete the
diagram, showing all other segments and acknowledgements sent.
(Assume there is no additional packet loss.) For each segment you
add to the diagram, provide the sequence number and number of
bytes of data; for each acknowledgement that you add, provide the
acknowledgement number. Transport Layer3-21
Exercise 3
❖ UDP and TCP use 1s complement for their checksums.
Suppose you have the following three 8-bit bytes:
▪ 01010011
▪ 01100110
▪ 01110100
❖ Q1. What is the 1s complement of the sum of these 8-bit
bytes?
Transport Layer3-22
Exercise 3
❖ Q2. Why is it that UDP takes the 1s complement of the
sum; that is, why not just use the sum?
▪ With the 1s complement scheme, how does the receiver detect
errors?
❖ Q3. Is it possible that a 1-bit error will go undetected?
❖ Q4. How about a 2-bit error?
Transport Layer3-23