preface

To be a good Android developer, you need a completeThe knowledge systemHere, let’s grow up to be what we want to be.

Network optimization has always been considered moving to optimize water is one of the deepest, so want to further optimize the network, we must first lay a more solid foundation network, in this article, we will once again confirm the key knowledge of computer network, to establish in your mind a relatively comprehensive system of network knowledge.

The outline

8. Network layer

1. Main functions of the network layer

Data routing.

2. IP protocol

1) Disassembling the IP protocol

Virtual Interconnection network

  • 1) The actual computer network is complex.
  • 2) Physical devices use the IP protocol to mask the differences between physical networks.
  • 3) When the hosts in the network are connected using IP protocol, there is no need to pay attention to network details.

Data communication between computers A and B can be thought of as being transmitted over A virtual interconnect network.

Functions of the IP protocol

  • 1) THE IP protocol makes the complex actual network into a virtual interconnection network.
  • 2) THE IP protocol enables the network layer to mask the details at the bottom layer and focus on the data forwarding at the network layer.
  • 3) IP protocol solves the problem of datagram transmission path in virtual network.

The IP address

Each unique network device has a unique IP address. Unlike the MAC address, which cannot be changed, the IP address changes according to the network environment connected to the device.

For example, an IP address: 192.168.11.11 = > 11000000.10101000.00001011.00001011

The characteristics of

  • The IP address contains 32 bits and is usually divided into four 8-bit bits.
  • The IP address is usually expressed in dotted decimal notation, that is, 0255.0255.0255.0255.
  • The maximum number of IP addresses is 2 ^ 32 = 4294961296 => 4.2 billion.

IP datagram = IP header + IP datagram data. The format of IP datagram packets is as follows:

version

The four digits indicate the VERSION of the IP protocol. The versions of the two communication parties must be the same. The current mainstream version is 4, that is, IPv4 and IPv6.

Bow length

The value contains four digits and a maximum of 15. It indicates the length of the IP header. The unit is a 32-bit word (4 bytes). Therefore, the maximum length of the IP header is 15 x 4, which is 60 bytes.

Type of Service (TOS)

Indicates whether the current packet is of high or low priority. Packets are allocated to three bands (band0, band1 and band2) according to TOS.

The total length

The value contains 16 bits and the maximum value is 65535. It represents the total length of the IP datagram (IP header + IP data).

Note that data transmission at the data link layer is limited by the maximum transmission unit (MTU), which is 1500 bytes. If the length of an IP datagram is longer than the MTU, the data link layer divides the IP datagram into multiple data frames for transmission.

logo

The protocol is used internally and does not need to be concerned.

mark

It has three digits. At present, only two digits are meaningful, indicating whether to fragment.

Slice offset

It has 13 bits. If a fragment occurs, it will record the IP offset of the current data frame.

TTL

  • The value is 8 bits, indicating the lifetime of an IP packet on the network. The TTL decreases by 1 every time it passes through a device. When the TTL is 0, the network device must discard the packet.
  • If an IP packet cannot find its destination on the network, IP data cannot be transmitted indefinitely on the network, which consumes bandwidth.

agreement

8 bits, indicating the protocol of the specific data carried by IP data. (for example: TCP, UPD, etc.)

agreement value
ICMP 1
IGMP 2
IP 4
TCP 6
UDP 17
OSPF 89

Header checksum

It takes 16 bits to check whether the IP header is incorrect. The receiver checks the IP header after receiving the IP packet. If an error occurs, the packet is discarded.

The source IP address

IP Indicates the IP address for sending data packets.

Destination IP Address

The IP address that the datagram arrived at.

2) IP protocol forwarding process

By jumping (hop – by – hop)

The data is transmitted from the destination device to the next network 1, then from the next network 1 to the router, and then from the router to the next network 2. Therefore, it is hop by hop, that is, hop-by-hop.

The routing table

  • 1) Unlike the MAC address table, which consists of groups of MAC addresses and hardware interfaces, the routing table consists of the destination IP addresses of groups and the IP addresses of the next hop.
  • 2) Both the computer and the router have routing tables.

