Summary of basic knowledge of computer network (4) - network layer

1 Overview

Because the network layer is the core of the entire Internet , it should be as simple as possible. The network layer provides only simple, flexible, connectionless, best-effort interactive datagram services upwards. 

Using the IP protocol, heterogeneous physical networks can be connected to make it look like a unified network at the network layer.

There are three other protocols  used in conjunction with the IP protocol :

  • Address Resolution Protocol ARP (Address Resolution Protocol)
  • Internet Control Message Protocol ICMP (Internet Control Message Protocol)
  • Internet Group Management Protocol IGMP (Internet Group Management Protocol)

2. IP datagram format

  • Version: There are two values ​​4 (IPv4) and 6 (IPv6);
  • Header length: 4 bits, so the maximum value is 15. A value of 1 indicates the length of a 32-bit word, which is 4 bytes. Since the fixed part length is 20 bytes, the minimum value is 5. If the length of the optional field is not an integer multiple of 4 bytes, it will be filled with the padding part at the end.
  • Differentiated services: used to obtain better services, generally not used.
  • Total length: including header length and data part length.
  • Time to live: TTL, which exists to prevent undeliverable datagrams from constantly circling the Internet. Datagrams are discarded when the TTL is 0 in units of router hops.
  • Protocol: Indicate which protocol the carried data should be handed over to for processing, such as ICMP, TCP, UDP, etc.
  • Header checksum: Because each time a datagram passes through a router, the checksum must be recalculated, so the checksum does not include the data part, which can reduce the workload of calculation.
  • IDENTIFICATION: Different fragments of the same datagram have the same identifier in the case of a datagram that is too long to be fragmented.
  • Fragment Offset: Together with the identifier, it is used in the case of fragmentation. The unit of slice offset is 8 bytes.

Fragmentation example of a datagram:

3. IP addressing method 

The addressing method of IP address has gone through three historical stages:

  • Classification
  • subnetting
  • no classification

3.1 Classification

It consists of two parts, the network number and the host number. Different categories have different network number lengths and are fixed.

IP address::= {<network number>, <host number>}

3.2 Subnetting 

By taking part of the host number field as the subnet number, the two-level IP addresses are divided into three-level IP addresses.

IP address::= {<network number>, <subnet number>, <host number>}

To use a subnet, a subnet mask must be configured. The default subnet mask of a class B address is 255.255.0.0. If the subnet of a class B address occupies two bits, the subnet mask is 11111111 11111111 11000000 00000000, which is 255.255.192.0.

Note that the external network does not see the existence of the subnet.

3.3 No classification

Classless addressing CIDR eliminates traditional Class A, Class B and Class C addresses and the concept of subnetting. It uses network prefixes and host numbers to encode IP addresses. The length of network prefixes can be changed as needed.

IP address::= {<network prefix number>, <host number>}

CIDR notation adopts the method of adding the length of the network prefix after the IP address , for example, 128.14.35.7/20 means that the first 20 bits are the network prefix.

The CIDR address mask can continue to be called the subnet mask , and the length of the first 1 of the subnet mask is the length of the network prefix.

There are many addresses in a CIDR address block, and a network represented by a CIDR can represent many original networks, and only one route is needed in the routing table to replace the original multiple routes, reducing the number of routing table entries. This method of reducing routing table entries by using network prefixes is called route aggregation, also known as forming a supernet.

The items in the routing table are composed of "network prefix" and "next hop address". More than one matching result may be obtained during the search, and the longest prefix match should be used to determine which one should be matched.

4. Address Resolution Protocol ARP

The network layer implements communication between hosts , while the link layer implements communication between specific links. Therefore, during the communication process, the source address and destination address of the IP datagram remain unchanged , while the MAC address changes as the link changes .

ARP implementation obtains MAC address from IP address:

