0% found this document useful (0 votes)
68 views121 pages

CN Module 2

The document discusses network application protocols and principles. It outlines topics including principles of network applications, popular protocols like HTTP, FTP, SMTP, DNS, and P2P applications. The goals are to conceptually understand network application protocols, examine specific protocols, and learn how to create network applications using sockets. Client-server and peer-to-peer architectures are introduced. Specifics around sockets, addressing processes, and transport layer services available to applications are also covered.

Uploaded by

Vamshidhar Reddy
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)
68 views121 pages

CN Module 2

The document discusses network application protocols and principles. It outlines topics including principles of network applications, popular protocols like HTTP, FTP, SMTP, DNS, and P2P applications. The goals are to conceptually understand network application protocols, examine specific protocols, and learn how to create network applications using sockets. Client-server and peer-to-peer architectures are introduced. Specifics around sockets, addressing processes, and transport layer services available to applications are also covered.

Uploaded by

Vamshidhar Reddy
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/ 121

Module - 2

Application Layer
Outline
1. Principles of network applications

2. Web and HTTP

3. FTP

4. Electronic mail : SMTP, POP3, IMAP

5. DNS

6. P2P applications

7. Socket programming with UDP and TCP


Goals
 Conceptual, implementation aspects of network application protocols
 Transport-layer service models
 Client-server paradigm
 Peer-to-peer paradigm

 Learn about protocols by examining popular application-level protocols


 Http
 Ftp
 Smtp / pop3 / imap
 Dns

 Creating network applications


 Socket API
Network Application
 Itis an application running on one host and provides a
communication to another application running on different.

 Network application development is writing programs that


run on different end systems and communicate with each
other over network.
 Web application there are two distinct programs that
communicate with each other:
◦ Browser program running in the user’s host (desktop,
laptop, tablet, smartphone, and so on).
◦ Web server program running in the Web server host.
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
Creating a network app application
transport
network
Write programs that: data link
physical
 run on (different) end
systems
 communicate over network

 e.g., web server software

communicates with browser


software
application
no need to write software for transport
network
network-core devices data link
physical
application
transport
network
 network-core devices do data link
physical
not run user applications
 applications on end systems

allows for rapid app


development, propagation
Application architectures
 The network architecture is fixed and provides a specific
set of services to applications

 Network Application Architectures


 Client-Server
 Peer-to-Peer (P2P)
Client-server architecture
Server:
 always-on host
 Permanent/Fixed IP address
 Large cluster of servers-Data Centers
 Ex: web server.

client/server Clients:
 communicate with server
 Not continuously connected
 may have dynamic IP addresses
 do not directly communicate with
each other
 Ex: web, FTP
Client-server architecture
• There is an always-on host, called the server, which
services requests from many other hosts, called clients.

• With the client-server architecture, clients do not


directly communicate with each other.

• The server has a fixed, well-known address, called an


IP address.

• The server is always on, a client can always contact the


server by sending a packet to the server’s IP address.

• Example: Web, FTP, Telnet, and e-mail.


P2P Architecture
 Peers- End systems.
 Server need not be on

 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 alternatively connected and

change IP addresses
 complex management
 Ex: Bit Torrent
P2P Architecture
• There is minimal dedicated servers in data centers.

• The application exploits direct communication between pairs of


alternatively connected hosts, called peers.

• The peers are not owned by the service provider, but are instead
desktops and laptops controlled by users.

• Most of the peers residing in homes, universities, and offices.

• The peers communicate without passing through a dedicated


server, the architecture is called peer-to-peer.
E.g. file sharing, Internet Telephony.
P2P Applications Challenges
1. ISP Friendly. Most residential ISPs (including DSL and
cable ISPs) have been dimensioned for “asymmetrical”
bandwidth usage, that is, for much more downstream than
upstream traffic.

2. Security. Because of their highly distributed and open


nature, P2P applications can be a challenge to secure.

3. Incentives. The success of future P2P applications also


depends on convincing users to volunteer bandwidth, storage,
and computation resources to the applications, which is the
challenge of incentive design
Processes Communicating
 What is process ?
◦ Process is an instance of an program running in a
computer
◦ Program under execution

• Within same host, two processes communicate using


inter-process communication (defined by OS)
 Processes in different hosts communicate by exchanging
messages across CN.
◦ A sending process creates and sends messages into the
network;
◦ A receiving process receives these messages and
possibly responds by sending messages back.

 aside:
applications with
P2P architectures
have client
Client and Server Processes
 A network application consists of pairs of processes that
