chapter 2 the application layer departamento de tecnología electrónica computer networking some of...

83
Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from: Computer Networking: A Top Down Approach , 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009.

Upload: giles-gallagher

Post on 27-Dec-2015

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Chapter 2The Application layer

Departamento deTecnología Electrónica

Computer NetworkingSome of these slides are given as copyrighted material from:

Computer Networking: A Top Down Approach ,5th edition. Jim Kurose, Keith RossAddison-Wesley, April 2009.

Page 2: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Chapter 2: The Application LayerOur goals: conceptual,

implementation aspects of network application protocols transport-layer

service models client-server

paradigm peer-to-peer

paradigm

learn about protocols by examining popular application-layer protocols HTTP DNS

programming network applications socket API

Application 2-2

Page 3: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Some network apps

e-mail web instant messaging remote login P2P file sharing multi-user network games streaming stored video

(e.g. YouTube)

voice over IP (VoIP) real-time video

conferencing cloud computing … …

Application 2-3

Page 4: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Creating a network app

write programs that run on (different) end systems communicate over network e.g., web server software

communicates with browser software

No need to write software for network-core devices network-core devices do not

run user applications applications on end systems

allows for rapid app development, propagation

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

Application 2-4

Page 5: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Chapter 2: Application layer

Application 2-5

2.1 Principles of network applications2.2 DNS2.3 Web and HTTP2.4 Socket programming with TCP2.5 Socket programming with UDP

Page 6: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Application architectures

client-serverpeer-to-peer (P2P)hybrid of client-server and P2P

Application 2-6

IP address: it uniquely identifies the devices (end systems, routers, etc...)

connected to a TCP/IP network. The ISP assigns a static (fixed) or dynamic (variable) IP addr. More soon ...

Note:

Page 7: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Client-server architectureserver:

always-on host permanent IP address server farms for scaling

clients: communicate with server may be intermittently

connected may have dynamic IP

addresses do not communicate directly

with each other

client/server

Application 2-7

Page 8: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pure P2P architecture

no always-on server arbitrary end systems

directly communicate peers are intermittently

connected and change IP addresses

highly scalable but difficult to manage

peer-peer

Application 2-8

Page 9: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Hybrid of client-server and P2PSkype

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

Application 2-9

Page 10: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

How is app layer implemented?

Application 2-10

Transport

Application

Transport

Application

InternetInternet

User interface User interface

Application Protocol

A_PDUSAP SAP

Web browsers, e.g.: Mozilla firefox, Chrome, Internet Explore, Safari,…

Page 11: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

App-layer protocol defines

types of exchanged messages, e.g., request, response

message syntax: what fields are in messages

& how fields are distinguished

message semantics meaning of information in

fields rules for when and how

processes send & respond to messages

public-domain protocols: defined in RFCs allows for interoperability e.g., HTTP, SMTPproprietary protocols: e.g., Skype

Application 2-11

Page 12: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Process communication

process: program running within a host.

within the same host, communication is held using inter-process communication (defined by OS).

In different hosts, communication is done by exchanging messages (PDUs). Communication services (generally defined by OS) are used.

client process: process that initiates communication

server process: process that waits to be contacted

Note: applications with P2P architectures have both client processes & server processes

Application 2-12

Page 13: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Sockets (SAP) process sends/receives

messages to/from its socket socket analogous to door

sending process sends message out door

sending process relies on transport infrastructure on the other side of the door, bringing message to socket at receiving process

process

TCP withbuffers,variables

socket

client

process

TCP withbuffers,variables

socket

server

Internet

controlledby OS

controlled byapp developer

API: (1) choice of transport protocol; (2) ability to fix a few parameters (more on this later)

Application 2-13

Page 14: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

How is a socket identified? If you want to send a friend a mail you need to know his

address to reach his home mailbox Each end system has unique 32-bit IP address (IPv4)

Q: Is your friend’s address enough to make the letters reach him? A: No. Several people may be living at the same home.

Several app protocols can be running on one end system Web browser, email client, Skype…

