0% found this document useful (0 votes)
23 views72 pages

Chapter - 2 CN

Uploaded by

240528
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views72 pages

Chapter - 2 CN

Uploaded by

240528
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 72

Chapter 2

Application
Layer

Application Layer: 2-1


Application Layer
The Application Layer of OSI (Open System Interconnection)
model, is the top layer in this model and takes care of network
communication.
The application layer provides the functionality to send and
receive data from users. It acts as the interface between the
user and the application. The application provides services like
file transmission, mail service, and many more
Application Layer Protocols
•HTTP (Hypertext Transfer Protocol): Used by web browsers to retrieve and display web pages, allowing users
to access and interact with websites. It enables client-server communication over the internet.

•FTP (File Transfer Protocol): Facilitates the transfer of files between a client and server, allowing users
to upload or download files securely across networks.
•SMTP (Simple Mail Transfer Protocol): Responsible for sending emails from client to
server and between
email servers, ensuring email delivery across different networks.

•DNS (Domain Name System): Translates domain names into IP addresses, allowing users
to access websites by name rather than IP, simplifying internet navigation.

•DHCP (Dynamic Host Configuration Protocol): Assigns IP addresses to devices on a


network
automatically, ensuring devices can connect and communicate without manual
configuration.
An application-layer protocol defines:
 types of messages exchanged, open protocols:
• e.g., request, response  defined in RFCs, everyone
 message syntax: has access to protocol
• what fields in messages & definition
how fields are delineated  allows for interoperability
 message semantics  e.g., HTTP, SMTP
• meaning of information in proprietary protocols:
fields  e.g., Skype, Zoom
 rules for when and how
processes send & respond to
messages
Application Layer: 2-5
What transport service does an app need?

data integrity throughput


 some apps (e.g., file transfer,  some apps (e.g., multimedia)
web transactions) require require minimum amount of
100% reliable data transfer throughput to be “effective”
 other apps (e.g., audio) can  other apps (“elastic apps”)
tolerate some loss make use of whatever
throughput they get
timing
 some apps (e.g., Internet security
telephony, interactive games)  encryption, data integrity,
require low delay to be “effective” …
Application Layer: 2-6
Internet transport protocols services
TCP service: UDP service:
 reliable transport between sending  unreliable data transfer
and receiving process between sending and receiving
 flow control: sender won’t process
overwhelm receiver  does not provide: reliability,
 congestion control: throttle sender flow control, congestion
when network overloaded control, timing, throughput
guarantee, security, or
 connection-oriented: setup required
connection setup.
between client and server processes
 does not provide: timing, minimum Q: why bother? Why
throughput guarantee, security is there a UDP?
Application Layer: 2-7
Securing TCP
Vanilla TCP & UDP sockets: TLS implemented in
 no encryption application layer
 cleartext passwords sent into socket  apps use TLS libraries, that
traverse Internet in cleartext (!) use TCP in turn
Transport Layer Security (TLS)  cleartext sent into “socket”
 provides encrypted TCP connections traverse Internet encrypted
 data integrity  more: Chapter 8
 end-point authentication

Application Layer: 2-8


Application layer: overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-9


Web and HTTP
First, a quick review…
 web page consists of objects, each of which can be stored on
different Web servers
 object can be HTML file, JPEG image, Java applet, audio file,…
 web page consists of base HTML-file which includes several
referenced objects, each addressable by a URL, e.g.,
www.someschool.edu/someDept/pic.gif

host name path name

Application Layer: 2-10


HTTP overview
HTTP: hypertext transfer protocol
 Web’s application-layer protocol
HT
 client/server model: PC running
TP
req
ues
HT t
• client: browser that requests, Firefox browser TP
res
pon
receives, (using HTTP protocol) and se

“displays” Web objects ues


t
req
• server: Web server sends (using HTTP
p o ns
e server running
es Apache Web
HTTP protocol) objects in response HTTP
r
server
to requests
iPhone running
Safari browser

Application Layer: 2-11


