SlideShare a Scribd company logo
1 of 115
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,     4th edition.
that you mention their source (after all, we’d like people to use our book!)      Jim Kurose, Keith Ross
                                                                                  Addison-Wesley, July
 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.                                              2012.
Thanks and enjoy! JFK/KWR

All material copyright 1996-2007
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


                                       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
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.9 Building a Web
 2.5 DNS                server




                                  2: Application Layer   6
Application architectures
 Client-server
 Peer-to-peer (P2P)
 Hybrid of client-server and P2P




                                   2: Application Layer   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   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   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   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).
  processes in different   Note: applications with
  hosts communicate by     P2P architectures have
  exchanging messages      client processes &
                           server processes


                                     2: Application Layer   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 (lots more on this later)
                                                           2: Application Layer   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   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   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
                                 Proprietary protocols:
 Message semantics
    meaning of information in     e.g., Skype
     fields
 Rules for when and how
 processes send &
 respond to messages
                                            2: Application Layer   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   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   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   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   19
Chapter 2: Application layer
 2.1 Principles of       2.6 P2P applications
 network applications    2.7 Socket programming
    app architectures   with TCP
     app requirements
                         2.8 Socket programming
 

 2.2 Web and HTTP        with UDP
 2.4 Electronic Mail
    SMTP, POP3, IMAP
 2.5 DNS




                                   2: Application Layer   20
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   21
HTTP overview

HTTP: hypertext
  transfer protocol                           HT
                                                TP
                                                   r
                                                  equ
  Web’s application layer      PC running HT
                                            TP
                                                      est
  protocol                      Explorer       res
                                                   pon
                                                       se
  client/server model
    client: browser that
                                                     st
                                                   ue
      requests, receives,                        eq
                                             TPr       on
                                                         se Server
      “displays” Web objects               HT     res
                                                      p      running
                                               TP          Apache Web
    server: Web server                      HT
                                                             server
      sends objects in
      response to requests
                                Mac running
                                 Navigator



                                                 2: Application Layer   22
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   23
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   24
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   25
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   26
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   27
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   28
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   29
HTTP request message: general format
  Post and head




                            2: Application Layer   30
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   31
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   32
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   33
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   34
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   35
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   36
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   37
Cookies (continued)
                                                  aside
What cookies can bring:       Cookies and privacy:
 authorization                  cookies permit sites to
 shopping carts                 learn a lot about you
 recommendations                you may supply name
                                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   38
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         reque
                                     HT            ues        TP          e
                               client TP               t    HT        on s
 HTTP requests to                          res                     esp
                                               pon             TPr
                                                   se       HT
 cache                                         ue
                                                  st
                                             eq       se
     object in cache: cache            T Pr        on
                                     HT          sp
      returns object                        P re
                                        HTT
     else cache requests
      object from origin        client
                                                                          origin
      server, then returns                                                server
      object to client
                                                         2: Application Layer   39
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   40
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   41
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   42
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   43
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   44
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.9 Building a Web
 2.5 DNS                server




                                  2: Application Layer   45
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   46
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
 file) to client                    FTP server maintains “state”:
                                    current directory, earlier
 after transferring one file,
                                    authentication
 server closes data connection.
                                                   2: Application Layer   47
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   48
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   49
Electronic Mail                                                outgoing
                                                          message queue
                                                            user mailbox
                                           user
Three major components:                   agent
  user agents                     mail
                                                                 user
                                 server
  mail servers                                                  agent
  simple mail transfer                     SMTP         mail
  protocol: SMTP                                       server       user
                                SMTP                               agent
User Agent
  a.k.a. “mail reader”                     SMTP
                                  mail                           user
  composing, editing, reading    server                         agent
  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
 (header & body) to be in 7-     SMTP: push
 bit ASCII
                                 both have ASCII
 SMTP server uses                command/response
 CRLF.CRLF to determine          interaction, status codes
 end of message
                                 HTTP: each object
                                 encapsulated in its own
                                 response msg
                                 SMTP: multiple objects
                                 sent in multipart msg


                                              2: Application Layer   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
Message format: multimedia extensions
     MIME: multimedia mail extension, RFC 2045, 2056
     additional lines in msg header declare MIME content
     type


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


                                                  2: Application Layer   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   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   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
                               message IDs and folder
 POP3 is stateless
                               name
 across sessions
                                        2: Application Layer   61
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.9 Building a Web
 2.5 DNS                server




                                  2: Application Layer   62
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   63
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   64
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   65
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   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   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   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                              7        6
  replies with name of           1    8
  server to contact
                                                authoritative DNS server
  “I don’t know this                               dns.cs.umass.edu
  name, but ask this     requesting host
  server”                  cis.poly.edu

                                                     gaia.cs.umass.edu


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



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

                                                2: Application Layer   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   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   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   75
