Transcript 2.applicati

Kurose ed. 5
Chapter II
II. Application Layer
(part a)
lectured by
Chang-jin Suh
Soongsil University, Dep. of Computer Science
Tel : 820-0686
www.netwarking.com
II-a: Application Layer
Chapter II
part a
II.1. Principles of app layer protocols
II.2. Web and HTTP
II.3. FTP
II.4. Electronic Mail ; SMTP, POP3, IMAP
part b
II.5. DNS
II.6. P2P file sharing
II.7. Socket programming with TCP (not covered)
II.8. Socket programming with UDP (not covered)
II-a: Application Layer
2
Chapter II : outlines
Chapter goals:
More chapter goals
 Conceptual,
 specific protocols:
implementation aspects of
 http
network application
 ftp
protocols
 smtp, pop3/imap



transport-layer service
models
client-server paradigm
peer-to-peer paradigm
 learn about protocols by
examining popular
application-level protocols
 expected schedule : 12
hours


dns
p2p : recently much
extended
 programming network
applications
(not covered)

socket programming
II-a: Application Layer
3
Some network apps







E-mail
Web
instant messaging
remote login
P2P file sharing
multi-user network
games
streaming stored video
clips
 voice over IP
 real-time video


conferencing
grid computing
…
II-a: Application Layer
4
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
No software written for
devices in network core


Network core devices do
not function at app layer
This design allows for
rapid app development
application
transport
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
II-a: Application Layer
5
II.1. Principles of ntwk
applications





application architecture : client-server, p2p
sockets
addresses
transport services : data loss, thruput, delay
application protocols
II-a: Application Layer
6
Application architectures
 Client-server
 Peer-to-peer (P2P)
 Hybrid of client-server and P2P
II-a: Application Layer
7
client-server archicture
server: fixed and passive



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
II-a: Application Layer
8
Pure P2P architecture
 not always on server
 arbitrary end systems

directly communicate
peers are intermittently
connected and change IP
addresses
Highly scalable
But difficult to manage
II-a: Application Layer
9
Hybrid of client-server and P2P
centralized control and p2p data transfer
Skype



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
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
II-a: Application Layer
10
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
II-a: Application Layer
11
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
host or
server
host or
server
process
controlled by
app developer
process
socket
socket
TCP with
buffers,
variables
Internet
TCP with
buffers,
variables
controlled
by OS
 API: (1) choice of transport protocol; (2) ability to fix
a few parameters (lots more on this later)
II-a: Application Layer
12
Addressing processes
 For a process to receive
messages, it must have an
identifier
 Every host has a unique 32bit IP address
Q: Does the IP address of the
host on which the process
runs suffice for identifying
the process?
Answer: No, many processes
can be running on same
host
Q: how does a process “identify”
the other process ?
 IP address of host
running other process
 port number allows
receiving host to
determine to which local
process the message
should be delivered
 Example port numbers:
 HTTP server: 80
 Mail server: 25
II-a: Application Layer
13
What transport service does an app need?
Data loss
 multimedia apps (e.g.,

audio) can tolerate some
loss.
Text service (e.g., telnet,
file transfer) require
100% reliable data
transfer
Throughput
 Realtime multimedia apps

Timing
 Some critical realtime
apps (e.g., Internet
telephony, interactive
games) require low
delay to be “effective”
(e.g., multimedia) require
minimum amount of
throughput to be
“effective”
other apps (“elastic apps”)
make use of whatever
bandwidth they get
Security

Encryption, data integrity…
II-a: Application Layer
14
Transport service requirements of common apps
Application
Data loss
file transfer
e-mail
web documents
real-time audio/video
no loss
no loss
loss-tolerant
loss-tolerant
stored audio/video
interactive games
financial apps
loss-tolerant
loss-tolerant
no loss
Bandwidth
Time Sensitive
no
elastic
no
elastic
no
elastic
audio: 5Kb-1Mb yes, 100’s msec
video:10Kb-5Mb
same as above yes, few secs
few Kbps up yes, 100’s msec
yes and no
elastic
** Stored audio/video can be sent in two ways
– file transfer or stored audio/video.
II-a: Application Layer
15
Services provided by Internet
transport protocols
TCP service:
 reliable transport between




