lect 8 applaction layer

Upload: amrit-bagga

Post on 13-Feb-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/23/2019 Lect 8 Applaction Layer

    1/112

    Application Layer

    Application Layer2-1

  • 7/23/2019 Lect 8 Applaction Layer

    2/112

    Chapter 2: outline

    2.1 principles of networkapplications

    2.2 Web and HTTP

    2.3 FTP

    2.6 P2P applications

    2.7 socket programmingwith UDP and TCP

    Application Layer2-2

    . e ectron c ma SMTP, POP3, IMAP

    2.5 DNS

  • 7/23/2019 Lect 8 Applaction Layer

    3/112

    Chapter 2: application layer

    our goals: conceptual,

    implementation aspectsof network applicationprotocols

    transport-layer

    learn about protocols byexamining popularapplication-levelprotocols HTTP

    FTP

    Application Layer2-3

    service models

    client-serverparadigm

    peer-to-peerparadigm

    SMTP / POP3 / IMAP

    DNS

    creating networkapplications

    socket API

  • 7/23/2019 Lect 8 Applaction Layer

    4/112

    Some network apps

    e-mail

    web

    text messaging

    remote login

    P2P file sharin

    voice over IP (e.g., Skype)

    real-time videoconferencing

    social networking

    search

    Application Layer2-4

    multi-user network games

    streaming stored video(YouTube, Hulu, Netflix)

  • 7/23/2019 Lect 8 Applaction Layer

    5/112

    Creating a network app

    write programs that:

    run on (different) end systems communicate over network

    e.g., web server softwarecommunicates with browser

    software

    application

    transport

    network

    data link

    physical

    Application Layer2-5

    no need to write software fornetwork-core devices

    network-core devices do not

    run user applications applications on end systems

    allows for rapid appdevelopment, propagation

    application

    transport

    network

    data link

    physical

    application

    transport

    network

    data link

    physical

  • 7/23/2019 Lect 8 Applaction Layer

    6/112

    Application architectures

    possible structure of applications:

    client-server

    peer-to-peer (P2P)

    Application Layer2-6

  • 7/23/2019 Lect 8 Applaction Layer

    7/112

    Client-server architecture

    server: always-on host

    permanent IP address

    data centers for scaling

    Application Layer2-7

    communicate with server

    may be intermittentlyconnected

    may have dynamic IPaddresses

    do not communicate directlywith each other

    client/server

  • 7/23/2019 Lect 8 Applaction Layer

    8/112

    P2P architecture

    no always-on server arbitrary end systems

    directly communicate

    peers request service fromother peers, provide service

    in return to other peers

    peer-peer

    Application Layer2-8

    self scalability newpeers bring new servicecapacity, as well as newservice demands

    peers are intermittentlyconnected and change IPaddresses

    complex management

  • 7/23/2019 Lect 8 Applaction Layer

    9/112

    Processes communicating

    process: program runningwithin a host

    within same host, twoprocesses communicate

    using inter-process

    client process: process thatinitiates communication

    server process: process thatwaits to be contacted

    clients, servers

    Application Layer2-9

    OS)

    processes in different hostscommunicate by exchanging

    messages

    aside: applications with P2P

    architectures have clientprocesses & serverprocesses

  • 7/23/2019 Lect 8 Applaction Layer

    10/112

    Sockets

    process sends/receives messages to/from its socket

    socket analogous to door

    sending process showes message out door

    sending process relies on transport infrastructure onother side of door to deliver message to socket at

    receiving process

    Application Layer2-10

    Internet

    controlled

    by OS

    controlled byapp developer

    transport

    application

    physical

    link

    network

    process

    transport

    application

    physical

    link

    network

    processsocket

  • 7/23/2019 Lect 8 Applaction Layer

    11/112

    Addressing processes

    to receive messages,process must have identifier

    host device has unique 32-bit IP address

    Q: does IP address of host

    on which process runs

    identifierincludes both IPaddress and port numbersassociated with process onhost.

    example port numbers:

    HTTP server: 80

    Application Layer2-11

    suffice for identifying theprocess?

    mail server: 25

    to send HTTP message togaia.cs.umass.edu webserver:

    IP address: 128.119.245.12 port number: 80

    more shortly

    A: no, manyprocessescan be running on same

    host

  • 7/23/2019 Lect 8 Applaction Layer

    12/112

    App-layer protocol defines

    types of messagesexchanged,

    e.g., request, response

    message syntax:

    what fields in messages

    open protocols: defined in RFCs

    allows for interoperability

    e.g., HTTP, SMTP

    proprietary protocols:

    Application Layer2-12

    delineated

    message semantics

    meaning of information

    in fields rules for when and how

    processes send & respondto messages

    e.g., ype

  • 7/23/2019 Lect 8 Applaction Layer

    13/112

    What transport service does an app need?

    data integrity

    some apps (e.g., file transfer,web transactions) require

    100% reliable data transfer

    other apps (e.g., audio) can

    tolerate some loss

    throughput

    some apps (e.g.,multimedia) requireminimum amount ofthroughput to beeffective

    Application Layer2-13

    timing

    some apps (e.g., Internettelephony, interactivegames) require low delayto be effective

    make use of whateverthroughput they get

    security encryption, data integrity,

  • 7/23/2019 Lect 8 Applaction Layer

    14/112

    Transport service requirements: common apps

    application

    file transfer

    e-mail

    Web documents

    data loss

    no loss

    no loss

    no loss

    throughput

    elastic

    elastic

    elastic

    time sensitive

    no

    no

    no

    Application Layer2-14

    rea - me au o v eo

    stored audio/video

    interactive games

    text messaging

    oss- o eran

    loss-tolerant

    loss-tolerant

    no loss

    au o: ps- ps

    video:10kbps-5Mbps

    same as above

    few kbps up

    elastic

    yes, s

    msec

    yes, few secs

    yes, 100s

    msec

    yes and no

  • 7/23/2019 Lect 8 Applaction Layer

    15/112

    Internet transport protocols services

    TCP service: reliable transport between

    sending and receivingprocess

    flow control: sender wont

    overwhelm receiver

    UDP service: unreliable data transfer

    between sending andreceiving process

    does not provide:

    Application Layer2-15

    congestion control: throttle

    sender when networkoverloaded

    does not provide: timing,

    minimum throughputguarantee, security connection-oriented: setup

    required between client andserver processes

    , ,congestion control,timing, throughputguarantee, security,orconnection setup,

    Q: why bother? Why isthere a UDP?

  • 7/23/2019 Lect 8 Applaction Layer

    16/112

    Internet apps: application, transport protocols

    application

    e-mail

    remote terminal access

    Web

    applicationlayer protocol

    SMTP [RFC 2821]

    Telnet [RFC 854]

    HTTP [RFC 2616]

    underlyingtransport protocol

    TCP

    TCP

    TCP

    Application Layer2-16

    e rans er

    streaming multimedia

    Internet telephony

    HTTP (e.g., YouTube),

    RTP [RFC 1889]

    SIP, RTP, proprietary

    (e.g., Skype)

    TCP or UDP

    TCP or UDP

  • 7/23/2019 Lect 8 Applaction Layer

    17/112

    Securing TCP

    TCP & UDP

    no encryption

    cleartext passwds sentinto socket traverse

    SSL is at app layer

    Apps use SSL libraries,which talk to TCP

    SSL socket API

    SSL

    provides encrypted

    TCP connection data integrity

    end-pointauthentication

    c eartext passw s sentinto socket traverseInternet encrypted

    See Chapter 7

    Application Layer2-17

  • 7/23/2019 Lect 8 Applaction Layer

    18/112

    Chapter 2: outline

    2.1 principles of networkapplications app architectures

    app requirements

    2.6 P2P applications

    2.7 socket programmingwith UDP and TCP

    Application Layer2-18

    .2.3 FTP

    2.4 electronic mail SMTP, POP3, IMAP

    2.5 DNS

  • 7/23/2019 Lect 8 Applaction Layer

    19/112

    Web and HTTP

    First, a review web page consists of objects

    object can be HTML file, JPEG image, Java applet,audio file,

    web a e consists of base HTML- ile which

    Application Layer2-19

    includes several referenced objects

    each object is addressable by a URL, e.g.,

    www.someschool.edu/someDept/pic.gif

    host name path name

  • 7/23/2019 Lect 8 Applaction Layer

    20/112

    HTTP overview

    HTTP: hypertexttransfer protocol Webs application layer

    protocol client/server model

    client: browser that

    PC running

    Firefox browser

    Application Layer2-20

    requests, receives,(using HTTP protocol)and displays Webobjects

    server: Web serversends (using HTTPprotocol) objects inresponse to requests

    server

    running

    Apache Web

    server

    iphone running

    Safari browser

  • 7/23/2019 Lect 8 Applaction Layer

    21/112

    HTTP overview (continued)

    uses TCP: client initiates TCP

    connection (createssocket) to server, port 80

    server accepts TCP

    HTTP is stateless server maintains no

    information aboutpast client requests

    Application Layer2-21

    HTTP messages(application-layer protocolmessages) exchanged

    between browser (HTTPclient) and Web server(HTTP server)

    TCP connection closed

    protocols that maintainstate are complex!

    past history (state) must bemaintained

    if server/client crashes, theirviews of state may beinconsistent, must bereconciled

  • 7/23/2019 Lect 8 Applaction Layer

    22/112

    HTTP connections

    non-persistent HTTP

    at most one objectsent over TCPconnection

    persistent HTTP

    multiple objects canbe sent over singleTCP connection

    Application Layer2-22

    closed

    downloading multipleobjects required

    multiple connections

    ,

  • 7/23/2019 Lect 8 Applaction Layer

    23/112

    Non-persistent HTTPsuppose user enters URL:

    1a. HTTP client initiates TCPconnection to HTTP server(process) atwww.someSchool.edu on port

    80

    1b. HTTP server at hostwww.someSchool.edu waiting

    for TCP connection at ort 80.

    (contains text,

    references to 10jpeg images)www.someSchool.edu/someDepartment/home.index

    Application Layer2-23

    2. HTTP client sends HTTP requestmessage (containing URL) intoTCP connection socket.

    Message indicates that clientwants objectsomeDepartment/home.index

    accepts connection, notifyingclient

    3. HTTP server receives request

    message, forms responsemessage containing requestedobject, and sends message intoits socket

    time

  • 7/23/2019 Lect 8 Applaction Layer

    24/112

    Non-persistent HTTP (cont.)

    5. HTTP client receives responsemessage containing html file,displays html. Parsing html file,finds 10 referenced jpeg objects

    4. HTTP server closes TCPconnection.

    Application Layer2-24

    6. Steps 1-5 repeated for each of10 jpeg objects

    time

    N i t t HTTP ti

  • 7/23/2019 Lect 8 Applaction Layer

    25/112

    Non-persistent HTTP: response time

    RTT (definition): time for a

    small packet to travel fromclient to server and back

    HTTP response time:

    one RTT to initiate TCP

    connection

    initiate TCPconnection

    RTT

    Application Layer2-25

    one or requestand first few bytes of HTTPresponse to return

    file transmission time

    non-persistent HTTPresponse time =

    2RTT+ file transmissiontime

    time totransmitfile

    file

    RTT

    filereceived

    time time

  • 7/23/2019 Lect 8 Applaction Layer

    26/112

    Persistent HTTP

    non-persistent HTTP issues: requires 2 RTTs per object

    OS overhead for each TCPconnection

    browsers often open

    persistent HTTP: server leaves connection

    open after sendingresponse

    subsequent HTTP

    Application Layer2-26

    to fetch referenced objects

    client/server sent overopen connection

    client sends requests assoon as it encounters areferenced object

    as little as one RTT for allthe referenced objects

  • 7/23/2019 Lect 8 Applaction Layer

    27/112

    HTTP request message

    two types of HTTP messages: request, response HTTP request message:

    ASCII (human-readable format)

    request line

    carriage return character

    line-feed character

    Application Layer2-27

    (GET, POST,

    HEAD commands)

    header

    lines

    carriage return,

    line feed at start

    of line indicates

    end of header lines

    GET /index.html HTTP/1.1\r\nHost: www-net.cs.umass.edu\r\nUser-Agent: Firefox/3.6.10\r\nAccept: text/html,application/xhtml+xml\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7\r\nKeep-Alive: 115\r\nConnection: keep-alive\r\n\r\n

  • 7/23/2019 Lect 8 Applaction Layer

    28/112

    HTTP request message: general format

    requestline

    headerlines

    method sp sp cr lfversionURL

    cr lfvalueheader field name

    ~~ ~~

    Application Layer2-28

    body

    cr lfvalueheader field name

    cr lf

    entity body~~ ~~

  • 7/23/2019 Lect 8 Applaction Layer

    29/112

    Uploading form input

    POST method: web page often includes

    form input

    input is uploaded toserver in entity body

    Application Layer2-29

    URL method: uses GET method

    input is uploaded in URLfield of request line:

    www.somesite.com/animalsearch?monkeys&banana

  • 7/23/2019 Lect 8 Applaction Layer

    30/112

    Method types

    HTTP/1.0: GET

    POST

    HEAD

    HTTP/1.1: GET, POST, HEAD

    PUT

    uploads file in entity

    bod to ath s ecified

    Application Layer2-30

    requested object outof response

    in URL field

    DELETE

    deletes file specified inthe URL field

    HTTP

  • 7/23/2019 Lect 8 Applaction Layer

    31/112

    HTTP response message

    status line(protocol

    status code

    status phrase)

    HTTP/1.1 200 OK\r\nDate: Sun, 26 Sep 2010 20:09:20 GMT\r\nServer: Apache/2.0.52 (CentOS)\r\nLast-Modified: Tue, 30 Oct 2007 17:00:02

    GMT\r\n" "

    Application Layer2-31

    ea er

    lines

    data, e.g.,

    requested

    HTML file

    - -Accept-Ranges: bytes\r\nContent-Length: 2652\r\nKeep-Alive: timeout=10, max=100\r\nConnection: Keep-Alive\r\nContent-Type: text/html; charset=ISO-8859-

    1\r\n\r\ndata data data data data ...

    HTTP d

  • 7/23/2019 Lect 8 Applaction Layer

    32/112

    HTTP response status codes

    200 OK

    request succeeded, requested object later in this msg

    status code appears in 1st line in server-to-

    client response message.

    some sample codes:

    Application Layer2-32

    ove ermanen y

    requested object moved, new location specified later in this msg(Location:)

    400 Bad Request

    request msg not understood by server404 Not Found

    requested document not found on this server

    505 HTTP Version Not Supported

    T HTTP ( l d ) f lf

  • 7/23/2019 Lect 8 Applaction Layer

    33/112

    Trying out HTTP (client side) for yourself

    1. Telnet to your favorite Web server:

    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

    telnet cis.poly.edu 80

    Application Layer2-33

    2. type in a GET HTTP request:

    GET /~ross/ HTTP/1.1

    Host: cis.poly.edu

    by typing this in (hit carriage

    return twice), you send

    this minimal (but complete)GET request to HTTP server

    3. look at response message sent by HTTP server!

    (or use Wireshark to look at captured HTTP request/response)

  • 7/23/2019 Lect 8 Applaction Layer

    34/112

    User-server state: cookies

    many Web sites use cookiesfour components:

    1) cookie header line ofHTTP response

    message

    example: Susan always access Internet

    from PC

    visits specific e-commercesite for first time

    Application Layer2-34

    2) cookie header line innext HTTP requestmessage

    3) cookie file kept onusers host, managedby users browser

    4) back-end database atWeb site

    arrives at site, site creates:

    unique ID

    entry in backenddatabase for ID

    Cookies: keeping state (cont )

  • 7/23/2019 Lect 8 Applaction Layer

    35/112

    Cookies: keeping state (cont.)

    client server

    cookie file

    ebay 8734usual http request msg Amazon server

    creates ID

    1678 for user createentry

    usual http responseset-cookie: 1678

    ebay 8734

    backend

    database

    Application Layer2-35

    usual http response msg

    usual http response msg

    one week later:

    usual http request msgcookie: 1678 cookie-

    specific

    action

    access

    usual http request msgcookie: 1678 cookie-

    specific

    action

    access

    ebay 8734

    amazon 1678

    C ki ( ti d)

  • 7/23/2019 Lect 8 Applaction Layer

    36/112

    Cookies (continued)

    what cookies can be usedfor: authorization shopping carts recommendations

    user session state Web

    cookies and privacy: cookies permit sites to

    learn a lot about you

    you may supply name ande-mail to sites

    aside

    Application Layer2-36

    e-mail)

    how to keep state: protocol endpoints: maintain state at

    sender/receiver over multipletransactions

    cookies: http messages carry state

    W b h ( )

  • 7/23/2019 Lect 8 Applaction Layer

    37/112

    Web caches (proxy server)

    user sets browser: Webaccesses via cache

    browser sends all HTTPrequests to cache

    goal: satisfy client request without involving origin server

    proxy

    server

    Application Layer2-37

    o ject in cac e: cac ereturns object

    else cache requestsobject from origin

    server, then returnsobject to client

    client

    client origin

    server

    origin

    server

    M b t W b hi

  • 7/23/2019 Lect 8 Applaction Layer

    38/112

    More about Web caching

    cache acts as bothclient and server server for original

    requesting client

    client to origin server

    why Web caching? reduce response time

    for client request

    reduce traffic on an

    Application Layer2-38

    typ ca y cac e sinstalled by ISP(university, company,residential ISP)

    Internet dense with

    caches: enables poorcontent providers to

    effectively delivercontent (so too doesP2P file sharing)

    Caching example:

  • 7/23/2019 Lect 8 Applaction Layer

    39/112

    Caching example:

    origin

    serverspublic

    Internet

    assumptions: avg object size: 100K bits

    avg request rate from browsers toorigin servers:15/sec

    avg data rate to browsers: 1.50 Mbps

    RTT from institutional router to any

    Application Layer2-39

    institutional

    network1 Gbps LAN

    1.54 Mbps

    access link

    access link rate: 1.54 Mbps

    consequences: LAN utilization: 15%

    access link utilization = 99% total delay = Internet delay + access

    delay + LAN delay

    = 2 sec + minutes + usecs

    problem!

    Caching example: fatter access link

  • 7/23/2019 Lect 8 Applaction Layer

    40/112

    assumptions: avg object size: 100K bits

    avg request rate from browsers toorigin servers:15/sec

    avg data rate to browsers: 1.50 Mbps

    RTT from institutional router to any

    Caching example: fatter access link

    origin

    serverspublic

    Internet

    Application Layer2-40

    access link rate: 1.54 Mbps

    consequences: LAN utilization: 15%

    access link utilization = 99%

    total delay = Internet delay + accessdelay + LAN delay

    = 2 sec + minutes + usecs

    1.54 Mbps

    access link154 Mbps 154 Mbps

    msecs

    Cost: increased access link speed (not cheap!)

    9.9%

    institutional

    network1 Gbps LAN

    Caching example: install local cache

  • 7/23/2019 Lect 8 Applaction Layer

    41/112

    Caching example: install local cache

    origin

    servers

    assumptions: avg object size: 100K bits

    avg request rate from browsers toorigin servers:15/sec

    avg data rate to browsers: 1.50 Mbps

    RTT from institutional router to any

    public

    Internet

    institutional

    network1 Gbps LAN

    Application Layer2-41

    1.54 Mbps

    access link

    local webcache

    access link rate: 1.54 Mbps

    consequences: LAN utilization: 15%

    access link utilization = 100%

    total delay = Internet delay + accessdelay + LAN delay

    = 2 sec + minutes + usecs

    ??

    How to compute linkutilization, delay?

    Cost: web cache (cheap!)

    Caching example: install local cache

  • 7/23/2019 Lect 8 Applaction Layer

    42/112

    Caching example: install local cache

    Calculating access linkutilization, delay with cache:

    suppose cache hit rate is 0.4 40% requests satisfied at cache,

    60% requests satisfied at origin

    origin

    servers

    access link utilization:

    public

    Internet

    Application Layer2-42

    1.54 Mbps

    access link

    60% of requests use access link data rate to browsers over access link

    = 0.6*1.50 Mbps = .9 Mbps utilization = 0.9/1.54 = .58

    total delay = 0.6 * (delay from origin servers) +0.4

    * (delay when satisfied at cache) = 0.6 (2.01) + 0.4 (~msecs) 0.4(0.01 seconds) + 0.6 (2.01 seconds) = ~ 1.2 secs less than with 154 Mbps link (and

    cheaper too!)

    institutional

    network1 Gbps LAN

    local webcache

    Conditional GET

  • 7/23/2019 Lect 8 Applaction Layer

    43/112

    Conditional GET

    Goal: dont send object ifcache has up-to-datecached version no object transmission

    delay

    lower link utilization

    HTTP request msgIf-modified-since:

    HTTP response

    HTTP/1.0

    object

    not

    modified

    before

    client server

    Application Layer2-43

    cac e: spec y a e ocached copy in HTTPrequestIf-modified-since:

    server: response containsno object if cached copyis up-to-date:HTTP/1.0 304 NotModified

    304 Not Modified

    HTTP request msg

    If-modified-since:

    HTTP responseHTTP/1.0 200 OK

    objectmodified

    after

    Ch t 2 tli

  • 7/23/2019 Lect 8 Applaction Layer

    44/112

    Chapter 2: outline

    2.1 principles of networkapplications app architectures

    app requirements

    2.6 P2P applications2.7 socket programming

    with UDP and TCP

    Application Layer2-44

    .2.3 FTP

    2.4 electronic mail SMTP, POP3, IMAP

    2.5 DNS

    FTP: the file transfer protocol

  • 7/23/2019 Lect 8 Applaction Layer

    45/112

    FTP: the file transfer protocol

    file transfer

    FTPserver

    FTP

    userinterface

    FTPclient

    local file

    system

    remote file

    system

    user

    at host

    Application Layer2-45

    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

    FTP: separate control, data connections

  • 7/23/2019 Lect 8 Applaction Layer

    46/112

    FTP: separate control, data connections

    FTP client contacts FTP serverat port 21, using TCP

    client authorized over controlconnection

    client browses remote

    FTPclient

    FTPserver

    TCP control connection,

    server port 21

    TCP data connection,server port 20

    Application Layer2-46

    ,over control connection

    when server receives filetransfer command, serveropens 2ndTCP data

    connection (for file) to client after transferring one file,

    server closes data connection

    server opens another TCPdata connection to transferanother file

    control connection: out of

    band

    FTP server maintainsstate: current directory,earlier authentication

    FTP commands responses

  • 7/23/2019 Lect 8 Applaction Layer

    47/112

    FTP commands, responses

    sample commands: sent as ASCII text over

    control channel

    USER username

    PASS password

    sample return codes status code and phrase (as

    in HTTP)

    331 Username OK,password required

    125 data

    Application Layer2-47

    current directory

    RETR filenameretrieves (gets) file

    STOR filename stores(puts) file onto remotehost

    connectionalready open;transfer starting

    425 Cant open

    data connection 452 Error writingfile

    Chapter 2: outline

  • 7/23/2019 Lect 8 Applaction Layer

    48/112

    Chapter 2: outline

    2.1 principles of networkapplications app architectures

    app requirements

    2.6 P2P applications2.7 socket programming

    with UDP and TCP

    Application Layer2-48

    .2.3 FTP

    2.4 electronic mail SMTP, POP3, IMAP

    2.5 DNS

    Electronic mail outgoing

  • 7/23/2019 Lect 8 Applaction Layer

    49/112

    Electronic mail

    Three major components: user agents

    mail servers

    simple mail transferprotocol: SMTP

    user mailbox

    outgoing

    message queue

    mail

    mail

    server

    SMTP

    user

    agent

    user

    agent

    user

    Application Layer2-49

    User Agent a.k.a. mail reader

    composing, editing, reading

    mail messages e.g., Outlook, Thunderbird,

    iPhone mail client

    outgoing, incomingmessages stored on server

    mail

    server

    SMTP

    SMTP

    user

    agent

    user

    agent

    useragent

    Electronic mail: mail servers

  • 7/23/2019 Lect 8 Applaction Layer

    50/112

    Electronic mail: mail servers

    mail servers: mailboxcontains incomingmessages for user

    message queue of outgoing(to be sent) mail messages

    mail

    mail

    server

    SMTP

    user

    agent

    user

    agent

    user

    Application Layer2-50

    mail servers to send emailmessages

    client: sending mailserver

    server: receiving mailserver

    mail

    server

    SMTP

    SMTP

    user

    agent

    user

    agent

    useragent

    Electronic Mail: SMTP [RFC 2821]

  • 7/23/2019 Lect 8 Applaction Layer

    51/112

    Electronic Mail: SMTP [RFC 2821]

    uses TCP to reliably transfer email message fromclient to server, port 25

    direct transfer: sending server to receivingserver

    three phases of transfer

    Application Layer2-51

    handshaking (greeting) transfer of messages

    closure

    command/response interaction (like HTTP, FTP) commands: ASCII text response: status code and phrase

    messages must be in 7-bit ASCI

    Scenario: Alice sends message to Bob

  • 7/23/2019 Lect 8 Applaction Layer

    52/112

    g

    1) Alice uses UA to compose

    message [email protected]

    2) Alices UA sends messageto her mail server; messageplaced in message queue

    4) SMTP client sends Alices

    message over the TCPconnection

    5) Bobs mail server places themessage in Bobs mailbox

    6) Bob invokes his user agent

    to read messa e

    Application Layer2-52

    useragent

    TCP connection with Bobsmail server

    mail

    server

    mailserver

    1

    2 3 4

    5

    6

    Alices mail server Bobs mail server

    useragent

    Sample SMTP interaction

  • 7/23/2019 Lect 8 Applaction Layer

    53/112

    p

    S: 220 hamburger.edu

    C: HELO crepes.frS: 250 Hello crepes.fr, pleased to meet you

    C: MAIL FROM:

    S: 250 [email protected]... Sender ok

    C: RCPT TO:

    S: 250 [email protected] ... Recipient ok

    Application Layer2-53

    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

    Try SMTP interaction for yourself:

  • 7/23/2019 Lect 8 Applaction Layer

    54/112

    Try SMTP interaction for yourself:

    telnet servername 25 see 220 reply from server

    enter HELO, MAIL FROM, RCPT TO, DATA, QUITcommands

    Application Layer2-54

    above lets you send email without using email client (reader)

    SMTP: final words

  • 7/23/2019 Lect 8 Applaction Layer

    55/112

    SMTP: final words

    SMTP uses persistentconnections

    SMTP requires message(header & body) to be in7-bit ASCII

    comparison with HTTP: HTTP: pull

    SMTP: push

    both have ASCII

    Application Layer2-55

    CRLF.CRLF todetermine end of message

    comman responseinteraction, status codes

    HTTP: each objectencapsulated in its own

    response msg SMTP: multiple objects

    sent in multipart msg

    Mail message format

  • 7/23/2019 Lect 8 Applaction Layer

    56/112

    g

    SMTP: protocol forexchanging email msgs

    RFC 822: standard for textmessage format:

    header lines, e.g.,

    headerblank

    line

    Application Layer2-56

    To:

    From:

    Subject:

    different from SMTP MAILFROM, RCPT TO:commands!

    Body: the message ASCII characters only

    body

    Mail access protocols

  • 7/23/2019 Lect 8 Applaction Layer

    57/112

    p

    senders mailserver

    SMTP SMTPmail access

    protocol

    receivers mailserver

    (e.g., POP,IMAP)

    user

    agent

    user

    agent

    Application Layer2-57

    mail access protocol: retrieval from server

    POP: Post Office Protocol [RFC 1939]: authorization,download

    IMAP: Internet Mail Access Protocol [RFC 1730]: more

    features, including manipulation of stored msgs onserver

    HTTP: gmail, Hotmail, Yahoo! Mail, etc.

    POP3 protocol3 d

  • 7/23/2019 Lect 8 Applaction Layer

    58/112

    authorization phase client commands: user: declare username

    pass: password

    server responses

    +OK

    C: list

    S: 1 498

    S: 2 912

    S: +OK POP3 server ready

    C: user bob

    S: +OK

    C: pass hungryS: +OKuser successfully logged on

    Application Layer2-58

    -ERR

    transaction phase, client: list: list message numbers

    retr: retrieve message by

    number dele: delete

    quit

    .C: retr 1

    S:

    S: .

    C: dele 1

    C: retr 2

    S: S: .

    C: dele 2

    C: quit

    S: +OK POP3 server signing off

    POP3 (more) and IMAP

  • 7/23/2019 Lect 8 Applaction Layer

    59/112

    ( )

    more about POP3 previous example uses

    POP3 download anddelete mode

    Bob cannot re-read e-

    mail if he chan es

    IMAP keeps all messages in one

    place: at server

    allows user to organizemessages in folders

    Application Layer2-59

    client

    POP3 download-and-keep: copies of messageson different clients

    POP3 is stateless acrosssessions

    sessions:

    names of folders andmappings betweenmessage IDs and folder

    name

    Chapter 2: outline

  • 7/23/2019 Lect 8 Applaction Layer

    60/112

    C apte : out e

    2.1 principles of networkapplications app architectures

    app requirements

    2.6 P2P applications2.7 socket programming

    with UDP and TCP

    Application Layer2-60

    .2.3 FTP

    2.4 electronic mail SMTP, POP3, IMAP

    2.5 DNS

    DNS: domain name system

  • 7/23/2019 Lect 8 Applaction Layer

    61/112

    y

    people: many identifiers: SSN, name, passport #

    Internet hosts, routers:

    IP address (32 bit) -used for addressing

    Domain Name System: distributed database

    implemented in hierarchy ofmany name servers

    application-layer protocol: hosts,

    Application Layer2-61

    name, e.g.,www.yahoo.com -used by humans

    Q: how to map between IPaddress and name, andvice versa ?

    resolve names (address/nametranslation)

    note: core Internet function,implemented as application-

    layer protocol complexity at networks

    edge

    DNS: services, structure

  • 7/23/2019 Lect 8 Applaction Layer

    62/112

    why not centralize DNS? single point of failure traffic volume

    distant centralized database

    maintenance

    DNS services hostname to IP address

    translation

    host aliasing canonical, alias names

    mail server aliasin

    Application Layer2-62

    load distribution

    replicated Webservers: many IPaddresses correspond

    to one name

    A: doesnt scale!

    DNS: a distributed, hierarchical database

  • 7/23/2019 Lect 8 Applaction Layer

    63/112

    Root DNS Servers

    com DNS servers org DNS servers edu DNS servers

    poly.edu

    DNS servers

    umass.edu

    DNS serversyahoo.com

    amazon.com

    pbs.org

    DNS servers

    Application Layer2-63

    client wants IP for www.amazon.com; 1st approx:

    client queries root server to find com DNS server

    client queries .com DNS server to get amazon.com DNS server

    client queries amazon.com DNS server to get IP address forwww.amazon.com

    DNS: root name servers

  • 7/23/2019 Lect 8 Applaction Layer

    64/112

    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

    Application Layer2-64

    13 root nameserversworldwide

    a. Verisign, Los Angeles CA

    (5 other sites)

    b. USC-ISI Marina del Rey, CA

    l. ICANN Los Angeles, CA

    (41 other sites)

    e. NASA Mt View, CA

    f. Internet Software C.

    Palo Alto, CA (and 48 other

    sites)

    i. Netnod, Stockholm (37 other sites)

    k. RIPE London (17 other sites)

    m. WIDE Tokyo

    (5 other sites)

    c. Cogent, Herndon, VA (5 other sites)

    d. U Maryland College Park, MD

    h. ARL Aberdeen, MD

    j. Verisign, Dulles VA (69 other sites )

    g. US DoD Columbus,

    OH (5 other sites)

    TLD, authoritative servers

  • 7/23/2019 Lect 8 Applaction Layer

    65/112

    top-level domain (TLD) servers: responsible for com, org, net, edu, aero, jobs, museums,

    and all top-level country domains, e.g.: uk, fr, ca, jp

    Network Solutions maintains servers for .com TLD

    Educause for .edu TLD

    Application Layer2-65

    authoritative DNS servers:

    organizations own DNS server(s), providingauthoritative hostname to IP mappings for organizationsnamed hosts

    can be maintained by organization or service provider

    Local DNS name server

  • 7/23/2019 Lect 8 Applaction Layer

    66/112

    does not strictly belong to hierarchy each ISP (residential ISP, company, university) has

    one also called default name server

    Application Layer2-66

    ,local DNS server has local cache of recent name-to-address translation

    pairs (but may be out of date!)

    acts as proxy, forwards query into hierarchy

    root DNS serverDNS nameresolution example

  • 7/23/2019 Lect 8 Applaction Layer

    67/112

    local DNS server

    2

    3

    4

    5

    TLD DNS server

    resolution example

    host at cis.poly.eduwants IP address forgaia.cs.umass.edu

    Application Layer2-67

    requesting hostcis.poly.edu

    gaia.cs.umass.edu

    ns.po y.e u

    16

    authoritative DNS server

    dns.cs.umass.edu

    78

    contacted server

    replies with name ofserver to contact

    the remaining queries

    are iterative. I dont know this

    name, but ask thisserver

    root DNS serverDNS nameresolution example

  • 7/23/2019 Lect 8 Applaction Layer

    68/112

    6

    3

    recursive query: puts burden of name

    resolution oncontacted name local DNS server

    2

    7

    resolution example

    TLD DNSserver

    Application Layer2-68

    5server The query from the

    requesting host tothe local DNS server

    is recursive, and theremaining queriesare iterative.

    heavy load at upper

    levels of hierarchy?

    requesting hostcis.poly.edu

    gaia.cs.umass.edu

    ns.po y.e u

    1

    authoritative DNS server

    dns.cs.umass.edu

    8

    DNS caching

  • 7/23/2019 Lect 8 Applaction Layer

    69/112

    DNS caching in order to improve the delay performance and to reduce

    the number of DNS messages In a query chain, when a DNS server receives a DNS reply (containing,

    for example, a mapping from a hostname to an IP address), it can cache

    the mapping in its local memory.

    For example,in Figure 2.21, each time the local DNS server dns.poly.edu

    Application Layer2-69

    ,contained in the reply.

    If a hostname/IP address pair is cached in a DNS server and another

    query arrives to the DNS server for the same hostname, the DNS server

    can provide the desired IP address, even if it is not authoritative for the

    hostname. Because hosts and mappings between hostnames and IP addresses are

    by no means permanent, DNS servers discard cached information after a

    period of time (often set to two days).

    root DNS serverDNS caching

  • 7/23/2019 Lect 8 Applaction Layer

    70/112

    local DNS server

    2

    3

    4

    5

    TLD DNS server

    Application Layer2-70

    requesting hostcis.poly.edu

    gaia.cs.umass.edu

    ns.po y.e u

    16

    authoritative DNS server

    dns.cs.umass.edu

    78

    DNS: caching, updating records once (any) name server learns mapping it caches

  • 7/23/2019 Lect 8 Applaction Layer

    71/112

    once (any) name server learns mapping, it cachesmapping cache entries timeout (disappear) after some time (TTL)

    TLD servers typically cached in local name servers

    thus root name servers not often visited

    cached entries may be out-of-date (best effort

    Application Layer2-71

    name-to-a ress trans ation if name host changes IP address, may not be known

    Internet-wide until all TTLs expire

    update/notify mechanisms proposed IETF standard

    RFC 2136

    DNS records

  • 7/23/2019 Lect 8 Applaction Layer

    72/112

    DNS: distributed db storing resource records (RR)that provide hostname-to-IP address mappings. Each DNS reply message carries one or more

    resource records.

    RR format: (name, value, type, ttl)

    type=A name is hostname

    type=CNAME

    Application Layer2-72

    type=NS name is domain (e.g.,

    foo.com)

    value is hostname ofauthoritative nameserver for this domain

    (foo.com, dns.foo.com,NS)is a Type NS record.

    value is IP address canonical (the real) name

    www.ibm.comis really

    servereast.backup2.ibm.com

    value is canonical name

    type=MX value is name of mailserver

    associated with name

    DNS protocol, messages

  • 7/23/2019 Lect 8 Applaction Layer

    73/112

    queryand replymessages, both with same message

    format

    msg header

    identification:16 bit # forquery, reply to query uses

    identification flags

    # questions

    # answer RRs

    2 bytes 2 bytes

    Application Layer2-73

    same #

    flags:

    query or reply

    recursion desired

    recursion available reply is authoritative

    questions (variable # of questions)

    answers (variable # of RRs)

    authority (variable # of RRs)

    additional info (variable # of RRs)

    DNS protocol, messages

  • 7/23/2019 Lect 8 Applaction Layer

    74/112

    identification flags

    # questions

    # answer RRs

    2 bytes 2 bytes

    Application Layer2-74

    name, type fieldsfor a query

    RRs in responseto query

    records forauthoritative servers

    additional helpfulinfo that may be used

    questions (variable # of questions)

    answers (variable # of RRs)

    authority (variable # of RRs)

    additional info (variable # of RRs)

    Inserting records into DNS

  • 7/23/2019 Lect 8 Applaction Layer

    75/112

    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)

    Application Layer2-75

    reg s rar nser s wo s n o .com server:(networkutopia.com, dns1.networkutopia.com, NS)

    (dns1.networkutopia.com, 212.212.212.1, A)

    create authoritative server type A record forwww.networkuptopia.com; type MX record fornetworkutopia.com

    Attacking DNS

  • 7/23/2019 Lect 8 Applaction Layer

    76/112

    DDoS attacks Bombard root servers

    with traffic Not successful to date

    Redirect attacks Man-in-middle

    Intercept queries

    DNS poisoning

    Local DNS servers

    cache IPs of TLDservers, allowing rootserver bypass

    Bombard TLD servers Potentially more

    dangerous

    en ogus re es oDNS server, whichcaches

    Exploit DNS for DDoS

    Send queries withspoofed sourceaddress: target IP

    Requires amplificationApplication Layer2-76

    Chapter 2: outline

  • 7/23/2019 Lect 8 Applaction Layer

    77/112

    2.1 principles of networkapplications app architectures

    app requirements

    2.6 P2P applications2.7 socket programming

    with UDP and TCP

    Application Layer2-77

    .2.3 FTP

    2.4 electronic mail SMTP, POP3, IMAP

    2.5 DNS

    Pure P2P architecture

  • 7/23/2019 Lect 8 Applaction Layer

    78/112

    no always-on server

    arbitrary end systemsdirectly communicate

    peers are intermittentlyconnected and change IPaddresses

    Application Layer2-78

    examples: file distribution

    (BitTorrent)

    Streaming (KanKan)

    VoIP (Skype)

    File distribution: client-server vs P2P

    Q i h h i di ib fil ( i F) f

  • 7/23/2019 Lect 8 Applaction Layer

    79/112

    Question: how much time to distribute file (size F) from

    one server to N peers? peer upload/download capacity is limited resource

    us: server uploadcapacity

    Application Layer2-79

    us

    uN

    dN

    server

    network (with abundant

    bandwidth)

    file, size F

    ui: peer i uploadcapacity

    di: peer i downloadcapacityu2 d2

    u1 d1

    di

    ui

    File distribution time: client-server

  • 7/23/2019 Lect 8 Applaction Layer

    80/112

    Application Layer2-80

    File distribution time: client-server

    i i

  • 7/23/2019 Lect 8 Applaction Layer

    81/112

    server transmission: mustsequentially send (upload) Nfile copies: time to send one copy: F/us time to send N copies: NF/us

    client: client must download

    us

    network

    di

    ui

    F

    Application Layer2-81

    increases linearly in N

    time to distribute F

    to N clients usingclient-server approach

    Dc-s > max{NF/us,,F/dmin}

    file copy dmin = min client download rate

    min client download time: F/dmin

    The distribution time is the time it takes to

    get a copy of the file to all N peers.

    File distribution time: P2P

    t i i t

  • 7/23/2019 Lect 8 Applaction Layer

    82/112

    server transmission: mustupload at least one copy

    time to send one copy: F/usus

    network

    di

    ui

    F

    client: each client mustdownload file copy min client download time: F/dmin

    Application Layer2-82

    time to distribute F

    to N clients using

    P2P approach

    DP2P

    > max{F/us,,F/d

    min,,NF/(u

    s

    + Sui

    )}

    c ients: as aggregate must up oa its max upload rate (limting max download rate) is us + Sui

    but so does this, as each peer brings service capacity

    increases linearly in N

    File distribution time: P2Pwe first make the following observations

  • 7/23/2019 Lect 8 Applaction Layer

    83/112

    Application Layer2-83

    Client-server vs. P2P: example

    li t l d t F/ 1 h 10 d

  • 7/23/2019 Lect 8 Applaction Layer

    84/112

    2.5

    3

    3.5

    tionTime P2P

    Client-Server

    client upload rate = u, F/u = 1 hour, us = 10u, dmin us

    Application Layer2-84

    0

    0.5

    1

    1.5

    2

    0 5 10 15 20 25 30 35

    N

    MinimumD

    istribu

    P2P file distribution: BitTorrent

    file divided into 256Kb chunks

  • 7/23/2019 Lect 8 Applaction Layer

    85/112

    tracker: tracks peersparticipating in torrent

    torrent: group of peersexchanging chunks of a file

    file divided into 256Kb chunks

    peers in torrent send/receive file chunks

    Application Layer2-85

    Alice arrives

    obtains listof peers from tracker and begins exchanging

    file chunks with peers in torrent

    P2P file distribution: BitTorrent

  • 7/23/2019 Lect 8 Applaction Layer

    86/112

    peer joining torrent:

    has no chunks, but willaccumulate them over timefrom other peers

    registers with tracker to get

    Application Layer2-86

    subset of peers(neighbors)

    while downloading, peer uploads chunks to other peers

    peer may change peers with whom it exchanges chunks

    churn: peers may come and go once peer has entire file, it may (selfishly) leave or

    (altruistically) remain in torrent

    BitTorrent: requesting, sending file chunks

  • 7/23/2019 Lect 8 Applaction Layer

    87/112

    requesting chunks: at any given time, different

    peers have different subsetsof file chunks

    periodically, Alice asks each

    sending chunks: tit-for-tat Alice sends chunks to those

    four peers currently sending herchunks at highest rate other peers are choked by Alice

    do not receive chunks from her

    Application Layer2-87

    they have

    Alice requests missingchunks from peers, rarestfirst

    re-evaluate top 4 every10 secs

    every 30 secs: randomly selectanother peer, starts sendingchunks optimistically unchoke this peer

    newly chosen peer may join top 4

    Distributed Hash Table (DHT)

  • 7/23/2019 Lect 8 Applaction Layer

    88/112

    Hash table

    DHT paradigm

    rcu ar an over ay networ s

    Peer churn

    Simple database with(key value) pairs:

    Simple Database

  • 7/23/2019 Lect 8 Applaction Layer

    89/112

    Key Value

    John Washington 132-54-3570

    Simple database with(key, value) pairs:

    key: human name; value: social security #

    ana ou se ones - -Xiaoming Liu 385-41-0902

    Rakesh Gopal 441-89-1956

    Linda Cohen 217-66-5609

    .

    Lisa Kobayashi 177-23-0199

    key: movie title; value: IP address

    More convenient to store and search on

    Hash Table

  • 7/23/2019 Lect 8 Applaction Layer

    90/112

    Original Key Key Value

    John Washin ton 8 62458 132-54-3570

    More convenient to store and search on

    numerical representation of key key = hash(original key)

    Diana Louise Jones 7800356 761-55-3791

    Xiaoming Liu 1567109 385-41-0902

    Rakesh Gopal 2360012 441-89-1956

    Linda Cohen 5430938 217-66-5609

    . Lisa Kobayashi 9290124 177-23-0199

    Distribute (key, value) pairs over millions of peers

    Distributed Hash Table (DHT)

  • 7/23/2019 Lect 8 Applaction Layer

    91/112

    st bute ( ey, va ue) pa s ove o s o pee s

    pairs are evenly distributed over peers Any peer can query database with a key

    database returns value for the key

    To resolve query, small number of messages exchanged among

    Each peer only knows about a small number of otherpeers

    Robust to peers coming and going (churn)

    Assign key-value pairs to peers

    rule: assign key-value pair to the peer that has the

  • 7/23/2019 Lect 8 Applaction Layer

    92/112

    rule: assign key value pair to the peer that has the

    closest ID. convention: closest is the immediate successor of

    the key.

    e.g., ID space {0,1,2,3,,63}

    suppose 8 peers: 1,12,13,25,32,40,48,60 If key = 51, then assigned to peer 60

    If key = 60, then assigned to peer 60

    If key = 61, then assigned to peer 1

    Circular DHT

    each peer only aware of

  • 7/23/2019 Lect 8 Applaction Layer

    93/112

    1

    each peer onlyaware of

    immediate successor andpredecessor.

    12

    13

    25

    3240

    48

    60

    overlay network

    Resolving a query

  • 7/23/2019 Lect 8 Applaction Layer

    94/112

    1

    12

    60

    What is the valueassociated with key 53

    value

    13

    25

    3240

    48

    O(N) messageson avgerage to resolve

    query, when there

    are N peers

    Circular DHT with shortcuts1 What is the value for

    key 53

    value

  • 7/23/2019 Lect 8 Applaction Layer

    95/112

    12

    13

    60

    key 53

    each peer keeps track of IP addresses of predecessor,

    successor, short cuts. reduced from 6 to 3 messages. possible to design shortcuts with O(log N) neighbors, O(log N)

    messages in query

    25

    3240

    Peer churn1

    handling peer churn:peers may come and go (churn)

    each peer knows address of its

  • 7/23/2019 Lect 8 Applaction Layer

    96/112

    3

    4

    12

    15

    each peer knows address of its

    two successorseach peer periodically pings itstwo successors to check aliveness

    if immediate successor leaves,

    example: peer 5 abruptly leaves8

    10immediate successor

    Peer churn1

    handling peer churn:peers may come and go (churn)

    each peer knows address of its

  • 7/23/2019 Lect 8 Applaction Layer

    97/112

    3

    4

    12

    15

    each peer knows address of its

    two successorseach peer periodically pings itstwo successors to check aliveness

    if immediate successor leaves,

    example: peer 5 abruptly leaves

    peer 4 detects peer 5s departure; makes 8 its immediatesuccessor

    4 asks 8 who its immediate successor is; makes 8simmediate successor its second successor.

    810

    immediate successor

    Chapter 2: outline

  • 7/23/2019 Lect 8 Applaction Layer

    98/112

    2.1 principles of networkapplications app architectures

    app requirements

    2.6 P2P applications2.7 socket programmingwith UDP and TCP

    Application Layer2-98

    .

    2.3 FTP

    2.4 electronic mail SMTP, POP3, IMAP

    2.5 DNS

    Socket programming

    goal: learn how to build client/server applications that

  • 7/23/2019 Lect 8 Applaction Layer

    99/112

    goal: learn how to build client/server applications that

    communicate using socketssocket: door between application process and end-

    end-transport protocol

    Application Layer2-99

    Internet

    controlled

    by OS

    controlled byapp developer

    transport

    application

    physical

    link

    network

    process

    transport

    application

    physical

    link

    network

    processsocket

    Socket programming

    Two socket types for two transport services:

  • 7/23/2019 Lect 8 Applaction Layer

    100/112

    Two socket types for two transport services:

    UDP: unreliable datagram TCP: reliable, byte stream-oriented

    Application Example:

    Application Layer2-100

    1. Client reads a line of characters (data) from itskeyboard and sends the data to the server.

    2. The server receives the data and convertscharacters to uppercase.

    3. The server sends the modified data to the client.4. The client receives the modified data and displays

    the line on its screen.

    Socket programming with UDP

    UDP: no connection between client & server

  • 7/23/2019 Lect 8 Applaction Layer

    101/112

    no handshaking before sending data sender explicitly attaches IP destination address and

    port # to each packet

    rcvr extracts sender IP address and port# from

    Application Layer2-101

    UDP: transmitted data may be lost or receivedout-of-order

    Application viewpoint:

    UDP provides unreliable transfer of groups of bytes(datagrams) between client and server

    Client/server socket interaction: UDP

    server (running onserverIP) client

  • 7/23/2019 Lect 8 Applaction Layer

    102/112

    create socket:

    clientSocket =

    socket(AF_INET,SOCK_DGRAM)

    Create datagram with server IP and

    create socket, port= x:

    serverSocket =

    socket(AF_INET,SOCK_DGRAM)

    ( g )

    close

    clientSocket

    read datagram from

    clientSocket

    port=x; send datagram viaclientSocketread datagram from

    serverSocket

    write reply to

    serverSocket

    specifyingclient address,

    port number

    Application 2-102

    Example app: UDP client

    Python UDPClientinclude Pythons socket

  • 7/23/2019 Lect 8 Applaction Layer

    103/112

    from socket import *

    serverName = hostname

    serverPort = 12000

    clientSocket = socket(socket.AF_INET,

    include Python s socket

    library

    create UDP socket for

    server

    Application Layer2-103

    socket.SOCK_DGRAM)message = raw_input(Input lowercase sentence:)

    clientSocket.sendto(message,(serverName, serverPort))

    modifiedMessage, serverAddress =

    clientSocket.recvfrom(2048)print modifiedMessage

    clientSocket.close()

    get user keyboard

    input

    Attach server name, port to

    message; send into socket

    print out received string

    and close socket

    read reply characters from

    socket into string

    Example app: UDP server

    Python UDPServer

  • 7/23/2019 Lect 8 Applaction Layer

    104/112

    from socket import *

    serverPort = 12000

    serverSocket = socket(AF_INET, SOCK_DGRAM)

    serverSocket.bind(('', serverPort))

    create UDP socket

    bind socket to local port

    number 12000

    Application Layer2-104

    print The server is ready to receivewhile 1:

    message, clientAddress = serverSocket.recvfrom(2048)

    modifiedMessage = message.upper()

    serverSocket.sendto(modifiedMessage, clientAddress)

    loop forever

    Read from UDP socket intomessage, getting clientsaddress (client IP and port)

    send upper case string

    back to this client

    Socket programming with TCP

    client must contact server when contacted by client,TCP k

  • 7/23/2019 Lect 8 Applaction Layer

    105/112

    server process must first berunning

    server must have createdsocket (door) thatwelcomes clients contact

    server TCP creates new socketfor server process tocommunicate with thatparticular client

    allows server to talk withmulti le clients

    Application Layer2-105

    client contacts server by: Creating TCP socket,

    specifying IP address, portnumber of server process

    when client creates socket:

    client TCP establishesconnection to server TCP

    source port numbers usedto distinguish clients(more in Chap 3)

    TCP provides reliable, in-orderbyte-stream transfer (pipe)between client and server

    application viewpoint:

    Client/server socket interaction: TCP

    server (running on hostid) client

  • 7/23/2019 Lect 8 Applaction Layer

    106/112

    wait for incoming

    connection re uest

    create socket,port=x, for incoming

    request:serverSocket = socket()

    create socket,connect to hostid ort=x

    TCP

    Application Layer2-106

    connectionSocket =serverSocket.accept()

    clientSocket = socket()

    send request using

    clientSocketread request from

    connectionSocket

    write reply to

    connectionSocket

    connec on se up

    close

    connectionSocket

    read reply fromclientSocket

    close

    clientSocket

    Example app: TCP client

    f k t i t *

    Python TCPClient

  • 7/23/2019 Lect 8 Applaction Layer

    107/112

    from socket import *

    serverName = servername

    serverPort = 12000

    clientSocket = socket(AF_INET, SOCK_STREAM)

    create TCP socket for

    server, remote port 12000

    Application Layer2-107

    clientSocket.connect((serverName,serverPort))sentence = raw_input(Input lowercase sentence:)

    clientSocket.send(sentence)

    modifiedSentence = clientSocket.recv(1024)

    print From Server:, modifiedSentenceclientSocket.close()

    No need to attach server

    name, port

    Example app: TCP server

    from socket import *

    Python TCPServer

  • 7/23/2019 Lect 8 Applaction Layer

    108/112

    from socket import

    serverPort = 12000

    serverSocket = socket(AF_INET,SOCK_STREAM)

    serverSocket.bind((,serverPort))

    serverSocket.listen 1

    create TCP welcoming

    socket

    server begins listening for

    Application Layer2-108

    print The server is ready to receive

    while 1:

    connectionSocket, addr = serverSocket.accept()

    sentence = connectionSocket.recv(1024)capitalizedSentence = sentence.upper()

    connectionSocket.send(capitalizedSentence)

    connectionSocket.close()

    loop forever

    server waits on accept()

    for incoming requests, newsocket created on return

    read bytes from socket (butnot address as in UDP)

    close connection to this

    client (but notwelcoming

    socket)

    Chapter 2: summary

    our study of network apps now complete!

  • 7/23/2019 Lect 8 Applaction Layer

    109/112

    application architectures client-server

    P2P

    application service

    specific protocols: HTTP

    FTP

    Application Layer2-109

    requ rements: reliability, bandwidth, delay

    Internet transport servicemodel

    connection-oriented,

    reliable: TCP unreliable, datagrams: UDP

    DNS

    P2P: BitTorrent, DHT

    socket programming: TCP,UDP sockets

    Chapter 2: summary

    most importantly: learned about protocols!

  • 7/23/2019 Lect 8 Applaction Layer

    110/112

    typical request/replymessage exchange:

    client requests info orservice

    important themes:

    control vs. data msgs

    in-band, out-of-band

    Application Layer2-110

    server responds withdata, status code

    message formats:

    headers: fields givinginfo about data

    data: info beingcommunicated

    centralized vs. decentralized stateless vs. stateful

    reliable vs. unreliable msgtransfer

    complexity at networkedge

  • 7/23/2019 Lect 8 Applaction Layer

    111/112

    Chapter 1Additional Slides

    Introduction1-111

    application

    (www browser,packet

  • 7/23/2019 Lect 8 Applaction Layer

    112/112

    Transport (TCP/UDP)

    Network IP

    email client)application

    OS

    packet

    analyzer

    co of all

    Link (Ethernet)

    Physical

    cap ure

    (pcap)

    Ethernet

    frames

    sent/receive

    d