Each host has an ARP cache , which contains the mapping tables from IP addresses to MAC addresses of hosts and routers on the local area network. If host A knows the IP address of host B, but there is no mapping from the IP address to the MAC address in the ARP cache, then host A sends an ARP request packet by broadcast, and host B sends an ARP response packet after receiving the request Inform Host A of its MAC address, and then Host A writes the mapping of Host B's IP address to MAC address into its cache.

5. Internet Control Message Protocol ICMP

ICMP was created to more efficiently forward IP datagrams and improve the chances of successful delivery. It is encapsulated in IP datagrams, but is not part of higher-level protocols.

 ICMP messages are divided into error report messages and query messages:

5.1 Ping

Ping is an important application of ICMP, mainly used to test the connectivity between two hosts .

The principle of Ping is to send an ICMP Echo request message to the destination host, and the destination host will send an Echo reply message after receiving it. Ping estimates packet round-trip time and packet loss rate based on time and number of successful responses.

5.2 Traceroute

Traceroute is another application of ICMP, which is used to trace the path of a packet from source to destination .

The IP datagram sent by Traceroute encapsulates the undeliverable UDP user datagram , and the destination host sends a destination unreachable error report message.

  • The source host sends a series of IP datagrams to the destination host. The TTL of the first datagram P1 is set to 1. When P1 reaches the first router R1 on the path, R1 accepts it and reduces the TTL by 1. At this time, the TTL is equal to 0, and R1 discards P1 and Send an ICMP time exceeded error report message to the source host;
  • The source host then sends a second datagram, P2, with a TTL of 2. P2 arrives at R1 first, R1 decrements the TTL by 1 and forwards it to R2 after accepting it, and R2 also decrements the TTL by 1 after accepting it. Since the TTL is equal to 0 at this time, R2 discards P2 and sends an ICMP time exceeded error message to the source host message.
  • Continue to perform such steps until the last datagram has just arrived at the destination host, and the host does not forward the datagram and does not decrease the TTL value by 1. But because the datagram encapsulates undeliverable UDP, the destination host will send an ICMP destination unreachable error report message to the source host.
  • The source host then knows the IP addresses of the routers it traveled to reach the destination host and the round-trip time to each router.

6. Virtual Private Network VPN

Due to the shortage of IP addresses, the number of IP addresses that an organization can apply for is often far less than the number of hosts owned by the organization. And an organization does not need to connect all the hosts to the external Internet, and the computers in the organization can use the IP addresses (private addresses) that are valid only in the organization.

There are three private address blocks:

  • 10.0.0.0 ~ 10.255.255.255
  • 172.16.0.0 ~ 172.31.255.255
  • 192.168.0.0 ~ 192.168.255.255

Use the public Internet as the communication carrier between the private networks of this institution. Dedicated means that the hosts in the organization only communicate with other hosts in the organization; virtual means that it seems to be, but it is not, that it has a public Internet.

In the figure below, the communication between sites A and B passes through the Internet. If host X in site A wants to communicate with host Y in another site B, the source address of the IP datagram is 10.1.0.1, and the destination address is 10.2.0.3. The datagram is first sent to the router R1 connected to the Internet, R1 encrypts the internal data, and then adds the header of the datagram again, the source address is the global address of router R1 125.1.2.3, and the destination address is the global address of router R2 194.4. 5.6. After receiving the datagram, router R2 decrypts the data part and restores the original datagram. At this time, the destination address is 10.2.0.3, and it is delivered to Y.

 

7. Network Address Translation NAT

When the host inside the private network uses the local IP address and wants to communicate with the host on the Internet, NAT can be used to convert the local IP to the global IP.

In the past, NAT made a one-to-one correspondence between local IP and global IP . In this way, only n hosts can access the Internet at the same time in a private network with n global IP addresses. In order to make more effective use of the global IP address, the commonly used NAT translation table now also uses the port number of the transport layer, so that multiple hosts in the private network share a global IP address. NAT using port numbers is also called Network Address and Port Translation NAPT.

8. Router

8.1 Structure of router

Functionally, routers can be divided into: routing and packet forwarding .

