OSI protocol

OSI protocol

Nature of the Internet is a series of network protocols, this protocol is called OSI protocol (a series of agreements), according to different functions, different division of labor, hierarchical seven man-made. In fact, this seven-story does not exist. This concept is not seven, but artificial division only. Distinguish purpose is to let you know which one is used to do.

Each layer running different protocols. Protocol is doing, it is the standard protocol.

In fact there are people to draw it into a five-story, four.

It is divided into seven layers: an application layer, layer, session layer, transport layer, network layer, data link layer, physical layer representation.

It is divided into five layers: an application layer, transport layer, network layer, data link layer, physical layer.

It is divided into four layers: the application layer, transport layer, network layer, network interface layer.

151- vernacular OSI seven layer protocol - seven agreements .jpg

Each run common physical device

151- vernacular OSI seven layer protocol - physical devices .jpg

Physical Layer

Physical layer functions: main transmitting low voltage (electric signal) based on the electrical characteristics, a high voltage corresponding to the number 1, a low voltage corresponding to the digital 0

The physical layer interpreted literally: the physical transfer of hardware, the physical properties. In Shenzhen, Beijing chat with your friends, your computer must be able to access, what is the physical embodiment of that? Is not connected to a network cable, plug a router, Beijing friends over there are not also have network cable, you have to insert a router. That is the communication between the computer and the computer must be in communication with the underlying physical layer aspects, you would like to call, the intermediate is not necessary that even a telephone line.

The physical link may be an intermediate fiber optic cable, cable, twisted pair, radio waves. Intermediate mass is an electrical signal, namely 010101 ... these bits.

151- vernacular OSI seven layer protocol - Physical layer .jpg

The underlying transport 010 010 101 001 ... these bits how to make more sense of it?

151- vernacular OSI seven layer protocol - Physical layer 1.jpg

010010101001 ... make these interesting, artificial packet easy to do, a set of eight, according to the transmitting and receiving are divided in groups of eight. Receiving a set of 8 bits, then the computation can be done in accordance with the 8 digits. If there are no packets, the other received a computer simply do not know where to start to do the calculation, but also parses the data can not be received. I made a 16 on you to do it in 16-bit computing? I made 100 100 You do the calculation in accordance with it? Is it does not make sense. So to get the bottom of the electrical signal meaningful, must take the underlying electrical signals do grouping. I do a set of eight, then I received the data, I knew these eight do a group, these eight do a set. Then each 8 you can get a certain number. Group who did live it? The physical layer can not do, the data link layer is dry.

data link layer

数据链路层由来:单纯的电信号0和1没有任何意义,必须规定电信号多少位一组,每组什么意思

数据链路层的功能:定义了电信号的分组方式

以太网协议

早期的时候,
数据链路层就是来对电信号来做分组的。以前每个公司都有自己的分组方式,后来形成了统一的标准,即以太网协议ethernet

ethernet规定:一组电信号构成一个数据报,叫做'帧',每一数据帧分成:报头head和数据data两部分

  • head包含:(固定18个字节)
    • 发送者/源地址,6个字节
    • 接收者/目标地址,6个字节
    • 数据类型,6个字节
  • data包含:(最短46字节,最长1500字节)
- -
head data
  • 数据报的具体内容:head长度+data长度=最短64字节,最长1518字节,超过最大限制就分片发送

这就像写信,发送者的地址(源地址)就是你家的地址,接收者地址(目标地址)就是对方的收信地址,你家的路由器就相当于邮局。其实在计算机通信中的源地址和目标地址指的是Mac地址。

Mac地址

head中包含的源和目标地址由来:ethernet规定接入internet的设备都必须具备网卡,发送端和接收端的地址便是指网卡的地址,即Mac地址

  • Mac地址:每块网卡出厂时都被烧制上一个世界唯一的Mac地址,长度为48位2进制,通常由12位16进制数表示(前六位是厂商编号,后六位是流水线号)

151- vernacular OSI seven layer protocol -Mac card 1.png

151- vernacular OSI seven layer protocol address .jpg -Mac

广播地址

