You are on page 1of 55

100

7. Application layer

Học viện Hàng không Việt Nam


101

OSI – Application layer

• Khái niệm
Application • Web & HTTP
• FTP
Presentation
• Email
Session • Torrent
Transport

Network

Datalink

Physical

Học viện Hàng không Việt Nam


102

Some network apps

• e-mail • voice over IP (e.g.,


• web Skype)
• text messaging • real-time video
conferencing
• remote login
• social networking
• P2P file sharing
• search
• multi-user network
games •…
• streaming stored video •…
(YouTube, Hulu, Netflix)

Học viện Hàng không Việt Nam


103

Creating a network app application


transport
network
data link
write programs that: physical

• run on (different) end systems


• communicate over network
• e.g., web server software
communicates with browser
software
no need to write software for application
network-core devices transport
network

• network-core devices do not data link application


physical transport

run user applications network


data link
physical
• applications on end systems
allows for rapid app
development, propagation

Học viện Hàng không Việt Nam


Application architectures
104

possible structure of applications:


• client-server
• peer-to-peer (P2P)

Học viện Hàng không Việt Nam


105

Client-server architecture
server:
• always-on host
• permanent IP address
• data centers for scaling
clients:
• communicate with server
client/server • may be intermittently
connected
• may have dynamic IP
addresses
• do not communicate directly
with each other
Học viện Hàng không Việt Nam
106

P2P architecture
• no always-on server peer-peer
• arbitrary end systems
directly communicate
• peers request service from
other peers, provide service
in return to other peers
• self scalability – new peers
bring new service capacity, as
well as new service demands
• peers are intermittently
connected and change IP
addresses
• complex management

Học viện Hàng không Việt Nam


107

Processes communicating
process: program running clients, servers
within a host client process: process that
• within same host, two initiates communication
processes communicate server process: process that
using inter-process waits to be contacted
communication (defined
by OS)
• processes in different  aside: applications with P2P
hosts communicate by architectures have client
exchanging messages processes & server
processes

Học viện Hàng không Việt Nam


108

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 to deliver message to socket at receiving process

application application
socket controlled by
process process app developer

transport transport
network network controlled
link by OS
link Internet
physical physical

Học viện Hàng không Việt Nam


109

Addressing processes
• to receive messages, process • identifier includes both IP
must have identifier address and port numbers
• host device has unique 32-bit associated with process on
/ 128-bit IP address host.
• Q: does IP address of host • example port numbers:
on which process runs suffice • HTTP server: 80
for identifying the process? • mail server: 25
 A: no, many processes • to send HTTP message to
can be running on same gaia.cs.umass.edu web server:
host • IP address: 128.119.245.12
• port number: 80
• more shortly…

Học viện Hàng không Việt Nam


110

App-layer protocol defines


• types of messages exchanged, open protocols:
•e.g., request, • defined in RFCs
response • allows for interoperability
• message syntax: • e.g., HTTP, SMTP
•what fields in proprietary protocols:
messages & how • e.g., Skype
fields are delineated
• message semantics
•meaning of
information in fields
• rules for when and how
processes send & respond to
messages

Học viện Hàng không Việt Nam


111

What transport service does an app need?


data integrity throughput
• some apps (e.g., file transfer,  some apps (e.g.,
web transactions) require 100% multimedia) require
minimum amount of
reliable data transfer throughput to be
• other apps (e.g., audio) can “effective”
tolerate some loss  other apps (“elastic apps”)
make use of whatever
timing throughput they get
• some apps (e.g., Internet
telephony, interactive security
games) require low delay to  encryption, data integrity,
be “effective”

Học viện Hàng không Việt Nam


112

Transport service requirements: common apps

application data loss throughput time sensitive

file transfer no loss elastic no


e-mail no loss elastic no
Web documents no loss elastic no
real-time audio/video loss-tolerant audio: 5kbps-1Mbps yes, 100’s
video:10kbps-5Mbps msec
stored audio/video loss-tolerant same as above
interactive games loss-tolerant few kbps up yes, few secs
text messaging no loss elastic yes, 100’s
msec
yes and no

