0% found this document useful (0 votes)
5 views37 pages

Ch_2 C_V7.01_J

Chapter 2 of the document covers the Application Layer in computer networking, focusing on principles of network applications, P2P applications, video streaming, and socket programming. It discusses the differences between client-server and P2P file distribution methods, highlighting the efficiency of P2P systems like BitTorrent. Additionally, it addresses the challenges of streaming content through Content Distribution Networks (CDNs) and provides insights into socket programming using both UDP and TCP protocols.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views37 pages

Ch_2 C_V7.01_J

Chapter 2 of the document covers the Application Layer in computer networking, focusing on principles of network applications, P2P applications, video streaming, and socket programming. It discusses the differences between client-server and P2P file distribution methods, highlighting the efficiency of P2P systems like BitTorrent. Additionally, it addresses the challenges of streaming content through Content Distribution Networks (CDNs) and provides insights into socket programming using both UDP and TCP protocols.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

LHU COMP 200

Chapter 2 ( 2 C )
Application Layer

These slides are not a substitute for


reading the text. Slides drawn from: Computer
Networking: A Top Down
Approach
7th edition.
Jim Kurose, Keith Ross
Pearson/Addison Wesley

Introduction 1-1
Chapter 2: outline
2.1 principles of network 2 C Slides:
applications 2.5 P2P applications ***
2.2 Web and HTTP 2.6 video streaming and
nt. traditional caching content distribution
(not in text) networks
2 B Slides: 2.7 socket programming
2.3 electronic mail with UDP and TCP
• SMTP, POP3, IMAP
2.4 DNS

Application Layer 2-2


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)

Application Layer 2-3


File distribution: client-server vs P2P
Question: how much time to distribute file
from one server to N peers?
• peer upload/download capacity is limited resource
us: server upload
capacity

di: peer i download


file, size F u1 d1 capacity
us u2 d2
server
di
uN network (with abundant
bandwidth) ui
dN
ui: peer i upload
capacity
p 140
Application Layer 2-4
File distribution time: client-server
 server transmission: F = File Size ; us = Upload Speed
sequentially send file time to send one copy: F/us
(upload) N copies:
time to send N copies : NF/us
 client: each client must dmin = min. client dnld Rate
download file copy
min. client dnld Time: F/dmin
Time to distribute
F to N clients (using Dc-s > max{NF/us,,F/dmin}
client-server approach)

increases linearly in N
Application Layer 2-5
File distribution time:
First Client Server Not to P2P
“Many hands make light work.”

F
us

di

network
ui

Application Layer 2-6


File distribution time: P2P
 server transmission: must
upload at least one copy F
us
• time to send one copy: F/us
di
 client: each client must network
download file copy ui
• min client download time: F/dmin
 clients: as aggregate must download NF bits
• max upload rate (limiting max download rate) is us + Sui
Tme to distribute F
to N nodes/clients
P2P approach DP2P > max{F/us,,F/dmin,,NF/(us + Sui)}

increases linearly in N …
… but so does this, as each peer brings service capacity
Application Layer 2-7
Comparison: Time to distribute to N

client-server Dc-s > max{NF/us,,F/dmin}

increases linearly in N

P2P DP2P > max{F/us,,F/dmin,,NF/(us + Sui)}

increases linearly in N …
… but so does this, as each peer brings service capacity
Application Layer 2-8
Client-server vs. P2P: example
“Many hands make light work.”
client upload rate = u, F/u = 1 hour, us = 10u, dmin ≥ us
3.5
P2P
Minimum Distribution Time

3
Client-Server
2.5

1.5

0.5

0
0 5 10 15 20 25 30 35

N
Application Layer 2-9
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

sharing
chunks
1 Alice arrives …
2 obtains list
of peers from tracker
3 begins exchanging p 144
file chunks with peers in torrent

Application Layer 2-10


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, peers 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

Application Layer 2-11


BitTorrent: requesting, sending file chunks

requesting chunks: sending chunks: tit-for-tat


 at any given time, different  Alice sends chunks to those
peers have different subsets four peers currently sending her
of file chunks chunks at highest rate
 periodically, a peer (e.g., • other peers are choked by Alice
Alice) asks each peer for list (do not receive chunks from her)
of chunks that they have • re-evaluate top 4 every10 secs
 Alice requests missing  every 30 secs: randomly select
chunks from peers, rarest another peer, starts sending
first chunks
• “optimistically unchoke” this peer
• newly chosen peer may join top 4

Application Layer 2-12


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 !

Application Layer 2-13


Chapter 2: outline
2.1 principles of network 2 C Slides:
applications 2.5 P2P applications
2.2 Web and HTTP 2.6 ** video streaming
nt. traditional caching and content
(not in text) distribution networks
2 B Slides: 2.7 socket programming
2.3 electronic mail with UDP and TCP
• SMTP, POP3, IMAP
2.4 DNS

Application Layer 2-14


