Computer Networks 364 Protocols

40
Computer Networks 364 Computer Networks 364 Protocols Protocols John Morris Computer Science/Electrical Engineering University of Auckland Email: [email protected] URL: http:/www.cs.auckland.ac.nz/~jmor159

description

Computer Networks 364 Protocols. John Morris Computer Science/Electrical Engineering University of Auckland Email: [email protected] URL: http:/www.cs.auckland.ac.nz/~jmor159. Protocols - HTTP. HyperText Transfer Protocol (HTTP) WWW application layer protocol - PowerPoint PPT Presentation

Transcript of Computer Networks 364 Protocols

Page 1: Computer Networks 364 Protocols

Computer Networks 364Computer Networks 364ProtocolsProtocols

John Morris

Computer Science/Electrical EngineeringUniversity of Auckland

Email: [email protected]: http:/www.cs.auckland.ac.nz/~jmor159

Page 2: Computer Networks 364 Protocols

Protocols - HTTPProtocols - HTTP► HyperText Transfer Protocol (HTTP)

WWW application layer protocol Client: browser (Netscape, Opera, that other one, … ) Server: a web server (source of Web pages - Apache, … ) Defines the language used by clients to request web pages

► RFC 2616 (HTTP/1.1) [ RFC 1945 (HTTP/1.0) ]

► Default port is 80

RFC = Request for CommentNow managed by the Internet Engineering Task Force (IETF)Over 2000 RFCsStandards for the Internet

Page 3: Computer Networks 364 Protocols

Protocols - HTTPProtocols - HTTP► HyperText Transfer Protocol (HTTP)

Web pages consist of a number of objects► Basic page► Embedded images, etc► Each object is fetched from the server in a single session

Open TCP connection GET message from client Response from server with object Close connection

► HTTP is stateless• Server does not keep track of state of session with client• Each request/response pair is independent of any other

• Suitable for information serving only applications• Transaction oriented applications

eg database update generally require some state to be maintained• HTTP makes it difficult to implement ‘safe’ transaction based systemsbut• Cookies provide a simple mechanism for maintaining state

Stateless protocols are simpler!

Page 4: Computer Networks 364 Protocols

Protocols - HTTPProtocols - HTTP► HyperText Transfer Protocol (HTTP)

Web pages consist of a number of objects► ...► Each object is fetched from the server in a single session

Open TCP connection GET message from client Response from server with object Close connection

► Obviously rather inefficient TCP connection establishment is expensive Persistent connections

► TCP connection is left open for subsequent requests► Further efficiency from pipelining

Send additional requests before first response received Allows browser to do useful work while server is fetching objects

► Parsing to discover embedded objects,► Formatting and displaying pages, etc

Page 5: Computer Networks 364 Protocols

HTTP exampleHTTP example

GET /somedir/page.html HTTP/1.1Host: www.someschool.eduConnection: closeUser-agent: Mozilla/4.0Accept-language:fr(extra carriage return, line feed)

Request line

Header lines}

Method

URL Version

Methods: GET POST HEAD

Page 6: Computer Networks 364 Protocols

HTTP request messagesHTTP request messagesGeneral form

Page 7: Computer Networks 364 Protocols

HTTP responseHTTP response

HTTP/1.1 200 OKConnection: closeDate: Thu, 06 Aug 1998 12:00:15 GMTServer: Apache/1.3.0 (Unix)Last-Modified: Mon, 22 Jun 1998 09:23:24 GMTContent-Length: 6821Content-Type: text/html

(data data data data data . . .)

Version

Status code

Status message Status line

Header lines

Entity body

Page 8: Computer Networks 364 Protocols

HTTP response - general formatHTTP response - general format

Page 9: Computer Networks 364 Protocols

HTTP response - common status codesHTTP response - common status codes► * 200 OK: Request succeeded and the information is returned in the

response.

► * 301 Moved Permanently: Requested object has been permanently moved; new URL is specified in Location: header of the response message. The client software will automatically retrieve the new URL.

► * 400 Bad Request: A generic error code indicating that the request could not be understood by the server.

► * 404 Not Found: The requested document does not exist on this server.

► * 505 HTTP Version Not Supported: The requested HTTP protocol version is not supported by the server.

Page 10: Computer Networks 364 Protocols

Try out http (client side) for yourselfTry out http (client side) for yourself

1. Telnet to your favorite Web server:

Opens TCP connection to port 80(default http server port) at www.eurecom.fr.Anything typed in sent to port 80 at www.eurecom.fr

telnet www.eurecom.fr 80

2. Type in a GET http request:

GET /~ross/index.html HTTP/1.0 By typing this in (hit carriagereturn twice), you sendthis minimal (but complete) GET request to http server