Forward process

  • 1. A sends an IP packet destined for C. A queries the routing table and finds that the next hop is E.
  • 2. A delivers the IP datagram to the data link layer and informs the destination MAC address of E.
  • 3), data link layer fill in the source MAC address A and destination MAC address E.
  • 4) The data link layer sends data to E through the physical layer.
  • 5) The data link layer of E receives the data frame and delivers the frame data to the network layer.
  • 6) E Queries the routing table and finds that the next hop is F.
  • 7) E delivers the datagram to the data link layer and informs the destination MAC address of F.
  • 8) The data link layer of E encapsulates data frames and sends them.
  • 9) The data link layer of F receives the data frame and sends the frame data to the network layer.
  • 10. F queries the routing table and finds that the next hop is C.
  • 11) F delivers the datagram to the data link layer and informs C of the destination MAC address.
  • 12) The data link layer of F encapsulates data frames and sends them.

MAC address is the biggest difference from IP address

  • 1) The MAC address of the data frame changes with each hop, while the IP address of the IP packet remains the same with each hop.
  • 2) THE IP address has the function of remote location, while the MAC address is more like the ID number. The uniqueness of the IP address is to ensure that different network cards have different identifications without worrying about conflicts in the same network.
  • 3. Compared with IP addresses, THE communication range of MAC addresses is smaller and limited to a subnet. For example, you can access 192.168.0.1/24 from 192.168.0.1/24 using a MAC address.

3) IP address subnets

Why do YOU divide IP addresses?

Because planning and assigning IP addresses is very difficult.

IP address of a category

Format: Network id + host ID

There are three types of IP addresses:

  • Class A: The first digit is 0, the network id is 8 bits, and the host ID is 24 bits.
  • Class B: The first digit is 10, the network id is 16 bits, and the host ID is 16 bits.
  • Class C: The first digit is 110, the network id is 24 bits, and the host ID is 8 bits.

Show the figure

Special network number

  • Class A All 0(00000000) indicates A special network.
  • Class A Address The last seven bits of A network segment are all 1(01111111:127).
  • Class B network segment (10000000.00000000:128.0) is unavailable.
  • The Class C address segment (192.0.0) is unavailable.

Special host number

  • Host ID all zeros indicate the current network segment and cannot be assigned to a specific host. For example, 1.0.0.0.
  • If the host id is all 1, the message is sent to all hosts in the current network segment. For example, 0.1.11.111.

Form figure

Local Loopback Address: 127.0.0.1, which does not belong to any classified Address class. It represents the device’s local virtual interface, so by default it is considered an interface that will never be discarded. The Windwos operating system has a similar definition, so you can ping through the local loopback address before installing the network adapter. It is used to check whether local network protocols and basic data interfaces are normal. The code looks like this:

quchao@quchaodeMacBook-Pro EMC-MBANK-ANDROID % ping 127.0. 01.
PING 127.0. 01. (127.0. 01.) :56 data bytes
64 bytes from 127.0. 01.: icmp_seq=0 ttl=64 time=0.068 ms
64 bytes from 127.0. 01.: icmp_seq=1 ttl=64 time=0.103 ms
64 bytes from 127.0. 01.: icmp_seq=2 ttl=64 time=0.081 ms
64 bytes from 127.0. 01.: icmp_seq=3 ttl=64 time=0.081 ms
Copy the code

Category address supplement

  • Class D address: 1110…..
  • Class E address: 1111…..

They are used for special purposes only.

Divide the subnet

A company has 256 employees, each with a computer. Which network segment should the company apply for?

Assigning class B addresses, but the number of hosts a Class B address can hold is 2^16-2, which is extremely wasteful. To solve this problem, subnets need to be created.

For example, IP address 193.10.10.0 is divided into 193.10.10.0 to 193.10.10.127 and 193.10.10.128 to 193.10.10.255.

How to determine the network number of an IP address when there are so many subnets?

Subnet mask

To quickly determine which subnet number an IP address belongs to, run the following command: IP & Subnet mask = Subnet number corresponding to the IP address. The components of a subnet mask are as follows:

  • 1), the same as the IP address, is 32-bit.
  • 2) consists of consecutive ones and consecutive zeros.
  • 3) The subnet mask of a certain subnet has consecutive 1’s.

For example, the subnet masks of class A, B, and C are as follows: Class A: 255.0.0.0, Class B: 255.255.0.0, and Class C: 255.255.255.0

