Computer Networking Chapter 2 Application Layer

2.1 Principles of Network Applications

2.1.1 Network Application Architectures

  • Client-server
    • server
      • always-on host
      • permanent IP address
      • data centers for scaling
    • clients
      • communicate with server
      • may be intermittently connected
      • may have dynamic IP addresses
      • do not communicate directly with each other
  • peer-to-peer
    • no always-on server
    • arbitrary end systems directly communicate
    • peers request service from other peers, provide service in return to other peers
      • self scalability – new peers bring new service capacity, as well as new service demands
    • peers are intermittently connected and change IP addresses
      • complex management ### 2.1.2 Processes Communicating
  • process: program running within a host
    • within same host, two processes communicate using inter-process communication (IPC, defined by OS)
    • processes in different hosts communicate by exchanging messages
  • clients, servers
    • client process: process that initiates communication
    • server process: process that waits to be contacted
    • applications with P2P architectures have client processes & server processes
  • sockets
    • process sends/receives message to/from its socket
    • analogous to door
      • sending process shoves message out door
      • sending process relies on transport infrastructure on other side of door to deliver message to socket at receiving process
    • Figure 2.1 socket
  • Addressing processes
    • to receive messages, process must have identifier
    • identifier includes both IP address and port numbers associated with process on host
    • host device has unique 32-bit IP address

2.1.3 Transport services Available to Applications

  • data integrity
    • some apps (e.g., file transfer, web transactions) require 100% reliable data transfer
    • other apps (e.g., audio) can tolerate some loss
  • timing
    • some apps (e.g., Internet telephony, interactive games) require low delay to be “effective”
  • throughput / bandwidth
    • some apps (e.g., multimedia) require minimum amount of throughput to be “effective”
    • other apps (“elastic apps”) make use of whatever throughput they get
  • security
    • encryption, data integrity, …

2.1.4 Transport Services Provided by the Internet

Figure 2.2 transport service requirements of common apps
Figure 2.2 transport service requirements of common apps
  • TCP service
    • connection-oriented: setup required between client and server processes
    • reliable transport between sending and receiving process
    • flow control: sender won’t overwhelm receiver
    • congestion control: throttle sender when network overloaded
    • does not provide: timing, minimum throughput guarantee, security
  • UDP service
    • unreliable data transfer between sending and receiving process
    • does not provide: reliability, flow control, congestion control, timing, throughput guarantee, security, or connection setup
Figure 2.3 Internet apps: application, transport protocols
Figure 2.3 Internet apps: application, transport protocols

2.1.5 Application-Layer Protocols

App-layer protocol defines

  • types of messages exchanged: request, response
  • message syntax: what fields in messages & how fields are delineated
  • message semantics: meaning of information in fields
  • rules for when and how processes send & respond to messages
  • open protocols:
    • defined in RFCs
    • allows for interoperability
    • e.g. HTTP, SMTP
  • proprietary protocols:
    • e.g. Skype

2.2 The Web and HTTP

2.2.1 Overview of HTTP

  • HTTP: hypertext transfer protocol
  • Web’s application layer protocol
  • client/server model
    • client: browser that requests, receives, (using HTTP protocol) and “displays” Web objects
    • server: Web server sends (using HTTP protocol) objects in response to requests
  • uses TCP:
    • client initiates TCP connection (creates socket) to server, port 80
    • server accepts TCP connection from client
    • HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)
    • TCP connection closed
  • HTTP is stateless

2.2.2 Non-Persistent and Persistent Connections

  • non-persistent HTTP
    • at most one object sent over TCP connection
    • downloading multiple objects required multiple connections
    • suppose user enter URL: www.someSchool.edu/someDepartment/home.index (contains text, references to 10 jpeg images)
      1. HTTP client initiates TCP connection to HTTP server (process) at www.someSchool.edu on port 80; HTTP server at host www.someSchool.edu waiting for TCP connection at port 80. “accepts” connection, notifying client
      2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object someDepartment/home.index
      3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket
      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
      6. Steps 1-5 repeated for each of 10 jpeg objects
    • response time
      • RTT (round-trip time): time for a small packet to travel from client to server and back
      • HTTP response time:
        • one RTT to initiate TCP connection
        • one RTT for HTTP request and first few bytes of HTTP response to return
        • file transmission time
        • non-persistent HTTP response time = 2RTT + file transmission time
      • Figure 2.4 HTTP response time
  • persistent HTTP
    • multiple objects can be sent over single TCP connection between client, server
    • server leaves connection open after sending response
    • subsequent HTTP messages between same 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.2.3 HTTP Message Format

  • HTTP request message

    figure 2.5 a typical HTTP request message
    figure 2.5 a typical HTTP request message
    • general format

      Figure 2.6 General Format of an HTTP request message
      Figure 2.6 General Format of an HTTP request message
  • HTTP response message

    figure 2.7 a typical HTTP response message
    figure 2.7 a typical HTTP response message
    • status code
      • 200 OK: request succeeded, requested object later in this msg
      • 301 Moved Permanently: requested object moved, new location specified later in this msg (Location:)
      • 400 Bad Request: request msg not understood by server
      • 404 Not Found: requested document not found on this server
      • 505 HTTP Version Not Supported