send messages to each other over a network.

 P2P :
◦ In a P2P file-sharing system, a file is transferred from a
process in one peer to a process in another peer.
◦ For each pair of communicating processes, one of the two
processes as the client and the other process as the server.
◦ With the Web, a browser is a client process and a Web
server is a server process.
 With P2P file sharing, the peer that is downloading the file is
labeled as the client, and the peer that is uploading the file is
labeled as the server.

 In P2P file sharing, a process can be both a client and a server.

A process in a P2P file-sharing system can both upload and


download files.

 In communication session between a pair of processes, the


process that initiates the communication is labeled as the
client.

 The process that waits to be contacted to begin the session


is the server.
The Interface between the Process and the Computer
Network (Socket)
 A processsends messages into, and receives messages from, the network
through a software interface called a socket.

 A process is analogous to a house and its socket is analogous to its door.

 When a process wants to send a message to another process on another


host, it shoves the message out its door (socket).

 Thissending process assumes that there is a transportation infrastructure


on the other side of its door that will transport the message to the door of
the destination process.

 Once the message arrives at the destination host, the message passes
through the receiving process’s door (socket), and the receiving process
then acts on the message.
Sockets
 Process sends/receives messages to/from its socket
 Socket analogous to door

 sending process push 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
 Socket is the interface between the application layer and the transport layer
within a host.

 Itis also referred to as the Application Programming Interface (API)


between the application and the network, since the socket is the
programming interface with which network applications are built.

 The application developer has control of everything on the application-


layer side of the socket but has little control of the transport-layer side of
the socket.

 The only control that the application developer has on the transport-layer
side is
◦ The choice of transport protocol
◦ The ability to fix a few transport-layer parameters such as maximum
buffer and maximum segment sizes.
◦ Once the application developer chooses a transport protocol the
application is built using the transport-layer services provided by that
protocol
Addressing processes
 To receive messages, process must have identifier.

 Host device has unique 32-bit IP address

 Q: Is IP address of host on which process runs sufficient for identifying the


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

 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
Transport Services Available to Applications
 Socket is an interface between application process and
transport layer protocol.

 For development of application , choose available


transport layer protocol.

 Consider the protocol with the services which match your


application
◦ Ex: Choose train or aeroplane to travel between cities
 Classify the services of a protocol with 4 parameters-

1.Reliable data transfer :


◦ Ex: Email, transfer files, financial applications require
100% reliable data transfer.
The data sent by one end of the application is delivered
correctly and completely to the other end of the
application.
◦ Ex: Gmail

If a protocol provides such a guaranteed data delivery


service, it is said to provide reliable data transfer.
◦ Ex: Banking Application

• One important service that a transport-layer protocol can


potentially provide to an application is process-to-process
reliable data transfer.
 When a transport protocol provides this service, the
sending process can just pass its data into the socket and
know with complete confidence that the data will arrive
without errors at the receiving process.

 When reliable delivery of data not possible – loss


tolerant applications (Cricket matches - Online)

 Ex: Real time media, you tube streaming videos


2. Throughput
 Throughput refers to how much data can be transferred
from one location to another in a given amount of time.

 Some apps require least amount of throughput to be


affective (multimedia).

 BW sensitive application – Specific throughput


required(skype).

 Elasticapplications can use of as much as or as little


throughput as happened to be available .
3. Timing
 A transport-layer protocol can also provide timing guarantees.
 Some apps like : internet telephony , interactive games require
low delay to be effective.

4. Security
 A transport protocol can provide an application with one or
more security services.
 For example,
◦ Sending host, a transport protocol can encrypt all data transmitted by
the sending process,
◦ Receiving host, the transport-layer protocol can decrypt the data before
delivering the data to the receiving process.
◦ Service would provide confidentiality, Integrity and Authentication
between the two processes, even if the data is somehow observed
between sending and receiving processes.
Transport service requirements: common
apps
Internet transport protocols services
Services Not Provided by Internet
Transport Protocols
Popular Internet applications, their application-layer
protocols, and their underlying transport protocols
Application-layer protocol
 An application-layer protocol defines how an application’s processes,
running on different end systems, pass messages to each other.

Defines -
◦ The types of messages exchanged, for example, request messages and
response messages.

◦ The syntax of the various message types, such as the fields in the
message and how the fields are delineated.

◦ The semantics of the fields, the meaning of the information in the fields.

◦ Rules for determining when and how a process sends messages and
responds to messages.
Web
 Early 1990, Internet was used only by researchers, academics,