Unclassified addressing CIDR

  • 1) There is no concept of class A, B and C network number and subnet division in CIDR.
  • 2) CIDR Refers to IP addresses with the same network prefix as a CIDR address block.
  • 3) Network prefixes are arbitrary bits.
  • 4) More flexible than the original subnets.

CIDR uses slash notation. For example, 193.10.10.129/25 indicates that the network number is 25 bits and the host number is 7 bits. In most homes, CIDR /24 is used, and the first address in the entire network is 192.168.0.1, which is usually the egress address of the private network. For example, if the computer at home is connected to WIFI, the WIFI router’s address is 192.168.0.1, and 192.168.0.255 is the broadcast address.

What is a loopback?

The loopback interface is usually assigned to 127.0.0.1, which is used for native internal communication and is processed by the kernel and returned directly, never to be seen on any network.

A company has a total of 200 employees and needs to be divided into two parts. Each part uses a small network. How to divide it using CIDR?

It is possible to use one /24 as a medium-sized network (known as a supernetwork in CIDR) and two /25 as a small network (known as a subnet in CIDR).

3. ARP and RARP

During IP data forwarding, A delivers the IP packet to the data link layer and informs the destination MAC address of the packet to E. How does A know that the destination MAC address is E?

1) Address Resolution Protocol (ARP)

ARP translates a 32-bit IP address at the network layer into a 48-bit MAC address at the data link layer.

ARP cache pool table

The mapping between IP addresses and hardware addresses is cached. If the MAC address table is not cached, the broadcast format is similar to that used to obtain the ADDRESS from the MAC address table

  • 1. E checks the MAC address table and finds no information about C.
  • 2. E broadcasts packets from A to ports other than A.
  • 3) E will receive the response from B and C and record the address.

ARP cache is the key to the operation of ARP and RARP. In addition, records in the ARP cache table are not permanent and have a certain period of time.

View the ARP cache table

Run the arp -a command as follows:

quchao@quchaodeMacBook-Pro EMC-MBANK-ANDROID % arp -a
? (22.1253.254.) at 0:10:db:ff:10:0 on en0 ifscope [ethernet]
? (224.0. 0251.) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet]
? (239.255255.250.) at 1:0:5e:7f:ff:fa on en0 ifscope permanent [ethernet]
Copy the code

ARP protocol

ARP protocol is directly encapsulated in the data link layer in the data frame.

If ARP is directly encapsulated in data frames at the data link layer, why is it part of the network layer?

This is mainly because THE ARP protocol uses IP addresses at the network layer.

ARP Content

2. Reverse Address Resolutioni Protocol (RARP) Indicates the Reverse Address resolution Protocol

  • 1. Translate the 48-bit MAC address at the data link layer into the 32-bit IP address at the network layer.
  • 2) Similar to ARP except that type 8035 is identified as RARP.

3) Summary

  • RARP and ARP are basic protocols in the TCP/IP protocol stack, and their operations are transparent to programmers.
  • Understanding them helps us understand the details of network layering.
  • They are important protocols to coordinate the work of data link layer and network layer.

4. Network Address Translation (NAT) technology

The gateway that does not change the IP address is called the forwarding gateway. The gateway whose IP address is changed is called the NAT gateway.

Why use NAT?

  • 1) IPv4 has a maximum of 4 + billion IP addresses.
  • 2) Unreasonable PLANNING of IP addresses in the early stage leads to IP number waste.

1) Intranet address

The characteristics of

  • 1) Internal organization use.
  • 2) Avoid duplication with the Internet address.

Three types of Intranet Addresses

  • Class A: 10.0.0.0 to 10.255.255.255 (tens of millions of devices are supported)
  • Class B: 172.16.0.0 to 172.31.255.255 (supporting millions of data-level devices).
  • Class C: 192.168.0.0 to 192.168.255.255 (support tens of thousands of devices).

For a company, it can use a globally unique external IP address externally. Usually, a class B Intranet address is used internally.

In the same way, a family can use a globally unique external IP address externally, and usually use a Class C Intranet address internally.

Question: Multiple Intranet devices use the same Extranet IP address to request extranet services. How can external users know which Intranet device makes the request?

Use NAT, which is used for multiple hosts to access the private network of the Internet through a public IP address, and reduces the consumption of IP addresses but increases the complexity of network communication.

2) Internet address

  • Worldwide use.
  • Global public network unique.

