Sunday, January 19, 2020

CS2105: Lecture 2 - Application Layer

Previously on avatar....

Packet switching: Store and forward

Information is chopped into small pieces called a packet. 
Routers need to receive all the packet before being able to forward to the next router

Internet protocol stack

An abstraction and seperation of the different layers and function of internet protocol

Principles of network applications

Creating a network app

Write programs that 
- run on different end system
- Communicates over network
e.g web server software, browser software

Theres no need to write software for network core devices
-Allow rapid application development

Softwares are running on end systems/hosts, thus we do need to write the software on network core 
devices

However, they have to talk to each other over the network.
e.g Web server software talking to browser software
to download infomation.

The network core is only in the network layer, theres no need to worry about it in the application layer. Network core are like routers and switches
An upper layer is implemented by using the service by the layer below it, thus the application layer just have to use the service that is provided by the transport layer.
We can use the service by choosing the service type provided

Client server architecture

Server
- Always on host
- Permanent IP address
- Data centers for scaling

Clients:
- Communicate with server
- May be intermittently connected
- May have dynamic IP address
- Do not communicate directly with each other

Peer to peer architecture

There is very minimum or no servers at all. The peers are allowed to talk to each other.
Advantages:
- Self scalable
More user that join, can automatically provide the information and service
So the demands is scalable


Disadvantages:
- Management is complex due to the changes of IP address

Process communicating

Process: Program running within a host.
- Within same host, two process communicate using inter-process communication (OS)
- Process in different host communicate by exchanging message

Client process: Initiate
Server: Waits to be contacted
EXTRA: application with p2p archi have client processes and server processes

Sockets

- Process sends and receives message to and from its sockets
- Process relies on transport infrastructure on other side of the door to deliver message to socket at receiving process

Addressing processes

- To receive message, process have identifier
- Host device have 32 bit IP address
- An identifier includes both IP address and port numbers associated with the process 

A host is like a building, we need to specify which apartment to send the letter

Transport Service

- Data integrity
Data transfer must be reliable (for some apps)
Apps such as audio can tolerate some loss

- Throughput
Some apps need minimum amount of throughput to be effective (e.g multimedia)
Some apps do not need, like email, it is okay to be delayed by 3 seconds

- Timing
Some apps require low delay to be effective (e.g interactive games)

- Security
encryption, data integrity


Insert slide 13

It is very hard to have it all, we only need 

Internet transport protocol service

TCP
- Reliable transport
- Flow control
- Congestion control
- No timing, minimum throughput and security

UDP
- Unreliable data transfer
- No congestion, security, connection setup

UDP is more faster in setting up a connection as it does not need two sides to agree to have a connection. However, security is not under transport layer. UDP Is cheaper
UDP has a chance to lose packets so its better to use it for video. If the reliability is not needed strictly, there is no need to pay for TCP.

Firewalls filter most UDP traffic, thus most internet providers use TCP

Insert 15

App layer protocol

- Types of message exchange
Request and response

- Message syntax
what fields in message and how fields are delineated
The format

- Message semantics
Meaning of information

- Rules
The behavior, how and when process send and response to messgae


Types of protocol
- Open protocols
Defined by RFC(public)
e.g HTTP, SMTP

- Proprietary protocols
e.g Skype


Web and HTTP

Web page consist of objects such as HTML file, JPEG image, Java applet, Audio file etc
The web page consist of base HTML files which included several reference objects
Each object is addressable by a URL

e.g www.someschool.edu/someDept/pic.gif
      ( Host name              ) (      path name    )

HTTP overview

Is a web application layer protocol.
Follows the client server model
Client: Browser that request and receivers using the HTTP protocols and shows the web objects
Servers: Sends the objects in response to request from client

They must be running on the same protocol in order for them to understand each other, it does not have to be develop by you. Web server can send back the objects in response to the request of the client.
It defines the behavior and the rules.

Uses TCP

- Clients initiate TCP connections (create socket)
- Server accepts TCP connection from client
- HTTP messages 
- TCP connection closed

HTTP is stateless, server maintains no info about past clients request
Keeping of information to maintain state is complex as if server or client crashes, their views of the state may be inconsistent.
It is stateless because we relied on TCP already which is reliable. TCP itself must be stateful.

HTTP connections

Non Persistent HTTP

At most one object send over TCP connection, connection then close.
Downloading multiple objects require multiple connection

e.g A user enters the URL, 
1. the HTTP client initiates TCP connection to HTTP server (Process) at the server url at port 
2.Once the HTTP accepts connection, it notify the client
3.The Client sends the HTTP request message into the TCP connection socket, asking from the client the object it wants to download
4. HTTP servers recieves request, forms response containing requested objects and sends message to its socket, server then close the TCP connection
5. HTTP client gets responses, and unpackage the file by parsing.


RTT:
Time for a small packet to travel from client to server and back

HTTP response time:
One RTT to init TCP connection
Once it is confirm connected, then you send the file
In response the server will transfer the file to you depending on the size of the file.
Bigger file = more packets send
It will close the connection once it is done.

The response time is = 2RTT + file transmission time


Persistent HTTP
- Multiple objects can be sent over single TCP connection between client and server

Servers leaves connection open after sending response
Subsequent HTTP message between same client/server sent over open connection
Client sends request as soon as it encounters a reference object

The response time = one RTT for all reference objects
(Only need to open once to get the objects)