four components

  • cookie header line of HTTP response message
  • cookie header line in next HTTP request message
  • cookie file kept on user's host, managed by user's browser
  • back-end database at Web site
Figure 2.8 Keeping user state with cookies
Figure 2.8 Keeping user state with cookies

cookies can be used for

  • authorization
  • shopping carts
  • recommendations
  • user session state
  • cookies permit sites to learn a lot about you

2.2.5 Web caching

also proxy server

goal: satisfy client request without involving origin server

What happens when a browser is requesting the object http://www.someschool.edu/campus.gif

  1. The browser establishes a TCP connection to the Web cache and sends an HTTP request for the object to the Web cache.
  2. The Web cache checks to see if it has a copy of the object stored locally. If it does, the Web cache returns the object within an HTTP response message to the client browser.
  3. If the Web cache does not have the object, the Web cache opens a TCP connection to the origin server, that is, to www.someschool.edu. The Web cache then sends an HTTP request for the object into the cache-to-server TCP connection. After receiving this request, the origin server sends the object within an HTTP response to the Web cache.
  4. When the Web cache receives the object, it stores a copy in its local storage and sends a copy, within an HTTP response message, to the client browser (over the existing TCP connection between the client browser and the Web cache).

acts both client and server

  • server for original requesting client
  • client to origin server

why Web caching?

  • reduce response time for client request
  • reduce traffic on an institution’s access link
  • Internet dense with caches: enables “poor” content providers to effectively deliver content (so too does P2P file sharing)

2.2.6 The Conditional GET

goal: don't send object if cache has up-to-date cached version

  • no object transmission
  • lower link utilization
Figure 2.9 Conditional GET
Figure 2.9 Conditional GET

2.3 File Transfer: FTP

the file transfer protocol

  • 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

separate control, data connections

  • FTP client contacts FTP server at port 21, using TCP

  • client authorized over control connection

  • client browses remote directory, sends commands over control connection

  • when server receives file transfer command, server opens 2nd TCP data connection (for file) to client

  • after transferring one file, server closes data connection

  • server opens another TCP data connection to transfer another file

  • control connection: "out of band"

  • FTP server maintains “state”: current directory, earlier authentication

    Figure 2.10 FTP: client & server
    Figure 2.10 FTP: client & server

2.4 Electronic Mail in the Internet

Figure 2.11 SMTP
Figure 2.11 SMTP

Three major components

  • user agents
  • mail servers
  • simple mail transfer protocol: SMTP

User Agent

  • a.k.a. "mail reader"
  • composing, editing, reading mail messages
  • e.g., Outlook, Thunderbird, iPhone mail client
  • outgoing, incoming messages stored on server

mail servers:

  • mailbox contains incoming messages for user
  • message queue of outgoing (to be sent) mail messages
  • SMTP protocol between mail servers to send email messages
    • client: sending mail server
    • "server": receiving mail server

2.4.1 SMTP

  • 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 (like HTTP, FTP)
  • commands: ASCII text
    • response: status code and phrase
  • messages must be in 7-bit ASCII
Figure 2.12 Scenario: Alice sends message to Bob
Figure 2.12 Scenario: Alice sends message to Bob
Figure 2.13 Sample SMTP interaction
Figure 2.13 Sample SMTP interaction

2.4.2 Comparison with HTTP

  • HTTP: pull
  • SMTP: push
  • both have ASCII command/response interaction, status codes
  • HTTP: each object encapsulated in its own response msg
  • SMTP: multiple objects sent in multipart msg

2.4.3 Mail Message Formats

SMTP: protocol for exchanging email msgs

RFC 822: standard for text message format:

header lines, e.g.

  • To:
  • From:
  • Subject:

different from SMTP MAIL FROM, RCPT TO: commands!

Body: the “message”

  • ASCII characters only