Chapter 2: Application layer
 2.1 Principles of       2.6 P2P applications
 network applications    2.7 Socket programming
    app architectures   with TCP
     app requirements
                         2.8 Socket programming
 

 2.2 Web and HTTP        with UDP
 2.4 Electronic Mail
    SMTP, POP3, IMAP
 2.5 DNS




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

                                  2: Application Layer   77
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   78
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 = max { NF/us, F/min(di) }
                       = dcs
                                              i
   client/server approach
                          increases linearly in N
                          (for large N)    2: Application Layer      79
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          dN        Network (with
  to download                                 abundant bandwidth)
                                    uN
  NF bits must be
  downloaded (aggregate)
      fastest possible upload rate: us +      Σui



       dP2P = max { F/us, F/min(di) , NF/(us +        Σui) }
                                 i
                                                    2: Application Layer   80
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   81
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   82
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   83
BitTorrent (2)             Sending Chunks: tit-for-tat
Pulling Chunks               Alice sends chunks to four
                             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
  (Alice) asks each          every 30 secs: randomly
  neighbor for list of       select another peer,
  chunks that they have.     starts sending chunks
                               newly chosen peer may
  Alice sends requests
  for her missing chunks        join top 4
                               “optimistically unchoke”
     rarest first

                                        2: Application Layer   84
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   85
P2P: searching for information
Index in P2P system: maps information to peer location
(location = IP address & port number)
.                               Instant messaging
   File sharing (eg e-mule)
      Index dynamically           Index maps user
      tracks the locations of     names to locations.
      files that peers share.     When user starts IM
      Peers need to tell          application, it needs to
      index what they have.       inform index of its
      Peers search index to       location
      determine where files       Peers search index to
      can be found                determine IP address
                                  of user.

                                              2: Application Layer   86
P2P: centralized index
                                                                           Bob
original “Napster” design        centralized
1) when peer connects, it     directory server
                                                     1
   informs central server:                                               peers
      IP address                                    1

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


3) Alice requests file from
   Bob
                                                          Alice




                                                         2: Application Layer    87
P2P: problems with centralized directory

 single point of failure   file transfer is
 performance bottleneck    decentralized, but
                           locating content is
 copyright infringement:
                           highly centralized
 “target” of lawsuit is
 obvious




                                    2: Application Layer   88
Query flooding
 fully distributed          overlay network: graph
    no central server        edge between peer X
 used by Gnutella             and Y if there’s a TCP
 Each peer indexes the        connection
 files it makes available     all active peers and
 for sharing (and no          edges form overlay
 other files)                 net
                              edge: virtual (not
                              physical) link
                              given peer typically
                              connected with < 10
                              overlay neighbors
                                         2: Application Layer   89
Query flooding
                                   File transfer:
  Query message                    HTTP
sent over existing TCP
connections
                                   Query
  peers forward                    QueryHit
Query message
                         y         Qu
  QueryHit            er             ery
                    Qu       Hi
                               t
sent over                 er
                            y
                       Qu
reverse
                     Query
path
                       QueryHit


Scalability:            Qu
                          er
                            y
limited scope
flooding
                                     2: Application Layer   90
Gnutella: Peer joining
1. joining peer Alice must find another peer in
   Gnutella network: use list of candidate peers
2. Alice sequentially attempts TCP connections with
   candidate peers until connection setup with Bob
3. Flooding: Alice sends Ping message to Bob; Bob
   forwards Ping message to his overlay neighbors
   (who then forward to their neighbors….)
       peers receiving Ping message respond to Alice
       with Pong message
1. Alice receives many Pong messages, and can then
   setup additional TCP connections
Peer leaving: see homework problem!

                                         2: Application Layer   91
Hierarchical Overlay
 between centralized
 index, query flooding
 approaches
 each peer is either a
 super node or assigned to
 a super node
    TCP connection between
     peer and its super node.
    TCP connections between
     some pairs of super nodes.   o r d in a r y p e e r


 Super node tracks                g r o u p - le a d e r p e e r


 content in its children          n e ig h o r in g r e la tio n s h ip s
                                       in o v e r la y n e tw o r k



                                                  2: Application Layer      92
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   93
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   94
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   95
Socket programming
Goal: learn how to build client/server application that
  communicate using sockets

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

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

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

                host or                host or
                server                 server

                                             2: Application Layer   97
