Presentation3

Download Report

Transcript Presentation3

Department of Computer and IT Engineering
University of Kurdistan
Computer Networks II
Application Layer
By: Dr. Alireza Abdollahpouri
‫‪Application Layer‬‬
‫الیه کاربرد مستقیما با کاربر (برنامه ها یا اشخاص) در ارتباط است‪ .‬این الیه از طریق پروتکلهاي مختلفی‬
‫که در اختیار دارد‪ ،‬خدمات مورد نیاز کاربران را فراهم میآورد‪ .‬هر کدام از پروتکلهاي این الیه بسته به نوع‬
‫و ماهیت آنها از یکی از پروتکلهاي ‪ TCP‬یا ‪ UDP‬در الیه پایینتر استفاده میکنند‪.‬‬
‫‪2‬‬
3
‫‪Application-Layer Protocols‬‬
‫مشهورترین پروتكلهاي اين اليه عبارتند از‪:‬‬
‫‪ :FTP‬پروتكلي براي انتقال فايل‬
‫‪ :HTTP‬پروتكلي براي دسترس ي به صفحات وب‬
‫‪ :DNS‬پروتكلي براي ترجمه نامهاي نمادين به آدرسهاي ‪IP‬‬
‫‪ :Telnet‬پروتكلي براي ورود به سيستم از راه دور‬
‫‪ SMTP‬و ‪ :POP3‬پروتكلهايي براي ارسال و دريافت ‪E-‬‬
‫‪mail‬‬
‫‪4‬‬
Applications and Application-Layer Protocols
Application: communicating, distributed
processes
 e.g., e-mail, Web, P2P file
sharing, instant messaging
 running in end systems (hosts)
 exchange messages to
implement application
Application-layer protocols
 one “piece” of an app
 define messages exchanged
by apps and actions taken
 use communication services
provided by lower layer
protocols (TCP, UDP)
application
transport
network
data link
physical
modem
modem
application
transport
network
data link
physical
application
transport
network
data link
physical
5
Client-Server Paradigm
Typical network app has two
pieces: client and server
Client:



initiates contact with server
(“speaks first”)
typically requests service from
server,
Web: client implemented in
browser; e-mail: in mail reader
Server:


applicatio
transport
network
data link
physical
provides requested service to client
e.g., Web server sends requested Web
page, mail server delivers e-mail
modem
modem
request
reply
applicatin
transport
network
data link
physical
6
Processes Communicating Across Network
 process sends/receives
messages to/from its
socket
 socket analogous to door
 sending process pushes
message out door
 sending process assumes
transport infrastructure on
other side of door which
brings message to socket
at receiving process
host or
server
host or
server
controlled by
app developer
process
process
socket
socket
TCP with
buffers,
variables
TCP with
buffers,
variables
Internet
controlled
by OS
7
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”
Bandwidth
 some apps (e.g.,
multimedia) require
minimum amount of
bandwidth to be
“effective”
 other apps (“elastic
apps”) make use of
whatever bandwidth
they get
8
Requirements of Selected Network Applications
Application
Data loss
Bandwidth
Time
Sensitive
file transfer
no loss
elastic
no
e-mail
no loss
elastic
no
web documents
no loss
elastic (few kbps)
no
real-time
audio/video
losstolerant
audio: few kbps-1Mbps
video:10kbps-5Mbps
yes, 100s of
msec
stored
audio/video
losstolerant
same as above
yes, few sec
interactive
games
losstolerant
few kbps-10kbps
yes, 100s of
msec
instant
messaging
no loss
elastic
yes and no
9
Internet Transport Protocols Services
TCP service:
UDP 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
no guarantee on: timing,
minimum bandwidth