3) Port mapping

For example, the following two NAT processes are performed: During data transmission, the internal IP address and port number of device A => External IP address and port number: 192.168.2.11:6666 => 173.21.59.10:16666; the internal IP address and port number of device B => External IP address and port number: 192.168.2.10:7777 = > 173.21.59.10:17777.

NAT can also be called NA(P)T because the Port is translated at the same time, that is, the Port is mapped.

5. Internet Control Message Protocol (ICMP)

1) ICMP protocol disassembly

function

The ICMP protocol is mainly used to assist the IP protocol to send and receive data. It can report error messages or exceptions.

ICMP Packet Structure

ICMP is encapsulated in IP datagram data, which is also divided into packet header and packet data. If the ICMP protocol is used, you need to write 1 in the 8-bit protocol header of the IP protocol to indicate that the specific data carried by the IP data is ICMP.

type

1. Error report message

Error report packets are divided into seven types. Most of the packet types consist of the type value and specific code. The details are shown in the figure below:

2. Query the message

There are two types of query messages, which are determined only by the value of the type. The details are shown in the figure below:

The common PING query packet is an ICMP query packet that actively requests and receives an active response. It is as follows:

  • ICMP ECHO REQUESTZ:Network packet capture is performed on the active request of ping.
  • ICMP ECHO REPLY:An unsolicited reply.

Therefore, the packets sent by ping are also ICMP compliant, with only their own format added. As follows:

  • 1) Identifier: Two teams of scouts were sent, one to investigate the battle situation, and the other to find water. Only an identifier could distinguish them.
  • 2) Serial number: All the scouts sent out should be numbered so as to know the battle situation on the front line.
  • 3) Sending request time value: stored in the option data, used to calculate the round-trip time and the length of the journey.

When the ping command is executed, the source host constructs an ICMP request packet. The two most important fields are as follows:

  • 1), type: For request packets, this value is 8.
  • 2) Sequence number: distinguish multiple request packets sent during continuous ping. Each time a request packet is sent, the sequence number automatically increases by 1.

2) Application of ICMP packets

Ping application

For example, the following information is displayed on ping www.wanandorid.com:

quchao@quchaodeMacBook-Pro cmmp-core-client-android % ping www.wanandroid.com
PING www.wanandroid.com (47.10474.169.) :56 data bytes
64 bytes from 47.10474.169.: icmp_seq=0 ttl=51 time=51.877 ms
64 bytes from 47.10474.169.: icmp_seq=1 ttl=51 time=52.416 ms
64 bytes from 47.10474.169.: icmp_seq=2 ttl=51 time=48.942 ms
64 bytes from 47.10474.169.: icmp_seq=3 ttl=51 time=45.816 ms
64 bytes from 47.10474.169.: icmp_seq=4 ttl=51 time=48.336 ms
64 bytes from 47.10474.169.: icmp_seq=5 ttl=51 time=42.358Ms c64 bytes from 47.10474.169.: icmp_seq=6 ttl=51 time=49.428 ms
64 bytes from 47.10474.169.: icmp_seq=7 ttl=51 time=41.963 ms
Copy the code

Run the Ping command to troubleshoot the network fault

When you encounter a network failure, in addition to directly ping the target IP address, you should also have a clear network topology, and clearly know which devices a packet passes through from the source address to the destination address, and then ping each of these devices or machines in the middle. The usual troubleshooting steps are as follows:

  • 1) Ping the loopback address 127.0.0.1 fails, indicating that there is a problem with the protocol stack used by the computer and the system or protocol stack needs to be reinstalled.
  • 2) Ping the gateway address (routing address) and Ping 192.168.0.1/192.168.1.1 from the internal network, indicating that the IP address from the local computer to the router is connected. If no, the WIFI and network cable are faulty.
  • 3) If the remote address can be pinged from www.wanandroid.com, the connection between the ISP network and the home is faulty. This time from telecom, Unicom, mobile and other ISP to troubleshoot the problem.

In addition to ping, we can also use tcpdump -I eth0 ICMP to see if the outgoing packet reached a certain point and the returned packet reached a certain point to make it easier to infer the location of the error.

Does ping difference necessarily mean the network is disconnected?

No, many intermediate devices are disabled from ping if they are not in our control, but a ping failure does not mean a network failure. At this time, you need to use Telnet to test whether the network is smooth through other protocols.

