# Blockchain-Assisted QoS-Aware Routing for Software-Defined Wide Area Network
## 3 System Architecture
### QoS-Aware Route Selection (QRS) Algorithm  
QRS's route selection algorithm includes a matching process to find the best-suited routing path for each application's traffic using Algorithms 1 and 2.  
```
Input:\(A_{i}\): application \(i\)'s QoS preference values \(v_{i}\) and weights \(w_{i}\), P: a list of probable packet routing paths, \(\beta\): a threshold value Output:\(N_{i}\): a list of routing paths satisfying \(A_{i}\)'s preferences
1\(N_{i}\leftarrow\phi\)for each p \(\epsilon\) P do
3 if matching(\(v_{i}\),P) \(\geq\beta\)then
4\(N_{i}\gets N_{i}\cup\) P
5 endif
6 endfor
```  
**Algorithm 1** Preference-matching algorithm (\(A_{i}\), \(P\), \(\beta\)) [27].  
To facilitate the routing path selection for a cloud application \(A_{i}\), the algorithm commences by considering all the paths to the neighboring router. However, it is important to note that all routers in the surrounding area or the currently considered router may not possess the required capabilities to meet the preferences outlined in \(v_{i}\). The QRS algorithm, therefore, identifies a subset of routing paths, denoted as \(N_{i}\), from the possible paths in P. These selected paths must offer support and align with the specified requirements at a certain matching score threshold denoted as \(\beta\) where the threshold \(\beta\) can ensure some extra capabilities that the considered routing path should also support.  
The \(A_{i}\)'s preference requirements for a cloud user as mentioned in \(v_{i}\) are compared with each path's capability using Equation (1):  
\[matching(v_{i},p)=\frac{\sum_{y=1}^{t}v_{i,y}\ p_{i,y}}{\sqrt{\sum_{y=1}^{t}v_ {i,y}^{2}\sum_{y=1}^{t}p_{i,y}^{2}}} \tag{1}\]  
If the \(matching(v_{i},p)\) value is greater than or equal to \(\beta\), then the network path \(p\) is considered to be suitable to satisfy \(A_{i}\)'s preference requirements and is included in \(N_{i}\). Here, \(p_{i,y}\) is the routing path \(p_{i}\)'s capability to satisfy the QoS requirement considering parameter \(y\).  
In Equation (2), \(\gamma(r,v_{i},k)\) measures the degree to which the cloud application \(A_{i}\) can find satisfaction in the chosen routing strategy \(r\) while considering the preference parameter k. When \((p_{r,k}-v_{i,k})\) equals zero, it signifies that routing path r can precisely fulfill the preference requirement k of \(A_{i}\). However, if \((p_{r,k}-v_{i,k})\) yields a negative result, it indicates that routing r falls short of satisfying \(A_{i}\)'s preference k. In this context, \(\gamma(r,v_{i},k)\) is ideally designed to encompass the minimum positive value among all the computed values.  
PrefMet(\(A_{i}\),\(\mathbf{r}\)) is an indicator to understand how closely the option \(r\) meets the preference requirements of \(A_{i}\) considering the weights of \(A_{i}\) on all the k features.  
\[PrefMet(A_{i},r)=\sum_{k=1}^{t}\frac{w_{i,k}}{\gamma(r,v_{i},k)}, \tag{2}\]  
\[\gamma(r,v_{i},k)=\left\{\begin{array}{rl}p_{r,k}-v_{i,k},\text{if }p_{r,k}>v_{i,k} \\ \min_{p\in N_{i}}\{\mid p_{r,k}-v_{i,k}\mid\
eq 0\},\\ \text{if }p_{r,k}=v_{i,k}\\ \mid p_{r,k}-v_{i,k}\mid+max_{p\in N_{i}}\{\mid p_{r,k}-v_{i,k}\mid\},\\ \text{if }p_{r,k}<v_{i,k}\end{array}\right.\]  
PrefMet(\(A_{i}\),\(r\)) results can be used in Equation (3) to select the best-suited routing path \(r_{\mu}\) for the application \(A_{i}\).  
\[r_{\mu}=SelectedPath(A_{i})=arg_{r\in N_{i}}max\ PrefMet(A_{i},r) \tag{3}\]  
When the routing path \(r_{\mu}\) is the selected path for the application traffic of \(A_{i}\), then Equation (4) can provide the cloud user of \(A_{i}\)'s satisfaction index, and based on this, the cloud user completes the payment to the SDN providers.  
\[Satisfaction(A_{i},r_{\mu})=1-\frac{1}{t}\sum_{k=1}^{t}\frac{\mid v(r_{\mu},k )-v_{i,k}\mid\times w_{i,k}}{v_{i,k}} \tag{4}\]