1 computer network application layer. 2 creating a network app write programs that run on different...

48
1 Computer Network Application Layer

Upload: claude-sutton

Post on 13-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

1

Computer Network

Application Layer

Page 2: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

2

Creating a network app

Write programs that run on different end

systems and communicate over a

network. e.g., Web: Web server

software communicates with browser software

little software written for devices in network core

network core devices do not run user application code

application on end systems allows for rapid app development, propagation

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

application

transportnetworkdata linkphysical

Page 3: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

3

Application architectures

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

Page 4: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

4

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

Page 5: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

5

Pure P2P architecture no always-on server arbitrary end systems

directly communicate peers are intermittently

connected and change IP addresses

example: Gnutella

Highly scalable but difficult to manage

Page 6: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

6

Hybrid of client-server and P2P

Skype Internet telephony app Finding address of remote party: centralized

server(s) Client-client connection is direct (not through server)

Instant messaging Chatting between two users is P2P Presence detection/location centralized:

User registers its IP address with central server when it comes online

User contacts central server to find IP addresses of buddies

Page 7: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

7

Processes communicating

Process: program running within a host.

within same host, two processes communicate using inter-process communication (defined by OS).

processes in different hosts communicate by exchanging messages

Client process: process that initiates communication

Server process: process that waits to be contacted

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

Page 8: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

8

Sockets

process sends/receives messages to/from its socket

socket analogous to door sending process shoves

message out door sending process relies on

transport infrastructure on other side of door which brings message to socket at receiving process

process

TCP withbuffers,variables

socket

host orserver

process

TCP withbuffers,variables

socket

host orserver

Internet

controlledby OS

controlled byapp developer

Page 9: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

9

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]proprietary(e.g. RealNetworks)proprietary(e.g., Vonage,Dialpad)

Underlyingtransport protocol

TCPTCPTCPTCPTCP or UDP

typically UDP

Page 10: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

10

Web and HTTP

First some jargon 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 Example URL:

www.someschool.edu/someDept/pic.gif

host name path name

Page 11: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

11

Architectural Overview

The parts of the Web model.

Page 12: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

12

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

HTTP 1.0: RFC 1945 HTTP 1.1: RFC 2068

PC runningExplorer

Server running

Apache Webserver

Mac runningNavigator

HTTP request

HTTP request

HTTP response

HTTP response

Page 13: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

13

HTTP request message

two types of HTTP messages: request, response

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 14: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

14

HTTP request message: general format

Page 15: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

15

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 16: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

16

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 server

404 Not Found requested document not found on this server

505 HTTP Version Not Supported

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

Page 17: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

17

Web caches (proxy server)

user sets browser: Web accesses via cache

browser sends all HTTP requests to cache

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 request

HTTP response

HTTP response

HTTP request

HTTP response

origin server

origin server

Page 18: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

18

More about Web caching Cache acts as

both client and server

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. Internet dense with

caches: enables “poor” content providers to effectively deliver content (but so does P2P file sharing)

Page 19: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

19

Dynamic Web Documents

Steps in processing the information from an HTML form.

PHP PHPPHP

Page 20: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

20

Client-Side Dynamic Web Page Generation (2)

(a) Server-side scripting with PHP.(b) Client-side scripting with JavaScript.

Page 21: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

21

FTP: the file transfer protocol

transfer file to/from remote host client/server model

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

server: remote host ftp: RFC 959 ftp server: port 21

file transfer FTPserver

FTPuser

interface

FTPclient

local filesystem

remote filesystem

user at host

Page 22: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

22

Electronic Mail

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

SMTP

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

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

Netscape Messenger outgoing, incoming messages

stored on server

user mailbox

outgoing message queue

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 23: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

23

Electronic Mail: mail servers

Mail Servers mailbox contains incoming

messages for user message queue of

outgoing (to be sent) mail messages

SMTP protocol between mail servers to send email messages

client: sending mail server

“server”: receiving mail server

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 24: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

24

Scenario: Alice sends message to Bob

1) 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 25: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

25

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: 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 26: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

26

DNS Why not centralize DNS? single point of failure traffic volume distant centralized

database maintenance

doesn’t scale!

DNS services Hostname to IP

address translation Host aliasing

Canonical and alias names

Mail server aliasing Load distribution

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

Page 27: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

27

Distributed, Hierarchical Database

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

DNS server Client queries amazon.com DNS server to get IP

address for www.amazon.com

Page 28: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

28

Local Name Server

Does not strictly belong to hierarchy Each ISP (residential ISP, company,

university) has one. Also called “default name server”

When a host makes a DNS query, query is sent to its local DNS server Acts as a proxy, forwards query into

hierarchy.

Page 29: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

29

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

Example

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

Page 30: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

30

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

3

Recursive 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”

Page 31: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

روال برقراري ارتباط بين دو برنامه از :راه دور