HTTP overview (continued)
HTTP uses TCP: HTTP is “stateless”
 client initiates TCP connection  server maintains no
(creates socket) to server, port 80 information about past client
 server accepts TCP connection requests
from client
 HTTP messages (application-layer
protocol messages) exchanged
between browser (HTTP client) and
Web server (HTTP server)
 TCP connection closed

Application Layer: 2-12


HTTP request messages
POST method:
 web page often includes form
input
 user input sent from client to
server in entity body of HTTP
POST request message

GET method (for sending data to server):


 include user data in URL field of HTTP
GET request message (following a ‘?’):
www.somesite.com/animalsearch?monkeys&banana

Application Layer: 2-13


HTTP response status codes
 status code appears in 1st line in server-to-client response message.
 some 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 (in
Location: field)
400 Bad Request
• request msg not understood by server
404 Not Found
• requested document not found on this server
505 HTTP Version Not Supported
Application Layer: 2-14
Application layer: overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-15


E-mail user
agent
Three major components: mail user
 user agents server agent
 mail servers SMTP mail user
 simple mail transfer protocol: SMTP server agent
SMTP

User Agent SMTP user


agent
mail
 a.k.a. “mail reader” server
user
 composing, editing, reading mail messages agent
 e.g., Outlook, iPhone mail client user
agent
 outgoing, incoming messages stored on outgoing
message queue
server user mailbox

Application Layer: 2-16


E-mail: mail servers user
agent
mail servers: mail user
server
 mailbox contains incoming agent

messages for user SMTP mail user


server agent
 message queue of outgoing (to be SMTP
sent) mail messages
SMTP user
SMTP protocol between mail mail
server
agent

servers to send email messages user


agent
 client: sending mail server user
 “server”: receiving mail server agent
outgoing
message queue
user mailbox

Application Layer: 2-17


SMTP RFC (5321) “client”
SMTP server
“server”
SMTP server

 uses TCP to reliably transfer email message


initiate TCP
from client (mail server initiating connection
connection) to server, port 25 RTT
 direct transfer: sending server (acting like client) TCP connection
initiated
to receiving server
 three phases of transfer 220
• SMTP handshaking (greeting) SMTP HELO
handshaking
• SMTP transfer of messages 250 Hello
• SMTP closure
 command/response interaction (like HTTP) SMTP
• commands: ASCII text transfers
• response: status code and phrase time
Application Layer: 2-18
Scenario: Alice sends e-mail to Bob
1) Alice uses UA to compose e-mail 4) SMTP client sends Alice’s message
message “to” bob@someschool.edu over the TCP connection
2) Alice’s UA sends message to her 5) Bob’s mail server places
mail server using SMTP; message the message in Bob’s
placed in message queue mailbox
3) client side of SMTP at mail server 6) Bob invokes his user
opens TCP connection with Bob’s mail agent to read message
server

1 user mail user


mail agent
agent server server
2 3 6
4
5
Alice’s mail server Bob’s mail server
Application Layer: 2-19
Retrieving email: mail access protocols
user
e-mail access user
SMTP SMTP protocol
agent agent
(e.g., IMAP,
HTTP)

sender’s e-mail receiver’s e-mail


server server

 SMTP: delivery/storage of e-mail messages to receiver’s server


 mail access protocol: retrieval from server
• IMAP: Internet Mail Access Protocol [RFC 3501]: messages stored on server, IMAP
provides retrieval, deletion, folders of stored messages on server
 HTTP: gmail, Hotmail, Yahoo!Mail, etc. provides web-based interface on
top of STMP (to send), IMAP (or POP) to retrieve e-mail messages
Application Layer: 2-20
Application Layer: Overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-21


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

Application Layer: 2-22


DNS: services, structure
DNS services:
 hostname-to-IP-address translation
 host aliasing
• canonical, alias names
 mail server aliasing
 load distribution
• replicated Web servers: many IP
addresses correspond to one
name

Application Layer: 2-23