UDP service:
 unreliable data transfer
sending and receiving
between sending and receiving
process
process
connection-oriented: setup
 no reliability, connectionless,
required between client,
no flow control, no congestion
server
control, no timing, nor
flow control: sender won’t
bandwidth guarantee
overwhelm receiver
congestion control: throttle Q: why bother? we need UDP?
sender when network
 to provide (port) address
overloaded
 to avoid congestion
does not guarantee: timing,
control
minimum bandwidth
connection  reliable  error control 
retransmission  connection and recovery
II-a: Application Layer
16
Internet apps and transport protocols used
Application
e-mail
remote terminal access
Web
file transfer
streaming multimedia
remote file server
Internet telephony
Application
layer protocol
Underlying
transport protocol
smtp [RFC 821]
telnet [RFC 854]
http [RFC 2068]
ftp [RFC 959]
proprietary
(e.g. RealNetworks)
NFS
proprietary
(e.g., Vocaltec)
TCP
TCP
TCP
TCP
TCP or UDP
TCP or UDP
typically UDP
II-a: Application Layer
17
II.2. Web and http/html





http and http operating example
non-persistent vs persistent connection
http message format
trying out http for yourself
stateless http

Cookie – the way to keep semi-“state”
 web caching
II-a: Application Layer
18
The Web and HTTP
 Web page:


consists of “objects”
addressed by a URL
 Most Web pages consist
of:


base HTML page, and
several referenced
objects.
 User agent for Web
is called a browser:


MS : Internet
Explorer
Netscape :
Communicator
 Server for Web is
called Web server:
 URL has two components:
www.someSchool.edu/someDept/pic.gif
host name
path name
II-a: Application Layer
19
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
 http1.0: RFC 1945
 http1.1: RFC 2068
web-content
provider
PC running
Explorer
Server
running
Apache Web
server
Mac running
Navigator
II-a: Application Layer
20
HTTP Overview (continued)
http over TCP
step 1. client initiates TCP
connection (creates socket)
to server, port 80
step 2. server accepts TCP
connection from client
step3. appl.-layer http mssgs
exchanged btwn browser and
Web server
step 4. TCP connection closed
http is “stateless”
 server maintains no info.
about past client requests
 Cookies are convenient in
keeping state info.
 In strict sense, having
cookie is not considered as
having states.
aside
Protocols having “state” are complex!
 past history (state) must be maintained
 if server/client crashes, their views of
“state” may be inconsistent, must be
reconciled (recovered)
II-a: Application Layer
21
HTTP connections
Non-persistent
 HTTP/1.0
 At most an object can
be sent over a TCP
connection.
 2 RTTs to fetch each
object
Persistent
 default for HTTP/1.1
 Multiple objects can
be sent over a TCP
connection:
 Fewer RTTs
** But most 1.0 browsers
use parallel TCP
connections.
II-a: Application Layer
22
웹문서 전달받기예 (non-persistent)
요청 자료 : html로 구성되며 k개의 object 포함된 경우
1단계 : base HTML page download
2단계 : referenced object1, object2, …, object_k download
** cache된 object는 download 생략
접속을 종료한다
.
.
접속을 종료한다
II-a: Application Layer
23
Non-persistent http example
Suppose user enters URL
www.someSchool.edu/someDepartment/home.index
(contains text,
references to 10
jpeg images)
1a. http client initiates TCP
connection request to http
server (process) at
www.someSchool.edu. Port 80
is default for http server.
1b. http server at host
RTT
2. http client sends http request
message (containing URL) into
TCP connection socket
Round-Trip Time 1 packet
time
tcp message
http message
www.someSchool.edu waiting
for TCP connection at port 80.
“accepts” connection, notifying
client
3. http server receives request
message, forms response
message containing requested
object
(someDepartment/home.index),
and sends message into socket
II-a: Application Layer
24
Non-persistent http (cont.)
4. http client receives response
time
message containing html file,
displays html. Parsing html
file, finds 10 referenced jpeg
objects
5. http server closes TCP
connection.
6. Steps 1-5 repeated for each
of 10 jpeg objects
II-a: Application Layer
25
Response time modeling
Definition of RTT: delay
since sending a small
packet to travel from
client to server and back. initiate TCP
Response time:
 one RTT to initiate TCP


