In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > IT Information >
Share
Shulou(Shulou.com)11/24 Report--
This article comes from the official account of Wechat: programmer cxuan (ID:cxuangoodjob), author: cxuan
We must have all tampered with the router, which can be said to be an indispensable equipment in our daily life. Even if you are not a programmer, the seven aunts next to you must have let you configure the router. But have you ever thought about the question of what this router is for? You may know that this is a device that provides WI-FI connectivity to the Internet for terminal devices. When our terminal equipment is connected to WI-FI, we can send data from my device to where I want (other terminal devices) through a router, and then achieve what I want and content.
This answer makes sense on the whole, but I'm going to ask you a question here.
How does a router send data to other routers?
To answer this question, we should start with the routing protocol.
In the Internet, whether it is a local area network or a wide area network, a packet can be transmitted from one terminal to another through reasonable routing control. The routing control module is used to control the packet sending process. The routing control module follows the routing protocol, which is the specification and standard of the data routing of the whole Internet.
In order to enable the packet to reach the target host correctly, the router must forward the data correctly in the process of data transmission, which is also the first function of the router: data processing, in addition to being able to forward, data processing also includes packet filtering, encryption, compression and so on.
So how does the router know where this data is going?
The router maintains a routing table that records the IP address and output path of the destination host in the packet. The main job of the router is to find the best transmission path for each routed packet. With regard to some of the structure and forwarding rules of the router, you are actually like this on the router. It has been mentioned in this article.
Static routes and dynamic routes we usually divide routers into static routes and dynamic routes, whether static routes or dynamic routes, will not be separated from the routing table. If you have set the routing rules before the data is sent, and the data will be forwarded according to the path you set in advance, this is a static route. if you do not set the routing rules in advance, just let the data be forwarded in accordance with the established rules of the routing protocol in the process of sending, this is dynamic routing, these two routing methods have their own advantages and disadvantages.
Static routing allows you to do a lot of work of setting up routes repeatedly, which is inefficient, has a large amount of tasks, and has poor expansibility. Once you add a new route, it will make you reset all routes, and there is even a single point of problem. When a route in the transmission node fails, the data basically does not bypass the route, and the administrator needs to reset the route before it can continue to send.
To use dynamic routing, you also need to set something manually, but you need to set up routing protocols. The complexity of each routing protocol is different, so the difficulty of setting is also different. For example, the setting process of RIP protocol is relatively simple, while the setting process of OSPF is more complicated. However, once the setup is completed, if you want to add a new route, you only need to set a new single route, and avoid the single point problem, dynamic routing can choose other paths to bypass the failed route.
Although both static and dynamic routes have their own advantages and disadvantages, you can use them together. Adults all want it.
The routing protocol discussed above that dynamic routing will dynamically adjust the forwarding path of data according to the situation of the network, so what is the basis of this behavior?
The answer is achieved by exchanging routing tables between routes. Routers exchange routing tables at the right time, in this way, all routers between networks can dynamically adjust the forwarding path of data. When the network situation changes, the routing information exchanged between routers will inform each other of the change of the network, so that all routers can know the change of the network through the diffusion of information.
The common dynamic routing protocols are RIP, OSPF, BGP, MPLS and so on. According to different autonomous systems, they can also be divided into IGP (Internal Gateway Protocol) and EGP (external Gateway Protocol). What's the difference between inside and outside?
This requires an understanding of what an autonomous system is:
An autonomous system (AS) is a router and network group under the management and control of an ISP network service provider. It can be a router directly connected to the LAN and connected to the Internet at the same time, or multiple Lans interconnected by the enterprise backbone network.
Intra-domain routing protocol IGP is used for dynamic routing within autonomous systems, while inter-domain routing protocol EGP is used for routing control between autonomous systems. IGP and EGP can also be called internal gateway protocol and external gateway protocol. IGP and EGP complement each other. Without EGP, it is impossible to realize the communication between different organizations, and without IGP, it is impossible to realize the internal communication of autonomous system. IGP protocol can be subdivided into RIP, RIP 2, OSPF and many other protocols. The EGP protocol uses the BGP protocol.
Let's take a look at these agreements.
The full name of RIP protocol RIP is Routing Information Protocol, routing information protocol. It is the first widely used protocol in IGP, and like many budding, it must be very simple at first.
The RIP protocol requires each router to maintain a set, which mainly records the distance between the router and the destination network. If the router is directly connected to the destination network, then the distance is 1. Otherwise, in the distance between the router and the destination network, as long as it passes through a router, its distance will be + 1, which is also called * * hop count * *. Each pass by a router, the hop count will be + 1, but this hop is limited to a maximum of 15, so it can be seen that RIP is only suitable for small-scale Internet.
RIP cannot use multiple routes between two networks. on the contrary, it chooses the line with the least routing for transmission, even if the delay is large.
From this, we can sum up two characteristics of RIP protocol: the first feature is that it only exchanges messages with neighboring routers, so how to judge this "neighbor"? If the communication between two routers does not need to pass through another router, the two routers are said to be adjacent. RIP also stipulates that non-adjacent routers will not exchange information. The second feature is that each router will unreservedly exchange all the information it knows, that is, exchange each other's routing tables.
There is also a very important question that we have not considered, since we know that the RIP protocol stipulates the rules for the exchange of information, how does it specify the time interval for the exchange?
RIP protocol provides for the exchange of routing information at fixed time intervals. When the routing information changes, it will update the neighboring routers by exchanging routing tables in time. The update principle is that the router needs to find out the shortest path, using the distance vector algorithm.
Distance vector algorithm
For each RIP message sent by a neighboring router, the following operations are usually done:
Modifying the contents of the RIP message will add + 1 to the values of the next hop address N and distance D fields in the RIP message.
For each content in the modified RIP message, perform the following steps:
If there is no address R of the destination network in the original routing table, the destination network address in the RIP message will be modified.
If the address of the destination network is in the original routing table, and the address of the next hop route is N, the content of the received RIP message is replaced in the original routing table.
If there is the address of the destination network in the original routing table, but the address of the next hop route is not N, if the distance D in the received RIP message is less than the distance in the routing table, it will be updated.
If you do not receive a routing table update message from a neighboring router for a period of time, mark the neighboring router as unreachable and set the distance to 16 as unreachable.
RIP protocol message format
At present, there are mainly two versions of RIP protocol: RIP 1 and RIP 2. Now more RIP 2 versions are used. RIP 2 protocol RIP protocol uses UDP protocol for transmission control.
The main differences between RIP 1 and RIP 2 are as follows:
RIP 1 is a classful routing protocol, and the RIP message does not contain a subnet mask, which requires all devices in the network to use the same subnet mask, while RIP 2 is a classless routing protocol that uses a subnet mask.
RIP 1 uses the broadcast method when sending update packets, while RIP 2 uses multicast by default. Of course, RIP 2 also supports broadcast transmission, but the use of multicast can not only meet the needs, but also save bandwidth.
The third difference is that RIP 2 supports plaintext or MD5 authentication, which requires both routers to authenticate when synchronizing their routing tables, which enhances security.
The following is the message format of RIP 2.
RIP 2 messages can be subdivided into header and routing parts.
The first part mainly has the fields of command, version and must be 0, in which the command identifies the type of message, 1 identifies the Request request, requests all or part of the routing information to the neighboring route, and 2 identifies the Response request and sends all or part of its own information to the neighboring router. Then there is the RIP version, which indicates whether it is RIP 1 or RIP 2. The latter must be 0. In fact, it is mainly designed to make up 4 bytes.
The following is the routing information for the RIP message:
Address cluster identifier: a value of 2 indicates the IP protocol. For Request messages, the value of this field is 0.
Routing tag: this is generally filled in the autonomous system number, it is possible that RIP receives routing information outside the autonomous system.
Network address: this represents the destination network address.
Subnet mask: the subnet mask of the destination address.
Next-hop router address: represents the next-hop address of the router. If 0.0.0.0, it means that the router address that issued this route is the optimal next-hop address.
Hop count: the number of routes that need to be passed.
One problem with RIP is that when a network fails, it takes a long time to synchronize information to all routers.
The main problems and Solutions of RIP
As shown in the figure below, there is a network 1 and router 1. The routing information in the RIP message from router 1 to network 1 (omitting other report field information for convenience description) is "1d1, direct delivery", which means that the distance to network 1 is the hop count of a router and is a directly connected way.
At this time, the RIP message from network 2 and router R2Magi R2 to network 1 is "1magin2 and R1", which indicates that the distance between router R2 and network 1 is 2 hops, and the next router is R1.
Well, the RIP message can be sent normally in the above two pictures, and everything is fine with each other. At this time, network 1 has a failure, resulting in R1 can not directly reach network 1, then R1, R2 at this time how to send the RIP message?
In fact, R1 is directly connected to network 1, so R1 first knows that network 1 is unavailable. Once R1 knows that network 1 is unavailable, it modifies the RIP message to "1line 16, direct", and then synchronizes the routing table with R2, as shown in the following figure:
However, due to the characteristics of the RIP protocol, the routing table synchronization process is not completed so quickly, and R2 does not know that network 1 is not available, so it continues to send messages to network 1 through R1.
Once the message from R2 is sent to R1, R1 will think that it can reach network 1 through R2, so R1 will modify the RIP message to "1LJ 3Q R2", indicating that my distance to network 1 is 3 hops, and the next router will pass through R2, as shown in the following figure.
Similarly, when R2 receives the message from R1, it modifies its RIP message to "1memo 4pr R1". Then cycle through R1 and R2.
When will the cycle end?
R1 and R2 did not know that Network 1 was unreachable until the hop count for both R1 and R2 increased to 16:00. Isn't that for nothing? But this is a feature of the RIP protocol. To put it more popularly, this feature is that good news spreads quickly, while bad news spreads slowly.
Is there any way to remedy this slow spread?
One way is to control the hop count to 16, which is equivalent to controlling the transmission time of the message; the other is to stipulate that the router will no longer reverse transmit the received message to the sender, which is called split horizon, as shown in the following figure.
Another way is to send it directly without waiting for a certain amount of time (for example, 30 seconds) when the routing information changes, which seems to be an easier way to think of. When you think about it, the network is down, and you have to wait 30 seconds to send it. It's really chicken.
In short, because of its protocol characteristics and messages, it can only be used in small networks.
The OSPF protocol OSPF was developed in 1989 to overcome the shortcomings of RIP. OSPF is called Open shortest path first (Open Shortest Path First) protocol. Note that although it is called the shortest path first protocol, it does not mean that other protocols are not the shortest path first. Generally, routers in autonomous systems will choose a shortest path for transmission.
OSPF uses a distributed link-state protocol rather than a distance vector protocol like RIP. Compared with the RIP protocol, OSPF has the following main changes:
OSPF sends messages to all routers in the autonomous system. OSPF first sends messages to neighboring routers, and then neighboring routers send messages to neighboring routers, gradually synchronizing all routers. On the other hand, RIP only sends messages to a few nearby routers.
The message sent by OSPF is the link state of all routers adjacent to the router, including which routers are adjacent, and the metric of the link, which is actually the hop count in RIP. For the RIP protocol, it simply synchronizes the entire routing table to neighboring routers.
OSPF synchronizes messages to all routers when the link changes, while RIP periodically exchanges routing table information regardless of whether the network state changes.
From this point of view, the difference between OSPF and RIP is quite big.
Because OSPF periodically synchronizes link information with surrounding routers, these routers can establish a link-state database, and each router knows how many routers are in the autonomous system and the metric with those routers, so each router can build a routing table on its own. Although the RIP protocol can also know this information, it can not know all the routing information in the whole autonomous system.
Having said so much, why is OSPF more suitable for large networks than RIP?
First of all, OSPF has no hop limit, and OSPF will divide the autonomous system into smaller regions, each with a logo. Of course, the division of regions is also limited to 200. the following is the division of different regions within the autonomous system by an OSPF.
The advantage of this is that it can improve the efficiency of message transmission in the area and reduce the traffic. Imagine how much traffic it would take for each router to synchronize messages if there was no partition within a particularly large autonomous system.
The division of OSPF adopts a hierarchical method, which is divided into upper and lower layers. in the upper layer, it is called backbone area, and the identifier of backbone area is 0.0.0.0. The function of backbone area is mainly used to connect other areas in the lower layer. Inside each area, there is an intermediate router responsible for communicating with backbone area routers, which is called area Border Router. The router in the backbone area is called the backbone router, and the backbone router can be the area border router. Among all the backbone routers, there is a router responsible for communicating with the external autonomous system. This router is called the homemade boundary system router.
Although the layered idea solves the problem of large traffic in OSPF, the type of communication is greatly increased, which makes the protocol OSPF very complex. However, the idea of layering is extremely important, because any large network or operating system will embody the idea of layering. After all, decoupling is an art.
OSPF does not use any transport layer protocol for communication; instead, it transmits IP datagrams directly.
So the question is, why are there still protocols that don't use transport layer protocols to transmit messages?
Because OSPF needs to perform reliable multicast operations, it will communicate with multiple neighboring routers in the autonomous system as much as possible, while TCP does not support multicast, and UDP cannot guarantee reliable transmission, so OSPF implements its own transport mechanism, thus bypassing TCP and UDP.
The packet formed by OSPF is not large, which can reduce the traffic. Another advantage is that the packet does not have to be sliced, because if any one of the sliced data slices is lost, it cannot be assembled into the sent data packet and must be retransmitted.
The following is the message of OSPF and the meaning of each field.
(1) version Version: the current OSPF version number is v2 and the main standards are RFC 1583 and RFC 2328.
(2) there are five message types of type Type:OSPF, which can represent any kind of OSPF message.
(3) packet length Packet length: the packet length, including the OSPF header, in bytes.
(4) Router identifier Router ID: indicates which router interface the packet is sent from and the IP address of this router.
(5) region identifier Area ID: an identifier that indicates which region the packet belongs to.
(6) check and: it is used to detect whether there are errors in the packet.
(7) Authentication types: at present, there are only two authentication types, 0 (not used) and 1 (password).
(8) Authentication data (authentication): enter 0 if the type is 0 and 8 characters password when it is 1.
In addition to the above-mentioned characteristics of these messages, OSPF has some other features:
(1) if there are multiple paths with the same metric to a destination network, OSPF will use each path through load balancing.
(2) OSPF allows administrators to set metric manually. If it is a sensitive business, you can set a higher metric. If the sensitivity requirement is not so high, you can set a lower metric. This is impossible in RIP, where RIP only allows one shortest path.
(3) OSPF packet has authentication function, which ensures the security of transmission link information.
(4) OSPF supports variable length subnetting and unclassified addressing CIDR.
(5) because the link state in the network often changes, OSPF will give each link a 32-bit sequence number, and the larger the sequence number, the newer the state.
It is mentioned above that there are five message types in OSPF, mainly the following five:
Type 1: hello message, which is sent periodically in the form of multicast. The main function is to maintain the reachability with neighboring routers and ensure two-way communication. But not all messages will establish a relationship. They must match all the fields in the message before they can be established. Here are the fields of the hello message.
Nestwork Mask: network mask.
Hello Interval: the interval at which hello messages are sent. By default, OSPF sends hello intervals of 10 s on P2P or broadcast type interfaces and 30 s of hello intervals on NBMA and P2MP type interfaces.
Options: optional, the router advertises that it can support a feature by setting the options field
Router Pri: router priority
Router Dead Interval: router failure time. By default, the routing interface is four times the size of hello interval, and if you do not receive a hello message from a neighbor within this time, the neighbor is considered invalid.
Designated Router: designated router. A field of 0.0.0.0 means that DR has not been specified or there is no DR. Backup Designated Router: back up the designated router. The interface IP address of the BDR in the network. A field of 0.0.0.0 means that BDR has not been specified or there is no BDR. Neighbor: neighbor. This is populated with the neighbor's Router ID.
Type 2: database grouping (Database Description), which is used to synchronize link-state information in their own link databases to neighboring sites.
Interface MTU: the maximum interface data unit from which the maximum IP data length is emitted. The default is 0.
I:initial bit, the initial flag bit, when sending multiple DD messages in succession, if the first message is 1, otherwise it is 0.
M:more, if set to 1 means that there are other DD messages that follow, and set to 0 if this is the last DD message.
M / S: this bit is set to 1 to indicate a master router.
DD sequence number DD message serial number. Both master and slave use sequence number to ensure the reliability and integrity of DD message transmission. Header information of the LSA contained in the LSA headers:DD message.
Type 3: link-state request (Link State Request) packet, requesting a complete LSA message with a LSR message.
LS Type: link-state type.
Link State ID:LSA logo.
Advertising Router: the router Router ID that generated the LSA.
Type 4: link-state update (Link State Update) grouping
After receiving the LSR, the router will respond with the LSU message, which contains the complete LSA information requested by the other party in the LSU message.
Detailed LSA messages are usually written separately, including LSA Header,Router-LSA,Network-LSA.
Type 5: link-state acknowledgement (Link State Acknowledgment) packet, which is used to acknowledge received LSU messages. The content is the header of the LSA that needs to be confirmed. A LSACK message can confirm multiple LSA.
OSPF stipulates that Hello packets are exchanged every 10 seconds to determine whether the network link is reachable, which is very similar to some kind of heartbeat detection mechanism. The routing table will be based on the detection results of Hello packets. Under normal circumstances, the vast majority of packets are Hello packets. If the Hello packet is not received within 40 seconds, the neighboring routers will be considered unreachable. The link information recorded in the link-state database should be modified immediately and the routing table should be redesigned.
The other four OSPF messages are used for link-state database synchronization. This synchronization means that different routers have the same link state. Two synchronized routers are called completely adjacent. It is not called adjacency when the physical distance is close, but to judge its link state.
Summarize the use of the above five message types: confirm whether it is connected by sending Hello packets; synchronize link-state information through DD packets; in the routing operation phase, request routing control information through link-state request packets, then receive routing synchronization information by link-state update packets, and finally notify that routing control information has been received by link-state confirmation packets.
When a new router starts to work, it does not know to whom to synchronize link information, so it needs to determine which neighboring routers have and how much metric is sent to neighboring routers by grouping. If all routers broadcast their own state information to the whole network, then each router can combine the link state information to get the state link database. But it costs too much.
Therefore, OSPF obtains the network-wide state link database by using database packets to exchange link information status with neighboring routers. The following are the OSPF messages that need to be sent to form a state link database.
In this way, a state link database will be established, and if the routing state changes during the operation of the network, only the link state update packet needs to be sent, and the link state confirmation message needs to be sent after the update is completed.
And OSPF doesn't have the problem of fast spread of good news and slow spread of bad news like RIP.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.