## 4 Layered SDN-Based Optimization Framework
### Iterative Solution via Gradient Descent
Let us start by considering the optimization at the bottom layer as the one that operates at the minimum latency, i.e., the time difference between the time indexes \(t\) and \(t+1\) is the Round Trip Time (RTT) between GW and eNB \(\tau_{N}^{G}\) (considered equal, for simplicity, for all GWs and eNBs), since it is the one closest to the devices and to the information regarding traffic. To map all the time instants into integer values of \(t\), it is convenient to normalize all times with respect to \(\tau_{N}^{G}\) (i.e., we set \(\tau_{N}^{G}=1\)). Our framework considers that in actual network infrastructures one has constraints that prevent the redistribution of the total resource across the operators (e.g., the decisions \(\{x_{0}:o=1,\ldots,O\}\)) and redistribution of operator resources across the GWs (e.g., the decisions \(\{y_{g}:g\in\mathcal{G}\}\)) from changing at the same timescale of the redistribution of GW resources across the eNBs (e.g., the decisions \(\{z_{n}:n\in\mathcal{N}\}\)). Therefore, even if a genie could compute the optimal solution of the decomposed problem at each instant \(t\), it might not be possible to implement the decision. ```
Input :\(y_{g},\{Q_{n}:n\in\mathcal{N}_{g}\}\) Output :\(\lambda_{y_{g}}^{*},\mathbf{z}_{g}\) if\(\sum_{n\in\mathcal{N}_{g}}Q_{n}\geq y_{g}\)then  Find the permutation \(\boldsymbol{\pi}=\{\pi_{i}:i=1,\ldots,|\mathcal{N}_{g}|\}\) to  sort the queues \(Q_{n}\) such that \(i\geq j\Rightarrow Q_{\pi_{i}}\leq Q_{\pi_{j}}\);  Find \(i^{*}=\inf\{i:\sum_{j=1}^{i}Q_{\pi_{j}}\geq y_{g}\}\); \(z_{\pi_{j}}=Q_{\pi_{j}}\) for \(j<i^{*},z_{\pi_{i^{*}}}=y_{g}-\sum_{j=1}^{i^{*}-1}Q_{\pi_{j}}\), \(z_{\pi_{j}}=0\) for \(j>i^{*}\), \(\lambda_{y_{g}}^{*}=Q_{\pi_{i^{*}}}\); else \(z_{n}=Q_{n}\;\forall n\in\mathcal{N}_{g},\lambda_{y_{g}}^{*}=0\);  end if
```  
**Algorithm 1**Solution of (9) (at GW \(g\)). Denoting with \(\underline{L}\) and \(\underline{P}\cdot\underline{L}\) the minimum refresh times for the GW decisions \(\boldsymbol{y}\) and for the operator's decisions \(\boldsymbol{x}\), respectively, time \(t\) can be written according to a poly-phase decomposition as  
\[t=(mP+p)L+\ell,\;m\in\mathbb{N},\;0\leq p\leq P-1,\;0\leq\ell\leq L-1, \tag{15}\]  
where \(P\cdot L>\underline{P}\cdot\underline{L}\) and \(L>\underline{L}\) are the selected refresh times. We illustrate the multi-timescale dynamics of the optimization framework in Figure 2 showing the interactions of eNBs, GWs, operators, and SDN orchestrator. In the next subsection, to comply with the refresh time limits, the greedy optimization, decoupled at any instant \(t\), is mapped into the stochastic optimization we solve. Changing the objectives from deterministic values to expected values is necessary to capture the uncertainty of the impact of the decisions \(\boldsymbol{x}\) and \(\boldsymbol{y}\) on the future queues evolving at a faster timescale, e.g., on the effect that a change in higher layers' resources distribution, produces on the lower layers' optimizations. ```
Input :\(\lambda_{Z}^{(0)}\), \(k_{4}=0\) Output :\(\lambda_{Z}^{(K_{4})}\), \(\mathbf{x}\) while\(k_{4}<K_{4}\)do  Call Algorithm 3 with input \(\lambda_{Z}^{(k_{4})}\) to all operators;  Receive \(\mathbf{x}^{(K_{3})}\Big{(}\lambda_{Z}^{(k_{4})}\Big{)}\) and update \(\lambda_{Z}^{(k_{4}+1)}\) via (11); \(k_{4}\gets k_{4}+1\);  end while  Decide \(\mathbf{x}[m+1]\) by projecting \(\mathbf{x}^{(K_{3})}\Big{(}\lambda_{Z}^{(K_{4}-1)}\Big{)}\) onto the feasible set in (2); \(m\gets m+1\);  Call Algorithm 2 with input \(\lambda_{Z}^{(0)}\leftarrow\lambda_{Z}^{(K_{4})}\);
```  
**Algorithm 2**At the SDN orchestrator. Figure 2: Illustration of the dynamics of the multi-timescale optimization framework within context of LayBack infrastructure: the optimal policy to minimize end-to-end delay is decoupled into multiple layers of sub-problems, with faster timescales at the lower LayBack layers The eNBs \(n,\ n\in\mathcal{N}_{g}\), at a GW \(g\) pass their queue occupancies each eNB-GW round-trip time RTT \(\tau_{N}^{G}\) to GW \(g\).