🌐计算机网络
type
status
date
slug
summary
tags
category
icon
password
一些要记住的东西
TTL: Time -To-Live IP包被路由器丢弃之前允许通过的最大的网段数量
TLD: 顶级域名服务器
URL:统一资源定位符
MSS: 最大报文段长度
MTU:最大传输单元,也就是最大链路层帧的长度
CIDR:无类别域间路由选择
ICANN:因特网名字与号码分配机构
RIP:路由信息选择协议
应用层协议:
协议名称 | 功能 | 运输层协议 |
HTTP/HTTPS | 传输网页的主要协议 | TCP |
FTP | 文件传输协议 | TCP |
SMTP | 电子邮件传输协议 | TCP |
POP3 | 从邮件服务器下载邮件 | TCP |
IMAP | TCP | TCP |
DNS | 将域名解析为IP地址 | UDP |
DHCP | 动态路由分配 | UDP? |
运输层协议:
协议名称 | 功能与特点 | 场景 |
TCP | 面向连接、可靠、流量控制、拥塞控制、数据分段 | Web浏览、电子邮件、文件传输 |
UDP | 无连接、不可靠、低开销、数据报文 | 实时应用、简单请求应答、广播 |
网络层协议:
协议名称 | 功能 | 运输层协议 |
IP | 提供不可靠、无连接的数据包传输,数据包路由选择,分片和重组 | TCP、UDP |
ICMP | 发送错误报告和操作信息,不传输应用数据,只提供控制和信息消息 | 不使用运输层协议,直接封装在IP数据包中 |
ARP | 将IP地址解析为物理(MAC)地址,允许主机在本地网络发现其他设备的MAC地址 | 不使用运输层协议,直接封装在链路层(如以太网帧)中 |
OSPF | 基于链路状态的内部网关协议,Dijkstra算法 | 不使用运输层协议,直接封装在IP数据包中 |
BGP | 用于不同AS之间的路由选择,基于路径向量的外部网关协议 | TCP |
链路层协议:
Chapter 1
Packet switching
hosts break application-layer messages into packets
each packet transmitted at full link capacity(每个数据包均已全链路容量传输)
store-and-forward: entire packet must arrive at router before it can be transmitted on next link(整个数据包到达路由器之后才能开始下一段传输)
What device has the function of storage and forwarding?
- Router and Switch
What device has not the function of storage and forwarding?
- Hub and Repeater
network core: interconnected routers and links
two fundamental approaches to moving data : circuit switching and packet switching
circuit switching : resources needed along the path are reserved
packet switching : not reserved, use resources on demand
general case : one packet(L bits), over a path consisting of N links each of rate R(N-1 routers)
End to end delay: N*L/R
queueing delay
each packet switch has multiple links, each link has an output buffer.
packet loss: if buffer is completely full, the arriving packet or one of the already-queued packets will be dropped
延时计算
链路段数为n,包数为k
传输延迟=[n+(k-1)]*每个包传输时间 总=传输+传播+其他(如果有)
circuit switching
commonly used in traditional telephone networks
resources not reserved, used on demand
high cost
FDM: each circuit continuously gets a fraction of the bandwidth
电路连续获得部分带宽
TDM: each circuits gets all of the bandwidth periodically during brief intervals of time (slots)
每个电路在短暂的时间间隔(时隙)内定期获得所有的带宽
Critics of packet switching:
packet switching is not suitable for real-time services(telephone calls and video conference calls) because of its variable and unpredictable end-to-end delays分组交换机不适合实时业务,因为其端到端延迟可变而且不可预测
延时计算
set-up time + 传输时间 + 传播时间
Proponents of packet switching分组传输的优势
it offers better sharing of transmission capacity than circuits switching.提供更好的传输容量共享
is simpler, more efficient, and less costly to implement than circuit switching.简单高效成本低
packet switching can allows more users to use network更多人使用
packet switching great for burst data 更适合突发数据
excessive congestion possible 可能出现过度拥塞