The packet forwarding fabric consists of three parts: a switching fabric , a set of input ports , and a set of output ports .

8.2 Router packet forwarding process

  • Extract the IP address D of the destination host from the header of the datagram to obtain the destination network address N;
  • If N is a network address directly connected to this router, direct delivery is performed;
  • If there is a specific host route with the destination address D in the routing table, the datagram is sent to the next-hop router specified in the table;
  • If there is a route to network N in the routing table, the datagram is sent to the next-hop router specified in the routing table;
  • If there is a default route in the routing table, send the datagram to the default router indicated in the routing table;
  • Report an error in forwarding packets.

8.3 Routing Protocols

Routing protocols are all self- adaptive, and can be adjusted adaptively with changes in network traffic and topology. The Internet can be divided into many smaller autonomous systems AS, and one AS can use a different routing protocol from other ASs.

Routing protocols can be divided into two categories:

  • Routing within an Autonomous System: RIP and OSPF
  • Routing between autonomous systems: BGP

1) Interior Gateway Protocol RIP

RIP is a distance vector based routing protocol. The distance refers to the number of hops, and the hop number of a directly connected router is 1. The maximum number of hops is 15, and more than 15 means unreachable.

RIP only exchanges its own routing table with neighboring routers at fixed time intervals. After several exchanges, all routers will eventually know the shortest distance to any network in the autonomous system and the address of the next-hop router.

Distance vector algorithm:

  • For the RIP message sent by the neighboring router whose address is X, first modify all the items in the message, change the address in the next hop field to X, and add 1 to all the distance fields;
  • For each item in the modified RIP message, perform the following steps:
  • If there is no destination network N in the original routing table, add this item to the routing table;
  • Otherwise: if the next-hop router address is X, replace the item in the original routing table with the received item; otherwise: if the distance d in the received item is smaller than the distance in the routing table, update it (for example, the original route The entry is Net2, 5, P, and the new entry is Net2, 4, X, then update); otherwise, do nothing.
  • If the updated routing table of the adjacent router has not been received within 3 minutes, the adjacent router is marked as unreachable, that is, the distance is set to 16.

The implementation of the RIP protocol is simple and the overhead is small. However, the maximum distance that RIP can use is 15, which limits the scale of the network. And when the network fails, it will take a long time to transmit this message to all routers.

2) Interior Gateway Protocol OSPF

Open Shortest Path First OSPF is developed to overcome the shortcomings of RIP.

Open means that OSPF is not controlled by a certain manufacturer, but published publicly; shortest path first means that the shortest path algorithm SPF proposed by Dijkstra is used.

OSPF has the following characteristics:

  • Send information to all routers in the autonomous system, this method is the flooding method.
  • The information sent is the state of the link with the adjacent routers. The link state includes which routers are connected to and the metric of the link. The metric is represented by cost, distance, delay, bandwidth, etc.
  • Routers send information only when the link state changes.

All routers have a topological map of the entire network and are consistent. Compared with RIP, the update process of OSPF converges very quickly.

3) Exterior Gateway Protocol BGP

BGP (Border Gateway Protocol, Border Gateway Protocol), routing between AS is difficult, mainly due to:

  • The Internet is massive;
  • Different routing protocols are used inside each AS, and the measurement of the path cannot be accurately defined;
  • The routing selection between ASs must take into account related policies, for example, some ASs are not willing to let other ASs pass through.

BGP can only find a better route, not the best route . Each AS must be configured with a BGP speaker, and exchange routing information by establishing a TCP connection between two adjacent BGP speakers.

References:

  • Computer Network, Xie Xiren
  • JamesF.Kurose, KeithW.Ross, Kurose, et al. Computer Networks: A Top-Down Approach[M]. Mechanical Industry Press, 2014.
  • W.RichardStevens. Detailed Explanation of TCP/IP. Volume 1, Protocol [M]. Machinery Industry Press, 2006.

Guess you like

Origin blog.csdn.net/daydayup858/article/details/129184069