Traceoute application

It is used to detect the path of IP datagrams across the network.

In the header of an IP datagram, there is an 8-bit TTL, which represents the lifetime of the IP data packet in the network. The TTL decreases by 1 every time the IP data packet passes through a device. When the TTL is 0, the network device must discard the IP packet and send an ICMP unreachable error packet.

Traceoute uses the ICMP destination unreachable error packet and TTL mechanism. In order to detect the path of the IP data packet, it sends a UDP packet. Set the TTL to 1 so that once a router is encountered, it is sacrificed. It then returns an ICMP packet, which is a network error packet of type time out, and tells you how far away a router is. The specific mechanism is as follows:

  • 1) First, it encapsulates a data packet with TTL of 1. When it reaches the first network, the TTL is reduced to 0. The first network finds that the TTL is reduced to 0 and sends an ICMP error packet with unreachable destination to the source host. At this point the source host will record the IP address of the first network.
  • 2) then, it encapsulates a data packet with a TTL of 2. When it reaches the second network, the TTL is reduced to 0. The second network finds that the TTL is reduced to 0 and sends an ICMP error packet with an unreachable destination to the source host. At this point the source host will record the IP address of the second network.
  • 3) Follow the TTL + 1, the network order of arrival + 1 rule, until the destination host, finally get the IP address of the destination host.

In this way, the source host receives all the path information and can output the path of the datagram across the network. The following is an example of the traceroute command:

Tracert github.com (tracert github.com for Windows) Quchao@quchaodeMacBook-Pro cmmp-core-client-android % traceroute github.com
traceroute to github.com (13.250177.223.), 64 hops max, 52 byte packets
1  22.493.254. (22.493.254.)  11.676 ms  7.331 ms  9.620 ms
2  59.40180.129. (59.40180.129.)  977.679 ms  440.943 ms  10.672 ms
3  49.18637.59..broad.dg.gd.dynamic.163data.com.cn (59.37186.49.)  9.207 ms  12.436 ms  10.636 ms
4  125.17637.59..broad.dg.gd.dynamic.163data.com.cn (59.37176.125.)  13.202 ms  10.292 ms  28.478 ms
5  183.5665.6. (183.5665.6.)  11.763 ms  9.236 ms
183.5665.18. (183.5665.18.)  11.392 ms
6  202.9794.134. (202.9794.134.)  18.357 ms
202.9794.150. (202.9794.150.)  18.175 ms
202.9794.134. (202.9794.134.)  36.600 ms
7  202.9794.98. (202.9794.98.)  245.161 ms
202.9712.29. (202.9712.29.)  19.504 ms
202.9712.. 41 (202.9712.. 41)  22.256 ms
Copy the code

Why is it possible to look for an IP address without seeing some router information in the middle?

Because some routers don’t return the ICMP packet at all.

6, routing,

1) Route overview

The routing table contains the mapping between the destination IP address and the next hop IP address.

Autonomous System

  • An autonomous system (AS) is a network device group under a management organization.
  • An AS internal network is managed by itself and provides one or more entrances and exits.

In terms of network classification, each backbone ISP can be considered AS a backbone AS, each regional ISP can be considered AS a regional AS, and each company, campus, and family can be considered AS a small AS.

2) Routing protocol

  • Internal routing protocol: Internal Gateway protocol (RIP, OSP)
  • Protocol for external routes as: External Gateway Protocol (BGP)

For example, the gateway protocol used directly by home AS1 and company AS2 is shown as follows:

We can convert the network topology diagram into a diagram where

  • Each vertex represents a network, router, or computer.
  • Each edge represents a network path.

The essence of routing algorithm is graph theory algorithm, but because of the complex network environment, routing algorithm is more complicated than graph theory algorithm.

How to design a good routing algorithm?

  • 1) Correct and complete: the algorithm is correct and complete.
  • 2) Simple calculation: The algorithm should be as simple as possible in calculation.
  • 3) Adapt to changes: The algorithm can adapt to various changes in the network.
  • 4) Stability and fairness: The algorithm is stable and published.

1. Routing Information Protocol (RIP) of the internal gateway Routing Protocol