Học viện Hàng không Việt Nam


113

Internet apps
application underlying
application layer protocol transport 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
streaming multimedia HTTP (e.g., YouTube), TCP or UDP
RTP [RFC 1889]
Internet telephony SIP, RTP, proprietary
(e.g., Skype) TCP or UDP

Học viện Hàng không Việt Nam


114

Web and HTTP

First, a review…
•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, e.g.,
www.someschool.edu/someDept/pic.gif

host name path name

Học viện Hàng không Việt Nam


115

HTTP overview
HTTP: hypertext
transfer protocol
• Web’s application layer
protocol
• client/server model PC running
•client: browser that Firefox browser
requests, receives,
(using HTTP
protocol) and
“displays” Web server
objects running
•server: Web server Apache Web
sends (using HTTP server
protocol) objects in
response to
requests iphone running
Safari browser

Học viện Hàng không Việt Nam


116

HTTP overview (continued)


uses TCP: HTTP is “stateless”
• client initiates TCP connection • server maintains no
(creates socket) to server, port information about past
client requests
80
• server accepts TCP connection
from client aside
protocols that maintain
• HTTP messages (application- “state” are complex!
layer protocol messages)  past history (state) must be
exchanged between browser maintained
(HTTP client) and Web server  if server/client crashes, their
(HTTP server) views of “state” may be
inconsistent, must be
• TCP connection closed reconciled

Học viện Hàng không Việt Nam


117

HTTP connections

non-persistent HTTP persistent HTTP


• at most one object sent • multiple objects can be
over TCP connection sent over single TCP
• connection then closed connection between
• downloading multiple client, server
objects required multiple
connections

Học viện Hàng không Việt Nam


118

Non-persistent HTTP: response time

RTT (definition): time for a small


packet to travel from client to
server and back
initiate TCP
HTTP response time: connection
• one RTT to initiate TCP RTT
connection request
• one RTT for HTTP request and file
first few bytes of HTTP response RTT
time to
transmit
to return file
• file transmission time file
received
• non-persistent HTTP response
time =
time
2RTT+ file transmission time
time

Học viện Hàng không Việt Nam


119

Persistent HTTP

non-persistent HTTP issues: persistent HTTP:


• requires 2 RTTs per object • server leaves connection
open after sending
• OS overhead for each TCP response
connection
• subsequent HTTP messages
• browsers often open parallel between same
TCP connections to fetch client/server sent over
referenced objects open connection
• client sends requests as
soon as it encounters a
referenced object
• as little as one RTT for all
the referenced objects

Học viện Hàng không Việt Nam


120

FTP: the file transfer protocol


file transfer
FTP FTP FTP
user client server
interface
user
at host remote file
local file system
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

Học viện Hàng không Việt Nam


121

FTP: separate control, data connections

TCP control connection,


• FTP client contacts FTP server server port 21
at port 21, using TCP
• client authorized over control TCP data connection,
connection FTP server port 20 FTP
client server
• client browses remote
directory, sends commands  server opens another TCP
over control connection data connection to transfer
• when server receives file another file
transfer command, server  control connection: “out of
opens 2nd TCP data connection band”
(for file) to client  FTP server maintains
“state”: current directory,
• after transferring one file, earlier authentication
server closes data connection
Học viện Hàng không Việt Nam
122

FTP commands, responses


sample commands: sample return codes
• sent as ASCII text over • status code and phrase (as
control channel in HTTP)
• USER username • 331 Username OK,
• PASS password password required
• 125 data
• LIST return list of file in connection already
current directory open; transfer
• RETR filename starting
retrieves (gets) file • 425 Can’t open data
connection
• STOR filename stores
(puts) file onto remote host • 452 Error writing
file

Học viện Hàng không Việt Nam


123

Electronic mail outgoing


message queue
user mailbox
Three major user
components: agent

• user agents mail user


