# A QoS-Guaranteed and Congestion-Controlled SDN Routing Strategy for Smart Grid
## 3 Design of QCORS Algorithm
### Packet-Redirection Strategy Model  
For a given topological pattern, the paths between nodes are calculated by the controller based on the routing algorithm. Routes between a pair of nodes are generally not recalculated unless the topology changes [49]. In this case, when an application flow breaks out, some key links may carry excessive loads. In the previous section, because the link load has been mapped to different levels of congestion, the controller can deal with the links according to the detected situation. Let \(G^{\prime}\) denotes a new virtual topology called no congestion link. In this case, if there is a link that is determined to be congested. It is supposed to be blocked to achieve a better transmission performance. An example is shown in Figure 3. Suppose the left one is the original communication topology, and the center link is considered a congested link. Then for the next coming packet, it will choose other links rather than the congested one even if it has to go through more hops to the destination. (1) Data collection: The node collects data from its predecessor and sends it to the successor. The range of data collection for node \(n\) is:  
\[0\leq\sum_{a\in I(n^{t})}x_{n}^{t}(a)\leq x_{max},\forall n\in N, \tag{4}\]  
where \(x_{n}^{t}(a)\) denotes the amount of data collected by node \(a\) in slot \(t\). In addition, \(a\in I(n^{t})\) represents the set of all predecessor nodes of node \(n\) at time \(t\), and \(x_{max}\) indicates the maximum data size collected by any node in the time slot. (2) The amount of transmission of the node. Considering time-varying characteristics of link capacity, it is assumed that link capacity is independent and identically distributed in different time slots. Moreover, all the output data should be less than or equal to the \begin{table}
\begin{tabular}{l c} \hline \hline
**Value of Congestion Level** & **Traffic Load Range at Link \(\boldsymbol{sd}\)** \\ \hline (1) No congestion & \(\overline{C(P_{sd}^{t})}\leq C(P_{sd}^{t})_{law}\) \\ (2) Low congestion & \(C(P_{sd}^{t})_{law}\leq\overline{C(P_{sd}^{t})}\leq C(P_{sd}^{t})_{high}\) \\ (3) Heavy congestion & \(\overline{C(P_{sd}^{t})}\geq C(P_{sd}^{t})_{high}\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Link load and congestion level mapping. Figure 3: The visualization of our strategy. (**a**) Topology at time \(t\); (**b**) Topology at time \(t+1\). The red link represents the “to be congested” link, and the green represents the “no congestion” link. Our designed algorithm is expected to avoid selecting the “congestion link” to improve the next-coming transmission. link capacity. Thus the transmitted data amounts of node \(n\) should have the following constraints:  
\[0\leq\sum\limits_{f}\sum\limits_{b\in O(n^{t})}x_{n}^{t}(b,f)\leq C_{n}^{t}(b), \forall b\in O(n), \tag{5}\]  
where \(C_{n}^{t}(b)\) represents the link capacity of the link \((n,b)\). Let \(x_{n}^{t}(b,f)\) denote the sum of \(f\) class data transferred between nodes \((n,b)\) in slot \(t\). In addition, in slot \(t\), the amount of data that node \(n\) sends to node \(b\) cannot exceed \(Q_{n}(t)\), which is the total queue size in node \(n\) at current time \(t\):  
\[0\leq\sum\limits_{b\in O(n^{t})}x_{n}^{t}(b)\leq Q_{n}(t),\forall n\in N. \tag{6}\]  
Based on Lyapunov optimization [37,38,44], the network can guarantee stability only if the following inequality can be satisfied,  
\[\lim\limits_{T\rightarrow\infty}\frac{1}{T}\sum\limits_{t=0}^{T-1}\sum\limits_ {n\in N}E[Q_{n}(t)]<\infty, \tag{7}\]  
where \(Q_{n}(t)\) denotes the length of the data queue at node \(n\) in slot \(t\). This means the total queue length in the system is bounded in the case of an infinite horizon. (3) Data queue model: \(Q_{n}^{f}(t)\) then represents the queue occupied by data of class \(f\).