directory

  • Why are networks layered?
  • OSI model compared to TCP/IP model
  • TCP/IP model
    • The physical layer
    • Data link layer
    • The network layer
    • The transport layer
    • The application layer

Why are networks layered?

This is actually very well understood, the Sui Dynasty began to have the Ministry of Civil Affairs, the Ministry of Household, the Ministry of Rites, the Ministry of arms, the Ministry of Punishment, the Ministry of Works, a huge organization to manage well must be split out, each has its own responsibilities out of the matter directly positioning, each layer can develop their own standards to solve their own level of things.

For example, a project is divided into DAO database layer, cache layer, service layer and controller access layer. Each layer focuses on its own part. With regard to its advantages, it is also appropriate to dump the words of high cohesion, low coupling and strong maintainability on the network layer.

From a professional point of view, programming requires that complex programs need to be layered.

OSI model compared to TCP/IP model

Open System Interconnection Reference Model (OSIOpen Systems Interconnection Reference model), it is only a reference conceptual model, does not provide a way to implement, the current Internet uses the TCP/IP model (layer 5), TCP/IP network communication protocol (layer 4).

If you look at the history of the network, you will find that the OSI model appeared later than TCP/IP. It was put forward on the basis of TCP/IP model. At that time, TCP/IP protocol application was already formed, the major operators did not want to change, and OSI model had some design redundancy, so the Internet finally chose the grassroots PLAYER TCP/IP. However, OSI has great reference value in theoretical research, so every major textbook will mention OSI model.

TCP/IP model

With this five-tier model, you can use TCP/IP to connect computers to communicate.

The physical layer

Sound carries faith by sound waves, pigeons by electromagnetic waves, and electricity by waves. The physical layer needs to solve the problem of transmitting bitstreams using transport media.

Take contra for example (this game is a bit age-revealing), you can start with one keyboard, two people playing together, which is fine but too bad for the experience.

Two computers online play two people, two computers the simplest way of communication is a twisted pair, two crystal head, cross connection, to connect two computer network card, respectively configuration “IP address”, “subnet mask”, “default gateway” into a network, the computer local area network (LAN) is formed one of the most simple, can online play contra!

If a third person wants to join in, they can buy a hub device with multiple ports to connect all three computers. The hub is pure physical work, will receive their own bytes all copy to other ports, other machines look to receive, so that three people happy together.

An Internet cafe people want to join in, can add a switch, switch interconnection, the formation of network topology. An Internet cafe hot how much, must be carefree ah, so the switch is with MAC address learning function, is conducive to faster find the target machine. Switches, however, work at the data link layer.

If everyone in a city wants to be included, it takes operators like China Mobile and China Unicom to spread fiber optic cables and build base stations everywhere, so that we can “meet you every night at 8:00 in King Valley” wherever we are today.

Data link layer

The data link layer is also called the MAC layer. Medium Access Control is called “multiple Access Control”.

  1. Ethernet protocol

Inside the physical layer, has helped you to convert the electrical signal into digital signal 010101001 form, but two machines to communicate the total can not be a bit a bit of 0101 communication, if others and you always deliberately jump word by word estimate you have long fire.

The data link layer is responsible for the encapsulation of these infinite 010011001 into a frame for transmission, then the Ethernet protocol was born, frame is also called the Ethernet frame, Ethernet protocol stipulates the rules of the frame, such as how many bits into a frame, etc.. Ethernet protocols are as follows:

Ethernet frame

Three people connected to play fighting games, the game is strict role and order, any one of the signal, this layer is mainly to solve these three problems:

  • To whom and to whom?
  • Which signals are received first and in what order?
  • What if I send it wrong?

Why is it called media access control? That’s what it controls.

  1. The MAC address

Who receive a data, the first is not only a hub switches, 3 PCS each computer signal is through the way of radio, broadcast out which need to deal with a computer, every computer needs to be a logo can express oneself in a data link layer, MAC address was born, the corresponding physical device is a network card interface, The MAC address of each nic is unique in the world and fixed during production. But network communication, but not MAC address for communication, but IP address, readers can think about the reason for the message answer.

With the identity, the Ethernet frame in the source MAC and the target MAC have, can find the corresponding target machine, packet broadcast on the link, the target MAC network card can determine that this is for itself, receive it open. After the IP packet was received, I removed the MAC header, opened the IP packet and found that the IP address of the packet was also my own. Then I removed the IP header, and according to the corresponding port XXX in the TCP header, this port happened to be the port monitored by my QQ, so I found the wechat process and threw it to QQ for processing. The same goes for the return, the source MAC becomes the destination MAC.

  1. ARP protocol

There is a problem is, a packet coming, how to find the corresponding host? When there are not many machines, you can put the MAC address of the target machine directly into the packet. But what if there are n machines? The person of an Internet bar plays fight together, total impossible one by one ask ah, brother your MAC address is what? , this operation is too dirty, hence the ARP protocol.

In the LAN, if you know the IP address and do not know the MAC address, then broadcast it, send a broadcast packet, who is the IP who answer, answer the packet will bring their MAC information. To prevent ARP broadcast every time, the local device caches ARP broadcast results. A switch is a device with the ability to learn MAC addresses. After learning MAC addresses, the switch can accurately find the host without broadcasting.

The network layer

In fact, some IP addresses have been mentioned above. In the computer network world, IP addresses are used for positioning. How to configure their own IP addresses?

  • You can actually use ifconfig(Windows is ipconfig)
  • You can also, if ADDR, just put the card up
  • Computer small white can open their own computer network configuration center to change the IP address on the line.