and university students.

 New application WWW arrived in 1994 by Tim Berners-Lee.

 World Wide Web - is an information where documents and other


web resources are identified by URL, interlinked by hypertext
links, and can be accessed via the Internet.

 On demand available, What they want, When they want it.

 Unlike TV and Radio.

 Navigate through Websites.


Web and HTTP
 Web page consists of objects.

 Object can be HTML file, JPEG image, Java applet, audio


file etc.…

 Web page consists of base HTML-file which includes


several referenced objects.

 Eachobject is addressable by a Uniform Resource Locator


(URL), like;
HTTP
 Hyper Text Transfer Protocol – Application layer
protocol.

 It is implemented in two programs.


1. Client Program
2. Server Program

 Exchanging HTTP message each others.

 HTTP defines the structure of these messages and how


web client – web server exchange messages.
 The HTTP client first initiates a TCP connection with the
server.

 Once the connection is established, the browser and the


server processes access TCP through their socket interfaces.

 On the client side the socket interface is the door between


the client process and the TCP connection.

 Onthe server side it is the door between the server process


and the TCP connection.

 The client sends HTTP request messages into its socket


interface and receives HTTP response messages from its
socket interface.(similarly for server)
 Client:A browser that requests, receives, (using HTTP
protocol) and “displays” Web objects.
 E.g. PC, Mobile
 Server: Web server sends (using HTTP protocol) objects
in response to requests.
 E.g. Apache Web Server
 Defines how web clients request web pages from web servers and
how servers transfer web pages to client.

 A client initiates TCP connection (creates socket) to server using


port 80.

 A server accepts TCP connection from client.

 HTTP messages (application-layer protocol messages) exchanged


between browser (HTTP client) and Web server (HTTP server).

 HTTP is “stateless protocol”, server maintains no information


about past client requests.

 HTTP connection types are:


1. Non-persistent HTTP
2. Persistent HTTP
Non-persistent & Persistent Connection
 In Client-Server communication, Client making
a series of requests to server, Server responding
to each of the requests.

 Series of requests may be made back to back or


periodically at regular time interval.

 So, Application developer need to make an


important decision;
 Should each request/response pair be sent over a
separate TCP connection.
 OR should all of the requests and corresponding
responses be sent over same TCP connection?
41
Non-persistent HTTP
A non-persistent connection is closed after the server sends
the requested object to the client.

 The connection is used exactly for one request and one


response.

 For downloading multiple objects it required multiple


connections.

 Example:
 Transferring a webpage from server to client, webpage
consists of a base HTML file and 10 JPEG images.
 Total 11 object are reside on server.
Non-persistent HTTP: Response time
 RTT(round-trip time):
A time for a small initiate TCP
packet to travel from connection
client to server and RTT
vice versa. request
file
time to
RTT transmit
 HTTP response time: file
◦ one RTT to initiate TCP file
connection. received
◦ one RTT for HTTP
request and first few time time
bytes of HTTP response
to return.
◦ File transmission time

Non-persistent HTTP response time = 2RTT + file


transmission time
Shortcomings of non-persistent http
 Each of new connections established , TCP buffers
allocated , TCP variables must kept both in client and
server.

 Burden on web server , which may be increase in case of


serving 100’s of different clients requests
simultaneously.

 Each objects suffers a delivery delay of 2 RTTs.


Persistent HTTP
 Server leaves the TCP connection open after sending responses.

 Subsequent HTTP messages between same client and server sent


over open connection.

 The server closes the connection only when it is not used for a
certain configurable amount of time.

 It requires as little as one round-trip time (RTT) for all the


referenced objects.

 With persistent connections, the performance is improved by 20%.

 Persistent connections are the default mode for HTTP/1.1.


• An entire Web page can be sent over a single persistent TCP
connection.

• These requests for objects can be made back-to-back,


without waiting for replies to pending requests (pipelining).

• The HTTP server closes a connection when it isn’t used for a


certain time.

• When the server receives the back-to-back requests, it sends


the objects back-to-back.

• The default mode of HTTP uses persistent connections with


pipelining.
HTTP Message Format

Two types:
1. Request Message
2. Response Message
1. HTTP Request Message
 It is in ASCII format which means that human-readable
format.

 HTTP request message consist three part:


1. Request line
2. Header line
3. Carriage return
 Each message followed by a carriage return and a line feed.

 The last line is followed by an additional carriage return and


line feed.

 The first line of an HTTP request message is called the


request line.

 The subsequent lines are called the header lines.

 The request line has three fields: the method field, the URL