3. Look at response message sent by http server!

Page 11: Computer Networks 364 Protocols

User-server interaction: authenticationUser-server interaction: authentication

Authentication : control access to server content

► authorization credentials: typically name, password

► stateless: client must present authorization in each request authorization: header line

in each request if no authorization: header,

server refuses access, sendsWWW authenticate: header line in response

client serverusual http request

msg401: authorization req.

WWW authenticate:

usual http request msg+ Authorization:

<cred>usual http response msg

usual http request msg+ Authorization: <cred>

usual http response msg

time

Page 12: Computer Networks 364 Protocols

Cookies: keeping “state”Cookies: keeping “state”

► Server-generated # rembered by server

► Later used for: authentication remembering

► user preferences,► previous choices

► Server sends “cookie” to client in response msgSet-cookie: 1678453

► Client presents cookie in later requestscookie: 1678453

client serverusual http request msgusual http response +Set-cookie: #

usual http request msgcookie: #usual http response msg

usual http request msgcookie: #usual http response msg

cookie-spectificaction

cookie-spectificaction

Page 13: Computer Networks 364 Protocols

Conditional GET: client-side cachingConditional GET: client-side caching

► Goal Don’t send object if client has

up-to-date cached version► Client

specify date of cached copy in http request

If-modified-since: <date>► Server

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

HTTP/1.0 304 Not Modified

client serverhttp request msgIf-modified-since: <date>

http responseHTTP/1.0 304 Not Modified

object not modified

http request msgIf-modified-since: <date>

http responseHTTP/1.1 200 OK<data>

object modified

Page 14: Computer Networks 364 Protocols

Web Caches (proxy server)Web Caches (proxy server)

► User sets browser Web accesses via web cache

► Client sends all http requests to web cache Object in web cache

► web cache returns object else web cache requests object

from original server, returns object to client

GoalSatisfy client request without involving original server

client

Proxyserver

client

http request

http request

http response

http response

http request

http response

origin server

origin server

Page 15: Computer Networks 364 Protocols

Why Web Caching?Why Web Caching?

AssumeCache is “close” to clienteg in same network

Smaller response time Cache “closer” to client

Decrease traffic to distant servers Link out of local network often

bottleneck► Cache works on locality of reference

principle Recently used objects more likely to be

needed again► Temporal locality

Keep them ‘closer’ Processor caches use the same

principle (+ spatial locality!)

originservers

public Internet

institutionalnetwork 10 Mbps LAN

1.5 Mbps access link

institutionalcache

Page 16: Computer Networks 364 Protocols

FTP: File Transfer ProtocolFTP: File Transfer Protocol

► Transfer file(s) to/from remote host► Client/Server model

Client: side that initiates transfer (either to/from remote) Server: remote host

► RFC 959► ftp server: port 21

file transfer FTPserver

FTPuser

interfaceFTP

client

local filesystem

remote filesystem

user at host

21

Page 17: Computer Networks 364 Protocols

FTP: Separate Control and Data ConnectionsFTP: Separate Control and Data Connections

► FTP client contacts server at port 21 Specifies TCP as transport protocol

► Two parallel TCP connections opened: Control

► Exchange commands, responses between client and server

►Out of band control Data

► File data to / from server► FTP server maintains state

Current directory Earlier authentication

FTPclient

FTPserver

TCP control connection

port 21

TCP data connectionport 20

Page 18: Computer Networks 364 Protocols

FTP Commands and ResponsesFTP Commands and Responses

Sample commands:► Sent as ASCII text over control

channel USER username PASS password LIST

► Return list of files in current directory

RETR filename ► Retrieves (gets) file

STOR filename ► Stores (puts) file onto remote

host

Sample return codes► Status Code and Phrase (as in

http)► 331 Username OK, password

required► 125 data connection

already open; transfer starting

► 425 Can’t open data connection

► 452 Error writing file

Page 19: Computer Networks 364 Protocols

Electronic MailElectronic Mail

Three major components: ► User agents ► Mail servers ► Simple Mail Transfer Protocol:

SMTP

User Agent► Mail reader► Composing, editing, reading mail

messages► Examples

Eudora, Outlook, elm, Netscape Messenger

► Outgoing, incoming messages stored on server

user mailbox

outgoing message queue

useragent

mailserver

SMTP

SMTP

SMTP

mailserver

mailserver

useragent

useragent

useragent

useragent

useragent

Page 20: Computer Networks 364 Protocols

eMail: Mail serverseMail: Mail serversMail Servers ► Mailbox contains incoming

messages (yet to be read) for user► Message queue of outgoing (to be

sent) mail messages► SMTP protocol

