CAN201 W2
This is the note of CAN201(introduction to networking).
This lecture is mainly discussing about Application Layer
. 应用程序层
- Principle of network application
- Web application
The lab of this week is about Introduction of Python
.
Lecture
Rich network applications
- Communication: Email, IM, SNS
- Web: countless
- Internet games: countless
- Video based: TikTok
- VoIP / Meeting: Zoom
- P2P file sharing: BitTorrent, Thunder…
Architectures for applications
- Client-server
- peer to peer
所有的applications都是这两个架构
Client-server architecture
- Server
- Always-on host 不间断的主机
- Permanent IP address 永久ip地址
- High performance 高性能 / Distributed computing
- Clients
- Link to the server for service 连接服务器进行服务
- May be intermittently connect to the internet 可能是间歇性连接到互联网
- Dynamic IP address 动态ip地址
- Do not communicate directly with each other
P2P architecture
- No always-on server is needed
- Arbitrary end systems directly exchange data
- 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 intermittently connected
- Dynamic IP addresses
How to communicate over the network?
Host –> Sockets 插座 –> Network
A program with: identifier protocol.
IP地址标记主机,port标记主机里的进程。
Host - Program
- process: a program running within a host
- processes in different / same hosts:
- socket can be used to exchange messages
- Processes in the same host:
- Inter-process communication defined by OS
- CS architecture:
- Client process: initiates communication
- Server process: waits to be contacted
- P2P architecture:
- client process / server process on the same host
Addressing processes
- Host device has unique 32-bit IPv4 and/or 128-bit IPv6
- Process network identifier:
- IPv4:port 192.168.1.100:80
- [IPv6]:port [240e:3a1:4cb1:69d0:f40c:4269:74a2:7ea3]:80
App-layer protocol defines
- Types of messages exchanged
- request, response
- Message syntax
- what fields in messages & how fields are delineated
- Message semantics:
- meaning of information in fields
- Message timing: when and how
一共两种协议
Open protocols: 公开协议
- Defined in RFCs
- Allows for interoperability
- e.g., HTTP, SMTP, FTP
Closed protocols: 私有协议
- e.g., Skype, Games, you own protocols…
Transport service requirements
There’re 4 requirements in transport service: 必须遵守 (应用协议)
- data integrity
- throughput
- timing
- security
Internet transport protocols services (传输层协议)
- TCP 传输控制协议
- UDP 用户数据报协议
TCP service
- Reliable transport between sending and receiving process 发送和接收过程之间的可靠传输
- Flow control 流量控制: sender won’t overwhelm receiver 发送方不会淹没接收方
- Congestion control 拥塞控制: throttle sender when network overloaded 当网络过载时限制发送者
- Does not offer 不提供: timing, minimum throughput guarantee, security 记时,最低吞吐量保证,安全性
- Connection-oriented 面向连接: setup required between client and server processes 需要在客户端和服务器进程之间进行设置
Internet transport protocols services
The problems with UDP service:
- unreliable data transfer between sending and recieving process
- Does not offer: reliability, flow control, congestion control, timing, throughput guarantee, security, or connection setup. 不提供: 可靠性,流量控制,拥塞控制,时间,吞吐量保证,安全性或连接设置
Securing TCP
Secure Sockets Layer - SSL
- TCP & UDP
- No encryption 无加密
- Cleartext psws 明文程序状态字 –> Internet
- SSL
- Provides encrypted TCP connection 提供加密TCP连接
- Data integrity 数据完整性
- End-point authentication 端点认证
- SSL is at app layer
- Apps use SSL libraries, that “talk” to TCP
- SSL socket API
- Cleartext psw 明文程序状态字 –> encrypted psw –> Internet
Web application
Web, HTTP and WWW
- World Wide Web: WWW
- HTTP: Hypertext Transfer Protocol
- Web page consists of base HTML-file which includes several referenced objects, addressable by a URL 网页上的每一个对象都通过url进行寻址
HTTP overview
HTTP: hypertext transfer protocol 超文本传输协议
- Application layer protocol 应用层协议
- Client/server model
- Client: browser that requests, receives, (using HTTP protocol) and show Web objects (Render)
- Server: Web server sends (using HTTP protocol) objects in response to requests
Uses TCP:
- Client initiates TCP connection (creates socket) to server, port 80 客户端发起TCP连接到服务器,端口80
- Server accepts TCP connection from client 服务器接受来自客户端的TCP连接
- HTTP messages (application-layer protocol messages) exchanged between browser (HTTP client) and Web server (HTTP server) 在浏览器和Web服务器之间交换HTTP消息
- TCP connection closed TCP连接关闭
HTTP is “stateless”: server maintains no information about past client requests. HTTP是“无状态的”:服务器不维护关于过去客户端请求的信息。
Protocols that maintain “state” are complex!
- past history (state) must be maintained.
- if server/client crashed, their view of “state” may be inconsistent, must be reconciled. 如果服务器/客户端崩溃,他们的“状态”视图可能不一致,必须协调
Non-persistent HTTP 非持久性HTTP
- At most one object sent over TCP connection 最多一个对象通过TCP连接发送
- Downloading multiple objects required multiple connections 下载多个对象需要多个连接
Persistent HTTP 持久HTTP
- Multiple objects can be sent over single TCP connection between client, server 客户端和服务器之间可以通过单个TCP连接发送多个对象
Non-response time
Persistent HTTP
Non-persistent HTTP issues
- Requires 2 RTTs per object 每个对象需要2个rtt
- OS overhead for each TCP connection 每个TCP连接的操作系统开销
- Browsers often open parallel TCP connections to fetch referenced objects 浏览器经常打开并行TCP连接来获取引用的对象
Persistent HTTP issues
- Server leaves connection open after sending response 服务器在发送响应后保持连接打开
- Subsequent HTTP messages between same client/server sent over open connection 在同一个客户端/服务器之间通过开放连接发送的后续HTTP消息
- Client sends requests as soon as it encounters a referenced object 客户端一遇到引用对象就发送请求
- As little as one RTT for all the referenced objects 对于所有引用的对象,只有一个RTT
Persistent HTTP is not perfect
HTTP request message
- Two types of HTTP messages: request, response
- HTTP 1.x request message:
- ASCII (human-readable format)
general format
HTTP 1.1 method
What do we need from a web protocol?
Get, Create, Modify, Delete —- resource / data / information
HTTP 1.0 1.1 Additional methods
Get, Post, Put, Delete, Patch —- Safe Methods
Head, Trace, Options, Connect —- Idempotent Methods 幂等方法
HTTP response status codes
- Status code appears in 1st line in server-to-client response message.
- Some sample codes:
- 200 OK
- 301 Move Permanently
- 400 Bad Request
- 404 Not Found
- 505 HTTP Version Not Supported
User-server state: cookies
- many web sites use cookie
- four components:
- cookie header line of HTTP response message HTTP响应消息的cookie报头行
- cookie header line in next HTTP request message 下一个HTTP请求消息中的cookie头行
- cookie file kept on user’s host, managed by user’s browser cookie文件保存在用户的主机上,由用户的浏览器管理
- back-end database at web site 网站的后端数据库
Example:
Bob always access Internet from PC and visits Taobao site for first time. When initial HTTP requests arrives at site, site creates: unique ID –> cookie, entry in backend database for ID.
cookies
What cookies can be used for: cookies可以用来做什么
- authorization 授权
- shopping carts 购物车
- recommendations 建议
- user session state 用户会话状态
How to keep “state”:
- Protocol endpoints: maintain state at sender/receiver over multiple transactions 协议端点:在多个事务中维护发送方/接收方的状态
- Cookies: http messages http消息
Cookies and privacy: cookies permit sites to learn a lot about you; remember to clean your cookies. Cookies允许网站了解更多关于你的信息。
Web Caches web缓存(Proxy server代理服务器)
Goal: satisfy client request without involving origin server 满足客户端请求而不涉及原始服务器
- User sets browser: Web accesses via cache 用户设置浏览器:通过缓存访问Web
- Browser sends all HTTP requests to cache 浏览器将所有HTTP请求发送到缓存
- object in cache: cache returns object 缓存返回对象
- else cache requests object from origin server, then returns object to client 从源服务器缓存请求对象,然后返回对象给客户端
- 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) 缓存通常由ISP安装
Why web caching?
- reduce response time for client request 减少客户的要求的反应时间
- reduce traffic on an institution’s access link 减少机构访问链接的流量
- internet dense with caches: enable “poor” content provides to effectively deliver content (so too does P2P file sharing) 使“糟糕的”内容提供商能够有效地传递内容
cache example
Assumptions:
- avg object size: 100K bits
- avg request rate from browsers to origin servers: 15/sec
- avg data rate to browsers: 1.50 Mbps 100k*15
- RTT from institutional router to any origin server: 2 sec
- access link rate: 1.54 Mbps
Consequences:
- LAN utilization: 0.15%
- access link utilization = 99% 1.50/1.54 无限拥塞,以分钟做为单位
- total delay = Internet delay + access delay + LAN delay = 2 sec + minutes + usecs
conditional GET
- Goal: don’t send object if cache has up-to-date cached version
- no object transmission delay
- lower link utilization
- cache: specify date of cahced copy in HTTP request
- If-modified-since:
- server response contains no object if cached copy is up-to-date:
- HTTP/1.0 304 Not Modified
How Email Works:
- A user (Alice) sends an email message and connects to an SMTP (Simple Mail Transfer Protocol) server as configured in her email client or Mail User Agent (MUA). 用户发送电子邮件消息并连接SMTP服务器配置在她的电子邮件客户端或邮件用户代理。
- On the SMTP server, a Mail Transfer Agent (MTA) looks at the recipient address and looks up the domain part of the address to determine its destination. 在SMTP服务器上,邮件传输代理查看收件人地址并查找地址的域部分以确定其目的地。
- After querying a Domain Name System (DNS) server for the name of the Mail eXchanger (MX) for the recipient’s domain name… 在DNS服务器上查询收件人域名的Mail exchange名称后
- …the SMTP server will send the message to that server via the SMTP protocol. SMTP服务器将通过SMTP协议将消息发送到该服务器。
- The receiving server will store the message and make it available to the recipient (Bob), who can access it via web, POP, or IMAP. 接收服务器将存储消息并使其对接收方可用,接收方可以通过web、POP或IMAP访问该消息。
Email Protocols
Components:
- mail user agent 先从mua发送到ms 然后ms发送到另外一个ms ms再送到收件人的mua
- mail server 邮件服务器
- SMTP (protocol)
Delivery:
- SMTP: simple mail transfer protocol[RFC2821, Apr. 2001]
Receive:
- POP3 - Post Office Protocol - Version 3[RFC1939, May 1996]
- IMAP - Internet Message Access Protocol[RFC3501, Mar. 2003]
- Exchange ActiveSync – Microsoft’s protocol[from 2002]
Lab
1 | import re # 为正则表达式引入的re库 |
References
- XJTLU MC PowerPoint slides (CAN201 Week2 Lecture2 & Lab2)
- 计算机网络 自顶向下方法.原书第6版