Top Banner
2: Application Layer Session No.2 Application Layer
48
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: TCP/IP Application layer

2: Application Layer

Session No.2

Application Layer

Page 2: TCP/IP Application layer

2: Application Layer

Chapter 2: Application layerr 2.1 Principles of

network applicationsr 2.2 Web and HTTPr 2.3 FTP r 2.4 Electronic Mail

❖ SMTP, POP3, IMAPr 2.5 DNSr 2.6 Socket

programming with TCPr 2.7 Socket

programming with UDP

Page 3: TCP/IP Application layer

2: Application Layer

Chapter 2: Application LayerOur goals: r conceptual,

implementation aspects of network application protocols❖ transport-layer

service models❖ client-server

paradigm❖ peer-to-peer

paradigm

r learn about protocols by examining popular application-level protocols❖ HTTP❖ FTP❖ SMTP / POP3 / IMAP❖ DNS

r programming network applications❖ socket API

Page 4: TCP/IP Application layer

2: Application Layer

Some network apps

r e-mailr webr instant messagingr remote loginr P2P file sharingr multi-user network

gamesr streaming stored video

clips

r voice over IPr real-time video

conferencingr r r

Page 5: TCP/IP Application layer

2: Application Layer

Creating a network appwrite 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

applicationtransportnetworkdata linkphysical

applicationtransportnetworkdata linkphysical

applicationtransportnetworkdata linkphysical

Page 6: TCP/IP Application layer

2: Application Layer

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTPr 2.3 FTP r 2.4 Electronic Mail

❖ SMTP, POP3, IMAPr 2.5 DNS

r 2.6Socket programming with TCP

r 2.7 Socket programming with UDP

Page 7: TCP/IP Application layer

2: Application Layer

Application architectures

r Client-serverr Peer-to-peer (P2P)r Hybrid of client-server and P2P

Page 8: TCP/IP Application layer

2: Application Layer

Client-server architectureserver:

❖ always-on host❖ permanent IP address

clients:❖ communicate with server❖ may be intermittently

connected❖ may have dynamic IP

addresses❖ do not communicate

directly with each other

client/server

Page 9: TCP/IP Application layer

2: Application Layer

Pure P2P architecture

r no always-on serverr arbitrary end systems

directly communicater peers are intermittently

connected and change IP addresses

Highly scalable but difficult to manage

peer-peer

Page 10: TCP/IP Application layer

2: Application Layer

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

Page 11: TCP/IP Application layer

2: Application Layer

Chapter 2: Application layer

r 2.1 Principles of network applications ❖ app architectures

r 2.2 Web and HTTPr 2.4 Electronic Mail

❖ SMTP, POP3, IMAPr 2.5 DNS

r 2.6 Socket programming with TCP

r 2.7 Socket programming with UDP

Page 12: TCP/IP Application layer

2: Application Layer

Web and HTTP

First some jargonr Web page consists of objectsr Object can be HTML file, JPEG image, Java

applet, audio file,…r Web page consists of base HTML-file which

includes several referenced objectsr Each object is addressable by a URLr Example URL:

www.someschool.edu/someDept/pic.gif

host name path name

Page 13: TCP/IP Application layer

2: Application Layer

HTTP overview

HTTP: hypertext transfer protocol

r Web’s application layer protocol

r client/server model❖ client: browser that

requests, receives, “displays” Web objects

❖ server: Web server sends objects in response to requests

PC runningExplorer

Server running

Apache Webserver

Mac runningNavigator

HTTP request

HTTP request

HTTP response

HTTP response

Page 14: TCP/IP Application layer

2: Application Layer

HTTP overview (continued)

Uses TCP:r client initiates TCP

connection (creates socket) to server, port 80

r server accepts TCP connection from client

r HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server)

r TCP connection closed

HTTP is “stateless”r server maintains no

information about past client requests

Protocols that maintain “state” are complex!

r past history (state) must be maintained

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

aside

Page 15: TCP/IP Application layer

2: Application Layer

HTTP connections

Nonpersistent HTTPr At most one object is

sent over a TCP connection.