Distance vector (DV) algorithm
  • 1) Use two vectors Di and Si for each node.
  • 2) Di describes the distance between the current node and other nodes.
  • 3) Si describes the next node from the current node to another node.
  • 4) First, each node will exchange information about vectors Di and Si with its neighboring nodes.
  • 5) Each node updates its own node information according to the exchanged information: first of all, calculate, then compare the current calculation result with the distance vector, if the distance is smaller, then update its own distance vector.
Features of RIP
  • 1) RIP is a routing protocol using DV algorithm.
  • 2), the number of network (Hop) as the distance of DV algorithm.
  • 3) RIP switches routing information every 30s.
  • 4) RIP considers the route whose hop count is greater than 15 to be unreachable.
Procedure of RIP
  • 1. The router initializes the routing information (the two vectors Di and Si).
  • 2,This section describes how to modify the message sent by neighboring router X.
    • 1) Retrieve the local route and insert the new route from the information into the routing table.
    • 2) Retrieve the local route. If the next hop is X, update it to the modified information.
    • 3) Retrieve the local route and compare the distance to the same destination. If the distance of the new information is smaller, update the routing table.
  • 3. If no information about the adjacent route is received within 3 minutes, the adjacent route is set to unreachable (16 hops).
Advantages of RIP

Simple implementation and low overhead.

Disadvantages of RIP

Suppose there is an A-B-C link. If node A fails to work, node B and NODE C ask each other for the total number of hops until they exceed 15.

  • 1) Trust adjacent nodes.
  • 2), they do not think, limited vision, resulting in slow transmission of fault information.
  • 3) It limits the size of the network and can only be used in smaller networks because it considers those with hops greater than 15 unreachable.

2. OSPF of the internal gateway routing protocol

Link State (LS) protocol

Differences with RIP:

  • 1) Send messages to all routers.
  • 2) The message describes the link status between the router and its neighbors.
  • 3) The update message is sent only when the link state transmission changes.

Therefore, it can be seen that THE LS protocol solves the problem of RIP that the route next door is trusted casually and the vision is insufficient.

Dijkstra algorithm

Features:

  • 1) Dijistra algorithm is a famous graph algorithm, which solves the problem of computing the shortest path.
  • 2) Solve the shortest path problem from one node to other nodes in the graph.
  • 3) Take the starting point as the center and expand outwardly.

Process:

  • 1, initialize two sets (S, U) (S is the set with only the initial vertex point A, U is the set of other vertices).
  • 2,If U is not empty, sort the vertex of the set U by distance, and take the vertex D closest to A:
    • 1) include vertex D into set S.
    • 2), update the distance from vertex D to all points in U set (update if the distance is smaller, otherwise do not update).
    • 3) Repeat step 2.
  • 3. The algorithm is completed until the U set is empty.
The process of opening the Open Shortest Path First (OSPF) protocol

The core is Dijkstra’s algorithm.

  • 1) Send messages to all routers, so that each router can get all the information in the network, and thus get the complete network topology (link-state database). Furthermore, each router can use Dijikstra to find its own shortest path to a particular vertex.
  • 2) The message describes the link status (distance, delay, bandwidth) between the router and its neighbors. Therefore, OSPF is more objective and advanced than RIP.
  • 3) Update information is sent only when the link state changes, which makes the router reduce data exchange and enable faster convergence.

Then, let’s review the whole process:

  • First, the router accesses the network.
  • The router then sends a greeting message to the neighbor to confirm the reachabability.
  • After confirmation, the system communicates with the neighbor and synchronizes the link-state database to the latest one.
  • Finally, the router broadcasts and updates the unknown route.
Five message types
  • 1) Hello message: test the reachabability between the router and its neighbor.
  • 2) Description information of link-state database: it is used to send some simple description information of its own link-state to neighboring routers.
  • 3) Link-state request information: used to request link-state data from neighboring routers.
  • 4) Link state update information: the most frequently used and most important information.
  • 5) Confirmation of link status: a confirmation of link updates.
Comparison between RIP and OSPF
RIP OSPF
Look at the network from the neighborhood The topology of the entire network
Add distances between routers Dijkstra computes the shortest path
Frequent, periodic update, convergence is slow State changes update, convergence is fast
Copy routing information between routes Transfer link status between routes and calculate paths by themselves
The disadvantage of OSPF

Although OSPF solves the RIP problem and provides a global view of the entire network, OSPF is complex and expensive to implement.