connection
RTT
request file
connection
RTT
one RTT for HTTP request
and first few bytes of
file
HTTP response to return
received
file transmission time
time to
transmit
file
time
time
II-a: Application Layer
26
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
II-a: Application Layer
27
http message : reqeust/response
 two types of http messages: request, response
 http request message:

ASCII (human-readable format)
space
carriage return+ linefeed
: additional comments
on request
http message format: request
II-a: Application Layer
28
http message : reqeust/response
 an example of http request
GET /somedir/page.html HTTP/1.1
Host: www.someschool.edu
User-agent: Mozilla/4.0
Connection: close
Accept-language:fr
(entity Body)
II-a: Application Layer
29
method types (1/2)
Method
– GET : 클라이언트가 서버로부터 문서를 읽어 오기를 요청
– POST : 클라이언트가 서버에게 어떤 정보를 제공
– HEAD : 클라이언트가 (문서 내용(entity body)은 요청하지 않고)
문서에 대한 정보가 들어있는 header part만을 요청
– PUT : 클라이언트가 서버에 저장될 새 교체문서를 제공
– COPY : 파일을 다른 위치로 복사
– DELETE : 서버에서 문서를 제거
– LINK : 다른 위치로 문서의 링크를 생성
II-a: Application Layer
30
Method types(1/2)
HTTP/1.0
 GET
 POST
 HEAD

asks server to send
back the header part
only (not objects)
HTTP/1.1
 GET, POST, HEAD
 PUT

uploads file in entity
body to the path
specified in URL field
 DELETE

deletes file specified in
the URL field
2: Application Layer
31
http request message: GET
A. downloading : GET
request line
(GET, POST,
HEAD commands)
GET /somedir/page.html HTTP/1.0
User-agent: Mozilla/4.0
Accept: text/html, image/gif, image/jpeg
header Accept-language:fr
lines
Carriage return,
line feed
indicates end
of message
(extra carriage return, line feed)
II-a: Application Layer
32
HTTP response message
status line
(protocol
status code
status phrase)
header
lines
data, e.g.,
requested
HTML file
HTTP/1.1 200 OK
Connection close
Date: 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 ...
II-a: Application Layer
33
http response status codes
1’st line in (server  client) response message.
A few sample 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
II-a: Application Layer
34
Uploading form input (1/2)
B. uploading : GET_URL, POST
B.1 URL(GET_URL) method: B.2. POST method:
 Input is uploaded in URL  Input is uploaded to
field of request line:
server in entity body


Input size is very
limited.
URL field is open.
So input is open (easily
read by others)
Allows large input.
 Inputs can be decoded
thus closed(hidden).
- client : data encoding,
- server : data decoding

2: Application Layer
35
Uploading form input (2/2)
GET_URL/POST는 각각 어떤 경우에 사용하나?
GET :
 용도 : 클라이언트
환경에서 서버에서 받은
데이터를 보는데 필요한
정보를 upload한다.


게시판의 리스트 읽기
글 보기
POST :
 용도 : 서버의 값이나
상태를 바꾸는 주요
정보를 서버에 제공


글쓰기 (올린 글이
db에 저장)
글수정 (db 내용수정)
 서버의 변수값이나 상태는  서버의 변수나 상태가
