When information needs to be transferred between two networks, the interconnection device of common routers is responsible for the transmission of data. The main work of the router is: The decision of the path and the forwarding of the packet (from the router an interface input, and then select the appropriate interface output); Maintenance path by the table.
The way the router works is very concise, extracting the destination address from the receiving message and determining the network number in the address, and finding the routing table to get the table entries that match the target network. The matching table entries in the routing table include the next station, destination, output interface, and other route-related parameters. The message is encapsulated in a frame that is suitable for the output interface and is output by the output interface.
The following is a detailed analysis of how the router works.
first, the concept of routing
routing is a relay process that forwards objects from one place to another . The mechanism of learning and maintaining the knowledge of network topology is considered as the routing function. The transit data flow through the router's ingress interface through the router is transferred to the out-of-office interface called the Swap / forward feature. Therefore, the routing device must have both the routing and switching capability to act as a valid relay device.
Several basic steps to complete the routing feature:
1. The router must determine whether it has activated support for a protocol group . The routing device must know the logical destination address when making a forwarding decision. To know the destination address, you must start the Protocol group for the logical addressing scheme and put it in the current active state. Common protocol groups are:TCP/IP,IPX,DECnet.
2. When the router can understand the addressing scheme, it is necessary to determine whether the destination logical network exists effectively in its current routing table. If the destination logical network does not exist in the routing table, the router may be programmed to discard the packet and generate an error message to advertise the sender. Of course, if the default route is set, the default route is forwarded to the packet when the destination logical network is not included in the device routing table.
3. If the destination network exists in the routing table, the router must determine which egress interface is the best path to reach the destination . This best path is associated with an out-of-office interface through the routing protocol process, and the routing protocol determines the best path to the destination through the metrics.
4. When the out-of-office interface is known, the router must encapsulate the packet using some encapsulation method and forward it to the next hop logical device .
The interchange operation is performed when a routing table entry is known to the destination logical network through the route function. 4 Basic stepsfor the swap operation: (8 shown)
1, if the frame header of the packet contains a router interface layer 2 address, or broadcast address, or multicast address, and the router is configured to receive the multicast address, then the packet through the router will be received into the router. When the frame is checked, the contents (packets) of the frame are cached for further processing if the addressing is correct.
2. The router examines the destination logical network portion of the header and compares it to the network and sub-network entries in the routing table. If there is an entry in the routing table that matches it, then the destination network is associated with a egress interface for the next hop logical device and router.
3, know the next hop the logical address of the device, you also need to find the next hop device physical address, for the LAN interface, the lookup is in the Address Resolution protocol (ARP) table, and for the WAN interface, The lookup is in a third-level and second-level address mapping table.
4. After knowing the physical address of the next hop device, the appropriate frame header will be generated in the router's memory. (For IP packets, routers also need to modify the IP header: Reduce the value of the time-to- live "TTL" field by 1 , update IP header Checksum) after the frame header is generated, the data frame is transferred to the out-of-office interface for transmission on the physical media. When a data frame is placed on the media, the out-of-office interface adds a cyclic redundancy check character and a frame ending delimiter on the frame. These characters are verified on the receiving interface of the next hop routing device.
Figure 8 The router performs basic switching functions
second, the
route selection process
How does a router choose the best route under many routing protocols, manual configuration, and routing policies? Understanding this problem is a great benefit for mastering how routers work.
There are three aspects involved in route selection:
1 , the processing of various routing protocols , including RIP,IGRPEIGRP,OSPF,IS-IS,BGP, and so on, each protocol passes the network routing information between routers through IP packets, and provides information for the establishment of routing tables.
2 , a routing table that receives information from the routing protocol and provides the information needed to forward the packet.
3 , the forwarding process, which requests the required information from the routing table and makes a decision to correctly forward the packet.
The forwarding decision of a packet depends on three parts of the process: the routing protocol, the routing table, and the actual forwarding interchange, the three relationships diagram 9:
Figure 9 routing protocols, routing tables, and actual forwarding exchanges three relationships
The router obtains the destination address from the network header of a message and then operates with the subnet mask (two numbers are 1, the result is 1, and any of thenumbers is 0. The result is 0) to determine the network number. When the network number is determined, it is possible to find the best interface that can forward the message to the destination by looking for a matching network number in the routing table. In most cases, a message needs to go through multiple routers before it reaches its destination.
We analyze an example of the transmission of a message in a small network. In this example, the message is from Tokyoand is destined for an NMS Workstation with an IP address of 192.168.3.3 . (ten)
route selection of the remote destination in figure Ten
The first step: The message is received by the NY router to determine its destination network number.
The second step: find the output interface name and the next station address by locating the routing table of the NY router. Because we are using a serial link, we do not need to use ARP.
Step three: Messages are sent to the next station router (London).
When the message arrives at the last router, a local sending process is used to forward the message to the final destination. The Ethernet local send process uses ARP. ( shown)
First step: Router London receives the message with the destination address as the NMS workstation;
Step Two: Router London looks up its routing table and discovers that the destination host is on a network that is directly connected to its interface, so it will be sent locally;
Step three: Router London sends an ARP request that is known to the destination host MAC through the ARP Reply packet (fourth step) Address, the message is sent directly to the destination host (fifth step).
Map One -to-one local destination route selection
the structure, establishment and maintenance of the routing table
Routers do not care about individual node addresses when creating routing tables, they only care about which network segment a package should be transported to. The routing table contains the path (hardware interface) through which the package arrives at the destination. Each router interface corresponds to a specific network segment. When the router checks the packet's logical address, it can decide which subnet the package should be forwarded to.
1.
the composition of the routing table
Routing tables are divided into static routing tables and dynamic routing tables, and static routing portals consist of static routes configured manually by the network administrator, and dynamic routing portals are routed by routing protocols such as RIP,OSPF,BGP The routing table information for the interchange is composed. the information required to perform the routing operation is contained in the router's routing table, which is generated by one or more routing protocol processes. The contents of the routing table are limited to the best route that contains only all destinations. If there are multiple good paths, all of these paths will be listed in the routing table.
The ability to understand the various functions of a routing table is important for understanding the routing process of a router. The General routing table has the following sevenitems (a):
Diagram of the route table
A-- source of routing information (Origin)
This is the routing mechanism, which indicates how the routing information is learned. There are three kinds of learning methods: Direct connected network, static route, some kind of dynamic routing protocol.
B-- Destination network address (destination)
This is the destination logical network or subnet address. The two core elements of each routing table entry are the destination network address and the local interface that forwards the packet. Sometimes a routing entry lists only the destination network and the next hop address without the local interface. It is not possible to forward packets without a local interface because the switching network board does not know which "switch" to connect to. In this case, you must perform a second loop lookup, using the next hop address as the destination address to locate a matching entry in the table to find a local interface.
C-- management distance (administrative distance)
Identifies a measure of how trustworthy a routing learning mechanism can be. The administrative distance determines the priority of routing information from the source side of different routing tables. Different routing sources, their administrative distances are different. The routing protocol with a small distance management priority is high. By default, direct-attached routes have the highest priority, static routes are second,BGP takes precedence over OSPF,OSPF takes precedence over RIP .
D-- measure value (metric)
A metric that measures the total "overhead" of a path, defined by a specific routing protocol. When a routing protocol provides multiple routes to a destination network, one of the best routes must be selected to be placed in the routing table. Measures are used to represent the cost of each possible route, and the least-measured route is the best route.
E-- Next Hop gateway address (next hop)
In order for the IP packet to reach its destination, the IP packet needs to be forwarded to the gateway. The router does not know the entire path to the destination address, only passes the data to the next router, and transmits the data to the destination network in the form of "relay". The next-hop address is the port address of the router to which it is attached.
F-- timing (age)
That is, the new and old extent of the routing information, indicating the time the route entry existed. The distance vector protocol periodically updates the timing so that the time value does not exceed a certain time value, and then goes into the "hold" state, and the route entry is deleted for a certain amount of time. Other routing protocols (such as OSPF,BGP) do not handle this time.
G-- the physical port being sent (local interface)
That is, the interface that is associated with the network to which it is destined. The interface that learns the route entry is also the interface that the packet leaves the router to go to the destination. The switching structure unit selects the appropriate "switch" based on this value to establish a channel between the inlet and the exit.
2, the establishment of the routing table
In general, each routing protocol for all routers in the same routing domain has a "convergence" (convergence) state or procedure . When all routers reach a stable, accurate, and consistent network topology State, they get a "convergence" state. Changes in the network topology can cause the router to "converge" again. How the router obtains the convergence state is determined by its specific configuration and routing protocol.
When each routing protocol handles routing updates, it chooses the best route to the destination address and tries to install it into the routing table. If there are only multiple dynamic routing protocols running, there is an issue of scrambling to install routes. There must be a mechanism to manage the installation of the route. This mechanism is based on the priority of each routing protocol to determine the installation process. Each routing protocol has a default administrative distance value, and the smaller the value, the higher the priority. Default administrative distance value for each routing protocol :
Figure The default management distance for each routing protocol
Assuming that the router runs EIGRP, OSPF, RIP, IGRP Four routing protocols, all of which are routed to the network 192.168.24.0/24, only EIGRP (internal) can install its route into the routing table because it has the lowest administrative distance value and the highest priority.
The default distance value of the routing protocol can be changed by hand, but changing the default distance value of the routing protocol is a prudent action that could lead to routing loops or other strange problems, and must be very careful! Its command is distance followed by a specific value. You can also change only the administrative distance value of a route that is distributed from one protocol to another. At the end of a static route, you can also follow a value that changes the original default value of 1.
3.
maintenance of the routing table
Routing forwarding can be fixed by the system administrator, when the network topology changes, the administrator manually adjust, can also be modified by the system based on the dynamic routing protocol.
RIP maintains only one table: the routing table, which periodically swaps all routing tables with neighboring routers, and if a route is declared unreachable, the route is marked as "possibledown" and is set to suppress state. The route entry will be purged if the route has not been re-learned from the original source router that published the route for a certain period of time.
OSPF,BGP maintains at least two additional tables, in addition to maintaining a single routing table: adjacent router tables and topology tables or path tables. Neighboring routers Establish and maintain neighboring router tables through HELLO packets. Once the adjacency relationship is established correctly, the topology database is established during the Exchange of routing table information. Based on the topology database,OSPF implements the shortest path-first algorithm and places the results in the main routing table.
iv.
route selection algorithm
The principle of taking the longest match when routing is selected is determined by the data structure of the routing table. The priority of routing protocol installation routes depends on the administrative distance value.
Visually, depending on the principle of subnetting, you can see which table entry is the "longest match". For example, the routing table has several destination networks (the number behind the slash is the subnet mask length):192.24.96.64/27,192.24.96.96/27,192.24.96.128/26,192.24.96.192/27,192.24.96.224/28,192.24.96.240/28, then toIPaddress is192.24.96.163the host's route will be selected192.24.96.128/26this table item. In fact, the host range for this network address is192.24.96.129~192.24.96.190, the only one that contains the destination hostIPaddress. However, the routing lookup software is not designed this way, which affects the lookup speed, but selects the fastest lookup algorithm based on the storage structure of the data. Suppose the data storage structure is a two-fork tree (Tree) way, only some of the nodes in the tree are routing entries and are tagged, then the routing lookup software traverses from the first bit of the destination address to the "tree", remembering the most recent matching route entry (according to the tag), and if there is no "road" to a node, then the remembered Route entry is the final lookup result. Simplifies the data structure of the routing entries for the above example -is shown.
Longest matching Tree structure in graphs
According to the figure, you can see the route matching method intuitively. Assuming that there is no 192.24.96.128/26 in the routing table , there is no match for the lookup of the destination address 192.24.96.163 , and no other route is possible. If the router is configured with a default route, the topmost root node in the tree has a pointer to the default route, so that the route lookup for any destination address, the default route is noted from the top, if there is no matching node in the downward traversal, and the packet is forwarded with the default route, if there is a matching node, Forward the packet with the last matching node's route, which is how the "longest match" works.
Router Development (ii)--How routers work