计算机网络第一章
每日一言
Gilbert, I know everything about you… because we are connected by an extremely deep bond. No matter how far apart we are, we will surely return to the same place. Because that is our fate! – Vincent Nightray
from Pandora Hearts
计算机网络的定义
- 定义:
A collection of autonomous(自主的) computers interconnected by a single technology.
一组自主的计算机通过单一技术相互连接 - 组成:
Computers/Hosts(主机)/End Systems(端系统)
Communication Links
通讯连接Switches(交换机)/Routers(路由器)
分布式系统 vs 计算机网络
分布式系统
A collection of independent computers appears to its users as a single coherent(凝聚的) system
分布式系统的目标是为用户和应用程序提供一个统一的、透明的计算和处理环境,使得多个节点能够协同工作,共同完成复杂的任务,如大规模数据处理、分布式计算等,让用户感觉像是在使用一个单一的系统。
计算机网络
主要目标是实现不同计算机之间的通信和数据传输,使计算机之间能够交换信息、共享资源,如文件共享、打印机共享等。
分布式系统在计算机网络之上,依赖于计算机网络。
计算机网络的模式
Client-Server Model 客户端服务器模型
A network with two clients and one server
客户端与服务端信息交互流程:
Home Applications 家庭网络应用
一种典型的peer-to -peer model 简称P2P模型
P2P(peer - to - peer)传输模式即点对点传输模式,是一种去中心化的网络传输模式。
计算机网络的分类
Classified by Transmission Technology (传输技术)
Broadcast networks(广播网络)
Sending a packet to all destinations, each machine checks the address field。
通信信道被网络上所有机器共享,任何一台机器发出的数据包能被所有其他机器收到。
- 如果数据包是为接收机器准备的,则该机器会处理数据包
- 如果数据包是为其他机器准备的,它只是被忽略。
Point-to-point networks(点到点网络)
点到点链路:只有一个发送方和接收方
To go from the source to the destination, a packet may visit one or more intermediate(中间的)machines (Often multiple routes are possible, finding good ones is important)
为了从源到目的地,一个数据包可能会访问一个或多个中间的机器(通常可以有多个路由,找到好的路由很重要)
Classified by Scale(规模)
personal area network (个域网PAN) -> Local area network (局域网LAN)-> Metropolitan area network (城域网MAN) ->Wide area network(广域网WAN) -> The Internet(英特网)
LAN Topology 局域网网络拓扑
BUS 总线型
特点:
- 所有计算机都通过一条共享电缆(总线)直接相连
- 如果一个结点出现故障,不会影响网络本身
- 成本低
- 总线坏了会导致网络故障
- 同一时刻只有一个节点可以发送数据,否则会发送碰撞
Ring 环线型
特点:
- 节点与节点相连。
- 所有数据从一个节点传输到另一个节点,直至到达目的地。
- 单一链路中断会导致网络故障。
- 每个节点也是一个中继器,用于放大信号。
Star 星型类
特点:
- 所有计算机都直接与一个中央组件(集线器或交换机)相连。
All computers are connected directly with a central component (Hub or Switch)
- 中央组件出现故障会导致网络本身瘫痪。
Failure of the central component leads to a failure of the network itself
- 某一台计算机出现故障不会导致网络本身瘫痪。
Failure of a computer do not cause a failure of the network itself
Classified by Location(网络位置)
Access Network 接入网
各种异构网络通过边缘路由器(edge router)接入。
Core Networks 核心网
核网络的主要功能是:路由和转发 Routing and Forwarding
路由:利用路由算法来确定数据包从源端到目的端所经过的路径,为数据传输规划合适的路线。
转发:类似 “交换” 操作,根据路由算法生成的本地转发表,将到达路由器输入链路的数据包,转移到合适的输出链路,实现数据包的接力传输。
Packet Switching 分组交换
Unit
(单位):packet
(包)Store and forward
存储转发packet header contains address(distination address and source address)
每个包中都含有包的目的地址和源地址- 每个分组在互联网中独立地选择传输路径, 支持灵活的统计多路复用
Store-and-forward 存储转发
- Packet transmission delay 数据分组传输延迟
takes L/R seconds to transmit (push out) L-bit packet into link at R bps - Store and forward
Entire(全部的) packet must arrive at router before it can be transmitted on next link
Circuit Switching (电路交换)
电路交换是一种在通信双方之间建立一条专用的物理通信路径(电路)的通信方式,就像传统电话网络那样 。在通信开始前,先通过呼叫建立连接,分配端到端的资源,包括链路带宽资源和交换机的交换能力等,这些资源在通信过程中被独占,不会与其他通信共享。
network architecture 分层结构和网络协议
为什么要分层
通过分层降低设计复杂性,每一层向更高层提供一些服务,但是会向高层隐藏这些层所提供服务的具体实现细节。
“分层”可将庞大而复杂的问题,转化为若干较小的局部问题,而较小的局部问题就比较易于研究和处理。
- Protocol(协议):
- An agreement between the communicating parties on how communication is to proceed.
- define the format,order of messages sent and received among network entities,and actiones taken on message transmission,receipt.定义网络实体之间发送和接收消息的格式、顺序,以及在消息传输、接收时采取的行动。
- Protocol Stack(协议栈): A list of protocols used by a certain system
- Peers(对等实体):
- The entities(实体) comprising(包含) the corresponding layers on different machines.包含不同机器上对应层的实体。
- The peers may be processes,hardware machines
- Interface(接口): Defines which primitive(原始的) operations and services the lower layer makes available to the upper one.定义下层向上层提供哪些基本操作和服务。
- Network architecture(网络体系结构):
- A set of layers and protocols(一组层和协议)
- Neither the details of the implementation nor the specification of the interfaces is part of the architecture
Information flow(信息流)
五层协议信息流传输示例:
- 第五层的应用进程生成消息 M 并交给第四层传输。
- 第四层在消息前添加头部信息(包含控制信息如序列号等),然后将结果传递给第三层 。
- 第三层由于协议对消息大小有限制,会将收到的消息拆分成更小的单元(数据包),为每个数据包添加第三层头部,并决定使用哪条输出线路,将数据包传递给第二层。
- 第二层会为每个数据单元添加头部和尾部,再将结果交给第一层进行物理传输。
每一层协议都会对数据包进行封装(Encapsulation),除了最高层负责产生消息,并不封住
考点复习:
Services(服务)
- Connection - Oriented(面向连接) :类似于打电话,在数据传输之前,需要在发送端和接收端之间建立一条逻辑连接。比如 TCP(传输控制协议),先通过 “三次握手” 建立连接,传输过程中对数据进行排序、确认和重传等操作以保证数据可靠传输,传输结束后通过 “四次挥手” 释放连接。这种方式适合对数据准确性要求高的场景,如文件传输、网页浏览等。
强调三个阶段:
- 建立连接
- 传输数据
- 释放连接
- Connectionless(无连接) :类似寄信,发送端无需事先与接收端建立连接,直接将数据报发送出去,每个数据报独立选择路由。像 UDP(用户数据报协议),它不保证数据一定能到达、不进行排序和重传,传输效率高但可靠性低。常用于对实时性要求高、少量数据传输的场景,如视频流、音频流传输和 DNS 查询等 。
只有一个阶段:
- 传输数据
Service provider and service user (服务提供者和服务用户)
The entities(实体) in layer n implement(执行) a service used by layer n+1, layer n is called the services provider, layer n+1 is called service user
SAP:service access point 服务访问点
Layer n SAPs are the places where layer n+1 can access the services offered。第n层SAP是第n+1层可以访问所提供服务的地方
PDU:Protocol Data Unit(协议数据单元)
Information exchanged between two peers。两个对等点之间交换的信息
Service Primitives(服务原语)
在计算机网络中,服务原语(Service Primitive)是上层实体(如应用程序)使用下层提供的服务时的一种抽象指令,用于定义服务用户和服务提供者之间的交互。
If the protocol stack is located in the operating system, the primitives are normally system calls(系统调用)
系统调用:由操作系统提供给用户的应用编程接口(API)
五个基础的服务原语:
总结
- service
- Defines what operations the layer is prepared to perform on behalf of its users, but it says nothing at all about how these operations are implemented
- 关键点:定义哪些服务可以被上层调用、隐藏所有实现方法
- Relates to an interface between two layers, with the lower layer being the service provider and the upper layer being the service user
- 较低层是服务提供者,较高层是服务用户
- Defines what operations the layer is prepared to perform on behalf of its users, but it says nothing at all about how these operations are implemented
- Protocol
- A set of rules governing the format and meaning of the messages that are exchanged by the peer entities
- 关键点:是对等实体间传递消息的格式和含义的规则
- Entities use protocols to implement their service definitions
- 关键点:服务是通过协议实现的
- Service and protocol are completely decoupled 解耦
- A set of rules governing the format and meaning of the messages that are exchanged by the peer entities
- 服务和协议的关系:
- 协议是水平的,服务是垂直的
- 实体使用协议来实现其定义的服务
- 上层实体通过接口使用下层实体的服务
Reference Models(网络参考模型)
- OSI参考模型:法律上的国际标准
- TCP/IP参考模型:最广泛应用的模型
该部分为考点:
- 需要知道每个模型有几层
- 需要知道每层的作用是什么
Open Systems Interconnection (OSI参考模型)
Physical Layer 物理层
Transmitting raw bits over a communication channel
通过通信信道传输原始比特
determined:
how many volts() should be used to represent a 1 and how many for a 0
应该分别用多少伏特代表1和0。how many nanoseconds a bit lasts
一位维持多少纳秒- whether transmission may proceed simultaneously in both directions 是否是全双工
how the initial connection is established and how it is torn down when both sides are finished
初始连接是如何建立的,以及当双方都完成时它是如何被断开的。
Data Link Layer 数据链路层
Transform a raw transmission facility(设施) into a logic channel
将原始传输设施转换为逻辑通道
范围:point-to-point : the protocols are between each machine and its immediate neighbors
. 该协议只作用于直接相邻的机器之间。
作用:
- Framing(成帧):
Sender break up the input data into data frames and transmit the frames
发送者将输入数据分解为数据帧并传输帧 - Error detection and correction(差错检测):
If the service is reliable, the receiver confirms correct receipt of each frame by sending back an acknowledgement frame.
如果是可靠性服务,接收方会通过发送确认帧来确认正确接收了每一帧。 - Flow control(流量控制):
Keep a fast transmitter from drowning a slow receiver in data.
防止快速发送器淹没数据中的慢速接收器 - Broadcast networks(广播网络):
how to control access to the shared channel
如何控制对于共享通道的访问
Network Layer 网络层
Control opeartion of subnets
控制子网的操作
作用:
- Forwarding(转发)
- Routing(路由):How packets are routed from source to destination (route table)
- Congestion control(拥塞控制)
- QoS(Quality of service 服务质量)
- Heterogeneous networks interconnection (异构网络互联)
- For broadcast networks, routing is simple 路由对于广播网络来说很简单
Transport Layer 传输层
传输层为终端用户提供端到端(end_to_end)的数据传输控制,作用域具体到主机上的进程(process)。
Accept data from above,split it up into smaller units if need be ,pass these to the network layer,and ensure that the pieces all arrive currently at the other end
接受来自上层的数据,如果需要的话将其拆分成较小的单元,把这些单元传递给网络层,并确保所有的这些部分都能正确地到达另一端(传输的目标设备)。
作用:
Determines what type of service(reliable or unreliable) to provide to the session layer
确定向会话层提供何种服务(可靠服务还是不可靠服务)an error-free end-to-end channel
无错误的端到端通道transporting of isolated messages,with no guarantee about the order of delivery
独立消息的传输,无法保证传递的顺序broadcasting of messages to multiple destinations
向多个目的地广播消息
Session Layer 会话层
Allows users on different machines to establish sessions.
允许不同机器上的用户建立会话连接。
Dialog control
会话控制- keeping track of whose turn it is to transmit 记录轮到谁进行传输
- Token management 令牌管理
preventing two parties from attempting the same critical operation at the same time
阻止双方同时尝试相同的关键操作
- Synchronization(同步)
checkpointing long transmissions to allow them to continue from where they were after a crash
对长传输进行检查点设置,以便在发生崩溃后能够从它们中断的地方继续进行。
Presentation Layer表示层
The syntax(语法) and semantics(语义) of the information transmitted
传输信息的语法和语义
the data structures to be exchanged can be defined in an abstract way
待交换的数据结构可以以抽象的方式进行定义。- Data encryption 数据加密
- Data compression 数据压缩
Application Layer 应用层
Avariety of protocols that are commonly needed by users. HTTP,File transfer,Electronic mail.....
.种用户通常需要的协议。包括 HTTP(超文本传输协议,用于在网络上传输网页等超文本内容)、文件传输协议(用于在不同设备之间传输文件)、电子邮件协议(用于发送和接收电子邮件)等等。
TCP/IP reference model
Internet layer
A packet-switching(分组交换) network based on a connectionless(无连接的) internetwork layer
这是一个基于无连接网络层的分组交换网络。Defines an official packet format and protocol called
定义了一种名为 IP(互联网协议)的官方数据包格式和协议The job of the internet layers is to deliver IP packets where they are supposed to go
联网层的工作是将 IP 数据包传送到它们应该去的地方。- Packet routing
- Avoiding congestion(拥堵)
Transport layer :TCP
TCP(Transmission Control Protocol)
- Reliable connection-oriented protocol that allows a byte stream originating on one machine to be delivered without error on any other machine in the internet
Fragments(碎片) incoming byte stream into discrete(离散的) messages,reassembles(组装) the received messages into the output stream
将传入的字节流分割成离散的消息,再将接收到的消息重新组装成输出流。Flow control to make sure a fast sender cannot swamp a slow receiver with more messa
ges than it can handle 流量控制是为了确保快速发送方不会用过多的消息淹没慢速接收方,使其无法处理这么多的消息。
Transport layer :UDP
UDP: User Datagram Protocol
- Unreliable ,connectionless protocol
For applications that do not want TCP's sequencing(排序) or flow control(流量控制) and wish to provide their own
对于那些不想要 TCP 的排序或流控制并且希望提供自己的(机制)的应用程序。For applications in which prompt delivery is more imporant than accurate delivery, such as transmitting speech or video, DNS
对于在其中快速交付比准确交付更为重要的应用程序,例如传输语音或视频,域名系统(DNS)。
网络中的计量单位
存储常用的单位:Byte (字节) 1MB = $2^{10}$B
传输速率常用单位:Bit (比特)1Mbps = $2^{10}$ b
而 1 B = 8 b
传输速率
影响:
- bandwidth : 带宽
- link capacity : 信道容量
表示单位时间内网络中的某信道所能通过的最高传输速率,单位为bit/s, 比特每秒
时延(delay / latency)
时延是指数据从网络的一端传送到另一端所需的时间,也成为延迟。
组成:
- 传输时延(transmission delay):数据从结点进入到传输媒体所需要的时间,传输时延又称为发送时延
- 传播时延(propagation delay):电磁波在信道中需要传播一定的距离而花费的时间
- 处理时延(processing delay):主机或路由器在收到分组时,为处理分组所花费的时间
- 排队时延(queueing delay):分组在路由器输入输出队列中排队等待处理所经历的时延
注意:对于高速网络链路,提高的仅仅是数据的发送速率,而不是降低了比特在链路上的传播时延。
在高速/高带宽的链路上,有可能减少传输时延,因为数据进入信道的速度更快了,但是传播时延由信号在介质中的传播速度(物理速度)决定
往返时延RTT(Round-Trip Time)
从发送方发送数据开始,到发送方收到来自接收方的确认,经历的总时间。
时延带宽积(BDP)
Bandwidth-delay product (时延带宽积):$传播时延* 带宽$