field, and the HTTP version field.
 The method field can take on several different values, including GET,
POST, HEAD, PUT, and DELETE.

 The great majority of HTTP request messages use the GET method.

 The GET method is used when the browser requests an object, with the
requested object identified in the URL field.

• If the value of the method field is POST, then the entity body
contains what the user entered into the form fields.

• HTML forms often use the GET method and include the inputted
data in the requested URL.

• The HEAD method is similar to the GET method. When a server


receives a request with the HEAD method, it responds with an
HTTP message but it leaves out the requested object.
• The PUT method is often used in conjunction with Web
publishing tools. It allows a user to upload an object to a
specific path (directory) on a specific Web server. The
PUT method is also used by applications that need to
upload objects to Web servers.

• The DELETE method allows a user, or an application, to


delete an object on a Web server.

• The header line Host: www-net.cs.umass.edu specifies the


host on which the object resides.

• User agent indicate browser name and version.


HTTP Request message: General format
• The header line Host: www.someschool.edu specifies the
host on which the object resides.

• Connection: close header line, the browser is telling the


server that it doesn’t want to bother with persistent
connections; it wants the server to close the connection
after sending the requested object.

• The User-agent: header line specifies the user agent, that


is, the browser type that is making the request to the server.
 Here the user agent is Mozilla/5.0, a Firefox browser.

• This header line is useful because the server can actually


send different versions of the same object to different
types of user agents.

• The Accept language: Header indicates that the user


prefers to receive a French version of its default version.
The Accept-language: header is just one of many
content negotiation headers available in HTTP.

• The entity body is empty with the GET method, but is


used with the POST method.
HTTP Response message

header
lines
 Ithas three sections: an initial status line, six header lines,
and then the entity body.

 The entity body is the meat of the message—it contains the


requested object itself (represented by data data data data
data ...).

 The status line has three fields: the protocol version field, a
status code, and a corresponding status message.

 In the example, the status line indicates that the server is


using HTTP/1.1 and that everything is OK
General format of an HTTP response
message
 The server uses the Connection: close header line to tell the
client that it is going to close the TCP connection after
sending the message.

 The
Date: header line indicates the time and date when the
HTTP response was created and sent by the server.

 The Server: header line indicates that the message was


generated by an Apache Web server; it is analogous to the
User-agent: header line in the HTTP request message.

 TheLast-Modified: header line indicates the time and date


when the object was created or last modified.
 The Last-Modified: critical for object caching, both in the
local client and in network cache servers.

 The Content-Length: header line indicates the number of


bytes in the object being sent.

 The Content-Type: header line indicates that the object in


the entity body is HTML text.
 In below example, the status line indicates that the server
is using HTTP/1.1 and that everything is OK.
HTTP Response Status Codes
 A 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(Location)
◦ 400 Bad Request
 Request message not understood by server
◦ 404 Not Found
 Requested document not found on this server
◦ 505 HTTP Version Not Supported
 Requested http version not support
User-Server interactions: Cookie
 Httpis stateless. Web servers that can handle thousands of
simultaneous TCP connections each and every day.

A Web site to identify users, either because the server


wishes to restrict user access or because it wants to serve
content as a function of the user identity.

 A small text file that is stored in the user's computer either


temporarily for that session only or permanently on the
hard disk.
 Cookiesprovide a way for the Web site to recognize you
and keep track of your preferences.
◦ https://www.youtube.com/watch?v=I01XMRo2ESg
 The cookie technology has four components:
1. A cookie header line in the HTTP response message
2. A cookie header line in the HTTP request message
3. A cookie file kept on the user’s end system and
managed by the user’s browser
4. A back-end database at the Web site- it stores cookie
ID
Example:
 Susan always access Internet from PC

 Visits specific e-commerce site for first time

 When initial HTTP requests arrives at site, site creates:


 Unique ID
 Entry in backend database for ID
Web caches (proxy server)
 Goal: Satisfy client request without involving origin
server

 Itsatisfies HTTP requests on the behalf of an origin Web


server.

 The Web cache has its own disk storage and keeps copies
of recently requested objects in this storage.
 A user’s browser can be configured so, user’s HTTP requests are first
directed to the Web Cache.

 A browser sends all HTTP requests to cache.

 As an example, suppose a browser is requesting the object http://


www.someschool.edu/campus.gif.

 Object in cache returns to client browser.

 Otherwise cache requests object from origin server, then returns object
to client browser.

