8/11《Linux高性能服务器编程》学习

TCP/IP协议族

是因特网使用的主流协议族,是一个分层的多协议的通信体系。

体系结构

四层:
数据链路层:ARP、data-link、RARP
(socket在中间)
网络层:ICMP、IP
传输层:TCP、UDP
应用层:telnet、OSPF、DNS

1数据链路层

the link layer
All these requirements led to the choice of a packet-switching network based on a connectionless layer that runs across different networks. The lowest layer in the model, the link layer describes what links such as serial lines(串行线) and classic Ethernet must do to meet the needs of this connectionless internet layer. It is not really a layer at all, in the normal sense of the term, but rather an interface between hosts and transmission links.(主机和传输线路之间的接口)

实现了网卡接口的网络驱动程序,以处理数据在不同物理媒介上的传输,为上层协议提供统一接口。
常用协议:地址解析协议ARP(Address Resolve Protocol)RARP 逆地址解析协议
实现的是IP地址和机器物理地址(通常是MAC地址)之间的相互转换。 RARP仅用于无盘工作站。

2网络层

the internet layer
它大致相当于OSI网络层。它的工作是允许主机将数据包注入任何网络,并让它们独立地传输到目的地(可能是在不同的网络上)。IP(互联网协议),加上一个称为ICMP(互联网控制消息协议)的伙伴协议,帮助它运行。
The job of the internet layer is to deliver IP packets where they are supposed to go. Packet routing is clearly a major issue here, as is congestion(though IP has not proven effective at avoiding congestion).

实现数据包的选路和转发
对上层协议隐藏了网络拓扑连接的细节,使得在传输层和网络应用程序看来,通信的双方是直接连接的。

IP协议
ICMP协议:差错控制;查询

ICMP并非严格意义的网络层协议,它要使用同一层的IP协议提供的服务。

3传输层

the transport layer
It is designed to allow peer entities on the source and destination hosts to carry on a conversation, just as in the OSI transport layer. Two end-to-end transport protocols have been defined here.

  1. The first one, TCP (Transmission Control Protocol), is a 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. It segments(分段) the incoming byte stream into discrete messages and passes each one on to the internet layer. At the destination, the receiving TCP process reassembles the received messages into the output stream. TCP also handles flow control to make sure a fast sender cannot swamp a slow receiver with more messages than it can handle.
  2. The second protocol in this layer, UDP (User Datagram Protocol), is an unreliable, connectionless protocol for applications that do not want TCP’s sequencing or flow control and wish to provide their own. It is also widely used for one-shot(一次性的), client-server-type request-reply queries(客户机——服务器类型的请求-应答查询) and applications in which prompt delivery(即时传输) is more important than accurate delivery(精确传递), such as transmitting speech or video.

为两台主机的应用程序提供端到端服务
传输层只关心通信的起始端目的端,不在乎数据包的中转过程。

主要协议:TCP协议、UDP协议、SCTP协议

TCP transmission control Protocol 传输控制协议

提供可靠的、面向连接的和基于流的服务。TCP协议使用超时重传、数据确认等方式来确保数据包被正确发送至目的端,因此TCP协议是可靠的。
基于流的数据没有边界限制,它源源不断地从通信的一端流入另一端。发送端可以逐个字节地向数据流中写入数据,接收端也可以逐个字节地将它们读出。

UDP user datagram protocol 用户数据报协议

为应用层提供不可靠、无连接、基于数据报的服务。
“不可靠”意味着UDP协议无法保证数据从发送端正确地传送到目的端。使用UDP协议的应用程序需要自己处理数据确认、超时重传等逻辑。UDP是无连接的,每次发送数据都要明确指定接收端的地址。
基于数据报的服务,相对于基于流。每个UDP数据报都有一个长度,接收端必须以该长度为最小单位将所有内容一次性读出,否则数据将被截断。

4应用层

the application layer

负责处理应用程序的逻辑
数据链路层、网络层、传输层负责处理网络通信细节,需要保证稳定高效,因此它们在内核空间实现。
应用层在用户空间实现,其负责的逻辑过于众多:文件传输、名称查询、网络管理等。

ping是应用程序,利用ICMP报文检测网络连接
telnet协议:一种远程登录协议,使我们能在本地完成远程任务
OSPF open shortest path first 开放最短路径优先 是一种动态路由更新协议,用于路由器之间的通信,以告知对方各自的路由信息
DNS domain name service 域名服务 提供机器域名到IP地址的转换

应用层协议可能直接使用网络层提供的服务,如ping程序和OSPF协议。应用层协议通常可以使用TCP服务,又可以使用UDP服务,如DNS。

模型comparison
层数OSITCP/IP
7ApplicationApplication
6Presentation
5Session
4TransportTransport
3NetworkInternet
2Data linkLink
1Pytsical
封装

应用程序数据在发送到物理网络之前,沿着协议栈从上往下依次传递。每层协议都在上层的数据基础上加上自己的头部信息(有时有尾部信息),实现该层的功能。

UDP不用为应用层数据保存副本,当其数据报发送之后,内核缓冲区中的该数据报就被丢弃。如果要重发,要重新从用户空间将该数据报拷贝到UDP内核发送缓冲区。

在以太网上传输的是以太网帧 Ethernet frame
在令牌环网络上传输的是令牌环帧 token ring frame

MTU max transmit unit 帧最大传输单元 即帧最多能携带多少上层协议数据(比如IP数据报),通常受到网络类型的限制。以太网帧的MTU是1500字节。

分用

帧到达目的主机时,沿着协议栈自底向上依次传输。各层协议依次处理帧中本层负责的头部数据,以获取所需的信息,并最终将处理后的帧交给目标应用程序。这个过程叫做分用(demultiplexing)。分用依靠头部信息中的类型字段实现。

TCP报文段和UDP数据报都通过其头部16位的端口号字段来区分上层应用程序。比如DNS协议对应的端口号是53,HTTP协议对应的端口号是80.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值