Thinking about the DNS
humongous distributed database:
 ~ billion records, each simple
handles many trillions of queries/day:
 many more reads than writes
 performance matters: almost every
Internet transaction interacts with
DNS
organizationally, physically decentralized:
 millions of different organizations
responsible for their records
“bulletproof”: reliability, security
Application Layer: 2-24
DNS: a distributed, hierarchical database

Root DNS Servers Root


… …
.com DNS servers .org DNS servers .edu DNS servers Top Level Domain
… … … …
yahoo.com amazon.com pbs.org nyu.edu umass.edu
DNS servers DNS servers DNS servers DNS servers DNS servers Authoritative

Client wants IP address for www.amazon.com; 1st approximation:


 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
Application Layer: 2-25
DNS security
DDoS attacks Spoofing attacks
 bombard root servers with  intercept DNS queries,
traffic returning bogus replies
 DNS cache poisoning
• not successful to date
 RFC 4033: DNSSEC
• traffic filtering
authentication services
• local DNS servers cache IPs of TLD
servers, allowing root server
bypass
 bombard TLD servers
• potentially more dangerous

Application Layer: 2-26


Application Layer: Overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-27


Peer-to-peer (P2P) architecture
 no always-on server mobile network
 arbitrary end systems directly national or global ISP

communicate
 peers request service from other
peers, provide service in return to
other peers local or
regional ISP
• self scalability – new peers bring new
service capacity, and new service demands home network content
 peers are intermittently connected provider
network datacenter
network
and change IP addresses
• complex management
 examples: P2P file sharing (BitTorrent), enterprise
network
streaming (KanKan), VoIP (Skype)
Application Layer: 2-28
File distribution: client-server vs P2P
Q: how much time to distribute file (size F) 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 u2 capacity
us d2
server
di
uN network (with abundant
bandwidth) ui
dN
ui: peer i upload
capacity
Introduction: 1-29
File distribution time: client-server
 server transmission: must sequentially
send (upload) N file copies:
F
• time to send one copy: F/us us

• time to send N copies: NF/us di


network
ui
 client: each client must download
file copy
• dmin = min client download rate
• min client download 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 Introduction: 1-30


File distribution time: P2P
 server transmission: must upload at
least one copy:
F
• time to send one copy: F/us us
 client: each client must download di
network
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

time to distribute F
to N clients using
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-31
Client-server vs. P2P: example
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-32
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

Application Layer: 2-33


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

Application Layer: 2-34


BitTorrent: requesting, sending file chunks

Requesting chunks: Sending chunks: tit-for-tat


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


Application layer: overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-37


Video Streaming and CDNs: context

 stream video traffic: major


consumer of Internet bandwidth
• Netflix, YouTube, Amazon Prime: 80% of
residential ISP traffic (2020)
 challenge: scale - how to reach
~1B users?
 challenge: heterogeneity
 different users have different capabilities (e.g., wired
versus mobile; bandwidth rich versus bandwidth poor)
 solution: distributed, application-level infrastructure
Application Layer: 2-38
Multimedia: video spatial coding example: instead
of sending N values of same
color (all purple), send only two
values: color value (purple) and
 video: sequence of images number of repeated values (N)

displayed at constant rate ……………………..


……………….…….
• e.g., 24 images/sec
 digital image: array of pixels
• each pixel represented by bits
 coding: use redundancy within and frame i
between images to decrease # bits
used to encode image
• spatial (within image) temporal coding example:
instead of sending
• temporal (from one image to complete frame at i+1,

next) send only differences from


frame i frame i+1

Application Layer: 2-39


Multimedia: video spatial coding example: instead
of sending N values of same
color (all purple), send only two
values: color value (purple) and
 CBR: (constant bit rate): video number of repeated values (N)

encoding rate fixed ……………………..


……………….…….
 VBR: (variable bit rate): video
encoding rate changes as
amount of spatial, temporal
coding changes
 examples: frame i
