## 3 DenseNet-Hybrid Control Plane Architecture
### Control Logic Switching Algorithm  
As a consequence of any impairment experienced by the control plane, due to either failure of the SDN controller or a degraded control channel, CPLR values will increase, and an anomaly will be inferred by the network node. Algorithm 1 describes the control logic switching algorithm. All state decisions have been explicitly reflected for the sake of clarity. This algorithm is periodically run in the local agent of each node. Each of these periods is referred to in Algorithm 1 with subindex \(k\in\mathbb{N}\). The local agent will call this algorithm by providing the \(current\_state\), the measured CPLR (calculated by the _CPLR detector_ module), and the slope calculated in the previous period (\(S_{k-1}\)) and the current one ((\(S_{k}\))) and will obtain, as output, the operational mode to be configured, which will only be applied by the local agent if different from \(current\_state\). There are various design criteria behind this algorithm. Since our goal is to stay as much as possible in centralized mode and only use the distributed mode as abackupoperational mode, the algorithm is more conservative (i.e., it attentps to make sure) when switching from centralized to distributed than vice versa (lines #3-15). The rationale behind this is that the application of network-wide management policies is easier when operating in centralized mode due to easier programmability through the SDN controller APIs and functionality. Furthermore, switching to distributed operation implies certain control message exchange and processing (Section 3.3.1). On the other hand, the algorithm will decide to switch to centralized mode in a greedier manner (i.e., based on slight improvements in network conditions), for the reasons explained above (lines #16 et seq. ), as soon as network conditions improve. To control its operation, there are two main parameters in the algorithm. First, \(CPLR_{max}\) is the CPLR under which TCP retransmissions are enough to guarantee (even if delayed) the interaction between the SDN controller and the node, though, as observed in Section 4, there may be an impact in network performance. Second, the conservative behavior is represented by parameter \(\delta\), the value of the slope (\(S_{k}\)) of the curve CPLR vs. t in the current period \(k\) that, if exceeded, implies a noticeable increasing trend of CPLR (line #6). Therefore, it is based on an increasing trend and not based on instantaneous CPLR values that the algorithm decides to switch to distributed operation. That is, at least it takes having an increasing slope above \(\delta\) during two evaluation periods to switch (lines #6-7). However, if the instantaneous value is such that CPLR is above \(CPLR_{max}\), which means that network performance cannot be guaranteed (even if with high losses), the switching decision is taken without waiting for evaluating the slope in the following period (line #13). **Input**: \(current\_state\), \(CPLR\), \(S_{k-1}\), \(S_{k}\)  
**Output**: \(next\_state\)\(\triangleright\) centralized or distributed  
```
1:procedureDECIDE_STATE
2:if\(current\_state\)=centralizedthen
3:if\((CPLR<CPLR_{max})\)then
4:if\(S_{k}\leq\delta\)then\(\triangleright\) If low CPLR increasing trend
5:\(next\_state\)=centralized
6:else
7:if\(S_{k-1}>\delta\)then
8:\(next\_state\)=distributed
9:else
10:\(next\_state\)=centralized
11:endif
12:endif
13:else
14:\(next\_state\)=distributed
15:endif
16:else
17:\(\triangleright\)\(current\_state\)=distributed
18:if\(S_{k}>=0\)then
19:\(next\_state\) = distributed
20:else
21:if\(CPLR<CPLR_{max}\)then
22:\(next\_state\)=centralized
23:else
24:\(next\_state\)=distributed
25:endif
26:endif
27:endif
28:endprocedure
```  
**Algorithm 1** Pseudo code of the control logic switching algorithm.