Interview Summary - computer network portion (1)

1, OSI seven-layer model and TCP / IP five layer model

A, OSI seven layer model
OSI defines a (physical layer, data link layer, network layer, transport layer, session layer, presentation layer, application layer) of the seven network interconnection frame, i.e. ISO open systems interconnection reference model. Each layer to achieve the respective functions and protocols, and an interface for communicating complete adjacent layers. OSI service definition specifies the services provided by each layer. The service is a layer of a layer and its ability to lower layers, which provides a higher level through the interface. These services and services provided by each layer is independent of how to achieve.

The function of each layer is defined
only for OSI layers are roughly elaborated on the function, it does not go into detail, because the actual complexity of each layer is a layer.
The whole process is sent to a commercial quotation Company A and Company B as an example to explain.

<1> Application Layer
of the OSI reference model layer closest to the user, the application provides a user interface to a computer, also provides users with a variety of network services directly. Web services protocols our common application layer are: HTTP, HTTPS, FTP, POP3 , SMTP and so on.
The actual owner of the company A is our users, and commercial quotations him to be sent, is a network application layer services provided, of course, the boss can also choose other services, for example, send a business contract, hair an inquiry, and so on.

<2> represents Layer
The presentation layer provides a variety of coding and conversion functions for application-layer data, a system to ensure that the application layer data can be transmitted to another system to identify the application layer. If necessary, the layer may provide a standard representation for converting the computer's internal data formats into a standard representation used in communication. Data compression and encryption functions are one of the conversion layer may be provided representation.
Because Company A and Company B are companies in different countries, agreed between them unified in English as the language of communication, so in this case the presentation layer (company secretary), is to transfer the application layer of information turn translated into English. Meanwhile, in order to prevent other companies see that people Company A's will do some of this quotation encryption processing. This is the role of representation, the application layer data conversion translation.

<3> Session Layer
The session layer is responsible for establishing, managing, and terminating communication sessions between the layers represent entities. The communication layer by the service requests and responses between the different devices in the application of the composition.
Session layer colleague after colleague to get the converted presentation layer information (session layer colleague of similar companies Liaison), a colleague of the session layer may grasp the Company and many other companies of Information, where the company is the actual transfer process entity. They have to manage the company's contact with the outside world a lot of conversation. After receiving the data presentation layer, session layer will be created and recorded this session, he must first find the address information of company B, then the entire data into an envelope, and wrote the address and contact information. Ready to send data. Company B is determined until after receiving the quotations, even if the session is over, Liaison Department colleagues will terminate the session.

<4> transport layer
transport layer to establish the role of the host end of the link, the transport layer to provide reliable end to end data transmission services and transparent upper layer protocols, the processing comprising error control and flow control problems. The top layer to shield the details of the underlying data communication, so that the user sees only high in a host entity to transfer between two hosts, and control settings by the user, and reliable data path. We usually say, TCP UDP is at this level. Both the port number where "end."
Person in charge of the transport layer is equivalent to express mail company in the transceiver, the company's own couriers, who are responsible for the data to be sent on one delivery to the courier company or post office.

<5> network layer
of this layer is established via IP addressing connection between two nodes, the transport layer is sent source packet, select the appropriate routing and switching node, without error according to a destination address of the transfer of the transport layer . It is often said that the IP layer. This layer is what we often say that the IP protocol layer. IP protocol is the foundation of the Internet.
The network layer is equivalent to a large courier company courier network, different national distribution center, for example, sent to Beijing from Shenzhen SF Express (ah, for example land, air and seems to fly directly to Beijing), first go to SF Shenzhen distribution center, distribution center and then sent to Shenzhen from Wuhan distribution center, distribution center and then sent to Wuhan from Beijing Shunyi distribution center. The distribution center each, equivalent to an IP node in the network.

<6> The data link layer
the bits into bytes, then the byte combination framing, the use of link-layer address (Ethernet MAC address) to access the medium, and performs error detection.
The data link layer is divided into two sublayers: a logical link control sublayer (LLC) sublayer and the media access control (MAC).
The MAC sublayer handles CSMA / CD algorithm, error checking data, framing and the like; LLC. Sublayer defines the last field enables to share a data link layer protocol. In actual use, LLC sublayer is not necessary.
This did not find the right example

The physical layer <7>
transmission of the final signal is actually the physical layer implementation. Bitstream transmitted via the physical medium. The provisions of the level, speed and cable pins. Common equipment (a variety of physical devices) hubs, repeaters, modem, cable, twisted pair, coaxial cable. These layers are the physical transmission medium.
Express delivery during transport, the equivalent of our physical layer, such as cars, trains, airplanes, boats.

OSI communications features: peer to peer communications
peer to peer communications, in order to make the data packets from a source to a destination, the source of each layer of the OSI model must communicate with a peer destination layer, this layer is referred to as peer communication communication. In each layer of the communication process, this layer using its own protocol.

