## 3 Control Layer Architecture
### Context Indicator Prediction  
The controller anticipates the context indicator value using a two-step strategy. Firstly, instead of directly considering the received context measurements, the controller aggregates them for a configurable time (\(\hat{t}\) ) using (3). This step results in two lists: \(\tilde{M}\) and \(\tilde{T}\). \(\tilde{M}\) contains the aggregation of the measurements received for periods of \(\hat{t}\) seconds. This list is represented as \(\tilde{M}=[\hat{m_{j}}\mid 1\leq j\leq\hat{z}]\), where \(\hat{z}\) is the max size of \(\tilde{M}\). \(\tilde{T}\) contains the time when each entry in \(\tilde{M}\) was calculated and is represented as \(\tilde{T}=[\tilde{t_{j}}\mid 1\leq j\leq\hat{z}]\). Secondly, once several aggregated samples of context measurements are available, these are used as an input of a linear regression (\(\rho\)) to calculate the prediction of this context indicator value for time \(t_{t+n}\):  
\[m_{t+n}=\rho(t_{t+n},\tilde{M},\tilde{T}) \tag{4}\]  
where \(\tilde{M}\) and \(\tilde{T}\) are sliding lists of size \(\tilde{z}\), \(t_{t+n}\) is the time ahead for the context indicator prediction and it is calculated as \(t=t+n\) where \(n\) is an offset, and \(m_{t+n}\) is the resulting predicted value of the context indicator value at time \(t_{t+n}\). Algorithm 2 shows how the controller calculates the prediction of a context indicator. The _addContextMeasurement_ procedure is executed by the controller when a contacted node shares its aggregated context measurement (\(m\)). This measurement is stored in the controller's received measurements list \(M_{i}\) (_line 2_). If the window time for receiving measurements from contacted nodes has expired (_line 3_), the controller aggregates all the received aggregated context measurements in the list \(M_{i}\) and its local context measurement, by using the procedure _getAggregatedContextMeasurement_ (_line 5_) defined in Algorithm 1. This aggregation result (\(\hat{m}\)) is stored in the list \(\tilde{M}\) along with the current time (_lines 6-7_ of Algorithm 2). The controller uses the entries in the above lists to calculate a prediction of the value of the context indicator (\(m_{t+m}\)) using a linear regression function \(\rho\) (_line 10_). The controller maintains the size of the aggregation calculations list \(\tilde{M}\) at the constant  
Figure 3: Closed-loop control system for congestion control. value \(\hat{z}\) by using a FIFO discarding policy (_lines 12-13_). Notice that at least two inputs are needed to use the linear regression function \(\rho\) (_lines 8_ and 9). If this condition is not fulfilled, the predicted measurement (\(m_{t+n}\)) assumes the value of the \(\hat{m}\) calculated at _line 5_ (_line 15_). Once \(m_{t+n}\) is calculated, \(M_{i}\) is emptied, ready to receive new context measurements from other contacts (_line 19_). A new aggregation window period (\(aggrTimeout\)) is configured, so all the measurement gathering and the prediction process starts over (_line 20_). ```
1:\(\triangleright\)\(M_{i}\): List of context measurements received from contacted nodes. 2:\(\triangleright\)\(m\): Received context measurement (controlled variable). 3:\(\triangleright\)\(t\): Current time. 4:\(\triangleright\)\(aggrTimeout\): Timeout for aggregating incoming context measurements. 5:\(\triangleright\)\(\hat{t}\): Time period for aggregating incoming context measurements. 6:\(\triangleright\)\(\hat{m}\): Aggregation of the received context measurements during \(\hat{t}\) s.
7:\(\triangleright\)\(\hat{M}\): Sliding list of the aggregations so far. 8:\(\triangleright\)\(\hat{T}\): Sliding list of the times when the aggregations were performed. 9:\(\triangleright\)\(t_{t+n}\): Prediction time. 10:\(\triangleright\)\(m_{t+n}\): Predicted value of the context indicator at \(t_{t+n}\).