Docstoc

03

Document Sample
03 Powered By Docstoc
					Chapter 2: Application Layer
 2.4 Electronic Mail
    SMTP, POP3, IMAP

 2.5 DNS
 2.6 P2P file sharing
 2.7 Socket programming with TCP
 2.8 Socket programming with UDP




                                    1
Electronic Mail                                                outgoing
                                                          message queue
                                                            user mailbox
                                           user
Three major components:                   agent
 user agents                     mail
                                                                 user
                                 server
 mail servers                                                  agent
 simple mail transfer                     SMTP         mail
  protocol: SMTP                                       server       user
                                SMTP                               agent
User Agent
 composing, editing, reading              SMTP
                                                                 user
  mail messages                   mail
                                                                agent
                                 server
 Examples: Eudora, Outlook,
  Mozilla Thunderbird                       user
 outgoing, incoming messages              agent
  stored on server                 user
                                  agent

                                                   2: Application Layer    2
Electronic Mail: Mail Servers
                                           user
Mail Servers                              agent
 mailbox contains incoming       mail
                                                                    user
  messages for user              server
                                                                   agent
 message queue of outgoing
                                           SMTP
  (to be sent) mail messages                               mail
                                                          server          user
 SMTP protocol between mail
  servers to send email         SMTP                                     agent

  messages                                 SMTP
    client: sending mail         mail                              user
                                                                   agent
      server                     server
    “server”: receiving mail
                                            user
      server                               agent
                                   user
                                  agent

                                                  2: Application Layer      3
Electronic Mail: SMTP [RFC 2821]

 uses TCP to reliably transfer email message from client
  server to the receiving server using port 25
 direct transfer: sending server to receiving server
 three phases of transfer
    handshaking (greeting)
    transfer of messages
    closure
 command/response interaction
    commands: ASCII text
    response: status code and phrase

 messages must be in 7-bit ASCII



                                                 2: Application Layer   4
Scenario: Alice sends message to Bob
1) Alice uses User Agent to          4) SMTP client sends Alice’s
   compose message and “to”             message over the TCP
   bob@someschool.edu                   connection
2) Alice’s User Agent sends          5) Bob’s mail server places the
   message to her mail server;          message in Bob’s mailbox
   message 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



       1                                  mail
                   mail
                                         server             user
       user       server
              2                                            agent
      agent         3                              6
                                 4         5


                                                       2: Application Layer   5
Sample SMTP Interaction
S:   220 hamburger.edu
C:   HELO crepes.fr
S:   250 Hello crepes.fr, pleased to meet you
C:   MAIL FROM: <alice@crepes.fr>
S:   250 alice@crepes.fr... Sender ok
C:   RCPT TO: <bob@hamburger.edu>
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


                                       2: Application Layer   6
SMTP: Summary
 SMTP uses persistent          Comparison with HTTP:
  connections
                                 HTTP: pull
 SMTP requires message
  (header & body) to be in 7-    SMTP: push
  bit ASCII                      both have ASCII
 SMTP server uses                command/response
  CRLF.CRLF to determine          interaction, status codes
  end of message
                                 HTTP: each object
                                  encapsulated in its own
                                  response msg
                                 SMTP: multiple objects
                                  sent in multipart msg


                                               2: Application Layer   7
Mail Message Format

SMTP: protocol for
  exchanging email msgs       header
                                                         blank
RFC 822: standard for text
                                                          line
  message format:
 header lines, e.g.,
       To:
   
                              body
      From:
      Subject:
   different from SMTP
      commands!
 body
      the “message”, ASCII
       characters only


                                  2: Application Layer     8
   Message Format: Multimedia Extensions
    MIME: multimedia mail extension, RFC 2045, 2056
    additional lines in msg header declare MIME content
     type

                              From: alice@crepes.fr
      MIME version            To: bob@hamburger.edu
                              Subject: Picture of yummy crepe.
        method used           MIME-Version: 1.0
      to encode data          Content-Transfer-Encoding: base64
                              Content-Type: image/jpeg
     multimedia data
      type, subtype,          base64 encoded data .....
parameter declaration         .........................
                              ......base64 encoded data
       encoded data


                                                   2: Application Layer   9