• mail servers server agent
• simple mail transfer protocol: SMTP
SMTP mail user
server agent

User Agent SMTP


• a.k.a. “mail reader” SMTP user
• composing, editing, reading mail
agent
mail messages server
• e.g., Outlook, Thunderbird, user
iPhone mail client agent
• outgoing, incoming messages user
stored on server agent

Học viện Hàng không Việt Nam


124

Electronic mail: mail servers


mail servers: user
agent
• mailbox contains incoming
messages for user mail user
server agent
• message queue of outgoing
(to be sent) mail messages SMTP mail user
• SMTP protocol between mail server agent
servers to send email SMTP
messages
SMTP user
•client: sending mail mail
agent
server server
user
• “server”: receiving agent

mail server user


agent

Học viện Hàng không Việt Nam


125

Electronic Mail: SMTP [RFC 2821]


• uses TCP to reliably transfer email message 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 (like HTTP, FTP)
• commands: ASCII text
• response: status code and phrase
• messages must be in 7-bit ASCI

Học viện Hàng không Việt Nam


126

Scenario: Alice sends message to Bob


1) Alice uses UA to compose 4) SMTP client sends Alice’s
message “to” message over the TCP
bob@someschool.edu connection
2) Alice’s UA sends message to 5) Bob’s mail server places the
her mail server; message message in Bob’s mailbox
placed in message queue 6) Bob invokes his user agent to
3) client side of SMTP opens read message
TCP connection with Bob’s
mail server

1 user mail user


mail agent
agent server server
2 3 6
4
5
Alice’s mail server Bob’s mail server
Học viện Hàng không Việt Nam
127

Mail message format


SMTP: protocol for
exchanging email msgs
header
RFC 822: standard for blank
line
text message format:
• header lines, e.g.,
• To: body
• From:
• Subject:
different from SMTP MAIL
FROM, RCPT TO:
commands!
• Body: the “message”
• ASCII characters only
Học viện Hàng không Việt Nam
128

Mail access protocols


user
mail access user
SMTP SMTP protocol agent
agent
(e.g., POP,
IMAP)

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, download
• IMAP: Internet Mail Access Protocol [RFC 1730]: more
features, including manipulation of stored msgs on server
• HTTP: gmail, Hotmail, Yahoo! Mail, etc.

Học viện Hàng không Việt Nam


129

POP3 (more) and IMAP


more about POP3 IMAP
• previous example uses • keeps all messages in one
POP3 “download and place: at server
delete” mode • allows user to organize
•Bob cannot re- messages in folders
read e-mail if he • keeps user state across
sessions:
changes client
•names of folders
• POP3 “download-and- and mappings
keep”: copies of messages
on different clients between message
• POP3 is stateless across
IDs and folder
sessions name
Học viện Hàng không Việt Nam
130

DNS: domain name system


people: many identifiers: Domain Name System:
•SSN, name, • distributed database implemented
passport # in hierarchy of many name servers
Internet hosts, routers: • application-layer protocol: hosts,
name servers communicate to
•IP address (32 bit) - resolve names (address/name
used for addressing translation)
datagrams • note: core Internet function,
implemented as application-layer
• “name”, e.g., protocol
www.yahoo.com - • complexity at network’s “edge”
used by humans
Q: how to map between IP
address and name, and vice
versa ?

Học viện Hàng không Việt Nam


131

DNS: services, structure


DNS services why not centralize DNS?
• hostname to IP address • single point of failure
translation • traffic volume
• host aliasing • distant centralized database
• canonical, alias names
• maintenance
• mail server aliasing
• load distribution A: doesn’t scale!
•replicated Web
servers: many IP
addresses
correspond to one
name
Học viện Hàng không Việt Nam
132

DNS: a distributed, hierarchical database


Root DNS Servers

… …

com DNS servers org DNS servers edu DNS servers

pbs.org poly.edu umass.edu


yahoo.com amazon.com
DNS servers DNS serversDNS servers
DNS servers DNS servers

client wants IP for www.amazon.com; 1st approx:


