ALevel-CS Chapter 17
Communication and Internet technologies
17.01 Transmission modes
Circuit switching
Circuit switching is the method used in the traditional telephone system.
For data transfer to take place, the following has to happen :
- The sender provides the identity of the intended receiver.
- The system checks whether or not the receiver is ready to accept data.
- If the receiver is available, a sequence of links is established across the network.
- The data is transferred.
- The links are removed.
packet switching technology(包交换)
三种交换的比较
分组交换实现
包交换(分组交换) - 将用户传送的数据划分成一定的长度,每个部分叫做一个分组。每个分组的前面有一个分组头,用以指明该分组发往何地址,然后由交换机根据每个分组的地址标志,将他们转发至目的地,这一过程称为分组交换。
二层交换
2层交换技术可以识别数据帧中的MAC地址信息,根据MAC地址进行转发,并将这些MAC地址与对应的端口,记录在自己内部的一个MAC地址表中。
2层交换机主要用在小型局域网中,机器数量在二、三十台以下,这样的网络环境下,广播包影响不大,2层交换机的快速交换功能、多个接入端口和低廉价格,为小型网络用户提供了完善的解决方案。
二层交换的流程:
- 当交换机从某个端口收到一个数据帧,它先读取包头中的源MAC地址,这样它就知道源MAC地址的机器是连在哪个端口上的;
- 再去读取数据帧头中的目的MAC地址,并在地址表中查找相应的端口;
- 如表中有与这目的MAC地址对应的端口,把数据帧直接复制到这端口上;
- 如表中找不到相应的端口则把数据帧广播到所有端口上,当目的机器对源机器回应时,交换机又可以学习一目的MAC地址与哪个端口对应,在下次传送数据时就不再需要对所有端口进行广播了。 不断的循环这个过程,对于全网的MAC地址信息都可以学习到,二层交换机就是这样建立和维护它自己的地址表。
三层交换
在大规模局域网中,为了减小广播风暴的危害,必须把大型局域网按功能或地域等因素划分成多个小局域网,这样必然导致不同子网间的大量互访,而单纯使用第2层交换技术,却无法实现子网间的互访。
为了从技术上解决这个问题,网络厂商利用第3层交换技术开发了3层交换机,也叫做路由交换机,它是传统交换机与路由器的智能结合。
3层交换机是为IP设计的,接口类型简单,拥有很强的3层包处理能力,价格又比相同速率的路由器低得多,非常适用于大规模局域网络。
七层交换
第7层交换技术通过逐层解开每一个数据包的每层封装,并识别出应用层的信息,以实现对内容的识别。
第7层交换技术通过应用层交换机实现了所有高层网络的功能,使网络管理者能够以更低的成本,更好地分配网络资源。
在Internet网、Intranet网和Extranet网,7层交换机都大有施展抱负的用武之地。比如企业到消费者的电子商务、联机客户支持,人事规划与建设、市场销售自动化,客户服务,防火墙负载均衡,内容过滤和带宽管理等。
互联网分层的好处:上层的变动完全不影响下层的结构
packet switching
The packet-switching method allows data transmission without a circuit being established.
Data cannot be sent in a continuous stream.
Instead data is packaged in portions inside packets.
A packet consists of a header which contains instructions for delivery plus the data body.
there are two ways that the network can provide a service:: connectionless service or connection-oriented service.
connectionless service - a packet is dispatched with no knowledge of whether or not the receiver is ready to accept the packet, and has no way of finding out if the transmission has succeeded.
connection-oriented service - the first packet sent includes a request for an acknowledgement.If the acknowledgement is received, the sender transmits further packets. If no acknowledgement is received, the sender tries again with the first packet.
17.02 Protocols
Key Terms
- Protocol - a set of rules for data transmission which are agreed by sender and receiver
protocols
protocol - it is a set of rules.
The set of rules that constitute a protocol must be agreed between the sender and the receiver for any communication transmitted over a network.
17.03 A Protocol Stack
- Each layer can only accept input from the next higher layer or the next lower layer.
- There is a defined interface between adjacent layers which constitutes the only interaction allowed between layers.
- A layer is serviced by the actions of lower layers.
- With the possible exception of the lowest layer the functioning of a layer is created by installed soft ware.
- A layer may comprise sub-layers.
- Any user interaction will take place using protocols associated with the highest level layer in the stack.
- Any direct access to hardware is confined to the lowest layer in the stack.
协议栈
逐层封装
协议传输
OSI 7层传输
17.04 The TCP/IP protocol suite
TCP/IP 协议栈
TCP/IP 是为使用互联网而开发制定的协议栈
OSI 七层网络协议 - TCP/IP 四层网络协议
TCP/IP的数据包
每个分层中,都会对所发送的数据附加一个首部,在这个首部中包含了该层必要的信息,如发送的目标地址以及协议相关信息。通常,为协议提供的信息为包首部,所要发送的内容为数据。在下一层的角度看,从上一层收到的包全部都被认为是本层的数据。
网络中传输的数据包由两部分组成:一部分是协议所要用到的首部,另一部分是上一层传过来的数据。首部的结构由协议的具体规范详细定义。在数据包的首部,明确标明了协议应该如何读取数据。反过来说,看到首部,也就能够了解该协议必要的信息以及所要处理的数据。包首部就像协议的脸。
数据处理流程
数据处理流程
- 应用程序处理 - 应用程序会进行编码处理,这些编码相当于 OSI 的表示层功能;编码转化后,邮件不一定马上被发送出去,这种何时建立通信连接何时发送数据的管理功能,相当于 OSI 的会话层功能。
- TCP 模块的处理 - TCP 根据应用的指示,负责建立连接、发送数据以及断开连接。TCP 提供将应用层发来的数据顺利发送至对端的可靠传输。为了实现这一功能,需要在应用层数据的前端附加一个 TCP 首部。
- IP 模块的处理 - IP 将 TCP 传过来的 TCP 首部和 TCP 数据合起来当做自己的数据,并在 TCP 首部的前端加上自己的 IP 首部。IP 包生成后,参考路由控制表决定接受此 IP 包的路由或主机。
- 网络接口(以太网驱动)的处理 - 从 IP 传过来的 IP 包对于以太网来说就是数据。给这些数据附加上以太网首部并进行发送处理,生成的以太网数据包将通过物理层传输给接收端。
- 网络接口(以太网驱动)的处理 - 主机收到以太网包后,首先从以太网包首部找到 MAC 地址判断是否为发送给自己的包,若不是则丢弃数据。如果是发送给自己的包,则从以太网包首部中的类型确定数据类型,再传给相应的模块,如 IP、ARP 等。这里的例子则是 IP 。
- IP 模块的处理 - IP 模块接收到 数据后也做类似的处理。从包首部中判断此 IP 地址是否与自己的 IP 地址匹配,如果匹配则根据首部的协议类型将数据发送给对应的模块,如 TCP、UDP。这里的例子则是 TCP。另外吗,对于有路由器的情况,接收端地址往往不是自己的地址,此时,需要借助路由控制表,在调查应该送往的主机或路由器之后再进行转发数据。
- TCP 模块的处理 - 在 TCP 模块中,首先会计算一下校验和,判断数据是否被破坏。然后检查是否在按照序号接收数据。***检查端口号,确定具体的应用程序。数据被完整地接收以后,会传给由端口号识别的应用程序。
- 应用程序的处理 - 接收端应用程序会直接接收发送端发送的数据。通过解析数据,展示相应的内容。
The TCP/IP protocol suite
TCP/IP is the protocol suite underpinning Internet usage.
The TCP/IP suite comprises a number of protocols, including the following::
- application layer:: HTTP, SMTP, DNS, FTP, POP3, IMAP
- transport layer:: TCP, UDP, SCTP
- network layer:: IP, IGMP, ICMP, ARP.
TCP 和 UDP
TCP 是面向连接的、可靠的流协议。流就是指不间断的数据结构,当应用程序采用 TCP 发送消息时,虽然可以保证发送的顺序,但还是犹如没有任何间隔的数据流发送给接收端。TCP 为提供可靠性传输,实行“顺序控制”或“重发控制”机制。此外还具备“流控制(流量控制)”、“拥塞控制”、提高网络利用率等众多功能。
UDP 是不具有可靠性的数据报协议。细微的处理它会交给上层的应用去完成。在 UDP 的情况下,虽然可以确保发送消息的大小,却不能保证消息一定会到达。因此,应用有时会根据自己的需要进行重发处理。
TCP 和 UDP 的优缺点无法简单地、绝对地去做比较:TCP 用于在传输层有必要实现可靠传输的情况;而在一方面,UDP 主要用于那些对高速传输和实时性有较高要求的通信或广播通信。TCP 和 UDP 应该根据应用的目的按需使用。
TCP (Transmission Control Protocol)
The protocol will transmit the user data to the transport layer.
The TCP protocol operating in the transport layer now has to take responsibility for ensuring the safe delivery of the ‘message’ to the receiver.
Each packet consists of a header plus the user data.
one item in the header is the port number which identifies the application layer protocol. The packet must also include the port number for the application layer protocol at the receiving end-system.
The TCP protocol is connection-oriented.
IP 地址
- 在计算机通信中,为了识别通信对端,必须要有一个类似于地址的识别码进行标识。在数据链路中的 MAC 地址正是用来标识同一个链路中不同计算机的一种识别码。
- 作为网络层的 IP ,也有这种地址信息,一般叫做 IP 地址。IP 地址用于在“连接到网络中的所有主机中识别出进行通信的目标地址”。因此,在 TCP/IP 通信中所有主机或路由器必须设定自己的 IP 地址。
- 不论一台主机与哪种数据链路连接,其 IP 地址的形式都保持不变。
- IP 地址(IPv4 地址)由32位正整数来表示。IP 地址在计算机内部以二进制方式被处理。然而,由于我们并不习惯于采用二进制方式,我们将32位的 IP 地址以每8位为一组,分成4组,每组以 “.” 隔开,再将每组数转换成十进制数。
IP地址由网络和主机两部分标识组成
网络标识在数据链路的每个段配置不同的值。网络标识必须保证相互连接的每个段的地址不相重复。而相同段内相连的主机必须有相同的网络地址。IP 地址的“主机标识”则不允许在同一个网段内重复出现。由此,可以通过设置网络地址和主机地址,在相互连接的整个网络中保证每台主机的 IP 地址都不会相互重叠。即 IP 地址具有了唯一性。
IP 包被转发到途中某个路由器时,正是利用目标 IP 地址的网络标识进行路由。因为即使不看主机标识,只要一见到网络标识就能判断出是否为该网段内的主机。
IP (Internet Protocol)
The function of the network layer, and in particular of the IP, is to ensure correct routing over the Internet.
IP protocol takes the packet received from the transport layer and adds a further header. The header contains the IP addresses of both the sender and the receiver.
To find the IP address of the receiver, it is very likely to use the DNS service to find the address corresponding to the URL supplied in the user data.
The IP packet, which is usually called a ‘datagram’, is sent to the data-link layer and therefore to a different protocol suite.
IP functions as a connectionless service.
路由
- 发送数据包时所使用的地址是网络层的地址,即 IP 地址。然而仅仅有 IP 地址还不足以实现将数据包发送到对端目标地址,在数据发送过程中还需要类似于“指明路由器或主机”的信息,以便真正发往目标地址。保存这种信息的就是路由控制表。
- 该路由控制表的形成方式有两种:一种是管理员手动设置,另一种是路由器与其他路由器相互交换信息时自动刷新。前者也叫做静态路由控制,而后者叫做动态路由控制。
- IP 协议始终认为路由表是正确的。然后,IP 本身并没有定义制作路由控制表的协议。即 IP 没有制作路由控制表的机制。该表示由一个叫做“路由协议”的协议制作而成。
IP地址和路由控制
- IP 地址的网络地址部分用于进行路由控制。
- 路由控制表中记录着网络地址与下一步应该发送至路由器的地址。
- 在发送 IP 包时,首先要确定 IP 包首部中的目标地址,再从路由控制表中找到与该地址具有相同网络地址的记录,根据该记录将 IP 包转发给相应的下一个路由器。如果路由控制表中存在多条相同网络地址的记录,就选择一个最为吻合的网络地址。
The router
the frame sent by the data-link layer will arrive at a router during transmission (more likely at several routers).
It is now the function of the router software to choose the next target host in the transmission. The software has access to a routing table appropriate to that router.
The routing table for every router has details of any current problems with any of the options for the next transmission step.
The major distinction between a switch and a router as a node in a network is that when a frame arrives at a switch, it is transmitted on without any routing decision. A switch operates in the data-link layer but has no access to the network layer.
17.05 The Ethernet protocol stack
以太网协议栈
数据链路层包括LLC子层、MAC Control子层(可选)、MAC子层和RS子层。MAC层主要负责控制与连接物理层的物理介质。在发送数据时,MAC协议事先判断是否可以发送数据,如果可以发送,将给数据添加一些控制信息,最终将数据以及控制信息以规定的格式发送到物理层;在接收数据时,MAC协议首先判断输入的信息是否发生传输错误,如果没有错误,则去掉控制信息发送至LLC层。
- LLC - Logical Link Control 逻辑链路控制
- MAC - Media Access Controller 媒介访问控制器
- PCS - Physical Coding Sublayer 物理编码子层
- PMA - Physical Media Attach 物理附加子层
The Ethernet protocol stack
Ethernet is a protocol suite designed for use in a local area network (LAN)
However, it is now almost inevitable that a LAN will be connected to the Internet and, therefore, a LAN’s protocol suite will support the protocol suite in use for the Internet.
TCP/IP protocol suite occupies the top three layers of the five-layer stack and is therefore supported by the lower two layers.
Logically the Ethernet suite can be viewed as comprising two sub-layers for each of the Data link and Physical layers.
The following points explain how Ethernet functions when supporting TCP/IP.
- The Logical Link Control (LCC) protocol is responsible for the interaction with the Network layer. It manages data transmissions and ensures the integrity of data transmissions. However, because Ethernet is a connectionless protocol it has no responsibility for checking that a transmission has been successfully delivered.
- The Medium Access Control (MAC) protocol is responsible for assembling the Ethernet packet which is referred to as a frame. Two components of this are the address of the transmitter and the address of the receiver. In addition the MAC protocol initiates frame transmission and handles recovery from transmission failure due to a collision (possibly using CSMA/CD).
- The Physical Coding Sublayer (PCS) protocol is responsible for coding data ready for transmission or decoding data received. It either receives a frame from the MAC protocol or sends one to it.
- The Physical Medium Attachment (PMA) protocol is responsible for signal transmitting and receiving.
MAC Address
Both addresses in the Ethernet frame are examples of what are called physical or MAC addresses.
A MAC address is the one which uniquely defines one NIC
4A3012241A::10
17.06 Application-layer protocols associated with TCP/IP
HTTP (HyperText Transfer Protocol)
Because HTTP (HyperText Transfer Protocol) underpins the World Wide Web it has to be considered to be the most important application-layer protocol.
HTTP is a transaction-oriented, client–server protocol. The transaction involves the client sending a ‘request’ message and the server sending back a ‘response’ message.
<Method> <URL> <Version>CRLF
where CR and LF are the ASCII carriage return and line feed characters. The request line usually has GET as the method.
Email protocols
SMTP (Simple Mail Transfer Protocol) is a ‘push’ protocol whereas POP3 (Post Office Protocol version 3) is a ‘pull’ protocol.
There is a more recent alternative to POP3, which is IMAP (Internet Message Access Protocol).
The approach using POP3 is for emails to be downloaded onto the client computer. With IMAP the emails are not downloaded; they remain stored on the server but remain accessible from the client.
SMTP has been largely replaced by the use of web-based mail. A browser is used to access the email application, so HTTP is now the protocol used. However, SMTP remains in use for transfer between the mail servers.
FTP (File Transfer Protocol)
FTP (File Transfer Protocol) is the application-layer protocol that can handle any file transfer between two end-systems.
17.07 Peer-to-peer (P2P) file sharing
Peer-to-peer (P2P) file sharing
P2P is an architecture that has no structure and no controlling mechanism. Peers act as both clients and servers and each peer is just one end-system. When a peer acts as a server it is called a ‘seed’.
How does a peer find others that have the wanted content?
Every content provider should provide a content description, called a torrent, which is a file that contains the name of the tracker (a server that leads peers to the content) and a list of the chunks that make up the content. The torrent file is at least three orders of magnitude smaller than the content so can be transferred quickly. The tracker is a server that maintains a list of all the other peers (the ‘swarm’) actively downloading and uploading the content.
How do peers replicate content to provide high-speed downloads for everyone?
Peers download and upload chunks at the same time, but peers have to exchange lists of chunks and aim to download rare chunks for preference. Each time a rare chunk is downloaded it automatically becomes less rare!
How do peers encourage other peers to provide content rather just using the protocol to download for themselves?
This requires dealing with the free-riders or ‘leechers’ who only download. The solution is for a peer to initially randomly try other peers but then to only continue to upload to those peers that provide regular downloads. If a peer is not downloading or only downloading slowly, the peer will eventually be isolated or ‘choked’.