Throughput吞吐量
rate (bits / time unit ) ai which bits are being sent from sender to receiver, it has instantaneous and average one
bottleneck link 瓶颈环节
link on end-end path that constrains end-end throughput
Layers:
each layer implements a service
- via its own internal-layer actions
- relying on services procided by layer below
Why use layers?
dealing with complex systems:
- explicits structure allows identification, relationship of complex system's pieces
- layered reference model for discussion
- modularization eases maintenance, updating of system
- change of implements of layer's service transparent to rest of system
- change in gate procedure (disembark by height) doesn't affect rest of system
- layering considered harmful?
- one layer may duplicate lower-layer functionality
- functionality at one layer may need information that is present only in another layer


application message
transport segment
network datagram
link frame
physical transmission medium
transprt layer and the higher layers typically run only on end-hosts and not on the intermediate switched and routers
传输层和更高层通常只在终端主机上运行而不在中间交换机和路由器上运行
而下三层在所有网络节点上实现

Application exchanges messages to implement some application service using services of transport layer
Transport-layer protocol transfer M from one process to another, using services of network layer, transport-layer protocol encapsulates application-layer message M with transport layer-layer header H to create a transport-layer segment.
Network-layer protocol transfers transport-layer segment [H | M] from one host to another, using link layer services, network-layer protocol encapsulates transport-layer segment [H | M] with network layer-layer header H to create a network-layer datagram, H used by network layer to protocol to implement its service.
Link-layer protocol transfer datagram[ H | [H | M]] from host to neighbouring host, using network-layer services, link-layer protocol encapsulates network datagram [[]] with link-layer header to create a link-layer frame
每层封装加一点header 一般题目中不说不会考虑


Chapter 2
C-S client- server
server:
- always on
- permanent IP
- often in datacenter, for scaling 用于扩展
client:
- contact, communicatoin with server
- dynamic IP
- intermittently connected
- do not communicate directly
e.g. HTTP,IMAP,FTP
Peer-Peer :
- no always-on server
- 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 intermittently connected and change IP address(间歇性链接并且更改IP)
hybrid c-s and p2p 混合

Process communicating
- 同一主机内进程的相互通信
- 不同主机上的进程通过交换消息进行通信
- sending: create and send to network
- receicing: receive and may respends by sending messages
客户端进程发起通信,p2p架构中也是(发起通信的peer就是客户端)
进程从Socket套接字中发送接收消息,单次二者传输中需要每侧各一个socket,即总共两个
为了接收消息,进程必须有标识符identifier,=主机IP+port number
Avaliable transport services
应用程序对于数据传输的要求不同
- 要求完整or允许部分损失
- 低延迟or可容忍延迟
- 需要最低吞吐量or利用获得的所有的吞吐量
- 安全性……

Internet transport protocol services
TCP and UDP

普通TCP UDP套接字,无加密,明文传输
传输层安全(TLS)提供加密的TCP连接
- 数据完整性
- end-point authentication
- 在应用层的实现,app使用TLS库,库中使用TCP,加密TCP明文进入互联网
HTTP and web
web page consist of base HTML-file which includes several referenced objects, each addressable by a URL,
HTTP:超文本传输协议 hypertext transfer protocol
web 的应用层协议
client: browser that requests, receives, and displays web objects
server:web server sends objects in response to requests
HTTP 使用TCP
- 客户端发起TCP连接,创建套接字到服务器,端口80
- 服务器接收来自客户端的TCP连接
- 交换的HTTP消息(应用层协议消息),在浏览器(客户端)和网络服务器(服务端)之间
- TCP连接关闭
HTTP是无状态的 stateless
- server maintains no information about past client requests 服务器不维护有关过去客户端请求的信息
protocol that maintain "state" are complex
- 必须维护过去的历史状态
- 若服务器、客户端有一方崩溃,他们对于“状态”的看法可能不一致需要协调
Types two
Non-persistent HTTP
- TCP connection opened
- at most one object sent over TCP connection
- TCP connection closed
- -----multiple objects need multiple connections
persistent HTTP
- TCP connection opended
- single TCP sent multiple objects
- TCP closed
对于非持久HTTP连接来说,每个TCP连接在服务器发送对象之后关闭,该链接不会为其他对象保留。
Response time: 估计从客户端请求基本HTML文件到客户端受到整个文件所花费的时间
RTT:time for a small packet to travel from client to server and back 小数据包来回的时间
包括处理延迟、排队延迟、传播延迟
三向握手
HTTP响应时间 2RTT
1RTT for initiate TCP connection
1RTT for request and receive object
所以:非持久HTTP响应时间=2RTT+文件传输时间
浏览器经常打开多个并行TCP连接来并行获取引用的对象
持久HTTP
服务器响应连接后保持连接打开,客户端一遇到引用的对象就发送请求,所有引用对象只需要1RTT(比非持久HTTP减半)
非流水线方式传输对象,1HTML和10JPEG需要11RTT
流水线方式传输,1HTML和10JPEG需要2RTT(不考虑传输时延的情况下)
HTTP 消息格式
request请求消息:request line + header line + body