Mail Access Protocols
                 SMTP         SMTP               access     user
          user
         agent                                  protocol   agent


                  sender’s mail   receiver’s mail
                     server           server

 SMTP: delivery/storage to receiver’s server
 Mail access protocol: retrieval from server
      POP: Post Office Protocol [RFC 1939]
        • authorization (agent <-->server) and download
      IMAP: Internet Mail Access Protocol [RFC 1730]
        • more features (more complex)
        • manipulation of stored msgs on server
      HTTP: Hotmail , Yahoo! Mail, etc.

                                                     2: Application Layer   10
POP3 Protocol                  S:   +OK POP3 server ready
                               C:   user bob
authorization phase            S:   +OK
                               C:   pass hungry
 client commands:             S:   +OK user successfully logged     on
    user: declare username
                               C:   list
    pass: password            S:   1 498
 server responses             S:   2 912
                               S:   .
    +OK
                               C:   retr 1
    -ERR                      S:   <message 1 contents>
transaction phase, client:     S:   .
                               C:   dele 1
 list: list message numbers   C:   retr 2
 retr: retrieve message by    S:   <message 1 contents>
  number                       S:   .
                               C:   dele 2
 dele: delete
                               C:   quit
 quit                         S:   +OK POP3 server signing off
                                             2: Application Layer   11
POP3 (more) and IMAP
More about POP3           IMAP
 Previous example uses    Keep all messages in
  “download and delete”     one place: the server
  mode.                    Allows user to
 Bob cannot re-read e-     organize messages in
  mail if he changes        folders
  client                   IMAP keeps user state
 “Download-and-keep”:      across sessions:
  copies of messages on        names of folders and
  different clients             mappings between
                                message IDs and folder
 POP3 is stateless
                                name
  across sessions

                                         2: Application Layer   12
Chapter 2: Application Layer
 2.4 Electronic Mail
    SMTP, POP3, IMAP

 2.5 DNS
 2.6 P2P file sharing
 2.7 Socket programming with TCP
 2.8 Socket programming with UDP




                                    13
DNS: Domain Name System

People: many identifiers:       Domain Name System:
      SSN, name, passport #       distributed database
Internet hosts, routers:            implemented in hierarchy of
                                    many name servers
      IP address (32 bit) -
       used for addressing
                                   application-layer protocol
                                    host, routers, name servers to
       datagrams
                                    communicate to resolve names
      “name”, e.g.,                (address/name translation)
       ww.yahoo.com - used by
                                      note: core Internet
       humans
                                       function, implemented as
Q: map between IP                      application-layer protocol
  addresses and name ?                complexity at network’s
                                       “edge”


                                                  2: Application Layer   14
 DNS
DNS services                 Why not centralize DNS?
 Hostname to IP              single point of failure
  address translation         traffic volume
 Host aliasing               distant centralized
      Canonical and alias     database
       names                  maintenance
 Mail server aliasing
 Load distribution
                             doesn’t scale!
    Replicated Web
     servers: set of IP
     addresses for one
     canonical name

                                              2: Application Layer   15
Distributed, Hierarchical Database
                          Root DNS Servers



   com DNS servers        org DNS servers     edu DNS servers


                             pbs.org         poly.edu   umass.edu
yahoo.com   amazon.com
                             DNS servers     DNS serversDNS servers
DNS servers DNS servers

Client wants IP for www.amazon.com; 1st approx:
 Client queries a 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
                                                  2: Application Layer   16
 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
                               a Verisign, Dulles, VA
                               c Cogent, Herndon, VA (also Los Angeles)
                               d U Maryland College Park, MD       k RIPE London (also Amsterdam,
                               g US DoD Vienna, VA                 Frankfurt)
                               h ARL Aberdeen, MD                   i Autonomica, Stockholm (plus 3
                               j Verisign, ( 11 locations)                          other locations)
                                                                                       m WIDE Tokyo
e NASA Mt View, CA
f Internet Software C. Palo Alto,
CA (and 17 other locations)

                                                                                                       13 root name
                                                                                                       servers worldwide
    b USC-ISI Marina del Rey, CA
    l ICANN Los Angeles, CA




                                                                                                       2: Application Layer   17
TLD and Authoritative Servers
 Top-level domain (TLD) servers: responsible
  for com, org, net, edu, etc, and all top-level
  country domains uk, fr, ca, jp.
   Network Solutions maintains servers for com TLD
   Educause for edu TLD
 Authoritative DNS servers: organization’s
  DNS servers, providing authoritative
  hostname to IP mappings for organization’s
  servers (e.g., Web and mail).
     Can be maintained by organization or service
      provider

                                          2: Application Layer   18
