SlideShare uma empresa Scribd logo
1 de 98
Chapter 2
Application Layer


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 obviously         Computer Networking:
represent a lot of work on our part. In return for use, we only ask the           A Top Down Approach,
following:
 If you use these slides (e.g., in a class) in substantially unaltered form,     5th edition.
that you mention their source (after all, we’d like people to use our book!)      Jim Kurose, Keith Ross
                                                                                  Addison-Wesley, April
 If you post any slides in substantially unaltered form on a www site, that
you note that they are adapted from (or perhaps identical to) our slides, and
note our copyright of this material.                                              2009.
Thanks and enjoy! JFK/KWR

All material copyright 1996-2009
J.F Kurose and K.W. Ross, All Rights Reserved
                                                                                    2: Application Layer   1
Chapter 2: Application layer
Ì 2.1 Principles of       Ì 2.6 P2P applications
  network applications    Ì 2.7 Socket programming
Ì 2.2 Web and HTTP          with TCP
Ì 2.3 FTP                 Ì 2.8 Socket programming
Ì 2.4 Electronic Mail       with UDP
      SMTP, POP3, IMAP
Ì 2.5 DNS




                                       2: Application Layer   2
Chapter 2: Application Layer
Our goals:                Ì learn about protocols
Ì conceptual,               by examining popular
  implementation            application-level
  aspects of network        protocols
  application protocols         HTTP
    transport-layer            FTP
     service models             SMTP / POP3 / IMAP
    client-server
                                DNS
     paradigm             Ì programming network
    peer-to-peer           applications
                              socket API
     paradigm
                               (tutorial)

                                          2: Application Layer   3
Some network apps
Ì e-mail                   Ì voice over IP
Ì web                      Ì real-time video
Ì instant messaging          conferencing
Ì remote login             Ì grid computing
Ì P2P file sharing         Ì
Ì multi-user network       Ì
  games                    Ì
Ì streaming stored video
  clips



                                        2: Application Layer   4
Creating a network app                        application
                                              transport
                                               network
                                               data link

write programs that                            physical


     run on (different) end
      systems
     communicate over network
     e.g., web server software
      communicates with browser
      software                      application
                                    transport
No need to write software            network
                                     data link

  for network-core devices
                                                            application
                                     physical
                                                            transport
                                                             network
     Network-core devices do                                data link
                                                             physical

      not run user applications
     applications on end systems
       allows for rapid app
      development, propagation
                                         2: Application Layer         5
Application architectures
Ì Client-server
Ì Peer-to-peer (P2P)
Ì Hybrid of client-server and P2P




                                    2: Application Layer   6
Client-server architecture
                 server:
                      always-on host
                      permanent IP address
                      server farms for
                       scaling
                 clients:
client/server
                       communicate with server
                       may be intermittently
                        connected
                       may have dynamic IP
                        addresses
                       do not communicate
                        directly with each other
                                2: Application Layer   7
Pure P2P architecture
Ì no always-on server
Ì arbitrary end systems
  directly communicate peer-peer
Ì peers are intermittently
  connected and change IP
  addresses



Highly scalable but
  difficult to manage


                                   2: Application Layer   8
Hybrid of client-server and P2P
Skype
    voice-over-IP P2P application
    centralized server: finding address of remote
     party:
    client-client connection: direct (not through
     server)
Instant messaging
    chatting between two users is P2P
    centralized service: client presence
     detection/location
      • user registers its IP address with central
        server when it comes online
      • user contacts central server to find IP
        addresses of buddies
                                         2: Application Layer   9
Processes communicating
Process: program running   Client process: process
  within a host.              that initiates
Ì within same host, two       communication
  processes communicate    Server process: process
  using inter-process         that waits to be
  communication (defined      contacted
  by OS).                  Ì Note: applications with
Ì processes in different     P2P architectures have
  hosts communicate by       client processes &
  exchanging messages        server processes



                                      2: Application Layer   10
Sockets
                                      host or                                   host or
Ì process sends/receives              server                                    server
  messages to/from its
  socket                                             controlled by
                                                     app developer
Ì socket analogous to door            process                                   process

      sending process shoves         socket                                    socket
       message out door              TCP with                                 TCP with
                                     buffers,                 Internet        buffers,
      sending process relies on     variables                                variables
       transport infrastructure
       on other side of door which
                                                 controlled
       brings message to socket                  by OS
       at receiving process

Ì API: (1) choice of transport protocol; (2) ability to fix
  a few parameters (more on this in tutorial)
                                                              2: Application Layer   11
Addressing processes
Ì to receive messages,
  process must have
  identifier
Ì host device has unique
  32-bit IP address
Ì Q: does IP address of
  host suffice for
  identifying the process?




                             2: Application Layer   12
Addressing processes
Ì to receive messages,      Ì identifier includes both
  process must have           IP address and port
  identifier                  numbers associated with
Ì host device has unique      process on host.
  32-bit IP address         Ì Example port numbers:
Ì Q: does IP address of            HTTP server: 80
  host on which process            Mail server: 25
  runs suffice for          Ì to send HTTP message
  identifying the               to gaia.cs.umass.edu web
  process?                      server:
    A: No, many                   IP address: 128.119.245.12
     processes can be              Port number: 80
     running on same host   Ì more shortly…
                                            2: Application Layer   13
App-layer protocol defines
Ì Types of messages              Public-domain protocols:
  exchanged,                     Ì defined in RFCs
      e.g., request, response   Ì allows for
Ì Message syntax:                  interoperability
   what fields in messages &
                                 Ì e.g., HTTP, SMTP
    how fields are delineated
Ì Message semantics
                                 Proprietary protocols:
   meaning of information in
                                 Ì e.g., Skype
    fields
Ì Rules for when and how
  processes send &
  respond to messages
                                            2: Application Layer   14
What transport service does an app need?
Data loss                       Throughput
Ì some apps (e.g., audio) can   Ì some apps (e.g.,
  tolerate some loss              multimedia) require
Ì other apps (e.g., file          minimum amount of
  transfer, telnet) require       throughput to be
  100% reliable data              “effective”
  transfer                      Ì other apps (“elastic apps”)
Timing                            make use of whatever
Ì some apps (e.g.,                throughput they get
  Internet telephony,
  interactive games)            Security
  require low delay to be       Ì Encryption, data integrity,
  “effective”                     …

                                           2: Application Layer   15
Transport service requirements of common apps

         Application      Data loss       Throughput           Time Sensitive

          file transfer   no loss         elastic              no
                 e-mail   no loss         elastic              no
     Web documents        no loss         elastic              no
real-time audio/video     loss-tolerant   audio: 5kbps-1Mbps   yes, 100’s msec
                                          video:10kbps-5Mbps
  stored audio/video      loss-tolerant   same as above        yes, few secs
   interactive games      loss-tolerant   few kbps up          yes, 100’s msec
  instant messaging       no loss         elastic              yes and no




                                                         2: Application Layer   16
Internet transport protocols services

TCP service:                        UDP service:
Ì   connection-oriented: setup      Ì unreliable data transfer
    required between client and       between sending and
    server processes                  receiving process
Ì   reliable transport between      Ì does not provide:
    sending and receiving process     connection setup,
Ì   flow control: sender won’t        reliability, flow control,
    overwhelm receiver                congestion control, timing,
                                      throughput guarantee, or
Ì   congestion control: throttle
                                      security
    sender when network
    overloaded
Ì   does not provide: timing,       Q: why bother? Why is
    minimum throughput                there a UDP?
    guarantees, security
                                                  2: Application Layer   17
Internet apps: application, transport protocols

                            Application             Underlying
           Application      layer protocol          transport protocol

                   e-mail   SMTP [RFC 2821]         TCP
remote terminal access      Telnet [RFC 854]        TCP
                    Web     HTTP [RFC 2616]         TCP
            file transfer   FTP [RFC 959]           TCP
  streaming multimedia      HTTP (eg Youtube),      TCP or UDP
                            RTP [RFC 1889]
     Internet telephony     SIP, RTP, proprietary
                            (e.g., Skype)           typically UDP




                                                      2: Application Layer   18
Web and HTTP
First some jargon
Ì Web page consists of objects
Ì Object can be HTML file, JPEG image, Java
  applet, audio file,…
Ì Web page consists of base HTML-file which
  includes several referenced objects
Ì Each object is addressable by a URL
Ì Example URL:
    www.someschool.edu/someDept/pic.gif

          host name             path name

                                      2: Application Layer   19
HTTP overview

HTTP: hypertext
 transfer protocol                         HT
                                              TP
                                                 re q
Ì Web’s application layer      PC running HT          ues
                                            TP            t
  protocol                      Explorer       re s
                                                    pon
                                                        se
Ì client/server model
    client: browser that
                                                         st
      requests, receives,                         re que
                                               TP             se Server
                                              T          p on
      “displays” Web objects                H        res          running
                                                 T P            Apache Web
    server: Web server                        HT
                                                                  server
      sends objects in
      response to requests
                                Mac running
                                 Navigator



                                                 2: Application Layer   20