Used between mail servers to send email messages

Client: sending mail server “Server”: receiving mail server

useragent

mailserver

SMTP

SMTP

SMTP

mailserver

mailserver

useragent

useragent

useragent

useragent

useragent

Page 21: Computer Networks 364 Protocols

eMail: SMTPeMail: SMTP

► RFC 821 First published: 1982

► Uses TCP to reliably transfer email message► Port 25► Direct transfer

Sending server to receiving server► Three phases of transfer

Handshaking (greeting) Transfer of messages Closure

► Command/response interaction Commands: ASCII text Response: status code and phrase

► Messages must be in 7-bit ASCII Legacy of 1982 Binary data must be encoded before transfer

Page 22: Computer Networks 364 Protocols

Sample SMTP interactionSample SMTP interaction

S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <[email protected]> S: 250 [email protected]... Sender ok C: RCPT TO: <[email protected]> S: 250 [email protected] ... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connection

This is why 7-bit ASCII

is required!

Page 23: Computer Networks 364 Protocols

Try SMTP yourselfTry SMTP yourself► telnet servername 25

See 220 reply from server Enter

► HELO ► MAIL FROM ► RCPT TO► DATA► QUIT► HELP

commands You can send email

Using telnet to send commands yourself By writing a simple program to do it for you!

Try making a simple Java mail sender

Page 24: Computer Networks 364 Protocols

SMTP: Final WordsSMTP: Final Words► Uses persistent connections► Requires message (header &

body) to be in 7-bit ASCII► Certain character strings not

permitted in message Example

► CRLF.CRLF Thus message has to be encoded

► Usually base-64 or quoted printable

Server uses CRLF.CRLF to determine end of message

Comparison with HTTP:► HTTP: pull► eMail: push► Command and response,

interaction and status codes

All ASCII in both

► HTTP Each object encapsulated in its

own response message► SMTP

Multiple objects sent in multipart message

Page 25: Computer Networks 364 Protocols

header

body

Mail message formatMail message format

RFC 821SMTP protocol for exchanging email messages

RFC 822Text message format Header lines, e.g.

► To:► From:► Subject:

Different from SMTP commands!Defines semantics (interpretation)

also► Body

The “message” ASCII characters only!

blankline

Page 26: Computer Networks 364 Protocols

Message format: Multimedia extensionsMessage format: Multimedia extensions

► RFC 822 format OK for text messages Inefficient for multimedia

Multipurpose Internet Mail Extensions (MIME) RFC 2045, 2056

► Additional lines in message header declare MIME content type

From: [email protected] To: [email protected] Subject: Picture of yummy crepe MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg

base64 encoded data ..... ......................... ......base64 encoded data

Multimedia datatype, subtype, parameters

Method usedto encode data

MIME version

Encoded data

Page 27: Computer Networks 364 Protocols

MIME typesMIME typesContent-Type: type/subtype; parametersContent-Type: type/subtype; parameters

Text► Subtypes: plain, html, ...

Image► Subtypes: jpeg, gif

Audio► Subtypes

basic ► 8-bit -law encoded

32kadpcm► 32 Kbps coding (RFC 1911)

Video► Subtypes: mpeg, quicktime

Application► Other data that must be

processed by reader before becoming “viewable”

► Subtypes msword octet-stream

► Arbitrary binary data

Page 28: Computer Networks 364 Protocols

MIME: Multipart TypeMIME: Multipart Type

From: [email protected] To: [email protected] Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=98766789 --98766789Content-Transfer-Encoding: quoted-printableContent-Type: text/plain

Dear Bob, Please find a picture of a crepe.--98766789Content-Transfer-Encoding: base64Content-Type: image/jpeg

base64 encoded data ..... ......................... ......base64 encoded data --98766789--

Arbitrary ASCII stringwhich definesboundaries of a part

Page 29: Computer Networks 364 Protocols

Mail Access ProtocolsMail Access Protocols

► SMTP: delivery to and storage on receiver’s server► Mail access protocol: retrieval from server

POP: Post Office Protocol [RFC 1939]► Simple, limited functions► Authorization (agent server) and download

IMAP: Internet Mail Access Protocol [RFC 2060]► More features (more complex)► Manipulation of stored messages on server

Set up, search folders, etc HTTP: Hotmail , Yahoo! Mail, etc

useragent

sender’s mail server

useragent

SMTP SMTP POP3 orIMAP

receiver’s mail server

Page 30: Computer Networks 364 Protocols

POP3 ProtocolPOP3 Protocol

Authorization phase► Client commands:

user: declare username pass: password

► Server responses +OK -ERR