Video Streaming and CDNs: context
 video traffic: major consumer of Internet bandwidth
• Netflix, YouTube: 37%, 16% of downstream
residential ISP traffic
• ~1B YouTube users, ~75M Netflix users
 challenge: scale - how to reach ~1B
users?
• single mega-video server won’t work (why?)
 challenge: heterogeneity
 different users have different capabilities (e.g.,
wired versus mobile; bandwidth rich versus
bandwidth poor)
 solution: distributed, application-level
infrastructure p 147
Application Layer 2-15
Multimedia: video
spatial coding example: instead
of sending N values of same
color (all purple), send only two
values: color value (purple) and
number of repeated values (N)
 video: sequence of images
displayed at constant rate ……………………..
……………….…….
• e.g., 24 images/sec
 digital image: array of pixels
• each pixel represented
by bits
 Coding/Compression: use frame i
redundancy within and
between images to decrease
# bits used to encode
image temporal coding example:
• spatial (within image) instead of sending
complete frame at i+1,
• temporal (from one send only differences from
frame i frame i+1
image to next)
Application Layer 2-16
Streaming stored video:
simple scenario:

Internet

video server client


(stored video)

Application Layer 2-17


Streaming multimedia: DASH
 DASH: Dynamic, Adaptive Streaming over HTTP
 server:
• divides video file into multiple chunks
• each chunk stored, encoded at different rates
• manifest file: provides URLs for different chunks
 client:
• periodically measures server-to-client bandwidth
• consulting manifest, requests one chunk at a time
• chooses maximum coding rate sustainable given
current bandwidth p 148
• can choose different coding rates at different points
in time (depending on available bandwidth at time)
Application Layer 2-18
Streaming multimedia: DASH
 DASH: Dynamic, Adaptive Streaming over HTTP
 “intelligence” at client: client determines
• when to request chunk (so that buffer starvation, or
overflow does not occur)
• what encoding rate to request (higher quality when
more bandwidth available)
• where to request chunk (can request from URL server
that is “close” to client or has high available
bandwidth)

Application Layer 2-19


CDN: Content distribution networks
 challenge: how to stream content (selected from
millions of videos) to hundreds of thousands of
simultaneous users?

 Simple/Wrong “solution”: one large “mega-server”


• single point of failure
• point of network congestion
• long path to distant clients
• multiple copies of video sent over outgoing link
this solution doesn’t scale

p 149
Application Layer 2-20
CDN: Content distribution networks
 challenge: stream content (selected from millions
of videos) to hundreds of thousands of
simultaneous users?
 Solution: store/serve multiple copies of videos at
multiple geographically distributed sites (CDN)
• enter deep: push CDN servers deep into many access
networks
• close to users: In ISPs
• used by Akamai, 1700 locations
• bring home: smaller number (10’s) of larger clusters in
POPs near (but not within) access networks
• At IXPs (Intenet eXchange Points) (See Sec. 1.4)
• used by Limelight p 150
Application Layer 2-21
Content Distribution Networks (CDNs)
 CDN: stores copies of content at CDN nodes
• e.g. Netflix stores copies of MadMen
 subscriber requests content from CDN
• directed to nearby copy, retrieves content
• may choose different copy if network path congested

manifest file
where’s Madmen?

Application Layer 2-22


Content Distribution Networks (CDNs)
challenges: coping with a congested Internet
 from which CDN node to retrieve content?
 viewer behavior in presence of congestion?
 what content to place in which CDN node?
• more .. in chapter 7

manifest file
where’s Madmen?

Application Layer 2-23


Case study: Netflix
Amazon cloud upload copies of
multiple versions of
video to CDN servers
CDN
server
Netflix registration,
accounting servers
3. Manifest file
2. Bob browses returned for
CDN
Netflix video 2 requested video server
3
1

1. Bob manages
Netflix account CDN
server

4. DASH
streaming p 154
Application Layer 2-24
Chapter 2: outline
2.1 principles of network 2.5 P2P applications
applications 2.6 video streaming and
2.2 Web and HTTP content distribution
2.3 electronic mail networks
• SMTP, POP3, IMAP 2.7 socket programming
2.4 DNS with UDP and TCP **

Application Layer 2-25


Socket programming
goal: learn how to build client/server applications that
communicate using sockets
socket: door between application process and end-
end-transport protocol

application application
socket controlled by
process process app developer

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

p 157-8
Application Layer 2-26
Socket programming
Two socket types for two transport services:
• UDP: unreliable datagram
• TCP: reliable, byte stream-oriented

Application Example:
1. client reads a line of characters (data) from its
keyboard and sends data to server
2. server receives the data and converts characters
to uppercase
3. server sends modified data to client
4. client receives modified data & displays on screen

Application Layer 2-27


Socket programming with UDP
UDP: no “connection” between client & server
 no handshaking before sending data
 sender explicitly attaches IP destination address and
port # to each packet
 receiver extracts sender IP address and port# from