unreliable data transfer
between sending and
receiving process
does not provide:
connection setup,
reliability, flow control,
congestion control, timing,
or bandwidth guarantee
10
Internet apps: application, transport protocols
applications
application-layer underlying transport
protocol
protocol
e-mail
SMTP [RFC 2821]
TCP
remote terminal access
Telnet [RFC 854]
TCP
web
HTTP [RFC 2616]
TCP
file transfer
FTP [RFC 959]
TCP
Name server
DNS [ RFC 1034]
UDP or TCP
streaming multimedia
proprietary
(e.g., youtube)
Typically UDP
11
Connectionless iterative server
UDP
12
Connection-oriented concurrent server
TCP
13
Sockets
Client process
Server process
Server IP Address
&
Port Number1
Welcoming
socket
send read
Client
socket
Client IP Address
&
Port Number
read write
bytes
Connection
socket
Server IP Address
&
Port Number2
14
Domain Name System
(DNS)
15
‫در اولين سالهاي راه اندازي شبكه اينترنت‪ ،‬راه حل بسيار ساده اي براي ترجمه نامهاي‬
‫نمادين به آدرس‪ IP‬وجود داشت و آن تعريف تمام نامها و آدرسهاي‪ IP‬معادل‪ ،‬در يك‬
‫فايل بنام ‪ hosts.txt‬بود‪ .‬اين فايل داراي دو ستون بود كه در يك طرف آدرس نمادين و‬
‫در طرف ديگر آدرس‪ IP‬معادل آن نوشته شده بود‪ .‬به دليل اينكه در آن تاريخ تعداد‬
‫آدرسها زياد نبود‪ ،‬حجم چنين فايلي چندان بزرگ نميشد و هر ماشين ميزبان مي توانست‬
‫يك نسخه از اين فايل را در اختيار داشته باشد و سـاعت ‪ 24‬هر شب اين فايل را از روي‬
‫فايل مرجع تازهسازي و بهروز ميكرد تا هر گونه تغيير احتمالي و تعريف آدرسهاي جديد‬
‫اعمال شود‪ .‬بديهي است كه امروزه با حجم ميليوني آدرسها در اينترنت‪ ،‬داشتن يك فايل‬
‫متمركز و قرار دادن تمام آدرسها و معادل آدرس‪ IP‬در آن‪ ،‬امكان پذير نيست‪.‬‬
‫راه حل‪ :‬استفاده از یک پایگاه داده سلسله مراتبی توزیع شده‬
‫‪16‬‬
Hierarchical Distributed Name Space
Root Server
‫ عدد سرویس دهنده ریشه وجود دارد‬13 ‫تعداد‬
17
DNS root Servers
18
DNS root Servers
19
Domains
20
DNS in the Internet
The inverse domain is
used to map an IP
address to a name
21
Generic domains
Description
com Commercial organizations
edu
Educational institutions
gov
Government institutions
int
International organizations
mil
Military groups
net
Network support centers
org
Nonprofit organizations
22
‫‪Country domains‬‬
‫پژوهشگاه دانشهای بنیادی در تهران‬
‫مسئولیت کنترل دامنه ‪ ir‬و زیر دامنه های‬
‫آن را به عهده دارد‬
‫‪http://www.nic.ir/‬‬
‫‪23‬‬
‫‪Recursive resolution‬‬
‫پرس و جوي تکراري‬
‫قسمت اعظم تالش براي‬
‫تبدیل یک نام برعهده‬
‫سرویس دهنده محلی‬
‫است‬
‫‪24‬‬
DNS Protocol: Forward Lookup Query
IP Address of www.icann.org is
142.12.01.23
Authorized name
server for org. zone
org.
Root
Name
Server
“ .”
edu.
ir.
com.
ac.ir.
www.icann.org.
Local
Name Server
uok.ac.ir.
Client
Forward Lookup Query:
What is IP Address of www.icann.org
25
Iterative resolution
‫پرس و جوي بازگشتی‬
26
Query and response messages
27
Note:
DNS can use the services of
UDP or TCP,
using the well-known port 53.
28
‫‪HTTP and WWW‬‬
‫وب جهان گستر و پروتکل انتقال صفحات ابرمتن‬
‫‪29‬‬
World Wide Web
Distributed services
30
Hypertext
31
Browser architecture
Interpreter
32
Categories of Web documents
33
Static document
34
Dynamic document
35
Active document
36
Web and HTTP
 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:
eng.uok.ac.ir/abdollahpouri/index.html
host name
path name
37
HTTP Overview
Server
running
Apache Web
server
HTTP: hypertext transfer
protocol




Web’s app 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 running
Explorer
Storage
contents:
base files,
objects
Mac running
Navigator
38
Note:
HTTP uses the services of TCP on
well-known port 80.
39
HTTP Overview (cont.)
Uses TCP:




client initiates TCP
connection (creates socket)
to server, port 80
server accepts TCP
connection from client
HTTP messages
(application-layer protocol
messages) exchanged
between browser (HTTP
client) and Web server
(HTTP server)
TCP connection closed
HTTP is “stateless”

server maintains no
information about past
client requests
40
HTTP Connections
Nonpersistent HTTP
 At most one object is
sent over a TCP
connection.
 HTTP/1.0 uses
nonpersistent HTTP
Persistent HTTP
 Multiple objects can be
sent over single TCP
connection between
client and server.
 HTTP/1.1 uses
persistent connections
in default mode
41
Non-persistent HTTP
Suppose user enters URL
www.uok.ac.ir/computer/home.html
(contains text,
references to 10
jpeg images)
time
1. HTTP client initiates TCP
connection to HTTP server
(process) at www.uok.ac.ir
on port 80
3. HTTP client sends HTTP
2. HTTP server at host
www.uok.ac.ir waiting for
TCP connection at port 80.
“accepts” connection,
notifying client
request message (containing
URL) into TCP connection
socket. Message indicates
that client wants object
Computer/home.html
4. HTTP server receives
request message, forms
response message containing
requested object, and sends
message into its socket
42
Non-persistent HTTP (cont.)
4. …
5. HTTP client receives
response message containing
html file, displays html.
Parsing html file, finds 10
referenced jpeg objects
time 7.
6. HTTP server closes
TCP connection.
Steps 1-6 repeated for
each of 10 jpeg objects
43
Response Time Modeling
Response time:
 one RTT to initiate TCP
connection
 one RTT for HTTP request
and first few bytes of HTTP
response to return
 file transmission time
total = 2RTT+transmit time
initiate TCP
connection
RTT
request
file
time to
transmit
file
RTT
file
received
time
time
44
Persistent HTTP
Nonpersistent HTTP issues:
 requires 2 RTTs per object
 OS must work and allocate
host resources for each TCP
connection
 but browsers often open
parallel TCP connections to
fetch referenced objects
Persistent HTTP
 server leaves connection
open after sending response
 subsequent HTTP messages
between same client/server
are sent over connection
Persistent without pipelining:
 client issues new request only
when previous response has
been received
 one RTT for each referenced
object
Persistent with pipelining:
 default in HTTP/1.1
 client sends requests as soon
as it encounters a referenced
object
 as little as one RTT for all the
