# Detection and Mitigation of RPL Rank and Version Number Attacks in the Internet of Things: SRPL-RP
## Appendix A  
```
1: Begin
2:input: node_id
3:input: min_sibling_rank
4:input: node_current_rank
5:input: parent_threshold_divisor
6:input: min_pst
7:input: threshold
8:set min_pst = (min_sibling_rank -  parent_threshold_divisor)
9:if node_current_rank < min_pst then
10:set threshold[node_id] = 5
11:else
12:set threshold[node_id] = 4
13:End if
14:End
```  
**Algorithm A1** Evaluation of Node Current's Rank and Node Sibling's Rank```
1:Begin
2:input: version
3:input: neighbor_1_current_rank
4:input: neighbor_1_previous_rank
5:input: neighbor_1_version
6:input: number
7:input: neighbor_1
8:input: neighbor_1_id
9:input: neighbor
10:input: neighbor_table_head
11:input: neighbor_table_next
12:input: n
13:input: m
14:input: p
15:ifversion!=240 //DEFAULTULT VERSION(DODAG) = 240
16:for neighbor_1 = neighbor_table_head; neighbor_1!= null; neighbor_1 = neighbor_table_next then
17:set number ++
18:set neighbor_1_id = address
19:set neighbor[number] = neighbor_1_id
20:set n[neighbor[number] = neighbor_1_current_rank
21:set m[neighbor[number] = neighbor_1_previous_rank
22:set p[neighbor[number] = neighbor_1_version
23:End for
24:End if
25:End
```

**Algorithm A3**. Checking the Condition of the Initial Default Version Number

```
1:Begin
2:input: version
3:input: neighbor_1_current_rank
4:input: neighbor_1_previous_rank
5:input: neighbor_1_version
6:input: number
7:input: neighbor_1
8:input: neighbor_1_id
9:input: neighbor
10:input: neighbor_table_head
11:input: neighbor_table_next
12:input: n
13:input: m
14:input: p
15:ifversion!=240 //DEFAULTULT VERSION(DODAG) = 240
16:for neighbor_1 = neighbor_table_head; neighbor_1!= null; neighbor_1 = neighbor_table_next then
17:set number ++
18:set neighbor_1_id = address
19:set neighbor[number] = neighbor_1_id
20:set n[neighbor[number] = neighbor_1_current_rank
21:set m[neighbor[number] = neighbor_1_previous_rank
22:set p[neighbor[number] = neighbor_1_version
23:End for
24:End if
25:End
```

**Algorithm A4**. Version Number Attack Mitigation

```
1:Begin
2:input: version_count
3:input: divisor
4:input: version
5:input: ver
6:input: j
7:input: threshold_table
8:input: node_id
9:ifversion_count >= divisor then
10:set version = ver[j]
11://updating version number
12:set threshold_table[node_id] = 2
13:else
14:set threshold_table[node_id] = 3
15:endif
16:end
```

**Algorithm A5**. The Condition of the Initial Default Version Number

```
1:Set the initial value  
```
1:input: preferred_parent1
2:input: preferred_parent2
3:input: preferred_parent1_status
4:input: preferred_parent2_status
5:input:parent1_metric
6:input:parent2_metric
7:input: p1
8:input: p2
9:if preferred_parent1 == 1 || preferred_parent2 == 1 then
10:if parent1_metric < parent2_metric then
11:set p1
12:else
13:set p2
14:End if
15:else
16:if preferred_parent1_status!= 1 &&
17:preferred_parent2_status!= 1 then
18:if parent1_metric < parent2_metric then
19:set p1
20:else
21:set p2
22:endif
23:End if
24:End
```
**Algorithm A5** Rank Attack Mitigation
```
1:input: node_id
2:input: attack_status
3:input: alert
4:if attack_status[node_id] == 0 then
5:set alert: (legitimate node, node_id)
6:else
7:if attack_status[node_id] == 1 then
8:set alert: (malicious node, node_id)
9:endif
10:End if
11:End
```
```
**Algorithm A6** Attacks Isolation
```
1:input: node_id
2:input: attack_status
3:input: alert
4:if attack_status[node_id] == 0 then
5:set alert: (legitimate node, node_id)
6:else
7:if attack_status[node_id] == 1 then
8:set alert: (malicious node, node_id)
9:endif
10:End if
11:End ```  
```

**Algorithm A7** Attacks Isolation

## References

* (1) [PERSON]; [PERSON] A review on smart home present state and challenges: Linked to context-awareness internet of things (IoT). _Wirel. Netw._**2019**, _25_, 3193-3204. [CrossRef]
* (2) [PERSON]; [PERSON] [PERSON]; [PERSON]; [PERSON]; [PERSON] Internet of Things for Smart Cities. _IEEE Internet Things J._**2014**, \(1\), 22-32.