Cache acts as both client and server


 server for original requesting client
 client to origin server

 Typically cache is installed by ISP (university, company, residential ISP)


Why Web caching ?
 Reduce response time for client request.

 Reduce traffic on an institution’s access link.

 Use of Content Distribution Networks (CDNs), Web caches


are increasingly playing an important role in the Internet.

A CDN company installs many geographically distributed


caches throughout the Internet, thereby localizing much of the
traffic.

A content delivery network, or content distribution network,


is a geographically distributed network of proxy servers and
their data centers. 
Example: Institutional Network and Internet
Conditional GET
 Theobject housed in the Web server may have been
modified since the copy was cached at the client.

 HTTP has a mechanism that allows a cache to verify


that its objects are up to date. This mechanism is
called the conditional GET.

 An
HTTP request message is a so-called conditional
GET message if
◦ the request message uses the GET method and
◦ the request message includes an If-Modified- Since: header
line.
 First,on the behalf of a requesting browser, a proxy cache
sends a request message to a Web server:
GET /fruit/kiwi.gif HTTP/1.1
Host: www.exotiquecuisine.com

 Second, the Web server sends a response message with the


requested object to the cache:
HTTP/1.1 200 OK
Date: Sat, 8 Oct 2011 15:39:29
Server: Apache/1.3.0 (Unix)
Last-Modified: Wed, 7 Sep 2011 09:23:24
Content-Type: image/gif
(data data data data data ...)
 The cache forwards the object to the requesting browser but also
caches the object locally.

 Importantly, the cache also stores the last-modified date along with the
object.

 Third, one week later, another browser requests the same object via
the cache, and the object is still in the cache.

 Sincethis object may have been modified at the Web server in the past
week, the cache performs an up-to-date check by issuing a conditional
GET.

 Specifically, the cache sends:

GET /fruit/kiwi.gif HTTP/1.1


Host: www.exotiquecuisine.com
If-modified-since: Wed, 7 Sep 2011 09:23:24
FTP
 Transferring file between 2 hosts

 User sitting in front of host ,wants to transfer file from


local host machine and remote machine.

 In order for the user to access the remote account, the user
must provide a user identification and a password.

 After providing this authorization information, the user


can transfer files from the local file system to the remote
file system and vice versa.
 File Transfer Protocol (FTP) is the commonly used
protocol for exchanging files over the Network or Internet.
Example: Filezilla

 FTP uses the Internet's TCP/IP protocols to enable data


transfer and uses client-server architecture.

 FTP promotes sharing of files via remote computers with


reliable and efficient data transfer.
 FTP client connect FTP server at port 21 using TCP.

 FTP uses two parallel TCP connections to transfer a file,


1. Control Connection: Used for sending control information
between two hosts.
2. Data Connection: To send a file.
 Control Information like user identification, password,
commands to change remote directory, commands to “put”
and “get” files.

 Clientwill browses remote file directory, sends commands


over control connection.

 FTP server maintains “state” about user like current


directory, earlier authentication.

 Difference between FTP and HTTP- 2 connections in ftp


and only one connection in http. But both are meant for
data exchange
FTP Commands and Replies

 USER username: Used to send the user identification to


the server.

 PASS password: Used to send the user password to the


server.

 LIST: Used to ask the server to send back a list of all the
files in the current remote directory. The list of files is sent
over a (new and non-persistent) data connection rather than
the control TCP connection.

 RETR filename: Used to retrieve (that is, get) a file from


the current directory of the remote host. This command
causes the remote host to initiate a data connection and to
send the requested file over the data connection.
 STOR filename: Used to store (that is, put) a file into
the current directory\ of the remote host.

 Statuscode and phrase in the status line of the HTTP


response message

◦ 331 Username OK, password required


◦ 125 Data connection already open; transfer starting
◦ 425 Can’t open data connection
◦ 452 Error writing file
Electronic Mail (Email)
 Email is an asynchronous communication medium in which people send and
read messages as convenient for them.

 Modern Email has many powerful features like:


 A messages with attachments
 Hyperlinks
 HTML-formatted text
 Embedded photos

 Email is fast, easy to distribute, and inexpensive.

 High level view of Internet mail system and its key components.
1. User agents
2. Mail servers
3. Simple Mail Transfer Protocol (SMTP)
Email
user
agent

mail user
server agent
SMTP mail user
server agent
SMTP
SMTP user
agent
mail
server
user
agent
user
agent
Outgoing
message queue
user mailbox
User Agent
User
 agents allow users to read, reply to, forward, save, and