referenced objects
45
HTTP request and response format
46
‫‪Request line‬‬
‫خط درخواست‬
‫‪Status line‬‬
‫خط وضعیت‬
‫هر سطر سرآیند به این فرمت است‬
‫‪47‬‬
:‫انواع دیگر درخواست‬
OPTIONS, PATCH, COPY, MOVE, LINK, UNLINK, TRACE,
48
HTTP Request Message - example
HTTP request message: ASCII (human-readable format)
request line
(GET, POST,
HEAD commands)
header
lines
Carriage return,
line feed
indicates end
of message
GET /somedir/page.html HTTP/1.1
Host: www.someschool.edu
User-agent: Mozilla/4.0
Connection: close
Accept-language:fr
If-modified-since:Sat, 2 Nov 2002 13:45:12
(carriage return, line feed)
49
Example 1
This example retrieves a document. We use the GET method to
retrieve an image with the path /usr/bin/image1. The request line
shows the method (GET), the URL, and the HTTP version (1.1).
The header has two lines that show that the client can accept
images in GIF and JPEG format. The request does not have a body.
The response message contains the status line and four lines of
header. The header lines define the date, server, MIME version, and
length of the document. The body of the document follows the
header (see next slide).
50
Example 1
51
Example 2
This example retrieves information about a document. We use the
HEAD method to retrieve information about an HTML document.
The request line shows the method (HEAD), URL, and HTTP
version (1.1). The header is one line showing that the client can
accept the document in any format (wild card). The request does
not have a body. The response message contains the status line and
five lines of header. The header lines define the date, server, MIME
version, type of document, and length of the document (see next
slide). Note that the response message does not contain a body.
52
Example 2
53
‫فرض كنيد كاربر‪ ،‬آدرس زير را در مرورگر خود وارد ميكند‪:‬‬
‫‪http://www.w3.org/hyper/www/project.html‬‬
‫مرورگر با تحليل آدرس متوجه ميشود كه بايد تقاضاي فايلي را طبق پروتكل ‪ HTTP‬به‬
‫سمت سرويس دهنده بفرستد‪ .‬مراحلي كه اتفاق مي افتند به شرح زير خواهند بود‪:‬‬
‫‪ )1‬مرورگر آدرس را تحليل كرده و قسمتهاي پروتكل‪ ،‬آدرس نام حوزه‪ ،‬شاخه و نام فايل را از‬
‫آن استخراج ميكند‪.‬‬
‫‪ )2‬مرورگر يك اتصال ‪ UDP‬با پورت ‪ 53‬سرويس دهنده ‪ DNS‬برقرار نموده و تقاضاي‬
‫ترجمه آدرس نام حوزه را به آن ارسال مي نمايد تا آدرس ‪ IP‬ماشين سرويس دهنده بدست آيد‪.‬‬
‫در اين مثال مرورگر تقاضاي ترجمه نام ‪ www.w3.org‬را به ‪ DNS‬ارسال ميكند‪.‬‬
‫‪54‬‬
‫‪ DNS )3‬در پاسخ‪ ،‬آدرس ‪ IP‬معادل با نام حوزه را برميگرداند‪ .‬فرض كنيد در اين مثال ‪DNS‬‬
‫آدرس ‪ IP‬را ‪128.30.52.31‬برگردانده است‪.‬‬
‫‪ )4‬مرورگر يك ارتباط ‪ TCP‬با آدرس ‪128.30.52.31‬و پورت‪ 80‬برقرار ميكند‪.‬‬
‫‪ )5‬پس از برقراري ارتباط‪ ،‬يك پيغام درخواست به صورت زير به سمت سرويس دهنده ارسال‬
‫ميشود‪:‬‬
‫”‪“GET /hyper/www/project.html http/1.1‬‬
‫‪ )6‬سرويس دهنده اين رشته را دريافت و پس از پردازش آن‪ ،‬فايل ‪project.html‬را از شاخه‬
‫‪/hyper/www/‬استخراج كرده و براي مرورگر ارسال مي نمايد‪.‬‬
‫‪ )7‬مرورگر فايل را دريافت كرده و پس از خاتمه دريافت ارتباط ‪TCP‬را قطع ميكند‪.‬‬
‫‪ )8‬مرورگر فايل ابرمتني را تفسير كرده و آنرا روي خروجي نمايش ميدهد‪.‬‬
‫‪ 1‬تا ‪8‬‬
‫‪ )9‬اگر فايل ابرمتني در جايي داراي صدا يا تصوير باشد به ازاي تك تك آنها مراحل‬
‫را تكرار نموده و آنها را بترتيب دريافت مي كند (با فرض ‪)persistent http‬‬
‫‪55‬‬
‫‪SMTP‬‬
‫‪and POP3‬‬
‫پروتکلهای انتقال و دریافت ایمیل‬
‫‪56‬‬
Electronic Mail
Sending/Receiving Mail
Addresses
User Agent
MIME
Mail Transfer Agent
Mail Access Protocols
Format of an email
Email address
User agent
Note:
Some examples of command-driven
user agents are mail, pine, and elm.
Note:
Some examples of GUI-based user
agents are Eudora, Outlook, and
Netscape.
Scenario: User1 sends message to User2
1) User1 (sender) uses UA to
compose message to
[email protected] .
2) User1’s UA sends message to
his mail server; message
placed in message queue.
3) Client side of SMTP opens TCP
connection with User2’s mail
server.
4) SMTP client sends User1’s
message over the TCP
connection.
5) User2’s mail server places the
message in User2’s mailbox.
6) User2 invokes his/her user agent
to read message.
webmail.uok.ac.ir
User1
1
user
agent
2
mail
server
3
[email protected]
mail
server
4
5
yahoo.com
user User2
agent
6
[email protected]
‫‪MIME‬‬
‫‪ MIME‬يك پروتكل تكميلي است كه اجازه مي دهد كاراكترهاي غير‪ ASCII‬نيز از طريق‪ SMTP‬منتقل شوند‪.‬‬
‫دقت كنيد كه‪ MIME‬يك پروتكل جايگزين براي‪ SMTP‬نيست و قادر به ارسال نامه نمي باشد بلكه توسعه اي‬
‫براي پروتكل‪ SMTP‬محسوب مي شود‪ .‬ميتوان ‪ MIME‬را به صورت برنامه اي تصور نمود كه داده غير‬
‫‪ ASCII‬را به داده‪ ASCII‬و بالعكس ترجمه ميكند‬
MIME header
Data types and subtypes in MIME
Type
Subtype
Description
Plain
Unformatted text
Mixed
Body contains ordered parts of different data types
Parallel
Same as above, but no order
Digest
Similar to mixed, but the default is message/RFC822
Alternative
Parts are different versions of the same message
RFC822
Body is an encapsulated message
Partial
Body is a fragment of a bigger message
Ext. Body
Body is a reference to another message
JPEG
Image is in JPEG
GIF
Video is in GIF format
Video
MPEG
Video is in MPEG format
Audio
Basic
Single-channel encoding of voice at 8 KHz
PostScript
Adobe PostScript
Octet-Stream
General binary data (8-bit bytes)
Text
Multiport
Message
Image
Application
Content-transfer encoding
Category Description
Type
ASCII characters and short lines
7bit
Non-ASCII characters and short lines
8bit
Non-ASCII characters with unlimited-length lines
Binary
6-bit blocks of data are encoded into 8-bit ASCII characters
Base64
Non-ASCII characters are encoded as an equal sign followed by an ASCII
code
Base64
Base64 encoding table
Value
Code
Value
Code
Value
Code
Value
Code
Value
Code
Value
Code
0
A
11
L
22
W
33
h
44
s
55
3
1
B
12
M
23
X
34
i
45
t
56
4
2
C
13
N
24
Y
35
j
46
u
57
5
3
D
14
O
25
Z
36
k
47
v
58
6
4
E
15
P
26
a
37
l
48
w
59
7
5
F
16
Q
27
b
38
m
49
x
60
8
6
G
17
R
28
c
39
n
50
y
61
9
7
H
18
S
29
d
40
o
51
z
62
+
8
I
19
T
30
e
41
p
52
0
63
/
9
J
20
U
31
f
42
q
53
1
10
K
21
V
32
g
43
r
54
2
MTA client and server
Mail Access Protocols
SMTP
Sender user
agent
SMTP
sender’s mail
server
access
protocol
user
Receiver
agent
receiver’s mail
server
 SMTP: delivery/storage to receiver’s server (PUSH)
 Mail access protocol: retrieval from server (PULL)
 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 messages on server
 HTTP: Hotmail , Yahoo! Mail, etc.
