Advanced Network Technologies Applications
Dr. Wei Bao | Lecturer School of Computer Science
HTTP/2
Key goal: decreased delay in multi-object HTTP requests HTTP1.1: introduced multiple, pipelined GETs over single
TCP connection
server responds in-order (FCFS: first-come-first-served scheduling) to GET requests
with FCFS, small object may have to wait for transmission (head-of-line (HOL) blocking) behind large object(s)
loss recovery (retransmitting lost TCP segments) stalls object transmission
HTTP/2
Key goal: decreased delay in multi-object HTTP requests HTTP/2: [RFC 7540, 2015] increased flexibility at server in
sending objects to client:
methods, status codes, most header fields unchanged from HTTP 1.1
transmission order of requested objects based on client- specified object priority (not necessarily FCFS)
push unrequested objects to client
divide objects into frames, schedule frames to mitigate Head- of-line (HOL) blocking
HTTP/2: mitigating HOL blocking
HTTP 1.1: client requests 1 large object (e.g., video file, and 3 smaller objects)
server
GET client O4
GET GET O3 O2
GET O1
object data requested
O1
O2 O3 O4
O1 O
2 O3 O 4
oObjects delivered in order requested: O2, O3, O4 wait behind 1
HTTP/2: mitigating HOL blocking
HTTP/2: objects divided into frames, frame transmission interleaved
server
GET client O4
GET GET GET O3 O2 O1
object data requested
O1
O2 O3 O4
O 2O
4O 3
O 1
O2, O3, O4 delivered quickly, O1 slightly delayed
HTTP/2 Streams and frames
Client Server
HTTP/2 Streams and frames
Frames:
• Basic HTTP/2 data unit, replacing HTTP/1.1 header
and body format.
• HTTP/2 frames have a binary encoding (more
efficient).
• Header frames, Data frames
Streams
• Bidirectional channel where frames are transmitted • Replacing HTTP/1.1 Request-Response mode
A single TCP connection to carry multiple streams
HTTP/2 push
The HTTP/2 Server Push mechanism allows the server to send resources proactively without waiting for a request, when it believes the client will need them.
https://blog.golang.org/h2push
Outline
› Web and HTTP (Done) › FTP
› Email
› DNS
› P2P
FTP
FTP: the file transfer protocol
FTP
user interface
FTP client
FTP server
user at host
file transfer
local file system
remote file system
transfer file to/from remote host client/server model
client: side that initiates transfer (either to/from remote)
server: remote host
ftp: RFC 959
ftp server: port 21, 20
FTP: separate control, data connections
› FTP client contacts FTP server at port 21, using TCP
› client authorized over control connection
› client browses remote directory, sends commands over control connection
› when server receives file transfer command, server opens 2nd TCP data connection (for file) to client
› after transferring one file, server closes data connection
FTP client
TCP control connection, server port 21
TCP data connection, FTP
server port 20
server
› server opens another TCP data connection to transfer another file
› control connection: “out of band”
› FTP server maintains “state”: current directory, earlier authentication
FTP commands, responses
sample commands:
› sent as ASCII text over control channel
› USER username
› PASS password
› LIST return list of file in current directory
› RETR filename retrieves (gets) file
› STOR filename stores (puts) file onto remote host
sample return codes
› status code and phrase (as in HTTP)
› 331 Username OK, password required
› 125 data connection already open; transfer starting
› 425 Can’t open data connection
› 452 Error writing file
Email
SMTP: Simple Mail Transfer Protocol IMAP: Internet Message Access Protocol POP3: Post Office Protocol 3
Electronic mail
Three major components:
› user agents (clients)
› mail servers
› simple mail transfer protocol: SM TP
User Agent
› a.k.a. “mail reader”
› composing, editing, reading mail
messages
› e . g. , Outlook, Thunderbird, iPhone mail client
SMTP
SMTP
SMTP
outgoing message queue
user mailbox
user agent
mail server
user agent
mail server
user agent
user agent
mail server
user agent
user agent
Electronic mail: mail servers
mail servers:
› mailbox contains incoming messages for user
› message queue of outgoing (to be sent) mail messages
SMTP
SMTP
user agent
mail server
user agent
mail server
user agent
› SMTP protocol to send email SMTP messages between mail servers
– client: sending mail to server
– “server”: receiving mail from server
user agent
mail server
user agent
user agent
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:ASCIItext
– response: status code and phrase
› messages must be in 7-bit ASCII
› Q: is SMTP stateful or stateless?
– Stateful
Scenario: Alice sends message to Bob
1) Alice uses UA to compose message “to” bob@someschool.edu
2) Alice’s UA sends message to her mail server; message placed in message queue
3) client side of SMTP opens TCP connection with Bob’s mail server
1 user agent
4) SMTP client sends Alice’s message over the TCP connection
5) Bob’s mail server places the message in Bob’s mailbox
6) Bob invokes his user agent to read message
mail server
mail server
user agent
2
Alice’s mail server
4
6
3
5
Bob’s mail server
Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM:
S: 250 alice@crepes.fr… Sender ok
C: RCPT TO:
S: 250 bob@hamburger.edu … Recipient ok
C: DATA
S: 354 Enter mail, end with “.” on a line by itself C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection
SMTP: final words
› SMTP uses persistent connections
› SMTP requires message (header & body) to be in 7- bit ASCII
› SMTP server uses CRLF.CRLF to determine
end of message – Carriage return – Line feed
comparison with HTTP:
› HTTP: pull
› SMTP: push
› both have ASCII command/response interaction, status codes
› HTTP: each object encapsulated in its own response msg
› SMTP: multiple objects sent in one msg
Mail message format
SMTP: protocol for exchanging email msgs
RFC 822: standard for text message format:
› header lines, e.g., – To:
– From:
– Subject:
different from SMTP MAIL FROM, RCPT TO: commands!
› Body: the “message” – ASCII characters only
blank line
header
body
Mail access protocols
user agent
SMTP SMTP
sender’s mail server
mail access protocol
(e.g., POP, IMAP)
user agent
› SMTP: delivery/storage to receiver’s server › mail access protocol: retrieval from server
receiver’s mail server
– POP: Post Office Protocol [RFC 1939]: authorization, download
– IMAP: Internet Mail Access Protocol [RFC 1730]: more features, including
manipulation of stored msgs on server
– HTTP: Using a browser to access a webmail https://webmail.sydney.edu.au
POP3 Protocol
authorization phase
› client commands:
– user: declare username – pass: password
› server responses – +OK
– -ERR
transaction phase, client: › list: list message numbers
› retr: retrieve message by number › dele: delete
› quit
S: +OK POP3 server ready
C: user bob
S: +OK
C: pass hungry
S: +OK user successfully logged on C: list
S: 1 498
S: 2 912
S: .
C: retr 1
S:
C: dele 1
C: retr 2
S:
C: dele 2
C: quit
S: +OK POP3 server signing off
POP3 (more) and IMAP
more about POP3
› previous example uses POP3 “download and delete” mode
IMAP
› keeps all messages in one place: at server
› allows user to organize messages in folders
› keeps user state across sessions:
– names of folders and mappings between message IDs and folder name
– Bob cannot re-read e-mail if he changes client
› POP3 “download-and-keep”: copies of messages on different clients
› POP3 is stateless across sessions
DNS
DNS: domain name system
Internet hosts, routers:
– IP address (32 bit) – used for addressing datagrams
– “name”, e.g., www.yahoo.com – used by humans
people: many identifiers: – name, passport #
Q: how to map between IP address and name, and vice versa ?
Domain Name System:
› distributed database implemented in hierarchy of many name servers
› application-layer protocol: hosts, name servers communicate to resolve names (address/name translation)
DNS: services, structure
DNS services
› hostname to IP address translation
› host aliasing
– canonical, alias names
› mail server aliasing › load distribution
– replicated Web servers: many IP addresses correspond to one name
why not centralize DNS?
› single point of failure
› distant centralized database › scalability
DNS: a distributed, hierarchical database
com DNS servers
yahoo.com DNS servers
Root DNS Servers
……
org DNS servers
pbs.org DNS servers
edu DNS servers
poly.edu umass.edu DNS serversDNS servers
amazon.com DNS servers
client wants IP for www.amazon.com; 1st approx:
› client queries root server to find com DNS server
› client queries .com DNS server to get amazon.com DNS server
› client queries amazon.com DNS server to get IP address for www.amazon.com
DNS: root name servers
c. Cogent, Herndon, VA (5 other sites) d. U Maryland College Park, MD
h. ARL Aberdeen, MD
j. Verisign, Dulles VA (69 other sites )
e. NASA Mt View, CA
f. Internet Software C.
Palo Alto, CA (and 48 other sites)
a. Verisign, Los Angeles CA (5 other sites)
b. USC-ISI Marina del Rey, CA l. ICANN Los Angeles, CA
k. RIPE London (17 other sites)
i. Netnod, Stockholm (37 other sites)
m. WIDE Tokyo (5 other sites)
13 root name “servers” worldwide
(41 other sites)
g. US DoD Columbus, OH (5 other sites)
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
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
DNS name resolution example
root DNS server
› host at cis.poly.edu wants IP address for gaia.cs.umass.edu
iterated query:
contacted server replies with name of server to contact
“I don’t know this name, but ask this server”
2
3
TLD DNS server
7
.edu DNS server
local DNS server
dns.poly.edu
1 8
requesting host
cis.poly.edu
4
5
6
authoritative DNS server
dns.cs.umass.edu
gaia.cs.umass.edu
DNS name resolution example (cont’d)
recursive query:
puts burden of name resolution on contacted name server
heavy load at upper levels of hierarchy?
2
7
local DNS server
dns.poly.edu
18
requesting host
cis.poly.edu
3
root DNS server
6
TLD DNS server .edu DNS server
4
authoritative DNS server
dns.cs.umass.edu
5
gaia.cs.umass.edu
DNS caching, updating records
› once (any) name server learns mapping, it caches mapping
– cache entries timeout (disappear) after some time (TTL)
› 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
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name, value, type, ttl)
type= A
name is hostname
value is IP address
type=NS
– name is domain (e.g., foo.com)
– value is hostname of authoritative name server for this domain
type=CNAME
name is alias name for some
“canonical” (the real) name www.ibm.com is really
servereast.backup2.ibm.com value is canonical name
type=MX
value is name of mailserver associated with name
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
– registrar inserts two RRs into .com TLD server: (networkutopia.com, dns1.networkutopia.com, NS)
(dns1.networkutopia.com, 212.212.212.1, A)
› create at authoritative server
type A record for www.networkuptopia.com;
(www.networkutopia.com, 212.212.212.22, A) (www.home.networkutopia.com, www.networkutopia.com, CNAME)
Socket Programming
37
Socket programming
goal: learn how to build client/server applications that communicate using sockets
socket: door between application process and end-end-transport protocol
socket controlled by app developer
application
process
transport
network
link
physical
application
process
transport
network
link
physical
Internet
controlled by OS
38
Socket programming
Two socket types for two transport services:
– UDP: unreliable datagram
– TCP: reliable, byte stream-oriented
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.
39
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
› receiver 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
40
Client/server socket interaction: UDP
server (running on serverIP) create socket, port= x:
serverSocket = socket(AF_INET,SOCK_DGRAM)
read datagram from
serverSocket
write reply to
serverSocket
specifying client address, port number
client
create socket:
clientSocket = socket(AF_INET,SOCK_DGRAM)
Create datagram with server IP and port=x; send datagram via clientSocket
read datagram from
clientSocket
close
clientSocket
41
UDP client
include Python’s socket library
create UDP for server
get user keyboard input
Attach server name, port to message; send into socket
read reply characters from socket into string
print out received string and close socket
Python UDPClient
from socket import *
serverName = ‘hostname’
serverPort = 12000
clientSocket = socket(socket.AF_INET,
socket.SOCK_DGRAM) message = input(’Input lowercase sentence:’)
message = message.encode(‘utf-8’) clientSocket.sendto(message,(serverName, serverPort)) modifiedMessage, serverAddress =
clientSocket.recvfrom(2048) print (modifiedMessage.decode(‘utf-8’))
clientSocket.close()
convert from string to bytes convert from bytes to string New feature in Python 3
42
UDP server
create UDP socket
bind socket to local port number 12000
loop forever
Read from UDP socket into message, getting client’s address (client IP and port)
send upper case string back to this client
Python UDPServer
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM) serverSocket.bind((”, serverPort))
print “The server is ready to receive”
while 1:
message, clientAddress = serverSocket.recvfrom(2048)
message=message.decode(‘utf-8’)
modifiedMessage = message.upper() serverSocket.sendto(modifiedMessage.encode(‘utf-8’),
clientAddress)
43
Socket programming with TCP
client must contact server
› server process must first be running
› server must have created socket (door) that welcomes client’s contact
client contacts server by:
› creating TCP socket, connecting server by specifying IP address, port number of server process
› client connects: client TCP establishes connection to server TCP
› when contacted by client, server TCP creates new socket for server process to communicate with that particular client
– allows server to talk with multiple clients
– source port numbers used to distinguish clients
application viewpoint:
TCP provides reliable, in-order byte-stream transfer (“pipe”) between client and server
44
Client-server socket interaction TCP
server (running on hostid) create socket,
port=x,
serverSocket = socket()
client
wait for incoming connection request serverSocket.listen(1)
Accept client
connectionSocket = serverSocket.accept()
read request from
connectionSocket write reply to
connectionSocket
close
connectionSocket
TCP connection setup
create socket,
connect to hostid, port=x
clientSocket = socket() clientSocket.connect((hostid, x))
send request using
clientSocket
read reply from
clientSocket
close
clientSocket
45
TCP client
create TCP socket for server, remote port 12000
Python TCPClient
from socket import *
serverName = ’servername’
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) sentence = input(‘Input lowercase sentence:’) clientSocket.send(sentence.encode(‘utf-8’))
## Do not specify serverName,serverPort
modifiedSentence = clientSocket.recv(1024)
print (‘From Server:’, modifiedSentence.decode(‘utf-8’)) clientSocket.close()
No need to attach server name, port
46
TCP server
create TCP welcoming socket
server begins listening for incoming TCP requests
loop forever
server waits on accept() for incoming requests, new socket created on return
read bytes from socket (but not address as in UDP)
close connection to this client (but not welcoming socket)
Python TCPServer
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM) serverSocket.bind((‘’, serverPort)) serverSocket.listen(1)
print (‘The server is ready to receive’)
while 1:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024) capitalizedSentence = sentence.decode(‘utf-8’).upper().encode(‘utf-8’) connectionSocket.send(capitalizedSentence) connectionSocket.close()
47
Peer-to-Peer
48
Pure peer-to-peer model architecture
› no always-on server
› arbitrary end systems directly
communicate
› peers are intermittently connected and change IP addresses
examples:
– file distribution (BitTorrent) – Streaming (Zattoo, KanKan) – VoIP (Skype)
49
File distribution: client-server vs. p2p
Question: how much time to distribute file (size F) from one server to N peers? – peer upload/download capacity is limited resource
us: server upload capacity
file, size Fserver us uN
dN
u d
1 1 u2 d2
network (with abundant bandwidth)
di: peer i download capacity
di ui
ui: peer i upload capacity
50
File distribution time: client-server
› server transmission: must sequentially send (upload) N file copies:
– time to send one copy: F/us
– time to send N copies: NF/us client: each client must
download file copy
dmin = min client download rate
(worst case) client download time:
F/dmin
F
us
di
ui
network
time to distribute F to N clients using
client-server approach
Dc-s > max{NF/us,,F/dmin}
increases linearly in N
51
File distribution time: p2p
› server transmission: must upload at least one copy
– time to send one copy: F/us
client: each client must
download file copy
client download time: F/dmin
F
us
di
ui
network
clients: as aggregate must download NF bits = upload NF bits Max upload rate us + Σui
NF/(us + Σui)
time to distribute F to N clients using
P2P approach
DP2P > max{F/us,,F/dmin,,NF/(us + Σui)}
increases linearly in N …
… but so does this, as each peer brings service capacity
52
Client-server vs. p2p
client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us
3.5 3 2.5 2 1.5 1 0.5 0
P2P
Client-Server
0 5 10 15 20 25 30 35 N
53
Minimum Distribution Time
P2P file distribution: BitTorrent
BitTorrent, a file sharing application
› 20% of European internet traffic in 2012.
› Used for Linux distribution, software patches, distributing movies › Goal: quickly replicate large files to large number of clients
› Web server hosts a .torrent file (w/ file length, hash, tracker’s URL…) › A tracker tracks downloaders/owners of a file
› Files are divided into chunks (256kB-1MB)
› Downloaders download chunks from themselves (and owners)
› Tit-for-tat: the more one shares (server), the faster it can download (client) 54
P2P file distribution: BitTorrent
› file divided into 256KB chunks
› peers in torrent send/receive file chunks
tracker: tracks peers participating in torrent
Alice arrives …
… obtains list
of peers from tracker
… and begins exchanging
file chunks with peers in torrent
torrent: group of peers exchanging chunks of a file
55
P2P file distribution: BitTorrent
› peer joining torrent:
– has no chunks, but will accumulate
them over time from other peers
– registers with tracker to get list of peers, connects to subset of peers ( “neighbors”)
› while downloading, peer uploads chunks to other peers › peer may change peers with whom it exchanges chunks › churn: peers may come and go
› once peer has entire file, it may (selfishly) leave or (altruistically) remain in torrent
56
BitTorrent: requesting, sending file chunks
requesting chunks:
› at any given time, different peers have different subsets of file chunks
› periodically, Alice asks each peer for list of chunks that they have
› Alice requests missing chunks from peers, rarest first
sending chunks: tit-for-tat
› Alice sends chunks to those four peers currently sending her chunks at highest rate
› other peers are choked by Alice (do not receive chunks from her)
› re-evaluate top 4 every10 secs
› every 30 secs: randomly select another peer, starts sending chunks
› “optimistically unchoke” this peer › newly chosen peer may join top 4
57
BitTorrent: tit-for-tat
(1) Alice “optimistically unchokes” Bob
(2) Alice becomes one of Bob’s top-four providers; Bob reciprocates (3) Bob becomes one of Alice’s top-four providers
higher upload rate: find better trading partners, get file faster !
58