計算機網路-應用層筆記

吳龍茗茶發表於2021-01-02

計算機網路-應用層筆記

注:此文章為計網接近滿績的巨佬博主“憂傷的小馬”所做。其部落格主頁地址和github傳送門如下:

憂傷的小馬:部落格主頁:https://blog.csdn.net/qq_45504981
github傳送門:https://github.com/rzy0901

2.1 principles of network applications

network apps:

  • 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:在這裡插入圖片描述

    • run on (different) end systems;
    • communicate over network;
  • client-server:

    • server: always on host, permanently ip, data centers for scaling.
    • client: 可以斷開,dynamic ip;
  • P2P:

    • no always on server;
    • arbitrary end systems;
    • peers are intermittently connected and change IP addresses(斷續連線,改變ip; )
    • self-scalability.

Process, socket(套接字):

  • Who?: Process send/receive message to/from network.

  • Where?: Process send/receive message to/from sockets.

  • Process with same hosts: inter-process communication( defined by OS)

    內部(process with same host)程式通訊由作業系統決定。在這裡插入圖片描述

    P2P 既有server process 又有 client process.

IP and Port number

  • process has identifier (both ip address and port numbers)

  • 32-bit ip address.

  • many processes run on same host.

    所以需要埠?

  • Example port number:

    • HTTP server: 80;
    • Mail server: 25;