compose messages.
E.g.
 Microsoft Outlook and Apple Mail.

Mail servers:
A mailbox
 contains incoming messages for user.
A message
 queue of outgoing (to be sent) mail messages.

SMTP
It
 is a principal application layer protocol between mail servers to
send email messages.
◦ client: sending mail to server
◦ server: receiving mail from other different mail server
SMTP
 Simple Mail Transfer Protocol used in sending and receiving
e-mail.

 It use TCP to reliably transfer email message from client to


server using port 25.

 It restricts the body (not just the headers) of all mail messages
to simple 7-bit ASCII.

 SMTP does not use intermediate mail servers for sending mail.

 Ifreceiving end mail server is down, the message remains in


sending end mail server and waits for a new attempt.
Scenario: Alice sends message to Bob

1) Alice uses UA to compose 4) SMTP client sends Alice’s


message “to” message over the TCP
[email protected] connection
2) Alice’s UA sends message to 5) Bob’s mail server places
her mail server; message the message in Bob’s
placed in message queue mailbox
3) client side of SMTP opens 6) Bob invokes his user
TCP connection with Bob’s agent to read message
mail server

1user mail user


mail agent
agent server server
2 3 6
4
5
Alice’s mail server
Bob’s mail erver
Mail Access Protocols (POP3 and IMAP)

user
m ail acce s s user
SMTP SMTP protocol
agent agent
(e .g., POP,
IMAP )

sender’s mail receiver’s mail


server server
 POP3
◦ Post Office Protocol – Version 3

 IMAP
◦ Internet Mail Access Protocol

 A mail access protocol, such as POP3, is used to transfer mail from


the recipient’s mail server to the recipient’s user agent.
POP3 – Post Office Version 3
 POP3 is an extremely simple mail access protocol(recipient
mail server to recipient user agent).

 With the TCP connection established, POP3 progresses


through three phases: authorization, transaction and update.

 In authorization, the user agent sends a username and a


password to authenticate the user.

 In transaction, the user agent retrieves messages, mark


messages for deletion, remove deletion marks and obtain
mail statistics.
 In update, after the quit command by client, ending the POP3
session; the mail server deletes marked messages.

 POP3 is designed to delete mail on the server as soon as the user


has downloaded it.

IMAP - Internet Mail Access Protocol


 To keeps all messages in one place: at server

 The recipient can then move and organize the message into
a new, user-created folder, read the message, delete the
message, move messages from one folder to another and so
on.

 To allow users to search remote folders for messages


matching specific criteria.
 Also permit a user agent to obtain components of
messages, When low-bandwidth connection between the
user agent and its mail server.

 In this case, user not to download all of the messages in


its mailbox, particularly avoiding long messages like an
audio or video clip.

 POP and IMAP:


◦ https://www.youtube.com/watch?v=bKECC0DHe9Y

 SMTP
◦ https://www.youtube.com/watch?v=bKECC0DHe9Y
DNS: domain name system
people: many identifiers:
 SSN, name, passport #

Internet hosts, routers:


 IP address (32 bit) - used for addressing datagrams
 “name”, e.g., www.yahoo.com - used by humans

Q: how to map between IP address and name, and vice


 DNS- Distributed database
versa ?
DNS - Domain Name System

Alphabetic name
IP Address
remember by human
To resolve the name issues in the internet –use of protocol DNS

It is an internet service that translates domain names into IP addresses.

Itis application-layer protocol. DNS service must translate the domain


name into the corresponding IP address.

In DNS system, If one DNS server doesn't know how to translate a
particular domain name, it asks another one, and so on, until the correct
IP address is returned.

DNS runs over UDP and uses port no 53.


DNS –Hierarchical database

 DNS client wants to determine the IP address for the hostname


www.amazon.com

 The client first contacts one of the root servers, which returns IP addresses
for TLD servers - top-level domain .com.

 Then contacts TLD servers, which returns the IP address of an


authoritative server for www.amazon.com

 Finally, contacts one of the authoritative servers for www.amazon.com,


which returns the IP address for the hostname www.amazon.com.
DNS: A distributed - hierarchical
database (13 root DNS servers)
T DNS Servers – Total 13
 Top-level domain (TLD) servers:
◦ It is responsible for com, org, net, edu, aero, jobs, museums, and all
top-level country domains, e.g.: uk, fr, ca, jp,in
◦ Network Solutions maintains servers for .com TLD
◦ Education for .edu TLD

 Authoritative DNS servers:


◦ To organization’s own DNS servers, providing authoritative
hostname to IP mappings for organization’s named hosts.
◦ It can be maintained by organization or service provider.

 Local DNS name servers:


◦ It does not strictly belong to hierarchy
◦ when host makes DNS query, query is sent to its local DNS server.
 It acts as proxy, forwards query into hierarchy.
 https://www.youtube.com/watch?v=2ZUxoi7YNgs
 Distributeddatabase design is more preferred over centralized design to
implement DNS in the Internet.

 A single point of failure: If the DNS server crashes then the entire Internet
will not stop.

 Trafficvolume: With millions of device and users accessing its services


from whole globe at the same time.

A Single DNS Server cannot handle huge DNS traffic but with distributed
system its distributed and reduce overload on server.

 Distant centralized database: A single DNS server cannot be “close to” all
the querying clients.

 If it is in New York City, then all queries from Australia must travel to the
other side of the globe, perhaps over slow and congested links cause
significant delays.

 Maintenance: To keep records for all Internet hosts. it would have to be


updated frequently to account for every new host.
DNS name resolution example
root DNS server

 Iterated query:
 A host at cis.poly.edu 2
3
TLD DNS server
wants IP address for 4
gaia.cs.umass.edu
5

local DNS server


dns.poly.edu
7 6
1 8

authoritative DNS server


dns.cs.umass.edu
requesting host
cis.poly.edu

gaia.cs.umass.edu
DNS name resolution example
root DNS server
 Recursive query:
2 3
 A host at cis.poly.edu
7
6
wants IP address for
gaia.cs.umass.edu TLD DNS
server
 Heavy load at upper
level of hierarchy. local DNS server 4
dns.poly.edu 5
1 8

authoritative DNS server


dns.cs.umass.edu
requesting host
cis.poly.edu

gaia.cs.umass.edu
DNS Services
 Host aliasing
◦ A host with a complicated hostname can have one or more alias
names.
◦ Alias hostnames, when present, are typically more mnemonic than
canonical hostnames.

 Mail server aliasing :


◦ DNS can be invoked by a mail application to obtain the canonical
hostname for a supplied alias hostname as well as the IP address of
the host.

 Load distribution:
◦ DNS is also used to perform load distribution among replicated
servers, such as replicated Web servers.
◦ The DNS database contains the set of IP addresses.
DNS: Caching, Updating Rcords
 once (any) name server learns mapping, it caches mapping
 cache entries timeout (disappear) after some time (TTL)
 TLD servers typically cached in local name servers
 thus root name servers not often visited

 cached entries may be out-of-date (best effort name-to-


address translation!)
 if name host changes IP address, may not be known
Internet-wide until all TTLs expire

 update/notify mechanisms proposed IETF standard


 RFC 2136
DNS records
DNS: distributed db storing resource records (RR)
RR format: (name, value, type, ttl)
type=A
 name is hostname
 value is IP address
type=NS
 name is domain (e.g., foo.com)
 value is hostname of authoritative name server for this domain

type=CNAME
 name is alias name for some “canonical” (the real) name
 www.ibm.com is really servereast.backup2.ibm.com
 value is canonical name

type=MX : value is name of mailserver associated with name


DNS protocol, messages
 query and reply messages, both with same message
format 2 bytes 2 bytes

msg header identification flags

 identification: 16 bit # for # questions # answer RRs