• MPEG 1 (CD-ROM) 1.5 Mbps
• MPEG2 (DVD) 3-6 Mbps
temporal coding example:
• MPEG4 (often used in instead of sending
complete frame at i+1,
Internet, 64Kbps – 12 Mbps) send only differences from
frame i frame i+1

Application Layer: 2-40


Streaming stored video
simple scenario:

Internet
video server
client
(stored video)

Main challenges:
 server-to-client bandwidth will vary over time, with changing network
congestion levels (in house, access network, network core, video server)
 packet loss, delay due to congestion will delay playout, or result in poor
video quality
Application Layer: 2-41
Streaming stored video
Cumulative data

2. video
sent
1. video 3. video received, played out at client
recorded (30 frames/sec)
(e.g., 30 time
network delay
frames/sec) (fixed in this
example)
streaming: at this time, client playing out
early part of video, while server still sending
later part of video
Application Layer: 2-42
Streaming stored video: challenges
 continuous playout constraint: during client
video playout, playout timing must match
original timing
• … but network delays are variable (jitter), so will
need client-side buffer to match continuous playout
constraint
 other challenges:
• client interactivity: pause, fast-forward, rewind,
jump through video
• video packets may be lost, retransmitted
Application Layer: 2-43
Streaming stored video: playout buffering

constant bit
Cumulative data rate video client video constant bit
transmission reception rate video
playout at client
variable
network

buffered
video
delay

client playout time


delay

 client-side buffering and playout delay: compensate for


network-added delay, delay jitter
Application Layer: 2-44
Dynamic, Adaptive
Streaming multimedia:Streaming
DASH over HTTP
server:
 divides video file into multiple chunks ...
 each chunk encoded at multiple different rates ...
 different rate encodings stored in different files
?
 files replicated in various CDN nodes
...
 manifest file: provides URLs for different chunks client

client:
 periodically estimates server-to-client bandwidth
 consulting manifest, requests one chunk at a time
• chooses maximum coding rate sustainable given current bandwidth
• can choose different coding rates at different points in time (depending
on available bandwidth at time), and from different servers
Application Layer: 2-45
Streaming multimedia: DASH
 “intelligence” at client: client
determines ...
• when to request chunk (so that buffer ...

starvation, or overflow does not occur) ?


• what encoding rate to request (higher ...
client
quality when more bandwidth
available)
• where to request chunk (can request
from URL server that is “close” to
client or has high available
bandwidth)
Streaming video = encoding + DASH + playout buffering
Application Layer: 2-46
Content distribution networks (CDNs)
challenge: how to stream content (selected from millions of
videos) to hundreds of thousands of simultaneous users?
 option 1: single, large “mega-
server”
• single point of failure
• point of network congestion
• long (and possibly congested) path
to distant clients

….quite simply: this solution doesn’t scale


Application Layer: 2-47
Content distribution networks (CDNs)
challenge: how to stream content (selected from millions of
videos) to hundreds of thousands of simultaneous users?
 option 2: 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
• Akamai: 240,000 servers deployed
in > 120 countries (2015)
• bring home: smaller number (10’s) of
larger clusters in POPs near access nets
• used by Limelight
Application Layer: 2-48
Akamai today:

Source: https://networkingchannel.eu/living-on-the-edge-for-a-quarter-century-an-akamai-retrospective-downloads/

Transport Layer: 3-49


How does Netflix work?
 Netflix: stores copies of content (e.g., MADMEN) at its
(worldwide) OpenConnect CDN nodes
 subscriber requests content, service provider returns manifest
• using manifest, client retrieves content at highest supportable rate
• may choose different rate or copy if network path congested

… …


manifest file

where’s Madmen?

… …
Application Layer: 2-50
Content distribution networks (CDNs)

OTT: “over the top”

… …
Internet host-host communication as a service


OTT challenges: coping with a congested Internet from the “edge”


 what content to place in which CDN node?
 from which CDN node to retrieve content? At which rate?
