## 3 Control Layer Architecture
### Controller Architecture  
The goal of a controller is to have an overview of its nearby part of the network, considering that the mobility nature of the nodes keeps changing the network's topology. This mobility brings on a network \"segmentation\" in terms of groups of nodes that eventually are connected between them. Ideally, some controllers would be required to cover all the possible network segments. The controller operates opportunistically, i.e., its actuation is triggered by contacting another node or controller. When that happens, the controller shares both its aggregated context measurement and a directive with the contacted node. ```
1\(M_{i}\): List of context measurements received from contacted nodes. 2\(l\)_hostID_: Identifier of a host. 3\(excludeHost\): Id of the host whose measurement in \(M_{i}\) will not be used. 4\(sumDecays\): Sum of the decays of all the measurements in \(M_{i}\). 5\(M_{i}\)_keys_: Measurement list indexes. 6\(m\): A received context measurement represented by the tuple \((v,\eta,t)\)
7\(threshold\): Decay threshold under which the measurement is considered to be expired. 8\(sumNrAgggr\): Sum of the # aggregations a measurement is made of. 9\(\#aggrEntries\): # of elements in \(M_{i}\) that have been aggregated. 10\(aContextReading\): A local context measurement. 11\(v_{i}\): Aggregated measurement value. 12
1:functiongetSumOfDecays(\(M_{i}\),excludeHost)
13\(sumDecays\gets 0\)
14 forall\(hostID\in M_{i}\)_keys_do
15 if\(hostID\succeq excludeHost\)then
16\(m\gets M_{i}[hostID]\)
17\(d\gets decay(current\_time-m[t])\)
18 if\(d<threshold\)then
19\(M_{i}\).remove(hostID)
20 else
21\(sumDecays\mathrel{+}=d\)
22 endif
23 endif
24
25 endfor
26
27\(sumDecays\mathrel{++}\)\(\triangleright\) Adding the decay of my own reading. 28
29 return\(sumDecays\)
30 endfunction
31 functiongetSumOfNroFAGSRs(\(M_{i}\), excludeHost)
32\(sumNrAgggr\gets 0\)
33
34 forall\(hostID\in M_{i}\)_keys_do
35 if\(hostID\mathrel{!=}excludeHost\)then
36\(m\gets M_{i}[hostID]\)
37\(sumNrAgggr\mathrel{+}=m[\eta]\)
38 endif
39
40 endfor
410\(sumNrAgggr\mathrel{++}\)\(\triangleright\) Considering its own reading. 421 return\(sumNrAgggr\)
43 endfunction
44
45 functiongetAggregatedContextMeasurement(\(M_{i}\), excludeHost)
46\(v_{l}\gets aContextReading\)
47\(decays\gets getSumOfDecays(M_{i},excludeHost)\)
48\(aggrEntries\gets 1\)\(\triangleright\) Considering its own reading. 49\(v_{i}\leftarrow v_{l}((\alpha\frac{1}{agggr})+((1-\alpha)\frac{1}{decays}))\)
50 forall\(hostID\in M_{i}\)_keys_do
51 if\(hostID\mathrel{!=}excludeHost\)then
52\(m\gets M_{i}[hostID]\)
53\(d\gets decay(current\_time-m[t])\)
54\(v_{i}+m[v]((\alpha\frac{m[\eta]}{agggr})+((1-\alpha)\frac{d}{decays}))\)
55\(\#aggrEntries\mathrel{+}+\)
56 endif
57
58 endfor
59 return\(m_{i}=(v_{i},\#aggrEntries,t)\)
60
610 endfunction
```  
**Algorithm 1** Context measurements aggregation algorithm. To generate a directive, the controller implements the closed-loop control system, also known as feedback control system [28], showed in Figure 3. A closed-loop control system is a control system that maintains a constant relation between the output of the system (\(\epsilon\): controlled variable) and the desired value (\(\tau\): the reference input) by subtracting one from the other as a measure of control. In the proposed control system, the controller feeds from incoming aggregated context measurements (\(m_{i}\)) and determines the value of the manipulated variable \(\mu\) out of those measurements and the system's reference input \(\tau\). The resulting manipulated variable \(\mu\) is encapsulated in an outgoing directive and shared with any node that might come into contact. Additionally, [PERSON] et al. [26] stated that considering the current condition of the OppNet to trigger an actuation is not effective as it would be too late, given the variability of the network. Following their considerations, proactively, we decide the actions to be taken based on predicting the network situation.