# WLQRP: A Weighting Link-Quality-Based Routing Protocol for Underwater Sensor Networks
## 4 Protocol Description
### Selecting the Optimal Relay and Data Forwarding  
Following the reception of HANDSHAKE-R responses from neighbor nodes, the node proceeds to identify the most suitable intermediary relay. Subsequently, leveraging the Packet-Bit information derived from the chosen relay node's HANDSHAKE-R response, node x determines which data packets within the pending forwarding queue can be pruned prior to forwarding the remaining packets to the selected relay node. Algorithm 3 summarizes the processing details upon receiving HANDSHAKE-R.  
During the process of selecting the optimal relay, the primary criterion involves evaluating the link quality of the neighboring nodes that have responded. In a scenario where a data packet is delivered to node x, encompassing a set of m neighboring nodes including y, the criterion for x's next-hop node selection involves identifying the neighbor with the most robust link quality that surpasses a pre-established threshold. The computation of link quality for neighboring nodes adheres to the subsequent formula:  
\[lq_{x,y}=\alpha\left[\beta S_{x,y}+(1-\beta)\frac{1}{HC(y)}\right]+(1-\alpha) \left[\gamma\overline{lq_{y,N}}+(1-\gamma)lq_{y,N_{-}}m\right]+\delta E(y) \tag{8}\]  
\(S_{x,y}\) represents the transmission success rate between nodes x and y, where the success rate is calculated as the ratio of actual data forwarding times to theoretical data forwarding times. Theoretical data forwarding times pertain to situations where nodes x and y achieve successful handshakes and designate y as the subsequent hop for data relay. Actual data forwarding times entails the successful transmission of data from node x to node y following a successful handshake. In other words, if the subsequent relay is selected as y but x fails to forward packets to y, then the transmission success rate will be reduced. Upon the determination of the subsequent hop node, the heterogeneity in link quality introduces variability in the consistent success of data packet transmissions. Therefore, the probability of successful data packet transmission serves as an indicator of channel quality, thereby aiding the WLQRP protocol in selecting relay nodes situated within favorable communication channels. ```
1: After node x receives the HANDSHAKE-R packet from neighbors
2: Select all neighbor nodes that have replied to HANDSHAKE-S sent by x
3: Calculate all neighbors' link quality
4: Select the neighbor node with the highest link quality
5:if the highest link quality greater than threshold then
6: Node x checks Packet-Bit in received HANDSHAKE-R
7: Remove duplicate data packets
8: Send data packets
9:else
10: The node temporarily stores the packet in a cache queue for the next send. 11:end
12:if y has received data packets then
13: node y sends ACK
14:end
15:if x has received ACK then
16: Packets are transmitted successfully
17:else
18: x retransmits data packets (up to three times)
19:if x has received ACK then
20: Packets are transmitted successfully
21:else
22: Node x selects another relay to transmit data packets
23:end
24:end
```  
**Algorithm 3****Upon receiving HANDSHAKE-R**  
\(\overline{lq_{y,N}}\) denotes the average link quality between node y and its neighboring nodes (except node x), while \(lq_{y,N}\_m\) signifies the maximum link quality value among all of y's neighboring nodes. By incorporating the average and maximum values of link quality among neighboring nodes for the subsequent hop, WLQRP is adept at skillfully circumventing link vulnerabilities and thereby mitigating the risk of encountering routing traps. \(E(y)\) represents the energy level of node y, thus mitigating the risk of data packet loss arising from inadequate energy resources within node y. The constants \(\alpha,\beta,\gamma,\delta\) in the formula are adjustable parameters, allowing for manipulation of the weighting between link quality and node energy pertaining to subsequent and subsequent-to-subsequent hop nodes.