python-- network protocol (OSI seven layer protocol)

A nature of the Internet

We will not speak of the Internet is how to communicate (send data, files, etc.), first with a classic example for everyone to say what is the Internet communications.

Now dating back to the eighties and nineties, when the phone is just emerging, there is no concept of mobile phones, but wired telephone, then the time if you call to people in the field, how should you do?

First you have to make sure that the two of you have a bunch of landline connection medium connection (telephone lines, converters, etc.) we collectively physical connection media.

Second, you want to dial, lock the other side of the phone.

Finally, the call began.

Calls are learned, then that's not the promotion of Putonghua, so if you call people and Henan, Henan, then you have to say.

If you call people and northeast, northeast, then you have to say.

And Shanghai if you contact the person who you talk in Shanghai dialect.

If you wanted to have in Guangxi, Inner Mongolia, Tangshan, Shandong and so much friends, if you call whether must learn the local dialect to communicate it?

Not really, but we promote Mandarin, so long as everyone will speak Mandarin, so that you can establish good communication.

If that is the Trump and Putin on the phone it?

Then you have to learn the language of each country it? No! No! No! Let now the lingua franca of international exchanges is English, in fact, I learned to speak English, you can communicate with people in the various countries. These two examples illustrate what? It explained to uniform standards, follow a standard, then it can establish good communication.

Communication with two people called principle between the two computers is the same.

  1, first connector connected by various physical media.

  2, to accurately determine the other computer (accurate to software) position.

  3, transmits and receives data through a unified standard (protocol package).

Physical connection media, this is a network engineer considered the back will give you a brief talked about, we mainly learn this unified standard.

English has become the standard for all unified communications world, as if the computer people located around the world, then the internet connection between two computers is actually

A series of uniform standards, which is called Internet Protocol, the nature of the Internet is a series of agreements, collectively called 'Internet Protocol' (Internet Protocol Suite).

Internet Protocol functions: how to define the computer access internet, and the computer communication standard of internet access.

 

OSI seven layer protocol

 

 

 

 

 

 

.1 physical layer

The origin of the physical layer: the above-mentioned, in order to play with isolation between the computer, you must access internet, implying that must be completed between the computer network

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

 Fiber: Twisted Pair:

         

2.2 Data Link Layer

The origin of the data link layer: a simple electrical signals 0 and 1 does not make any sense, must provide an electrical signal how many bits a groups of what it means

The data link layer: Defines the electric signal grouping

Ethernet protocols:

Early on each company has its own grouping, and later formed a unified standard that Ethernet protocol ethernet

ethernet provisions

  • A set of electrical signals constitute a data leopard, called 'frame'
  • Each data frame is divided into: a header and a data head data of two parts
       head                                data                             

 

 

fixing head comprising :( 18 bytes)

  • Sender / source address of 6 bytes
  • Recipient / destination address, six bytes
  • Data type, six bytes

46 byte data comprising :( minimum, maximum 1500 bytes)

  • Specific contents of the packet

head shortest length + data length = 64 bytes, 1518 bytes maximum, exceeds the maximum limit fragment transmission

mac address:

Source and destination addresses contained in the head Origin: ethernet predetermined internet access devices must have the card, the transmission and receiver means is address card address, i.e. the address mac

mac address: each NIC are fired on a world unique mac address, a length of 48 binary factory, generally indicated by 12 hexadecimal numbers (the first six numbers is the vendor, after six pipelined number)

 

broadcast:

With mac address, two hosts on the same network can communicate with the (host obtains a mac address of another host via arp protocol)

The most primitive way of using ethernet, broadcast communication mode, i.e. the basic computer communication by roar

 2.3 Network Layer

The origin of the network layer: With ethernet, mac address, broadcast transmission mode, the computer in the world can communicate with each other, the problem is that the Internet is a worldwide

一个个彼此隔离的小的局域网组成的,那么如果所有的通信都采用以太网的广播方式,那么一台机器发送的包全世界都会收到,

这就不仅仅是效率低的问题了,这会是一种灾难

上图结论:必须找出一种方法来区分哪些计算机属于同一广播域,哪些不是,如果是就采用广播的方式发送,如果不是,

就采用路由的方式(向不同广播域/子网分发数据包),mac地址是无法区分的,它只跟厂商有关

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

IP协议:

  • 规定网络地址的协议叫ip协议,它定义的地址称之为ip地址,广泛采用的v4版本即ipv4,它规定网络地址由32位2进制表示
  • 范围0.0.0.0-255.255.255.255
  • 一个ip地址通常写成四段十进制数,例:172.16.10.1

ip地址分成两部分

  • 网络部分:标识子网
  • 主机部分:标识主机

注意:单纯的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

255255.255.255.0:11111111.11111111.11111111.00000000

AND运算得网络地址结果:10101100.00010000.00001010.000000001->172.16.10.0

 

172.16.10.2:10101100.00010000.00001010.000000010

255255.255.255.0:11111111.11111111.11111111.00000000

AND运算得网络地址结果:10101100.00010000.00001010.000000001->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数据                                

Guess you like

Origin www.cnblogs.com/huajiu/p/11610512.html