불변하는 동작을 할 때에
사용한다.
바뀌는 동작을 할 때에
사용한다.
** 방문자 수 정도는 바뀐다.
2: Application Layer
36
Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server:
telnet cis.poly.edu 80
Opens TCP connection to port 80
(default HTTP server port) at cis.poly.edu.
Anything typed in sent
to port 80 at cis.poly.edu
2. Type in a GET HTTP request:
GET /~ross/ HTTP/1.1
Host: cis.poly.edu
By typing this in (hit carriage
return twice), you send
this minimal (but complete)
GET request to HTTP server
3. Look at response message sent by HTTP server!
II-a: Application Layer
37
User-server state : Cookies
Many major Web sites use
cookies
Four components:
1) cookie header line in
HTTP response message
2) cookie header line in
HTTP request message
3) cookie file kept on
user’s host and managed
by user’s browser
4) back-end database at
Web site
Example: (See slide next)



Susan access Internet
always from same PC
She visits a specific ecommerce site for
first time
When initial HTTP
requests arrives at
site, site creates
• a unique ID,
• an entry in backend
database for ID
II-a: Application Layer
38
Cookies: keeping “history”
client
Cookie file
ebay: 8734
server
usual http request msg
usual http response +
Set-cookie: 1678
cookie generation
Cookie file
amazon: 1678
ebay: 8734
usual http request msg
cookie: 1678
usual http response msg
one week later:
Cookie file
amazon: 1678
ebay: 8734
cookie re-use
usual http request msg
cookie: 1678
usual http response msg
server
creates ID
1678 for user
cookiespecific
action
cookiespecific
action
amazon
backend
database
retrieving
previous
history !
II-a: Application Layer
39
Cookies (continued)
aside
Cookies and privacy:
 cookies permit sites to
learn a lot about you
 you may supply name
and e-mail to sites
What cookies can bring:
 authorization
 shopping carts
 recommendations
 user session state (Web e-mail)
cookie는 잡다한 기억을 하는 보관하는
장소이다. 엄격하게 말하면 이 잡다한
기억을 state라고 의미하지는 않는다.
 How to keep “state”:
 protocol endpoints: maintain state at

sender/receiver over multiple transactions
cookies: http messages carry state
II-a: Application Layer
40
COOKIE란 ? (read)
 정의 : 웹서버가 쿠키는 웹사이트 이용자에 대해서 대한 기본 설정 정보를



보관하기 위해서 웹 서버가 이용자의 브라우저로 전송하는 소량의 정보.
동작 : 이용자가 웹사이트에 접속을 하면 서비스제공자의 컴퓨터는 이용자의
브라우저에 있는 쿠키의 내용을 읽고, 이용자의 추가정보를 자신의 컴퓨터에서
찾아 접속에 따른 ID, 패스워드 등의 추가 입력 없이 서비스를 제공한다.
 고객이 사이트에 처음 등록하거나 "Log In"할 때 설정되고, 서비스를 "Log
Out"할 때 수정됨.
 쿠키는 고객의 컴퓨터를 식별하지만 고객을 개인적으로 식별하지는
않는다. 사이트에 접속하는 각 브라우저에는 고유한 쿠키가 부여된다.
허용여부 : 고객은 쿠키의 허용여부를 선택할 수 있다. 웹브라우저의 옵션에
따라서 고객은 모든 쿠키를 다 받아들이거나, 쿠키가 설치될 때 통지를
보내도록 하거나, 아니면 모든 쿠키를 거부할 수 있다. 다만, 쿠키설정을
거부하면 원하는 서비스가 제공되지 못하는 경우가 많다.
용도 :
 고객이 맞춤화 된 사이트 서비스 : 더 나은 서비스를 제공
 등록이용자와 미등록이용자의 사용 빈도나 반복 사용의 한도 조사
 이용자의 관심사와 행동에 기초한 타겟팅 서비스 구현
 고객의 총체적인 방문 형태를 측정하여 이용자 습관을 이해함.
II-a: Application Layer
41
Web caches (proxy server)
Goal: satisfy client request without involving origin server
 user sets browser:

