Network Four [Transition point between physics and logic: detailed network layer]

1. What did the network layer do? What is IP?

Regardless of what the network layer is doing, let's look at such a five-layer network structure diagram:

The orange layer is called the network layer.

Through the figure, we can find that

The main protocols of the network layer are: ARP, IP, ICMP, IGMP

Among them, IP accounts for most of the country.

And what is IP?

The full name of IP is Internet Protocol-Internet Protocol.

As we learned earlier, the agreement is established between peer entities.

In other words, if you want to exchange data in an orderly manner on the network,

It must follow some pre-agreed rules.

These rules clearly specify the format of the data exchanged, as well as related synchronization issues.

The agreement consists of three parts:

Syntax: specifies the format of the transmitted data

Semantics: specifies the function to be completed

Synchronization: specifies the conditions and timing relationships for performing various operations, etc.

The entities at the network layer are called datagrams, or packets,

So what the IP protocol does is:

The entity of the network layer: datagram, specifies a unified format, called IP datagram.

Let's take a look at the format of the IP datagram:

First of all, his data part is the protocol data unit passed down by the transport layer.

Then there is a header,

The header information is as follows: 

All data to be transmitted at the network layer must add the header of the above format,

Follow the information corresponding to each field in this header.

For example, the IP version number used, its own length, source address and destination address, etc.

It should be emphasized that the second field in the third row is the protocol field.

Personal understanding:

IP itself is a large protocol that specifies the datagram header of such a format,

The data inside can be used for routing selection: then they follow protocols such as OSPF or IGP;

It can also be dynamically assigned IP addresses: then they follow the DHCP protocol (based on UDP).

In other words, the IP protocol is like a creator of the world. He stipulates that a person has a head, two arms and two legs, and wears clothes.

As for the specific clothes to wear, it depends on what the person wants to do.

If a person is a takeaway and wears a company’s takeaway clothes,

Then food delivery is the semantics of this data;

Wearing the company’s takeaway clothes is the protocol followed by this data. If I am a takeaway from company A, then I am responsible for the delivery from area A to area B. How many hours will it take to complete, whether speed is priority or quality is priority;

I am a takeaway from Company B, so I am responsible for passing from one city to another.

The express company is like the internal gateway protocol IGP and the external gateway protocol EGP,

The takeaway is like the content of the message under the OSPF protocol.

The whole takeaway person has one head, two arms and two legs, and wears clothes. The rule is IP packets.

After understanding the IP protocol, let's talk about what the network layer does.

First of all, the network layer unifies the format of the data in this layer through the IP protocol.

After unifying the format,

1. The primary function of the network layer is to transmit data.

The transport layer passes the protocol data unit of the transport layer-the message to the network layer, and the network layer plus the IP header becomes an IP datagram.

Here need to use routers and routing algorithms to transmit to the network layer of the destination.

However, the data in the IP datagram here is based on a logical level.

No matter what protocol is used at the network layer, the hardware address must be used in the end when transmitting data frames on the actual network link.

In order to deliver to the data link layer, we need to use the ARP protocol (Address Resolution Protocol),

To complete the mapping from IP address to MAC address.

In this way, the rest is handed over to the data link layer for framing, error control, flow control, etc.,

Then to the physical layer, the physical layer converts the data into a signal, and transmits it to the other party's physical layer, and then to the other party's link layer and network layer.

This forms a data exchange between the network layer and the network layer.

2. To unify the format of IP datagrams, another purpose is to interconnect heterogeneous networks.

The use of physical layer or data link layer relay systems (repeaters, switches, etc.) is nothing more than expanding a network.

But from the perspective of the network layer, it is still a network.

Since we have adopted standardized protocols at the network layer,

So we can connect various physical heterogeneous networks through routers,

Become a virtual IP network.

3. Congestion control 

If all nodes are too late to accept the packet, but want to discard a large number of packets,

The network is in a state of congestion.

Congestion control is to ensure that the subnet can carry the reached traffic, which is a global process.

 

2. Functions of the network layer and data exchange methods

The network layer mainly has the following functions:

Function 1: routing and packet forwarding

The router performs two functions:

1. Route selection: First, choose the nearest or relatively close route.

2. Packet forwarding: After the route is determined, it needs to be sent out from the appropriate port.