reponse 响应报文:status line + header lines + blank line + body
Maintaining user/server state: cookies
网站和客户端浏览器使用cookie来维护事务之间的某些状态
- cookie header line of 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

cookie用途:
- 授权
- 购物车
- 监狱
- 用户会话状态(web电子邮件)
How to keep state?
协议端点:在多个事务中维护发送者、接收者的状态
在消息中:HTTP消息中的cookie携带状态
cookie 跟踪给定网站上的用户行为,跨多个网站跟踪用户行为
web caches 网络缓存

web缓存既充当客户端也充当服务端 p62
why?
- 减少客户端请求的响应时间,缓存更加靠近客户端
- 减少机构访问连接的流量
- 互联网上有密集的缓存,使内容贫瘠的内容提供商能够更有效的提供内容


应用层
电子邮件的三个组成:
- 用户代理 user agent
- 邮件服务器mail server
- 简单邮件传输协议SMTP simple mail transfer protocol
邮件服务器之间使用SMTP协议来发送电子邮件



DNS 域名系统
host aliasing 主机别名
canonical 规范主机名

root name servers 根名称服务器
top-level domain TLD 顶级域名服务器
local DNS name servers 本地DNS名称服务器
DNS名称解析 迭代查询 iterated query、
我不知道,但是你问问这个吧

递归查询 recursive query
将名称解析负担置于所联系的名称

once (any) name server learns mapping, it caches mapping, and immediately returns a cached mapping in response to a query

A; 主机 IP A
CNAME: 别名 权威名 CNAME
NS:websever DNS server NS
MX:@后(email address) 权威名(email server) MX

DNS query and reply messages, both have same format:
DNS uses UDP
Peer-to-peer architecture
- no always-on server
- 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, and new service demands
- peers are intermittently connected and change IP addresses

UDP and TCP
Two socket types for two transport services:
- UDP: unreliable datagram
- TCP: reliable, byte stream-oriented
UDP: no “connection” between client and server:
- no handshaking before sending data
- sender explicitly attaches IP destination address and port # to each packet
- receiver 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 processes
Socket programming with TCP
client must contact server
- server process must first be running
- server must have created socket (door) that welcomes
client’s contact client contacts server by:
- Creating TCP socket
- a TCP connection is established between the client and server
- the client socket address (IP address and port number)
- the server socket address (IP address and port number)
when contacted by client, server TCP creates new socket for server process to communicate with that particular client
Chapter 3
Transport services and protocols:
- procvide logical communication between application processes running on different hosts
transport protocols actions in end systems:
- sender: breaks application messages into segments, passes to network layer
- receiver: reassembles segments into messages, passes to application layer
two transport protocols availble TCP, UDP
传输层负责进程间的逻辑通信,网络层负责主机间的逻辑通信
本书中,segment包括传输层数据包和TCP与UDP数据包,datagram包括网络层数据包,但另一些文献中,UDP数据包属于datagram
multiplexing and demultiplexing 复用和解复用
Q:传输层如何知道给哪一个进程消息
sender: multiplexing
handle data from multiple sockets, add transport header (later used for demultiplexing)
receiver: demultiplexing
use header info to deliver received segments to correct socket