Application 2-14

For every IP address you have an associated name (hostname) which are used to identify the network devices by humans and applications.

For example, www.dte.us.es = 150.214.141.196

More on Names and IPs on next section…

Note

Page 15: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

How is a socket identified? Each app protocol is identified by a port number Client port number and server port number may not be the same example port numbers:

HTTP server: 80 DNS server: 53 Mail server: 25

ICANN (Internet Corporation for Assigned Names and Numbers) is responsible for public app protocols port registering

http://www.iana.org/assignments/port-numbers

Socket is identified by the pair: IP address Port number

Application 2-15

Page 16: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Application 2-16

Transport

Aplicació

nTransport

Aplicació

n

InternetInternet

Interfaz Usuario Interfaz Usuario

Client IP address, port150.214.141.196, 80

Example

DTE web server

Page 17: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Localhost is usually asociated to IP address 127.0.0.1, but other IPs may be used…. More on Chapter 4…

Localhost: Connecting 2 process on the same host

Application 2-17

Note

localhost: is a “reserved name” related to a particular IP address which always identify our own end system.

It’s useful to connect network applications on a single host (without any other physical network connection).

In general, it allows interprocess comunications in the end system using the same Internet protocol stack.

Q: How can the communication service on the host able to distinguish each process?

OS Internet Communication Service

OS Internet Communication Service

socket1

process1

socket2

process2

Page 18: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

What transport service does an app need?

Data loss some apps (e.g., audio) can

tolerate some loss other apps (e.g., file transfer,

telnet) require 100% reliable data transfer

Timing some apps (e.g., Internet

telephony, interactive games) require low delay to be “effective”

Throughput 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, …

Application 2-18

Page 19: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Transport service requirements of common apps

Application

file transfere-mail

Web documentsreal-time audio/video

stored audio/videointeractive gamesinstant messaging

Data loss

no lossno lossno lossloss-tolerant

loss-tolerantloss-tolerantno loss

Throughput

elasticelasticelasticaudio: 5kbps-1Mbpsvideo:10kbps-5Mbpssame as above few kbps upelastic

Time Sensitive

nononoyes, 100’s msec

yes, few secsyes, 100’s msecyes and no

Application 2-19

Page 20: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Internet transport protocols services

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 guarantees, security

UDP service: unreliable data transfer

between sending and receiving process

does not provide: connection setup, reliability, flow control, congestion control, timing, throughput guarantee, or security

Q: Why UDP?

Application 2-20

Page 21: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Internet apps: application, transport protocols

Application

e-mailremote terminal access

Web file transfer

streaming multimedia

Internet telephony

Applicationlayer protocol

SMTP [RFC 2821]Telnet [RFC 854]HTTP [RFC 2616]FTP [RFC 959]HTTP (e.g., YouTube), RTP [RFC 1889]SIP, RTP, propietary(e.g., Skype)

Underlyingtransport protocol

TCPTCPTCPTCPTCP or UDP

typically UDP

Application 2-21

Page 22: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Chapter 2: Application layer

Application 2-22

2.1 Principles of network applications2.2 DNS2.3 Web and HTTP2.4 Socket programming with TCP2.5 Socket programming with UDP

Page 23: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

DNS: Domain Name System

people: many identifiers: SSN, name, passport #

Internet hosts, routers: IP address (32 bit) - used for

addressing datagrams “name”, e.g.,

www.yahoo.com - used by humans

Q: map between IP address and name, and viceversa?

Domain Name System: distributed database implemented

in hierarchy of many name servers application-layer protocol host,

routers, name servers to communicate to resolve names (address/name translation) note: core Internet function,

implemented as application-layer protocol

Application 2-23

Page 24: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTTP client

Application 2-24

DNS client

InternetInternet

DNS server

HTTP server

http://www.dte.us.es/index.html

DNS adds an additional delay

Page 25: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

DNS Why not centralize DNS? single point of failure traffic volume distant centralized database maintenance… doesn’t scale!

Which transport service does it use?

Not reliable UDP, port 53

