origin

Many programmers like me who changed careers after graduation may not have studied computer courses systematically in college.

In the short term, these things will not be touched at work. But as a programmer, computer networks are a must, and you’ll need them when you’re trying to solve complex problems.

In the words of uncle Mouse:

For example, there are “airbenders and sword benders” mentioned in swordsman.

  • Jian Zong kung fu is quick and effective. If everyone has practiced for ten years, the Jian school must have the upper hand. Practice 20 years, that is each good at the game, it is difficult to split up and down; It was not until twenty years later that those who practiced Airzong kung fu gradually became stronger and stronger. By 30 years, the swordsmen will no longer be able to compete with the airborns.

Jian Zong kung fu can be accomplished quickly, but it lacks stamina. In the long run, airbenders are more powerful.

In the field of programming, the framework of common learning is jian Zong, effective quickly, immediately can start to work. And the basic knowledge is airbender, which is important in the long run.

So, now I decided to systematically learn the basic knowledge of computer, using a blog to record.

First look at the computer network, our textbook is the computer network, the top-down approach (7th edition), the video is USTC 烇 zheng, Yang jian, a full set of “computer network” https://www.bilibili.com/video/BV1JV411t7ow?p=1

I’m going to take you through the basics of computer networking quickly, from zero to one. Now we come to the first chapter Internet, let’s go!

Internet architecture and ISPs

Previously we divided the Internet by node and link types: network edge, network core, and access network.

Devices on a network are now divided by contact density into an ISP network.

Given millions of access ISPs, how do you connect them?

You cannot connect all of them directly. If you connect every two ISPs directly, it is not scalable and requires an O(N^2) connection.

  • An end system connects to the Internet through Internet Service Providers (ISPs)

    • Residential, corporate and university ISPs access ISPs
  • The corresponding end systems to access ISPs must be interconnected. Therefore, any two end systems can send packets to each other

  • Ultimately, the “network of networks, the Internet,” is very complex, and its development and evolution is driven by economic and national policies

Packet latency, loss, and throughput

Packet switching mode, its shareability is better, more suitable for communication with the computer.

But the benefits of packet switching are not obtained without reason, it needs to consume a lot of costs, on the other hand, it has a lot of problems.

One is that there will be more delay than his line switch; Another is that packets may be dropped during data transmission.

How do packet loss and delay occur?

A group comes in and looks up the routing table to decide which link to take.

  • If no packets are being transmitted on the current link, the packets can be transmitted directly
  • If another packet is being transmitted on the link, the current packet must be queued.

    • You get to the head of the line before you let him go. This is the reason for the packet delay.
  • Of course, the queue is also limited, if the current queue has overflow. Then, the group will be dropped. This is one of the reasons why groups are lost.

Four types of packet delay

So what are the other delays besides queue delays?

  1. Node processing delay

For each group, the node first checks the group for errors and then extracts the target IP address field and looks it up in the routing table.

This takes time to do a series of processes, which we call processing latency.

  1. Queuing delay

After looking up the routing table, I decide to send it out over this link, but there are other groups in the queue on this link, and there will be queuing delays.

The duration of the queuing delay is uncertain and depends on the level of congestion on the router.

  1. Transmission delay

Assuming that the packets are transmitted on a first-come-first-served basis, which is common in packet-switched networks, our packets will be transmitted only after all the packets that have already arrived have been transmitted. L bits represent the length of the packet and R BPS represent the transmission rate of the link from router A to router B.

The transmission delay is L/R. This is how long it takes to push all the packet bits down the link.

  1. Propagation delay propagation

Once a bit is pushed to the link, the bit needs to be propagated to router B. The time required to propagate from the starting point of the link to router B is the propagation delay.

The bit travels at the propagation rate of the link, which depends on the physical medium of the link, in the range of m/s, which is equal to or slightly less than the speed of light. The propagation delay is equal to the distance between two routers divided by the propagation rate, that is, the propagation delay is D /s, where D is the distance between two routers, and s is the propagation rate of the link. The propagation delay is in milliseconds.

Transmission delay is the time it takes a router to push a packet out. It is a function of packet length and link transmission rate, and is independent of the distance between two routers.

The propagation delay is the time it takes for a bit to travel from one router to another and is related to the distance between the two routers.

The team analogy

Transmission vs propagation

  • Ten cars form a convoy, and then the car passes through the first toll booth, crosses the highway, and arrives at the second toll booth, and its speed is 100 kilometers per hour. When each car goes through the service station, it takes a little bit of time, it takes 12 seconds for the toll collector to issue you a card or something like that, 12 seconds for 10 cars that’s 120 seconds.

    • The sum of the time each car in a fleet beats it out equals a transmission delay.
  • It takes 60 minutes for a car to travel 100 kilometers per hour, which is a propagation delay.