Persistent might be more efficient for user point of view but for server, if everyone use persistent, the server might be overloaded and might cause DOS attacks. (Denial of service)

Protocols and states are stored in hosts.

v1.1 - persistent
v1.0 - non persistent 
Can specify to change

HTTP Request Message

Only two types: request and response
These are the message being sent by the server/client for HTTP
Format: Insert 27
1. Method/Command
(GET/POST/HEAD)
2. What you want get
3. Version
4. Headerlines
Under connection, it defines if its persistent or non persistent
Host: Specify where the web server is. This is because the message might not be send directly to the webserver itself (web proxy)
For GET method, the body might be empty.
For POST method, we need to submit certain request to the server thus the body might not be empty. 
e.g do a form or to do a search request.

Uploading form input

POST
- Webpage often includes form input
- Input is uploaded to server in entitiy body

URL
- GET method
- INput is uploaded in URL field request line

Method types

HTTP/1.0
- GET
- POST
-HEAD
Default: Non persistent

HTTP/1.1
-GET, POST, HEAD
- PUT
upload file in entity body to path specified in URL

- DELETE
delete file specified in URL field

HTTP response message

1. Status line
- Version
- Protocol status code status phase

2. Header line
- Date
- Server
- Modified last
- Connection

3. Data requested

HTTP response status codes

Status code appears in 1st line in server to client response message
Sample codes:
Insert 31

Cookies

Cookies keep track of certain states for our client. (Since HTTP is stateless)
Many website use cookies. Cookie is initiated by server.

1) Cookie header line of HTTP response message

2) Cookie header line in next HTTP request message

3) Cookie file kept on user's host, managed by user's browser
Cookie is kept in the local memory, the browser. Whenever the client wants to make another request with the same host, it will include the cookie so the server will know which client it is.

4) Back-end database at website
Server keep all the cookies in their own local database so they can keep track of their browsing history. Keeps the ID
A new user will have a new cookie created.

This sending of cookie allow the server to be able to keep track of the client search history and behavior so that they can provide better service for the client.
Cookies can be use to provide authentication, maintain shopping carts, recommendation, user session state.

This is nothing to do with the protocol but the work of the cookie which allow the server to know who is the client. Cookies permit sites to learn a lot about us. (Privacy)
Cookie is built in network edges.

Web Caches (Proxy Server)

Goal: To satisfy client request without involving origin server. 
When we use hTTP request, it might not be send directly to the server but to a proxy server provided by our service provider. 
- The first time, the server will act like a client and submit a request to the origin server
- The proxy server will then store the content in its local memory, acting like a cache layer.
- When there is a second time, the proxy server will directly reply to the client without contacting the origin server. 
- There is a possibility of a cache miss, which requires the proxy server to look at the origin server.
It is much faster to get info from the Proxy server rather than making multiple request to the original
server

Conditional GET
Sometimes the cache is not up to date with the actual.
HTTP request: If-Modified-since: <Date>

Cache: Specify the date of the copy in HTTP request
Server: Response contains no object if cache copy is up to date

Server will send new content if its not up to date with the cache version,

DNS: Domain Name System

Used as identifiers for internet host.
- IP address use for addressing
- "name" use by humans
e.g yahoo.com

This service is provided by DNS which is built at the application layer.
The mapping is provided by a hierarchy of many name servers which provide a central database.

Local DNS Name server

Host makes a DNS query and its sent to its local DNS server.
    - local cache of recent name to address translation pairs 
    - acts as proxy
Does not strictly belong to hierarchy.
It is implement by multiple server.

Hierarchical Database of DNS
Note: is the right to left in reading URL
1. Root
The source of the entire directory.
The first point to be contacted when we cannot resolve the name
There are over 400 servers all over the world
Root servers do not have an actual mapping. 

2. Organization/Institution (Authoratative servers)
- Edu/Org/UK

The org will own these servers so that when outside ppl contact them, they will provide the actual mapping between host name and ip address.
But if we are end user that one to publish our own website, the our website is our own authorative servers.

3. More specific


DNS Name Resolution Example

Suppose a host at cls.poly.edu. wants to access the website of gia.cs.umasss.edu
It does not know the ip address of that host
It makes a local dns request to the dns server of that host
The local, lets say it does not have a mapping, it will contact one of the root server that it knows.
It returns an ip address of a top level dns server which takes care of the edu domain.
The local dns server will further contact the top level dns server
The top lelvel dns server take care of all so it does not know the detailed details but it return a mapping of an authoritative server that knows the mapping
The local dns server will make a query to that authoritative server that will return the ip address of the host that the client wants.

<Insert slide 44>

Iterative query: Do not return the correct address but give you another server's ip address to contact (Immediatery contact)

This local dns server will finally get the ipaddress and return to the client.
IF the root dns server is serving the recursive manner, even if it does not know, it will help the local dns server to make a query to the authorative server.

ie. Each server will make a request for the server one level on top if it does not know what the response is. 

DNS: Caching, updating record

When client makes request and obtain the final answer, they will keep the answers in a cache. When other clients want to make similar request, it can just retrieve from the cache immdiately. 

Out of date
The host names can change however, the cache could be outdated. For DNS, they will use a time to lift value (TTL =2 days), after that the content might be obselete so the cache will be deleted.

By passing the high level domain service
The top level domain service are often cache in local dns such that when dns do not know the mapping, they do not have to go to the root but just go directly to the highere level domain servuce,
(By pass the need to go to root)





No comments:

Post a Comment