Reality we network is a complex network composed of LAN topology, each local area network (LAN) in the same network segment, the MAC address of this person’s DNA, can accurate to one person, but is not addressable positioning function, MAC address without addressing the functional design number, the factory after the nics are used where I don’t know, China can use imported NETWORK cards made in the United States, but IP addresses have design addressing function. IP addresses in each region, like logistics addresses, can locate a person’s specific location layer by layer. Hackers find many people based on IP addresses.

Dynamic Host Configuration Protocol (DHCP) Dynamic Host Configuration Protocol

If there are only a few hosts in the LAN, it is ok to configure IP addresses for fun, but if a school computer needs network management to configure one by one, it is not fun, so we need a protocol that can automatically configure IP, namely DHCP.

When each host wants to join a network, it must be a newcomer who knows everything and only knows its MAC address. Therefore, it still relies on broadcasting, using IP address 0.0.0.0 to send a broadcast packet. 255.255.255.255 is encapsulated in UDP and UDP is encapsulated in BOOTP (the predecessor of DHCP). When a DHCP SERVER receives a packet with a MAC address, it knows who is asking for an IP address when there is no IP address. So give it a subnet mask, gateway, and IP, and the new machine can happily join the LAN family.

Gateway (gateway)

Said so much is also in the LOCAL area network, the network outside so wonderful, if you want to go abroad to play the first thing is to solve the passport, to pass the customs, more than once in front of the nic configuration need to configure the gateway. If your IP address is 192.168.1.100 and your neighbor’s IP address is 192.168.10.100, then I want to access it to see how the computer understands it. Here’s how Linux handles it:

It’s too late for this picture!

Gateway everyone can understand the routers in the network layer into work, it has more than one network adapter connected to different local area network (LAN), each network card IP address and the corresponding local area network (LAN) in the same network segment, like the airport at work, you take along a country passport sent to which country, will the MAC header and the IP header are down, and then judge the content will be where packet forwarding. Routing is divided into static routing dynamic routing, routing algorithm and other complex logic.

DNS DOMAIN NAME SYSTEM (DNS)

If you have a strong memory, of course, you can visit Baidu in this way, just like typing a phone number to call a person, but most people are directly looking through the address book to find a name to call, the network world is the same, need a domain name to mark an IP, So you can visit Baidu at www.baidu.com. A domain name is an address book in the online world.

Imagine, rely on a directory to all over the world, once it hung up the global village is gg, therefore the DNS server must be high availability, high concurrency, distributed, so complicated first reaction is certainly hierarchical design, ideas are interlinked, so there will be a root DNS server, top-level domain DNS server, authoritative DNS server, As follows:

The drawing is a little ugly

To improve IP address resolution performance, cache is required. Many carriers (China Unicom) deploy DNS cache servers nearby. The DNS resolution process is as follows:

image

Content Delivery Network (CDN) cache

Access an address should be so complicated, look for such a multilayer, wait a second more in reality are uncomfortable, it will have to think of some way to go as far as possible take data cache, world there are so many data center, we have data center, not far away, why not in the data center deployment of some machines to make the cache cluster caching data? So the role of CDN came out, here is not to elaborate on its specific form, nothing more than layered, high availability design.

The transport layer

TCP, UDP

Just like the logistics system, after receiving the order, the route is selected, and the goods will be shipped. The traffic situation is so complicated that a series of problems such as congestion, loss of goods, and timeout will definitely be encountered in the shipping process. The transmission layer is designed to solve these problems. There are UDP protocols and TCP protocols. The main difference between them is that UDP is unreliable while TCP is reliable.

UDP protocol is suitable for applications that are not sensitive to packet loss, do not need to establish a connection, and have high speed. The ARP and DHCP mentioned above are based on UDP protocol, as well as the live streaming media protocol, early games that require high real-time performance, the Internet of Things and mobile communications, etc.

To ensure the reliable transmission of TCP, it is necessary to consider the guarantee sequence, packet loss processing, maintenance connection, flow control, and congestion control and other problems, so there is a complex three-time handshake, four-time wave, but also to maintain the TCP state machine. Congestion control is solved by congestion window, sequence, packet loss processing, flow control corresponding to sliding window.

Port

Imagine data of the river-crossing arrived in your computer, and then what to do, you also opened WeChat, QQ, nailing, others will give you a clockwork news you always carried to the corresponding program, it is finally arrived, let’s understand each application into a program that is reflected to the needs of the port, the port on your computer will not repeat, Otherwise, the data will not be able to judge, many people when playing Tomcat, open two 8080 port will encounter error.

The application layer

There would be specific to the application layer, and, after all, we can see, everyone has different needs, such as A need to send mail, B need to place an order, C need to download the file, this need to solve to tell each other, I want to do, according to do something different, and catalytic out A variety of different protocols to best solve your demand.

The HTTP, HTTPS protocol

HTTP is the earliest protocol, which is divided into POST, DELETE, PUT, GET and other requests, corresponding to the server to add, DELETE, change and check data, and then developed to HTTP2.0 through compression, frame, binary coding, multiplexing and other technologies to improve performance, and finally developed to HTTPS, through the improvement of encryption technology to improve security.

The relationship between transport layer protocols and application layer protocols

Application layer protocol = TCP/UDP + PORT PORT number

  • HTTP = TCP + 80
  • HTTPS = TCP + 443
  • RDP = TCP + 3389
  • FTP = TCP + 21
  • TELNET = TCP + 23
  • SMTP = TCP + 25
  • DNS = UDP + 53
  • TFTP = UDP + 69
  • SNMP = UDP + 161
  • RIP = UDP + 520

Welcome to pay attention to my public account “Forrest Gump’s code road”, if you have any questions, you can add me to discuss.