# QoS Enabled Layered Based Clustering for Reactive Flooding in the Internet of Things
## 4 Proposed CBF for IoT
### The IntraLayer Clustering (IALC)  
Based on link state information, motes calculate intralayer clustering routes for every extended cluster of motes. Link state updates may receive a mote, either from an interrupt made by the mote discovery protocol (MDP) or from the IALC link state query packet. The link state table keeps an updated list of all link states' information. In addition, the clustering table is recomputed once updates for the waiting link state have been received. Further, links that lie beyond the cluster have been removed and the link state tables are updated. The latest delivered updates of link state and its sources are sent to the mote's neighbor within the cluster. Additionally, a mote shares all intra-cluster link state information to the newly discovered neighbor. The protocol is shown in Figure 5 and Algorithm 2. Figure 4: MDP Query Packet format and Neighbor-mote-table. Figure 5: Intralayer cluster protocol (IALC). ```
1://Identity and eliminate the missing and lost neighbors-mote. Every note has neighbor-mote-table. Begin
2:Mote-Table[neighbor-mote]. Arrive == Not True)
3:If (Mote-Table[neighbor-mote]. previous_list \(\geq\) Max_previous_list)Then
4: Eliminate (Mote-Table[neighbor-mote]); //If previous_list has not received the neighbor's-mote beacon then eliminate the neighbor-mote Begin
5:Mote-Table
6:If (Mote-Table[neighbor-mote]. Arrive == Not True)
7:If (Mote-Table[neighbor-mote]. previous_list \(\geq\) Max_previous_list)Then
8: Eliminate (Mote-Table[neighbor-mote]); //If previous_list has not received the neighbor's-mote beacon then eliminate the neighbor-mote from the mote-table. 9:Interrupt-load-params (neighbor-mote);
10:Set-interrupt (IALC, \"neighbor-mote-lost\", \"Update IALC Routing Table\"); Endif
11:elseMote-Table[neighbor-mote]. previous_list ++;
12:// Increase number of cycles that neighbor-mote's beacon has not been received. 13:Elseif (Mote-Table[neighbor-mote]. previous_list == -1)Then
14:// Immediately, alert and update the IALC, if a new neighbor-mote found. 15:Interrupt-load-params (neighbor-mote);
16:Set-interrupt (IALC, \"neighbor-mote-found\", \"Update IALC Routing Table\");
17:Mote-Table [neighbor-mote]. previous_list = 0; Endif
18:Mote-Table [neighbor-mote]. Arrive = Not True;
19:Update-Timer -Mote-Table = T ++;
20:End. ```  
**Algorithm 2**Intralayer cluster (IALC) algorithm. ```
//IALC might be triggered by either from an interrupt made by the mote discovery protocol (MDP) or link state query packet updates. Begin
1:If (query-packet arrived) Then
2:Extract(query-packet);
3:My-changed-link = Not True;
4:Else
5:Interrupt-extract-params (&destination-link);
6:Source-link = my-mote-id;
7:Source-pk = my-mote-id;
8:Id-link-state = my-id-link-state; Endif
9:Elseif (Interrupt-type = \"Found Neighbor-mote) Then
10:Status-link = Up; Endif // Share all intra cluster link states information to the new discovered neighbor-mote. 11:Elseif (neighbor-mote) (Link State Table, my-mote-id, link-destination)) Then
12:Forward-link-state-table (Link State Table, link-destination);
13:My-id-link-state ++;
14:Else
15:Status-link = Down;
16:Elseif (neighbor-mote is (Link State Table, my-mote-id, link-destination)) Then
17:My-id-link-state ++;
18:End

### The Interlayer Clustering (IELC)

The core responsibility of the IELC is to discover routes to the hosts that are outside of the mote's cluster. In case a destination mote is not listed in the (IALC) local clustering table, the IELC then triggers a route query request at the network layer. Every route query request is allotted a query-id that is distinctive to the source mote id. The route query request might be uniquely identified by the combination of query-id and source-mote-id in the network. Once the query-id and source-mote-id have been recorded in the request packet, the query packet is then forward to all the border or peripheral motes of the cluster. Upon receiving the route query request by the mote, the detected-queries-table records the query-id, source-mote-id, last-hop, and broadcasting-mote.