# Dynamic Control Architecture Based on Software Defined Networking for the Internet of Things
## 3 System Model
Moreover, \(\lambda(s,d)\) represents the _one-way_ latency needed to deliver a messages _flow_ from \(s\) to \(d\) nodes, while \(\theta(\pi_{s,d})\) is the minimum time interval in which all the nodes along the path \(\pi_{s,d}\) are jointly available. Finally, the last constraint is imposed to preserve the end-to-end flow from the source (\(\phi_{s,out}\)) toward the destination (\(\phi_{d,in}\)). It is worth recalling that in principle the solution of the optimisation problem (1) can be easily obtained by applying the Dijkstra algorithm, once a proper set of weights \(\mathbf{w}\) is applied to every link. To this purpose, a generalised time varying weight \(\mathbf{w}(t)\!\!\equiv\!\!\left\{w_{i,j}(t)\right\}\), associated to the link connecting the \(i\)th and \(j\)th nodes, is introduced as:  
\[w_{i,j}(t)=w_{\tau}(t)\frac{\tau}{\tau_{\text{max}}}+w_{\epsilon}(t)\frac{ \epsilon}{\epsilon_{\text{max}}} \tag{2}\]  
where \(\tau\) is the number of hops associated to the e2e path, \(\epsilon\) is the residual battery level of the destination node, \(\tau_{\text{max}}\) is the maximum number of hops, \(\epsilon_{\text{max}}\) is the maximum battery level and \(w_{\tau}(t)\) and \(w_{\epsilon}(t)\) represent the weighting factors to each terms, such that \(\forall t\,\ w_{\tau}(t)+w_{\epsilon}(t)=1\). In particular, \(w_{\tau}(t)\) and \(w_{\epsilon}(t)\) could be dynamically updated according to two different schemes:  
* _Reactive_ mode: An application can directly communicate with the SDN Controller and asynchronously compel the adoption of a shortest path, due to real time constraints. In this case, it is accomplished with \(w_{\tau}(t)\gg w_{\epsilon}(t)\), whereas the condition \(w_{\tau}(t)\ll w_{\epsilon}(t)\) is usually verified. * _Proactive_ mode: The SDN Controller autonomously modifies the weighting factors based on its own dataset of network related information. It is worth noticing that, according to our unifying formulation, the hop-based mode and the energy-forwarding strategies represent two special cases that can be easily implemented setting \(w_{\tau}(t)=1\) and \(w_{\epsilon}(t)=0\) or \(w_{\tau}(t)=0\) and \(w_{\epsilon}(t)=1\), respectively. Since battery consumption is mainly affected by packets transmission and reception, the SDN takes into account this drawback by adapting the _control_ messages rate, typically reducing it when the residual battery is below a certain critical level. Specifically, this is gradually accomplished using two thresholds:  
* _Soft_: It indicates that the node is no longer in a full energy state and, consequently, a moderate control message reduction can be applied. * _Critical_: In this case, the node has a limited residual battery and a more stringent energy management is necessary to avoid its shut down. When \(T_{s}\) is reached, the sending periods of Beacon and Report messages are exponentially increased. Further, when \(T_{c}\) is overcome, the above-mentioned periods are again increased according to an exponential rule. This approach allows the nodes to maintain an updated _upstream_ path to the Sink node (and to the Controller) and publish their data to an external data center (e.g., a Cloud), without significant performance degradation. The network view achieved by the SDN Controller depends mainly on the sending period of the Report messages. A high sending rate reduction can cause an update delay of the Controller's view and remarkable differences from the actual WSN. This situation may involve a considerable Packet Loss Ratio (PLR) and a greater Round Trip Time (RTT), especially in a mobile scenario. Additionally, the SDN Controller can also manage the node _Duty Cycle_ (DC) by varying the duration of its _active_ and _sleep_ states, where the latter usually is increased as the residual battery decreases. This procedure is usually adopted when the critical threshold is approached. To enable the DC procedure, the SDN Controller sends a specific message, called Config packet, which contains the sleeping period.