Local Name Server
 Does not strictly belong to hierarchy
 Each ISP (residential ISP, company,
  university) has one.
     Also called “default name server”
 When a host makes a DNS query, query is
  sent to its local DNS server
     Acts as a proxy, forwards query into hierarchy.




                                          2: Application Layer   19
Example                                  root DNS server



                                     2
 Host at cis.poly.edu                      3
                                                     TLD DNS server
  wants IP address for                          4
  gaia.cs.umass.edu
                                                5

                         local DNS server
                          dns.poly.edu
                                                7        6
                                1    8

                                                authoritative DNS server
                                                  dns.cs.umass.edu
                         requesting host
                          cis.poly.edu

                                                    gaia.cs.umass.edu


                                                    2: Application Layer   20
Recursive Queries                       root DNS server


recursive query:
                                    2
 puts burden of name                                    3
  resolution on                          7       6
  contacted name                                                 TLD DNS server
  server
 heavy load?
                        local DNS server
iterated query:          dns.poly.edu                5       4

 contacted server             1    8
  replies with name of
  server to contact                          authoritative DNS server
 “I don’t know this
                                               dns.cs.umass.edu
                       requesting host
  name, but ask this    cis.poly.edu
  server”
                                               gaia.cs.umass.edu

                                                         2: Application Layer   21
DNS: Caching and Updating Records
   once (any) name server learns mapping, it             caches
    mapping
     cache entries timeout (disappear) after some
      time
     TLD servers typically cached in local name
      servers
          • Thus root name servers not often visited
   update/notify mechanisms under design by IETF
      RFC 2136
        http://www.ietf.org/html.charters/dnsind-charter.html




                                                      2: Application Layer   22
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
                                   www.ibm.com is really
 Type=NS
                                     servereast.backup2.ibm.com
    name is domain (e.g.
                                    value is canonical name
     foo.com)
    value is hostname of
                               Type=MX
     authoritative name
                                  value is name of mailserver
     server for this domain
                                   associated with name

                                                 2: Application Layer   23
DNS Protocol, Messages
DNS protocol : 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




                                        2: Application Layer   24
DNS Protocol, Messages

    Name, type fields
         for a query

      RRs in response
              to query

         records for
authoritative servers

   additional “helpful”
info that may be used




                          2: Application Layer   25
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 of
       your 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 for
  www.networkuptopia.com and Type MX record for
  networkutopia.com
 How do people get the IP address of your Web site?


                                                 2: Application Layer   26
Chapter 2: Application Layer
 2.4 Electronic Mail
    SMTP, POP3, IMAP

 2.5 DNS
 2.6 P2P file sharing
 2.7 Socket programming with TCP
 2.8 Socket programming with UDP




                                    27
P2P File Sharing
                           Alice chooses one of
Example                     the peers, Bob.
 Alice runs P2P client    File is copied from
  application on her        Bob’s PC to Alice’s
  notebook computer         notebook: HTTP
 Intermittently           While Alice downloads,
  connects to Internet;     other users uploading
  gets new IP address       to Alice.
  for each connection      Alice’s peer is both a
 Asks for “Hey Jude”       Web client and a
                            transient Web server.
 Application displays
  other peers that have   All peers are servers =
  copy of Hey Jude.         highly scalable!
                                       2: Application Layer   28
P2P: Problems with Centralized Directory

   Single point of failure   file transfer is
   Performance               decentralized, but
    bottleneck                locating content is
   Copyright
                              highly centralized
    infringement




                                       2: Application Layer   29
File Distribution: Server-Client vs P2P
  Question : How much time to distribute file
   from one server to N peers?
                                                us: server upload
                                                bandwidth
               Server
                                                ui: peer i upload
                         u1   d1   u2           bandwidth
                    us                  d2
                                                di: peer i download
File, size F                                    bandwidth
               dN
                          Network (with
               uN         abundant bandwidth)




                                                  2: Application Layer   30