3) External Gateway routing protocol BGP(Border Gateway Protocol) marginal Gateway protocol

  • BGP is a protocol that runs between AS.
  • BGP is proposed because of the complexity of human factors in the computer network. In the actual network environment, data transmission is also affected by remediation and security factors.

Why use BGP between ass?

  • 1) The scale of the Internet is very large, which makes it very difficult to select routes between AS. If we choose link-state protocol between AS, each router needs to store a lot of link-state data. Moreover, if Dijikstra algorithm is used, the operation will be slow, so BGP protocol is needed.
  • 2) Different routing protocols are used in AS. For example, RIP is used in one AS, while OSPF is used in another AS. Routers that use different protocols cannot communicate with each other. Therefore, they need to use BGP to coordinate.
  • 3) Some factors besides network characteristics, such AS politics and security, should be considered between AS.

Due to policy and security reasons, BGP can only find a good route to the destination. AS use BGP speakers to exchange routing information.

Data link layer

1. Main functions

1) Encapsulation into frames

What is a data frame?

  • A frame is the basic unit of data at the data link layer.
  • The sender adds specific tags before and after a piece of data at the network layer to form a frame.
  • The receiver recognizes the frame based on a specific mark before and after it.

Data frame structure

  • When the network layer transmits IP datagrams to the data link layer, frame headers and frames are added before and after IP datagrams at the data link layer.
  • The beginning and end of the frame are specific control characters, that is, some specific bit streams, such as SOH:00000001 at the beginning of the frame and EOT:00000100 at the end of the frame.

What if the data happens to have these bits in it?

2) Transparent transmission

What is transparent transmission?

  • 1) A very important term in the field of computing. For example, for the data link layer, the work done by the physical layer is transparent. The physical layer only needs to expose the interface.
  • 2) Something that actually exists but looks as if it does not.
  • 3) Even if the control characters are in the frame data, they should be treated as if they do not exist.

Application of transparent transmission

What if the data happens to have these control characters in it?

Add an ESC escape character before the control character. If the data contains an ESC escape character, add another ESC escape character before the control character. Escape characters at the data link layer can be likened to escape characters in programming languages.

3) Error monitoring

Why do error monitoring?

So the physical layer just transmits the bit stream and has no control over whether something goes wrong. So the data link layer is responsible for error monitoring.

Methods of error monitoring

1. Parity code

Add the parity check code (1/0) to the end of the bitstream. For example: 00110100 => The sum of all bits is 3, which is the base number, and add 1 to the end of the bitstream. (even plus 0)

Its limitation is that it cannot detect errors when two bits are wrong in the bitstream.

2, CRC (cyclic redundancy check code)
  • 1) a method of generating a fixed-bit parity check code according to the data transmitted or saved.
  • 2) Check for possible errors after data transmission or saving.
  • 3) The generated numbers are calculated and appended to the data.

CRC uses modular 2 division, namely: when the highest bit is 0, the remainder is considered insufficient to divide, and the quotient is 0.

Adding a verification code to the sender:

  • 1) Select a polynomial G(x) for verification (for example, CRC-7 and CRC-8 represent that the highest bit in G(x) is 8), and add R zeros to the end of the data.
  • 2) Divide the data after r zeros by the module 2 division by the bit string of the polynomial.
  • 3) Fill the remainder of the obtained number in the position of R zeros of the original data to obtain a verifiable bit string.

Verification code of receiver:

  • The received data is divided by G(x) bit string. If the remainder is 0, the verification is successful.

disadvantages

  • 1) The larger the order r of bit string, the stronger the error detection ability of CRC. (Degenerate odd-check code when the order is 1)
  • 2) The data link layer only checks the data, but does not correct it. If the wrong data is detected, the data will be discarded.

2. Maximum Transmission Unit (MTU)

1), MTU

Why design an MTU?

Data frames that are too large or too small will affect the efficiency of transmission. For example, it increases the total delay of data transmission. An Ethernet MTU is 1500 bytes.

2) Path MTU

Is determined by the minimum MTU of all Mtus in the transmission link.

3. Ethernet protocol

1), MAC address (physical address, hardware address)

The characteristics of

  • Each device has a unique MAC address.
  • A MAC address contains 48 bits in hexadecimal format. Example: 30-b4-9e-ED-85-da.