… …
Application Layer: 2-51
Application Layer: Overview
 P2P applications
 Principles of network  video streaming and content
applications distribution networks
 Web and HTTP  socket programming with
 E-mail, SMTP, IMAP UDP and TCP
 The Domain Name System
DNS

Application Layer: 2-52


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

Application Layer: 2-53


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 and displays line on its screen

Application Layer: 2-54


Socket programming with UDP
UDP: no “connection” between
client and 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 processes
Application Layer: 2-55
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 serverIP address
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
Application Layer: 2-56
Example app: UDP client
Python UDPClient
include Python’s socket library from socket import *
serverName = 'hostname'
serverPort = 12000
create UDP socket clientSocket = socket(AF_INET,
SOCK_DGRAM)
get user keyboard input message = input('Input lowercase sentence:')
attach server name, port to message; send into socket clientSocket.sendto(message.encode(),
(serverName, serverPort))
read reply data (bytes) from socket modifiedMessage, serverAddress =
clientSocket.recvfrom(2048)
print out received string and close socket print(modifiedMessage.decode())
clientSocket.close()

Note: this code update (2023) to Python 3 Application Layer: 2-57


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, getting message, clientAddress = serverSocket.recvfrom(2048)
client’s address (client IP and port)
modifiedMessage = message.decode().upper()
send upper case string back to this client serverSocket.sendto(modifiedMessage.encode(),
clientAddress)

Note: this code update (2023) to Python 3 Application Layer: 2-58


Socket programming with TCP
Client must contact server  when contacted by client, server
 server process must first be TCP creates new socket for server
running process to communicate with that
 server must have created socket particular client
(door) that welcomes client’s • allows server to talk with multiple
contact clients
• client source port # and IP address used
Client contacts server by: to distinguish clients (more in Chap 3)
 Creating TCP socket, specifying IP
address, port number of server Application viewpoint
process TCP provides reliable, in-order
 when client creates socket: client byte-stream transfer (“pipe”)
between client and server
TCP establishes connection to processes
server TCP
Application Layer: 2-59
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
Application Layer: 2-60
Example app: TCP client
Python TCPClient
from socket import *
serverName = 'servername'
serverPort = 12000
create TCP socket for server, clientSocket = socket(AF_INET, SOCK_STREAM)
remote port 12000
clientSocket.connect((serverName,serverPort))
sentence = input('Input lowercase sentence:')
clientSocket.send(sentence.encode())
No need to attach server name, port modifiedSentence = clientSocket.recv(1024)
print ('From Server:', modifiedSentence.decode())
clientSocket.close()

Note: this code update (2023) to Python 3 Application Layer: 2-61


Example app: TCP server
Python TCPServer
from socket import *
serverPort = 12000
create TCP welcoming 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 connectionSocket, addr = serverSocket.accept()
requests, new socket created on return

read bytes from socket (but sentence = connectionSocket.recv(1024).decode()


not address as in UDP) capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence.
encode())
close connection to this client (but not connectionSocket.close()
welcoming socket)
Note: this code update (2023) to Python 3 Application Layer: 2-62
Chapter 2: Summary
our study of network application layer is now complete!
 application architectures  specific protocols:
• client-server • HTTP
• P2P • SMTP, IMAP
 application service requirements: • DNS
• P2P: BitTorrent
• reliability, bandwidth, delay
 video streaming, CDNs
 Internet transport service model  socket programming:
• connection-oriented, reliable: TCP
TCP, UDP sockets
• unreliable, datagrams: UDP

Application Layer: 2-63


Chapter 2: Summary
Most importantly: learned about protocols!
 typical request/reply message important themes:
exchange:  centralized vs. decentralized
• client requests info or service  stateless vs. stateful
• server responds with data, status code  scalability
 message formats:  reliable vs. unreliable
• headers: fields giving info about data message transfer
• data: info(payload) being  “complexity at network
communicated
edge”

Application Layer: 2-64