Web accesses via
cache
browser sends all HTTP
requests to cache


if object in cache: cache
returns object
else cache requests
object from origin
server, then returns
object to client
proxy
server
(web
cache)
server A
client
client
server B
II-a: Application Layer
42
More about Web caching
 Cache acts as both client and server
 Typically cache is installed by various types of
ISPs (university, company, residential ISP)
II-a: Application Layer
43
Why Web Caching?
origin
servers
Assume: cache is “close” to
public
client (e.g., in same
Internet
network)
 smaller response time:
cache “closer” to client
1.5 Mbps
access link
 decreased traffic to
institutional
distant servers

link out of
institutional/local ISP
 less load to servers
network
10 Mbps LAN
institutional
cache
II-a: Application Layer
44
Caching example(1/3)
origin
Assumptions
servers
 average object size = 100,000
public
bits
Internet
 avg. request rate from
institution’s browsers to origin
servers = 15/sec
 delay from institutional router
1.5 Mbps
to any origin server and back to
access link
router = 2 sec
institutional
Consequences (with no cache)
network
10 Mbps LAN
 utilization on LAN = 15%
 utilization on access link = 100%
 total delay = Internet delay +
access delay + LAN delay
no institutional
cache
= 2 sec + minutes + milliseconds
II-a: Application Layer
45
Caching example (2/3)
Possible solution
 increase bandwidth of access
link to, say, 10 Mbps
origin
servers
public
Internet
Consequences (with
increased uplink capacity)
 utilization on LAN = 15%
 utilization on access link = 15% institutional
 Total delay = Internet delay +
network
access delay + LAN delay
= 2 sec + msecs + msecs
 often a costly upgrade
10 Mbps
access link
10 Mbps LAN
no institutional
cache
II-a: Application Layer
46
Caching example (3/3)
Install cache
 suppose hit rate is .4
Consequence (with cache)
 40% requests will be satisfied
origin
servers
public
Internet
almost immediately
 60% requests satisfied by
1.5 Mbps
origin server
access link
 utilization of access link
institutional
reduced to 60%, resulting in
network
10 Mbps LAN
negligible delays (say 10 msec)
 total avg delay = Internet
delay + access delay + LAN
institutional cache
delay = .6*(2.01) secs +
milliseconds < 1.4 secs
II-a: Application Layer
47
conditional GET : client-side caching
 Goal: don’t send object if
server
client
client has up-to-date stored
(cached) version
 client: specify date of
cached copy in http request
If-modified-since:
<date>
http request msg
If-modified-since:
<date>
http response
HTTP/1.0
304 Not Modified
Case1.
object not
modified
 server: response contains
no object if cached copy is
up-to-date:
HTTP/1.0 304 Not
Modified
http request msg
If-modified-since:
<date>
http response
HTTP/1.1 200 OK
…
Case2.
object
modified
<data>
II-a: Application Layer
48
II.3 ftp
 what is transfer file protocol ?
 TCP connections
 FTP commands

GET, PUT
II-a: Application Layer
49
ftp: the file transfer protocol
user
at host
FTP
FTP
user
client
interface
file transfer
local file
system
FTP
server
remote file
system
 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(for control), port 20(for data)
II-a: Application Layer
50
ftp: separate control, data connections
 two parallel connections :
: “out of band” signalling
2.data connection :
1. control connection:TCP conn  When server receives a
 Client obtains authorization
file transfer command,
 Client browses remote
the server opens a TCP
directory
data connection to client
** FTP server maintains “state”  After transferring one
current directory, earlier
file,
server
closes
authentication
connection.
 Server opens a second
TCP control connection
port 21
TCP data connection to
transfer another file.
FTP
client
TCP data connection
port 20
FTP
server
II-a: Application Layer
51
ftp commands, responses
Sample commands:
 sent as ASCII text over
control channel
 USER username
 PASS password
