I. Working Principle of routers
We know that routers are used to connect different network segments or networks. In a LAN, if you do not need to communicate with the external network, the workstations in the internal network can identify other nodes, you can use a vswitch to send messages. You cannot use a vro to remember the MAC addresses of each node in the LAN. The router identifies different networks by identifying the network ID numbers of different networks. Therefore, to ensure successful routing, each network must have a unique network ID. To identify another network, the router must first identify the network ID of the vro IP address of the peer network to see if it is consistent with the network ID number in the destination node address. If it is, of course, sent to the router of this network, after receiving the packet from the source network, the router of the receiving Network, identify the node to which the message is sent based on the host ID in the IP address of the destination node, and then send it directly.
To better illustrate the working principle of the router, we assume that there is such a simple network. Assume that four terminal devices are connected together in the same CIDR block, and the IP addresses of each device in this CIDR block are assumed to be: a1, A2, A3, and A4. A Router connected to this CIDR block is used to connect to other CIDR blocks. the IP address of the port connecting the router to CIDR Block A is A5. Similarly, when a router connects to another CIDR block of B, the network ID of This CIDR block is "B", and the IP addresses of the other wks connected to the B CIDR block are set: b1, B2, B3, B4. We set the IP address of the router port connecting to the B network segment to B5, as shown in structure 1.
Figure 1
There are two different CIDR blocks in such A simple network at the same time. If A1 users in CIDR Block A want to send data to B2 users in CIDR Block B, with a vro, it is very simple.
First, A1 prepares the sent data and sent packets, and broadcasts the data to all node hubs in the same CIDR Block through hubs or switches in the form of data frames, because the vswitch cannot recognize this address, it also adopts the broadcast mode). After listening to the data frame sent by A1, analyze the IP address information of the target node. After obtaining the data packet, the router always needs to analyze the IP address information first ). If it is known that it is not the current segment, it receives the data frame and further analyzes the route table to find that the network ID of the receiving node is the same as that of port B5, at this time, the A5 port of the router sends the data frame directly to the B5 port of the router. Port B5 then determines the destination node as B2 Based on the host ID in the destination node IP address information in the data frame, and then sends the data to node B2. Such a complete data frame routing and forwarding process is completed, and the data is successfully delivered to the target node correctly.
Of course, in fact, a network like above is very simple, and the functions of the router cannot be fundamentally reflected. Generally, a network will connect to multiple other network segments or networks at the same time, as shown in figure 2, A, B, C, and D networks are connected through routers.
Figure 2
Now let's take a look at how vrouters play their routing and data forwarding roles in the network environment 2. We also need to assume that the IP Address Allocation of each network user is not mentioned much, as shown in figure 2. Assume that A user A1 in Network A sends A request signal to the C3 user in Network C as follows:
Step 1: User A1 sends the target user C3 address C3 together with data information to all nodes in the same network in the form of data frames through a hub or switch in the form of broadcast, when port A5 of the vroa5 listens to this address, the analysis shows that the destination node is not in this network segment. If the destination node needs to be routed and forwarded, the data frame is received.
Step 2: After receiving data frames of user A1, port A5 of the router extracts the IP address of the target user C3 from the header and calculates the optimal route table for user C3. Since the analysis shows that the C3 network ID number is the same as the C5 network ID number of the vroc5, direct transmission from the A5 port of the vroa5 to the C5 port of the vro should be the best way to transmit signals.
Step 2: The C5 port of the vroc5 fetches the IP address of the target user C3 again, and finds the host ID in the IP address of C3. If there is a switch in the network, it can be sent to the switch first, the switch identifies the specific network node Location Based on the MAC address table. If there is no switch device, the data frame is directly sent to the user C3 Based on the host ID in the IP address, this complete data communication and forwarding process has also been completed.
It can be seen from the above that no matter how complicated the network is, the router actually works in such a few steps, so the principle of the entire router is almost the same. Of course, the actual network is much more complex than the steps shown in 2, and the actual steps are not as simple as above, but the general process is like this.