有了Mac地址以后,计算机就可以通信了,假设一个教室就是一个局域网(隔离的网络),这个教室里面有几台计算机,计算机的通信和人的通信是一个道理,把教室里面的人都比作一个个计算机,假设教室里面的人都是瞎子,其实计算机就是瞎子的,计算机通信基本靠吼,现在我要找教室里面的飞哥要战狼2的片,然后我就吼一声,说我要找飞哥要战狼2的片,战狼2的片就属于我的数据,但是我在发的时候我是不是要标识我是谁,我要找谁,我是谁就是我的Mac地址,我要找谁就是飞哥的Mac地址,这两个地址做数据包的头部,再加上数据战狼2的片就构成了一个数据帧。

这个数据包封装好以后就往外发,到物理层以后就全部转成二进制,往外发是怎么发的呢?就是靠吼。即“我是nick,我找飞哥要战狼2的片”。这么吼了一嗓子以后,全屋子的人都能听到,这就是广播。

计算机底层,只要在一个教室里(一个局域网),都是靠广播的方式,吼。

151- vernacular OSI seven layer protocol - Broadcast .jpg

广播出去以后,所有人都听得见,所有人都会拆开这个包,读发送者是谁,接收者是谁,只要接收者不是自己就丢弃掉。对计算机来说,它会看自己的Mac地址,飞哥收到以后,他就会把片发给我,发送回来同样采用广播的方式了,靠吼。

同一个教室(同一个局域网)的计算机靠吼来通信,那不同教室的计算机又如何?

比如说局域网1的pc1与局域网2的pc10如何通信?你在教室1(局域网1)吼,教室2(局域网2)的人肯定是听不见的。这就是跨网络进行通信,数据链路层就解决不了这个问题了,这就得靠网络层出面了。

注意:在讲网络层之前,其实基于广播的这种通信就可以实现全世界通信了,你吼一声,如果全世界是一个局域网,全世界的计算机肯定可以听得见,从理论上似乎行得通,如果全世界的计算机都在吼,你想一想,这是不是一个灾难。因此,全世界不能是一个局域网。于是就有了网络层。

网络层

网络层功能:引入一套新的地址用来区分不同的广播域/子网,这套地址即网络地址

网络层的由来:有了ethernet、Mac地址、广播的发送方式,世界上的计算机就可以彼此通信了,问题是世界范围的互联网是由 一个个彼此隔离的小的局域网组成的,那么如果所有的通信都采用以太网的广播方式,那么一台机器发送的包全世界都会收到

  • 对于上述的问题这就不仅仅是效率低的问题了,这会是一种灾难

151- vernacular OSI seven-layer protocols - Network layer .jpg

为了解决上述灾难,网络层定义了一个IP协议,

你想,我是这个教室的一个学生,我想找隔壁教室一个叫老王的学生,我也不认识老王,那怎么办,我吼?老王在另外一个教室肯定是听不到的。找教室的负责人,这个教室的负责人就负责和隔壁教室的负责人说话,说我们教室的有个学生要找你们教室的老王。往外传的东西交给负责人就可以了,内部的话上面已经提到,通过广播的方式,对外的东西广播失效。教室的负责人就是网关,网关即网络关口的意思。

Mac地址是用来标识你这个教室的某个位置,IP地址是用来标识你在哪个教室(哪个局域网)。你要跨网络发包你是不是要知道对方的IP地址,比如你要访问百度,你肯定得知道百度服务器的IP地址。计算机在发包前,会判断你在哪个教室,对方在哪个教室,如果在一个教室,基于Mac地址的广播发包就OK了;如果不在一个教室,即跨网络发包,那么就会把你的包交给教室负责人(网关)来转发。Mac地址及IP地址唯一标识了你在互联网中的位置。

数据链路层中会把网络层的数据包封装到数数据链路层的数据位置,然后再添加上自己的包头,再发给物理层,物理层发给网关,网关再发给对方教室的网关,对方教室的网关收到后在那个教室做广播。

在数据链路层看,数据封装了两层,跟玩俄罗斯套娃有点类似,一层套了一层。

151- vernacular OSI seven layer protocol - the network layer packet .jpg