HTTP overview (continued)
Uses TCP:                        HTTP is “stateless”
Ì client initiates TCP           Ì server maintains no
  connection (creates socket)       information about
  to server, port 80                past client requests
Ì server accepts TCP
  connection from client                                  aside
                                Protocols that maintain
Ì HTTP messages (application-      “state” are complex!
  layer protocol messages)      Ì past history (state) must
  exchanged between browser        be maintained
  (HTTP client) and Web
                                Ì if server/client crashes,
  server (HTTP server)
                                   their views of “state” may
Ì TCP connection closed
                                   be inconsistent, must be
                                   reconciled

                                             2: Application Layer   21
HTTP connections
Nonpersistent HTTP        Persistent HTTP
Ì At most one object is   Ì Multiple objects can
  sent over a TCP           be sent over single
  connection.               TCP connection
                            between client and
                            server.




                                       2: Application Layer   22
Nonpersistent HTTP
                                                (contains text,
Suppose user enters URL                        references to 10
  www.someSchool.edu/someDepartment/home.index   jpeg images)

    1a. HTTP client initiates TCP
        connection to HTTP server
        (process) at
                                        1b. HTTP server at host
                                           www.someSchool.edu waiting
        www.someSchool.edu on port 80
                                           for TCP connection at port 80.
                                            “accepts” connection,
                                           notifying client
    2. HTTP client sends HTTP
        request message (containing
        URL) into TCP connection        3. HTTP server receives request
        socket. Message indicates         message, forms response
        that client wants object          message containing requested
        someDepartment/home.index         object, and sends message
                                          into its socket

 time
                                                       2: Application Layer   23
Nonpersistent HTTP (cont.)

                                           4. HTTP server closes TCP
                                             connection.
       5. HTTP client receives response
          message containing html file,
          displays html. Parsing html
          file, finds 10 referenced jpeg
          objects
time   6. Steps 1-5 repeated for each
          of 10 jpeg objects




                                                       2: Application Layer   24
Non-Persistent HTTP: Response time
Definition of RTT: time for
  a small packet to travel
  from client to server
  and back.                   initiate TCP
                              connection
Response time:                        RTT
Ì one RTT to initiate TCP         request
                                  file
  connection                                                         time to
                                      RTT
                                                                     transmit
Ì one RTT for HTTP
                                                                     file
  request and first few             file
                                    received
  bytes of HTTP response
  to return                                  time                time
Ì file transmission time
total = 2RTT+transmit
  time                                              2: Application Layer   25
Persistent HTTP

Nonpersistent HTTP issues:       Persistent HTTP
Ì requires 2 RTTs per object     Ì server leaves connection
Ì OS overhead for each TCP          open after sending
  connection                        response
Ì browsers often open parallel   Ì subsequent HTTP messages
  TCP connections to fetch           between same
  referenced objects                client/server sent over
                                    open connection
                                 Ì client sends requests as
                                    soon as it encounters a
                                    referenced object
                                 Ì as little as one RTT for all
                                    the referenced objects


                                                 2: Application Layer   26
HTTP request message

  Ì two types of HTTP messages:          request, response
  Ì HTTP request message:
      ASCII (human-readable format)


  request line
 (GET, POST,         GET /somedir/page.html HTTP/1.1
HEAD commands)       Host: www.someschool.edu
                     User-agent: Mozilla/4.0
             header Connection: close
               lines Accept-language:fr

 Carriage return,
                    (extra carriage return, line feed)
     line feed
  indicates end
    of message
                                                     2: Application Layer   27
HTTP request message: general format




                            2: Application Layer   28
Uploading form input
Post method:
Ì Web page often
  includes form input     URL method:
Ì Input is uploaded to    Ì Uses GET method
  server in entity body   Ì Input is uploaded in
                            URL field of request
                            line:

          www.somesite.com/animalsearch?monkeys&banana




                                       2: Application Layer   29
Method types
HTTP/1.0                        HTTP/1.1
Ì GET                           Ì GET, POST, HEAD
Ì POST                          Ì PUT
Ì HEAD                                uploads file in entity
                                       body to path specified
     asks server to leave
                                       in URL field
      requested object out of
      response                  Ì DELETE
                                    deletes file specified in
                                     the URL field




                                                 2: Application Layer   30
HTTP response message
  status line
   (protocol
 status code         HTTP/1.1 200 OK
status phrase)       Connection close
                     Date: Thu, 06 Aug 1998 12:00:15 GMT
           header    Server: Apache/1.3.0 (Unix)
             lines   Last-Modified: Mon, 22 Jun 1998 …...
                     Content-Length: 6821
                     Content-Type: text/html

 data, e.g.,         data data data data data ...
 requested
 HTML file




                                          2: Application Layer   31
HTTP response status codes
In first line in server->client response message.
A few sample codes:
200 OK
      request succeeded, requested object later in this message
301 Moved Permanently
      requested object moved, new location specified later in
       this message (Location:)
400 Bad Request
      request message not understood by server
404 Not Found
      requested document not found on this server
505 HTTP Version Not Supported
                                                  2: Application Layer   32
HTTP Server
How to scale to large number of users?

-Fork
--create a copy of itself which handles each
  client request
-Threads
--create a thread to handle each request
HTTP Server
Forked server operation
--A single listen socket for client requests
--A connected socket to each request
--A forked process for each connected
  socket
---child process closes listening socket
  (Why?)
--Server goes back to listening
--Forked process exits after connection is
  processed.
HTTP Server
Threaded server
--Listening is similar
--connection socket created
--A thread is given the connection socket
---listening socket is left alone by thread
--Thread closes connected socket after
  request
--Server keeps listening for new requests
HTTP Client
How to reduce fetch time?

-Pipelining
--send multiple requests without waiting for
  responses –persistent connections
--Pipelined requests are expected to be served
  “in-order” to client
--Use headers to separate responses
-Multiple requests sent via
--Threads or Forked processes
Trying out HTTP (client side) for yourself

1. Telnet to your favorite Web server:
  telnet cis.poly.edu 80   Opens TCP connection to port 80
                           (default HTTP server port) at cis.poly.edu.
                           Anything typed in sent
                           to port 80 at cis.poly.edu


2. Type in a GET HTTP request:
       GET /~ross/ HTTP/1.1        By typing this in (hit carriage
       Host: cis.poly.edu          return twice), you send
                                   this minimal (but complete)
                                   GET request to HTTP server

3. Look at response message sent by HTTP server!

                                                   2: Application Layer   37
User-server state: cookies
                             Example:
Many major Web sites
  use cookies                Ì Susan always access
Four components:               Internet always from PC
  1) cookie header line of   Ì visits specific e-
     HTTP response message     commerce site for first
  2) cookie header line in     time
     HTTP request message
  3) cookie file kept on     Ì when initial HTTP
     user’s host, managed by   requests arrives at site,
     user’s browser            site creates:
  4) back-end database at
     Web site                    unique ID
                                 entry in backend
                                  database for ID
                                          2: Application Layer   38
Cookies: keeping “state” (cont.)
        client                                 server
      ebay 8734
                    usual http request msg
                                              Amazon server
      cookie file    usual http response       creates ID
                    Set-cookie: 1678          1678 for user create
      ebay 8734                                                  entry
      amazon 1678
                    usual http request msg
                      cookie: 1678              cookie-     access
                                                specific
one week later:     usual http response msg      action                  backend
                                                                         database
                                                            access
      ebay 8734     usual http request msg
      amazon 1678      cookie: 1678              cookie-
                                                spectific
                    usual http response msg       action

                                                        2: Application Layer   39
Cookies (continued)
                                                  aside
What cookies can bring:       Cookies and privacy:
Ì authorization               Ì cookies permit sites to
Ì shopping carts                learn a lot about you
                              Ì you may supply name
Ì recommendations
                                and e-mail to sites
Ì user session state
  (Web e-mail)
How to keep “state”:
Ì protocol endpoints: maintain state
  at sender/receiver over multiple
  transactions
Ì cookies: http messages carry state

                                        2: Application Layer   40
Web caches (proxy server)
Goal: satisfy client request without involving origin server

Ì user sets browser:                                                        origin
                                                                            server
  Web accesses via
  cache                                 HT               Proxy
                                            TP                            st
Ì browser sends all                            req server          re que
                                      HT            ues         TP           e
                                client TP               t      T         ons
  HTTP requests to                          res              H       e sp
                                                pon
                                                     se          TPr
                                                             HT
  cache                                         ues
                                                     t
                                              eq        se
      object in cache: cache            T Pr        on
                                      HT            p
       returns object                        P re s
                                         H TT
      else cache requests
       object from origin        client
                                                                            origin
       server, then returns                                                 server
       object to client
                                                           2: Application Layer   41
More about Web caching
Ì cache acts as both      Why Web caching?
  client and server       Ì reduce response time
Ì typically cache is        for client request
  installed by ISP        Ì reduce traffic on an
  (university, company,     institution’s access
  residential ISP)          link.
                          Ì Internet dense with
                            caches: enables “poor”
                            content providers to
                            effectively deliver
                            content (but so does
                            P2P file sharing)
                                       2: Application Layer   42
