chapter€2 application€layer - nyu computer science · · 2005-02-16lecture€3:...
TRANSCRIPT
Internet and Intranet Protocols andApplications
Lecture 3:Application Layer 2:Email, DNS and P2P
February 1, 2005Arthur Goldberg
Computer Science DepartmentNew York University
Chapter 2Application Layer
Computer Networking:A Top Down
Approach Featuringthe Internet,3rd edition.
Jim Kurose, KeithRoss
AddisonWesley, July2004.
A note on the use of these ppt slides:We’re making these slides freely available to all (faculty, students, readers).They’re in PowerPoint form so you can add, modify, and delete slides(including this one) and slide content to suit your needs. They obviouslyrepresent a lot of work on our part. In return for use, we only ask thefollowing:q If you use these slides (e.g., in a class) in substantially unaltered form,that you mention their source (after all, we’d like people to use our book!)q If you post any slides in substantially unaltered form on a www site, thatyou note that they are adapted from (or perhaps identical to) our slides, andnote our copyright of this material.
Thanks and enjoy! JFK/KWR
All material copyright 19962004J.F Kurose and K.W. Ross, All Rights Reserved
3
Chapter 2: Application layer• 2.1 Principles of
network applications• 2.2 Web and HTTP• 2.3 FTP• 2.4 Electronic Mail
– SMTP, POP3, IMAP• 2.5 DNS
• 2.6 P2P file sharing• 2.7 Socket
programming withTCP
• 2.8 Socketprogramming withUDP
• 2.9 Building a Webserver
2: Application Layer 4
Electronic Mail
Three major components:user agentsmail serverssimple mail transferprotocol: SMTP
User Agenta.k.a. “mail reader”composing, editing, readingmail messagese.g., Eudora, Outlook, elm,Netscape Messengeroutgoing, incoming messagesstored on server
user mailbox
outgoingmessage queue
mailserver
useragent
useragent
useragent
mailserver
useragent
useragent
mailserver
useragent
SMTP
SMTP
SMTP
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 5
Electronic Mail: mail servers
Mail Serversmailbox contains incomingmessages for usermessage queue of outgoing(to be sent) mail messagesSMTP protocol between mailservers to send emailmessages
client: sending mailserver“server”: receiving mailserver
mailserver
useragent
useragent
useragent
mailserver
useragent
useragent
mailserver
useragent
SMTP
SMTP
SMTP
2: Application Layer 6
Electronic Mail: SMTP [RFC 2821]
uses TCP to reliably transfer email message from clientto server, port 25direct transfer: sending server to receiving serverthree phases of transfer
handshaking (greeting)transfer of messagesclosure
command/response interactioncommands: ASCII textresponse: status code and phrase
messages must be in 7bit ASCII
2: Application Layer 7
Scenario: Alice sends message to Bob1) Alice uses UA to compose
message and “to”[email protected]
2) Alice’s UA sends messageto her mail server; messageplaced in message queue
3) Client side of SMTP opensTCP connection with Bob’smail server
4) SMTP client sends Alice’smessage over the TCPconnection
5) Bob’s mail server places themessage in Bob’s mailbox
6) Bob invokes his user agentto read message
useragent
mailserver
mailserver user
agent
1
2 3 4 56
2: Application Layer 8
Sample SMTP interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <[email protected]> S: 250 [email protected]... Sender ok C: RCPT TO: <[email protected]> S: 250 [email protected] ... 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
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 9
Try SMTP interaction for yourself:
telnet servername 25see 220 reply from serverenter HELO, MAIL FROM, RCPT TO, DATA, QUITcommands
above lets you send email without using email client(reader)
2: Application Layer 10
SMTP: final words
SMTP uses persistentconnectionsSMTP requires message(header & body) to be in 7bit ASCIISMTP server usesCRLF.CRLF to determineend of message
Comparison with HTTP:HTTP: pullSMTP: push
both have ASCIIcommand/responseinteraction, status codes
HTTP: each objectencapsulated in its ownresponse msgSMTP: multiple objectssent in multipart msg
2: Application Layer 11
Mail message format
SMTP: protocol forexchanging email msgs
RFC 822: standard for textmessage format:header lines, e.g.,
To:From:Subject:
different from SMTPcommands!
bodythe “message”, ASCIIcharacters only
header
body
blankline
2: Application Layer 12
Message format: multimedia extensions
MIME: multimedia mail extension, RFC 2045, 2056additional lines in msg header declare MIME contenttype
From: [email protected]: [email protected]: Picture of yummy crepe.MIMEVersion: 1.0ContentTransferEncoding: base64ContentType: image/jpeg
base64 encoded data ....................................base64 encoded data
multimedia datatype, subtype,
parameter declaration
method usedto encode data
MIME version
encoded data
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 13
Mail access protocols
SMTP: delivery/storage to receiver’s serverMail access protocol: retrieval from server
POP: Post Office Protocol [RFC 1939]• authorization (agent <> server) and download
IMAP: Internet Mail Access Protocol [RFC 3501]• more features (more complex)• manipulation of stored messages on server
HTTP: Hotmail, Yahoo! Mail, etc.
useragent
sender’s mailserver
useragent
SMTP SMTP accessprotocol
receiver’s mailserver
2: Application Layer 14
POP3 protocol
authorization phaseclient commands:
user: declare username
pass: passwordserver responses
+OK
ERR
transaction phase, client:
list: list message numbers
retr: retrieve message bynumber
dele: deletequit
C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> S: . C: dele 1 C: retr 2 S: <message 1 contents> S: . C: dele 2 C: quit S: +OK POP3 server signing off
S: +OK POP3 server readyC: user bobS: +OKC: pass hungryS: +OK user successfully logged on
2: Application Layer 15
POP3 (more) and IMAPMore about POP3
Previous example uses“download and delete”mode.Bob cannot reread email if he changesclient“Downloadandkeep”:copies of messages ondifferent clientsPOP3 is statelessacross sessions
IMAPKeep all messages inone place: the serverAllows user toorganize messages infoldersIMAP keeps user stateacross sessions:
names of folders andmappings betweenmessage IDs and foldername
2: Application Layer 16
Chapter 2: Application layer
2.1 Principles ofnetwork applications2.2 Web and HTTP2.3 FTP2.4 Electronic Mail
SMTP, POP3, IMAP2.5 DNS
2.6 P2P file sharing2.7 Socket programmingwith TCP2.8 Socket programmingwith UDP2.9 Building a Webserver
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 17
DNS: Domain Name System
People: many identifiers:SSN, name, passport #
Internet hosts, routers:IP address (32 bit) used for addressingdatagrams“name”, e.g.,ww.yahoo.com used byhumans
Q: map between IPaddresses and name ?
Domain Name System:distributed databaseimplemented in hierarchy ofmany name serversapplicationlayer protocolhost, routers, name servers tocommunicate to resolve names(address/name translation)
note: core Internetfunction, implemented asapplicationlayer protocolcomplexity at network’s“edge”
2: Application Layer 18
DNSWhy not centralize DNS?
single point of failuretraffic volumedistant centralized databasemaintenance
doesn’t scale!
DNS servicesHostname to IP addresstranslationIP address to HostnametranslationHost aliasing
Canonical and alias namesMail server aliasingLoad distribution
Replicated Web servers:set of IP addresses forone canonical nameBut performs poorly –suppose Aol cached one IPaddress
2: Application Layer 19
Root DNS Servers
com DNS servers org DNS servers edu DNS servers
poly.eduDNS servers
umass.eduDNS serversyahoo.com
DNS serversamazon.comDNS servers
pbs.orgDNS servers
Distributed, Hierarchical Database
Client wants IP for www.amazon.com; 1st approx:Client queries a root server to find com DNSserverClient queries com DNS server to get amazon.comDNS serverClient queries amazon.com DNS server to get IPaddress for www.amazon.com
2: Application Layer 20
DNS: Root name serverscontacted by local name server that cannot resolve nameroot name server:
contacts authoritative name server if name mapping not knowngets mappingreturns mapping to local name server
84 root nameservers worldwide
See www.rootservers.orgb USCISI Marina del Rey, CAl ICANN Los Angeles, CA
e NASA Mt View, CAf Internet Software C. Palo Alto,CA (and 17 other locations)
i Autonomica, Stockholm (plus 3other locations)
k RIPE London (also Amsterdam,Frankfurt)
m WIDE Tokyo
a Verisign, Dulles, VAc Cogent, Herndon, VA (also Los Angeles)d U Maryland College Park, MDg US DoD Vienna, VAh ARL Aberdeen, MDj Verisign, ( 11 locations)
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 21
TLD and Authoritative Servers
Toplevel domain (TLD) servers: responsiblefor com, org, net, edu, etc, and all toplevelcountry domains uk, fr, ca, jp
Network solutions maintains servers for com TLDEducause for edu TLD
Authoritative DNS servers: organization’sDNS servers, providing authoritativehostname to IP mappings for organization’sservers (e.g., Web and mail)
Can be maintained by organization or serviceprovider
2: Application Layer 22
Local Name Server
Does not strictly belong to hierarchyEach ISP (residential ISP, company,university) has one
Also called “default name server”When a host makes a DNS query, query issent to its local DNS server
Acts as a proxy, forwards query into hierarchy
2: Application Layer 23
requesting hostcis.poly.edu
gaia.cs.umass.edu
root DNS server
local DNS serverdns.poly.edu
1
23
4
5
6
authoritative DNS serverdns.cs.umass.edu
78
TLD DNS server
Example
Host at cis.poly.eduwants IP address forgaia.cs.umass.edu
2. Find gaia.cs.umass.edu3. Find gaia.cs.umass.edu4. List of IPs for TLD
servers for edu5. Find gaia.cs.umass.edu6. IP for authoritative
server for umass.edu7. Find gaia.cs.umass.edu8. IP for gaia.cs.umass.edu9. IP for gaia.cs.umass.edu
2: Application Layer 24
requesting hostcis.poly.edu
gaia.cs.umass.edu
root DNS server
local DNS serverdns.poly.edu
1
2
45
6
authoritative DNS serverdns.cs.umass.edu
7
8
TLD DNSserver
3
Recursive queriesrecursive query:
Name server findsanswerputs burden of nameresolution oncontacted nameserverheavy load?
iterated query:contacted serverreplies with name ofserver to contact“I don’t know thisname, but ask thisserver”
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 25
DNS: caching and updating records
When a name server learns a mapping, it cachesthe mapping
A server discards cached entries after a timeout(typically 2 days)TLD servers typically cached in local name servers
• Thus root name servers queried infrequently
update/notify mechanisms under design by IETFRFC 2136www.ietf.org/html.charters/dnsindcharter.html
2: Application Layer 26
DNS recordsDNS: distributed db storing resource records (RR)
Type=NSname is domain (e.g.foo.com)
value is IP address ofauthoritative nameserver for this domain
RR format: (name, value, type, ttl)
Type=Aname is hostname
value is IP address
Type=CNAMEname is alias name for some“cannonical” (the real) name
www.ibm.com is really servereast.backup2.ibm.com
value is cannonical nameType=MX
value is name of mailserverassociated with name
2: Application Layer 27
DNS protocol, messagesDNS protocol : query and reply messages, both with
same message format
msg headeridentification: 16 bit #for query, reply to queryuses same #flags:
query or replyrecursion desiredrecursion availablereply is authoritative
2: Application Layer 28
DNS protocol, messages
Name, type fields for a query
RRs in responseto query
records forauthoritative servers
additional “helpful”info that may be used
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 29
Inserting records into DNS
Example: just created startup “Network Utopia”Register name networkuptopia.com at a registrar(e.g., Network Solutions)
Need to provide registrar with names and IP addresses ofyour authoritative name server (primary and secondary)Registrar inserts two RRs into the com TLD server:
(networkutopia.com, dns1.networkutopia.com, NS)(dns1.networkutopia.com, 212.212.212.1, A)
Put in authoritative server Type A record forwww.networkuptopia.com and Type MX record fornetworkutopia.comHow do people get the IP address of your Web site?
2: Application Layer 30
Chapter 2: Application layer
2.1 Principles ofnetwork applications
app architecturesapp requirements
2.2 Web and HTTP2.4 Electronic Mail
SMTP, POP3, IMAP2.5 DNS
2.6 P2P file sharing2.7 Socket programmingwith TCP2.8 Socket programmingwith UDP2.9 Building a Webserver
2: Application Layer 31
P2P file sharing
ExampleAlice runs P2P clientapplication on hernotebook computerIntermittentlyconnects to Internet;gets new IP addressfor each connectionAsks for “Hey Jude”Application displaysother peers that havecopy of Hey Jude.
Alice chooses one ofthe peers, Bob.File is copied fromBob’s PC to Alice’snotebook: HTTPWhile Alice downloads,other users uploadingfrom Alice.Alice’s peer is both aWeb client and atransient Web server.
All peers are servers =highly scalable!
2: Application Layer 32
P2P: centralized directory
original “Napster” design1) when peer connects, it
informs central server:IP addresscontent
2) Alice queries for “HeyJude”
3) Alice requests file fromBob
centralizeddirectory server
peers
Alice
Bob
1
1
1
12
3
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 33
P2P: problems with centralized directory
Single point of failurePerformancebottleneckCopyrightinfringement
file transfer isdecentralized, butlocating content ishighly decentralized
2: Application Layer 34
Query flooding: Gnutella
fully distributedno central server
public domain protocolmany Gnutella clientsimplementing protocol
overlay network: graphedge between peer Xand Y if there’s a TCPconnectionall active peers andedges is overlay netEdge is not a physicallinkGiven peer willtypically be connectedwith < 10 overlayneighbors
2: Application Layer 35
Gnutella: protocol
Query
QueryHit
Query
Query
QueryHit
Query
Query
QueryHit
File transfer:HTTP Query message
sent over existing TCPconnections peers forward
Query message QueryHit
sent overreversepath
Scalability:limited scopeflooding
2: Application Layer 36
Gnutella: Peer joining
1. Joining peer X must find some other peer inGnutella network: use list of candidate peers
2. X sequentially attempts to make TCP with peerson list until connection setup with Y
3. X sends Ping message to Y; Y forwards Pingmessage.
4. All peers receiving Ping message respond withPong message
5. X receives many Pong messages. It can thensetup additional TCP connections
Peer leaving: see homework problem!
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 37
Questions about Gnutella, 1
What are ‘littleendian’ and ‘bigendian’?Why does the protocol have to specifythem?Unique identifiers: How are uniqueDescriptor IDs and Servent Identifiersgenerated?The spec says (p 3, para 2) “if a serventbecomes out of synch with its input stream,it should drop the connection”. How wouldit know?
2: Application Layer 38
Questions about Gnutella, 2
In the section ‘Descriptor Routing’ on page 5, thespec says “Pong descriptors may only be sent alongthe same path that carried the incoming Pingdescriptor” and “Push descriptors may only be sentalong the same path that carried the incomingQueryHit descriptor.” How would this beimplemented?In the section ‘Firewalled Servents’ the spec says“A servent can request a file push by routing aPush request back to the servent that sent theQueryHit descriptor describing the target file.”How is this possible? Isn’t the latter serventbehind a firewall?
2: Application Layer 39
Exploiting heterogeneity: KaZaA
Each peer is either agroup leader or assignedto a group leader.
TCP connection betweenpeer and its group leader.TCP connections betweensome pairs of groupleaders.
Group leader tracks thecontent in all itschildren.
ordinary peer
groupleader peer
neighoring relationshipsin overlay network
2: Application Layer 40
KaZaA: Querying
Each file has a hash and a descriptorClient sends keyword query to its groupleaderGroup leader responds with matches:
For each match: metadata, hash, IP addressIf group leader forwards query to othergroup leaders, they respond with matchesClient then selects files for downloading
HTTP requests using hash as identifier sent topeers holding desired file
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 41
Kazaa tricks
Limitations on simultaneous uploadsRequest queuingIncentive prioritiesParallel downloading
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
Internet and Intranet Protocols andApplications
Lecture 3:Application Layer 2:Email, DNS and P2P
February 1, 2005Arthur Goldberg
Computer Science DepartmentNew York University
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2
Chapter 2Application Layer
Computer Networking:A Top Down
Approach Featuringthe Internet,3rd edition.
Jim Kurose, KeithRoss
AddisonWesley, July2004.
A note on the use of these ppt slides:We’re making these slides freely available to all (faculty, students, readers).They’re in PowerPoint form so you can add, modify, and delete slides(including this one) and slide content to suit your needs. They obviouslyrepresent a lot of work on our part. In return for use, we only ask thefollowing:q If you use these slides (e.g., in a class) in substantially unaltered form,that you mention their source (after all, we’d like people to use our book!)q If you post any slides in substantially unaltered form on a www site, thatyou note that they are adapted from (or perhaps identical to) our slides, andnote our copyright of this material.
Thanks and enjoy! JFK/KWR
All material copyright 19962004J.F Kurose and K.W. Ross, All Rights Reserved
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
3
Chapter 2: Application layer• 2.1 Principles of
network applications• 2.2 Web and HTTP• 2.3 FTP• 2.4 Electronic Mail
– SMTP, POP3, IMAP• 2.5 DNS
• 2.6 P2P file sharing• 2.7 Socket
programming withTCP
• 2.8 Socketprogramming withUDP
• 2.9 Building a Webserver
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 4
Electronic Mail
Three major components:user agentsmail serverssimple mail transferprotocol: SMTP
User Agenta.k.a. “mail reader”composing, editing, readingmail messagese.g., Eudora, Outlook, elm,Netscape Messengeroutgoing, incoming messagesstored on server
user mailbox
outgoingmessage queue
mailserver
useragent
useragent
useragent
mailserver
useragent
useragent
mailserver
useragent
SMTP
SMTP
SMTP
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 5
Electronic Mail: mail servers
Mail Serversmailbox contains incomingmessages for usermessage queue of outgoing(to be sent) mail messagesSMTP protocol between mailservers to send emailmessages
client: sending mailserver“server”: receiving mailserver
mailserver
useragent
useragent
useragent
mailserver
useragent
useragent
mailserver
useragent
SMTP
SMTP
SMTP
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 6
Electronic Mail: SMTP [RFC 2821]
uses TCP to reliably transfer email message from clientto server, port 25direct transfer: sending server to receiving serverthree phases of transfer
handshaking (greeting)transfer of messagesclosure
command/response interactioncommands: ASCII textresponse: status code and phrase
messages must be in 7bit ASCII
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 7
Scenario: Alice sends message to Bob1) Alice uses UA to compose
message and “to”[email protected]
2) Alice’s UA sends messageto her mail server; messageplaced in message queue
3) Client side of SMTP opensTCP connection with Bob’smail server
4) SMTP client sends Alice’smessage over the TCPconnection
5) Bob’s mail server places themessage in Bob’s mailbox
6) Bob invokes his user agentto read message
useragent
mailserver
mailserver user
agent
1
2 3 4 56
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 8
Sample SMTP interaction S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <[email protected]> S: 250 [email protected]... Sender ok C: RCPT TO: <[email protected]> S: 250 [email protected] ... 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
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 9
Try SMTP interaction for yourself:
telnet servername 25see 220 reply from serverenter HELO, MAIL FROM, RCPT TO, DATA, QUITcommands
above lets you send email without using email client(reader)
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 10
SMTP: final words
SMTP uses persistentconnectionsSMTP requires message(header & body) to be in 7bit ASCIISMTP server usesCRLF.CRLF to determineend of message
Comparison with HTTP:HTTP: pullSMTP: push
both have ASCIIcommand/responseinteraction, status codes
HTTP: each objectencapsulated in its ownresponse msgSMTP: multiple objectssent in multipart msg
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 11
Mail message format
SMTP: protocol forexchanging email msgs
RFC 822: standard for textmessage format:header lines, e.g.,
To:From:Subject:
different from SMTPcommands!
bodythe “message”, ASCIIcharacters only
header
body
blankline
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 12
Message format: multimedia extensions
MIME: multimedia mail extension, RFC 2045, 2056additional lines in msg header declare MIME contenttype
From: [email protected]: [email protected]: Picture of yummy crepe.MIMEVersion: 1.0ContentTransferEncoding: base64ContentType: image/jpeg
base64 encoded data ....................................base64 encoded data
multimedia datatype, subtype,
parameter declaration
method usedto encode data
MIME version
encoded data
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 13
Mail access protocols
SMTP: delivery/storage to receiver’s serverMail access protocol: retrieval from server
POP: Post Office Protocol [RFC 1939]• authorization (agent <> server) and download
IMAP: Internet Mail Access Protocol [RFC 3501]• more features (more complex)• manipulation of stored messages on server
HTTP: Hotmail, Yahoo! Mail, etc.
useragent
sender’s mailserver
useragent
SMTP SMTP accessprotocol
receiver’s mailserver
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 14
POP3 protocol
authorization phaseclient commands:
user: declare username
pass: passwordserver responses
+OK
ERR
transaction phase, client:
list: list message numbers
retr: retrieve message bynumber
dele: deletequit
C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> S: . C: dele 1 C: retr 2 S: <message 1 contents> S: . C: dele 2 C: quit S: +OK POP3 server signing off
S: +OK POP3 server readyC: user bobS: +OKC: pass hungryS: +OK user successfully logged on
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 15
POP3 (more) and IMAPMore about POP3
Previous example uses“download and delete”mode.Bob cannot reread email if he changesclient“Downloadandkeep”:copies of messages ondifferent clientsPOP3 is statelessacross sessions
IMAPKeep all messages inone place: the serverAllows user toorganize messages infoldersIMAP keeps user stateacross sessions:
names of folders andmappings betweenmessage IDs and foldername
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 16
Chapter 2: Application layer
2.1 Principles ofnetwork applications2.2 Web and HTTP2.3 FTP2.4 Electronic Mail
SMTP, POP3, IMAP2.5 DNS
2.6 P2P file sharing2.7 Socket programmingwith TCP2.8 Socket programmingwith UDP2.9 Building a Webserver
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 17
DNS: Domain Name System
People: many identifiers:SSN, name, passport #
Internet hosts, routers:IP address (32 bit) used for addressingdatagrams“name”, e.g.,ww.yahoo.com used byhumans
Q: map between IPaddresses and name ?
Domain Name System:distributed databaseimplemented in hierarchy ofmany name serversapplicationlayer protocolhost, routers, name servers tocommunicate to resolve names(address/name translation)
note: core Internetfunction, implemented asapplicationlayer protocolcomplexity at network’s“edge”
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 18
DNSWhy not centralize DNS?
single point of failuretraffic volumedistant centralized databasemaintenance
doesn’t scale!
DNS servicesHostname to IP addresstranslationIP address to HostnametranslationHost aliasing
Canonical and alias namesMail server aliasingLoad distribution
Replicated Web servers:set of IP addresses forone canonical nameBut performs poorly –suppose Aol cached one IPaddress
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 19
Root DNS Servers
com DNS servers org DNS servers edu DNS servers
poly.eduDNS servers
umass.eduDNS serversyahoo.com
DNS serversamazon.comDNS servers
pbs.orgDNS servers
Distributed, Hierarchical Database
Client wants IP for www.amazon.com; 1st approx:Client queries a root server to find com DNSserverClient queries com DNS server to get amazon.comDNS serverClient queries amazon.com DNS server to get IPaddress for www.amazon.com
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 20
DNS: Root name serverscontacted by local name server that cannot resolve nameroot name server:
contacts authoritative name server if name mapping not knowngets mappingreturns mapping to local name server
84 root nameservers worldwide
See www.rootservers.orgb USCISI Marina del Rey, CAl ICANN Los Angeles, CA
e NASA Mt View, CAf Internet Software C. Palo Alto,CA (and 17 other locations)
i Autonomica, Stockholm (plus 3other locations)
k RIPE London (also Amsterdam,Frankfurt)
m WIDE Tokyo
a Verisign, Dulles, VAc Cogent, Herndon, VA (also Los Angeles)d U Maryland College Park, MDg US DoD Vienna, VAh ARL Aberdeen, MDj Verisign, ( 11 locations)
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 21
TLD and Authoritative Servers
Toplevel domain (TLD) servers: responsiblefor com, org, net, edu, etc, and all toplevelcountry domains uk, fr, ca, jp
Network solutions maintains servers for com TLDEducause for edu TLD
Authoritative DNS servers: organization’sDNS servers, providing authoritativehostname to IP mappings for organization’sservers (e.g., Web and mail)
Can be maintained by organization or serviceprovider
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 22
Local Name Server
Does not strictly belong to hierarchyEach ISP (residential ISP, company,university) has one
Also called “default name server”When a host makes a DNS query, query issent to its local DNS server
Acts as a proxy, forwards query into hierarchy
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 23
requesting hostcis.poly.edu
gaia.cs.umass.edu
root DNS server
local DNS serverdns.poly.edu
1
23
4
5
6
authoritative DNS serverdns.cs.umass.edu
78
TLD DNS server
Example
Host at cis.poly.eduwants IP address forgaia.cs.umass.edu
2. Find gaia.cs.umass.edu3. Find gaia.cs.umass.edu4. List of IPs for TLD
servers for edu5. Find gaia.cs.umass.edu6. IP for authoritative
server for umass.edu7. Find gaia.cs.umass.edu8. IP for gaia.cs.umass.edu9. IP for gaia.cs.umass.edu
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 24
requesting hostcis.poly.edu
gaia.cs.umass.edu
root DNS server
local DNS serverdns.poly.edu
1
2
45
6
authoritative DNS serverdns.cs.umass.edu
7
8
TLD DNSserver
3
Recursive queriesrecursive query:
Name server findsanswerputs burden of nameresolution oncontacted nameserverheavy load?
iterated query:contacted serverreplies with name ofserver to contact“I don’t know thisname, but ask thisserver”
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 25
DNS: caching and updating records
When a name server learns a mapping, it cachesthe mapping
A server discards cached entries after a timeout(typically 2 days)TLD servers typically cached in local name servers
• Thus root name servers queried infrequently
update/notify mechanisms under design by IETFRFC 2136www.ietf.org/html.charters/dnsindcharter.html
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 26
DNS recordsDNS: distributed db storing resource records (RR)
Type=NSname is domain (e.g.foo.com)
value is IP address ofauthoritative nameserver for this domain
RR format: (name, value, type, ttl)
Type=Aname is hostname
value is IP address
Type=CNAMEname is alias name for some“cannonical” (the real) name
www.ibm.com is really servereast.backup2.ibm.com
value is cannonical nameType=MX
value is name of mailserverassociated with name
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 27
DNS protocol, messagesDNS protocol : query and reply messages, both with
same message format
msg headeridentification: 16 bit #for query, reply to queryuses same #flags:
query or replyrecursion desiredrecursion availablereply is authoritative
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 28
DNS protocol, messages
Name, type fields for a query
RRs in responseto query
records forauthoritative servers
additional “helpful”info that may be used
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 29
Inserting records into DNS
Example: just created startup “Network Utopia”Register name networkuptopia.com at a registrar(e.g., Network Solutions)
Need to provide registrar with names and IP addresses ofyour authoritative name server (primary and secondary)Registrar inserts two RRs into the com TLD server:
(networkutopia.com, dns1.networkutopia.com, NS)(dns1.networkutopia.com, 212.212.212.1, A)
Put in authoritative server Type A record forwww.networkuptopia.com and Type MX record fornetworkutopia.comHow do people get the IP address of your Web site?
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 30
Chapter 2: Application layer
2.1 Principles ofnetwork applications
app architecturesapp requirements
2.2 Web and HTTP2.4 Electronic Mail
SMTP, POP3, IMAP2.5 DNS
2.6 P2P file sharing2.7 Socket programmingwith TCP2.8 Socket programmingwith UDP2.9 Building a Webserver
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 31
P2P file sharing
ExampleAlice runs P2P clientapplication on hernotebook computerIntermittentlyconnects to Internet;gets new IP addressfor each connectionAsks for “Hey Jude”Application displaysother peers that havecopy of Hey Jude.
Alice chooses one ofthe peers, Bob.File is copied fromBob’s PC to Alice’snotebook: HTTPWhile Alice downloads,other users uploadingfrom Alice.Alice’s peer is both aWeb client and atransient Web server.
All peers are servers =highly scalable!
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 32
P2P: centralized directory
original “Napster” design1) when peer connects, it
informs central server:IP addresscontent
2) Alice queries for “HeyJude”
3) Alice requests file fromBob
centralizeddirectory server
peers
Alice
Bob
1
1
1
12
3
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 33
P2P: problems with centralized directory
Single point of failurePerformancebottleneckCopyrightinfringement
file transfer isdecentralized, butlocating content ishighly decentralized
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 34
Query flooding: Gnutella
fully distributedno central server
public domain protocolmany Gnutella clientsimplementing protocol
overlay network: graphedge between peer Xand Y if there’s a TCPconnectionall active peers andedges is overlay netEdge is not a physicallinkGiven peer willtypically be connectedwith < 10 overlayneighbors
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 35
Gnutella: protocol
Query
QueryHit
Query
Query
QueryHit
Query
Query
QueryHit
File transfer:HTTP Query message
sent over existing TCPconnections peers forward
Query message QueryHit
sent overreversepath
Scalability:limited scopeflooding
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 36
Gnutella: Peer joining
1. Joining peer X must find some other peer inGnutella network: use list of candidate peers
2. X sequentially attempts to make TCP with peerson list until connection setup with Y
3. X sends Ping message to Y; Y forwards Pingmessage.
4. All peers receiving Ping message respond withPong message
5. X receives many Pong messages. It can thensetup additional TCP connections
Peer leaving: see homework problem!
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 37
Questions about Gnutella, 1
What are ‘littleendian’ and ‘bigendian’?Why does the protocol have to specifythem?Unique identifiers: How are uniqueDescriptor IDs and Servent Identifiersgenerated?The spec says (p 3, para 2) “if a serventbecomes out of synch with its input stream,it should drop the connection”. How wouldit know?
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 38
Questions about Gnutella, 2
In the section ‘Descriptor Routing’ on page 5, thespec says “Pong descriptors may only be sent alongthe same path that carried the incoming Pingdescriptor” and “Push descriptors may only be sentalong the same path that carried the incomingQueryHit descriptor.” How would this beimplemented?In the section ‘Firewalled Servents’ the spec says“A servent can request a file push by routing aPush request back to the servent that sent theQueryHit descriptor describing the target file.”How is this possible? Isn’t the latter serventbehind a firewall?
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 39
Exploiting heterogeneity: KaZaA
Each peer is either agroup leader or assignedto a group leader.
TCP connection betweenpeer and its group leader.TCP connections betweensome pairs of groupleaders.
Group leader tracks thecontent in all itschildren.
ordinary peer
groupleader peer
neighoring relationshipsin overlay network
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 40
KaZaA: Querying
Each file has a hash and a descriptorClient sends keyword query to its groupleaderGroup leader responds with matches:
For each match: metadata, hash, IP addressIf group leader forwards query to othergroup leaders, they respond with matchesClient then selects files for downloading
HTTP requests using hash as identifier sent topeers holding desired file
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com
2: Application Layer 41
Kazaa tricks
Limitations on simultaneous uploadsRequest queuingIncentive prioritiesParallel downloading
Click t
o buy NOW!
PDFXCHANGE
www.docutrack.com Clic
k to buy N
OW!PDFXCHANGE
www.docutrack.com