File distribution time: server-client
                                    Server
 server sequentially           F                u1 d1 u2
  sends N copies:                         us                d2

      NF/us time                    dN        Network (with
                                               abundant bandwidth)
 client i takes F/di                uN
  time to download

   Time to distribute F
       to N clients using = dcs = max { NF/us, F/min(di) }
                                                  i
 client/server approach
                              increases linearly in N
                              (for large N) 2: Application Layer     31
File distribution time: P2P
                                      Server
 server must send one
                                  F            u1 d1 u2
  copy: F/us time                     us              d2

 client i takes F/di time
                                         Network (with
  to download
                                   dN
                                         abundant bandwidth)
 NF bits must be
                                   uN

  downloaded (aggregate)
    fastest possible upload rate: us + Sui




       dP2P = max { F/us, F/min(di) , NF/(us + Sui) }
                                      i
                                                 2: Application Layer   32
Server-client vs. P2P: example
Client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us

                                   3.5
                                             P2P
       Minimum Distribution Time



                                    3
                                             Client-Server
                                   2.5

                                    2

                                   1.5

                                    1

                                   0.5

                                    0
                                         0    5      10      15       20   25   30      35

                                                                  N
                                                                                2: Application Layer   33
P2P: Centralized Directory
                                                                           Bob
original “Napster” design        centralized
1) when peer connects, it     directory server
                                                     1
   informs central server:                                               peers

      IP address                                    1

      content
                                                     1             3
2) Alice queries for “Hey
                                           2
   Jude”                                         1


3) Alice requests file from
   Bob

                                                          Alice




                                                         2: Application Layer    34
File distribution: BitTorrent
 P2P file distribution

     tracker: tracks peers          torrent: group of
     participating in torrent       peers exchanging
                                    chunks of a file


    obtain list
    of peers

                          trading
                          chunks




                  peer

                                        2: Application Layer   35
BitTorrent (1)
 file divided into 256KB   chunks.
 peer joining torrent:
    has no chunks, but will accumulate them over time
    registers with tracker to get list of peers,
     connects to subset of peers (“neighbors”)
 while downloading, peer uploads chunks to other
  peers.
 peers may come and go
 once peer has entire file, it may (selfishly) leave or
  (altruistically) remain
                                            2: Application Layer   36
BitTorrent (2)             Sending Chunks: tit-for-tat
                            Alice sends chunks to four
Pulling Chunks
                             neighbors currently
 at any given time,
                             sending her chunks at the
  different peers have       highest rate
  different subsets of
  file chunks                  re-evaluate top 4 every
                                10 secs
 periodically, a peer
                            every 30 secs: randomly
  (Alice) asks each
  neighbor for list of       select another peer,
  chunks that they have.     starts sending chunks
                               newly chosen peer may
 Alice sends requests
  for her missing chunks        join top 4
                               “optimistically unchoke”
     rarest first

                                        2: Application Layer   37
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




                                 With higher upload rate,
                                 can find better trading
                                 partners & get file faster!
                                                2: Application Layer   38
Chapter 2: Application Layer
 2.4 Electronic Mail
    SMTP, POP3, IMAP

 2.5 DNS
 2.6 P2P file sharing
 2.7 Socket programming with TCP
 2.8 Socket programming with UDP




                                    39
Socket Programming
Goal: learn how to build client/server applications that
  communicate using sockets

Socket API                        socket
 introduced in BSD4.1 UNIX,
                                       a host-local,
  1981                             application-created,
 explicitly created, used,       OS-controlled interface
  released by apps                  (a “door”) into which
 client/server paradigm           application process can
 two types of transport                both send and
  service via socket API:        receive messages to/from
                                     another application
    unreliable datagram
                                           process
    reliable, byte stream-
      oriented

                                           2: Application Layer   40
Socket-Programming Using TCP
 Socket: a door between application process and end-
   end-transport protocol (UCP or TCP)
 TCP service: reliable transfer of bytes from one
   process to another

                                                    controlled by
controlled by                          process      application
  application   process
                                                    developer
   developer     socket                 socket
                TCP with               TCP with     controlled by
controlled by
                                       buffers,     operating
   operating    buffers,    internet                system
      system    variables              variables

                host or                host or
                server                 server

                                             2: Application Layer   41
Socket Programming with TCP
Client must contact server       When contacted by client,
 server process must first       server TCP creates new
   be running                     socket for server process to
 server must have created        communicate with client
   socket (door) that               allows server to talk with
   welcomes client’s contact         multiple clients
                                    source port numbers