Caching example
                                                                        origin
Assumptions                                                           servers
Ì average object size = 100,000
                                                public
  bits                                       Internet
Ì avg. request rate from
  institution’s browsers to
  origin servers = 15/sec
                                                    1.5 Mbps
Ì delay from institutional router                   access link
  to any origin server and back
                                  institutional
  to router = 2 sec                 network
                                                           10 Mbps LAN
Consequences
Ì utilization on LAN = 15%
Ì utilization on access link = 100%
                                                             institutional
Ì total delay  = Internet delay +                               cache
   access delay + LAN delay
 = 2 sec + minutes + milliseconds
                                                         2: Application Layer   43
Caching example (cont)
                                                                      origin
possible solution                                                   servers
Ì increase bandwidth of access
                                                public
   link to, say, 10 Mbps                       Internet
consequence
Ì utilization on LAN = 15%
Ì utilization on access link = 15%                    10 Mbps
Ì Total delay   = Internet delay +                    access link
   access delay + LAN delay          institutional
 = 2 sec + msecs + msecs               network
                                                          10 Mbps LAN
Ì often a costly upgrade



                                                            institutional
                                                               cache


                                                      2: Application Layer   44
Caching example (cont)
                                                                  origin
possible solution: install                                      servers
  cache                                     public
Ì suppose hit rate is 0.4                  Internet
consequence
Ì 40% requests will be
  satisfied almost immediately
                                                  1.5 Mbps
Ì 60% requests satisfied by
                                                  access link
  origin server
Ì utilization of access link     institutional
  reduced to 60%, resulting in     network
                                                      10 Mbps LAN
  negligible delays (say 10
  msec)
Ì total avg delay = Internet
  delay + access delay + LAN                           institutional
  delay = .6*(2.01) secs + .
                                                          cache
  4*milliseconds < 1.4 secs

                                                  2: Application Layer   45
Conditional GET

Ì Goal: don’t send object if     cache                           server
  cache has up-to-date cached            HTTP request msg
  version                                If-modified-since:
                                                                    object
Ì cache: specify date of                       <date>
                                                                      not
  cached copy in HTTP request                                       modified
                                           HTTP response
   If-modified-since:                       HTTP/1.0
     <date>                              304 Not Modified
Ì server: response contains no
  object if cached copy is up-
                                         HTTP request msg
  to-date:                               If-modified-since:
   HTTP/1.0 304 Not                            <date>                object
     Modified                                                        modified
                                           HTTP response
                                          HTTP/1.0 200 OK
                                              <data>
                                                       2: Application Layer   46
FTP: the file transfer protocol

                  FTP                   file transfer
                          FTP                            FTP
                  user   client                         server
               interface
      user
     at host                                                     remote file
                           local file                            system
                           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

                                                        2: Application Layer   47
FTP: separate control, data connections
                                             TCP control connection
Ì FTP client contacts FTP server                    port 21
    at port 21, TCP is transport
    protocol                                TCP data connection
Ì   client authorized over control  FTP           port 20        FTP
    connection                     client                       server
Ì   client browses remote          Ì server opens another TCP
    directory by sending commands
                                      data connection to transfer
    over control connection.
                                      another file.
Ì   when server receives file      Ì control connection: “out of
    transfer command, server
                                      band”
    opens 2nd TCP connection (for
                                   Ì FTP server maintains “state”:
    file) to client
                                      current directory, earlier
Ì   after transferring one file,
                                      authentication
    server closes data connection.
                                                     2: Application Layer   48
FTP commands, responses

Sample commands:                Sample return codes
Ì sent as ASCII text over       Ì status code and phrase (as
  control channel                   in HTTP)
Ì USER username                 Ì   331 Username OK,
Ì PASS password                     password required
Ì LIST return list of file in   Ì   125 data connection
  current directory                 already open;
                                    transfer starting
Ì RETR filename retrieves
                                Ì   425 Can’t open data
  (gets) file                       connection
Ì STOR filename stores          Ì   452 Error writing
  (puts) file onto remote           file
  host

                                               2: Application Layer   49
Electronic Mail                                                 outgoing
                                                           message queue
                                                             user mailbox
                                           user
Three major components:                   agent
Ì user agents                     mail
                                                                  user
Ì mail servers                   server
                                                                 agent
Ì simple mail transfer                     SMTP          mail
  protocol: SMTP                                        server       user
                                SMTP                                agent
User Agent
Ì a.k.a. “mail reader”                     SMTP
                                  mail                            user
Ì composing, editing, reading                                    agent
                                 server
  mail messages
Ì e.g., Eudora, Outlook, elm,                user
  Mozilla Thunderbird                       agent
                                   user
Ì outgoing, incoming messages     agent
  stored on server
                                                    2: Application Layer    50
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     51
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
    commands: ASCII text
    response: status code and phrase

Ì messages must be in 7-bit ASCII



                                                 2: Application Layer   52
Scenario: Alice sends message to Bob
1) Alice uses UA to compose      4) SMTP client sends Alice’s
   message and “to”                 message over the TCP
   bob@someschool.edu               connection
2) Alice’s UA sends message      5) Bob’s mail server places the
   to her mail server; message      message in Bob’s mailbox
   placed in message queue       6) Bob invokes his user agent
3) Client side of SMTP opens        to read message
   TCP connection with Bob’s
   mail server



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


                                                   2: Application Layer   53
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   54
Try SMTP interaction for yourself:

Ì telnet servername 25
Ì see 220 reply from server
Ì enter HELO, MAIL FROM, RCPT TO, DATA, QUIT
  commands
above lets you send email without using email client
  (reader)




                                          2: Application Layer   55
SMTP: final words
Ì SMTP uses persistent          Comparison with HTTP:
  connections
                                Ì HTTP: pull
Ì SMTP requires message
                                Ì SMTP: push
  (header & body) to be in 7-
  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   56
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     57
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: gmail, Hotmail, Yahoo! Mail, etc.

                                                     2: Application Layer   58
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
    +OK
                               S:   .
                               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   59
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
Ì POP3 is stateless             message IDs and folder
                                name
  across sessions
                                         2: Application Layer   60
DNS: Domain Name System

People: many identifiers:       Domain Name System:
      SSN, name, passport #    Ì distributed database
                                  implemented in hierarchy of
Internet hosts, routers:
                                  many name servers
      IP address (32 bit) -
                                Ì application-layer protocol
       used for addressing
                                  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   61
DNS
DNS services                    Why not centralize DNS?
Ì hostname to IP                Ì single point of failure
  address translation           Ì traffic volume
Ì host aliasing                 Ì distant centralized
      Canonical, alias names     database
Ì mail server aliasing          Ì maintenance
Ì load distribution
    replicated Web servers:
                                doesn’t scale!
     set of IP addresses for
     one canonical name




                                                 2: Application Layer   62
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   63
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 LA)
                                    d U Maryland College Park, MD     k RIPE London (also 16 other locations)
                                    g US DoD Vienna, VA
                                    h ARL Aberdeen, MD                i Autonomica, Stockholm (plus
                                    j Verisign, ( 21 locations)                     28 other locations)
e NASA Mt View, CA                                                                             m WIDE Tokyo (also Seoul,
f Internet Software C. Palo Alto,                                                              Paris, SF)
CA (and 36 other locations)



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




                                                                                                           2: Application Layer   64
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, mail).
    can be maintained by organization or service
     provider

                                         2: Application Layer   66
Local 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
     acts as proxy, forwards query into hierarchy




                                          2: Application Layer   67
DNS name                                   root DNS server

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

 iterated query:          local DNS server
                            dns.poly.edu
 Ì contacted server                                       6
                                                 7
   replies with name of           1    8
   server to contact
 Ì “I don’t know this                            authoritative DNS server
                                                    dns.cs.umass.edu
   name, but ask this     requesting host
   server”                  cis.poly.edu

                                                      gaia.cs.umass.edu


                                                     2: Application Layer   68
DNS name
resolution example                       root DNS server



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

                                1    8

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

                                                 gaia.cs.umass.edu

                                                          2: Application Layer   69
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   70
DNS records
DNS: distributed db storing resource records (RR)
          RR format:   (name, value, type, ttl)


Ì Type=A                    Ì Type=CNAME
    name is hostname           name is alias name for some
    value is IP address         “canonical” (the real) name
Ì Type=NS                        www.ibm.com is really
                                  servereast.backup2.ibm.com
    name is domain (e.g.
                                value is canonical name
     foo.com)
    value is hostname of    Ì Type=MX
     authoritative name server
                                 value is name of mailserver
     for this domain
                                  associated with name

                                             2: Application Layer   71
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   72
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   73
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
Ì How do people get IP address of your Web site?


                                                 2: Application Layer   74
Pure P2P architecture
Ì no always-on server
Ì arbitrary end systems
  directly communicate peer-peer
Ì peers are intermittently
  connected and change IP
  addresses