demultiplexing work
每个数据报都有源IP地址和目标IP地址,携带一个传输层segment, 每个segment有源port和目标port number
主机将会使用IP地址和端口号将网段导向相应的套接字
Connectionless demultiplexing
创建套接字的时候,必须指定主机本地端口
创建要发送到UDP套接字的数据报的时候,必须指定目标IP地址和目标端口号
具有相同的目的端口号的数据报,无论源IP与源端口号是否相同,都会定向到接收主机的相同套接字
Connection-oriented demux 面向连接的解复用
TCP套接字接口有4元标识
- 源IP
- 源端口
- 目的IP
- 目的端口
解复用即是使用这四个值将数据段引导到适当的套接字接口——不同的源IP和源端口会定向到不同的套接字
❖the exception of a TCP segment carrying the original connection-establishment request
So
服务器主机同时支持多个TCP套接字,每一个可以与不同的客户端连接
网络服务器为每个连接的客户端设置不用的套接字,即,持久HTTP一套,非持久HTTP每个请求一套
Multiplexing, demultiplexing: based on segment, datagram header field values
UDP使用目的端口号进行解复用
TCP使用4元组进行解复用
复用与解复用在每一层都进行
UDP(User Datagram Protocol)
UDP的传输是不加修饰的、可能丢失的、可能顺序错误的、无握手,每个数据报相互独立
Why is there a UDP?
- RTT low(no connection establishment 连接多RTT)
- 简单,双方无连接状态
- small header size TCP 20B UDP 8B
- no congestion control 无拥塞控制,快速传输,拥塞情况可传输
UDP use:
- streaming multimedia apps (loss tolerant, rate sensitive)流媒体,可承受损耗,速率敏感
- DNS
- SNMP
- HTTP/3
if reliable transfer needed over UDP (e.g., HTTP/3):
- add needed reliability at application layer
- add congestion control at application layer
UDP发送端:
- 选定应用层消息message
- 确定UDPsegment header
- 创建UDP网段
- 传递给IP UDP网段
UDP接收端:
- 从IP接收segment
- 检查UDP校验和header
- 提取应用层消息
- 使用套接字将信息解复用至应用程序

UDP checksum
目标:检测传输段中的错误
sender:将segment contents,including header fields 视为一个16位的整数序列
校验和:
- 循环进位累加,【最高位溢出加回最低】
- 结果取反码!
校验和输入UDP校验和字段发给接收方
接收方接收所有的校验和,进行检查计算
- NO 检测到错误
- YES,暂时!未检测到错误
Internet checksum: weak protection!
- 位翻转——不改变校验和
Why checksum in UDP?
- one of the links may use a link-layer protocol that does not provide error checking 不提供错误检查
- bit errors could be introduced when a segment is stored in a router’s memory 存储在路由器中时可能位错误
- provide error checking as a safety measure 安全措施
Note:
- UDP does not do anything to recover from an error 发现错误了也无法恢复哦
- Some implementations of UDP simply discard the damaged segment; others pass the damaged segment with a warning 有的会丢弃损坏,有的会同时传递警告
Principles of reliable data transfer
important in application, transport, link