Socket programming with TCP
Client must contact server       When contacted by client,
   server process must first     server TCP creates new
   be running                    socket for server process to
   server must have created      communicate with client
   socket (door) that              allows server to talk with
   welcomes client’s contact        multiple clients
                                   source port numbers
Client contacts server by:
                                    used to distinguish
   creating client-local TCP        clients (more in Chap 3)
   socket
   specifying IP address, port   application viewpoint
   number of server process
                                 TCP provides reliable, in-order
   When client creates             transfer of bytes (“pipe”)
   socket: client TCP              between client and server
   establishes connection to
   server TCP
                                                2: Application Layer   98
Client/server socket interaction: TCP
Server   (running on hostid)                 Client
    create socket,
    port=x, for
    incoming request:
    welcomeSocket =
       ServerSocket()

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

                                              send request using
    read request from                         clientSocket
    connectionSocket

    write reply to
    connectionSocket                          read reply from
                                              clientSocket
    close
    connectionSocket                           close
                                               clientSocket
                                                              2: Application Layer   99
Stream jargon
                                                 keyboard               monitor

A stream is a sequence of
characters that flow into
or out of a process.




                                                        inFromUser
                                         input
                                      stream

An input stream is          Client
attached to some input
                            Process
                            process
source for the process,
e.g., keyboard or socket.
An output stream is
attached to an output




                                                                            inFromServer
                                                        outToServer
                                   output                                                     input
source, e.g., monitor or          stream                                                   stream

socket.
                                                    client TCP
                                                      clientSocket
                                                      socket                                            TCP
                                                                                                      socket

                                                 to network           from network



                                                   2: Application Layer                                        100
Socket programming with TCP
Example client-server app:
1) client reads line from
   standard input (inFromUser
   stream) , sends to server via
   socket (outToServer
   stream)
2) server reads line from socket
3) server converts line to
   uppercase, sends back to
   client
4) client reads, prints modified
   line from socket
   (inFromServer stream)


                                   2: Application Layer   101
Example: Java client (TCP)
                     import java.io.*;
                     import java.net.*;
                     class TCPClient {

                       public static void main(String argv[]) throws Exception
                       {
                         String sentence;
                         String modifiedSentence;
            Create
      input stream        BufferedReader inFromUser =
                           new BufferedReader(new InputStreamReader(System.in));
           Create
    client socket,        Socket clientSocket = new Socket("hostname", 6789);
 connect to server
            Create        DataOutputStream outToServer =
     output stream         new DataOutputStream(clientSocket.getOutputStream());
attached to socket
                                                               2: Application Layer   102
Example: Java client (TCP), cont.

            Create            BufferedReader inFromServer =
      input stream             new BufferedReader(new
attached to socket             InputStreamReader(clientSocket.getInputStream()));

                              sentence = inFromUser.readLine();
          Send line
          to server           outToServer.writeBytes(sentence + 'n');

          Read line           modifiedSentence = inFromServer.readLine();
       from server
                              System.out.println("FROM SERVER: " + modifiedSentence);

                              clientSocket.close();

                          }
                      }
                                                                2: Application Layer   103
Example: Java server (TCP)
                      import java.io.*;
                      import java.net.*;

                      class TCPServer {

                       public static void main(String argv[]) throws Exception
                        {
                          String clientSentence;
           Create         String capitalizedSentence;
 welcoming socket
                          ServerSocket welcomeSocket = new ServerSocket(6789);
     at port 6789
                          while(true) {
Wait, on welcoming
socket for contact            Socket connectionSocket = welcomeSocket.accept();
          by client
                             BufferedReader inFromClient =
     Create input             new BufferedReader(new
stream, attached              InputStreamReader(connectionSocket.getInputStream()));
        to socket

                                                                  2: Application Layer   104
Example: Java server (TCP), cont

    Create output
stream, attached            DataOutputStream outToClient =
        to socket            new DataOutputStream(connectionSocket.getOutputStream());
     Read in line
     from socket            clientSentence = inFromClient.readLine();

                            capitalizedSentence = clientSentence.toUpperCase() + 'n';
   Write out line
                            outToClient.writeBytes(capitalizedSentence);
       to socket
                        }
                    }
               }                  End of while loop,
                                  loop back and wait for
                                  another client connection


                                                                  2: Application Layer   105
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   106
Socket programming with UDP

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



                                              2: Application Layer   107
Client/server socket interaction: UDP
Server   (running on hostid)   Client

    create socket,             create socket,
    port= x.                   clientSocket =
    serverSocket =             DatagramSocket()
    DatagramSocket()
                               Create datagram with server IP and
                               port=x; send datagram via
     read datagram from         clientSocket
     serverSocket

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



                                            2: Application Layer    108