Ì Three topics:
    File distribution
    Searching for information

   – Case Study: Skype/Bit-
     torrent
                                   2: Application Layer   75
File Distribution: Server-Client vs P2P
  Question : How much time to distribute file
   from one server to N peers?
                                                us: server upload
               Server
                                                bandwidth
                                                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   76
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     77
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
                                      dN
  to download                                   abundant bandwidth)
                                      uN
Ì NF bits must be
  downloaded (aggregate)
   Ì fastest possible upload rate: u +
                                    s         Σ ui


       dP2P = max { F/us, F/min(di) , NF/(us + Σui) }
                                     i
                                                     2: Application Layer   78
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   79
Types of P2P Architectures
Centralized
--E.g., Napster

Pure
--E.g., Gnutella

Hybrid
--E.g., Bit-torrent
Key Differences
Centralized
-A server keeps track of location of files &
  corresponding peers
-Peer only needs to contact the server to get
  the download location
-Insecure due to single point of failure
Pure
-No tracking of files
-Queries are flooded throughout the network
-Robust as there is no single point of failure
Key Differences
Hybrid
-Overlay networks –logically connected nodes
-Publish file locations on websites/blogs etc
-A group of “trackers” maintain file locations
(Bit-torrent for example)
-Distributed Hash Tables are used for
  efficient searching of file locations
Useful Links
http://bittorrent.org/bittorrentecon.pdf
http://dessent.net/btfaq/
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   83
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   84
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
                               re-evaluate top 4 every
  file chunks
                                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
     rarest first
                               “optimistically unchoke”

                                        2: Application Layer   85
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   86
Distributed Hash Table (DHT)
Ì DHT = distributed P2P database
Ì Database has (key, value) pairs;
   key: ss number; value: human name
   key: content type; value: IP address

Ì Peers query DB with key
    DB returns values that match the key

Ì Peers can also insert (key, value) peers
DHT Identifiers
Ì Assign integer identifier to each peer in range
  [0,2n-1].
      Each identifier can be represented by n bits.
Ì Require each key to be an integer in same range.
Ì To get integer keys, hash original key.
    eg, key = h(“Led Zeppelin IV”)
    This is why they call it a distributed “hash” table
How to assign keys to peers?
Ì Central issue:
    Assigning (key, value) pairs to peers.

Ì Rule: assign key to the peer that has the
  closest ID.
Ì Convention in lecture: closest is the
  immediate successor of the key.
Ì Ex: n=4; peers: 1,3,4,5,8,10,12,14;
    key = 13, then successor peer = 14
    key = 15, then successor peer = 1
Circular DHT (1)
                     1


           15               3

                                4
           12
                            5
                10
                     8
Ì Each peer only aware of immediate successor
  and predecessor.
Ì “Overlay network”
Circle DHT (2)

O(N) messages                                   0001              Who’s resp
on avg to resolve                                                 for key 1110 ?
                           I am
query, when there                                       0011
are N peers
                    1111
                                                          1110


                           1110
                                                                  0100
                                                          1110

                  1100
                                  1110
                                                   1110          0101
 Define closest                          1110

 as closest                1010
 successor                                       1000
Circular DHT with Shortcuts
                              1            Who’s resp
                                           for key 1110?
                                      3
               15

                                           4
               12
                                       5
                    10
                            8
Ì Each peer keeps track of IP addresses of predecessor,
  successor, short cuts.
Ì Reduced from 6 to 2 messages.
Ì Possible to design shortcuts so O(log N) neighbors, O(log
  N) messages in query
Peer Churn
           1
                          •To handle peer churn, require

                  3       each peer to know the IP address
15
                          of its two successors.
                          • Each peer periodically pings its
                      4
                          two successors to see if they
12                        are still alive.
                  5
     10
          8
Ì Peer 5 abruptly leaves
Ì Peer 4 detects; makes 8 its immediate successor;
  asks 8 who its immediate successor is; makes 8’s
  immediate successor its second successor.
Ì What if peer 13 wants to join?
P2P Case study: Skype
                                        Skype clients (SC)
Ì inherently P2P: pairs
  of users communicate.
Ì proprietary               Skype
  application-layer      login server            Supernode
  protocol (inferred via                         (SN)
  reverse engineering)
Ì hierarchical overlay
  with SNs
Ì Index maps usernames
  to IP addresses;
  distributed over SNs

                                        2: Application Layer   94
Peers as relays
Ì Problem when both
  Alice and Bob are
  behind “NATs”.
      NAT prevents an outside
       peer from initiating a call
       to insider peer
Ì Solution:
    Using Alice’s and Bob’s
     SNs, Relay is chosen
    Each peer initiates
     session with relay.
    Peers can now
     communicate through
     NATs via relay

                                     2: Application Layer   95
Key Differences Re-visited
-Client-Server architecture poor scaling for
  Server
