程序代写代做代考 FTP dns Application Layer

Application Layer

All material copyright 1996-2012
J.F Kurose and K.W. Ross, All Rights Reserved

George Parisis
School of Engineering and Informatics

University of Sussex

Application Layer 2-2

Application layer
Objectives:
v  conceptual, implementation aspects of network

application protocols
§  transport-layer service models
§  client-server paradigm
§  peer-to-peer paradigm

v  learn about protocols by examining popular application-
level protocols
§  HTTP
§  SMTP / POP3 / IMAP
§  DNS

v  creating network applications
§  socket API

Application Layer 2-3

Outline

v  Principles of network applications
v  Electronic mail

§  SMTP, POP3, IMAP
v  Web and HTTP
v  DNS
v  socket programming with UDP and TCP

Application Layer 2-4

Some network apps
v  e-mail
v  web
v  text messaging
v  remote login
v  P2P file sharing
v  multi-user network games
v  streaming stored video

(YouTube, Hulu, Netflix)

v  voice over IP (e.g.,
Skype)

v  real-time video
conferencing

v  social networking
v  search
v  …
v  …

Application Layer 2-5

Creating a network app
write programs that:
v  run on (different) end

systems
v  communicate over network
v  e.g., web server software

communicates with
browser software

no need to write software for
network-core devices

v  network-core devices do
not run user applications

v  applications on end
systems allows for rapid
app development,
propagation

application
transport
network
data link
physical

application
transport
network
data link
physical

application
transport
network
data link
physical

Application Layer 2-6

Client-server architecture

server:
v  always-on host
v  permanent IP address
v  data centers for scaling

clients:
v  communicate with server
v  may be intermittently

connected
v  may have dynamic IP

addresses
v  do not communicate

directly with each other

client/server

Application Layer 2-7

P2P architecture
v  no always-on server
v  arbitrary end systems directly

communicate
v  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

v  peers are intermittently
connected and change IP
addresses

v  ISP friendly, Security,
Incentives

peer-peer

Application Layer 2-8

Processes communicating

process: program running
within a host

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

v  processes in different hosts
communicate by
exchanging messages

client process: process
that initiates
communication

server process: process
that waits to be contacted

v  applications with P2P

architectures have client
processes & server
processes

clients, servers

Application Layer 2-9

Sockets
v  process sends/receives messages to/from its socket
v  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

v  API between application and network

Internet

controlled
by OS

controlled by
app developer

transport

application

physical

link

network

process

transport

application

physical

link

network

process
socket

Application Layer 2-10

Addressing processes
v  to receive messages, process must have identifier
v  host device has unique 32-bit IP address (or more)
v  Q: does IP address of host on which process runs

suffice for identifying the process?
§  A: no, many processes can be running on same host

v  identifier includes both IP address and port numbers
associated with process on host.

v  example port numbers:
§  HTTP server: 80
§  mail server: 25

v  to send HTTP message to gaia.cs.umass.edu web
server:
§  IP address: 128.119.245.12
§  port number: 80

v  more shortly…

Application Layer 2-11

Application layer protocol defines

v  types of messages
exchanged:
§  e.g., request,

response
v  message syntax:

§  what fields in
messages & how
fields are delineated

v  message semantics
§  meaning of

information in fields
v  rules for when and how

processes send &
respond to messages

open protocols:
v  defined in RFCs
v  allows for

interoperability
v  e.g., HTTP, SMTP
proprietary protocols:
v  e.g., Skype

Application Layer 2-12

What transport service does an app need?
data integrity
v  some apps (e.g., file

transfer, web transactions)
require 100% reliable data
transfer

v  other apps (e.g., audio) can
tolerate some loss

timing
v  some apps (e.g.,

Internet telephony,
interactive games)
require low delay to be
“effective”

throughput
v  some apps (e.g.,

multimedia) require
minimum amount of
throughput to be
“effective”

v  other apps (“elastic
apps”) make use of
whatever throughput
they get

security
v  encryption, data integrity,

Application Layer 2-13

Transport service requirements: common apps

application

file transfer
e-mail

Web documents
real-time audio/video

stored audio/video
interactive games

text messaging

data loss

no loss
no loss
no loss
loss-tolerant

loss-tolerant
loss-tolerant
no loss

throughput

elastic
elastic
elastic
audio: 5kbps-1Mbps
video:10kbps-5Mbps
same as above
few kbps up
elastic

time sensitive

no
no
no
yes, 100’s msec

yes, few secs
yes, 100’s msec
yes and no

Application Layer 2-14

Internet transport protocols services

TCP service:
v  reliable transport between

sending and receiving
process

v  flow control: sender won’t
overwhelm receiver

v  congestion control: throttle
sender when network
overloaded

v  does not provide: timing,
minimum throughput
guarantee, security

v  connection-oriented:
setup required between
client and server
processes

UDP service:
v  unreliable data transfer

between sending and
receiving process

v  does not provide:
reliability, flow control,
congestion control,
timing, throughput
guarantee, security, or
connection setup

Q: why bother? Why is
there a UDP?

Application Layer 2-15

Internet apps: application, transport protocols

application

e-mail
remote terminal access

Web
file transfer

streaming multimedia

Internet telephony

application
layer protocol

SMTP [RFC 2821]
Telnet [RFC 854]
HTTP [RFC 2616]
FTP [RFC 959]
HTTP (e.g., YouTube),
RTP [RFC 1889]
SIP, RTP, proprietary
(e.g., Skype)

underlying
transport protocol

TCP
TCP
TCP
TCP
TCP or UDP

TCP or UDP

Application Layer 2-16

Outline

v  Principles of network applications
v  Electronic mail

§  SMTP, POP3, IMAP
v  Web and HTTP
v  DNS
v  socket programming with UDP and TCP

Application Layer 2-17

Electronic mail
Three major components:
v  user agents
v  mail servers
v  Simple Mail Transfer

Protocol: SMTP

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

mail messages
v  e.g., Outlook, Thunderbird,

iPhone mail client
v  outgoing, incoming

messages stored on server

user mailbox

outgoing
message queue

mail
server

mail
server

mail
server

SMTP

SMTP

SMTP

user
agent

user
agent

user
agent

user
agent

user
agent

user
agent

Application Layer 2-18

Electronic mail: mail servers
mail servers:
v  mailbox contains

incoming messages for
user

v  message queue of
outgoing (to be sent)
mail messages

v  SMTP protocol between
mail servers to send
email messages
§  client: sending mail

server
§  “server”: receiving

mail server

mail
server

mail
server

mail
server

SMTP

SMTP

SMTP

user
agent

user
agent

user
agent

user
agent

user
agent

user
agent

Application Layer 2-19

Electronic Mail: SMTP [RFC 2821]
v  uses TCP to reliably transfer email message

from client to server, port 25
v  direct transfer: sending server to receiving

server
v  three phases of transfer

§  handshaking (greeting)
§  transfer of messages
§  closure

v  command/response interaction (like HTTP,
FTP)
§  commands: ASCII text
§  response: status code and phrase

v  messages must be in 7-bit ASCI

Application Layer 2-20

user
agent

Scenario: Alice sends message to Bob

1) Alice uses UA to compose
message “to”
bob@someschool.edu

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

mail
server

mail
server

1
2 3 4

5
6

Alice’s mail server Bob’s mail server

user
agent

Application Layer 2-21

Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM:
S: 250 alice@crepes.fr… Sender ok
C: RCPT TO:
S: 250 bob@hamburger.edu … Recipient ok
C: DATA
S: 354 Enter mail, end with “.” on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection

Application Layer 2-22

Try SMTP interaction for yourself:
v  telnet servername 25
v  see 220 reply from server
v  enter HELO, MAIL FROM, RCPT TO, DATA, QUIT

commands

above lets you send email without using email client

Application Layer 2-23

Mail message format

SMTP: protocol for
exchanging email msgs

RFC 5322: standard for
text message format:

v  header lines, e.g.,
§  To:
§  From:
§  Subject:
different from SMTP

MAIL FROM, RCPT
TO: commands!

v  Body: the “message”
§  ASCII characters only

header

body

blank
line

Application Layer 2-24

Mail access protocols

v  SMTP: delivery/storage to receiver’s server
v  Recipients could run SMTP servers but …
v  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.

sender’s mail
server

SMTP SMTP
mail access

protocol

receiver’s mail
server

(e.g., POP,
IMAP)

user
agent

user
agent

Application Layer 2-25

POP3 protocol

authorization phase
v  client commands:

§  user: declare username
§  pass: password

v  server responses
§  +OK
§  -ERR

transaction phase, client:
v  list: list message numbers
v  retr: retrieve message by

number
v  dele: delete
v  quit

C: list
S: 1 498
S: 2 912
S: .
C: retr 1
S:
S: .
C: dele 1
C: retr 2
S:
S: .
C: dele 2
C: quit
S: +OK POP3 server signing off

S: +OK POP3 server ready
C: user bob
S: +OK
C: pass hungry
S: +OK user successfully logged on

Application Layer 2-26

POP3 (more)

more about POP3
v  previous example uses POP3 “download and delete”

mode
§  Bob cannot re-read e-mail if he changes client

v  POP3 “download-and-keep”: copies of messages on
different clients

v  POP3 is stateless across sessions (keeps state
throughout a session– messages marked for deletion)

IMAP

Application Layer 2-27

v  for nomadic users (i.e. all of us in 201X) – complex protocol
v  keeps all messages in one place: at server
v  allows user to organize messages in folders (at server)
v  keeps user state across sessions:

§  names of folders and mappings between message IDs
and folder name

v  users can get parts of a multi-part message
§  low-bandwidth or expensive connectivity

e-mail over HTTP

Application Layer 2-28

v  user agent = browser
v  accessing email becomes a Web Application running on

top of HTTP
v  sending/pushing an email to the user’s SMTP server is

also done through HTTP (instead of SMTP)
v  server-to-server communication as usual

Multipurpose Internet Mail Extensions
(MIME)
v  an Internet standard that extends the format of email

to support…
§  text in character sets other than ASCII
§  non-text attachments: audio, video, images, application

programs
§  Message bodies with multiple parts

v  all human-written Internet email is transmitted via
SMTP in MIME format

v  MIME designed for SMTP but extensively used in
HTTP

v  Content-Type
§  text/plain, multipart/mixed, image/jpeg, audio/mp3, video/

mp4, and application/msword
§  http://www.freeformatter.com/mime-types-list.html Application Layer 2-29

Application Layer 2-30

Summary

v  application architectures
§  client-server
§  P2P

v  application service requirements:
§  reliability, bandwidth, delay

v  Internet transport service model
§  connection-oriented, reliable: TCP
§  unreliable, datagrams: UDP

v  SMTP, POP, IMAP