除非通过信息传递的方式,否则发送方和接收方都互相不知道对方的“状态”——是否接收到了信息?
Reliable data transfer——RDT 可靠数据传输协议:Interface
consider only unidirectional data transfer but control info will flow in both
use finite state machines (FSM, 有限状态机) to specify sender,receiver
- when in this “state” ,next state uniquely determined by next event
- event causing state transition actions taken on state transition
RDT | 新增改进 | 遗憾 |
RDT1.0 | 基础版 | 啥也没解决啊亲 |
RDT2.0 | 接收端通过ACK与NAK告知错误与否 | ACK和NAK也会出错的,重传冗余、遗失 |
RDT2.1 | 数据包增加编号 | ㅤ |
RDT2.1plus | 编号只需要0和1 | 接受方不知道发送方收没收到,发送方需要检查 |
RDT2.2 | 不发送NAK,发送收到的最后一个ACK | 其实哪哪都会出错的,包括基础渠道 |
RDT3.0 | 加入等待时间,超出重发 | 性能太低了 |
RDT3.0pipeline | 流水线发送数据包 | ㅤ |
ㅤ | ㅤ | ㅤ |
RDT1.0
基本渠道完全可靠,无误差,无数据包丢失
separate FSMs for sendrs and receivers 发送方和接受方有独立的FSM,均通过底层通道发送读取
RDT2.0
该通道可能会有位错误,如翻转bit
从错误中恢复:
- ACK确认:接收方告知收到
- NAK负确认:接受发告知有错误,发送方收到后重传
sender sends one packet and then waits for reponse


如果ACK/NAK出错呢?
发送方不知道接收方怎么样了,可能会重传数据包,会导致冗余或者一致,可能无法判断
所以,发送方给每一个数据包增加编号(senquence number),达成丢弃重复,避免冗余避免丢失


RDT2.1 只需要seq0和seq1
这一个,那一个,够用了
但此时,接收方并不知道自己的消息发送方是否接收到,且发送方必须检查接收到的ACK/NAK是否损坏
RDT2.2 无NAK协议
接收方不发送NAK,就收到的最后一个数据包发送ACK,同时,接受方必须明确包含被ACK的数据包序列号,发送方必须通过收到的ACK检查数据包序列号


RDT3.0 有误差和损耗的信道
基础的渠道也可能会丢失数据包or传输的信息
在发送方中加入等待的时间,在此期间收到ACK,无事发生;没有收到ACK,重传;ACK只是延迟,是重复的重传,没事,接收者会指定收到的ACK;真的丢了,也传输了一个


U sender: utilization – fraction of time sender busy sending
忙于发送的时间分数 =发送时间/总时间,总时间=发送时间+RTT
RTT应为总传播延时
基础情况下,等待接收方返回信号后再发下一个数据包,性能太差
RDT3.0 流水线协议操作
流水线协议允许多个再传输过程中的待确认数据包:
- 需要增加序号列范围
- 需要在某一端进行缓冲
流水线协议有两种,GBN and SR
Go-back-N:
sender can have up to N unack’ed packets in pipeline ▪
receiver only sends cumulative ack
- doesn’t ack packet if there’ s a gap
sender has timer for oldest unacked packet
- when timer expires, retransmit all unacked packets
GBN传输的时候,发送方首先会受到窗口数限制,等待接受方的ACK包,接收方始终发送最晚接收到的包的ACK(可能重复),且不保留失序的包的信息,没接到预期编号ACK超时后从这里开始全部重发
问题:
如果窗口、带宽延迟比较大,就需要重新传输大量包
Selective Repeat:
sender can have up to N unack’ed packets in pipeline ▪
rcvr sends individual ack for each packet
sender maintains timer for each unacked packet
- when timer expires, retransmit only that unacked packet
SR在接到失序的包时会缓存,返回该编号ACK,发送端未收到某ACK后重发,接收端收到后会接受其与之后连续缓存的所有包,返回该ACK
窗口大小小于等于序列大小/2
可靠的数据传输机制
- 校验和
- ACK
- NACK
- 序列号
- 定时器
- Window pipeline
TCP Connection

.png?table=block&id=20fac750-c456-803c-9b91-d1f0f339edb6&t=20fac750-c456-803c-9b91-d1f0f339edb6)
Question: How receiver handles out-of-order segments? Answer:
- (1) TCP spec doesn’t say, - up to implementor;
- (2)keeps out-of-order bytes and waits for missing bytes to fill in the gaps (in practice)
.png?table=block&id=20fac750-c456-8038-b633-f08c295b323b&t=20fac750-c456-8038-b633-f08c295b323b)
TCP连接与TCP拥塞控制
等待更新…………
上一篇
Python学习(一)
下一篇
操作系统
Loading...