## 3 The Proposed Routing Protocol--CRD
### The Proposed Routing Protocol--CRD
#### 3.4.2 The Proposed Routing Protocol--CRD  
Based on Algorithms 1-4, we propose the CRD routing algorithm in Algorithm 5 to find a route from a source to a destination which avoids the affected region of the primary user. For ease of explanation, we remind some definitions of cluster head and gateway as follows:  
Figure 6: The basic concept of proposed routing protocol—CRD. * A cluster head (CH) is a representation of a cluster and its tasks are aggregating and transmitting messages of rest nodes in this cluster within a single hop. A CH can directly communicate with a GW or other CHs. * A gateway (GW) is an intermediate node which can directly communicate with its CH or CHs/GWs of other clusters within a single hop. We note that in the routing process, each cluster head or gateway will decide which focus region and sending channel to send a RREQ packet. ```
Condition: (node \(v\) is a CH and u is source) or (node \(v\) is a CH and node \(u\) is a gateway) or (both node \(u\) and \(v\) are gateways and ) node \(v\) is not in the same cluster with node \(u\)) or (node \(v\) is a gateway and node \(u\) is a cluster head)
```  
**Algorithm 5** The flowchart of proposed routing algorithm--CRD. The proposed CRD protocol can be explained in Figure 6 as follows. Source \(S\) generates a RREQ packet. Source \(S\) then switches to channel 2 and sends the RREQ packet to CH\({}_{1}\). By usingthe Algorithm 4, CH\({}_{1}\) chooses a focus region with a sending channel 1 to forwards the RREQ packet to GW\({}_{1}\) and GW\({}_{2}\). GW\({}_{1}\) forwards the RREQ to CH\({}_{3}\) without switching channel. Because CH\({}_{3}\) is in the radio range of PU which uses channel 1 as licensed channel, CH\({}_{3}\) can not forward the RREQ to GW\({}_{6}\) on channel 1. GW\({}_{2}\) forwards the RREQ to CH\({}_{2}\) without switching channel. Recalling again Algorithm 4, CH\({}_{2}\) chooses a focus region with a sending channel 2 to forward the RREQ to GW\({}_{4}\). GW\({}_{4}\) forwards the RREQ packet to CH\({}_{4}\) without switching channel. CH\({}_{4}\) switches to channel 1 and forwards the RREQ packet to destination \(D\). When destination \(D\) receives the RREQ packet from CH\({}_{4}\), it generates a RREP packet. Destination \(D\) then switches to channel 2 and sends the RREP to CH\({}_{4}\). CH\({}_{4}\) continues to forward the RREP packet to GW\({}_{4}\) without switching channel. GW\({}_{4}\) switches to channel 1 and forwards the RREP packet to CH\({}_{2}\). CH\({}_{2}\) continues to forward the RREP packet to GW\({}_{2}\) without switching channel. GW\({}_{2}\) switches to channel 2 and forwards the RREP packet to CH\({}_{1}\). CH\({}_{1}\) switches to channel 1 and forwards the RREP packet to source \(S\). When source \(S\) receives a RREP packet, it sends data to the destination. Due to the explanation above, we describe the proposed CRD routing algorithm by the following steps. * Step 1. Source \(S\) generates a RREQ packet (Figure 4) and sends it to its CH on the channel of this CH. * Step 2. If a CH \(v\) receives a RREQ packet from source \(S\) or GW node, CH \(v\) uses the CFS algorithm to choose a focus region with a sending channel \(c\) in order to forward the RREQ packet. If a GW \(v\) receives a RREQ packet from a CH or from a GW which is not in the same cluster with GW \(v\), it also chooses a focus region with a sending channel \(c\) to forward the RREQ packet by using the CFS algorithm. After forwarding the RREQ packet, node \(v\) records the sender channel and next hop into its routing table. * Step 3. If destination \(D\) receives a RREQ packet, it records the sender channel and next hop into its routing table. It generates a RREP packet (Figure 4) and sends it to source \(S\). We note that in steps 2 and 3, if a node \(v\) has already a RREQ\({}_{1}\) and it receives a new RREQ\({}_{2}\), node \(v\) considers three following cases
* If the sequence number (\(seq\_num\)) of RREQ\({}_{2}\) is greater than \(seq\_num\) of RREQ\({}_{1}\), node \(v\) will drop the RREQ\({}_{1}\) and forward RREQ\({}_{2}\).