DNS services hostname to IP address

translation (direct) IP address to hostname

translation (inverse) host aliasing

Canonical, alias names mail server aliasing

@domain load distribution

replicated Web servers: set of IP addresses for one canonical name

Application 2-25

Page 26: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

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 among DNS servers proposed IETF standard RFC 2136

Application 2-26

Page 27: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

DNS: how does it work? (simplified!) If an application have a hostname and not the associated IP address it requests

the resolution to the DNS service in the same host (reverse resolution is also available). El DNS service check if there’s an entry in the DNS cache for the hostname or IP address and then…

… if there’s an entry in the cache: It returns the requested resolution to the application.

… if there’s no entry in the cache: The DNS service sends a DNS REQUEST (DNS_PDU) to the DNS Server IP

address configured on the host (at least one is usually configured) and wait for the DNS REPLY (another type of DNS_PDU) from the DNS Server it was requested. The reply is then added to the cache to accelerate future requests and it’s also returned to the application. If it’s not possible to resolve the hostname or IP address, it notifies the

application.

Application 2-27

When a DNS Server receives a DNS REQUEST, its behaviour is the same as a host, it first tries its own cache and if it’s not available it generates a Request to another DNS Server in a higher hierarchy, and the Reply is then forwarded back to the client.

Note

Page 28: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Chapter 2: Application layer

Application 2-28

2.1 Principles of network applications2.2 DNS2.3 Web and HTTP2.4 Socket programming with TCP2.5 Socket programming with UDP

Page 29: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Web and HTTP

First, a review… 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 (Uniform Resource Locator)

example URL:

www.informatica.us.es/DTE/pic.gif

host name path name

Application 2-29

Page 30: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTML language formatIt allows formatting web pages; created in 1991. It includes elements with TAGS in

<>. Each element usually have 4 fields: a starting tag (like “<html>”) & an ending tag (like “</html>”), some attributes (in starting tag) and some contents (between the tags).

<!DOCTYPE html…> remarks document start (optional)<html>document</html> start/finish of document<head>headers</head> header content (not visible to the end user, like title, styles, metainformation, etc…)<body>webpage</body> it contains the body of the webpage, with:

from <h1> to <h6> headings<table>table</table> creates a table with fils/cols<a href=“URL”>link</a> hiperlink: when the user clicks on the link, the URL

object is requested.<img src=“URL”> object reference, navigator requests the URL

object inmediately to be shown.

Application 2-30

You can view the HTML code in any webpage with

your favourite navigator, right-click -> view source code.

Aside

Page 31: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTTP overview

HTTP: hypertext transfer protocol

Web’s application layer protocol

client/server model client: browser that

requests, receives, “displays” Web objects

server: Web server sends objects in response to requests

PC runningIExplorer

Server running

Apache Webserver

Linux runningFirefox

HTTP request

HTTP request

HTTP response

HTTP response

Application 2-31

Page 32: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTTP overview (continued)

Uses TCP: client initiates TCP connection

(creates socket) to server, port 80 in server

server accepts TCP connection from client

HTTP messages (A_PDU’s: Application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)

TCP connection closed

HTTP is “stateless” server maintains no

information about past client requests

protocols that maintain “state” are complex!

past history (state) must be maintained

if server/client crashes, their views of “state” may be inconsistent, must be synchronized

note

Application 2-32

Page 33: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTTP connections

non-persistent HTTP one object sent over TCP

connection.

persistent HTTP multiple objects can be

sent over single TCP connection between client, server.

Application 2-33

Page 34: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Non-persistent HTTPsuppose user enters URL:

1a. HTTP client initiates TCP connection to HTTP server (process) at www.dte.us.es on port 80

2. HTTP client sends HTTP request message (containing URL) into TCP connection socket. Message indicates that client wants object with pathname /personal/smartin/lab3/referencias.html

1b. HTTP server at host www.dte.us.es waiting for TCP connection at port 80. “accepts” connection, notifying client

3. HTTP server receives request message, forms response message containing requested object, and sends message into its socket