Example: Java client (UDP)
                                        keyboard               monitor




                                                inFromUser
                                input
                             stream


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




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

                                        to network           from network




                                                                                                           2: Application Layer   109
Example: Java client (UDP)
                      import java.io.*;
                      import java.net.*;

                      class UDPClient {
                         public static void main(String args[]) throws Exception
                         {
            Create
      input stream       BufferedReader inFromUser =
                          new BufferedReader(new InputStreamReader(System.in));
            Create
      client socket      DatagramSocket clientSocket = new DatagramSocket();
         Translate
                         InetAddress IPAddress = InetAddress.getByName("hostname");
   hostname to IP
address using DNS        byte[] sendData = new byte[1024];
                         byte[] receiveData = new byte[1024];

                         String sentence = inFromUser.readLine();
                         sendData = sentence.getBytes();
                                                                       2: Application Layer   110
Example: Java client (UDP), cont.
    Create datagram
  with data-to-send,     DatagramPacket sendPacket =
length, IP addr, port     new DatagramPacket(sendData, sendData.length, IPAddress, 9876);

    Send datagram        clientSocket.send(sendPacket);
         to server
                         DatagramPacket receivePacket =
                          new DatagramPacket(receiveData, receiveData.length);
    Read datagram
                         clientSocket.receive(receivePacket);
      from server
                         String modifiedSentence =
                           new String(receivePacket.getData());

                         System.out.println("FROM SERVER:" + modifiedSentence);
                         clientSocket.close();
                         }
                     }


                                                                  2: Application Layer   111
Example: Java server (UDP)
                     import java.io.*;
                     import java.net.*;

                     class UDPServer {
                      public static void main(String args[]) throws Exception
          Create        {
 datagram socket
                        DatagramSocket serverSocket = new DatagramSocket(9876);
    at port 9876
                        byte[] receiveData = new byte[1024];
                        byte[] sendData = new byte[1024];

                        while(true)
                         {
  Create space for
                           DatagramPacket receivePacket =
received datagram
                            new DatagramPacket(receiveData, receiveData.length);
           Receive          serverSocket.receive(receivePacket);
         datagram
                                                                 2: Application Layer   112
Example: Java server (UDP), cont
                            String sentence = new String(receivePacket.getData());
      Get IP addr
                            InetAddress IPAddress = receivePacket.getAddress();
       port #, of
           sender           int port = receivePacket.getPort();

                                   String capitalizedSentence = sentence.toUpperCase();

                            sendData = capitalizedSentence.getBytes();
Create datagram
                            DatagramPacket sendPacket =
to send to client            new DatagramPacket(sendData, sendData.length, IPAddress,
                                       port);
      Write out
       datagram             serverSocket.send(sendPacket);
       to socket        }
                    }
                }                    End of while loop,
                                     loop back and wait for
                                     another datagram
                                                                         2: Application Layer   113
Chapter 2: Summary
our study of network apps now complete!
  application architectures         specific protocols:
                                     HTTP
      client-server
                                     FTP
      P2P
                                     SMTP, POP, IMAP
      hybrid
                                     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   114
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
      communicated                “complexity at network
                                  edge”
                                            2: Application Layer   115

More Related Content

What's hot

What's hot (20)

OSI reference model
OSI reference modelOSI reference model
OSI reference model
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Osi model vs TCP/IP
Osi model vs TCP/IPOsi model vs TCP/IP
Osi model vs TCP/IP
 
IPv4 Addressing
 IPv4 Addressing   IPv4 Addressing
IPv4 Addressing
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Control
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Chapter 2 : Application Layer
Chapter 2 : Application LayerChapter 2 : Application Layer
Chapter 2 : Application Layer
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Application Layer
Application LayerApplication Layer
Application Layer
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)
 
OSI Model
OSI ModelOSI Model
OSI Model
 
IP Routing
IP RoutingIP Routing
IP Routing
 
Network Layer
Network LayerNetwork Layer
Network Layer
 
Network address translation
Network address translationNetwork address translation
Network address translation
 
Cs8591 Computer Networks
Cs8591 Computer NetworksCs8591 Computer Networks
Cs8591 Computer Networks
 
TCP/ IP
TCP/ IP TCP/ IP
TCP/ IP
 
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
 
Chapter 2 - Network Models
Chapter 2 - Network ModelsChapter 2 - Network Models
Chapter 2 - Network Models
 