Function 2: Heterogeneous network interconnection

Connecting various physical networks with different performances into a logical network makes these networks look like a unified network at the IP layer.

Function 3: Congestion control

Congestion control is to ensure that the subnet can carry the traffic reached.

 

Why do we need to exchange data?

The exchange is through some exchange centers, the data is concentrated and transmitted.

The transmission line is shared by all users, which greatly saves communication lines and reduces system costs.

There are three ways in total:

Among them, packet switching is divided into datagram mode and virtual circuit mode.

1. Circuit switching

principle:

Establish a dedicated physical connection line composed of intermediate nodes between the source node and the destination node.

Until the end of the data transmission, this line has been maintained. 

stage:

Advantages: exclusive resources, small communication delay, orderly, no conflicts;

Disadvantages: Poor flexibility, because of the monopoly of resources, the overall use efficiency is low, and it is difficult to standardize.

2. Message exchange

The unit of data exchange is a message.

Use store-and-forward mode.

The length is inconsistent, and the length is unlimited and variable.

Advantages: dynamic allocation of lines to improve line utilization

Disadvantages: Poor real-time performance, only suitable for digital signals, and because the length of the message is unlimited, a large buffer is required for each node.

3. Packet switching

Packet switching solves the problem of large message transmission in message switching.

That is, the exchange mode of the IP layer.

 Three ways to illustrate:

4. Datagram method

1. The source host A divides the message into multiple packets and sends them to the directly connected node A in turn.

2. After receiving the packets, A performs error detection and routing for each packet, and the next node of different packets may be different.

3. After node C receives packet P1, it performs error detection on P1. If it is correct, it sends an acknowledgment message to A. After receiving C's confirmation, node A discards the copy of packet P1.

4. All packets arrive at destination B.

The connectionless method does not guarantee the orderly arrival of packets and reliable communication. 

5. Virtual circuit mode 

The virtual circuit provides connection services for the network layer. A logical link is established between the source node and the destination node, rather than an actual physical connection.

The orderly arrival of packets is guaranteed, and the reliability is guaranteed by the network.

Fatal shortcomings: a single failure, all virtual circuits passing through the faulty node cannot work normally. 

Three, IPv4

IPv4 refers to the commonly used IP, and the version number is 4.

The IP protocol defines the basic unit of data transmission-IP packet and its exact data format.

IP also includes a set of rules that specify how to process packets and how to control errors.

The format of the IPv4 packet is as follows:

If the total length of the IP datagram is greater than the maximum transmission unit of the link layer, such as Ethernet is 1500B, and many WANs do not exceed 576B, then the data in the IP datagram needs to be divided into multiple smaller IP data packets. These smaller datagrams are called slices. 

Four, IPv4 address

IPv4 address: A unique 4-byte identifier in the world that identifies the interface of the router host.

Its address consists of two parts: {"Network Number", "Host Number"}.

The network number indicates the network to which the host or router is connected;

The host number identifies the host or router.

There are five types of addresses:

Special IP address

Some of the IP addresses have special uses and are not used as host IP addresses:

If the host number is all 0, it means the network itself;

If the host number is all 1, it means the direct broadcast address of this network, broadcast to all hosts on the specific network;

If the 32 bits are all 0s, that is 0.0.0.0, it means the host on this network;

If the 32 bits are all 1, that is 255.255.255.255, it means the broadcast address of the entire TCP/IP network, also known as the restricted broadcast address, and the router will not forward it;

127.0.0.0 is reserved as the loop self-test address, which represents any network itself and is used for local self-test.

 

Five, private IP address and network address translation NAT

First of all, why divide private IP addresses?

Two reasons:

1. The IP address is limited, and the IP address is a globally unique identifier. After the private IP address is drawn, these private IP addresses can be reused in different networks, which greatly saves the consumption of IP addresses;

2. For network security, the internal network structure is hidden, which reduces the risk of attacks on the internal network.

So we have divided the private IP address.

The private IP address is only used in the local area network, not in the wide area network.

All routers in the Internet will not forward datagrams whose destination address is a private address.

This kind of Internet using private IP addresses is called the local Internet.

So how does a host with a private IP address communicate with other hosts in the WAN?

This requires the NAT protocol-Network Address Translation Protocol. 