Transaction phaseclient:► list: list message numbers► retr: retrieve message by number► dele: delete► quit

C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> S: . C: dele 1 C: retr 2 S: <message 1 contents> S: . C: dele 2 C: quit S: +OK POP3 server signing off

S: +OK POP3 server ready C: user alice S: +OK C: pass hungry S: +OK user successfully logged on

Page 31: Computer Networks 364 Protocols

DNS: Domain Name SystemDNS: Domain Name System

People: Many identifiers: IRD #, name, passport #

Internet hosts, routers: IP address (32 bit)

► Used for in datagrams “name” eg gaia.cs.umass.edu

► Used by humans(with some exceptions!)

? Map between IP addresses and name?

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

Complexity at network’s “edge”

Page 32: Computer Networks 364 Protocols

DNS name serversDNS name servers

► No server has all name IP address mappings

Local name servers: Each ISP, company has local

(default) name server DNS query first goes to local

name serverAuthoritative name server:

For a host: stores that host’s IP address, name

Can perform name/address translation for that host’s name

Why not centralize DNS?► Single point of failure► Congestion

Traffic volume on central server

► Distance Time to reach centralized

database► Maintenance

Doesn’t scale!

Page 33: Computer Networks 364 Protocols

DNS: Root Name ServersDNS: Root Name Servers

► Contacted by local name server that can not resolve name► Root Name Server:

Contacts authoritative name server if name mapping not known Gets mapping Returns mapping to local name server

b USC-ISI Marina del Rey, CAl ICANN Marina del Rey, CA

e NASA Mt View, CAf Internet Software C. Palo Alto, CA

i NORDUnet Stockholm

k RIPE London

m WIDE Tokyo

a NSI Herndon, VAc PSInet Herndon, VAd U Maryland College Park, MDg DISA Vienna, VAh ARL Aberdeen, MDj NSI (TBD) Herndon, VA

13 root name servers worldwide

Page 34: Computer Networks 364 Protocols

Simple DNS exampleSimple DNS example

Host surf.eurecom.fr wants IP address of gaia.cs.umass.edu

1. Contacts its local DNS server, dns.eurecom.fr

2. dns.eurecom.fr contacts root name server, if necessary

3. Root name server contacts authoritative name server, dns.umass.edu, if necessary

requesting hostsurf.eurecom.fr

gaia.cs.umass.edu

root name server

authorititive name serverdns.umass.edulocal name server

dns.eurecom.fr

1

23

45

6

Page 35: Computer Networks 364 Protocols

DNS exampleDNS example

Root name server:► May not know

authoritative name server

► May know intermediate name server: who to contact to find authoritative name server

requesting hostsurf.eurecom.fr

gaia.cs.umass.edu

root name server

local name serverdns.eurecom.fr

1

23

4 5

6

authoritative name serverdns.cs.umass.edu

intermediate name serverdns.umass.edu

7

8

Page 36: Computer Networks 364 Protocols

DNS: iterated queriesDNS: iterated queries

Recursive query:► Puts burden of name

resolution on contacted name server

Heavy load?

Iterated query:► Contacted server

replies with name of server to contact

► “I don’t know this name, but ask this server” requesting host

surf.eurecom.fr

gaia.cs.umass.edu

root name server

local name serverdns.eurecom.fr

1

23

4

5 6

authoritative name serverdns.cs.umass.edu

intermediate name serverdns.umass.edu

7

8

iterated query

Page 37: Computer Networks 364 Protocols

DNS: Caching and updating recordsDNS: Caching and updating records

► Once (any) name server learns mapping, it caches mapping Cache entries timeout (disappear) after some time

► Update/notify mechanisms being designed by IETF RFC 2136 http://www.ietf.org/html.charters/dnsind-charter.html

Page 38: Computer Networks 364 Protocols

DNS recordsDNS records

DNS: Distributed database storing resource records (RR)

► Type=NS name is domain (eg foo.com) value is IP address of

authoritative name server for this domain

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

► Type=A name is hostname value is IP address

► Type=CNAME name is alias name for some

“cannonical” (real) name► www.ibm.com is really servereast.backup2.ibm.com

value is cannonical name

► Type=MX value is name of mailserver

associated with name

Page 39: Computer Networks 364 Protocols

DNS protocol, messagesDNS protocol, messagesDNS protocol

query and reply messagesboth with same message format

Message header► identification

16 bit # for query, reply to query uses same #

► flags query or reply recursion desired recursion available reply is authoritative

Page 40: Computer Networks 364 Protocols

DNS protocol, messagesDNS protocol, messages

Name, type fields for a query

RRs in reponseto query

records forauthoritative servers

additional “helpful”info that may be used