time

(contains text & references to 13 objects)

Application 2-34

http://www.dte.us.es/personal/smartin/lab3/referencias.html

Page 35: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Nonpersistent HTTP (cont.)

5. HTTP client receives response message containing html file, displays html. Parsing html file, finds 13 referenced objects (images, scripts, …)

6. Steps 1-5 repeated for each of 13 objects with different unique URLs

4. HTTP server closes TCP connection.

time

Application 2-35

Page 36: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Non-Persistent HTTP: Response time

RTT (Round-Trip Time): time for a PDU with a few bytes to travel from client to server and back.

Response time: one RTT to initiate TCP

connection one RTT for HTTP request

and first few bytes of HTTP response to return

file transmission timetotal = 2RTT+transmit time

time to transmit file

initiate TCPconnection

RTT

requestfile

RTT

filereceived

time time

Application 2-36

Page 37: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Persistent HTTP

non-persistent HTTP issues: requires 2 RTTs per object OS overhead for each TCP

connection

persistent HTTP 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 finds a referenced object

Each referenced object takes only 1 RTT

Application 2-37

Parallel HTTP connections: browsers often open parallel TCP

connections to fetch referenced objects faster. They are requested sequentally per each connection (persistent or not).

Note that:

Page 38: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Mensajes HTTP (HTTP_PDU) 2 types of messages:

HTTP Request: Sent by the client Takes neccessary information Transporta información

(HTTP_PCI) to get an object from the server (HTTP_UD) ASCII chracters (intelligible text)

HTTP Response: Sent by the server Takes the object (HTTP_UD) requested by the client and

some control information (HTTP_PCI)

Aplicación 2-38

Page 39: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTTP request message

request line(GET, POST, HEAD commands)

header lines

\r & \n at startof line indicatesend of header lines

Application 2-39

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

<CR>: Carriage-Return : \r

<LF>: Line-Feed: \n

Note:

UD

Page 40: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Some HTTP headers CLIENT can send

Host: hostname (name of the web site) User-Agent: web_navigator_version Accept-xxx: preferences_list_for_xxx_feature Connection: keep-alive

Client if asking the server to stablish persistant connection

Keep-Alive: nnnClient if asking the server to keep the persistant

connection alive for nnn seconds.

Aplicación 2-40

Page 41: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTTP request message: general format

Application 2-41

requestline

headerlines

body

PDU

UD

PCI

Page 42: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Uploading form input

Web page often includes form input (with some parameters that are sended to server). There are two methods to send:

POST method: input is uploaded to server in entity body

GET method: Inputs are uploaded in URL field of request line

(separated by “?” and “&”):

GET /animalsearch?monkeys&banana HTTP/1.1\r\nHost: www.somesearchengine.com\r\n…

Application 2-42

Page 43: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Method types

HTTP/1.0 (RFC-1945) GET POST HEAD

Identical to GET but object is not included in response (only corresponding headers)

HTTP/1.1 (RFC-2616) GET, POST, HEAD PUT

uploads file in entity body to path specified in URL field

DELETE deletes file specified in the

URL field

Application 2-43

Page 44: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTTP response message

status line(protocolstatus codestatus phrase)

header lines

data, e.g., requestedHTML file

Application 2-44

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\nETag: "17dc6-a5c-bf716880"\r\nAccept-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 ...

Page 45: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Some HTTP headers the SERVER can send

Date: date Last-Modified: (last modification of the requested object) Server: web_server_version Content-Type: object_type (HTML, image, text …) Content-Length: body_length (in bytes) Connection: keep-alive

Server announces the connection will be persistant. Keep-Alive: timeout=ttt, max=nnn

Server will close the connection after ttt seconds of inactivity or otherwise after nnn seconds.

Application 2-45

Page 46: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

HTTP response status codes

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

status code appears in 1st line in serverclient response message.

some sample codes:

Application 2-46

Page 47: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Trying out HTTP (client side) for yourself1. Telnet to your favourite Web server:

opens TCP connection to port 80(default HTTP server port) at www.dte.us.esanything typed in sent to port 80 at www.dte.us.es

telnet www.dte.us.es 80

2. type in a GET HTTP request:

GET /docencia/ HTTP/1.1Host: www.dte.us.es

by typing this, you sendthis minimal (but complete) GET request to HTTP server

3. look at response message sent by HTTP server! (or use Wireshark!)

Application 2-47Q: What happens if you send “hello”?

Page 48: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

User-server state: cookies

many Web sites use cookiesfour components:

1) cookie header line of HTTP response message

2) cookie header line in HTTP request message

3) cookie file kept on user’s host, managed by user’s browser

4) back-end database at Web site

example: Susan always accesses

Internet from her PC visits specific e-commerce

site for first time (e.g. Amazon)

when initial HTTP requests arrives at site, site creates: unique ID entry in back-end

database for ID

Application 2-48

Page 49: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Cookies: Example

Client visits AMAZON AMAZON server

usual http response msg

usual http response msg

cookie file

one week later:

usual http request msgcookie:1678 cookie-

specificaction

access

ebay 8734usual http request msg Amazon server

creates ID1678 for user create

entry

usual http response Set-cookie:1678

ebay 8734amazon 1678

usual http request msgcookie:1678 cookie-

specificaction

accessebay 8734amazon 1678

backenddatabase

Application 2-49

Page 50: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Cookies (continued)

what cookies can bring: authorization shopping carts recommendations user session state (Web e-

mail)

cookies and privacy: cookies allow sites to

learn a lot about you you may supply personal

information to sites (name, e-mail,…)

Note

Application 2-50

Page 51: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Web caches (proxy server)

user sets browser: Web accesses via cache-proxy

browser sends all HTTP requests to cache-proxy object in cache: cache

returns object Else, cache requests object

from origin server, then returns object to client

Goal: satisfy client request without involving origin server

client

Proxyserver

client

HTTP request

HTTP response

HTTP request HTTP request

origin server

origin server

HTTP responseHTTP response

Application 2-51

Page 52: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

More about Web caching - Proxy

cache acts as both client (of the original server) and server (of the user client)

typically cache is installed by ISP (university, company, residential ISP)

why Web caching? reduce response time for

client request reduce traffic on an

institution’s access link. enables “poor” content

providers to effectively deliver content (but so does P2P file sharing)

Application 2-52

Page 53: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Conditional GET

Goal: don’t send object if cache has up-to-date cached version

Cache-proxy: specify date of cached copy in HTTP request

If-modified-since: <date>

server: response contains no object if cached copy is up-to-date:

HTTP/1.0 304 Not Modified

Or modified object is sended with the last-modified date:

Last-modified:<date>

cache-proxy server

HTTP request msgIf-modified-since: <date>

HTTP responseHTTP/1.0

304 Not Modified

object modified

before<date>

HTTP request msgIf-modified-since: <date>

HTTP responseHTTP/1.0 200 OK

Last-modified: <date><data>

object modified

after <date>

Application 2-53

Page 54: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Chapter 2: Application layer

Application 2-54

2.1 Principles of network applications2.2 DNS2.3 Web and HTTP2.4 Socket programming with TCP2.5 Socket programming with UDP

Page 55: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Socket programming

Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released

by apps client/server paradigm two types of transport service

via socket API: unreliable datagram reliable, byte stream-

oriented

A local-host, application-created,

OS-controlled interface (a “door”) where

application processes can both send and

receive messages to/from another application processes

socket

Goal: learn how to build client/server application that communicate using sockets

Application 2-55

Page 56: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Application 2-56

Transport

Application

Transport

Application

InternetInternet

User interface User interface

Client IP address, portServer IP address, port

Application protocolServerClient

Page 57: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

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

process

TCP withbuffers,

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

client orserver

process

TCP withbuffers,

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

client orserver

internet

Application 2-57

Page 58: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Socket programming with TCP

Client must contact server server process must first be

running server must open a socket

(door) that welcomes client’s contact