Sample return codes
 status code and phrase (as

 LIST return list of file in

 RETR filename retrieves

 STOR filename stores

current directory
(gets) file
(puts) file onto remote
host
in http)
331 Username OK,
password required
125 data connection
already open;
transfer starting
425 Can’t open data
connection
452 Error writing
file
II-a: Application Layer
52
ftp modes
alphabet representaion
 ASCII : a unique international standard
 EBCIDIC : previously used in IBM machine
file types
 ASCII file



Text only
all characters are written as 7bit ASCII
ended by ‘EOF’ which were ^z but not always
 binary file (image)



executable file, most currently used files e.g., hwp, doc, ppt, …
8bits including ‘EOF’ are used
currently not ended with ‘EOF’.
II-a: Application Layer
53
ftp modes (advanced)
구분
(파일
타입)
TYPE
(데이터
구조)
STRU
항목
내용
ASCII(7bit) :
default
현재 전세계의 영어 표기의 standard
EBCDIC(7bit)
한쪽 시스템이 EDCDIC 타입일 경우에는 이 모드를
선택해야 (IBM, 후지쯔에서 사용)
BINARY 혹은
IMAGE (8bit)
2진 파일을 전환없이 전송하므로 가장 빠름. ASCII
를 전송할 때에는 ‘EOF 이후는 전송 안됨.
FILE : default
전달할 데이터는 연속적인 바이트(스트림)로 이루어
진 파일임.
RECORD
PAGE
전달할 데이터는 일련의 레코드로 이루어짐
텍스트 파일(ASCII or EBCDIC)에서만 사용
전달할 데이터는 여러 페이지로 구분됨.
전송할 때에 페이지 번호가 포함되기 때문에 수신측
은 페이지 단위로 수신할 수 있음.
II-a: Application Layer
54
ftp modes (advanced)
구분
항목
STREAM
:default
(전송
모드)
MODE
BLOCK
COMPRESSED
내용
적응계층에서 파일을 변형하지 않고 전달한다.
1. 데이터 구조가 피일 구조인 경우
파일의 전체 크기를 모르는 상태에서 전송하며 EOF(EndOf–File)가 파일의 종료를 알려줌
2. 데이터 구조가 레코드 구조인 경우
레코드 단위로 전송되며 각 레코드는 한 바이트의
EOR(End-Of–Record)로 종료된다.
또한 파일의 종료 시에는 EOF가 사용된다.
적응계층에서 파일은 연속되는 블록으로 구분 후 전달한다.
데이터 블록에는 3바이트의 헤더가 추가된다. 헤더는 1바
이트는 블록설명자(descriptor)와 2바이트는 블록의 크기
로 구성된다. EOF, EOB, EOR(record) 등이 사용된다.
Run-length code로 길이를 줄인(압축)한 후에 전송 (대량
의 데이터를 저속의 회선으로 전송할 때 사용) : Runlength code는 faximile 이외에서는 비효율적으로 사용되
지 않음!
II-a: Application Layer
55
ftp modes
passive connection modes :
아래에서 주소는 directory를 의미함.
IP주소는 TCP연결 때에 이미 알았음
to avoid NAT or firewall interruption
<active전송모드(default)>
<수동전송모드>
II-a: Application Layer
56
ftp modes
PASV 명령의 답변으로
port명령어 전달(서버의 데이터
포트 주소 전달)
port명령으로 data
채널용 client 주소 전달
여러 명이
공동으로 사용
OK
PASV
단독 사용
전달받은 주소로
data 채널연결
단점 : (1)client측에 NAT가 있으면 자신의
주소가 아닌 주소를 client가 보냄.
(2) client firewall이 data채널 연결을 차단함.
<active 전송모드(default)>
서버는 hacking 당할 위험이
커서 사용하길 꺼림.
<수동전송모드>
II-a: Application Layer
57
II.4. Electronic Mail
 mail system structure :

user agents, mail servers, SMTP
 components
 related protocols