C:\> telnet www.uok.ac.ir 25
Connecting to www.uok.ac.ir ...
================== ‫================برقراري اتصال‬
220 PARSDATA Mail Server (IMail 8.00 2586-5) NT-ESMTP Server X1
HELO PARSDATA
250 hello PARSDATA Mail Server
===================== ‫=================== پوشش نامه‬
MAILFROM: [email protected]
250 ok
RCPT TO: [email protected]
250 ok deliver to alternate
=================== ‫================== سرآيند و بدنه نامه‬
DATA
354 ok, send it; end with <CRLF>.<CRLF>
FROM: Abdollahpour
TO: myself
Hi this is a sample e-mail to show SMTP in action.
.
============= ‫===============خاتمه اتصال‬
250 Message queued
QUIT
221 Goodbye
Connection to host lost
POP3 Protocol
authorization phase
 client commands:
 user: declare
username
 pass: password
 server responses
 +OK
 -ERR
transaction phase, client:
 list: list message
numbers
 retr: retrieve message
by number
 dele: delete
 quit
S:
C:
S:
C:
S:
+OK POP3 server ready
user USER1
+OK
pass zxcdvf
+OK user successfully logged
C:
S:
S:
S:
C:
S:
S:
C:
C:
S:
S:
C:
C:
S:
list
1 498
2 912
.
retr 1
<message 1 contents>
.
dele 1
retr 2
<message 1 contents>
.
dele 2
quit
+OK POP3 server signing off
on
File Transfer
Connections
Communication
File Transfer
User Interface
Anonymous
Note:
FTP uses the services of TCP. It needs
two TCP connections. The well-known
port 21 is used for the control
connection, and the well-known port
20 is used for the data connection.
FTP
control connection: “out of band”
FTP: Separate Control, Data Connections1
TCP control connection
port 21 (persistent)
FTP client
TCP data connection
port 20(nonpersistent)
FTP server
 FTP client contacts FTP server at port 21, specifying