Client contacts server by: creating client 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 client allows server to talk with

multiple clients source port numbers used to

distinguish clients (more in Chap 3)

TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server

application viewpoint

Application 2-58

Page 59: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Client/server socket interaction: TCP

wait for incomingconnection requestconnectionSocket =welcomeSocket.accept()

create socket,port=x, forincoming request:welcomeSocket =

ServerSocket()

create socket,connect to hostid, port=xclientSocket =

Socket()

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection

setup

Application 2-59hostid = IP or hostname

Wait for primitive: Connection.indication

Send primitive: Connection.response

Send primitive: Connection.request

Wait for primitive: Connection.confirm

Page 60: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

ou

tTo

Se

rve

r

to network from network

inF

rom

Se

rve

r

inF

rom

Use

r

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCP socket

Clientprocess

Java Stream

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

input stream is attached to some input source for the process, e.g., keyboard or socket.

output stream is attached to an output source, e.g., monitor or socket.

Ex.: we are going to use 3 streams and 1 socket in the client

Application 2-60

To transport

layer

From transport layer

keyboard monitor

input stream

output stream

input stream

outT

oSer

ver

inFr

omSe

rver

client TCP socket

inFr

omU

ser

Page 61: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

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 socket3) server converts line to uppercase, sends back to client4) client reads, prints modified line from socket

(inFromServer stream)

Application 2-61

Page 62: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: Java client (TCP)

import java.io.*; import java.net.*; class TCPClient {

public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence;

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

Socket clientSocket = new Socket("hostname", 6789);

DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

createinput stream

create clientSocket object

of type Socket, connect to server

createoutput stream

attached to socket

Application 2-62

This package defines Socket() and ServerSocket() classes

server port #

server name,e.g., www.dte.us.es

T_ICI

T_ICI

Page 63: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: Java client (TCP), cont.

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

sentence = inFromUser.readLine();

outToServer.writeBytes(sentence + '\n');

modifiedSentence = inFromServer.readLine();

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

clientSocket.close(); } }

Application 2-63

createinput stream

attached to socket

send lineto server

read linefrom server

close socket(clean up behind yourself!)

Send primitive: Data.request PDU

Wait for primitive: Data.indication

Page 64: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: Java server (TCP)import java.io.*; import java.net.*;

class TCPServer {

public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence;

ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept();

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));

wait, on welcomingsocket accept() method

for client contact create, new socket on return

Application 2-64

createwelcoming socket

at port 6789

create inputstream, attached

to socket

Page 65: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: Java server (TCP), cont

DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());

clientSentence = inFromClient.readLine();

capitalizedSentence = clientSentence.toUpperCase() + '\n';

outToClient.writeBytes(capitalizedSentence); } } }

end of while loop,loop back and wait foranother client connection

Application 2-65

create outputstream, attached

to socket

read in linefrom socket

write out lineto socket

PDU

PDUSend primitive: Data.request

Wait for primitive: Data.indication

Page 66: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Chapter 2: Application layer

Application 2-66

2.1 Principles of network applications2.2 DNS2.3 Web and HTTP2.4 Socket programming with TCP2.5 Socket programming with UDP

Page 67: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Socket programming with UDP

UDP: no “connection” between client and server

no handshaking sender explicitly attaches IP

address and port of destination to each message (PDU) that wants to send

server must extract IP address, port of sender from received message

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

application viewpoint:

UDP provides unreliable transfer of groups of bytes (“datagrams”)

between client and server

Application 2-67

Page 68: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Client/server socket interaction: UDP

Server (running on hostid)

closeclientSocket

read datagram fromclientSocket

create socket,clientSocket = DatagramSocket()

Client

Create datagram with server IP andport=x; send datagram via clientSocket

create socket,port= x.serverSocket = DatagramSocket()

read datagram fromserverSocket

write reply toserverSocketspecifying client address,port number

Application 2-68hostid = IP or hostname

Wait primitive: Data.indication

Send primitive: Data.request

Page 69: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: client (UDP datagrams)

Application 2-69