Install a NAT software, that is, network address translation software, on the router connected to the Internet on the private network,

This router becomes a NAT router, and it has at least one valid external global IP address.

His role is to convert private network addresses to public addresses.

In the above figure, there are two hosts on the private network 192.168.0.0,

The NAT router is responsible for converting the address on the LAN side to the address on the WAN side, and the port number uniquely identifies a certain process of this network. 

Six, subnetting

Why divide subnets?

There are two reasons:

1. The utilization of IP address space is sometimes very low.

For example, I am a company owner,

Although there are not many employees now,

But in order to expand the company in the future,

I purchased a Class B address,

It provides 2^16-2 hosts;

In this way, for a long period of time, many IP addresses in Class B addresses will be empty.

As a result, the utilization of the IP address space is very low.

2. The two-level IP address is not flexible enough. 

In order to solve the above two problems, we introduced subnets.

Subnet: {"Network Number", "Subnet Number", "Host Number"}

The subnet is divided by the host number of the two-level IP address, not the network number.

So from an IP address itself, we don't know whether a network is subnetted.

In order to know whether a network has been subnetted,'we introduced a subnet mask.

The subnet mask is a 32-bit binary string corresponding to the IP address, consisting of a string of 1s and a string of 0s.

1. Corresponding to the network number and subnet number in the IP address,

0, corresponding to the host number in the IP address.

You only need to AND the subnet mask and IP address bit by bit to get the network address of the corresponding subnet.

7. CIDR (No Classification Addressing)

The traditional division of IP addresses is still a solid thinking.

And CIDR, the non-classified addressing protocol eliminates the traditional concept of A, B, C and subnetting,

He grouped consecutive IP addresses with the same network prefix to form a CIDR address block.

 

Eight, route aggregation

The function of CIDR is to aggregate multiple subnets into a larger subnet to form a supernet or route aggregation.

When using CIDR, there may be multiple matching results. We should choose the route with the longest network prefix because it is more specific. 

 

Nine, the protocol of ARP

Earlier we learned about the data exchange method,

There are circuit switching, message switching, and packet switching.

For a group in the IP layer, it is always a logical thing:

The IP address is just a fictitious logical address, not a real physical address.

But on the actual network link, when transmitting data frames, the hardware (physical) address must be used in the end.

So we need a protocol to complete the mapping from IP address to MAC address and physically solve the problem of where to go next hop.

This protocol is the address resolution protocol ARP.

Each host has an ARP cache. This cache is used to store the mapping table from the IP address of the router to the MAC address of each host on the local area network, which is called the ARP table.

We use the ARP protocol to maintain this ARP table.

 

How ARP works

If host A wants to send an IP datagram to host B,

1. Check whether there is an IP address of host B in its own ARP cache.

If yes, write the hardware address into the destination address of the MAC frame, and then send the MAC frame to the destination hardware address through the LAN;

2. If not, record the destination address of the MAC frame as FF-FF-FF-FF-FF-FF, encapsulate and broadcast an ARP request packet with this frame.

All hosts in the same LAN will receive this request packet, and if a host is not the destination host of the request packet, it will be discarded;

3. After the destination host B receives the request packet from A, it will give back a response packet to A, which contains the mapping relationship between B's IP and MAC.

4. After A receives the response packet, it writes the mapping between B's IP and MAC into its own ARP cache, and then repeats step 1 to send it.

ARP protocol has 4 typical situations:

1. Host A sends to host B on this network, and uses ARP to find B's hardware address;

2. Host A sends to host B on another network, and uses ARP to find the hardware address of a router (gateway) on this network;

3. The router sends it to host A on this network, and uses ARP to find the hardware address of host A;

4. The router sends it to host B on another network, and uses ARP to find the hardware address of a router on this network.

exercise:

 

10. DHCP of the protocol

How does the host obtain an IP address?

There are two ways:

1. Static configuration-manual

2. Dynamic configuration

DHCP-Dynamic Host Configuration Protocol solves the problem of dynamically assigning IP addresses to each host.

DHCP is an application layer protocol, which uses a client/server approach. Through broadcast interaction, based on UDP.

A host that needs an IP address broadcasts a discovery message to the DHCP server when it starts, and then the host becomes a client of the DHCP server.

Although all hosts can receive this broadcast message, only the DHCP server will answer this message.

Let's take a look at the working process of DHCP:

1. The host broadcasts a DHCP discovery message (trying to find a DHCP server to assign an IP address to itself)

2. The DHCP server broadcasts DHCP offer messages (the server intends to assign an IP address and related configuration to the host)

3. The host broadcasts a DHCP request message (the host wants to accept the above IP address and related configuration, so it requests the server)

4. DHCP broadcast DHCP confirmation message (officially assign IP address to host)

11. ICMP of the agreement

In order to forward IP datagrams more effectively and improve the chances of successful delivery,

We use ICMP, the Internet Control Message Protocol.

This protocol supports the host or router to send some error or abnormal reports to the destination host or router , as well as network exploration, in the form of specific ICMP messages.

There are two types of ICMP messages:

1. Error message: used for the target host/router to report errors and abnormal conditions to the source host/router.

2. Inquiry message: used to test whether the destination station is reachable and to understand its related status.

Common application: PING detection between packet networks

 

12. IPv6

There are three measures to solve the exhaustion of IP addresses:

1. Use CIDR without classification to make the allocation of IP addresses more reasonable.

2. Adopt network address translation NAT

However, the above two methods can only delay the rate of depletion.

So we introduced IPv6, which has a larger address space (128bit).

Compared with IPv4:

1. IPv6 expands the address space;

2. The IPv6 header is more flexible

3. IPv6 supports plug and play, automatic configuration, no DHCP required

 

Thirteen, routing protocol-RIP of IGP

RIP is a routing protocol based on distance-vector

Suitable for small internet,

Only exchange information with neighboring routers,

The exchange is its own routing table,

Exchange every 30 seconds.

 

 

Exercise:

 

RIP protocol message format:

 

Features: When the network fails, it takes a relatively long time to transmit this information to all routers. 

14. Routing Protocol-OSPF of IGP

OSPF is a routing protocol based on link state.

1. Broadcast information with all routers

2. The information is the link status of all routers adjacent to this router (which neighbors and the metric/cost of the link)

3. Only when the link status changes , the router broadcasts this information to all routers.

Suitable for large networks.

Based on IP datagram. 

15. Routing Protocol-BGP of EGP

BGP is an exterior gateway protocol, based on distance-vectors.

1. Exchange information with neighboring BGP speakers of other ASs.

2. What is exchanged is the network reachability information, that is, a series of ASs to be passed through to reach a certain network.

3. When there is a change, just update the changed part.

It is an application layer protocol, which is transmitted by means of TCP.

Comparison of three protocols:

 

16. IP multicast

Suppose host A has a video program and want 90 hosts to accept it.

If it is based on unicast-one to one:

But if it is based on multicast:

 

The IP multicast address allows the original device to send packets to a group of devices.

Devices belonging to the multicast group will be assigned a multicast group IP address.

Class D address.

Multicast is based on UDP.

IGMP protocol 

The IGMP protocol lets the router know whether a host (process) on the local area network has joined or left a multicast group.

Both ICMP and IGMP are based on IP datagram transmission.

IGMP work has two phases:

Phase 1: Join the multicast group

1. When a host wants to join a multicast group, the host sends an IGMP message to the multicast address of the multicast group, requesting that it become a member of the group;

2. After the local multicast router receives the IGMP message, it must use the multicast routing protocol to send the group membership to other multicast routers on the Internet.

 Phase 2: Check whether it is still a member of the multicast group

1. The local multicast router periodically searches for the hosts on the local LAN to know whether these hosts are still members of the multicast group.

2. As long as there is a host corresponding to a certain group, the multicast router will consider this group to be active; if no host responds after several searches, the multicast router will think that there is no host of this multicast group on the network , The membership of this group will no longer be sent to other multicast routers.

17. Mobile IP

Mobile IP technology means that mobile nodes use fixed network IP addresses to achieve roaming across different network segments, and to ensure that network rights based on network IP do not change during the roaming process.

 

It is equivalent to one more middleman. 

18. Router of network layer equipment

A router is a special-purpose computer with multiple input ports and output ports, and its task is to forward packets.

 

 

Guess you like

Origin blog.csdn.net/Kukeoo/article/details/114683184