PowerPoint Presentation
Application Layer
All material copyright 1996-2012
J.F Kurose and K.W. Ross, All Rights Reserved
George Parisis
School of Engineering and Informatics
University of Sussex
Application Layer
2-*
Outline
Principles of network applications
Electronic mail
SMTP, POP3, IMAP
Web and HTTP
DNS
socket programming with UDP and TCP
Application Layer
*
Application Layer
2-*
DNS: domain name system
people: many identifiers:
SSN, name, passport #
Internet hosts, routers:
IP address (32 bit) – used for addressing datagrams
“name”, e.g., www.yahoo.com – used by humans
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)
note: core Internet function, implemented as application-layer protocol
complexity at network’s “edge”
Application Layer
*
Application Layer
2-*
DNS: services, structure
why not centralize DNS?
single point of failure
traffic volume
distant centralized database
maintenance
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
A: doesn’t scale!
Application Layer
*
Application Layer
2-*
DNS: a distributed, hierarchical database
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
…
…
Root DNS Servers
com DNS servers
org DNS servers
edu DNS servers
poly.edu
DNS servers
umass.edu
DNS servers
yahoo.com
DNS servers
amazon.com
DNS servers
pbs.org
DNS servers
Application Layer
*
Application Layer
2-*
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
13 logical root name “servers” worldwide
each “server” replicated many times
a. Verisign, Los Angeles CA
(5 other sites)
b. USC-ISI Marina del Rey, CA
l. ICANN Los Angeles, CA
(41 other sites)
e. NASA Mt View, CA
f. Internet Software C.
Palo Alto, CA (and 48 other sites)
i. Netnod, Stockholm (37 other sites)
k. RIPE London (17 other sites)
m. WIDE Tokyo
(5 other sites)
c. Cogent, Herndon, VA (5 other sites)
d. U Maryland College Park, MD
h. ARL Aberdeen, MD
j. Verisign, Dulles VA (69 other sites )
g. US DoD Columbus, OH (5 other sites)
Application Layer
*
Application Layer
2-*
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 Layer
*
Application Layer
2-*
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 Layer
*
Application Layer
2-*
requesting host
cis.poly.edu
gaia.cs.umass.edu
root DNS server
1
2
3
4
5
6
authoritative DNS server
dns.cs.umass.edu
7
8
TLD DNS server
DNS name
resolution example
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”
local DNS server
dns.poly.edu
Application Layer
*
Application Layer
2-*
4
5
6
3
recursive query:
puts burden of name resolution on contacted name server
heavy load at upper levels of hierarchy
requesting host
cis.poly.edu
gaia.cs.umass.edu
root DNS server
1
2
7
authoritative DNS server
dns.cs.umass.edu
8
DNS name
resolution example
TLD DNS
server
local DNS server
dns.poly.edu
Application Layer
*
Application Layer
2-*
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
Application Layer
*
Application Layer
2-*
DNS records
DNS: distributed db storing resource records (RR)
type=NS
name is domain (e.g., foo.com)
value is hostname of authoritative name server for this domain
RR format: (name, value, type, ttl)
type=A
name is hostname
value is IP address
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
Application Layer
*
Application Layer
2-*
DNS protocol, messages
query and reply messages, both with same message format
msg header
identification: 16 bit # for query, reply to query uses same #
flags:
query or reply
recursion desired
recursion available
reply is authoritative
identification
flags
# questions
questions (variable # of questions)
# additional RRs
# authority RRs
# answer RRs
answers (variable # of RRs)
authority (variable # of RRs)
additional info (variable # of RRs)
2 bytes
2 bytes
Application Layer
*
Application Layer
2-*
name, type fields
for a query
RRs in response
to query
records for
authoritative servers
additional “helpful”
info that may be used
DNS protocol, messages
identification
flags
# questions
questions (variable # of questions)
# additional RRs
# authority RRs
# answer RRs
answers (variable # of RRs)
authority (variable # of RRs)
additional info (variable # of RRs)
2 bytes
2 bytes
Application Layer
*
Application Layer
2-*
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 Layer
*
Content Delivery Networks
Overlay networks across the world
Efficiently manage popular content on behalf of content providers
DNS Redirection
DNS Redirection
A nice photo in Facebook: https://www.facebook.com/photo.php?fbid=10153425280267954&set=t.532692953&type=3&size=2048%2C1358
You can’t see it because you are not FB friends with me
Right click Copy image url Paste
https://scontent-lhr8-1.xx.fbcdn.net/v/t31.0-8/11845080_10153425280267954_3099288129582999879_o.jpg?_nc_cat=102&_nc_ohc=2tkg4E_rFcMAX_51MqT&_nc_ht=scontent-lhr8-1.xx&oh=360bcfbf52a92eb0f8f95805c9778ce5&oe=5ED4F4AA
This is not Facebook!!
And this is not Google: https://lh4.googleusercontent.com/-6kihAcO5zeA/UtVI0OiAiGI/AAAAAAAAorg/vDUY686AKsU/w1900-h1068-no/DSCF0127.JPG
Side note: there is no access control on the CDN’s side
DNS Redirection
Facebook, Google and other content providers change the URLs that point to static content to point to a CDN provider
Such URLs are resolved by DNS servers owned and ran by CDN providers
There happens all the magic!
DNS Resolution
Resolve a7.g.akamai.net
Resolver contacts root server
Root server sends a referral to a name server responsible for .net
Resolver queries .net name server
Returns a referral for .akamai.net
This is the top-level Akamai server
Resolver queries a top-level Akamai server
Returns a referral for .g.akamai.net
Low-level Akamai server (TTL approx 1 hour)
Resolver queries a low-level Akamai server
Returns IP addresses of servers available to satisfy the request
Short TTL (several seconds to 1 minute)
Application Layer
2-*
Outline
Principles of network applications
Electronic mail
SMTP, POP3, IMAP
Web and HTTP
DNS
socket programming with UDP and TCP
Application Layer
*
2: Application Layer
*
Socket programming
Socket API
introduced in BSD4.1 UNIX, 1981
explicitly created, used, released by apps
client/server paradigm
two types of transport service via socket API:
unreliable datagram
reliable, byte stream-oriented
Goal: learn how to build client/server application that communicate using sockets
socket
a host-local,
application-created,
OS-controlled interface (a “door”) into which an
application process can both send and
receive messages to/from another application process
2: Application Layer
2: Application Layer
*
Socket-programming using TCP
TCP service: reliable transfer of bytes from one process to another
controlled by
application
developer
controlled by
operating
system
host or
server
controlled by
application
developer
controlled by
operating
system
host or
server
internet
TCP with
buffers,
variables
socket
process
TCP with
buffers,
variables
socket
process
application viewpoint
TCP provides reliable, in-order
transfer of bytes (“pipe”)
between client and server
2: Application Layer
2: Application Layer
*
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 client-local TCP socket
specifying IP address, port number of server process
When client creates socket: client TCP establishes connection to server TCP
When contacted by client, server TCP creates new socket for server process to communicate with client
allows server to talk with multiple clients
source port numbers used to distinguish clients
2: Application Layer
2: Application Layer
*
Client/server socket interaction: TCP
Server (running on hostid)
Client
wait for incoming
connection request
connectionSocket =
welcomeSocket.accept()
create socket,
port=x, for
incoming request:
welcomeSocket =
ServerSocket()
create socket,
connect to hostid, port=x
clientSocket =
Socket()
read reply from
clientSocket
close
clientSocket
close
connectionSocket
send request using
clientSocket
read request from
connectionSocket
write reply to
connectionSocket
TCP
connection setup
2: Application Layer
2: Application Layer
*
Socket programming with TCP
Example client-server application:
1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream)
2) server reads line from socket
3) server converts line to uppercase, sends back to client
4) client reads, prints modified line from socket (inFromServer stream)
2: Application Layer
2: Application Layer
*
Example: Java client (TCP)
import java.io.*;
import java.net.*;
class TCPClient {
public static void main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket(“hostname”, 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
Create
input stream
Create
client socket,
connect to server
Create
output stream
attached to socket
2: Application Layer
2: Application Layer
*
Example: Java client (TCP), cont.
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + ‘\n’);
modifiedSentence = inFromServer.readLine();
System.out.println(“FROM SERVER: ” + modifiedSentence);
clientSocket.close();
}
}
Create
input stream
attached to socket
Send line
to server
Read line
from server
2: Application Layer
2: Application Layer
*
Example: Java server (TCP)
import java.io.*;
import java.net.*;
class TCPServer {
public static void main(String argv[]) throws Exception
{
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(6789);
while(true) {
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));
Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket
2: Application Layer
2: Application Layer
*
Example: Java server (TCP), cont
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + ‘\n’;
outToClient.writeBytes(capitalizedSentence);
}
}
}
Read in line
from socket
Create output
stream, attached
to socket
Write out line
to socket
End of while loop,
loop back and wait for
another client connection
2: Application Layer
2: Application Layer
*
Socket programming with UDP
UDP: no “connection” between client and server
no handshaking
server must extract IP address, port of sender from received packet
UDP: transmitted data may be received out of order, or lost
application viewpoint
UDP provides unreliable transfer
of groups of bytes (“datagrams”)
between client and server
2: Application Layer
2: Application Layer
*
Client/server socket interaction: UDP
Server (running on hostid)
create socket,
port= x.
serverSocket =
DatagramSocket()
close
clientSocket
read datagram from
clientSocket
create socket,
clientSocket =
DatagramSocket()
Client
Create datagram with server IP and
port=x; send datagram via
clientSocket
read datagram from
serverSocket
write reply to
serverSocket
specifying
client address,
port number
2: Application Layer
2: Application Layer
*
Example: Java client (UDP)
import java.io.*;
import java.net.*;
class UDPClient {
public static void main(String args[]) throws Exception
{
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName(“hostname”);
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
Create
input stream
Create
client socket
Translate
hostname to IP
address using DNS
2: Application Layer
2: Application Layer
*
Example: Java client (UDP), cont.
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
String modifiedSentence =
new String(receivePacket.getData());
System.out.println(“FROM SERVER:” + modifiedSentence);
clientSocket.close();
}
}
Create datagram with data-to-send,
length, IP addr, port
Send datagram
to server
Read datagram
from server
2: Application Layer
2: Application Layer
*
Example: Java server (UDP)
import java.io.*;
import java.net.*;
class UDPServer {
public static void main(String args[]) throws Exception
{
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true)
{
DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
Create
datagram socket
at port 9876
Create space for
received datagram
Receive
datagram
2: Application Layer
2: Application Layer
*
Example: Java server (UDP), cont
String sentence = new String(receivePacket.getData());
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress,
port);
serverSocket.send(sendPacket);
}
}
}
Get IP addr
port #, of
sender
Write out
datagram
to socket
End of while loop,
loop back and wait for
another datagram
Create datagram
to send to client
2: Application Layer
Application Layer
2-*
Summary
application architectures
client-server
P2P
application service requirements:
reliability, bandwidth, delay
Internet transport service model
connection-oriented, reliable: TCP
unreliable, datagrams: UDP
our study of network applications now complete!
specific protocols:
HTTP
SMTP, POP, IMAP
DNS
socket programming: TCP, UDP sockets
Application Layer