# A Robust Routing Protocol in Cognitive Unmanned Aerial Vehicular Networks
## 4 Proposed Routing Protocol
### Cluster Formation
#### 4.4.1 Node Move-In
```
START:  UN_, Starts Span Scanning; \(UN_{j}\), Prepares \(ACL_{j}\); \(UN_{j}\), Prepares \(IN_{n}\); \(UN_{j}\), Broadcasts \(ACL_{j}\) and \(IN_{n}\); \(UN_{j}\), Constructs \(G_{ci}\) based on \(G_{pi}\); \(UN_{j}\), Calculates \(CNRF_{j}\); \(UN_{j}\), shares \(CNRF_{j}\) to \(UN_{n}\); if(\(UN_{j}\) in \(UN_{n}\))then if(\(i>1\))then if(\(ACL_{j}\cap ACL_{CN})>2\)then \(UN_{j}\), Joins \(CN_{j}\) as \(CM_{j}\); \(CN_{j}\) rejects join request for \(UN_{j}\); \(UN_{j}\) to join other \(CN\); if\(CN_{j}\) fails to join any cluster then \(CN_{j}\), forms new cluster and states \(CN\); elseif(\(CNRF_{j}>CNRF_{CN}\))then if(\(UN_{j}==CN_{j}\))then \(UN_{j}\), becomes new \(CN_{j}\); \(CN_{j}\), becomes \(SCN\); elseif(\(CN_{n}\subset UN_{n}\))then \(UN_{j}\) calculates new \(CNRF\) for \(UN_{new}=CN_{n}\); if(\(CNRF_{new}>CNRF_{Chi}\))then go to 23; else if(\(NN_{j}\in CN_{n}\))then if(\(j>1\))then select \(NN_{j}\) with highest \(CNRF\); \(UN_{j}\) form new cluster and becomes \(CN\); else \(UN_{j}\) form new cluster; else \(UN_{j}\) forms new Cluster and new \(CN\); \(UN_{j}\) selects \(CN\) with highest \(CNRF\) and then \(SCN\);  END
```  
**Algorithm 3**Node Move-In  
```
START:  UN_, Starts Span Scanning; \(UN_{j}\), Prepares \(ACL_{j}\); \(UN_{j}\), Prepares \(IN_{n}\); \(UN_{j}\), Broadcast \(ACL_{j}\) and \(IN_{n}\); \(UN_{j}\), Constructs \(G_{ci}\) based on \(G_{pi}\); \(UN_{j}\), Calculates \(CNRF_{j}\); \(UN_{j}\), shares \(CNRF_{j}\) to \(UN_{n}\); if(\(UN_{j}\) in \(UN_{n}\))then if(\(i>1\))then if(\(ACL_{j}\cap ACL_{CN})>2\)then \(UN_{j}\), Joins \(CN_{j}\) as \(CM_{j}\); \(CN_{j}\) rejects join request for \(UN_{j}\); \(UN_{j}\) to join other \(CN\); if\(CN_{j}\) fails to join any cluster then \(CN_{j}\), forms new cluster and states \(CN\); elseif(\(CNRF_{j}>CNRF_{CN}\))then if(\(UN_{j}\), \(UN_{j}\), becomes new \(CN_{j}\); \(CN_{j}\), becomes \(SCN\); elseif(\(CN_{n}\subset UN_{n}\))then \(UN_{j}\) calculates new \(CNRF\) for \(UN_{new}=CN_{n}\); if(\(CNRF_{new}>CNRF_{Chi}\))then go to 23; else if(\(UN_{j}\in CN_{n}\))then if(\(j>1\))then select \(NN_{j}\) with highest \(CNRF\); \(UN_{j}\) form new cluster and becomes \(CN\); else \(UN_{j}\) form new cluster and new \(CN\); \(UN_{j}\) selects \(CN\) with highest \(CNRF\) and then \(SCN\);  END
```  
**Algorithm 4**Node Move-In  
**Cluster Joining:** If neighboring CNs are detected, \(UN_{j}\) attempts to join the cluster. It selects the CN with the highest CNRF value or the lowest ID if CNRF values are identical. \(UN_{j}\) then compares its CNRF with the selected CN and requests to join as a Cluster Member (CM). **Cluster Formation:** If \(UN_{j}\)'s CNRF is higher than the selected CN's, and its neighboring node set matches the CN's CM list, \(UN_{j}\) becomes the new CN, and the existing CN becomes the Secondary CN (SCN). Otherwise, \(UN_{j}\) joins as a CM or attempts to form a new cluster if no suitable cluster is found. **Further Considerations:** If \(UN_{j}\) provides better connectivity than the existing Nearest Node (NN) with a neighboring cluster, it becomes the NN. Additionally, \(UN_{j}\) can declare itself as CN and form a new cluster if joining existing clusters fails. This protocol ensures flawless integration of nodes into clusters, optimizing network organization and communication efficiency. From Algorithm 3, The joining UAV Node (\(UN_{j}\)) starts to scan its span and prepares the \(ACL_{j}\) for \(UN_{n}\). \(UN_{j}\) then broadcasts \(ACL_{j}\) and \(UN_{n}\) and create biclique graph (\(G_{ci}\)) based on bipartite graph (\(G_{pi}\)) and calculates \(CNRF_{j}\). then it shares the value with neighboring \(UN_{s}\). After that, it checks if the joining node belongs to the neighboring node or not, if the value of the joining node's channel is greater than 1 then it again checks if the joining accessible channel list intersects with the central node's ACL and is greater than 2. The \(UN_{j}\) then joins \(CN_{j}\) as CM.