2.4.4 Mail Access Protocols

Figure 2.14 Mail Access Protocols
Figure 2.14 Mail Access Protocols
  • SMTP: delivery/storage to receiver’s server
  • 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 on server
    • HTTP: gmail, Hotmail, Yahoo! Mail, etc.
  • POP3
    • authorization phase
      • client commands:
        • user: declare username
        • pass: password
      • server responses
        • +OK
        • -ERR
    • transaction phase, client:
      • list: list message numbers
      • retr: retrieve message by number
      • dele: delete
      • quit
    • previous example uses POP3 “download and delete” mode
      • Bob cannot re-read e-mail if he changes client
    • POP3 “download-and-keep”: copies of messages on different clients
    • POP3 is stateless across sessions
  • IMAP
    • keeps all messages in one place: at server
    • allows user to organize messages in folders
    • keeps user state across sessions:
      • names of folders and mappings between message IDs and folder name

2.5 DNS—–The Internet's Directory Service

2.5.1 Services Provided by DNS

map between IP address and name, and vice versa

  • distributed database implemented in hierarchy of many name servers
  • application-layer protocol: hosts, name servers communicate to resolve names (address/name translation)
    • note: core Internet function, implemented as application-layer protocol
    • complexity at network’s "edge"

DNS services

  • hostname to IP address translation
  • host aliasing
    • canonical, alias names
  • mail server aliasing
  • load distribution
    • replicated Web servers: many IP addresses correspond to one name

2.5.2 Overview of How DNS Works

why not centralize DNS?

- single point of failure
- traffic volume
- distant centralized database
- maintenance

DNS: a distributed, hierarchical database

Figure 2.15 Portion of the hierarchy of DNS servers
Figure 2.15 Portion of the hierarchy of DNS servers
  • 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 for www.amazon.com
  • Root DNS servers
    • contacted by local name server that cannot resolve name
    • contacts authoritative name server if name mapping not known
    • gets mapping
    • returns mapping to local name server
  • 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
  • Authoritative DNS servers
    • organization’s own DNS server(s), providing authoritative hostname to IP mappings for organization’s named hosts
    • can be maintained by organization or service provider
  • Local DNS 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
      • has local cache of recent name-to-address translation pairs (but may be out of date!)
      • acts as proxy, forwards query into hierarchy
  • Figure 2.16 Interaction of the various DNS servers
    • recursive queries: query sent from cis.poly.edu to dns.poly.edu
      • puts burden of name resolution on contacted name server
      • heavy load at upper levels of hierarchy?
    • iterative queries: subsequent three queries, since all the replies are directly returned to dns.poly.edu
      • contacted server replies with name of server to contact
      • "I don’t know this name, but ask this server"

DNS Caching

  • once (any) name server learns mapping, it caches mapping
    • 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 name-to-address translation!)
    • if name host changes IP address, may not be known Internet-wide until all TTLs expire
  • update/notify mechanisms proposed IETF standard
    • RFC 2136

2.5.3 DNS Records and Messages

DNS: distributed db storing resource records (RR), RR format: (Name, Value, Type, TTL)

  • Type = A:
    • name is hostname
    • value is IP address
  • Type = NS:
    • name is domain
    • value is hostname authoritative name server for this domain
  • Type = CNAME:
    • name is alias name for some "canonical" (the real) name
    • www.ibm.com is really servereast.backup2.ibm.com
    • value is canonical name
  • Type = MX:
    • value is name of mailserver associated with name

DNS messages

  • query and reply messages, both with same message format
Figure 2.17 DNS message format
Figure 2.17 DNS message format
  • The first 12 bytes is the header section
    • identification: 16 bits (2 bytes) # for query, reply to query uses same #
    • flags:
      • query or reply
      • recursion desired
      • recursion available
      • reply is authoritative

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

2.6 Peer-to-Peer Applications

  • no always-on server
  • arbitrary end systems directly communicate
  • peers are intermittently connected and change IP addresses

2.6.1 P2P File Distribution

Applications with P2P architecture can be self-scaling

  • Peers are redistributors as well as consumers of bits
Figure 2.18 Distribution time for P2P and client-server architectures
Figure 2.18 Distribution time for P2P and client-server architectures