Additional Chapter 2 slides
JFK note: the timeout slides are important IMHO if one is doing a programming assignment (especially
an RDT programming assignment in Chapter 3), since students will need to use timers in their code,
and the TRY/EXCEPT is really the easiest way to do this. I introduce this here in Chapter 2 with the
socket programming assignment since it teaches something (how to handle exceptions/timeouts), and
lets students learn/practice that before doing the RDT programming assignment, which is harder

Application Layer: 2-65


Socket programming: waiting for multiple events

 sometimes a program must wait for one of several events to happen, e.g.,:
 wait for either (i) a reply from another end of the socket, or (ii) timeout: timer
 wait for replies from several different open sockets: select(), multithreading
 timeouts are used extensively in networking
 using timeouts with Python socket:
receive a message
socket() connect() send() settimeout() recv() …
timeout
handle
timeout


Application Layer: 2-66
How Python socket.settimeout() works?

timer starts! no packet arrives in 30 secs timeout

s.settimeout(30) s.recv() interrupt s.recv() &


raise timeout exception

receive a message no packet arrives in 10 secs


timer starts! & timer stop! timer starts! timeout

s.settimeout(10) s.recv() s.recv() interrupt s.recv() &


raise timeout exception

Set a timeout on all future socket operations of that specific socket!


Application Layer: 2-67
Python try-except block
Execute a block of code, and handle “exceptions” that may occur when
executing that block of code
try:
Executing this try code block may cause exception(s) to catch. If an exception
<do something> is raised, execution jumps from jumps directly into except code block
except <exception>:
this except code block is only executed if an <exception> occurred in the try
<handle the exception> code block (note: except block is required with a try block)
Socket programming: socket timeouts
Toy Example:
- A shepherd boy tends his master’s sheep. Python TCPServer (Villagers)
- If he sees a wolf, he can send a message to
villagers for help using a TCP socket. from socket import *
- The boy found it fun to connect to the server serverPort = 12000
without sending any messages. But the villagers serverSocket = socket(AF_INET,SOCK_STREAM)
don’t think so.
- And they decided that if the boy connects to serverSocket.bind(('',serverPort))
the server and doesn’t send the wolf location serverSocket.listen(1)
within 10 seconds for three times, they will stop counter = 0
listening to him forever and ever.
while counter < 3:
set a 10-seconds timeout on connectionSocket, addr = serverSocket.accept()
all future socket operations connectionSocket.settimeout(10)
try:
timer starts when recv() is called and will wolf_location = connectionSocket.recv(1024).decode()
send_hunter(wolf_location) # a villager function
raise timeout exception if there is no connectionSocket.send('hunter sent')
message within 10 seconds.
except timeout:
catch socket timeout exception counter += 1
connectionSocket.close()

Application Layer: 2-69


Sample SMTP interaction
S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
C: MAIL FROM: <alice@crepes.fr>
S: 250 alice@crepes.fr... Sender ok
C: RCPT TO: <bob@hamburger.edu>
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-70
CDN content access: a closer look
Bob (client) requests video http://netcinema.com/6Y7B23V
 video stored in CDN at http://KingCDN.com/NetC6y&B23V

1. Bob gets URL for video


http://netcinema.com/6Y7B23V
from netcinema.com web page 2. resolve http://netcinema.com/6Y7B23V
2 via Bob’s local DNS
1
6. request video from 5 Bob’s
KINGCDN server, local DNS
streamed via HTTP server
3. netcinema’s DNS returns CNAME for
netcinema.com 4
http://KingCDN.com/NetC6y&B23V

netcinema’s
authoratative DNS KingCDN.com KingCDN
authoritative DNS
Application Layer: 2-71
Case study: Netflix
Amazon cloud upload copies of
multiple versions of
video to CDN servers
CDN
server
Netflix registration,
accounting servers
Bob browses
Netflix video CDN
2 Manifest file, server
requested
1 3 returned for
Bob manages specific video
Netflix account
CDN
4 server

DASH server
selected, contacted,
streaming begins
Application Layer: 2-72

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy