# Whisper: Programmable and Flexible Control on Industrial IoT Networks
## 3 Whisper Framework: SDN without SDN
### Algorithms Description
#### 3.4.3 Selecting Primitives  
Finally, the last step of Whisper translates each building block into one or more primitives. There are different algorithms to create primitives--one for each block--and they will be executed every time a block is needed. The most important algorithm is the one that creates the primitives for the _Switch parent_ block which we detailed in Algorithm 3 (the algorithm for the _Cell allocation_ block is only a simple translation to 6P commands (add or delete). The Forwarding block is a particular case of _Switch parent_ where \(d_{t_{j}}=w_{i}\)). Algorithm 3 iterates through the parent candidates \(PC_{t}\), of the target node \(t\) that has a tentative rank lower or equal to the rank the target node perceives from its desired parent \(d_{t}\). For every of these parent candidates, it checks if they are in the same branch as \(d_{t}\). In case they are in the same branch, only if the node is not in the same branch as \(t\) as well and there is only one other neighbor with the same rank can the solution be done in three steps. First, one switches towards the neighbor with the lowest rank with a Primitive 1, the second increases the rank of the branch of t with a Primitive 2 and performs a second switch towards \(d_{t}\) with an extra Primitive 1. Otherwise, the algorithm will notifythe operator that there is no solution with the current assumptions and that a Whisper node has to be used. In case the parent candidate is not in the same branch as \(d_{t}\), then the rank of the branch will be increased directly from the root by sending a propagating DIO (Primitive 2) to the head of the branch of that candidate. This way, by artificially increasing the rank of the different candidates directly from the root, the rank that t sees from \(d_{t}\) will be the lowest. This way \(d_{t}\) will be chosen by \(t\) as preferred parent after receiving a remote DIO (Primitive 1) from the root with an artificial rank increase _inc_. However, these increments will not be always possible, since they could trigger undesired additional parent switches in other parts of the branch, if not a cascade effect that could destabilize the entire network. In order to know if these increments are possible, the so-called constraint nodes \(CN_{t}\) are obtained for a given increment _inc_. These constraint nodes are the ones that would provoke an undesired switch if they receive an increment of rank _inc_. Once they are obtained, the function _isPossibleExtendDioPropagation()_, following an iterative greedy approach, calculates if there can be increments of _inc_ in the branches coupled with the constraint nodes. ```
1:procedureSelectPrimitives()
2:for\(n\) in \(PC_{t}-\{d_{t}\}\) if \(RANK_{t}(n)<=RANK_{t}(d_{t})\)do
3:if\((P[0]_{n}=P[0]_{d_{t}})\)then
4:if\(P_{n}[0]==P_{t}[0]\)then
5: A W node is needed. Abort and report with new G*(N',E') return
6:else
7:ifLen ([for m in \((PC_{t}-\{d_{t}\}\)] if \(P_{m}[0]=P_{n}[0]\)])=1 then
8: get \(CN_{t}[I]\)
9:\(inc=abs(RANK_{t}(d_{t})-RANK_{t}(n))+1\)
10:if possibleExtendDioPropagation(inc) then
11:\(I[P_{t}[0]]=inc\), if lower or equal than previous \(I[P_{t}[0]]\)
12: needExtraRemotePrimitive1=TRUE
13:else
14: A W node is needed. Abort and report with new G*(N',E') return
15:else
16: A W node is needed. Abort and report with new G*(N',E') return
17:else
18: get \(CN_{n}[I]\)
19:\(inc=abs(RANK_{t}(d_{t})-RANK_{t}(n))+1\)
20:if possibleExtendDioPropagation(inc) then
21:\(I[P_{n}[0]]=inc\), if lower or equal than previous \(I[P_{n}[0]]\)
22:else
23: A W node is needed. Abort and report with new G*(N',E') return
24: numNeighboursProcessed+=1
25:if numNeighboursProcessed == 0 then
26:return \"Primitive 1: remote DIO from \(r\) to \(t\) with RANK 2599\"
27:else
28:return preparePrimitives(\(I\), needExtraRemotePrimitive1)
```  
**Algorithm 3** Select Primitives: Switch Parent block  
If these new branches have additional CNs, these new CNs will also be iterated until a stable solution is found, or until the entire network has been tracked.