Persistent HTTPr Multiple objects can

be sent over single TCP connection between client and server.

Page 16: TCP/IP Application layer

2: Application Layer

HTTP request message

r two types of HTTP messages: request, responser HTTP request message:

❖ ASCII (human-readable format)

GET /somedir/page.html HTTP/1.1Host: www.someschool.edu User-agent: Mozilla/4.0Connection: close Accept-language:fr

(extra carriage return, line feed)

request line(GET, POST,

HEAD commands)

header lines

Carriage return, line feed

indicates end of message

Page 17: TCP/IP Application layer

2: Application Layer

HTTP response message

HTTP/1.1 200 OK Connection closeDate: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 …... Content-Length: 6821 Content-Type: text/html data data data data data ...

status line(protocol

status codestatus phrase)

header lines

data, e.g., requestedHTML file

Page 18: TCP/IP Application layer

2: Application Layer

HTTP response status codes

200 OK❖ request succeeded, requested object later in this message

301 Moved Permanently❖ requested object moved, new location specified later in

this message (Location:)400 Bad Request

❖ request message not understood by server404 Not Found

❖ requested document not found on this server505 HTTP Version Not Supported

In first line in server->client response message.A few sample codes:

Page 19: TCP/IP Application layer

2: Application Layer

User-server state: cookies

Many major Web sites use cookies

Four components:1) cookie header line of

HTTP response message2) cookie header line in

HTTP request message3) cookie file kept on user’

s host, managed by user’s browser

4) back-end database at Web site

Example:r Susan always access

Internet always from PCr visits specific e-

commerce site for first time

r when initial HTTP requests arrives at site, site creates: ❖ unique ID❖ entry in backend

database for ID

Page 20: TCP/IP Application layer

2: Application Layer

Cookies (continued)What cookies can bring:r authorizationr shopping cartsr recommendationsr user session state

(Web e-mail)

Cookies and privacy:r cookies permit sites to

learn a lot about your you may supply name

and e-mail to sites

aside

How to keep “state”:r protocol endpoints: maintain state

at sender/receiver over multiple transactions

r cookies: http messages carry state

Page 21: TCP/IP Application layer

2: Application Layer

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTPr 2.3 FTP r 2.4 Electronic Mail

❖ SMTP, POP3, IMAPr 2.5 DNS

r 2.6Socket programming with TCP

r 2.7 Socket programming with UDP

Page 22: TCP/IP Application layer

2: Application Layer

FTP: the file transfer protocol

r transfer file to/from remote hostr client/server model

❖ client: side that initiates transfer (either to/from remote)

❖ server: remote hostr ftp: RFC 959r ftp server: port 21

file transfer FTPserver

FTPuser

interface

FTPclient

local filesystem

remote filesystem

user at host

Page 23: TCP/IP Application layer

2: Application Layer

FTP: separate control, data connections

r FTP client contacts FTP server at port 21, TCP is transport protocol

r client authorized over control connection

r client browses remote directory by sending commands over control connection.

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

r after transferring one file, server closes data connection.

FTPclient

FTPserver

TCP control connectionport 21

TCP data connectionport 20

r server opens another TCP data connection to transfer another file.

r control connection: “out of band”

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

Page 24: TCP/IP Application layer

2: Application Layer

FTP commands, responses

Sample commands:r sent as ASCII text over

control channelr USER usernamer PASS password

r LIST return list of file in current directory

r RETR filename retrieves (gets) file

r STOR filename stores (puts) file onto remote host

Sample return codesr status code and phrase (as

in HTTP)r 331 Username OK,

password requiredr 125 data connection

already open; transfer starting

r 425 Can’t open data connection

r 452 Error writing file

Page 25: TCP/IP Application layer

2: Application Layer

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTPr 2.3 FTP r 2.4 Electronic Mail

❖ SMTP, POP3, IMAPr 2.5 DNS

r 2.6 Socket programming with TCP

r 2.7 Socket programming with UDP

Page 26: TCP/IP Application layer

2: Application Layer

Electronic Mail

Three major components: r user agents r mail servers r simple mail transfer

protocol: SMTP