BitTorrent

  • peer joining torrent:
    • has no chunks, but will accumulate them over time from other peers
    • registers with tracker to get list of peers, connects to 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
  • requesting chunks:
    • at any given time, different peers have different subsets of file chunks
    • periodically, Alice asks each peer for list of chunks that they have
    • Alice requests missing chunks from peers, rarest first
  • sending chunks: tit-for-tat
    • Alice sends chunks to those four peers currently sending her chunks at highest rate
      • other peers are choked by Alice (do not receive chunks from her)
      • re-evaluate top 4 every 10 secs
    • every 30 secs: randomly select another peer, starts sending chunks
      • "optimistically unchoke" this peer
      • newly chosen peer may join top 4

2.6.2 Distributed Hash Tables (DHTs)

DHT paradigm

  • Distribute (key, value) pairs over millions of peers
    • 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 peers
  • Each peer only knows about a small number of other peers
  • Robust to peers coming and going (churn)
  • Assign key-value pairs to peers
    • 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 and overlay networks

  • each peer only aware of immediate successor and predecessor

    Figure 2.19 overlay network
    Figure 2.19 overlay network
  • O(N) messages on average to resolve query, when there are N peers

  • Circular DHT with shortcuts

    • 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
    1Figure 2.20 (a)A circular DHT & (b)A circular DHT with shortcuts
    1Figure 2.20 (a)A circular DHT & (b)A circular DHT with shortcuts
  • reduced from 6 to 3 messages.

    •possible to design shortcuts with O(log N) neighbors, O(log N) messages in query

Peer churn

  • peers may come and go (churn)
  • each peer knows address of its two successors
  • each peer periodically pings its two successors to check aliveness
  • if immediate successor leaves, choose next successor as new immediate successor

2.7 Socket Programming: Creating Network

socket: door between application process and end-end-transport protocol

Figure 2.21 socket communication
Figure 2.21 socket communication

Application Example:

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

  2. The server receives the data and converts characters 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.

2.7.1 Socket Programming with UDP

UDP: no “connection” between client & server

  • no handshaking before sending data
  • sender explicitly attaches IP destination address and port # to each packet
  • rcvr extracts sender IP address and port# from received packet

UDP: transmitted data may be lost or received out-of-order

  • UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server
Figure 2.22 The client-server application using UDP
Figure 2.22 The client-server application using UDP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# UDPClient.py
from socket import * # include Python's socket library

serverName = 'localhost'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_DGRAM) # create UDP socket for server

message = input("Input lowercase sentence:") # get keyboard input
clientSocket.sendto(message.encode(), (serverName, serverPort)) # Attach server name, port to message; send into socket

modifiedMessage, serverAddress = clientSocket.recvfrom(2048) # read reply characters from socket into string

print(modifiedMessage.decode()) # print out received string and close socket
clientSocket.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
# UDPServer.py
from socket import *

serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM) # create UDP socket
serverSocket.bind(('', serverPort)) # bind socket to local port number 12000

print("The server is ready to receive")

while True: # loop forver
message, clientAddress = serverSocket.recvfrom(2048) # Read from UDP socket into message, getting client’s address (client IP and port)
modifiedMessage = message.decode().upper()
serverSocket.sendto(modifiedMessage.encode(), clientAddress) # send upper case string back to this client

2.7.2 Socket Programming with TCP

client must contact server

  • server process must first be running
  • server must have created socket (door) that welcomes client’s contact

client contacts server by:

  • Creating TCP socket, specifying IP address, port number of server process
  • when client creates socket: client TCP establishes connection to server TCP

when contacted by client, server TCP creates new socket for server process to communicate with that particular client

  • allows server to talk with multiple clients
  • source port numbers used to distinguish clients (more in Chap 3)
Figure 2.23 The client-server application using TCP
Figure 2.23 The client-server application using TCP
1
2
3
4
5
6
7
8
9
10
11
12
# TCPClient.py
from socket import *

serverName = "localhost"
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM) # create TCP socket for server, remote port 12000
clientSocket.connect((serverName, serverPort))
sentence = input("Input lowercase sentence:")
clientSocket.send(sentence.encode()) # No need to attach server name, port
modifiedSentence = clientSocket.recv(1024)
print("From Server:", modifiedSentence.decode())
clientSocket.close()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# TCPServer.py
from socket import *

serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM) # create TCP welcoming socket
serverSocket.bind(("", serverPort))
serverSocket.listen(1) # server begins listening for incoming TCP requests
print("The server is ready to receive")
while 1: # loop forever
connectionSocket, addr = serverSocket.accept() # server waits on accept() for incoming requests, new socket created on return
sentence = connectionSocket.recv(1024).decode() # read bytes from socket (but not address as in UDP)
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence.encode()) # close connection to this client (but not welcoming socket)
connectionSocket.close()

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×