Ipv4 presentation
Ipv4 presentationIpv4 presentation
Ipv4 presentation
 

Similar to 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 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
 
Computer network network edge and network
Computer network network edge and networkComputer network network edge and network
Computer network network edge and networkrjnavallasca
 
02_Chapter_2_V6_LV.pptx
02_Chapter_2_V6_LV.pptx02_Chapter_2_V6_LV.pptx
02_Chapter_2_V6_LV.pptxALI2H
 
Ch2 application layer Network
Ch2 application layer NetworkCh2 application layer Network
Ch2 application layer Networkcairo university
 

Similar to Lecture application layer (20)

Chapter2 application
Chapter2 applicationChapter2 application
Chapter2 application
 
Week3 applications
Week3 applicationsWeek3 applications
Week3 applications
 
3rd edition chapter2
3rd edition chapter23rd edition chapter2
3rd edition chapter2
 
Chapter2[one.]
Chapter2[one.]Chapter2[one.]
Chapter2[one.]
 
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
 
App layer
App layerApp layer
App layer
 
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
 
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
 
20CS2008 Computer Networks
20CS2008 Computer Networks 20CS2008 Computer Networks
20CS2008 Computer Networks
 
Chapter 2 v6.3
Chapter 2 v6.3Chapter 2 v6.3
Chapter 2 v6.3
 
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.1.pptx
Chapter_2_v8.1.pptxChapter_2_v8.1.pptx
Chapter_2_v8.1.pptx
 
Chapter_2_v8.3.pptx
Chapter_2_v8.3.pptxChapter_2_v8.3.pptx
Chapter_2_v8.3.pptx
 
02_Chapter_2_V6_LV.pptx
02_Chapter_2_V6_LV.pptx02_Chapter_2_V6_LV.pptx
02_Chapter_2_V6_LV.pptx
 
Ch2 application layer Network
Ch2 application layer NetworkCh2 application layer Network
Ch2 application layer Network
 

More from Hasam Panezai

More from Hasam Panezai (9)

Introduction to android basics
Introduction to android basicsIntroduction to android basics
Introduction to android basics
 
Cognitive architecture
Cognitive architectureCognitive architecture
Cognitive architecture
 
cog arch
cog archcog arch
cog arch
 
To lec 03
To lec 03To lec 03
To lec 03
 
To lec 04
To lec 04To lec 04
To lec 04
 
Lecture 1 4
Lecture 1 4Lecture 1 4
Lecture 1 4
 
White box
White boxWhite box
White box
 
Software testing & its technology
Software testing & its technologySoftware testing & its technology
Software testing & its technology
 
Lecture (coa)
Lecture (coa)Lecture (coa)
Lecture (coa)
 

Recently uploaded

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