ou

tTo

Se

rve

r

to network from network

inF

rom

Se

rve

r

inF

rom

Use

r

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCP socket

Clientprocess

To transport

layer

UDP socket

keyboard monitor

input stream

UDPpacket

UDPpacket

send

Pack

et

rece

iveP

acke

t

client UDP socket

inFr

omU

ser

Input: receives packet (recall that TCP received “byte stream”)

Output: sends packet (recall that TCP sent “byte stream”)

From transport layer

Page 70: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: Java client (UDP)import java.io.*; import java.net.*; class UDPClient { public static void main(String args[]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine();

sendData = sentence.getBytes();

createinput stream

create client socket

translate hostname to IP

address using DNS

Application 2-70

Page 71: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: Java client (UDP) (cont.)

DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); }

}

create T_IDU with A_PDU,

length, IP addr, port

send T_IDU

receive T_IDU

Application 2-71

A_PDUT_ICI

Send primitive: Data.request

Wait for primitive: Data.indication

create new T_IDU

T_IDU

Page 72: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: Java server (UDP)import java.io.*; import java.net.*; class UDPServer { public static void main(String args[]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

serverSocket.receive(receivePacket);

Create UDP socketat port 9876

(known by client)

create new T_IDU

receiveT_IDU

Application 2-72

Wait for primitive: Data.indication

Page 73: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Example: Java server (UDP) (cont.) String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase();

sendData = capitalizedSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); serverSocket.send(sendPacket); } }

}

get sender IP addr and port # from

T_ICI

Send T_IDU

end of while loop,loop back and wait foranother datagram

create T_IDU with A_PDU to

send, length, IP addr and port #

Application 2-73

Page 74: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

PROBLEMS AND EXERCISES

Computer Networking – Chapter 2: Application layer

Departamento deTecnología Electrónica

Application 2-74

Page 75: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr1: True or false?

Application 2-75

a) With non-persistent connections between browser and origin server, it is possible for a single TCP segment to carry two different HTTP request messages.

b) A user requests a Web page that consists of some text and two images. For this page, the client sends one request message and receives three response messages.

c) These two different Web pages www.mit.edu/index.html and www.dte.us.es/index.html can be sent over the same persistent connection.

d) The “Date:” header in the HTTP response message indicates when the object in the response was last modified.

e) HTTP response messages never have an empty message body.

Page 76: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr2: Application-Transport

Application 2-76

Consider an HTTP client that wants to retrieve a Web document from a given URL. HTTP server’s IP address is initially unknown. What transport and application-layer protocols besides HTTP are needed in this scenario?

Page 77: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr3: HTTP client headers

Application 2-77