• client queries 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

Học viện Hàng không Việt Nam


133

DNS: root name servers


• contacted by local name server that can not resolve name
• root name server:
• contacts authoritative name server if name mapping not known
• gets mapping
• returns mapping to local name server
c. Cogent, Herndon, VA (5 other sites)
d. U Maryland College Park, MD k. RIPE London (17 other sites)
h. ARL Aberdeen, MD
j. Verisign, Dulles VA (69 other sites ) i. Netnod, Stockholm (37 other sites)

e. NASA Mt View, CA m. WIDE Tokyo


f. Internet Software C. (5 other sites)
Palo Alto, CA (and 48 other
sites)

a. Verisign, Los Angeles CA 13 root name


(5 other sites)
b. USC-ISI Marina del Rey, CA
“servers”
l. ICANN Los Angeles, CA worldwide
(41 other sites)
g. US DoD Columbus,
OH (5 other sites)

Học viện Hàng không Việt Nam


134

TLD, authoritative servers

top-level domain (TLD) servers:


• responsible for com, org, net, edu, aero, jobs, museums,
and all top-level country domains, e.g.: uk, fr, ca, jp
• Network Solutions maintains servers for .com TLD
• Educause for .edu TLD
authoritative DNS servers:
• organization’s own DNS server(s), providing authoritative
hostname to IP mappings for organization’s named hosts
• can be maintained by organization or service provider

Học viện Hàng không Việt Nam


135

Local DNS name server


• does not strictly belong to hierarchy
• each ISP (residential ISP, company, university) has one
• also called “default name server”
• when host makes DNS query, query is sent to its local
DNS server
• has local cache of recent name-to-address translation pairs
(but may be out of date!)
• acts as proxy, forwards query into hierarchy

Học viện Hàng không Việt Nam


136
DNS name root DNS server
resolution example
2
• host at cis.poly.edu wants 3
TLD DNS server
IP address for 4
gaia.cs.umass.edu
5

local DNS server


iterated query: dns.poly.edu
 contacted server 7 6
replies with name of 1 8
server to contact
 “I don’t know this authoritative DNS server
dns.cs.umass.edu
name, but ask this requesting host
server” cis.poly.edu

gaia.cs.umass.edu

Học viện Hàng không Việt Nam


137

DNS name root DNS server


resolution example
2 3
recursive query: 7
6
 puts burden of name TLD DNS
resolution on server
contacted name local DNS server
server dns.poly.edu 5 4
 heavy load at upper 1 8
levels of hierarchy?
authoritative DNS server
dns.cs.umass.edu
requesting host
cis.poly.edu

gaia.cs.umass.edu

Học viện Hàng không Việt Nam


138

Pure P2P architecture


• no always-on server
• arbitrary end systems directly
communicate
• peers are intermittently
connected and change IP
addresses

examples:
•file distribution
(BitTorrent)
•Streaming (KanKan)
•VoIP (Skype)

Học viện Hàng không Việt Nam


139

P2P file distribution: BitTorrent


 file divided into 256Kb chunks
 peers in torrent send/receive file chunks

tracker: tracks peers torrent: group of peers


participating in torrent exchanging chunks of a file

Alice arrives …
… obtains list
of peers from tracker
… and begins exchanging
file chunks with peers in torrent

Học viện Hàng không Việt Nam


140

P2P file distribution: BitTorrent


• peer joining torrent:
• has no chunks, but will
accumulate them over
time from other peers
• registers with tracker to
get list of peers, connects
to subset of peers
(“neighbors”)

 while downloading, peer uploads chunks to other peers


 peer may change peers with whom it exchanges chunks
 churn: peers may come and go
 once peer has entire file, it may (selfishly) leave or
(altruistically) remain in torrent

Học viện Hàng không Việt Nam


141

BitTorrent: tit-for-tat
(1) Alice “optimistically unchokes” Bob
(2) Alice becomes one of Bob’s top-four providers; Bob reciprocates
(3) Bob becomes one of Alice’s top-four providers