query, reply to query uses # authority RRs # additional RRs
same #
questions (variable # of questions)
 flags:
 query or reply answers (variable # of RRs)
 recursion desired
 recursion available authority (variable # of RRs)

 reply is authoritative
additional info (variable # of RRs)
DNS protocol, messages

2 bytes 2 bytes

identification flags

# questions # answer RRs

# authority RRs # additional RRs

name, type fields questions (variable # of questions)


for a query
RRs in response answers (variable # of RRs)
to query
records for authority (variable # of RRs)
authoritative servers
additional “helpful” additional info (variable # of RRs)
info that may be used
DNS protocol, messages
 The question section contains information about the query that is
being made.

 Includes
(1) a name field that contains the name that is being queried, and
(2) a type field that indicates the type of question being asked about the name.

 In a reply from a DNS server, the answer section contains the


resource records for the name that was originally queried.

 In each resource record there is the Type, the Value, and the TTL.

 The authority section contains records of other authoritative servers.

 The additional section contains a Type A record providing the IP


address for the canonical hostname of the mail server.
Inserting records into DNS
 Example: new startup “Network Utopia”

 Register name networkuptopia.com at DNS registrar (e.g.,


Network Solutions)
◦ provide names, IP addresses of authoritative name server
(primary and secondary)
◦ registrar inserts two RRs into .com TLD server:
(networkutopia.com, dns1.networkutopia.com, NS)
(dns1.networkutopia.com, 212.212.212.1, A)

 Create authoritative server type A record for


www.networkuptopia.com; type MX record for
networkutopia.com
Attacking DNS
 DDoS attacks
 Bombard root servers with traffic

 Not successful to date


 Traffic Filtering
 Local DNS servers cache IPs of TLD servers, allowing root server bypass
 Bombard TLD servers

 Potentially more dangerous

 Redirect attacks
 Man-in-middle
 Intercept queries
 DNS poisoning
 Send bogus relies to DNS server, which caches

 Exploit DNS for DDoS


 Send queries with spoofed source address: target IP
 Requires amplification
Socket programming
 When two programs are executed, a client process and a
server process are created, and these processes
communicate with each other by reading from, and writing
to, sockets.

 When creating a network application, the developer’s main


task is to write the code for both the client and server
programs.

 If one developer writes code for the client program and


another developer writes code for the server program, and
both developers carefully follow the rules of the RFC, then
the two programs will be able to interoperate.
 The other type of network application is a proprietary
network application.

 In this case the client and server programs employ an


application-layer protocol that has not been openly
published in an RFC or elsewhere.

A single developer creates both the client and server


programs, and the developer has complete control over
what goes in the code.

 But because the code does not implement an open protocol,


other independent developers will not be able to develop
code that interoperates with the application.
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


by OS
link Internet link

physical physical
 Socket is interface between application and network.
◦ An application creates a socket.
◦ Two type of socket:
1. TCP Socket – Reliable Transmission
2. UDP Socket – Unreliable Transmission

 Once configured the application can pass data to the socket


for transmission and receive data from the socket
(transmitted through the network by some other host).

application application
socket controlled by
process process app developer

transport transport
network network controlled
Internet link by OS
link
physical physical
Type of Socket
 SOCK_STREAM  SOCK_DGRAM

◦ E.g. TCP ◦ E.g. UDP


◦ Reliable delivery ◦ Unreliable delivery
◦ In-order guaranteed ◦ No order guarantees
◦ Connection-oriented ◦ Connection-less
◦ Bidirectional ◦ Unidirectional

App D1
App
3 2 3 2
1 D2
socket Dest. 1 socket
D3
 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 the data to the server.

2. The server receives the data and converts characters to


uppercase.

3. The server sends the modified data to the client.

4. The client receives the modified data and displays the


line on its screen.
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
 rcvr 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
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
Example app: UDP client
Python UDPClient
include Python’s socket
library from socket import *
serverName = ‘hostname’
serverPort = 12000
create UDP socket for clientSocket = socket(socket.AF_INET,
server

get user keyboard


socket.SOCK_DGRAM)
input message = raw_input(’Input lowercase sentence:’)
Attach server name, port to
message; send into socket clientSocket.sendto(message,(serverName, serverPort))
read reply characters from modifiedMessage, serverAddress =
socket into string
clientSocket.recvfrom(2048)
print out received string print modifiedMessage
and close socket
clientSocket.close()
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 1:
Read from UDP socket into message, clientAddress = serverSocket.recvfrom(2048)
message, getting client’s
address (client IP and port) modifiedMessage = message.upper()
send upper case string serverSocket.sendto(modifiedMessage, clientAddress)
back to this client
Socket programming with TCP
client must contact server  when contacted by client, server
 server process must first TCP creates new socket for
be running server process to communicate
 server must have created with that particular client
socket (door) that  allows server to talk with
welcomes client’s contact multiple clients
client contacts server by:  source port numbers used to
distinguish clients
 Creating TCP socket,

specifying IP address, port


number of server process Application viewpoint:
 when client creates
TCP provides reliable, in-order
socket: client TCP byte-stream transfer (“pipe”)
establishes connection to between client and server
server TCP
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
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)
name, port
modifiedSentence = clientSocket.recv(1024)
print ‘From Server:’, modifiedSentence
clientSocket.close()
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 1:
server waits on accept() connectionSocket, addr = serverSocket.accept()
for incoming requests, new
socket created on return
sentence = connectionSocket.recv(1024)
read bytes from socket (but
not address as in UDP) capitalizedSentence = sentence.upper()
close connection to this
connectionSocket.send(capitalizedSentence)
client (but not welcoming connectionSocket.close()
socket)
Thank You

You might also like