Consider the following string of ASCll characters that were captured by Wireshark when the browser sent an HTTP GET message (i .e., this is the actual content of an HTTPGET message). The characters <cr><l/> are carriage return and line-feed characters (that is, the character string <cr> in the text below represents the single carriage-return character that was contained at that point in the HTTP header). Answer the following questions, indicating where in the HTTP GET message below you found the answer.

 GET /cs453/index.html HTTP/l.l<cr><lf>Host: gaia.cs.umass.edu<cr><lf>User-Agent: Mozilla/5.0 (WindowsiUi Windows NT 5.1i en-USi rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) <cr><lf>Accept:ext/xml, application/xml, application/xhtml+xml, text/htmliq=0.9, text/plain iq=0.8,image/png,*/*;q=0.5<cr><lf>Accept-Language: en-us,enjq=0.5<cr><lf>AcceptEncoding:zip,deflate<cr><lf>Accept-Charset: ISO-8859-1,utf-8;q=0.7,*jq=0.7<cr><lf>Keep-Alive: 300<cr><If>Connection:keep-alive<cr><lf><cr><lf>

a) What is the URL of the document requested by the browser?

b) What version of HTTP is the browser running?

c) Does the browser request a non-persistent or a persistent connection?

d) What is the IP address of the host on which the browser is running?

e) What type of browser initiates this message? Why is the browser type needed in an HTTP request message?

Page 78: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr4: HTTP server headers

Application 2-78

The text below shows the reply sent from the server in response to the HTTP GET message in the question above. Answer the following questions, pointing out where in the message below you found the answer.

HTTP/1.1 200 OK<cr><lf>Date: Tue, 07 Mar 2008 12:39:45GMT<cr><lf>Server: Apache/2.0.52 (Fedora) <cr><lf>Last-Modified: Sat, 10 Dec2005 18:27:46 GMT<cr><lf>ETag: "526c3-f22-a88a4c80"<cr><lf>AcceptRanges: bytes<cr><lf>Content-Length: 3874<cr><lf> Keep-Alive: timeout=max=100<cr><lf>Connection: Keep-Alive<cr><lf>Content-Type: text/html; charset= ISO-8859-1<cr><lf><cr><lf><!doctype html public "// w3c//dtd html 4.0 transitional//en"><lf><html><lf> <head><lf> <meta http- equiv="Content-Type“ content="text/htmlj charset=iso-8859-1"><lf> <meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0j U) Netscape]"><lf> <title>CMPSCI 453 / 591 / NTU-ST550A Spring 2005 homepage</title><lf></head><lf> <much more document text following here (not shown)

a) Was the server able to successfully find the document or not? What time was the document reply provided?

b) When was the document last modified?

c) How many bytes are there in the returned document?

d) What are the first 5 bytes of the returned document?

e) Did the server agree to a persistent connection?

Page 79: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr5: RTT with DNS (I)

Application 2-79

Suppose you click on a link within your Web browser to obtain a Web page. The IP address for the associated URL is not cached in your local host, so a DNS request is necessary to obtain the IP address. Suppose that RTT for a DNS request is RTTDNS.

Besides, suppose that the Web page associated with the link contains exactly one object, consisting of a small amount of HTML text (assume object transmission time = 0). Let RTT0 be the RTT between the local host and the Web server. How long does it take since the client clicks on the link until the client receives the object?

Page 80: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr6: RTT with DNS (II)

Application 2-80

Referring to Problem Pr5, suppose the HTML file references eight very small objects on the same server. Despite of transmission times, how long does it take to get the web page using:a)Non-persistent HTTP with no parallel TCP connections?b)Non-persistent HTTP with the browser configured for 5 parallel connections?c)Persistent HTTP?

Page 81: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr7: Proxy (I)This figure shows two networks (institutional and

public). The institutional network is a high speed LAN. A router in the institutional network and a router in the Internet are connected by 1.5 Mbps. The origin servers are attached to the Internet but are located all over the globe. Suppose that:

The average object size = 100 Kbits The average request rate from institution’s browsers

to origin servers = 15 requests/sec HTTP request message are negligibly small Delay from institutional router to any origin server

and back to router = 2 sec

We can calculate the following:a) utilization on LAN = 15%b) utilization on access link = 100%c) As access link uses is 100%, aL/R ~ 1, queues can

grow indefinitely and with them the associated delay. Total delay: increses indefinitely.

originservers

public Internet

Institutional network

10 Mbps LAN

1.5 Mbps access link

Application 2-81

Page 82: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr7: Proxy (II)One possible solution:increase bandwidth of access link to, say, 10 Mbpsconsequencesa)utilization on LAN ?b)utilization on access link ?c)average total delay ?d)Comments ?

Application 2-82

public Internet

Institutional network

10 Mbps LAN

10 Mbps access link

Page 83: Chapter 2 The Application layer Departamento de Tecnología Electrónica Computer Networking Some of these slides are given as copyrighted material from:

Pr7: Proxy (III)

Another possible solution:

Install proxy-cache server Success rate of 0.4:

40% requests replied by the proxy inmediately

60% requests forwared to the origin web servers

Consequences: utilization on LAN ? utilization on access link ? average total delay ? Comments ?

Originservers

PublicInternet

Institutionalnetwork 10 Mbps LAN

1.5 MbpsAccess link

Institutionalproxy

Aplicación 2-83