程序代写代做代考 FTP dns data structure 3rd Edition: Chapter 2

3rd Edition: Chapter 2

Application Layer
2-*
Chapter 2
Application Layer
Computer Networking: A Top Down Approach

7th edition
Jim Kurose, Keith Ross
Pearson/Addison Wesley
April 2016

Application Layer

*

Application Layer
2-*
Chapter 2: outline
2.1 principles of network applications
2.2 Web and HTTP
2.3 electronic mail
SMTP, POP3, IMAP
2.4 DNS
2.5 P2P applications
2.6 Video streaming and content distribution networks

Application Layer

*

Application Layer
2-*
Chapter 2: application layer
our goals:
conceptual, implementation aspects of network application protocols

transport-layer service models
client-server paradigm
peer-to-peer paradigm
content distribution networks
learn about protocols by examining popular application-level protocols

HTTP
SMTP / POP3 / IMAP
DNS
creating network applications

socket API

Application Layer

*

Application Layer
2-*
Some network apps
e-mail
web
text messaging
remote login
P2P file sharing
multi-user network games
streaming stored video (YouTube, Hulu, Netflix)

voice over IP (e.g., Skype)
real-time video conferencing
social networking
search

Application Layer

*

Application Layer
2-*
Creating a network app
write programs that:
run on (different) end systems
communicate over network
e.g., web server software communicates with browser software

no need to write software for network-core devices
network-core devices do not run user applications
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

*

Application Layer
2-*
Application architectures
possible structure of applications:
client-server
peer-to-peer (P2P)
hybrid of client-server and P2P

Application Layer

*

Application Layer
2-*
Client-server architecture
server:
always-on host
permanent IP address
data centers for scaling

clients:
communicate with server
may be intermittently connected
may have dynamic IP addresses
do not communicate directly with each other

client/server

Application Layer

*

Application Layer
2-*
P2P architecture
no always-on server
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

peer-peer

Application Layer
Advantages: self-scalability, cost-effectiveness
Challenges: security, performance, reliability, incentives, ISPs
*

Hybrid of client-server and P2P
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
centralized service: client presence detection/location
user registers its IP address with central server when it comes online
user contacts central server to find IP addresses of buddies
Application 2-*

Application Layer
2-*
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
aside: applications with P2P architectures have client processes & server processes

clients, servers

Application Layer

*

Application Layer
2-*
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
Internet
controlled
by OS
controlled by
app developer

transport
application
physical
link
network
process

transport
application
physical
link
network
process
socket
API: (1) choice of transport protocol; (2) ability to fix a few parameters (more on this later)

Application Layer

*

Application Layer
2-*
Addressing processes
to receive messages, process must have identifier
host device has unique 32-bit IP address
Q: does IP address of host on which process runs suffice for identifying the process?

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

HTTP server: 80
mail server: 25
to send HTTP message to gaia.cs.umass.edu web server:

IP address: 128.119.245.12
port number: 80
more shortly…

A: no, many processes can be running on same host

Application Layer
Port number: 16-bit unsigned integer
*

Application Layer
2-*
App-layer protocol defines
types of messages exchanged,

e.g., request, response
message syntax:

what fields in messages & how fields are delineated
message semantics

meaning of information in fields
rules for when and how processes send & respond to messages

open protocols:
defined in RFCs
allows for interoperability
e.g., HTTP, SMTP

proprietary protocols:
e.g., Skype

Application Layer
Application vs app layer protocol
*

Application Layer
2-*
What transport service does an app need?
data loss
some apps (e.g., file transfer, web transactions) require 100% reliable data transfer
other apps (e.g., audio) can tolerate some loss

timing
some apps (e.g., Internet telephony, interactive games) require low delay to be “effective”

throughput
some apps (e.g., multimedia) require minimum amount of throughput to be “effective”
other apps (“elastic apps”) make use of whatever throughput they get
security
encryption, data integrity, …

Application Layer

*

Application Layer
2-*
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 ms

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

Application Layer

*

Application Layer
2-*
Internet transport protocols services
TCP 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
does not provide: timing, minimum throughput guarantee, security

UDP service:
unreliable data transfer between sending and receiving process
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

*

Application Layer
2-*
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

*

Securing TCP
TCP & UDP
no encryption
cleartext passwds sent into socket traverse Internet in cleartext
SSL
provides encrypted TCP connection
data integrity
end-point authentication
SSL is at app layer
apps use SSL libraries, that “talk” to TCP

SSL socket API
cleartext passwords sent into socket traverse Internet encrypted
see Chapter 8

Application Layer
2-*

Application Layer

Socket programming
Socket API
introduced in BSD4.1 UNIX, 1981
A socket is explicitly created, used, released by apps
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 an
application process can both send and
receive messages to/from another application process