SMTP : e-mail protocol between mail servers
POP3, IMAP : e-mail protocol between user and user
agent
MIME : extension to SMTP
 mail message format
II-a: Application Layer
58
Electronic Mail
outgoing
message queue
user mailbox
Three major components:
 user agents
 mail servers
 simple mail transfer
user
agent
mail
server
SMTP
protocol: SMTP
User Agent (PC)
 a.k.a. “mail reader”
 composing, editing, reading
mail messages
 e.g., Outlook Express,
Netscape Messenger
 outgoing, incoming messages
stored on server
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
II-a: Application Layer
59
Electronic Mail: mail servers
Mail Servers
 mailbox contains incoming


messages (yet to be read)
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
user
agent
mail
server
SMTP
SMTP
mail
server
user
agent
SMTP
user
agent
mail
server
user
agent
user
agent
user
agent
II-a: Application Layer
60
(extra) SMTP 메일 시스템 구성
 메일시스템의 기본구성
송신측
수신측
UA
UA
POP3
IMAP
SMTP
MTA
SMTP
MTA
II-a: Application Layer
61
(extra) SMTP 메일 시스템 구성
 구성요소
MTA (Mail Transfer Agent)
• SMTP 프로토콜이 수행되는 대표적인 객체
• 기본적으로 SMTP는 MTA_server와
MTA_client사이에서 동작하는
프로토콜이다.
 UA (User Agent)
• 사용자가 이용하는 시스템으로서 메일 배달을
의뢰하거나 수령함.
• 즉, 메일을 실제 생성하고 삭제가 행해짐.

II-a: Application Layer
62
(extra) 메일 시스템 구성
 확장된 메일시스템의 구성
송신측
UA
▪▪▪
수신측
UA
UA
▪▪▪
UA
SMTP
POP3
IMAP
MBMB
MB
MSA
MTA
MTA
MDA
SMTP
Spool
서버
Queue
서버
II-a: Application Layer
63
SMTP 메일 시스템 구성 (advanced)
 구성요소





MSA (Mail Submission Agent) : MTA_client
전단계에서 MTA가 행해야 할 기본적인 절차를 수행한
후 MTA로 메일 배달을 의뢰
MDA (Mail Delivery Agent) : MTA로부터 호출되어
전달받은 메일을 MB로 이동하는 전달자
Spool: sender측에 위치한 queue. UA로부터 전달할
것을 의뢰받은 메일을 전송이 완료될 때까지 보관하는
저장소
Queue : MTA를 통하여 수신한 메일을 임시로 보관하는
저장소
Mail Box: 등록자 별로 분리된 사용자에게 배달된 메일의
보관장소, 즉
• Queue는 수신측의 우체국내의 보관소,
• mailbox는 분류된 사서함 보관소로 비유할 수 있다.
II-a: Application Layer
64
SMTP 동작 (important)
 SMTP 동작절차
1. TCP연결  2. session연결  3.메일전송
5. TCP해제  4. session해제


송신자
SMTP
TCP
메일전송
session연결
TCP 연결
수신자
SMTP
TCP
인터넷
II-a: Application Layer
65
Electronic Mail: smtp [RFC 2821]
 uses tcp to reliably transfer email msg from


client to server, 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
II-a: Application Layer
66
Scenario: Alice sends message to Bob
(read)
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
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
1
user
agent
SMTP
2
mail
server
3
SMTP
4
mail
server
5
POP3,
IMAP,
http
6
user
agent
II-a: Application Layer
67
Sample smtp interaction
S:
C:
S:
C:
S:
C:
S:
C:
S:
C:
C:
C:
C:
C:
C:
C:
C:
S:
C:
S:
220 hamburger.edu ‘Beginning of SMTP(and TCP)session
HELO crepes.fr ‘ source mail server’s domain name
250 Hello crepes.fr, pleased to meet you
MAIL FROM: <[email protected]> ‘ src addr. < > may be omitted
250 [email protected]... Sender ok
RCPT TO: <[email protected]> ‘ dest. addr. < > may omitted
250 [email protected] ... Recipient ok
DATA
‘ beginning of message & beginning of header
354 Enter mail, end with "." on a line by itself
Date: 23 Oct 81 11:22:33 ‘date of mail delivery in header
From: [email protected] ‘ source address in the mail header
To: [email protected] ‘ destin address in the mail header
Subject: Mail System Problem ‘ subject in the mail header
‘end of header
Do you like ketchup?
‘ Beginning of body
How about pickles?
.
‘ end of body + ‘ end of message
250 Message accepted for delivery
QUIT
221 hamburger.edu ‘ End of SMTP (and TCP) session
II-a: Application Layer
68
Try smtp interaction for yourself:
 telnet servername 25