-Pure/Centralized P2P architecture good
  scaling but performs poorly when upload
  speeds of peer is bad (due to individual TCP
  connections
-Hybrid/Torrents –advantage of both
  centralized/pure P2P by splitting files into
  multiple chunks and off-loading work to
  different peers (creating more sources)
Chapter 2: Summary
our study of network apps now complete!
Ì application architectures         Ì specific protocols:
    client-server                      HTTP
    P2P                                FTP
    hybrid                             SMTP, POP, IMAP
                                        DNS
Ì application service
                                        P2P: BitTorrent, Skype
  requirements:
       reliability, bandwidth,     Ì socket programming
       delay
Ì Internet transport
  service model
      connection-oriented,
       reliable: TCP
      unreliable, datagrams: UDP
                                               2: Application Layer   97
Chapter 2: Summary
Most importantly: learned about protocols
Ì typical request/reply          Important themes:
  message exchange:              Ì control vs. data msgs
      client requests info or
                                     in-band, out-of-band
       service
      server responds with      Ì centralized vs.
       data, status code           decentralized
Ì message formats:               Ì stateless vs. stateful
    headers: fields giving      Ì reliable vs. unreliable
     info about data
                                   msg transfer
    data: info being
                                 Ì “complexity at network
     communicated
                                   edge”
                                             2: Application Layer   98

Mais conteúdo relacionado

Mais procurados

Communication middleware
Communication middlewareCommunication middleware
Communication middlewarePeter R. Egli
 
Network protocols and Java programming
Network protocols and Java programmingNetwork protocols and Java programming
Network protocols and Java programmingdifatta
 
protocol architecture
 protocol architecture protocol architecture
protocol architectureSrinivasa Rao
 
Internet protocol stack
Internet protocol stackInternet protocol stack
Internet protocol stackAmi Prakash
 
Application layer
Application layerApplication layer
Application layerAnithaRaj31
 
Skype testing overview
Skype testing overviewSkype testing overview
Skype testing overviewQA Club Kiev
 
Optimal Streaming Protocol for VoD Using Clients' Residual Bandwidth
Optimal Streaming Protocol for VoD Using Clients' Residual BandwidthOptimal Streaming Protocol for VoD Using Clients' Residual Bandwidth
Optimal Streaming Protocol for VoD Using Clients' Residual BandwidthIDES Editor
 
Data Networking Concepts
Data Networking ConceptsData Networking Concepts
Data Networking ConceptsPeter R. Egli
 
Emg White Paper Ver1.2
Emg White Paper Ver1.2Emg White Paper Ver1.2
Emg White Paper Ver1.2bradgaunt
 
The TCP/IP and OSI models
The TCP/IP and OSI modelsThe TCP/IP and OSI models
The TCP/IP and OSI modelsJake Weaver
 
Multiuser chat application using java
Multiuser chat application using javaMultiuser chat application using java
Multiuser chat application using javaasifnoman240
 
Chapter7 multimedia
Chapter7 multimediaChapter7 multimedia
Chapter7 multimediaKhánh Ghẻ
 
topicCybersecurity_4
topicCybersecurity_4topicCybersecurity_4
topicCybersecurity_4Anne Starr
 

Mais procurados (20)

Chapter1 intro
Chapter1 introChapter1 intro
Chapter1 intro
 
Communication middleware
Communication middlewareCommunication middleware
Communication middleware
 
Profile_Prateek
Profile_PrateekProfile_Prateek
Profile_Prateek
 
Network protocols and Java programming
Network protocols and Java programmingNetwork protocols and Java programming
Network protocols and Java programming
 
TCPIP
TCPIPTCPIP
TCPIP
 
Ch05
Ch05Ch05
Ch05
 
protocol architecture
 protocol architecture protocol architecture
protocol architecture
 
Internet protocol stack
Internet protocol stackInternet protocol stack
Internet protocol stack
 
Application layer
Application layerApplication layer
Application layer
 
Skype testing overview
Skype testing overviewSkype testing overview
Skype testing overview
 
Application layer : DNS
Application layer : DNSApplication layer : DNS
Application layer : DNS
 
Skype
SkypeSkype
Skype
 
Optimal Streaming Protocol for VoD Using Clients' Residual Bandwidth
Optimal Streaming Protocol for VoD Using Clients' Residual BandwidthOptimal Streaming Protocol for VoD Using Clients' Residual Bandwidth
Optimal Streaming Protocol for VoD Using Clients' Residual Bandwidth
 
Data Networking Concepts
Data Networking ConceptsData Networking Concepts
Data Networking Concepts
 
Tcp
TcpTcp
Tcp
 
Emg White Paper Ver1.2
Emg White Paper Ver1.2Emg White Paper Ver1.2
Emg White Paper Ver1.2
 
The TCP/IP and OSI models
The TCP/IP and OSI modelsThe TCP/IP and OSI models
The TCP/IP and OSI models
 
Multiuser chat application using java
Multiuser chat application using javaMultiuser chat application using java
Multiuser chat application using java
 
Chapter7 multimedia
Chapter7 multimediaChapter7 multimedia
Chapter7 multimedia
 
topicCybersecurity_4
topicCybersecurity_4topicCybersecurity_4
topicCybersecurity_4
 

Semelhante a App Layer Protocols and Socket Programming

Lecture application layer
Lecture application layerLecture application layer
Lecture application layerHasam Panezai
 
Materi Perkuliahan Jaringan Komputer Teknik Informatika Chapter 2
Materi Perkuliahan Jaringan Komputer Teknik Informatika Chapter 2Materi Perkuliahan Jaringan Komputer Teknik Informatika Chapter 2
Materi Perkuliahan Jaringan Komputer Teknik Informatika Chapter 2Raga Yustia
 
applicationapplicationapplicationapplication.ppt
applicationapplicationapplicationapplication.pptapplicationapplicationapplicationapplication.ppt
applicationapplicationapplicationapplication.pptDEEPAK948083
 
Chapter2 application layer
Chapter2 application layerChapter2 application layer
Chapter2 application layerKhánh Ghẻ
 
Chapter2 l2 modified_um
Chapter2 l2 modified_umChapter2 l2 modified_um
Chapter2 l2 modified_umSajid Baloch
 
Lecture-2012-2-Application Layer-Introduction.ppt
Lecture-2012-2-Application Layer-Introduction.pptLecture-2012-2-Application Layer-Introduction.ppt
Lecture-2012-2-Application Layer-Introduction.pptRashmin Tanna
 
CS3001_Computer_Networks_Chapter_2_v8.1(1).pptx
CS3001_Computer_Networks_Chapter_2_v8.1(1).pptxCS3001_Computer_Networks_Chapter_2_v8.1(1).pptx
CS3001_Computer_Networks_Chapter_2_v8.1(1).pptxfarhanali32014
 
Chapter 2 - Computer Networking a top-down Approach 7th
Chapter 2 - Computer Networking a top-down Approach 7thChapter 2 - Computer Networking a top-down Approach 7th
Chapter 2 - Computer Networking a top-down Approach 7thAndy Juan Sarango Veliz
 
Computer network network edge and network
Computer network network edge and networkComputer network network edge and network
Computer network network edge and networkrjnavallasca
 
Hasanain_Application Layer_Chapter_2_Version 7.1.ppt
Hasanain_Application Layer_Chapter_2_Version 7.1.pptHasanain_Application Layer_Chapter_2_Version 7.1.ppt
Hasanain_Application Layer_Chapter_2_Version 7.1.pptnadeemrana0257
 
02_Chapter_2_V6_LV.pptx
02_Chapter_2_V6_LV.pptx02_Chapter_2_V6_LV.pptx
02_Chapter_2_V6_LV.pptxALI2H
 
Application protocols
Application protocolsApplication protocols
Application protocolsOnline
 
Ch2 application layer Network
Ch2 application layer NetworkCh2 application layer Network
Ch2 application layer Networkcairo university
 

Semelhante a App Layer Protocols and Socket Programming (20)

Lecture application layer
Lecture application layerLecture application layer
Lecture application layer
 
Materi Perkuliahan Jaringan Komputer Teknik Informatika Chapter 2
Materi Perkuliahan Jaringan Komputer Teknik Informatika Chapter 2Materi Perkuliahan Jaringan Komputer Teknik Informatika Chapter 2
Materi Perkuliahan Jaringan Komputer Teknik Informatika Chapter 2
 
applicationapplicationapplicationapplication.ppt
applicationapplicationapplicationapplication.pptapplicationapplicationapplicationapplication.ppt
applicationapplicationapplicationapplication.ppt
 
Chapter2_L2.ppt
Chapter2_L2.pptChapter2_L2.ppt
Chapter2_L2.ppt
 
Chapter2 application layer
Chapter2 application layerChapter2 application layer
Chapter2 application layer
 
Chapter2 Application
Chapter2 ApplicationChapter2 Application
Chapter2 Application
 
Chapter2 l2 modified_um
Chapter2 l2 modified_umChapter2 l2 modified_um
Chapter2 l2 modified_um
 
20CS2008 Computer Networks
20CS2008 Computer Networks 20CS2008 Computer Networks
20CS2008 Computer Networks
 
Lecture-2012-2-Application Layer-Introduction.ppt
Lecture-2012-2-Application Layer-Introduction.pptLecture-2012-2-Application Layer-Introduction.ppt
Lecture-2012-2-Application Layer-Introduction.ppt
 
CS3001_Computer_Networks_Chapter_2_v8.1(1).pptx
CS3001_Computer_Networks_Chapter_2_v8.1(1).pptxCS3001_Computer_Networks_Chapter_2_v8.1(1).pptx
CS3001_Computer_Networks_Chapter_2_v8.1(1).pptx
 
Chapter 2 - Computer Networking a top-down Approach 7th
Chapter 2 - Computer Networking a top-down Approach 7thChapter 2 - Computer Networking a top-down Approach 7th
Chapter 2 - Computer Networking a top-down Approach 7th
 
Computer network network edge and network
Computer network network edge and networkComputer network network edge and network
Computer network network edge and network
 
Chapter_2_v8.3.pptx
Chapter_2_v8.3.pptxChapter_2_v8.3.pptx
Chapter_2_v8.3.pptx
 
Chapter_2_v8.1.pptx
Chapter_2_v8.1.pptxChapter_2_v8.1.pptx
Chapter_2_v8.1.pptx
 
Chapter 2 v6.3
Chapter 2 v6.3Chapter 2 v6.3
Chapter 2 v6.3
 
Hasanain_Application Layer_Chapter_2_Version 7.1.ppt
Hasanain_Application Layer_Chapter_2_Version 7.1.pptHasanain_Application Layer_Chapter_2_Version 7.1.ppt
Hasanain_Application Layer_Chapter_2_Version 7.1.ppt
 
02_Chapter_2_V6_LV.pptx
02_Chapter_2_V6_LV.pptx02_Chapter_2_V6_LV.pptx
02_Chapter_2_V6_LV.pptx
 
Application protocols
Application protocolsApplication protocols
Application protocols
 
Np unit1
Np unit1Np unit1
Np unit1
 
Ch2 application layer Network
Ch2 application layer NetworkCh2 application layer Network
Ch2 application layer Network
 

Mais de Digvijay Singh (14)

Week3.1
Week3.1Week3.1
Week3.1
 
Week2.1
Week2.1Week2.1
Week2.1
 
Week1.2 intro
Week1.2 introWeek1.2 intro
Week1.2 intro
 
Networks
NetworksNetworks
Networks
 
Uncertainty
UncertaintyUncertainty
Uncertainty
 
Overfitting and-tbl
Overfitting and-tblOverfitting and-tbl
Overfitting and-tbl
 
Ngrams smoothing
Ngrams smoothingNgrams smoothing
Ngrams smoothing
 
Query execution
Query executionQuery execution
Query execution
 
Query compiler
Query compilerQuery compiler
Query compiler
 
Machine learning
Machine learningMachine learning
Machine learning
 
Hmm viterbi
Hmm viterbiHmm viterbi
Hmm viterbi
 
3 fol examples v2
3 fol examples v23 fol examples v2
3 fol examples v2
 
Multidimensional Indexing
Multidimensional IndexingMultidimensional Indexing
Multidimensional Indexing
 
Bayesnetwork
BayesnetworkBayesnetwork
Bayesnetwork
 

Último

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Último (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

App Layer Protocols and Socket Programming

  • 1. Chapter 2 Application Layer 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 obviously Computer Networking: represent a lot of work on our part. In return for use, we only ask the A Top Down Approach, following:  If you use these slides (e.g., in a class) in substantially unaltered form, 5th edition. that you mention their source (after all, we’d like people to use our book!) Jim Kurose, Keith Ross Addison-Wesley, April  If you post any slides in substantially unaltered form on a www site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this material. 2009. Thanks and enjoy! JFK/KWR All material copyright 1996-2009 J.F Kurose and K.W. Ross, All Rights Reserved 2: Application Layer 1
  • 2. Chapter 2: Application layer Ì 2.1 Principles of Ì 2.6 P2P applications network applications Ì 2.7 Socket programming Ì 2.2 Web and HTTP with TCP Ì 2.3 FTP Ì 2.8 Socket programming Ì 2.4 Electronic Mail with UDP  SMTP, POP3, IMAP Ì 2.5 DNS 2: Application Layer 2
  • 3. Chapter 2: Application Layer Our goals: Ì learn about protocols Ì conceptual, by examining popular implementation application-level aspects of network protocols application protocols  HTTP  transport-layer  FTP service models  SMTP / POP3 / IMAP  client-server  DNS paradigm Ì programming network  peer-to-peer applications  socket API paradigm (tutorial) 2: Application Layer 3
  • 4. Some network apps Ì e-mail Ì voice over IP Ì web Ì real-time video Ì instant messaging conferencing Ì remote login Ì grid computing Ì P2P file sharing Ì Ì multi-user network Ì games Ì Ì streaming stored video clips 2: Application Layer 4
  • 5. Creating a network app application transport network data link write programs that physical  run on (different) end systems  communicate over network  e.g., web server software communicates with browser software application transport No need to write software network data link for network-core devices application physical transport network  Network-core devices do data link physical not run user applications  applications on end systems allows for rapid app development, propagation 2: Application Layer 5
  • 6. Application architectures Ì Client-server Ì Peer-to-peer (P2P) Ì Hybrid of client-server and P2P 2: Application Layer 6
  • 7. Client-server architecture server:  always-on host  permanent IP address  server farms for scaling clients: client/server  communicate with server  may be intermittently connected  may have dynamic IP addresses  do not communicate directly with each other 2: Application Layer 7
  • 8. Pure P2P architecture Ì no always-on server Ì arbitrary end systems directly communicate peer-peer Ì peers are intermittently connected and change IP addresses Highly scalable but difficult to manage 2: Application Layer 8
  • 9. Hybrid of client-server and P2P Skype  voice-over-IP P2P application  centralized server: finding address of remote party:  client-client connection: direct (not through server) Instant messaging  chatting between two users is P2P  centralized service: client presence detection/location • user registers its IP address with central server when it comes online • user contacts central server to find IP addresses of buddies 2: Application Layer 9
  • 10. Processes communicating Process: program running Client process: process within a host. that initiates Ì within same host, two communication processes communicate Server process: process using inter-process that waits to be communication (defined contacted by OS). Ì Note: applications with Ì processes in different P2P architectures have hosts communicate by client processes & exchanging messages server processes 2: Application Layer 10
  • 11. Sockets host or host or Ì process sends/receives server server messages to/from its socket controlled by app developer Ì socket analogous to door process process  sending process shoves socket socket message out door TCP with TCP with buffers, Internet buffers,  sending process relies on variables variables transport infrastructure on other side of door which controlled brings message to socket by OS at receiving process Ì API: (1) choice of transport protocol; (2) ability to fix a few parameters (more on this in tutorial) 2: Application Layer 11
  • 12. Addressing processes Ì to receive messages, process must have identifier Ì host device has unique 32-bit IP address Ì Q: does IP address of host suffice for identifying the process? 2: Application Layer 12
  • 13. Addressing processes Ì to receive messages, Ì identifier includes both process must have IP address and port identifier numbers associated with Ì host device has unique process on host. 32-bit IP address Ì Example port numbers: Ì Q: does IP address of  HTTP server: 80 host on which process  Mail server: 25 runs suffice for Ì to send HTTP message identifying the to gaia.cs.umass.edu web process? server:  A: No, many  IP address: 128.119.245.12 processes can be  Port number: 80 running on same host Ì more shortly… 2: Application Layer 13
  • 14. App-layer protocol defines Ì Types of messages Public-domain protocols: exchanged, Ì defined in RFCs  e.g., request, response Ì allows for Ì Message syntax: interoperability  what fields in messages & Ì e.g., HTTP, SMTP how fields are delineated Ì Message semantics Proprietary protocols:  meaning of information in Ì e.g., Skype fields Ì Rules for when and how processes send & respond to messages 2: Application Layer 14
  • 15. What transport service does an app need? Data loss Throughput Ì some apps (e.g., audio) can Ì some apps (e.g., tolerate some loss multimedia) require Ì other apps (e.g., file minimum amount of transfer, telnet) require throughput to be 100% reliable data “effective” transfer Ì other apps (“elastic apps”) Timing make use of whatever Ì some apps (e.g., throughput they get Internet telephony, interactive games) Security require low delay to be Ì Encryption, data integrity, “effective” … 2: Application Layer 15
  • 16. Transport service requirements of common apps Application Data loss Throughput Time Sensitive file transfer no loss elastic no e-mail no loss elastic no Web documents no loss elastic no real-time audio/video loss-tolerant audio: 5kbps-1Mbps yes, 100’s msec video:10kbps-5Mbps stored audio/video loss-tolerant same as above yes, few secs interactive games loss-tolerant few kbps up yes, 100’s msec instant messaging no loss elastic yes and no 2: Application Layer 16
  • 17. Internet transport protocols services TCP service: UDP service: Ì connection-oriented: setup Ì unreliable data transfer required between client and between sending and server processes receiving process Ì reliable transport between Ì does not provide: sending and receiving process connection setup, Ì flow control: sender won’t reliability, flow control, overwhelm receiver congestion control, timing, throughput guarantee, or Ì congestion control: throttle security sender when network overloaded Ì does not provide: timing, Q: why bother? Why is minimum throughput there a UDP? guarantees, security 2: Application Layer 17
  • 18. Internet apps: application, transport protocols Application Underlying Application layer protocol transport protocol e-mail SMTP [RFC 2821] TCP remote terminal access Telnet [RFC 854] TCP Web HTTP [RFC 2616] TCP file transfer FTP [RFC 959] TCP streaming multimedia HTTP (eg Youtube), TCP or UDP RTP [RFC 1889] Internet telephony SIP, RTP, proprietary (e.g., Skype) typically UDP 2: Application Layer 18
  • 19. Web and HTTP First some jargon Ì Web page consists of objects Ì Object can be HTML file, JPEG image, Java applet, audio file,… Ì Web page consists of base HTML-file which includes several referenced objects Ì Each object is addressable by a URL Ì Example URL: www.someschool.edu/someDept/pic.gif host name path name 2: Application Layer 19
  • 20. HTTP overview HTTP: hypertext transfer protocol HT TP re q Ì Web’s application layer PC running HT ues TP t protocol Explorer re s pon se Ì client/server model  client: browser that st requests, receives, re que TP se Server T p on “displays” Web objects H res running T P Apache Web  server: Web server HT server sends objects in response to requests Mac running Navigator 2: Application Layer 20
  • 21. HTTP overview (continued) Uses TCP: HTTP is “stateless” Ì client initiates TCP Ì server maintains no connection (creates socket) information about to server, port 80 past client requests Ì server accepts TCP connection from client aside Protocols that maintain Ì HTTP messages (application- “state” are complex! layer protocol messages) Ì past history (state) must exchanged between browser be maintained (HTTP client) and Web Ì if server/client crashes, server (HTTP server) their views of “state” may Ì TCP connection closed be inconsistent, must be reconciled 2: Application Layer 21
  • 22. HTTP connections Nonpersistent HTTP Persistent HTTP Ì At most one object is Ì Multiple objects can sent over a TCP be sent over single connection. TCP connection between client and server. 2: Application Layer 22
  • 23. Nonpersistent HTTP (contains text, Suppose user enters URL references to 10 www.someSchool.edu/someDepartment/home.index jpeg images) 1a. HTTP client initiates TCP connection to HTTP server (process) at 1b. HTTP server at host www.someSchool.edu waiting www.someSchool.edu on port 80 for TCP connection at port 80. “accepts” connection, notifying client 2. HTTP client sends HTTP request message (containing URL) into TCP connection 3. HTTP server receives request socket. Message indicates message, forms response that client wants object message containing requested someDepartment/home.index object, and sends message into its socket time 2: Application Layer 23
  • 24. Nonpersistent HTTP (cont.) 4. HTTP server closes TCP connection. 5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 10 referenced jpeg objects time 6. Steps 1-5 repeated for each of 10 jpeg objects 2: Application Layer 24
  • 25. Non-Persistent HTTP: Response time Definition of RTT: time for a small packet to travel from client to server and back. initiate TCP connection Response time: RTT Ì one RTT to initiate TCP request file connection time to RTT transmit Ì one RTT for HTTP file request and first few file received bytes of HTTP response to return time time Ì file transmission time total = 2RTT+transmit time 2: Application Layer 25
  • 26. Persistent HTTP Nonpersistent HTTP issues: Persistent HTTP Ì requires 2 RTTs per object Ì server leaves connection Ì OS overhead for each TCP open after sending connection response Ì browsers often open parallel Ì subsequent HTTP messages TCP connections to fetch between same referenced objects client/server sent over open connection Ì client sends requests as soon as it encounters a referenced object Ì as little as one RTT for all the referenced objects 2: Application Layer 26
  • 27. HTTP request message Ì two types of HTTP messages: request, response Ì HTTP request message:  ASCII (human-readable format) request line (GET, POST, GET /somedir/page.html HTTP/1.1 HEAD commands) Host: www.someschool.edu User-agent: Mozilla/4.0 header Connection: close lines Accept-language:fr Carriage return, (extra carriage return, line feed) line feed indicates end of message 2: Application Layer 27
  • 28. HTTP request message: general format 2: Application Layer 28
  • 29. Uploading form input Post method: Ì Web page often includes form input URL method: Ì Input is uploaded to Ì Uses GET method server in entity body Ì Input is uploaded in URL field of request line: www.somesite.com/animalsearch?monkeys&banana 2: Application Layer 29
  • 30. Method types HTTP/1.0 HTTP/1.1 Ì GET Ì GET, POST, HEAD Ì POST Ì PUT Ì HEAD  uploads file in entity body to path specified  asks server to leave in URL field requested object out of response Ì DELETE  deletes file specified in the URL field 2: Application Layer 30
  • 31. HTTP response message status line (protocol status code HTTP/1.1 200 OK status phrase) Connection close Date: Thu, 06 Aug 1998 12:00:15 GMT header Server: Apache/1.3.0 (Unix) lines Last-Modified: Mon, 22 Jun 1998 …... Content-Length: 6821 Content-Type: text/html data, e.g., data data data data data ... requested HTML file 2: Application Layer 31
  • 32. HTTP response status codes In first line in server->client response message. A few sample codes: 200 OK  request succeeded, requested object later in this message 301 Moved Permanently  requested object moved, new location specified later in this message (Location:) 400 Bad Request  request message not understood by server 404 Not Found  requested document not found on this server 505 HTTP Version Not Supported 2: Application Layer 32
  • 33. HTTP Server How to scale to large number of users? -Fork --create a copy of itself which handles each client request -Threads --create a thread to handle each request
  • 34. HTTP Server Forked server operation --A single listen socket for client requests --A connected socket to each request --A forked process for each connected socket ---child process closes listening socket (Why?) --Server goes back to listening --Forked process exits after connection is processed.
  • 35. HTTP Server Threaded server --Listening is similar --connection socket created --A thread is given the connection socket ---listening socket is left alone by thread --Thread closes connected socket after request --Server keeps listening for new requests
  • 36. HTTP Client How to reduce fetch time? -Pipelining --send multiple requests without waiting for responses –persistent connections --Pipelined requests are expected to be served “in-order” to client --Use headers to separate responses -Multiple requests sent via --Threads or Forked processes
  • 37. Trying out HTTP (client side) for yourself 1. Telnet to your favorite Web server: telnet cis.poly.edu 80 Opens TCP connection to port 80 (default HTTP server port) at cis.poly.edu. Anything typed in sent to port 80 at cis.poly.edu 2. Type in a GET HTTP request: GET /~ross/ HTTP/1.1 By typing this in (hit carriage Host: cis.poly.edu return twice), you send this minimal (but complete) GET request to HTTP server 3. Look at response message sent by HTTP server! 2: Application Layer 37
  • 38. User-server state: cookies Example: Many major Web sites use cookies Ì Susan always access Four components: Internet always from PC 1) cookie header line of Ì visits specific e- HTTP response message commerce site for first 2) cookie header line in time HTTP request message 3) cookie file kept on Ì when initial HTTP user’s host, managed by requests arrives at site, user’s browser site creates: 4) back-end database at Web site  unique ID  entry in backend database for ID 2: Application Layer 38
  • 39. Cookies: keeping “state” (cont.) client server ebay 8734 usual http request msg Amazon server cookie file usual http response creates ID Set-cookie: 1678 1678 for user create ebay 8734 entry amazon 1678 usual http request msg cookie: 1678 cookie- access specific one week later: usual http response msg action backend database access ebay 8734 usual http request msg amazon 1678 cookie: 1678 cookie- spectific usual http response msg action 2: Application Layer 39
  • 40. Cookies (continued) aside What cookies can bring: Cookies and privacy: Ì authorization Ì cookies permit sites to Ì shopping carts learn a lot about you Ì you may supply name Ì recommendations and e-mail to sites Ì user session state (Web e-mail) How to keep “state”: Ì protocol endpoints: maintain state at sender/receiver over multiple transactions Ì cookies: http messages carry state 2: Application Layer 40
  • 41. Web caches (proxy server) Goal: satisfy client request without involving origin server Ì user sets browser: origin server Web accesses via cache HT Proxy TP st Ì browser sends all req server re que HT ues TP e client TP t T ons HTTP requests to res H e sp pon se TPr HT cache ues t eq se  object in cache: cache T Pr on HT p returns object P re s H TT  else cache requests object from origin client origin server, then returns server object to client 2: Application Layer 41
  • 42. More about Web caching Ì cache acts as both Why Web caching? client and server Ì reduce response time Ì typically cache is for client request installed by ISP Ì reduce traffic on an (university, company, institution’s access residential ISP) link. Ì Internet dense with caches: enables “poor” content providers to effectively deliver content (but so does P2P file sharing) 2: Application Layer 42
  • 43. Caching example origin Assumptions servers Ì average object size = 100,000 public bits Internet Ì avg. request rate from institution’s browsers to origin servers = 15/sec 1.5 Mbps Ì delay from institutional router access link to any origin server and back institutional to router = 2 sec network 10 Mbps LAN Consequences Ì utilization on LAN = 15% Ì utilization on access link = 100% institutional Ì total delay = Internet delay + cache access delay + LAN delay = 2 sec + minutes + milliseconds 2: Application Layer 43
  • 44. Caching example (cont) origin possible solution servers Ì increase bandwidth of access public link to, say, 10 Mbps Internet consequence Ì utilization on LAN = 15% Ì utilization on access link = 15% 10 Mbps Ì Total delay = Internet delay + access link access delay + LAN delay institutional = 2 sec + msecs + msecs network 10 Mbps LAN Ì often a costly upgrade institutional cache 2: Application Layer 44
  • 45. Caching example (cont) origin possible solution: install servers cache public Ì suppose hit rate is 0.4 Internet consequence Ì 40% requests will be satisfied almost immediately 1.5 Mbps Ì 60% requests satisfied by access link origin server Ì utilization of access link institutional reduced to 60%, resulting in network 10 Mbps LAN negligible delays (say 10 msec) Ì total avg delay = Internet delay + access delay + LAN institutional delay = .6*(2.01) secs + . cache 4*milliseconds < 1.4 secs 2: Application Layer 45
  • 46. Conditional GET Ì Goal: don’t send object if cache server cache has up-to-date cached HTTP request msg version If-modified-since: object Ì cache: specify date of <date> not cached copy in HTTP request modified HTTP response If-modified-since: HTTP/1.0 <date> 304 Not Modified Ì server: response contains no object if cached copy is up- HTTP request msg to-date: If-modified-since: HTTP/1.0 304 Not <date> object Modified modified HTTP response HTTP/1.0 200 OK <data> 2: Application Layer 46
  • 47. FTP: the file transfer protocol FTP file transfer FTP FTP user client server interface user at host remote file local file system 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 2: Application Layer 47
  • 48. FTP: separate control, data connections TCP control connection Ì FTP client contacts FTP server port 21 at port 21, TCP is transport protocol TCP data connection Ì client authorized over control FTP port 20 FTP connection client server Ì client browses remote Ì server opens another TCP directory by sending commands data connection to transfer over control connection. another file. Ì when server receives file Ì control connection: “out of transfer command, server band” opens 2nd TCP connection (for Ì FTP server maintains “state”: file) to client current directory, earlier Ì after transferring one file, authentication server closes data connection. 2: Application Layer 48
  • 49. FTP commands, responses Sample commands: Sample return codes Ì sent as ASCII text over Ì status code and phrase (as control channel in HTTP) Ì USER username Ì 331 Username OK, Ì PASS password password required Ì LIST return list of file in Ì 125 data connection current directory already open; transfer starting Ì RETR filename retrieves Ì 425 Can’t open data (gets) file connection Ì STOR filename stores Ì 452 Error writing (puts) file onto remote file host 2: Application Layer 49
  • 50. Electronic Mail outgoing message queue user mailbox user Three major components: agent Ì user agents mail user Ì mail servers server agent Ì simple mail transfer SMTP mail protocol: SMTP server user SMTP agent User Agent Ì a.k.a. “mail reader” SMTP mail user Ì composing, editing, reading agent server mail messages Ì e.g., Eudora, Outlook, elm, user Mozilla Thunderbird agent user Ì outgoing, incoming messages agent stored on server 2: Application Layer 50
  • 51. 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 51
  • 52. 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  commands: ASCII text  response: status code and phrase Ì messages must be in 7-bit ASCII 2: Application Layer 52
  • 53. Scenario: Alice sends message to Bob 1) Alice uses UA to compose 4) SMTP client sends Alice’s message and “to” message over the TCP bob@someschool.edu connection 2) Alice’s UA sends message 5) Bob’s mail server places the to her mail server; message message in Bob’s mailbox placed in message queue 6) Bob invokes his user agent 3) Client side of SMTP opens to read message TCP connection with Bob’s mail server 1 mail mail server user user server 2 agent agent 3 6 4 5 2: Application Layer 53
  • 54. 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 54
  • 55. Try SMTP interaction for yourself: Ì telnet servername 25 Ì see 220 reply from server Ì enter HELO, MAIL FROM, RCPT TO, DATA, QUIT commands above lets you send email without using email client (reader) 2: Application Layer 55
  • 56. SMTP: final words Ì SMTP uses persistent Comparison with HTTP: connections Ì HTTP: pull Ì SMTP requires message Ì SMTP: push (header & body) to be in 7- 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 56
  • 57. 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 57
  • 58. 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: gmail, Hotmail, Yahoo! Mail, etc. 2: Application Layer 58
  • 59. 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  +OK S: . 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 59
  • 60. 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 Ì POP3 is stateless message IDs and folder name across sessions 2: Application Layer 60
  • 61. DNS: Domain Name System People: many identifiers: Domain Name System:  SSN, name, passport # Ì distributed database implemented in hierarchy of Internet hosts, routers: many name servers  IP address (32 bit) - Ì application-layer protocol used for addressing 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 61
  • 62. DNS DNS services Why not centralize DNS? Ì hostname to IP Ì single point of failure address translation Ì traffic volume Ì host aliasing Ì distant centralized  Canonical, alias names database Ì mail server aliasing Ì maintenance Ì load distribution  replicated Web servers: doesn’t scale! set of IP addresses for one canonical name 2: Application Layer 62
  • 63. 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 63
  • 64. 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 LA) d U Maryland College Park, MD k RIPE London (also 16 other locations) g US DoD Vienna, VA h ARL Aberdeen, MD i Autonomica, Stockholm (plus j Verisign, ( 21 locations) 28 other locations) e NASA Mt View, CA m WIDE Tokyo (also Seoul, f Internet Software C. Palo Alto, Paris, SF) CA (and 36 other locations) 13 root name servers worldwide b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA 2: Application Layer 64
  • 65.
  • 66. 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, mail).  can be maintained by organization or service provider 2: Application Layer 66
  • 67. Local 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  acts as proxy, forwards query into hierarchy 2: Application Layer 67
  • 68. DNS name root DNS server resolution example 2 Ì Host at cis.poly.edu 3 TLD DNS server wants IP address for 4 gaia.cs.umass.edu 5 iterated query: local DNS server dns.poly.edu Ì contacted server 6 7 replies with name of 1 8 server to contact Ì “I don’t know this authoritative DNS server dns.cs.umass.edu name, but ask this requesting host server” cis.poly.edu gaia.cs.umass.edu 2: Application Layer 68
  • 69. DNS name resolution example root DNS server recursive query: 2 3 Ì puts burden of name 7 6 resolution on TLD DNS server contacted name server Ì heavy load? local DNS server dns.poly.edu 5 4 1 8 authoritative DNS server dns.cs.umass.edu requesting host cis.poly.edu gaia.cs.umass.edu 2: Application Layer 69
  • 70. 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 70
  • 71. DNS records DNS: distributed db storing resource records (RR) RR format: (name, value, type, ttl) Ì Type=A Ì Type=CNAME  name is hostname  name is alias name for some  value is IP address “canonical” (the real) name Ì Type=NS www.ibm.com is really servereast.backup2.ibm.com  name is domain (e.g.  value is canonical name foo.com)  value is hostname of Ì Type=MX authoritative name server  value is name of mailserver for this domain associated with name 2: Application Layer 71
  • 72. 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 72
  • 73. 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 73
  • 74. 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 Ì How do people get IP address of your Web site? 2: Application Layer 74
  • 75. Pure P2P architecture Ì no always-on server Ì arbitrary end systems directly communicate peer-peer Ì peers are intermittently connected and change IP addresses Ì Three topics:  File distribution  Searching for information – Case Study: Skype/Bit- torrent 2: Application Layer 75
  • 76. File Distribution: Server-Client vs P2P Question : How much time to distribute file from one server to N peers? us: server upload Server bandwidth 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 76
  • 77. 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 77
  • 78. 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 dN to download abundant bandwidth) uN Ì NF bits must be downloaded (aggregate) Ì fastest possible upload rate: u + s Σ ui dP2P = max { F/us, F/min(di) , NF/(us + Σui) } i 2: Application Layer 78
  • 79. 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 79
  • 80. Types of P2P Architectures Centralized --E.g., Napster Pure --E.g., Gnutella Hybrid --E.g., Bit-torrent
  • 81. Key Differences Centralized -A server keeps track of location of files & corresponding peers -Peer only needs to contact the server to get the download location -Insecure due to single point of failure Pure -No tracking of files -Queries are flooded throughout the network -Robust as there is no single point of failure
  • 82. Key Differences Hybrid -Overlay networks –logically connected nodes -Publish file locations on websites/blogs etc -A group of “trackers” maintain file locations (Bit-torrent for example) -Distributed Hash Tables are used for efficient searching of file locations Useful Links http://bittorrent.org/bittorrentecon.pdf http://dessent.net/btfaq/
  • 83. 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 83
  • 84. 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 84
  • 85. 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  re-evaluate top 4 every file chunks 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  rarest first  “optimistically unchoke” 2: Application Layer 85
  • 86. 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 86
  • 87. Distributed Hash Table (DHT) Ì DHT = distributed P2P database Ì Database has (key, value) pairs;  key: ss number; value: human name  key: content type; value: IP address Ì Peers query DB with key  DB returns values that match the key Ì Peers can also insert (key, value) peers
  • 88. DHT Identifiers Ì Assign integer identifier to each peer in range [0,2n-1].  Each identifier can be represented by n bits. Ì Require each key to be an integer in same range. Ì To get integer keys, hash original key.  eg, key = h(“Led Zeppelin IV”)  This is why they call it a distributed “hash” table
  • 89. How to assign keys to peers? Ì Central issue:  Assigning (key, value) pairs to peers. Ì Rule: assign key to the peer that has the closest ID. Ì Convention in lecture: closest is the immediate successor of the key. Ì Ex: n=4; peers: 1,3,4,5,8,10,12,14;  key = 13, then successor peer = 14  key = 15, then successor peer = 1
  • 90. Circular DHT (1) 1 15 3 4 12 5 10 8 Ì Each peer only aware of immediate successor and predecessor. Ì “Overlay network”
  • 91. Circle DHT (2) O(N) messages 0001 Who’s resp on avg to resolve for key 1110 ? I am query, when there 0011 are N peers 1111 1110 1110 0100 1110 1100 1110 1110 0101 Define closest 1110 as closest 1010 successor 1000
  • 92. Circular DHT with Shortcuts 1 Who’s resp for key 1110? 3 15 4 12 5 10 8 Ì Each peer keeps track of IP addresses of predecessor, successor, short cuts. Ì Reduced from 6 to 2 messages. Ì Possible to design shortcuts so O(log N) neighbors, O(log N) messages in query
  • 93. Peer Churn 1 •To handle peer churn, require 3 each peer to know the IP address 15 of its two successors. • Each peer periodically pings its 4 two successors to see if they 12 are still alive. 5 10 8 Ì Peer 5 abruptly leaves Ì Peer 4 detects; makes 8 its immediate successor; asks 8 who its immediate successor is; makes 8’s immediate successor its second successor. Ì What if peer 13 wants to join?
  • 94. P2P Case study: Skype Skype clients (SC) Ì inherently P2P: pairs of users communicate. Ì proprietary Skype application-layer login server Supernode protocol (inferred via (SN) reverse engineering) Ì hierarchical overlay with SNs Ì Index maps usernames to IP addresses; distributed over SNs 2: Application Layer 94
  • 95. Peers as relays Ì Problem when both Alice and Bob are behind “NATs”.  NAT prevents an outside peer from initiating a call to insider peer Ì Solution:  Using Alice’s and Bob’s SNs, Relay is chosen  Each peer initiates session with relay.  Peers can now communicate through NATs via relay 2: Application Layer 95
  • 96. Key Differences Re-visited -Client-Server architecture poor scaling for Server -Pure/Centralized P2P architecture good scaling but performs poorly when upload speeds of peer is bad (due to individual TCP connections -Hybrid/Torrents –advantage of both centralized/pure P2P by splitting files into multiple chunks and off-loading work to different peers (creating more sources)
  • 97. Chapter 2: Summary our study of network apps now complete! Ì application architectures Ì specific protocols:  client-server  HTTP  P2P  FTP  hybrid  SMTP, POP, IMAP  DNS Ì application service  P2P: BitTorrent, Skype requirements:  reliability, bandwidth, Ì socket programming delay Ì Internet transport service model  connection-oriented, reliable: TCP  unreliable, datagrams: UDP 2: Application Layer 97
  • 98. Chapter 2: Summary Most importantly: learned about protocols Ì typical request/reply Important themes: message exchange: Ì control vs. data msgs  client requests info or  in-band, out-of-band service  server responds with Ì centralized vs. data, status code decentralized Ì message formats: Ì stateless vs. stateful  headers: fields giving Ì reliable vs. unreliable info about data msg transfer  data: info being Ì “complexity at network communicated edge” 2: Application Layer 98