Subject Name: Computer Networks
Module 2 : Application Layer
Module 3 : Transport Layer
Faculty Name : Dr. Savita R. Bhosale
Index
Lecture 10- HTTP 03
Lecture 11- DNS 39
Lecture 12- Transport Layer Services & Principles 69
Module 2: Application Layer
Lecture No: 9
HTTP
Hyper Text Transfer Protocol (HTTP)
• HTTP is the protocol that supports communication between web browsers and
web servers.
• A “Web Server” is a HTTP server
• Most clients/servers today speak version 1.1, but 1.0 is also in use.
• RFC 1945 (HTTP 1.0)
• RFC 2616 (HTTP 1.1)
Lecture 10: HTTP
Hyper Text Transfer Protocol (HTTP)
“HTTP is an application-level protocol with the lightness and speed necessary
for distributed, hypermedia information systems.”
Transport Independence
The HTTP protocol generally takes place over a TCP connection,
but the protocol itself is not dependent on a specific transport layer.
Lecture 10: HTTP
Request - Response
• HTTP has a simple structure:
• client sends a request
• server returns a reply.
• HTTP can support multiple request-reply exchanges over a single TCP connection.
• The “well known” TCP port for HTTP servers is port 80.
• Other ports can be used as well...
Lecture 10: HTTP
HTTP 1.0+ Request
• Lines of text (ASCII). Request-Line
• Lines end with CRLF “\r\n” Headers
.
.
.
• First line is called “Request-Line”
blank line
Content...
CRFL: Carriage Return Line Feed, this sequence is always used to terminate a line.
The HTTP protocol uses the CRLF character sequence to signify where one header ends
and another begins. It also used to signify where header end and the website content
begins
Lecture 10: HTTP
Request Line
Method URI HTTP-Version\r\n
• The request line contains 3 tokens (words).
• space characters “ “ separate the tokens.
• Newline (\n) seems to work by itself but the protocol requires CRLF
The target of an HTTP request is called a ‘resource’. Whose nature isn’t
defined further; it can be a document, a photo or anything else. Each resource
is identified by Uniform Resource Identifier (URI) used throughout HTTP for
identifying resources.
Lecture 10: HTTP
Request Method
The Request Method can be:
GET HEAD DELETE
PUT POST TRACE
OPTIONS
future expansion is supported
GET, HEAD and POST are supported everywhere.
HTTP 1.1 servers often support PUT, DELETE, OPTIONS & TRACE.
Lecture 10: HTTP
Methods
• GET: Retrieve information identified by the URI. Typically used to retrieve an
HTML document
• HEAD: Retrieve meta-information about the URI. Used to find out if a document
has changed
• POST: Send information to a URI and retrieve result. Used to submit a form
Lecture 10: HTTP
Methods
• PUT: Store information in location named by URI.
• DELETE: Remove entity identified by URI.
• TRACE: Used to trace HTTP forwarding through proxies, tunnels, etc.
• OPTIONS: Used to determine the capabilities of the server or characteristics of a
named resource.
Lecture 10: HTTP
URI: Universal Resource Identifier
• URIs defined in RFC 2396.
• Absolute URI:
scheme://hostname[:port]/path
http://www.cse.unr.edu:80/~mgunes/cpe401
• Relative URI:
/path
/blah/foo
No server mentioned
Lecture 10: HTTP
URI Usage
• When dealing with a HTTP 1.1 server, only a path is used (no scheme or
hostname).
HTTP 1.1 servers are required to be capable of handling an absolute URI, but
there are still some out there that won’t…
• When dealing with a proxy HTTP server, an absolute URI is used.
client has to tell the proxy where to get the document!
more on proxy servers in a bit….
Lecture 10: HTTP
HTTP Version Number
“HTTP/1.0” or “HTTP/1.1”
• Starting with HTTP 1.0 the version number is part of every request.
Client tells the server what version it can talk (what options are supported, etc).
• HTTP 0.9 did not include a version number in a request line.
If a server gets a request line with no HTTP version number, it assumes 0.9
HTTP 0.9 was used for many years.
Lecture 10: HTTP
The Header Lines
• Request Headers provide information to the server about the client
what kind of client
what kind of content will be accepted
who is making the request
• Each header line contains
an attribute name followed by a “:” followed by a space and the attribute value.
• There can be 0 headers (HTTP 1.0)
HTTP 1.1 requires a Host: header
Lecture 10: HTTP
Example HTTP Headers
Accept: text/html
Host: www.cse.unr.edu
From: [email protected]
User-Agent: Mozilla/4.0
Referer: http://www.unr.edu/
Lecture 10: HTTP
End of the Headers
• Each header ends with a CRLF ( \r\n )
• The end of the header section is marked with a blank line.
just CRLF
• For GET and HEAD requests, the end of the headers is the end of the request!
Lecture 10: HTTP
POST
• A POST request includes some content (some data) after the headers (after the
blank line).
• There is no format for the data (just raw bytes).
• A POST request must include a Content-Length line in the headers:
Content-length: 267
Lecture 10: HTTP
Example POST Request
POST /~mgunes/cpe401/grades.cgi HTTP/1.1
Accept: */*
Host: www.cse.unr.edu
User-Agent: SecretAgent V2.3
Content-Length: 35
Referer: http://www.unr.edu/
stuid=6660182722&item=test1&grade=99
Lecture 10: HTTP
Example GET Request
GET /~mgunes/cpe401/lab1.htm HTTP/1.1
Accept: */*
Host: www.cse.unr.edu
User-Agent: Internet Explorer
From:
[email protected]Referer: http://www.unr.edu/
Lecture 10: HTTP
HTTP Response
• ASCII Status Line
Status-Line
• Headers Section
Headers
.
• Content can be anything (not just text)
.
.
typically an HTML document or some blank line
kind of image.
Content...
Lecture 10: HTTP
Response Status Line
HTTP-Version Status-Code Message
• Status Code is 3 digit number (for computers)
1xx Informational
2xx Success
3xx Redirection
4xx Client Error
5xx Server Error
• Message is text (for humans)
Lecture 10: HTTP
Example Status Lines
HTTP/1.0 200 OK
HTTP/1.0 301 Moved Permanently
HTTP/1.0 400 Bad Request
HTTP/1.0 500 Internal Server Error
Lecture 10: HTTP
Response Headers
• Provide the client with information about the returned entity (document).
what kind of document
how big the document is
how the document is encoded
when the document was last modified
• Response headers end with blank line
Lecture 10: HTTP
Response Header Examples
Date: Wed, 30 Jan 2002 12:48:17 EST
Server: Apache/1.17
Content-Type: text/html
Content-Length: 1756
Content-Encoding: gzip
Lecture 10: HTTP
Content
• Content can be anything (sequence of raw bytes).
• Content-Length header is required for any response that includes content.
• Content-Type header also required.
Lecture 10: HTTP
Single Request/Reply
• The client sends a complete request.
• The server sends back the entire reply.
• The server closes it’s socket.
• If the client needs another document it must open a new connection.
This was the default for HTTP 1.0
Lecture 10: HTTP
Persistent Connections
• HTTP 1.1 supports persistent connections (this is the default).
• Multiple requests can be handled over a single TCP connection.
• The Connection: header is used to exchange information about persistence
(HTTP/1.1)
• 1.0 Clients used a Keep-alive: header
Lecture 10: HTTP
HTTP Proxy Server
HTTP
Browser Proxy
Server
Lecture 10: HTTP
Network Lab # HTTP Proxy
• You need to write a proxy server.
• Must be able to handle GET, HEAD and POST requests.
• Filtering: Your proxy will be given a list of domain names on the command line,
you should refuse to forward requests to any server whose name is within a
specified domain.
send back status line: 403 Forbidden.
Lecture 10: HTTP
The code you need
• Proxy is both a client and a server
• Parsing the HTTP request is needed.
You need to understand HTTP
• You will need to parse headers.
need to look at Content-length, Connection, etc.
Lecture 10: HTTP
Testing
• Tell your browser to use a proxy
Edit preferences/options.
• Interrupt a long transfer (press stop).
• Fill out a form (probably uses POST).
Test it with a browser.
Test it with telnet
Write an abusive client and a rude server!
Lecture 10: HTTP
What is expected
• We should be able to surf through your proxy!
• Proxy should print some info about each request (print the request line).
• No memory leaks!
• Check every system call for errors!
• No crashes, no matter what kind of nonsense we send your proxy.
• We should not be able to kill your proxy by-
sending a bad request.
using a server that sends bad replies.
Lecture 10: HTTP
HTTP V1.1 Details
• The RFC is 114 pages!
• we don’t expect you to read it all or to support every nitty-gritty detail.
• work on creating a working proxy (one you can use through a browser).
• performance is not a big deal (but it shouldn’t be horribly worse than without
your proxy).
• Don’t worry about persistence, pipelining, chunking, etc, you need to turn off
persistence if you don't want to handle it.
Lecture 10: HTTP
HTTP Headers
• You will need to look at the Content-Length header in a POST.
• You need to know how many bytes to read after the end of the headers.
• You will need to either look at Connection (Proxy-Connection) headers or
(at a minimum) to force Connection: close as a request header.
Lecture 10: HTTP
Thank You
Unit No: 2 Application Layer
Lecture No: 10
DNS
DNS (Domain Name System) OBJECTIVES
To describe the purpose of DNS.
To define the concept of domains and domain name space.
To describe the distribution of name spaces and define zones.
To discuss the use of DNS in the Internet and describe three categories of
domains: generic, country, and reverse.
To discuss name-address resolution and show the two resolution methods:
recursive and iterative.
To show the format of DNS message and how they can be compressed.
To discuss DDNS and DNSSEC..
Lecture 11: DNS
NEED FOR DNS
• To identify an entity, TCP/IP protocols use the IP address, which uniquely
identifies the connection of a host to the Internet.
• However, people prefer to use names instead of numeric addresses.
• Therefore, we need a system that can map a name to an address or an address to
a name.
Lecture 11: DNS
Purpose of DNS
User
1
Host
name
Host
name
2
5
IP address
6 3 Query
IP address
Response 4
Transport layer
Lecture 11: DNS
Example of using the DNS service
Lecture 11: DNS
NAME SPACE
• To be unambiguous, the names assigned to machines must be carefully selected
from a name space with complete control over the binding between the names
and IP addresses.
• In other words, the names must be unique because the addresses are unique.
• A name space that maps each address to a unique name can be organized in two
ways:
Flat Name Space
Hierarchical Name Space
Lecture 11: DNS
Domain name space
• To have a hierarchical name space, a domain name space was designed.
• In this design the names are defined in an inverted-tree structure with the root at
the top.
• The tree can have only 128 levels: level 0 (root) to level 127.
Lecture 11: DNS
Domain name space
arpa: address and routing parameter area
ad: active directory
Lecture 11: DNS
Domain names and labels
Lecture 11: DNS
Domains
Lecture 11: DNS
Hierarchy of name servers
Lecture 11: DNS
Hierarchy of name servers
Lecture 11: DNS
Zones and domains
Lecture 11: DNS
Servers
A primary server loads all information from
the disk file; the secondary server loads all
information from the primary server.
When the secondary server downloads
information from the primary, it is
called zone transfer.
Lecture 11: DNS
DNS in Internet
DNS is a protocol that can be used in different platforms.
In the Internet, the domain name space (tree) is divided into three different sections:
generic domains,
country domains, and
the inverse domain.
Lecture 11: DNS
DNS in Internet
Lecture 11: DNS
Generic Domain
Lecture 11: DNS
Generic Domain Labels
Lecture 11: DNS
Country Domains
Lecture 11: DNS
Inverse Domains
Lecture 11: DNS
Resolution
Mapping a name to an address or an address to a name is called name-address
resolution.
Resolver
Mapping Names to Addresses
Mapping Addresses to Names
Recursive Resolution
Iterative Resolution
Caching
Lecture 11: DNS
Recursive Resolution
3
4
8 7
2 5
9
6
10
Lecture 11: DNS
Iterrative Resolution
5
6
3
4
1
2
7
8
9
10
Lecture 11: DNS
DNS MESSAGES
• DNS has two types of messages: query and response.
• Both types have the same format.
• The query message consists of a header and question records
• The response message consists of a header, question records, answer records,
authoritative records, and additional records.
Lecture 11: DNS
Query and response messages
Lecture 11: DNS
Header Format
Lecture 11: DNS
ENCAPSULATION
• DNS can use either UDP or TCP.
• In both cases the well-known port used by the server is port 53.
• UDP is used when the size of the response message is less than 512 bytes because
most UDP packages have a 512-byte packet size limit.
• If the size of the response message is more than 512 bytes, a TCP connection is
used.
Lecture 11: DNS
REGISTRARS
• How are new domains added to DNS?
• This is done through a registrar, a commercial entity accredited by ICANN
(Internet Corporation for Assigned Names and Numbers).
• A registrar first verifies that the requested domain name is unique and then enters
it into the DNS database.
• A fee is charged.
Lecture 11: DNS
DDNS
• When the DNS was designed, no one predicted that there would be so many
address changes.
• In DNS, when there is a change, such as adding a new host, removing a host, or
changing an IP address, the change must be made to the DNS master file.
• The DNS master file must be updated dynamically.
• The Dynamic Domain Name System (DDNS) therefore was devised to respond to
this need.
Lecture 11: DNS
SECURITY OF DNS
• DNS is one of the most important systems in the Internet infrastructure; it
provides crucial services to the Internet users.
• Applications such as Web access or e-mail are heavily dependent on the proper
operation of DNS.
• DNS can be attacked in several Ways.
• To protect DNS, IETF has devised a technology named DNS Security (DNSSEC) that
provides the message origin authentication and message integrity using a security
service called digital signature.
Lecture 11: DNS
Thank You
Module 2: Application Layer
Lecture No: 12
Transport Layer Services
and Principles
TCP/IP Protocols
Lecture 12: Transport Layer Services and Principles
Services Provided to the Upper Layers
Lecture 12: Transport Layer Services and Principles
The Transport Services & Principles
• Residing between the application and network layers, the transport
layer is a central piece of the layered network architecture.
• It has the critical role of providing communication services directly to
the application processes running on different hosts.
• Transport layer protocols are TCP (Transmission Control Protocol)
and UDP (User Datagram Protocol).
Lecture 12: Transport Layer Services and Principles
TCP/IP Functions
• To create a process-to-process communication (using port numbers)
• To create a flow control mechanism at the transport level (using sliding
window)
• To create a error control mechanism at the transport level (using Ack packet,
time-out, retransmission)
• Sequence control mechanism
• A connection oriented, reliable transport protocol
Lecture 12: Transport Layer Services and Principles
TCP Services
• Services offered by TCP to the processes at the application layer
• TCP services include:
– Process-to-Process Communication
– Stream Delivery Service
– Full-Duplex Communication
– Connection-Oriented Service
– Reliable Service
Lecture 12: Transport Layer Services and Principles
Process-to-Process Communication
For client/server communication we must define the
Local host
Local client program
Remote host
Remote server program
Lecture 12: Transport Layer Services and Principles
Process-to-Process Communication
Lecture 12: Transport Layer Services and Principles
Well-known port in TCP
Port Protocol Description
7 Echo Echoes a received datagram back to the sender
9 Discard Discards any datagram that is received
11 Users Active users
13 Daytime Returns the date and the time
17 Quote Returns a quote of the day
19 Chargen Returns a string of characters
20 FTP,data File transfer Protocol for data
21 FTP,control File transfer Protocol for control
23 TELNET Terminal Network
25 SMTP Simple Mail Transfer Protocol
53 DNS Domain Name Server
67 BOOTP Bootstrap protocol
79 Finger finger
80 HTTP Hypertext Transfer Protocol
111 RPC Remote Procedure Call
Lecture 12: Transport Layer Services and Principles
Finding port number in Linux
• In UNIX, the well-known ports are stored in a file called /etc/services
• Each line in this file gives the name of the server and the well-known port
number.
• We can use the grep utility to extract the line corresponding to the desired
application.
• The following shows the ports for FTP.
$ grep ftp /etc/services
ftp-data 20/tcp
ftp-control 21/tcp
Lecture 12: Transport Layer Services and Principles
Socket Address
• A socket is the interface between the application process and the transport-layer protocol.
The application at the sending side pushes messages through the socket.
• At the other side of the socket, the transport-layer protocol has the responsibility of getting
the messages to the socket of the receiving process.
• Socket addresses:
~ a combination of IP address and port number
~ to make a connection for each end
~ to need a pair of socket addresses: client and server socket address
Lecture 12: Transport Layer Services and Principles
Socket Address
Lecture 12: Transport Layer Services and Principles
TCP SERVICES
• Stream delivery service
- Sending and receiving buffers
- Segments
• Full-Duplex service
piggybacking
• Connection-Oriented service
A virtual connection (not physical connection)
• Reliable service
Reply acknowledge packet
Lecture 12: Transport Layer Services and Principles
Stream delivery
• Sending TCP
~ receives data as a stream of bytes from application process using sending
buffer
~ make data to appropriate segments and transfer to network
• Receiving TCP
~ receives segments using receiving buffer
~ reassemble segments to data and send data as a stream of bytes to
application process
Lecture 12: Transport Layer Services and Principles
Sending and Receiving Buffers
• The sending process and the receiving process may not produce and consume
data at the same speed, TCP needs buffers for storage
Lecture 12: Transport Layer Services and Principles
TCP Segments
• IP layer, as a service provider for TCP, needs to send data in packets, not as a
stream of bytes.
• TCP groups a number of bytes together into a packet called segment
Lecture 12: Transport Layer Services and Principles
The Transport Protocol: TCP and UDP
Type of transport services provided by the Internet-
• The Internet makes two transport protocols available to applications,
UDP and TCP.
• When you create a new network application for the Internet, one of the
first decisions you have to make is whether to use UDP or TCP.
• Each of these protocols offers a different set of services to the invoking
applications.
Lecture 12: Transport Layer Services and Principles
The Transport Protocol: TCP and UDP
TCP service: UDP service:
reliable transport between unreliable data transfer between
sending and receiving process sending and receiving process
flow control: sender won’t does not provide: reliability, flow
overwhelm receiver control, congestion control, timing,
congestion control: throttle throughput guarantee, security, or
sender when network overloaded connection setup.
connection-oriented: setup
required between client and
server processes
• does not provide: timing,
minimum throughput guarantee,
security
Lecture 12: Transport Layer Services and Principles
The Transport Protocol: TCP and UDP
Lecture 12: Transport Layer Services and Principles
The Transport Principles
Reliable data transfer 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
security
timing
some apps (e.g., Internet encryption, data integrity,
telephony, interactive
games) require low delay to
be “effective”
Lecture 12: Transport Layer Services and Principles
The Transport Principles
Lecture 12: Transport Layer Services and Principles
Thank You