User Agentr a.k.a. “mail reader”r composing, editing, reading

mail messagesr e.g., Eudora, Outlook, elm,

Mozilla Thunderbirdr outgoing, incoming messages

stored on server

user mailbox

outgoing message queue

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 27: TCP/IP Application layer

2: Application Layer

Electronic Mail: mail servers

Mail Servers r mailbox contains incoming

messages for userr message queue of outgoing

(to be sent) mail messagesr SMTP protocol between mail

servers to send email messages❖ client: sending mail

server❖ “server”: receiving mail

server

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 28: TCP/IP Application layer

2: Application Layer

Electronic Mail: SMTP [RFC 2821]

r uses TCP to reliably transfer email message from client to server, port 25

r direct transfer: sending server to receiving server

r three phases of transfer❖ handshaking (greeting)❖ transfer of messages❖ closure

r command/response interaction❖ commands: ASCII text❖ response: status code and phrase

Page 29: TCP/IP Application layer

2: Application Layer

Scenario: Alice sends message to Bob1) Alice uses UA to compose

message and “to” [email protected]

2) Alice’s UA sends message to her mail server; message placed in message queue

3) Client side of SMTP opens TCP connection with Bob’s mail server

4) SMTP client sends Alice’s message over the TCP connection

5) Bob’s mail server places the message in Bob’s mailbox

6) Bob invokes his user agent to read message

useragent

mailserver

mailserver user

agent

1

2 3 4 56

Page 30: TCP/IP Application layer

2: Application Layer

Mail message format

SMTP: protocol for exchanging email msgs

RFC 822: standard for text message format:

r header lines, e.g.,❖ To:❖ From:❖ Subject:different from SMTP

commands!r body

❖ the “message”, ASCII characters only

header

body

blankline

Page 31: TCP/IP Application layer

2: Application Layer

Mail access protocols

r SMTP: delivery/storage to receiver’s serverr Mail access protocol: retrieval from server

❖ POP: Post Office Protocol [RFC 1939]• authorization (agent <-->server) and download

❖ IMAP: Internet Mail Access Protocol [RFC 1730]• more features (more complex)• manipulation of stored msgs on server

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

useragent

sender’s mail server

useragent

SMTP SMTP accessprotocol

receiver’s mail server

Page 32: TCP/IP Application layer

2: Application Layer

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTPr 2.3 FTP r 2.4 Electronic Mail

❖ SMTP, POP3, IMAPr 2.5 DNS

r 2.6 Socket programming with TCP

r 2.7 Socket programming with UDP

Page 33: TCP/IP Application layer

2: Application Layer

DNS: Domain Name System

People: many identifiers:❖ SSN, name, passport #

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

used for addressing datagrams

❖ “name”, e.g., ww.yahoo.com - used by humans

Q: map between IP addresses and name ?

Domain Name System:r distributed database

implemented in hierarchy of many name servers

r 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 34: TCP/IP Application layer

2: Application Layer

DNS Why not centralize DNS?r single point of failurer traffic volumer distant centralized

databaser maintenance

doesn’t scale!

DNS servicesr hostname to IP

address translationr host aliasing

❖ Canonical, alias namesr mail server aliasingr load distribution

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

Page 35: TCP/IP Application layer

2: Application Layer

Root DNS Servers

com DNS servers org DNS servers edu DNS servers

poly.eduDNS servers

umass.eduDNS serversyahoo.com

DNS serversamazon.comDNS servers

pbs.orgDNS servers

Distributed, Hierarchical Database

Client wants IP for www.amazon.com; 1st approx:r client queries a root server to find com DNS serverr client queries com DNS server to get amazon.com

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

address for www.amazon.com

Page 36: TCP/IP Application layer

2: Application Layer

DNS: Root name serversr contacted by local name server that can not resolve namer root name server:

❖ contacts authoritative name server if name mapping not known❖ gets mapping❖ returns mapping to local name server

13 root name servers worldwide

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

e NASA Mt View, CAf Internet Software C. Palo Alto, CA (and 36 other locations)

i Autonomica, Stockholm (plus 28 other locations)