(you can see 220 reply from server)
 enter HELO, MAIL FROM, RCPT TO, DATA, QUIT
commands

above commands let you send email without using
email client (reader)
II-a: Application Layer
69
smtp: final words
 smtp uses persistent connections
 smtp requires that message (header & body) be in 7
bit ascii
certain character strings are not permitted in
message (e.g., CRLF.CRLF).


smtp server uses CRLF.CRLF to determine end of
mssg
Thus mssg has to be encoded (usually into either base64 or quoted printable)
II-a: Application Layer
70
Mail message format
smtp: protocol for exchanging
email msgs
RFC 822: standard for text
message format:
 header lines, e.g.,
 To:
 From:
 Subject:
Different from (added to)
smtp commands!
 body
 the “message”, ASCII
characters only
header
blank
line
body
II-a: Application Layer
71
Message format: MIME
 MIME: multimedia mail extension, RFC 2045, 2056
requires additional lines in msg header


Convert binary  ascii
Define file type : content-type
MIME version
method used
to encode data
multimedia data
type, subtype,
parameter declaration
encoded data
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
II-a: Application Layer
72
Message format: MIME
 Convert binary  ascii
II-a: Application Layer
73
Message format: MIME
 content-type :


Define file type.
can directly read the attached file
II-a: Application Layer
defined content-types as standard
74
Message format: MIME
 Encoding : BASE64 : 3byte 4 x 6bit
II-a: Application Layer
75
Mail access protocols
user
agent
PC
SMTP
SMTP
POP3 or
IMAP,http
user
agent
PC
(used to be
power off)
sender’s mail receiver’s mail
server
server
 SMTP: delivery/storage to receiver’s server
 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: han mail , Yahoo! Mail, etc.
II-a: Application Layer
76
POP3 protocol (skip)
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 alice
+OK
pass hungry
+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
II-a: Application Layer
77
on
POP3 and IMAP
More about POP3
 Uses “download and
delete” mode


like previous example
Bob cannot re-read email if he changes
client (he is nomadic)
 POP3 is stateless
IMAP
 more complex
 IMAP keeps user state
across sessions:
IMAP의 개선된 기능
􀂾 전자우편을 내려받기 전에 헤더 검사
􀂾 전자우편을 내려받기 전에 특정 문자열로 내용 검색
􀂾 전자우편을 부분적으로 내려받기
􀂾 전자우편 서버에서 편지함의 생성,삭제, 변경
􀂾 폴더 내 편지함을 체계적으로 생성하여 전자우편 보관
II-a: Application Layer
78
web-based mail server
web-based mail server
http
smtp
http
advantages of web-based mail server than smtp server
 http : non-ascii allowed (smtp : ascii allowed only)

no need to use encoding for binary data
 advanced security :

http is more reliable than smtp against hackers’ attack.
 http becomes very popular and familiar.
II-a: Application Layer
79
web-based mail server
Comparison smtp with http
 both have ASCII command/response interaction,
status codes
 http: pull service (data required to the client)
- email: push (data required to the server)
 http: each object is encapsulated in its own response
message (non-persistent)
- smtp: multiple objects message sent in a multipart
message (persistent)
II-a: Application Layer
80