higher upload rate: find better


trading partners, get file faster !

Học viện Hàng không Việt Nam


142

C. TRAO ĐỔI THÔNG TIN GIỮA


CÁC LAYER

Học viện Hàng không Việt Nam


143

Data Data Data Data


Data Data Data

IP
IP Header
Header Data 11 Data
IP Header 1 IP Header 1

Frame Header
Frame Header IP
IPHeader
Header 11 II IP Header 1
Frame Header IP Header 1 I

Học viện Hàng không Việt Nam


144
TÓM TẮT MÔ HÌNH OSI
Application Cung cấp các dịch vụ mạng cho ứng dụng khác

Presentation Cung cấp các dịch vụ nén, mã hóa và chuyển


đổi dữ liệu
Session Thiết lập, duy trì và điều khiển phiên làm việc

Transport Cung cấp kết nối end-to-end, flow control, sửa


lỗi

Network Định tuyến các gói tin (packet), congestion


control, QoS.
Datalink Cung cấp dịch vụ truy cập đường truyền, phát
hiện lỗi
Physical Chuyển đổi và truyền tải tín hiệu dạng bit
Học viện Hàng không Việt Nam
145

D. OSI vs TCP/IP

Học viện Hàng không Việt Nam


146

Lịch sử phát triển


• Được khởi động từ dự án DARPA của bộ quốc phòng Mĩ.
oCần một mô hình mạng vẫn có khả năng hoạt động
dù bị tấn công phá hủy một phần cơ sở hạ tầng.
oSự ra đời của ARPNet và hệ thống giao thức kết nối
phi tập trung là tiền đề cho mô hình TCP/IP.

Học viện Hàng không Việt Nam


147

Lịch sử phát triển


•Sự phát triển của TCP/IP gắn liền với sự phát triển của
ARPNet những năm đầu thập niên 1970.
oCộng đồng hỗ trợ và sử dụng to lớn.
oĐược hoàn thiện và cải tiến nhanh chóng.
•TCP/IP được xem là 1 phần của UNIX (made in USA)
oGắn liền với hdh Berkeley Unix.
oTCP/IP được xem là mô hình của Mĩ.

Học viện Hàng không Việt Nam


148

Application Layer
Presentation Layer Application Layer
Session Layer
Transport Layer Transport Layer
Network Layer Internet Layer
Datalink Layer
Network Access Layer
Physical Layer
OSI Model TCP/IP Model
OSI vs TCP/IP 4 layers
Học viện Hàng không Việt Nam
149

Application Layer
Presentation Layer Application Layer
Session Layer
Transport Layer Transport Layer
Network Layer Internet Layer
Datalink Layer Datalink Layer
Physical Layer Physical Layer
OSI Model TCP/IP Model
OSI vs TCP/IP 5 layers
Học viện Hàng không Việt Nam
150

OSI Model TCP/IP Model


TCP/IP model Học viện Hàng không Việt Nam
151

Application Layer HTTP, FTP, SMTP, SSH, etc.

Transport Layer TCP, UDP, etc.

Internet Layer IPv4, IPv6, ICMP, etc.

Datalink Layer 802.3, 802.11, MAC, CSMA, etc.

Physical Layer PPP, topology, duplex, transmission

TCP/IP model
Học viện Hàng không Việt Nam
152

SO SÁNH MÔ HÌNH OSI VÀ TCP/IP


Giống nhau
• Mô hình phân lớp.
• Transport, Network, Physical và Datalink layer.
• Phương thức vận chuyển gói tin đều dựa trên Packet-
switching.
Khác nhau
• Mô hình OSI khái quát, TCP/IP liên hệ với Internet.
• Số layer mỗi mô hình.
• Lớp Application trong mô hình TCP/IP mang tính chất
phức tạp hơn so với OSI.

Học viện Hàng không Việt Nam


153

HỌC VIỆN HÀNG KHÔNG VIỆT NAM


154

HỌC VIỆN HÀNG KHÔNG VIỆT NAM

You might also like