Check the MAC address of the computer

  • MAC: ifconfig
  • Windows:ipconfig /all

The MAC address table

There is a mapping between MAC addresses and hardware interfaces. Each MAC address has a corresponding hardware interface.

2) Content of agreement

The characteristics of

  • A widely used LAN technology.
  • A protocol applied to the data link layer.
  • With the help of it, data frame transmission between adjacent devices can be completed.

The data format

The unit is byte.

What is the frame data?

  • If it is IP data at the network layer, the type is 0800 and frame data = IP datagram.
  • If it is an ARP request/reply, the type is 0806. Frame data = ARP request/reply (28 bytes) + PAD (18 bytes).
  • For RARP request/reply, the type is 8035, frame data = RARP request/reply (28 bytes) + PAD (18 bytes)

Data transmission process

  • 1) Device A sends data frames through the network adapter.
  • 2) When the data frame reaches the router, the router takes out the first 6 bytes, that is, the MAC address of destination device B.
  • 3) The router matches the MAC address table and finds the network interface of destination device B.
  • 4) The router sends data frames to the network interface.

If the MAC address does not know the hardware interface of B, what does the router do?

  • 1. E checks the MAC address table and finds no information about C.
  • 2. E broadcasts packets from A to ports other than A.
  • 3) E will receive the response from B and C and record the address.

Physical layer

1,

  • 1) Connect different physical devices
  • 2) Transmit a bit stream

What is bitstream?

For data streams represented by high and low electrical frequencies, 1 => high electrical frequency, 0 => low electrical frequency. For example, digital signals converted from bitstream 100110101010 are shown in the figure below:

2, common transmission media

1), wired media

1. Twisted pair cable

Unshielded twisted pair cable

From the outside to the inside by PVC sleeve layer, insulation layer, copper wire composition.

Twisted-pair cable

Unlike the unshielded twisted-pair, the second layer is shielded.

2. Coaxial cable

From the outside to the inside by the insulation protective sleeve layer, outer conductor shielding layer, insulation layer, the conductor composition.

3, optical fiber

Optical fibers consist of cladding (medium with low refractive index) and core (medium with high refractive index).

2) Wireless media

  • 1) Infrared
  • 2) Wireless (e.g. 4G, WIFI)
  • 3) Laser

3. Basic concept of channel

  • A channel is a medium that transmits information in one direction.
  • A communication circuit consists of a receiving channel and a transmitting channel.

How do I handle sending and receiving conflicts?

Classification of channels

  • 1) Simplex channel: can only communicate in one direction, without feedback information in the opposite direction. Such as cable television, radio sets and so on.
  • 2) Half-duplex channel: both parties can send and receive information. It cannot be sent and accepted at the same time.
  • 3) Full-duplex channel: Both parties can send and receive information at the same time. For example, network cables, networks, and so on.

4. Division and reuse

Classification of reuse

  • 1) Frequency division multiplexing
  • 2) Time division multiplexing
  • 3) Wavelength division multiplexing
  • 4) Code division multiplexing

Xi. Summary

Computer network is a basic subject that we need to continue to explore in depth. In this paper, we have a comprehensive understanding of the core basic knowledge of computer network, which lays a certain network foundation for us to discuss the problems related to mobile network optimization later. The journey of network optimization has just begun

High-frequency problems in computer networks can be viewed here.

Reference links:


  • 1, moOCs “Programming essential Basic computer principles + Operating System + computer Network” network part of chapter 9-13
  • 2. Chapter 1-5, An Interesting Discussion on Network Protocols
  • 3. First 6 chapters of the Top-down Approach to Computer Networking
  • 4, (recommended intensive reading)HTTP soul question, strengthen your knowledge of HTTP
  • The soul of the TCP protocol, to consolidate your network base
  • A little sister of the front end of 50,000 words interview bible
  • Interview with you fly: this is a comprehensive summary of the basic computer network strategy
  • 8. JavaGuide – Networking
  • 9. Interview – Network
  • 10. Summarized the interview experience of one hundred front-end interviews from the beginning of 17 to the beginning of 18 (including answers)
  • 11. Cs-notes – Network

Thank you for reading this article. I hope you can share it with your friends or tech groups. It means a lot to me.

I hope we can be friends beforeGithub,The Denver nuggetsLast time we shared our knowledge.