Lecture application layer

  • 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, 4th edition. that you mention their source (after all, we’d like people to use our book!) Jim Kurose, Keith Ross Addison-Wesley, July  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. 2012. Thanks and enjoy! JFK/KWR All material copyright 1996-2007 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 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. 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.9 Building a Web 2.5 DNS server 2: Application Layer 6
  • 7. Application architectures Client-server Peer-to-peer (P2P) Hybrid of client-server and P2P 2: Application Layer 7
  • 8. 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 8
  • 9. 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 9
  • 10. 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 10
  • 11. 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). processes in different Note: applications with hosts communicate by P2P architectures have exchanging messages client processes & server processes 2: Application Layer 11
  • 12. 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 (lots more on this later) 2: Application Layer 12
  • 13. 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 13
  • 14. 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 14
  • 15. 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 Proprietary protocols: Message semantics  meaning of information in e.g., Skype fields Rules for when and how processes send & respond to messages 2: Application Layer 15
  • 16. 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 16
  • 17. 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 17
  • 18. 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 18
  • 19. 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 19
  • 20. Chapter 2: Application layer 2.1 Principles of 2.6 P2P applications network applications 2.7 Socket programming  app architectures with TCP app requirements 2.8 Socket programming  2.2 Web and HTTP with UDP 2.4 Electronic Mail  SMTP, POP3, IMAP 2.5 DNS 2: Application Layer 20
  • 21. 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 21
  • 22. HTTP overview HTTP: hypertext transfer protocol HT TP r equ Web’s application layer PC running HT TP est protocol Explorer res pon se client/server model  client: browser that st ue requests, receives, eq TPr on se Server “displays” Web objects HT res p running TP Apache Web  server: Web server HT server sends objects in response to requests Mac running Navigator 2: Application Layer 22
  • 23. 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 23
  • 24. 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 24
  • 25. 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 25
  • 26. 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 26
  • 27. 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 27
  • 28. 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 28
  • 29. 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 29
  • 30. HTTP request message: general format Post and head 2: Application Layer 30
  • 31. 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 31
  • 32. 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 32
  • 33. 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 33
  • 34. 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 34
  • 35. 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 35
  • 36. 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 36
  • 37. 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 37
  • 38. Cookies (continued) aside What cookies can bring: Cookies and privacy: authorization cookies permit sites to shopping carts learn a lot about you recommendations you may supply name 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 38
  • 39. 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 reque HT ues TP e client TP t HT on s HTTP requests to res esp pon TPr se HT cache ue st eq se  object in cache: cache T Pr on HT sp returns object P re HTT  else cache requests object from origin client origin server, then returns server object to client 2: Application Layer 39
  • 40. 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 40
  • 41. 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 41
  • 42. 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 42
  • 43. 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 43
  • 44. 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 44
  • 45. 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.9 Building a Web 2.5 DNS server 2: Application Layer 45
  • 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 46
  • 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 file) to client FTP server maintains “state”: current directory, earlier after transferring one file, authentication server closes data connection. 2: Application Layer 47
  • 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 48
  • 49. 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 49
  • 50. Electronic Mail outgoing message queue user mailbox user Three major components: agent user agents mail user server mail servers agent simple mail transfer SMTP mail protocol: SMTP server user SMTP agent User Agent a.k.a. “mail reader” SMTP mail user composing, editing, reading server agent 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 (header & body) to be in 7- SMTP: push bit ASCII both have ASCII SMTP server uses command/response CRLF.CRLF to determine interaction, status codes end of message HTTP: each object encapsulated in its own response msg SMTP: multiple objects sent in multipart msg 2: Application Layer 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. Message format: multimedia extensions MIME: multimedia mail extension, RFC 2045, 2056 additional lines in msg header declare MIME content type From: alice@crepes.fr MIME version To: bob@hamburger.edu Subject: Picture of yummy crepe. method used MIME-Version: 1.0 to encode data Content-Transfer-Encoding: base64 Content-Type: image/jpeg multimedia data type, subtype, base64 encoded data ..... parameter declaration ......................... ......base64 encoded data encoded data 2: Application Layer 58
  • 59. 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 59
  • 60. 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 60
  • 61. POP3 (more) and IMAP More about POP3 IMAP Previous example uses Keep all messages in “download and delete” one place: the server mode. Allows user to Bob cannot re-read e- organize messages in mail if he changes folders client IMAP keeps user state “Download-and-keep”: across sessions: copies of messages on  names of folders and different clients mappings between message IDs and folder POP3 is stateless name across sessions 2: Application Layer 61
  • 62. 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.9 Building a Web 2.5 DNS server 2: Application Layer 62
  • 63. 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 63
  • 64. 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 64
  • 65. 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 65
  • 66. 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 66
  • 67. 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 67
  • 68. 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 68
  • 69. 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 7 6 replies with name of 1 8 server to contact authoritative DNS server “I don’t know this dns.cs.umass.edu name, but ask this requesting host server” cis.poly.edu gaia.cs.umass.edu 2: Application Layer 69
  • 70. DNS name resolution example root DNS server recursive query: 2 3 puts burden of name 6 7 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 70
  • 71. 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 71
  • 72. DNS records DNS: distributed db storing resource records (RR) RR format: (name, value, type, ttl) Type=A Type=CNAME  name is hostname  name is alias name for some  value is IP address “canonical” (the real) name www.ibm.com is really Type=NS servereast.backup2.ibm.com  name is domain (e.g.  value is canonical name foo.com)  value is hostname of Type=MX authoritative name  value is name of mailserver server for this domain associated with name 2: Application Layer 72
  • 73. 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 73
  • 74. 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 74
  • 75. 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 75
  • 76. Chapter 2: Application layer 2.1 Principles of 2.6 P2P applications network applications 2.7 Socket programming  app architectures with TCP app requirements 2.8 Socket programming  2.2 Web and HTTP with UDP 2.4 Electronic Mail  SMTP, POP3, IMAP 2.5 DNS 2: Application Layer 76
  • 77. 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 2: Application Layer 77
  • 78. 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 78
  • 79. 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 = max { NF/us, F/min(di) } = dcs i client/server approach increases linearly in N (for large N) 2: Application Layer 79
  • 80. 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 dN Network (with to download abundant bandwidth) uN NF bits must be downloaded (aggregate) fastest possible upload rate: us + Σui dP2P = max { F/us, F/min(di) , NF/(us + Σui) } i 2: Application Layer 80
  • 81. 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 81
  • 82. 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 82
  • 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 83
  • 84. BitTorrent (2) Sending Chunks: tit-for-tat Pulling Chunks Alice sends chunks to four 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 (Alice) asks each every 30 secs: randomly neighbor for list of select another peer, chunks that they have. starts sending chunks  newly chosen peer may Alice sends requests for her missing chunks join top 4  “optimistically unchoke”  rarest first 2: Application Layer 84
  • 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 85
  • 86. P2P: searching for information Index in P2P system: maps information to peer location (location = IP address & port number) . Instant messaging File sharing (eg e-mule) Index dynamically Index maps user tracks the locations of names to locations. files that peers share. When user starts IM Peers need to tell application, it needs to index what they have. inform index of its Peers search index to location determine where files Peers search index to can be found determine IP address of user. 2: Application Layer 86
  • 87. P2P: centralized index Bob original “Napster” design centralized 1) when peer connects, it directory server 1 informs central server: peers  IP address 1  content 1 3 2) Alice queries for “Hey 2 Jude” 1 3) Alice requests file from Bob Alice 2: Application Layer 87
  • 88. P2P: problems with centralized directory single point of failure file transfer is performance bottleneck decentralized, but locating content is copyright infringement: highly centralized “target” of lawsuit is obvious 2: Application Layer 88
  • 89. Query flooding fully distributed overlay network: graph  no central server edge between peer X used by Gnutella and Y if there’s a TCP Each peer indexes the connection files it makes available all active peers and for sharing (and no edges form overlay other files) net edge: virtual (not physical) link given peer typically connected with < 10 overlay neighbors 2: Application Layer 89
  • 90. Query flooding File transfer: Query message HTTP sent over existing TCP connections Query peers forward QueryHit Query message y Qu QueryHit er ery Qu Hi t sent over er y Qu reverse Query path QueryHit Scalability: Qu er y limited scope flooding 2: Application Layer 90
  • 91. Gnutella: Peer joining 1. joining peer Alice must find another peer in Gnutella network: use list of candidate peers 2. Alice sequentially attempts TCP connections with candidate peers until connection setup with Bob 3. Flooding: Alice sends Ping message to Bob; Bob forwards Ping message to his overlay neighbors (who then forward to their neighbors….) peers receiving Ping message respond to Alice with Pong message 1. Alice receives many Pong messages, and can then setup additional TCP connections Peer leaving: see homework problem! 2: Application Layer 91
  • 92. Hierarchical Overlay between centralized index, query flooding approaches each peer is either a super node or assigned to a super node  TCP connection between peer and its super node.  TCP connections between some pairs of super nodes. o r d in a r y p e e r Super node tracks g r o u p - le a d e r p e e r content in its children n e ig h o r in g r e la tio n s h ip s in o v e r la y n e tw o r k 2: Application Layer 92
  • 93. 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 93
  • 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 94
  • 95. 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 95
  • 96. Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API socket introduced in BSD4.1 UNIX, a host-local, 1981 application-created, explicitly created, used, OS-controlled interface released by apps (a “door”) into which client/server paradigm application process can two types of transport both send and service via socket API: receive messages to/from  unreliable datagram another application process  reliable, byte stream- oriented 2: Application Layer 96
  • 97. Socket-programming using TCP Socket: a door between application process and end- end-transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another controlled by controlled by process application application process developer developer socket socket TCP with TCP with controlled by controlled by buffers, operating operating buffers, internet system system variables variables host or host or server server 2: Application Layer 97
  • 98. Socket programming with TCP Client must contact server When contacted by client, server process must first server TCP creates new be running socket for server process to server must have created communicate with client socket (door) that  allows server to talk with welcomes client’s contact multiple clients  source port numbers Client contacts server by: used to distinguish creating client-local TCP clients (more in Chap 3) socket specifying IP address, port application viewpoint number of server process TCP provides reliable, in-order When client creates transfer of bytes (“pipe”) socket: client TCP between client and server establishes connection to server TCP 2: Application Layer 98
  • 99. Client/server socket interaction: TCP Server (running on hostid) Client create socket, port=x, for incoming request: welcomeSocket = ServerSocket() TCP create socket, wait for incoming connection request connection setup connect to hostid, port=x connectionSocket = clientSocket = welcomeSocket.accept() Socket() send request using read request from clientSocket connectionSocket write reply to connectionSocket read reply from clientSocket close connectionSocket close clientSocket 2: Application Layer 99
  • 100. Stream jargon keyboard monitor A stream is a sequence of characters that flow into or out of a process. inFromUser input stream An input stream is Client attached to some input Process process source for the process, e.g., keyboard or socket. An output stream is attached to an output inFromServer outToServer output input source, e.g., monitor or stream stream socket. client TCP clientSocket socket TCP socket to network from network 2: Application Layer 100
  • 101. Socket programming with TCP Example client-server app: 1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (inFromServer stream) 2: Application Layer 101
  • 102. Example: Java client (TCP) import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; Create input stream BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Create client socket, Socket clientSocket = new Socket("hostname", 6789); connect to server Create DataOutputStream outToServer = output stream new DataOutputStream(clientSocket.getOutputStream()); attached to socket 2: Application Layer 102
  • 103. Example: Java client (TCP), cont. Create BufferedReader inFromServer = input stream new BufferedReader(new attached to socket InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); Send line to server outToServer.writeBytes(sentence + 'n'); Read line modifiedSentence = inFromServer.readLine(); from server System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); } } 2: Application Layer 103
  • 104. Example: Java server (TCP) import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; Create String capitalizedSentence; welcoming socket ServerSocket welcomeSocket = new ServerSocket(6789); at port 6789 while(true) { Wait, on welcoming socket for contact Socket connectionSocket = welcomeSocket.accept(); by client BufferedReader inFromClient = Create input new BufferedReader(new stream, attached InputStreamReader(connectionSocket.getInputStream())); to socket 2: Application Layer 104
  • 105. Example: Java server (TCP), cont Create output stream, attached DataOutputStream outToClient = to socket new DataOutputStream(connectionSocket.getOutputStream()); Read in line from socket clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + 'n'; Write out line outToClient.writeBytes(capitalizedSentence); to socket } } } End of while loop, loop back and wait for another client connection 2: Application Layer 105
  • 106. 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 106
  • 107. Socket programming with UDP UDP: no “connection” between client and server no handshaking sender explicitly attaches application viewpoint IP address and port of destination to each packet UDP provides unreliable transfer of groups of bytes (“datagrams”) server must extract IP between client and server address, port of sender from received packet UDP: transmitted data may be received out of order, or lost 2: Application Layer 107
  • 108. Client/server socket interaction: UDP Server (running on hostid) Client create socket, create socket, port= x. clientSocket = serverSocket = DatagramSocket() DatagramSocket() Create datagram with server IP and port=x; send datagram via read datagram from clientSocket serverSocket write reply to serverSocket specifying read datagram from client address, clientSocket port number close clientSocket 2: Application Layer 108
  • 109. Example: Java client (UDP) keyboard monitor inFromUser input stream Client Process Input: receives process packet (recall Output: sends thatTCP received packet (recall “byte stream”) receivePacket sendPacket that TCP sent UDP packet UDP packet “byte stream”) client UDP clientSocket socket UDP socket to network from network 2: Application Layer 109
  • 110. Example: Java client (UDP) import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { Create input stream BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Create client socket DatagramSocket clientSocket = new DatagramSocket(); Translate InetAddress IPAddress = InetAddress.getByName("hostname"); hostname to IP address using DNS byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); 2: Application Layer 110
  • 111. Example: Java client (UDP), cont. Create datagram with data-to-send, DatagramPacket sendPacket = length, IP addr, port new DatagramPacket(sendData, sendData.length, IPAddress, 9876); Send datagram clientSocket.send(sendPacket); to server DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); Read datagram clientSocket.receive(receivePacket); from server String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } } 2: Application Layer 111
  • 112. Example: Java server (UDP) import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception Create { datagram socket DatagramSocket serverSocket = new DatagramSocket(9876); at port 9876 byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { Create space for DatagramPacket receivePacket = received datagram new DatagramPacket(receiveData, receiveData.length); Receive serverSocket.receive(receivePacket); datagram 2: Application Layer 112
  • 113. Example: Java server (UDP), cont String sentence = new String(receivePacket.getData()); Get IP addr InetAddress IPAddress = receivePacket.getAddress(); port #, of sender int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); Create datagram DatagramPacket sendPacket = to send to client new DatagramPacket(sendData, sendData.length, IPAddress, port); Write out datagram serverSocket.send(sendPacket); to socket } } } End of while loop, loop back and wait for another datagram 2: Application Layer 113
  • 114. Chapter 2: Summary our study of network apps now complete! application architectures specific protocols:  HTTP  client-server  FTP  P2P  SMTP, POP, IMAP  hybrid  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 114
  • 115. 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 communicated “complexity at network edge” 2: Application Layer 115