TCP as transport protocol.
 Client obtains authorization over control connection.
 Client browses remote directory by sending commands
over control connection.
 When server receives a command for a file transfer,
server opens a TCP data conn. to client at port 20.
Using the control connection
Using the data connection
File transfer
Example 1
Figure 26.16 (next slide) shows an example of how a file is stored.
1. The control connection is created, and several control
commands and responses are exchanged.
2. Data are transferred record by record.
3. A few commands and responses are exchanged to close the
connection.
Example 1
List of FTP commands in UNIX
Commands
!, $, account, append, ascii, bell, binary, bye, case, cd, cdup,
close, cr, delete, debug, dir, discount, form, get, glob, hash, help,
lcd, ls, macdef, mdelete, mdir, mget, mkdir, mls, mode, mput,
nmap, ntrans, open, prompt, proxy, sendport, put, pwd, quit,
quote, recv, remotehelp, rename, reset, rmdir, runique, send,
status, struct, sunique, tenex, trace, type, user, verbose,?
Example 2
We show some of the user interface commands that accomplish the
same task as in Example 1. The user input is shown in boldface. As
shown below, some of the commands are provided automatically
by the interface. The user receives a prompt and provides only the
$ ftp challenger.atc.fhda.edu
arguments.
Connected to challenger.atc.fhda.edu
220 Server ready
Name: forouzan
Password: xxxxxxx
ftp > ls /usr/user/report
200 OK
150 Opening ASCII mode
...........
...........
226 transfer complete
ftp > close
221 Goodbye
ftp > quit
Example 3
We show an example of using anonymous FTP. We connect to
internic.net, where we assume there are some public data available.
$ ftp internic.net
Connected to internic.net
220 Server ready
Name: anonymous
331 Guest login OK, send "guest" as password
Password: guest
ftp > pwd
257 '/' is current directory
ftp > ls
200 OK
150 Opening ASCII mode
bin
...
ftp > close
221 Goodbye
ftp > quit
Remote Login:
Telnet
Questions
88