مشخص IPالف( درخواست برقراري ارتباط با كامپيوتري خاص با و برنامه اي روي آن كامپيوتر با آدرس پورت مشخص =

)(socketدرخواست فراخواني تابع سيستمي

در صورت برقراري )(recv و )(sendب( مبادله داده ها با توابع ارتباط

)(closeج( اتمام ارتباط با فراخواني تابع

Page 32: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

انواع سوكت و امفاهيم آنه

Connection اسوكتهاي اتصال گر= سوكتهاي نوع استريم •Oriented

سوكتهاي بدون اتصال= سوكتهاي نوع ديتاگرام •Connectionless

لزوم TCPسوكتهاي نوع استريم مبتني بر پروتكل تكاني ها به روش دست قبل از مبادله داده يك اتصالبرقراري

اي مرحله سه

مبادله داده UDPسوكتهاي نوع ديتاگرام مبتني بر پروتكل تضميني عدم ويبدون نياز به برقراري هيچ ارتباط و يا اتصال

ها ها و ترتيب داده ها، صحت داده بررسيدن داده

Page 33: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

سوكتهاي نوع ديتاگرام

كاربرد:

و انتقال صدا و تصوير يا سيستم

DNS

سوكتهاي نوع استريم

كاربرد:

FTP پروتكل انتقال فايل

پروتكل انتقال صفحات ابرمتنHTTP

پروتكل انتقال نامه هايSMTPالكترونيكي

Page 34: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

سeeوكت يeeك مفهeeوم انeeتزاعي از تعريeeف ارتبeeاط در •نويسي سطح برنامه

نويس برنeامه اعالم آمeادگي جهت مبادلeه داده هeا نوسeط •بeه سيسeتم عامeل بeدون درگeير شeدن بeا جزئيeات پروتكeل

TCP اeي UDP ادeايج تقاضeاي فضeا و منeابع مeورد نيeاز و از سيستم عاملجهت برقراري يك ارتباط

socket سوكت

Page 35: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

مشتري سرويس دهنده /

:تعريف عمومي

مشتري)clientپروسه ايست نيازمند اطالعات : ):)serverسرويس دهنده )

پروسه اي است براي به اشتراك گذاشتن اطالعات و تحويل اطالعات به مشتري

Page 36: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

Server Side برنامه سمت سرويس دهنده

دهنده نصب ميشود و اي است كه روي ماشين سرويس برنامهمنتظر است تا تقاضائي مبني بر برقراري يك ارتباط دريافت

كرده و پس از پردازش آن تقاضا ، پاسخ مناسب را ارسال سرويس دهنده شروع نمايد بنابراين در حالت كلي برنامه

.كننده يك ارتباط نيست

Page 37: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

Client Side برنامه هاي سمت مشتري

ابر نيeeاز، اقeeدام بeeه درخواسeeت بنee برنامeeه هeeاي سeeمت مشeeتريمي نمايند.اطالعات

تعeداد مشeتريها روي ماشeينهاي متفeاوت يeا حeتي روي يeك ماشeين تواند متعدد باشد مي

در و ليكن معمeوًالx تعeداد سeرويس دهنeده هeا يكي اسeت .)مگر سيستم هاي توزيع شده(

Client Server

Request For Information

Returned Information

ارتباط بين سرويس دهنده و مشتري

Page 38: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

دهنده الگوريتم كار برنامه سمت سرويس

:)(Socketالف( از UDP )يا TCPاعالم درخواست ارتباط و تعيين نوع آن )ا

سيستم عامل با اين تابع سيستمي

:)(Bindب( نسبت دادن يك آدرس پورت سوكتي كه باز كرده ايم

:Listen)(ج( با اين تابع به سيستم TCPاعالم شروع پذيرش تقاضاهاي ارتباط

TCPعامل و تعين حداكثر تعداد پذيرش ارتباط

)(Accept: د( با استفاده از اين تابع از تقاضاي معرفي يكي از ارتباطات معلق

سيستم عامل

)Send)(,recv): ه(مبادله داده

)(Close:و( قطع ارتباط دو طرفه ارسال و دريافت

قطع يك طرفه يكي از عمليات ارسال يا دريافت )(Shutdown:ز(

Page 39: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

الگوريتم كار برنامه سمت مشتري

)الف)(Socket: ايجاد يك سوكت )مشخصه يك ارتباط (

)ب)(Connect: تقاضاي برقراري ارتباط با سرويس دهنده

)ج)Send)(,recv):ارسال و دريافت داده ها

)د)(Close:. قطع ارتباط بصورت دو طرفه :Shutdown)( قطع ارتباط بصورت يك طرفه.

Page 40: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

توابع مورد استفاده در برنامه سمت سرويس دهندهTCP) مبتني بر(

socketتابع )(

Bind)( تابع

Accept)( تابع

Listen)( تابع

Send)(,recv)( توابع

Close)(,shutdown)( توابع

Page 41: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

85مهر

Connect)(تابع

socketتابع )(

Send)(,recv)( توابع

Close)(,shutdown)( توابع

(TCP مبتني بر) توابع مورد استفاده در برنامه مشتريپروتكل

Page 42: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

42

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 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 43: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

43

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

host orserver

process

TCP withbuffers,

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

Page 44: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

44

Socket programming with TCP

Client must contact server server process must first

be running server must have created

socket (door) that welcomes client’s contact

Client contacts server by: creating client-local 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

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

application viewpoint

Page 45: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

45

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 client socket,

connect to server

Createoutput stream

attached to socket

Page 46: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

46

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(); } }

Createinput stream

attached to socket

Send lineto server

Read linefrom server

Page 47: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

47

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()));

Createwelcoming socket

at port 6789

Wait, on welcomingsocket for contact

by client

Create inputstream, attached

to socket

Page 48: 1 Computer Network Application Layer. 2 Creating a network app Write programs that run on different end systems and communicate over a network. e.g.,

48

Example: Java server (TCP), cont

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

clientSentence = inFromClient.readLine();

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

outToClient.writeBytes(capitalizedSentence); } } }

Read in linefrom socket

Create outputstream,

attached to socket

Write out lineto socket

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