Client contacts server by:
                                     used to distinguish
 creating client-local TCP
                                     clients
   socket
 specifying IP address, port    application viewpoint
   number of server process
                                  TCP provides reliable, in-order
 When client creates
                                    transfer of bytes (“pipe”)
   socket: client TCP
                                    between client and server
   establishes connection to
   server TCP
                                                2: Application Layer   42
Stream Terminology
 A stream is a sequence of
  characters that flow into
  or out of a process.
 An input stream is
  attached to some input
  source for the process,
  e.g., keyboard or socket.
 An output stream is
  attached to an output
  source, e.g., monitor , file
  or socket.




                                 2: Application Layer   43
Socket Programming with TCP
Example client-server
                                                keyboard            monitor



  application:
1) client reads line from




                                                      inFromUser
                                              input
   standard input (inFromUser                stream

   stream) , sends to server via   Client
                                   Process
   socket (outToServer             process
   stream)
2) server reads line from socket
3) server converts line to
   uppercase, sends back to




                                                                       inFromServer
                                                      outToServer
   client
                                         output                                        input
                                         stream                                       stream

4) client reads, prints modified
   line from socket                              client TCP
                                                   clientSocket
   (inFromServer stream)                           socket                                 TCP
                                                                                         socket

                                               to network           from network


                                                 2: Application Layer                             44
Client/Server Socket Interaction: TCP
Server (running on hostid)                    Client
     create socket,
     port=x, for
     incoming request:
     welcomeSocket =
        ServerSocket()

                             TCP             create socket,
     wait for incoming
     connection request connection   setup   connect to hostid, port=x
     connectionSocket =                      clientSocket =
     welcomeSocket.accept()                         Socket()

                                               send request using
     read request from                         clientSocket
     connectionSocket

      write reply to
      connectionSocket                         read reply from
                                               clientSocket
      close
      connectionSocket                          close
                                                clientSocket
                                                               2: Application Layer   45
    Example: Java Client (TCP)
                     import java.io.*;
                     import java.net.*;
                     class TCPClient {

                       public static void main(String argv[]) throws Exception
                       {
                         String sentence;
                         String modifiedSentence;
            Create
      input stream        BufferedReader inFromUser =
                           new BufferedReader(new InputStreamReader(System.in));
           Create
    client socket,        Socket clientSocket = new Socket("hostname", 6789);
 connect to server
            Create        DataOutputStream outToServer =
     output stream         new DataOutputStream(clientSocket.getOutputStream());
attached to socket
                                                               2: Application Layer   46
Chapter 2: Application Layer
 2.4 Electronic Mail
    SMTP, POP3, IMAP

 2.5 DNS
 2.6 P2P file sharing
 2.7 Socket programming with TCP
 2.8 Socket programming with UDP




                                    47
Socket Programming with UDP

UDP: no “connection” between
  client and server
 no handshaking
 sender explicitly attaches   application viewpoint
  IP address and port of
  destination to each packet   UDP provides unreliable transfer
                               of groups of bytes (“datagrams”)
 server must extract IP
                                   between client and server
  address, port of sender
  from received packet
UDP: transmitted data may be
  received out of order, or
  lost



                                              2: Application Layer   48
Client/Server Socket Interaction: UDP
Server (running on hostid)   Client

     create socket,          create socket,
     port=x, for             clientSocket =
     incoming request:       DatagramSocket()
     serverSocket =
     DatagramSocket()
                             Create, address (hostid, port=x,
                             send datagram request
                             using clientSocket
      read request from
      serverSocket

      write reply to
      serverSocket
      specifying client        read reply from
      host address,            clientSocket
      port number              close
                               clientSocket



                                          2: Application Layer   49
Example: Java Client (UDP)
                              keyboard           monitor




                                    inFromUser
                            input
                           stream


                Client
                Process
                                                                                Input: receives
                process
                                                                                packet (recall
    Output: sends                                                               thatTCP received
    packet (recall                                                              “byte stream”)




                                                    receivePacket
                                    sendPacket
    that TCP sent          UDP
                          packet
                                                                     UDP
                                                                    packet
    “byte stream”)
                                   client UDP
                                     clientSocket
                                     socket                             UDP
                                                                       socket

                              to network         from network




                                                                                     2: Application Layer   50

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:3
posted:11/24/2011
language:English
pages:50