Capacity of the channel

If a car travels at a speed of 1,000 km/hr, it takes one minute for the toll booth to serve each car.

So before all the cars arrive at the first toll booth, will the cars arrive at the second toll booth?

yes! Seven minutes later, the first car arrived at the second toll booth, and there were still three cars at the first toll booth.

Before the entire packet is transmitted by the first router, the first bit reaches the second router!

So here, by the way, we introduce a concept called channel capacity. The first toll booth, the computer equivalent of a LAN, had almost no capacity. We’re not finished yet. Everyone’s already received it. The second is equivalent to WAN wide area Network, so the two situations are completely different.

Node delay

So the latency in each node, processing latency, queuing latency, transmission latency, propagation latency.

  • In general, the processing delay is usually microseconds or less.
  • Queuing delays are random, depending on the level of congestion at the moment.
  • The transmission delay depends on the length of packet L, and R represents the transmission rate of the link from router A to router B.
  • The propagation delay depends on the distance between d and the two routers. S is the propagation rate of the link.

Queue delay: The flow intensity cannot be greater than 1

Traffic intensity is (R link bandwidth x average rate of a packets arriving in queues)/L packet length.

  • It has to be between zero and one, where zero is more light load and one is more heavy load.
  • The flow intensity is equal to 0, and the queuing delay is very small. However, the closer the flow intensity is to 1, the queuing delay tends to be infinite.

throughput

What is throughput? The number of valid bits sent from the source host to the destination host per unit of time.

🌰 In this scenario, there are two links from the source host to the other host, which is equivalent to two pipes. The first pipe is thinner and the second is thicker. What does this effective throughput depend on during transmission? Thin pipes, called bottleneck links.

Internet Scenario

Now let’s look at a real scenario where 10 hosts communicate through a link R, then each host can only get 1/10 of its bandwidth, and 1/n of its bandwidth.

  • Why do you think it’s average? We’ll talk about fairness in TCP when we talk about the transport layer, TCP.
  • Throughput is determined by the bottleneck link.

Protocol hierarchy and service model

How to implement complex system networks?

The network is a very complex system.

  • The functions of the network are complex. In order to realize the physical signal bearing of digital signals, point-to-point local transmission, end-to-end routing transmission, reliable data transmission, process differentiation, and various very complex network applications, etc
  • When you look at the Internet, there are tens of billions of devices, billions of users. There are thousands of popular applications on the Internet, which can be said to be one of the largest artificial systems and one of the most complex systems.

So as an engineer, how do you design and implement complex computer networks? What are some ideas?

  • You might think of modularity. To decompose a more complex function into a module, module calls each other. In this way, any module can call the functions and services provided by any other module. In this way, complex functions can be broken down into simpler problems in a modular way.
  • Another way to solve this problem is the layered approach. In this method, complex functions are divided into modules, but only adjacent modules and between modules, that is, between adjacent levels, can be called and called. It does not allow or recommend such calls across layers.

Computer networks are designed and implemented in a hierarchical way. Scientists break down computer networks into well-defined layers, each layer providing services to the top layer through interfaces, and each layer falling down to achieve complex functions.

Let’s take a look at a real life example to make it easier for you to understand.

🌰 : An exchange between two distant philosophers

Two distant philosophers wanted to exchange ideas, one in America, the other in France.

We can set up three levels.

  • Level 1: secretary, to solve remote communication problems.
  • The second layer: translation, the philosophers used the original French, English into the common language.
  • The third layer: philosophers, who export philosophical ideas.

So what are the benefits of this hierarchical approach?

  • First, break down big problems into smaller ones. For example, in our example, a complex problem is transformed into three subproblems, each of which is relatively independent and relatively single.
  • Second, it is convenient to adopt some new technologies. For example, at the secretary level, the communication between two philosophers could be improved by telegraphy and telephone, which was originally transmitted by carriage.

Functional level

Hierarchical mode to achieve complex network functions

level

  • The complex functions of a network are divided into distinct functional layers, each of which implements one or a group of functions.
  • Some of the functions implemented by each layer can be called by the upper layer, and these functions are called services. In other words, each layer provides services to the upper layer through the interlayer interface.

    • 🌰 How do I send a packet to another entity?
  • Using the services provided by the lower layer to exchange PDU (protocol data unit) with the other party, including its own processing, including some resource arrangements. And then ultimately through the interlayer interface, to provide better services to the upper layer, layer by layer, and finally achieve a very complex computer network function.

agreement

The set of rules that should be followed during the interaction of the entity itself is called a protocol.

How is the protocol implemented? With the help of services provided by the lower layer.

What is the purpose of implementing the protocol? It’s to provide better service to the top.

Services on this layer

New functionality between protocol entities at this layer implemented by services at the lower layer (available at the upper layer) + services provided at the lower layer

Since this is the core of the Internet, let’s review how to design and implement complex computer networks.

  • To divide a computer network into distinct layers of functions, each of which implements one or a set of functions.
  • It is realized by the mutual action of the protocol entity.

    • How do you do that? With the help of the interfaces between layers and the services provided by the lower layer, the corresponding PDU can be exchanged so as to realize the PDU protocol action. In this way, better services can be provided to the upper layer.
  • The services provided by each layer to the upper layer include the sum of the services provided by all the lower layers. It also includes new service features that emerge from the interaction between this layer and peer entities. Otherwise, I don’t need your floor. ? You’re just the sum of the services that are provided at the bottom, and that doesn’t work, and you have to create new features, new services.

Services and service access points

Then we’ll introduce the terminology.

service

What is a service? The underlying entities provide the upper entities with the ability to communicate between them. Services are vertical relationships in which upper-layer entities access services provided by lower layers through interfaces between layers.

There are two concepts, service users and service providers.

Service user & service provider

What is a service user?

For example, there are many applications on TCP entities, a.NET application, an FTP application, and a Web application.

Are there three simultaneous users for this TCP entity? We call them service users.

And those who provide services to them are called service providers.

Primitive primitive

The upper layer uses the form of the lower layer services, the higher layer uses the services provided by the lower layer, and the lower layer provides services to the higher layer all interact through service access primitives.

In other words, we’ll call the primitive primitive the form in which the user uses the service provider’s service and the form in which the service provider offers the service to the user.

🌰 then let’s take an example, such as SF express can provide a lot of business, send documents, send electronic products, send large items, receive documents and so on. The specific services that you use it to provide are called primitives.

🌰 Application processes use the services provided by the transport layer through a set of socket API functions called primitives.

SAP Services Access Point

Service access point

If I am a service provider, I provide services to three application entities simultaneously. So at this point, a piece of data comes in, which application is this piece of data going to?

So, am I trying to figure out who this data is for?

As a result, service access points are created by adding a series of points to the interface between layers that distinguish different upper-layer users. Let the lower level service provider distinguish the information of the different upper level users.

🌰 For example, express delivery, a express company, can not serve only one person. Therefore, when we send the express, we should fill in the express form, recording who you are, where you send it from, who the recipient is and his detailed address. After arriving at the delivery service, he was able to tell who the delivery was for.

How to distinguish between different senders and receivers is what service access points do.

Type of service

Connection-oriented services

If two apps establish a connection, say hello to each other first. This form of this service is called a connection-oriented service.

The two application processes use services provided by TCP. Is a typical connection-oriented service.

The client process establishes a connection to the server process, initiates a connection to the other party, and the other party responds with a connection acknowledgement after receiving the connection request. In other words, two applications should shake hands before communicating.

Connectionless services

Anyway, it’s called connectionless services, like UDP. Two application processes before communication, do not need to shake 🤝, do not need to establish a connection.

Services and Agreements

The difference between

Protocol is a horizontal relationship, which is a set of rules that peer entities should follow in the process of communication.

Services are vertical. Inside the system, services are provided to the upper layer in the form of primitives on SAP through interlayer interfaces.

  • Remember the nouns from above, we strung them together to explain what a service is.

    • In the internal layer of a system, between two adjacent layers, its interface, the user of the service on SAP through the primitive, the upper layer to use the lower layer of services, the lower layer to provide services to the upper layer.
  • Remember SAP and primitives?

    • Because many users can use the underlying services, a single protocol entity in the underlying layer can provide services to multiple users simultaneously, so it must be distinguished by SAP.
  • Because the services provided by the lower layer to the upper layer have a variety of types, and these types in the process of use, there are a series of operational specifications. Therefore, it is necessary to standardize and distinguish in the form of primitives.

This diagram illustrates the relationship between a protocol and a service. Layer 5 accesses services provided by layer 4 through interlayer interfaces, and so on, all the way to layer 1. But the physical layer directly uses physical media to transmit physical signals, converting digital signals into physical signals for propagation. This is the vertical relationship between the service and the served.

And each layer of the entity in the communication process should follow some rules, called protocols.

contact

  • When this layer protocol is implemented, the services provided by the lower layer can be implemented
  • What is the purpose of this agreement? In order to provide better service to the upper layer

Data Unit (DU)

What is a data unit?

For the current level N, it provides services up to layer N+1 through the SAP of the layer indirect interface.

  • So he’s going to transmit data to N+1, which we call the service data unit SDU.
  • SDU goes through layer indirection, it needs to add some interface control information (ICI) to get through layer indirection more smoothly, that’s his business, I can leave it.

  • After the SDU is obtained, the control information of this layer is added in front of the SDU to form the protocol data unit word PDU of this layer. In other words, the exchange of information to layer protocol entities is implemented by layer NTH PDUs.

What is the core content?

  • Each layer of the PDU has its head and body.

    • The body is derived from the SDU data handed in by the upper layer, which the upper layer wants the layer to load.
  • The header information is partly transferred by ICI and partly added by this layer.
  • 🌰 is equivalent to loading the SDU of the upper layer into the truck of this layer. Truck is divided into truck head, truck body. The head of the truck is loaded with the head information, and the body of the truck is loaded with the cargo SDU.

Then we will separate each layer of protocol data units, they are special names.

  • The data unit of the application layer is called application message.
  • The transport layer is called a segment, or simply a segment.
  • When we go to the network layer, we usually call it a packet, but if the network works connectionless, we call it a datagram, and a datagram is a network layer grouping;
  • When you go to the link layer, it’s usually called a frame;
  • And then finally the physical layer, the protocol data unit, is a little bit more ambiguous, you can call it whatever you want.

Each layer is called a different data unit.

Hierarchical processing achieves the benefits of complex systems

Hierarchical implementation, for the realization of complex computer network system in the end what benefits, we can simply analyze.

Conceptualization: Clearly structured, easy to identify network components and describe their relationships

What’s the biggest benefit?

A large complex system can be broken down into smaller functions, each of which can be implemented independently. Divide and conquer, each function is better designed to achieve.

Structure: Modularity is easier to maintain and upgrade

The second benefit is that changing the implementation of a service at one level does not affect the rest of the system, allowing for smooth upgrades.

  • 🌰 or two philosophers exchange philosophical questions.

    • The two secretaries used to exchange information by way of walking, but with the progress of The Times, they exchanged information by telegraph and telephone.
  • And the secretary and the translation of the interface is constant, that is to say, the bottom layer adopts new technology, for the upper layer is perceptual. This facilitates smooth upgrade of the whole system.

The problem?

The efficiency is low, and the information exchange between layers is troublesome.

But in general, the benefits of layered solutions to network problems far outweigh the disadvantages, so computer networks are basically designed in layers.

The Internet protocol stack

So what are the layers of computer network? What is the main function of each level? Here are the secrets.

  • The functions of the computer network are divided into five levels, each providing a corresponding function. Physical layer, link layer, network layer, transport layer, and application layer.

The physical layer

Send a bit over the wire.

  • The sender converts one or a group of bits from the frame handed over by the upper layer into a physical signal and transmits it to the other side in the medium. The receiver restores the physical signals on the physical media, such as electromagnetic and optical signals, to the original digital signal 0101.
  • 🌰 is to convert the digital data into physical signals, and then load on the media, from a point to another point adjacent, such as from the computer to another switch network port, and then the physical layer of the other side’s network card load on the media on the physical signal reversal back, the formation of the original digital data.

The link layer

The transmission of data between adjacent network nodes, connecting network cards by a link.

  • Transmit data in frames based on the services provided by the physical layer. The data is transmitted in frames between two adjacent points.
  • What do you mean two next to each other? For example, if my computer is connected to a switch on the entire floor, their network ports are connected, so they are adjacent points.
  • Of course, some link layers provide reliable services, while others provide unreliable services.

Can the transfer of data from the source host to the destination host be completed with only the transmission between relative points? B: No, what shall I do?

The network layer

  • Extending two adjacent points into an end-to-end relationship between source and target nodes is what the network layer does. In other words, based on the data transmission between two adjacent points provided by the link layer, the transmission is the end-to-end data transmission in the unit of packet.
  • The link layer provides a P2P relationship, and the network layer provides an end-to-end relationship. On the basis of point-to-point data transmission at the link layer, it provides end-to-end data transmission.

Is the service provided by the network layer enough for the application process to run directly? Can’t.

The transport layer

The transport layer is a service on top of the network layer, subdivided into services to processes by means of host-to-host transport at the network layer. And turn unreliable communication into reliable communication.

  • Your host is running a lot of application processes, that data to you here, do you want to do a process to process distinction?
  • In addition, there is a very important service to turn unreliable communication into reliable communication.

    • The services provided by the network layer are unreliable. As we’ve seen before, packets can be lost during transmission, they can be wrong, they can be out of order, they can be repeated. Get here and turn it into a reliable communication service.
  • 🌰 Transport layer TCP See below for networking products and services provided by IP. IP provides services that are unreliable, and TCP wants to make them reliable. No mistakes, no repetition, no loss.

The application layer

Network applications provide network application services for human users or other application processes. Such as Taobao, Douyin, etc., these web applications are the reason for the Existence of the Internet.

ISO/OSI reference model

Then in addition to the five layer reference model of TCP IP for the Internet, there is another network called ISO/OSI/Open Systems Interconnection.

There are reference models, architectures and a set of standards. The network can be divided into several layers, what is the main function of each layer, what is the architecture, what are the protocols in each layer.

It’s divided into seven layers, called the Seventh heaven, the physical layer, the link layer, the network layer, the transport layer, the session layer, the presentation layer and the application layer. The red ones are not in the TCP IP stack.

  • Presentation layer: allows applications to interpret transmitted data, e.g. encryption, compression, machine-specific presentation transformation.

    • The information transmitted between application processes does not need to be encoded, only the semantic aspects of the information are concerned.
  • Session layer: synchronization, checkpoint, and recovery of data exchange

    • Session management, establishing and maintaining sessions.

So in the TCP IP stack in the Internet architecture, isn’t there a need to represent transformation and session management? Of course, this is all done by the application layer itself.

Encapsulation and unencapsulation

The packet is sent from the source host to another host. I am a Web browser, you are a WEP client, I want to send a request to you. It seems logical that I could send you a message directly, but directly would have to be quoted.

encapsulation

  • At the application layer, can messages be sent directly to each other’s application process? Can’t. It must be implemented through the interlayer interface, with the help of services provided by the lower layer.
  • When it’s handed over to the transport layer, it has to add its own control information, add its own control information, and then form its own segment.
  • The packet segment is then handed over to the network layer. The network layer adds its own header information, such as the source IP address and the destination IP address, to form a group.

    • The synchronization information is formed by this layer, plus the information brought by the upper ICI as it passes through the layer’s indirect ports. Make a transformation at the network layer to form the synchronization information at this layer.
  • When it goes to the link layer, it adds the group to the link layer header and possibly the end to form a frame for the physical layer,
  • The physical layer then forms a group of each bit, or bits, and punches them out in groups or one by one.

decapsulation

  • To the physical layer of the other party, and then restore to the corresponding link layer frame.

    • Determine which is the beginning of a frame, which is the end of a frame, and which is the content part of a frame. The physical layer takes the frame out.
  • The link layer knows the contents of the frame, including the frame header and the data section.

    • The frame contains information such as the destination MAC address. You can query the switch stack table and switch table to determine where to send the data.
  • The port then encapsulates it into frames of other links, and passes it to its physical layer, which then takes every bit of it, turns it into an electromagnetic signal, an optical signal, and sends it out.
  • At the next hop, several network adapters are inserted into the router. Each network adapter inherits the functions of the link layer and physical layer.

    • That means I am a router, I connect to the network through the network card, and connect to the network through the network card.

      • Then the network card says a frame, I take the data part of the frame, the frame carries the upper layer, network layer protocol data unit, is the group.
  • It has control information like the destination IP, and I look up the forwarding table at the network layer and decide which network port to send it through.
  • I’m going to pass the packet through the interface to the network card, and then the network card is going to encapsulate it into a frame, and then each bit of the frame is going to be a physical signal, and then I’m going to punch it out and go to the next hop.
  • In this way, you can finally reach the target host.

    • The target host takes out every bit of the physical layer of the network layer, and then it takes out the frames, and then it takes out the data parts, and it groups them.
  • The packet is handed over to the network layer, which in turn takes the packet segment out of the packet and gives it to the transport layer.
  • The transport layer takes the segment and passes the Message, or part of the message, to the application layer.
  • At the application layer, the two application processes can finally communicate.

Say so,

  • Do encapsulation on the source side.
  • In the middle of a router or switch, do a decapsulation, re-encapsulation.
  • Make a large decapsulation at the target end.

Each layer of protocol data unit

Each level of protocol data unit has a specification.

  • Application layer: Message
  • Transport layer: Segment: TCP segment, UDP datagram
  • Network layer: packet(if no connection mode: datagram)
  • Data link layer: Frames
  • Physical layer: Bit