最终变成

- - -
以太网头 IP头 IP数据

现在来看另一个问题,在吼之前怎么知道对方的Mac地址?这就得靠ARP协议。

ARP协议的由来:在你找飞哥要片之前,你的先干一件事,想办法知道飞哥的Mac地址。即你的机器必须先发一个ARP包出去,ARP也是靠广播的方式发,ARP发送广播包的方式如下:

- 源Mac 目标Mac 源IP 目标IP 数据部分
发送端主机 发送端Mac FF:FF:FF:FF:FF:FF 172.16.10.10/24 172.16.10.11/24 数据

局域网中怎么获取对方的Mac地址:

肯定要知道对方的IP地址,这是最基本的,就像你要访问百度,肯定得知道百度的域名,域名就是百度的IP地址。自己的IP可以轻松获得,自己的Mac也轻松获取,目标Mac为12个F,我们叫广播地址,表达的意思是我想要获取这个目标IP地址172.16.10.11的机器的Mac地址。Mac为12个F代表的是一种功能,这个功能就是获取对方的Mac地址,计算机的Mac永远不可能是12个F。假设是在本教室广播,一嗓子吼出去了,所有人开始解包,只有IP地址是172.16.10.11的这个人才会返回他的Mac地址,其他人全部丢弃。发回来源Mac改成飞哥自己的Mac地址,同时把飞哥的Mac地址放在数据部分。

跨网络怎么获取对方的Mac地址:

通过IP地址区分,计算机运算判断出飞哥不在同一个教室,目标IP就变成了网关的IP了。网关的IP在计算机上配死了,可以轻松获取。

- 源Mac 目标Mac 源IP 目标IP 数据部分
发送端主机 发送端Mac FF:FF:FF:FF:FF:FF 172.16.10.10/24 172.16.10.11/24 数据
- 源Mac 目标Mac 源IP 目标IP 数据部分
发送端主机 发送端Mac FF:FF:FF:FF:FF:FF 172.16.10.10/24 网关地址 数据
- 源Mac 目标Mac 源IP 目标IP 数据部分
发送端主机 发送端Mac 网关Mac 172.16.10.10/24 飞哥的IP 数据

注意:网关帮你去找飞哥,但对用户来说,由于速度太快我们根本就感觉不到网关的存在。

IP协议详解

规定网络地址的协议叫IP协议,它定义的地址称之为IP地址,广泛采用的v4版本即IPv4,它规定网络地址由32位2进制表示
范围0.0.0.0-255.255.255.255

  • 一个IP地址通常写成四段十进制数,例:172.16.10.1

    IP地址的两部分:

  1. 网络部分:标识子网
  2. 主机部分:标识主机
  • 注意:单纯的IP地址段只是标识了IP地址的种类,从网络部分或主机部分都无法辨识一个IP所处的子网

例:172.16.10.1与172.16.10.2并不能确定二者处于同一子网

子网掩码详解

所谓”子网掩码”,就是表示子网络特征的一个参数。它在形式上等同于IP地址,也是一个32位二进制数字,它的网络部分全部为1,主机部分全部为0。比如,IP地址172.16.10.1,如果已知网络部分是前24位,主机部分是后8位,那么子网络掩码就是11111111.11111111.11111111.00000000,写成十进制就是255.255.255.0。

知道”子网掩码”后,我们就能判断,任意两个IP地址是否处在同一个子网络。方法是将两个IP地址与子网掩码分别进行AND运算(两个数位都为1,运算结果为1,否则为0),然后比较结果是否相同,如果是的话,就表明它们在同一个子网络中,否则就不是。

比如,已知IP地址172.16.10.1和172.16.10.2的子网掩码都是255.255.255.0,请问它们是否在同一个子网络?两者与子网掩码分别进行AND运算

  • 172.16.10.1:10101100.00010000.00001010.000000001
    • 255.255.255.0:11111111.11111111.11111111.00000000
    • AND运算得网络地址结果:10101100.00010000.00001010.000000000->172.16.10.0
  • 172.16.10.2:10101100.00010000.00001010.000000010
    • 255.255.255.0:11111111.11111111.11111111.00000000
    • AND运算得网络地址结果:10101100.00010000.00001010.000000000->172.16.10.0
  • 结果都是172.16.10.0,因此它们在同一个子网络。

总结一下,IP协议的作用主要有两个,一个是为每一台计算机分配IP地址,另一个是确定哪些地址在同一个子网络。

IP数据包详解

IP数据包也分为head和data部分,无须为IP包定义单独的栏位,直接放入以太网包的data部分

  • head:长度为20到60字节
  • data:最长为65,515字节

注意:以太网数据包的"数据"部分,最长只有1500字节。因此,如果IP数据包超过了1500字节,它就需要分割成几个以太网数据包,分开发送了。

- - -
以太网头 IP头 IP数据

有了Mac地址+IP地址,我们就能确定世界上独一无二的一台计算机。

ARP协议详解

arp协议由来:计算机通信基本靠吼,即广播的方式,所有上层的包到最后都要封装上以太网头,然后通过以太网协议发送,在谈及以太网协议时候,我门了解到:通信是基于Mac的广播方式实现,计算机在发包时,获取自身的Mac是容易的,如何获取目标主机的Mac,就需要通过arp协议

arp协议功能:广播的方式发送数据包,获取目标主机的Mac地址

协议工作方式:每台主机IP都是已知的,例如:主机172.16.10.10/24访问172.16.10.11/24

1.首先通过IP地址和子网掩码区分出自己所处的子网

场景 数据包地址
同一子网 目标主机Mac,目标主机IP
不同子网 网关Mac,目标主机IP

2.分析172.16.10.10/24与172.16.10.11/24处于同一网络(如果不是同一网络,那么下表中目标IP为172.16.10.1,通过arp获取的是网关的Mac)

- 源Mac 目标Mac 源IP 目标IP 数据部分
发送端主机 发送端Mac FF:FF:FF:FF:FF:FF 172.16.10.10/24 172.16.10.11/24 数据

3.这个包会以广播的方式在发送端所处的自网内传输,所有主机接收后拆开包,发现目标IP为自己的,就响应,返回自己的Mac

传输层

传输层的由来:网络层的IP帮我们区分子网,以太网层的Mac帮我们找到主机,然后大家使用的都是应用程序,你的电脑上可能同时开启qq,暴风影音,等多个应用程序。

那么我们通过IP和Mac找到了一台特定的主机,如何标识这台主机上的应用程序,答案就是端口,端口即应用程序与网卡关联的编号。

传输层功能:建立端口到端口的通信

补充:端口范围0-65535,0-1023为系统占用端口

  • With the Mac address + IP address + port, we can determine the application on the world's only one computer

TCP protocol

  • Reliable transmission, TCP packet length is not limited, and can be theoretically infinite, but in order to ensure the efficiency of the network, typically the length of the TCP packet does not exceed the length of the IP packet, to ensure that a single TCP packet re-segmentation is not necessary.
- - - -
Ethernet header IP header TCP header data

UDP protocol

  • Unreliable transport, "header" section of only a total of eight bytes, a total length of no more than 65,535 bytes, exactly into an IP packet.
- - - -
Ethernet header IP header UDP header data

TCP packets

151- vernacular OSI seven layer protocol -TCP packets .jpg

TCP three-way handshake and four wave

151- vernacular OSI seven layer protocol -TCP three-way handshake and four waving .jpg

Application layer

The origin of the application layer: the user is using the application, are working at the application layer, is the development of the Internet, everyone can develop their own applications, a variety of data, data must be provided in the form of good organization

Application layer functions: a predetermined data format of the application.

  • Example: TCP protocol data can be transferred to various programs, such as Email, WWW, FTP and the like. So, there must be agreement provides different e-mail, Web pages, FTP data format, these application protocols constitute the "application level."

151- vernacular OSI seven layer protocol - Application Layer .jpg

Note: The data above through several layers of agonizing, has been horrendous.

151- vernacular OSI seven layer protocol - seven data content .jpg

Guess you like

Origin www.cnblogs.com/gaohuayan/p/11084872.html