received packet
UDP: transmitted data may be lost or received
out-of-order
Application viewpoint:
 UDP provides unreliable transfer of groups of bytes
(“datagrams”) between client and server
p 159
Application Layer 2-28
Client/server socket interaction: UDP

server (running on serverIP) client


create socket:
create socket, port= x: clientSocket =
serverSocket = socket(AF_INET,SOCK_DGRAM)
socket(AF_INET,SOCK_DGRAM)
Create datagram with server IP and
port=x; send datagram via
read datagram from clientSocket
serverSocket

write reply to
serverSocket read datagram from
specifying clientSocket
client address,
port number close
clientSocket p 160
Application 2-29
Example app: UDP client
Python UDPClient
include Python’s socket
library
from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for clientSocket = socket(AF_INET,
server
SOCK_DGRAM)
get user keyboard
input message = raw_input(’Input lowercase sentence:’)
Attach server name, port to clientSocket.sendto(message.encode(),
message; send into socket
(serverName, serverPort))
read reply characters from modifiedMessage, serverAddress =
socket into string
clientSocket.recvfrom(2048)
print out received string print modifiedMessage.decode()
and close socket
p 161-2
clientSocket.close()
Application Layer 2-30
Example app: UDP server
Python UDPServer
from socket import *
serverPort = 12000
create UDP socket serverSocket = socket(AF_INET, SOCK_DGRAM)
bind socket to local port
number 12000
serverSocket.bind(('', serverPort))
print (“The server is ready to receive”)
loop forever while True:
Read from UDP socket into message, clientAddress = serverSocket.recvfrom(2048)
message, getting client’s
address (client IP and port) modifiedMessage = message.decode().upper()
send upper case string serverSocket.sendto(modifiedMessage.encode(),
back to this client
clientAddress)

p 163-4
Application Layer 2-31
Socket programming with TCP
client must contact server  when contacted by client,
 server process must first be server TCP creates new
running socket for server process
 server must have created to communicate with that
welcome socket (door) particular client
for client(s) to contact • allows server to talk with
multiple clients
client contacts server by: • source port numbers used
 Creating TCP socket, to distinguish clients
specifying IP address, port (more in Chap 3)
number of server process
 when client creates socket: application viewpoint:
client TCP establishes TCP provides reliable, in-order
connection to server TCP byte-stream transfer (“pipe”)
between client and server
p 165
Application Layer 2-32
Client/server socket interaction: TCP
server (running on hostid) client
create socket,
port=x, for incoming
request:
serverSocket = socket()

wait for incoming create socket,


connection request
TCP connect to hostid, port=x
connectionSocket = connection setup clientSocket = socket()
serverSocket.accept()

send request using


read request from clientSocket
connectionSocket

write reply to
connectionSocket read reply from
clientSocket
close
connectionSocket close
clientSocket
p 167
Application Layer 2-33
Example app: TCP client
Python TCPClient
from socket import *
serverName = ’servername’
create TCP socket for
serverPort = 12000
server, remote port 12000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
sentence = raw_input(‘Input lowercase sentence:’)
No need to attach server clientSocket.send(sentence.encode())
name, port
modifiedSentence = clientSocket.recv(1024)
print (‘From Server:’, modifiedSentence.decode())
clientSocket.close()

p 166-8
Application Layer 2-34
Example app: TCP server
Python TCPServer
from socket import *
create TCP welcoming serverPort = 12000
socket serverSocket = socket(AF_INET,SOCK_STREAM)
serverSocket.bind((‘’,serverPort))
server begins listening for
incoming TCP requests serverSocket.listen(1)
print ‘The server is ready to receive’
loop forever
while True:
server waits on accept()
for incoming requests, new
connectionSocket, addr = serverSocket.accept()
socket created on return

sentence = connectionSocket.recv(1024).decode()
read bytes from socket (but
not address as in UDP) capitalizedSentence = sentence.upper()
close connection to this connectionSocket.send(capitalizedSentence.
client (but not welcoming
socket) encode())
connectionSocket.close()
Application Layer 2-35
Chapter 2: summary
our study of network apps now complete!
 application architectures  specific protocols:
• client-server • HTTP
• P2P • SMTP, POP, IMAP
 application service
requirements: • DNS
• reliability, bandwidth, delay • P2P: BitTorrent
 Internet transport service  video streaming, CDNs
model  socket programming:
• connection-oriented,
TCP, UDP sockets
reliable: TCP
• unreliable, datagrams: UDP

Application Layer 2-36


Chapter 2: summary
most importantly: learned about protocols!

 typical request/reply important themes:


message exchange:
 control vs. messages
• client requests info or
service • in-band, out-of-band
• server responds with  centralized vs. decentralized
data, status code
 stateless vs. stateful
 message formats:
 reliable vs. unreliable message
• headers: fields giving
info about data transfer
• data: info(payload)  “complexity at network
being communicated edge”

Application Layer 2-37

You might also like