Goal: learn how to build client/server application that communicate using sockets
Application 2-*

socket

Socket
Socket Family

PF_INET denotes the Internet family
PF_UNIX denotes communication on the same host
PF_PACKET denotes direct access to the network interface (i.e., it bypasses the TCP/IP protocol stack)

Socket Type

SOCK_STREAM is used to denote a byte stream
SOCK_DGRAM is an alternative that denotes a message oriented service, such as that provided by UDP

The University of Adelaide, School of Computer Science
*
Chapter 2 — Instructions: Language of the Computer
*
PF_PACKET, SOCK_RAW equivalent to PF_INET, SOCK_PACKET but the 2nd one is obsolete

fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); or ETH_P_IP, ETH_P_IPV6, ETH_P_ARP, …

PF vs AF: Stevens and beej always use AF

PF_UNIX: communication on the same machine. TYPE = SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET (message oriented that preserves the order)

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
controlled by
application
developer
controlled by
operating
system
client or
server
controlled by
application
developer
controlled by
operating
system
client or
server
internet
Application 2-*
TCP with
buffers,
variables

socket

process
TCP with
buffers,
variables

socket

process

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 (more in Chap 3)
TCP provides reliable, in-order
transfer of bytes (“pipe”)
between client and server
Application 2-*

application viewpoint

Client
process

client TCP socket
Stream jargon
stream is a sequence of bytes that flow into or out of a process.
input stream is attached to some input source for the process, e.g., keyboard or socket.
output stream is attached to an output source, e.g., monitor or socket.

Application 2-*

Creating a Socket
int sockfd = socket(socket_family, type, protocol);

The socket number returned is the socket descriptor for the newly created socket

int sockfd = socket (PF_INET, SOCK_STREAM, 0);
int sockfd = socket (PF_INET, SOCK_DGRAM, 0);

The combination of PF_INET and SOCK_STREAM implies TCP

Application 2-*

The University of Adelaide, School of Computer Science
*
Chapter 2 — Instructions: Language of the Computer
*
PF vs. AF: Stevens, beej always use AF

Client-Server Model with TCP
Server
Passive open
Prepares to accept connection, does not actually establish a connection

Server invokes
int bind (int socket, struct sockaddr *address, int addr_len)
int listen (int socket, int backlog)
int accept (int socket, struct sockaddr *address, int *addr_len)

Application 2-*

The University of Adelaide, School of Computer Science
*
Chapter 2 — Instructions: Language of the Computer
*

Client-Server Model with TCP
Bind
Binds the newly created socket to the specified address i.e. the network address of the local participant (the server)
Address is a data structure which combines IP and port

Listen
Defines how many connections can be pending on the specified socket

Application 2-*

The University of Adelaide, School of Computer Science
*
Chapter 2 — Instructions: Language of the Computer
*

Client-Server Model with TCP
Accept
Carries out the passive open
Blocking operation
Does not return until a remote participant has established a connection
When it does, it returns a new socket that corresponds to the new established connection and the address argument contains the remote participant’s address

Application 2-*

The University of Adelaide, School of Computer Science
*
Chapter 2 — Instructions: Language of the Computer
*

Client-Server Model with TCP
Client
Application performs active open
It says who it wants to communicate with

Client invokes
int connect (int socket, struct sockaddr *address, int addr_len)

Connect
Does not return until TCP has successfully established a connection at which application is free to begin sending data
Address contains remote machine’s address

Application 2-*

The University of Adelaide, School of Computer Science
*
Chapter 2 — Instructions: Language of the Computer
*

Client-Server Model with TCP
In practice
The client usually specifies only remote participant’s address and let’s the system fill in the local information
Whereas a server usually listens for messages on a well-known port
A client does not care which port it uses for itself, the OS simply selects an unused one

Application 2-*

The University of Adelaide, School of Computer Science
*
Chapter 2 — Instructions: Language of the Computer
*

Client-Server Model with TCP
Once a connection is established, the application process invokes two operations

int send (int socket, char *msg, int msg_len,
int flags)

int recv (int socket, char *buff, int buff_len,
int flags)

Application 2-*

The University of Adelaide, School of Computer Science
*
Chapter 2 — Instructions: Language of the Computer
*
Return #bytes written/read

TCP Client/Server Socket Interaction

Application 2-*


input
stream�
clientSocket�
outToServer�
to network�
from network�
inFromServer�
inFromUser�
keyboard�
monitor�
Process�
TCP
socket�
input
stream�
output
stream�

outToServer
to network
from network
inFromServer
inFromUser
keyboard
monitor
Process
clientSocket
input
stream
input
stream
output
stream
TCP
socket

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *