[0034] Example
[0035] figure 1 It is the topology diagram of the mobile ad hoc network based on the TCP/IP protocol in the embodiment. In this embodiment, the mobile ad hoc network includes 4 nodes, each circle represents a node, where a number represents a node number, each edge represents a direct link, and the value represents a data packet delivery rate. It can be seen that in this embodiment, the adjacent nodes of node 1 are 2, 3, the adjacent nodes of node 2 are 1, 3, the adjacent nodes of node 3 are 1, 2, 4, and the adjacent nodes of node 4 are 3. .
[0036] The following is based on figure 1 The shown mobile ad hoc network describes in detail the on-demand routing method of the mobile ad hoc network based on link quality of the present invention. The present invention includes the following steps:
[0037] S1: Every active node i every T after joining the network 0 Broadcast a HELLO message in seconds, including the message type and the node address, and at the same time monitor the HELLO messages sent by other nodes; if a node i is at the preset time T s The HELLO message sent by node j is N ij0, then node j is the neighbor node of node i, and record the address of node j in the neighbor list of node i ADD j And the link quality between node i and node j q ij = T 0 N ij T s .
[0038] In this embodiment, the broadcast period T of the HELLO message 0 =1s, receiving statistical time T s = 5s. Such as figure 1 As shown, the link quality between each node in this embodiment is q 12 =q 21 =0.8, q 13 =q 31 =0.2, q 23 =q 32 =0.8, q 34 =q 43 = 0.6.
[0039] figure 2 It is a schematic diagram of the HELLO message packet structure. Such as figure 2 As shown, in this embodiment, the type is 0, and it is reserved as 0. The function of the type field is to distinguish the types of transmitted messages.
[0040] S2: When the data source node x needs to send data to the destination node y, if there is a valid route between the source node x and the destination node y, the data is sent directly, and if there is no valid route, go to step S3 for route discovery. The effective route judgment can directly judge whether there is a routing table entry in the source node x pointing to the destination node y, or whether the source node x can receive the RREP message from the destination node y within a certain period of time, and so on.
[0041] In this embodiment, node 1 needs to send data to node 4. Assuming that there is no effective route between node 1 and node 4 at this time, route discovery is performed on the route from node 1 to node 4 at this time.
[0042] S3: Source node x constructs an RREQ message, including message type, hop count, route request identifier, route request originating node address, route request destination node address, and last hop node address. At this time, the hop value is 0, and the last hop node address Is the address of the source node; the source node delays sending the RREQ message to all neighbor nodes m of the source node 1 ,m 1 =1,2,3,...,N x , Neighbor node m 1 The delay time is Seconds, where A is the preset negative parameter, Is the neighbor node m 1 Link quality with source node x, N x Is the number of neighbors stored in the neighbor list of source node x.
[0043] image 3 It is a schematic diagram of the RREQ message data packet structure. Such as image 3 As shown, in this embodiment, node 1 constructs an RREQ message, where the type is 1, the number of hops is 0, the route request identifier is 0, the route request originating node address is the IP address of node 1, and the route request destination node address is node 4. IP address. The route request identifier is used to distinguish RREQ messages existing in the network. After the RREQ message is constructed, it is encapsulated in the UDP protocol and sent to all neighbor nodes 2 and 3 of node 1 with a delay. The value range of parameter A is generally -1 to -10. In this embodiment, parameter A is set to -1, so the delay time for nodes 2 and 3 is T 1v =-ln(q 1v ),v=2,3, then T 12 =-ln(0.8) = 0.2231s, T 13 =-ln(0.2)=1.6094s.
[0044] S4: When a node in the network receives the RREQ message, it extracts the route request identifier and the route request initiating node address, and judges whether the route request identifier and the route request initiating node address already exist in the routing table of this node. The RREQ message is discarded; if it does not exist, go to step S5.
[0045] After node 1 broadcasts the RREQ message, the delay of node 2 is smaller than that of node 3, so node 2 receives the RREQ message first.
[0046] S5: The node creates a new routing table entry in the routing table, the destination address of which is the address of the routing request originating node in the RREQ message, the next hop node address is the address of the previous hop node in the RREQ message, and the identification number is RREQ The route request identifier in the message, and the distance value is the hop value in the RREQ message; it is judged whether the destination node address of the route request is the address of the current node, if it is, it means that the current node is the destination node and go to step S7, if not, go to step S6.
[0047] Node 2 creates a new routing table entry in its routing table, and its destination address is the address of the routing request originating node in the RREQ message, that is, the IP address of node 1; the next hop node address is the previous hop node address in the RREQ message , Which is the IP address of node 1; the identification number is the route request identifier in the RREQ message, which is 0; the distance value is the hop value in the RREQ message, which is 0. It can be seen that the routing table entry established in the present invention is a reverse routing table entry. It can be judged that the node 2 address is not the destination node address of the routing request, so step S6 is entered.
[0048] S6: Add 1 to the hop value in the RREQ message, change the address of the previous hop node to the address of the current node, and then delay forwarding the RREQ message to the neighbor node m of this node 2 ,m 2 =1,2,3,...,N z Other neighbor nodes except the previous hop, node m 2 The delay time is among them Is node m 2 Link quality with this node, N z Is the number of neighbors stored in the neighbor list of this node; return to step S4.
[0049] As for node 2, there is only node 3 for neighboring nodes except for the previous hop node 1. Therefore, after adding 1 to the hop value in the RREQ message, and changing the last hop node address to the IP address of node 2, the RREQ message is delayed and forwarded to the 3 nodes with a delay time of T 23 =-ln(0.8)=0.231s.
[0050] Return to step 4, that is, node 3 processes the RREQ message, establishes a routing table entry in node 3 and delays forwarding it to neighboring node 4 except node 2 of the previous hop. During the period due to T 12 +T 23 13 Therefore, when node 3 receives the RREQ message directly from node 1, node 3 has already received the RREQ message forwarded by node 2 that carries the same route request identifier and the address of the route request originating node, so node 3 will come from node 1. The RREQ message is discarded.
[0051] Return to step 4, that is, node 4 processes the RREQ message, establishes a routing table entry in node 4, and judges that node 4 is the destination node in the RREQ message, so step S7 is performed.
[0052] S7: The destination node y replies to the source node x according to the routing table RREP message, including the type, hop count, route reply identifier, route reply originating node address, route reply destination node address, and last hop node address. At this time, the hop value is 0 , The last hop node address is the destination node address, and the route reply destination node address is the source node address.
[0053] Figure 4 It is a schematic diagram of the RREP message data packet structure. Such as Figure 4 As shown, in this embodiment, node 4 constructs an RREP message, where Type is 2, the number of hops is 0, the route reply identifier is the same as the route request identifier in the RREP message, and the route reply originating node address is the IP address of node 4. , The destination node address of the route reply is the IP address of node 1, and the previous hop node address is the IP address of node 4. Reply cycle T of RREP message 1 = 1s. Since effective routing table entries with node 1 as the destination address have been established in nodes 2, 3, and 4, the RREP message replies from node 4 is forwarded to source node 1 according to these routing table entries.
[0054] S8: When a node receives a RREP message, it creates a new routing table entry in the routing table. Its destination address is the address of the originating node of the route reply in the RREP message, and the next hop node address is the previous hop node in the RREP message. The address, the identification number is the route reply identification in the RREP message, the distance value is the hop value in the RREP message, and step S9 is entered.
[0055] S9: Determine whether the route reply node address is the address of this node, if yes, go to step S11, if not, go to step S10;
[0056] S10: Add 1 to the hop value in the RREP message, change the previous hop node address to the current node address, and forward it to the next hop node address pointing to the route reply destination node address according to the routing table, and return to step S8.
[0057] It can be seen that in this embodiment, when nodes 1, 2, and 3 receive the RREP message, a routing table entry pointing to node 4 is established in their respective routing tables. After the nodes 2 and 3 have established the routing table entries, step S10 is entered, the RREP message is processed and then forwarded to the next hop node pointing to node 1. After node 1 has established the routing table entry, it proceeds to step S11.
[0058] S11: The route discovery ends, and the source node sends data to the destination node according to the obtained effective route.
[0059] At this point, an effective route from node 1 to node 4 has been established in the mobile ad hoc network.
[0060] Since the mobile ad-hoc network topology changes dynamically, routing changes are also very frequent. Therefore, under normal circumstances, each node also needs to monitor each routing table entry in its routing table, retain when there is data used, delete when there is no data used, and remove invalid routing table entries in the routing table. Therefore, the present invention also includes:
[0061] S12: Each node maintains a timer for each routing table entry. When there is data to use a routing table entry, the corresponding timer is cleared to 0. When the timer value reaches the preset value T over When the corresponding routing table entry is deleted. Default value T over The value range is usually 5-10s.
[0062] In addition, the present invention also provides a route maintenance method, which can find faulty nodes in the mobile ad hoc network and unstable links, so as to update the optimal route in real time, and improve the response speed of the mobile ad hoc network to failures. Realize the tracking and maintenance of routing. The route maintenance method includes the following steps:
[0063] S2.1: After the effective route is established, the destination node continues to the source node with a cycle T 1 Repeat RREP messages, each node l of the source node and the intermediate forwarding node listens to the RREP message, and counts the preset time T respectively r The number of RREP messages received from the destination node in the network, and continuous statistics of n T r Number of RREP messages in M l,t ,t=1,2,...,n, n is the preset parameter, and the routing quality is calculated according to the following formula:
[0064] p l , t = T 1 M l , r T s
[0065] The smaller the subscript, the newer the data.
[0066] It can be seen that the parameter n≥2 needs to be preset. In this embodiment, n=4, that is, 4 routing qualities p are used each time l,1 ,p l,2 ,p l,3 ,p l,4. Reply cycle T of RREP message 2 =1s, statistical time T r = 5s.
[0067] S2.2: Each node l judges whether p l,1λmin(p l,2 ,p l,3 ,...,P l,n ), λ,0 l,1λmin(p l,2 ,p l,3 ,...,P l,n ), return to step S2.1 to continue monitoring RREP messages; if p l,1 ≤λmin(p l,2 ,p l,3 ,...,P l,n ), the route is unstable, and step S2.3 is entered. In general, λ=0.8.
[0068] S2.3: Node 1 generates an RRER message according to its routing table, including the destination node address of the unstable route, the current node address, and the number of hops between the current node and the source node, and sends it to the source node. The source node re-initiates the destination Route discovery of nodes.
[0069] Figure 5 It is a schematic diagram of the RERR message data packet structure. Such as Figure 5 As shown, in this embodiment, the type of the RERR message is 3, and the route unreachable node address is the destination node address of the unstable route.
[0070] S2.4: After the intermediate node and the source node receive the RERR message, extract the Hops value in the RERR message, and calculate the waiting time T w = T h ×(Hops+Dist), where T h It is the time required for one-hop transmission, Dist is the number of hops from the source node to the destination node; the intermediate node or the source node is not allowed to send the RERR message related to the destination node during the waiting time; if it can be received within the waiting time The RREP message from the destination node, that is, the route has been repaired at this time, and the intermediate node or the source node does not do any operation, otherwise the node invalidates the routing table entry.