Two, TCP / IP five layer model
TCP / IP five layer and seven-layer OSI protocol correspondence is as follows.

In each layer a different working devices, such as switches on the work we have used in the data link layer, is a common router works at the network layer.

Also in various protocols to achieve each layer, i.e., each layer of different services. The map shows the main protocol of each layer.

2, a common application layer protocol and transport layer, network layer protocols, and hardware such as routers or the like in which layer

Three common application layer protocols: HTTP, FTP, SMTP
transport layer: Transmission Control Protocol TCP, User Datagram Protocol (UDP)
network layer four protocol: the ARP protocol, IP protocol, ICMP protocol, IGMP protocol.

The physical layer to the hub, the switch operates at the data link layer, the router in the network layer.

3, TCP and UDP difference and scenarios, which are based on the TCP protocol, UDP-based What

Difference:
Depending on the needs of the application, the transport layer requires two kinds of different transport protocols, connectionless-oriented TCP and UDP connections. When using TCP transport layer connection-oriented protocol, although the following is unreliable network (only best effort service), then this logic communication channels equivalent to a full duplex channel reliably. When using a connectionless UDP protocol, which is a logical communication channel is still an unreliable channel.

应用场景:
TCP:提供面向连接的服务。在传送数据之前必须先建立连接,数据传送结束后要释放连接。TCP不提供广播或多播服务。由于TCP要提供可靠的、面向连接的传输服务,因此不可避免地增加了许多的开销,如确认、流量控制、计时器以及连接管理等。这不仅使协议数据单元的首部增大很多,还要占用许多的处理机资源。

UDP:在传送数据之前不需要先建立连接。远地主机的传输层在收到UDP数据报后不需要给出任何确认。虽然UDP不提供可靠交付,但在某些情况下UDP却是一种最有效的工作方式。

基于TCP和UDP的协议:
基于TCP的有FTP、Telnet、SMTP、HTTP、POP3与DNS
基于UDP的有TFTP、SNMP与DNS
其中DNS既可以基于TCP,也可以基于UDP。

使用TCP和UDP的应用和应用层协议

TCP和UDP协议比较

4、TCP可靠传输的保证,拥塞控制目和过程

TCP通过下列方式来提供可靠性:

1、应用数据被分割成TCP认为最适合发送的数据块。TCP在三次握手建立连接过程中,会在SYN报文中使用MSS(Maximum Segment Size)选项功能,协商交互双方能够接收的最大段长MSS值。MSS是传输层TCP协议范畴内的概念,顾名思义,其标识TCP能够承载的最大的应用数据段长度,因此,MSS=MTU-20字节TCP报头-20字节IP报头,那么在以太网环境下,MSS值一般就是1500-20-20=1460字节。但是如果主机没有填写这一项,该值的默认大小为536字节。客户端与服务器端分别根据自己发包接口的MTU值计算出相应MSS值,并通过SYN报文告知对方.MSS是控制TCP报文段的大小,发送窗口(TCP中发送方可发送的最大数据)的大小由窗口值和拥塞窗口值共同确定;

2、 TCP将保持它首部和数据的检验和。这是一个端到端的检验和,目的是检测数据在传输过程中的任何变化。如果收到段的检验和有差错,TCP将丢弃这个报文段和不确认收到此报文段。 (校验出包有错,丢弃报文段,不给出响应,TCP发送数据端,超时时会重发数据).

3、超时重传机制:当TCP发出一个数据后,它启动一个定时器,等待目的端确认收到这个报文段。如果不能及时收到一个确认,将重发这个报文段。在未收到确认之前,这些已经发送的数据报将留在发送缓冲区,直到收到确认之后才清除已发送的数据.

4、既然TCP报文段作为IP数据报来传输,而IP数据报的到达可能会失序,因此TCP报文段的到达也可能会失序。如果必要,TCP将对收到的数据进行重新排序,将收到的数据以正确的顺序交给应用层。(对失序数据进行重新排序,然后才交给应用层).如果TCP的接收端必须丢弃重复的数据。(对于重复数据,能够丢弃重复数据)

5、TCP还能提供流量控制。TCP连接的每一方都有固定大小的缓冲空间。TCP的接收端只允许另一端发送接收端缓冲区所能接纳的数据。这将防止较快主机致使较慢主机的缓冲区溢出。(TCP可以进行流量控制,防止较快主机致使较慢主机的缓冲区溢出)。一旦有一方来不及接受数据,势必会造成数据的丢失!!

6.以字节为单位的滑动窗口:

滑动窗口的基本原理可表示如下:

可以看到数据发送方维持了一个大小为20的发送窗口,其中发送前沿向前移动,强烈建议不向后移动,这个时候我们可以看到,当前发送方可以发送的字节序列从31-50为止,现在发送方可以发送的数据为20字节。

A已经发送了从31到41之间的11个字节序,其中32和33已经到达接收方,但31没有按序到达;

此时,B向A发出31的确认(表示31号没有收到),此时窗口值依然为20,因为此时B发送的是对31号的确认,A的发送窗口不能向前移动;随后B收到了31号字节,发送给A一个确认包,这个包的窗口值依然为20(假设窗口值不变),但此时确认号为34,这表明B已经收到了截至33号的所有数据,并把它们交付给了主机,然后将它们删除,B将接收窗口向后挪动3个单位,那么接受范围从34到53;随后,A接收到了B对31-33号数据的接收确认,A将发送窗口向后挪动3个单位,其中p2位置不变,此时代表A可以发送的字节序列为34-53;随后A的p2指针和p3重合,代表已经将所有可以发送的数据全部发送,但是还没有收到确认;

TCP的连接过程可表示为:

所以总结一下这个收发过程就是:
(1)客户端和服务器端各自建立套接字,通过彼此的套接字进行通信;
(2)服务器端绑定监听端口,然后监听,循环等待来自客户端的连接;
(3)一旦收到来自客户端的连接,进行三次握手,一旦连成功就fork()一个子进程来处理和当前客户端的连接,然后父进程继续监听客户端的连接;
(4)此后就是数据传输过程(如上图所示);
(5)一旦数据传输完毕就是放连接;

7.选择确认ACK:
选择确认是针对没有出错但是未按序到达的报文段,如果中间只是缺少一些报文段,那么发送方就可以不重传已发送的所有数据,而只是重传缺少的数据。课本上的具体例子如下:

拥塞控制:
1、产生拥塞的原因:在某段时间,若对网络中某一资源的需求超过了该资源所能提供的可用部分,网络的性能就会变坏。即对资源的需求的总和大于可用资源
注意拥塞控制与流量控制的区别:拥塞控制是防止过多的数据注入网络中,使得网络中路由器或链路不致过载,有一个前提是,网络能够承受现有的网络负荷,是一个全局性过程;流量控制是指点对点通信的控制,做的是抑制发送端发送数据的速率,便于接收端来得及接收。
2、拥塞控制是一个动态的过程,通常使用网络负载(单位时间输入给网络的分组数量)和吞吐量(单位时间从网络输出的分组的数量)来进行比较:
当网络负载大于吞吐量,网络进入拥塞,严重甚至会产生死锁。

二、TCP拥塞控制方法
主要有四种算法:慢开始、拥塞避免、快重传、快恢复。

1、慢开始和拥塞避免
基于窗口的拥塞控制,在发送方维护一个拥塞窗口(cwnd),大小等于发送窗口,通过出现了超时来判断网络出现拥塞。慢开始的思路是一开始发送方发送一个字节,在收到接收方的确认,然后发送的字节数量增大一倍(也就是按照指数增长的速率),从小到大逐步增大cwnd,直到cwnd 达到慢开始门限(ssthresh),停止慢开始算法,使用拥塞避免算法,拥塞避免算法思路是增长速率变为线性增长,也就是每经过一个往返时间RTT就把发送方的cwnd加1,所以综上:
当cwnd < ssthresh ,使用慢开始算法;
当cwnd = ssthresh,可以使用慢开始算法,也可以使用拥塞算法;
当cwnd > ssthresh,使用拥塞算法;

2、快重传和快恢复
通过上面两个算法可以使得网络传输速率一直增大,直到出现超时,这时候需要将cwnd重新调整到1个字节开始,使用慢开始算法,同时需要将慢开始门限ssthresh调整为cwnd(超时点)的一半,继续执行慢开始、拥塞避免算法。如果收到3-ACK(发送方一连接收到3个对同一个报文段的重复确认),这种可能的情况是,并不是发生了拥塞,可能是报文丢失,所以发送方不执行慢开始算法,直接使用快重传算法,立即发送缺失的报文段。同时执行快恢复算法,将门限值(ssthresh)调整为此时cwnd的一半,并执行拥塞避免算法。

三、总结
从宏观上看,在连接建立开始到连接终止这个过程中,TCP传输的速率需要流量控制和拥塞控制,共同调整发送方的窗口,所以最终发送方的发送窗口的上限值为Min(rwnd,cwnd)。而拥塞控制,主要调控发送方的网络负载和吞吐量的相对大小,从慢开始(指数增长,增长率大)、拥塞避免算法(线性增长,增长率不变)一直增大速率,期间算法切换条件是慢开始门限值(ssthresh),若此增大期间出现超时,都需要将ssthresh = cwnd / 2, cwnd = 1(之后执行慢开始算法);若此增大期间出现3-ACK,则ssthresh=cwnd / 2, cwnd = ssthresh(之后执行拥塞避免算法),直至到连接终止结束。

Guess you like

Origin www.cnblogs.com/xjtu-lyh/p/12416763.html