k RIPE London (also 16 other locations)

m WIDE Tokyo (also Seoul, Paris, SF)

a Verisign, Dulles, VAc Cogent, Herndon, VA (also LA)d U Maryland College Park, MDg US DoD Vienna, VAh ARL Aberdeen, MDj Verisign, ( 21 locations)

Page 37: TCP/IP Application layer

2: Application Layer

requesting hostcis.poly.edu

gaia.cs.umass.edu

root DNS server

local DNS serverdns.poly.edu

1

23

4

5

6

authoritative DNS serverdns.cs.umass.edu

78

TLD DNS server

DNS name resolution example

r Host at cis.poly.edu wants IP address for gaia.cs.umass.edu

iterated query:r contacted server

replies with name of server to contact

r “I don’t know this name, but ask this server”

Page 38: TCP/IP Application layer

2: Application Layer

requesting hostcis.poly.edu

gaia.cs.umass.edu

root DNS server

local DNS serverdns.poly.edu

1

2

45

6

authoritative DNS serverdns.cs.umass.edu

7

8

TLD DNS server

3recursive query:r puts burden of name

resolution on contacted name server

r heavy load?

DNS name resolution example

Page 39: TCP/IP Application layer

2: Application Layer

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTPr 2.3 FTP r 2.4 Electronic Mail

❖ SMTP, POP3, IMAPr 2.5 DNS

r 2.6 Socket programming with TCP

r 2.8 Socket programming with UDP

Page 40: TCP/IP Application layer

2: Application Layer

Socket programming

Socket APIr introduced in BSD4.1 UNIX,

1981r explicitly created, used,

released by apps r client/server paradigm r two types of transport

service via socket API: ❖ unreliable datagram ❖ reliable, byte stream-

oriented

a host-local, application-created,

OS-controlled interface (a “door”) into which

application process can both send and

receive messages to/from another application

process

socket

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

Page 41: TCP/IP Application layer

2: Application Layer

Socket-programming using TCPSocket: 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

host orserver

process

TCP withbuffers,variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

Page 42: TCP/IP Application layer

2: Application Layer

Socket programming with TCPClient must contact serverr server process must first

be runningr server must have created

socket (door) that welcomes client’s contact

Client contacts server by:r creating client-local TCP

socketr specifying IP address, port

number of server processr When client creates

socket: client TCP establishes connection to server TCP

r 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

Page 43: TCP/IP Application layer

2: Application Layer

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

Page 44: TCP/IP Application layer

2: Application Layer

Chapter 2: Application layer

r 2.1 Principles of network applications

r 2.2 Web and HTTPr 2.3 FTP r 2.4 Electronic Mail

❖ SMTP, POP3, IMAPr 2.5 DNS

r 2.6 Socket programming with TCP

r 2.7 Socket programming with UDP

Page 45: TCP/IP Application layer

2: Application Layer

Socket programming with UDP

UDP: no “connection” between client and server

r no handshakingr sender explicitly attaches

IP address and port of destination to each packet

r server must extract IP address, port of sender from received packet

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

application viewpointUDP provides unreliable transfer of groups of bytes (“datagrams”)

between client and server

Page 46: TCP/IP Application layer

2: Application Layer

Chapter 2: Summary

r application architectures❖ client-server❖ P2P❖ hybrid

r application service requirements:❖ reliability, bandwidth,

delay

our study of network apps now complete!r specific protocols:

❖ HTTP❖ FTP❖ SMTP, POP, IMAP❖ DNS

r socket programming

Page 47: TCP/IP Application layer

2: Application Layer

Chapter 2: Summary

r typical request/reply message exchange:❖ client requests info or

service❖ server responds with

data, status coder message formats:

❖ headers: fields giving info about data

❖ data: info being communicated

Most importantly: learned about protocols

Important themes: r control vs. data msgs

❖ in-band, out-of-bandr centralized vs.

decentralized r stateless vs. statefulr reliable vs. unreliable

msg transfer r “complexity at network

edge”

Page 48: TCP/IP Application layer

2: Application Layer

That’s all for today!

Any questions?

Thank you!