![在這裡插入圖片描述](https://img-blog.csdnimg.cn/20210102222855928.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDA3Nzk1NQ==,size_16,color_FFFFFF,t_70#pic_center) ![在這裡插入圖片描述](https://img-blog.csdnimg.cn/20210102222903639.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDA3Nzk1NQ==,size_16,color_FFFFFF,t_70#pic_center)

Internet transfer protocols service

TCP UDP 是傳輸層協議

在這裡插入圖片描述

  • TCP service:

    • Reliable transport; Flow control; Congestion control; Connection-oriented;

    • Dose not provide timing, minimum throughput guarantee, and security.

  • UDP service:

    • Unreliable data transfer.
    • Does not provide: reliability, flow control, congestion control, timing, throughput guarantee, security, or connection setup.

在這裡插入圖片描述
在這裡插入圖片描述

2.2 Web and HTTP

Web

  • Web page consists of objects.

    object can be HTML file, JPEG image, Java applet, audio file,…

  • web page consists of base HTML-file which includes several referenced objects.

  • Each object is addressable by a URL.

    HTML 基本檔案 (bases HTML-file) 通過物件的URL地址引用頁面中的物件。

    在這裡插入圖片描述

HTTP overview

  • Hypertext transfer protocol

  • Web’s application layer protocol (應用層協議)

  • client/server mode.

  • uses TCP.(步驟從上到下1、2、3)

    HTTP messages exchanged
    HTTP messages exchanged
    client initiate TCP connection
    server accepts TCP connection from client
    browser (HTTP client)
    Web server (HTTP server)
    TCP connection closed
  • HTTP is stateless .

server maintains no information about past client request.

HTTP connection

  • non-persistent HTTP: (非持續連線HTTP)

    At most one object sent over TCP connection.

    Connection then closed.

    Downloading multiple objects required multiple connections.

    一個connection傳一個object. 每傳完object都會關閉connection.

  • persistent HTTP: (持續連線HTTP)

    multiple objects can be sent over single TCP connection between client, server.

    一個connection傳多個object.

Non-persistent HTTP

在這裡插入圖片描述
在這裡插入圖片描述

第4步,HTTP server 通知TCP斷開connection,但是直到TCP確認客戶完整收到響應報文為止,它才會實際中斷連線。

Non-persistent HTTP: response time

  • RTT (definition): time for a small packet to travel from client to server and back.

    傳輸一個packet往返的時間。

  • Non-persistent HTTP: response time = 2*RTT+file transmission time.

一個RTT建立connection, 一個RTT傳輸HTTP request和HTTP response在這裡插入圖片描述

Persistent HTTP

server leaves connection open after sending response.

One RTT needed.

HTTP message

在這裡插入圖片描述

HTTP request message

  • 在這裡插入圖片描述

  • 在這裡插入圖片描述

    CR: carriage return;(回車) LF: line feed(換行) 其實就是\r\rn

    request line coding = ASCII (human-readable format)

    request line = method + url + http version

    Uploading form input: POST method, URL method.

    Method types:

    • HTTP/1.0:

      GET. POST, HEAD

    • HTTP/1.1:

      GET,POST,HEAD.

      PUT, DELETE.(上傳或刪除指定URL檔案)

HTTP response messages

在這裡插入圖片描述
在這裡插入圖片描述

User-server state: Cookies

  • Four components for “cookie”: (對應下圖藍色圓柱)

    • cookie header line in HTTP response message.
    • cookie header line in next HTTP request message.
    • cookie file kept on user’s host, managed by user’s browser.
    • back-end database at Web site.

在這裡插入圖片描述

第一次request沒有cookie, 建立ID:1678,返回response message (cookie header line: Set cookie:1678)

在這裡插入圖片描述

Web caches (proxy server) 快取器、代理伺服器

goal: satisfy client request without involving origin server

if HTTP request in cache:

​ return HTTP response from cache

else:

​ cache requests object from origin server

​ then return object to client

在這裡插入圖片描述

Cache acts as server for original requesting client.

Cache acts as client to origin server.

Lower link utilization, lower delay.

Typically cache is installed by ISP (university, company, residential ISP). 在這裡插入圖片描述
1.減少響應時間 2.減少“交通壓力”3.使內容提供商更加有效傳輸資料

Example:

在這裡插入圖片描述

Conditional GET

Goal: don’t send object if cache has up-to-date cached version

cache: specify date of cached copy in HTTP request:

  • If-modified-since: <date>

server: response contains no object if cached copy is up-to-date:

  • HTTP/1.0 304 Not Modified

在這裡插入圖片描述

2.3 electronic mail: SMTP,POP3,IMAP

Electronic mail:

在這裡插入圖片描述

  • Three major components:

    • user agent;
    • mail server;
    • SMTP (simple mail transfer control);
  • User agent:

    • composing, editing, reading mail messages;

    • outgoing, incoming messages stored on server;

      mailbox : incoming messages

      message queue: outgoing messages

  • Mail server:

    • mailbox contains incoming messages for user;
    • message queue of outgoing (to be sent) mail messages;
    • SMTP protocol between mail servers to send email messages;

Scenario:

在這裡插入圖片描述

(1)Alice uses UA to compose message to bob@someschool.edu;

(2)Alice’s UA sends message to her mail server; message placed in message queue

(3)client side of SMTP opens TCP connection with Bob’s mail server;

(4)SMTP client sends Alice’s message over the TCP connection;

(5)Bob’s mail server places the message in Bob’s mailbox

(6)Bob invokes his user agent to read message;

Electronic Mail: SMTP

  • uses TCP to reliably transfer email message from client to server, port 25;

  • direct transfer: sending server to receiving server;

  • three phases of transfer:

    • handshaking (greeting);

    • transfer of messages;

    • closure;

  • command/response interaction (like HTTP):

    • commands: ASCII text
    • response: status code and phrase
  • messages must be in 7-bit ASCII;

  • SMTP uses persistent connections;

  • \r\n.\r\n determines end of message.

在這裡插入圖片描述

三次握手以後,連線建立成功,伺服器推送就緒資訊:

  • 220: 服務就緒

server: 交代認證伺服器域名,發件者郵箱,收件者郵箱:

  • 250

client: 傳送DATA\r\n

server: 伺服器返回354,表示自己已經作好接受郵件的準備.

client: 客戶端傳送郵件正文

client: 正文結束符 .

server: 服務端返回250表示成功。

client: 郵件傳送結束,客戶端請求斷開連線。 傳送QUIT\r\n

server: 伺服器返回211,提示斷開申請被採納,並主動斷開連線,整個郵件傳送過程結束。

SMTP vs HTTP

  • SMTP: push (推協議)

    HTTP: pull (拉協議)

  • both have ASCII command/response interaction, status codes;

  • HTTP: each object encapsulated in its own response message;

    網頁上每個object都有自己的url連結?

  • SMTP: multiple objects sent in multipart message;

    郵件很多附件?

Mail access protocols (郵件訪問協議)

在這裡插入圖片描述

  • POP: Post Office Protocol [RFC 1939]: authorization, download.

  • IMAP: Internet Mail Access Protocol [RFC 1730]: more features, including manipulation of stored messages on server.

  • HTTP: gmail, Hotmail, Yahoo! Mail, etc.
    在這裡插入圖片描述
    在這裡插入圖片描述

2.4 DNS

Domain Name system:

  • distributed database implemented in hierarchy of many name servers.

  • application-layer protocol: hosts, name servers communicate to resolve names (address/name translation)

    域名,ip對映

DNS service:

  • Host name to ip address translation.

  • Host aliasing.

  • Mail server aliasing.

  • Load distribution.

    replicated Web servers: many IP addresses correspond to one name.

    在這裡插入圖片描述

DNS: a distributed, hierarchical database:
在這裡插入圖片描述

查詢 www.amazon.com ip地址:

  • 查詢root dns server返回com DNS server
  • 查詢 .com DNS server返回 amazon.com DNS server;
  • 查詢 amazon.com DNS server 得到 www.amazon.com ip地址;

查詢 www.sustech.edu.cn ip地址:

  • root dns server 返回 cn;
  • top 返回 edu.cn;
  • authoritative 返回 sustech.edu.cn ➡️ www.sustech.edu.cn;

DNS servers

  • root name servers (根DNS伺服器);

    • contacts authoritative name server if name mapping not known
    • gets mapping
    • returns mapping to local name server

    在這裡插入圖片描述

  • top-level domain (TLD) servers (頂級域伺服器);

    com org net edu aero cn

  • Authoritative DNS servers(權威DNS伺服器);

    • organization’s own DNS servers
    • providing authoritative hostname to IP mappings for organization’s named hosts
    • can be maintained by organization or service provider
  • Local DNS name server. (default name server)

    • does not strictly belong to hierarchy

    • each ISP (residential ISP, company, university) has one

    • when host makes DNS query, query is sent to its local DNS server

      • has local cache of recent name-to-address translation pairs;

        (but may be out of date!)

      • acts as proxy, forwards query into hierarchy;
        在這裡插入圖片描述
        在這裡插入圖片描述

在這裡插入圖片描述

在這裡插入圖片描述
在這裡插入圖片描述

在這裡插入圖片描述
在這裡插入圖片描述

2.5 P2P applications

Pure P2P architecture

  • no always on server;

  • arbitrary end systems;

  • peers are intermittently connected and change IP addresses(斷續連線,改變ip; )

  • self-scalability.

    examples:

    • file distribution (BitTorrent)
    • Streaming (KanKan)
    • VoIP (Skype)

File distribution:

Question: how much time to distribute file (size F) from one server to N peers?

在這裡插入圖片描述

ParameterDescription
u s u_s usserver upload capacity
u i u_i uipeer i i i upload capacity
d i d_i dipeer i i i download capacity
d m i n d_{min} dminminimum download capacity: d m i n = m i n { d 1 , d 2 , . . . , d N } d_{min}=min\{d_1,d_2,...,d_N\} dmin=min{d1,d2,...,dN} unit: b i t s / s e c bits/sec bits/sec
D c − s D_{c-s} Dcstime to distribute F F F to N N N clients
F F FFile size
  • For client server model:
    D c − s ≥ m a x { N F / u s , F / d m i n } D_{c-s}\geq max\{NF/u_s,F/d_{min}\} Dcsmax{NF/us,F/dmin}

N 足夠大,由 N F / u S NF/u_S NF/uS決定

  • For P2P model:

D c − s ≥ m a x { F / u s , F / d m i n , N F / ( u s + ∑ u i ) } D_{c-s}\geq max\{F/u_s,F/d_{min},NF/(u_s+\sum u_i)\} Dcsmax{F/us,F/dmin,NF/(us+ui)}

極限為: m a x { F / u s , F / d m i n , F / u i m i n } max\{F/u_s,F/d_{min},F/u_{i_{min}}\} max{F/us,F/dmin,F/uimin}

  • 在這裡插入圖片描述

P2P file distribution: BitTorrent

  • file divided into 256 Kb chunks.
  • peers in torrent send/receive file chunks.

在這裡插入圖片描述
在這裡插入圖片描述

2.6 Video streaming and content distribution networks (CDNs)

在這裡插入圖片描述

在這裡插入圖片描述

在這裡插入圖片描述
在這裡插入圖片描述

Bob通過local dns server訪問netcinema,netcinema給了他一個新的url --> Bob 通過新的url 訪問資源。

2.7 socket programming with UDP and TCP

  • 轉載請註明出處:

https://blog.csdn.net/weixin_44077955/article/details/112125922

文章難免有疏漏錯誤之處,歡迎私信博主及時更正,大家共同進步?。

Reference:

①:計算機網路-自頂向下方法

②:http://gaia.cs.umass.edu/kurose_ross/ppt.htm

相關文章