# Multi-Constraint and Multi-Policy Path Hopping Active Defense Method Based on SDN
## 4 Design of Multi-Constraint Multi-Strategy Hopping Algorithm
### Hopping Strategy Execution Algorithm  
This paper proposes a multi-constraint and multi-strategy path hopping mechanism, which uses the proportion of the remaining bandwidth of the link as the threshold. When the remaining bandwidth of the link is greater than the threshold (\(B_{i,j}\geq X\)), it means that the network has not suffered from flooding or DDoS attacks, so the hopping strategy is mainly to resist eavesdropping, and the next hopping path is selected based on \(W_{1}(path_{i}^{S\to D})\) for the next cycle. At the same time, in order to achieve dynamic changes in the hopping cycle, the hopping cycle is combined with the path weight, as shown in Equation (11), where \(A\) is a constant, and \(T\) is the cycle of executing hopping. When the remaining bandwidth of the link is less than the threshold (\(B_{i,j}\leq X\)), it means that the current link is transmitting a large amount of data or is under attack. The purpose of selecting the hopping path based on the path weight above is to avoid key nodes, enhance the diversity and unpredictability of hopping, and effectively resist eavesdropping attacks, but it cannot effectively resist attacks such as flooding. Therefore, this paper designs a multi-strategy hopping mechanism. When the remaining bandwidth of the link is lessthan the threshold, in order to effectively resist link-flooding or DDos attacks, the hopping path is selected based on the remaining bandwidth of the link. The greater the remaining bandwidth, the higher the probability of selection, as shown in Equation (12). Because the weight and remaining bandwidth of each path are different, the hopping cycles are also different, and they can switch between the two path selection modes adaptively according to the current network status. Compared with the random selection and fixed hopping cycle of existing research, this method enhances the diversity and unpredictability of hopping and improves the defense capability of the network. The hopping strategy execution algorithm is shown as Algorithm 1. \[T =A*W_{1}(path_{i}^{S\to D}) \tag{11}\] \[T =A*W_{2}(path_{i}^{S\to D}) \tag{12}\]  
```
1:Space\({}^{S\to D}\), \(W_{1}(path_{i}^{S\to D})\), \(W_{2}(path_{i}^{S\to D})\), \(NC_{ik}\), \(B_{ik}\), \(J_{m*m}\), \(L_{m*n}\)
2:\(path_{i}^{S\to D}\)
3:functionHoppingStrategy(\(S,D,W_{1},W_{2},NC_{ik},B_{ik}\), \(J,L\))
4:Set \(A\), \(X\)
5:Initial \(alternate\_paths=[]\), \(T_{now}=0\), \(weight1=weight2=0\)
6:while True do
7: Update \(NC_{ik}\), \(B_{ik}\)
8:for\(path_{i}\) in Space\({}^{S\to D}\)do
9:if\((i,j)\leq a\) and \((T_{now}-T_{recent}\geq\beta\) or \(T_{recent}==0)\) and \(B_{ik}\geq B\)then
10:alternate\_paths.append\((path_{i})\)
11:endif
12: Update \(W_{1}(path_{i}^{S\to D})\), \(W_{2}(path_{i}^{S\to D})\)
13: Sleep \((T)\)
14:endfor
15:endwhile
16:if\(B_{i,j}\geq X\)then
17:\(T=A*W_{1}(path_{i}^{S\to D})\)
18:\(num=random(0,1)\)
19:for\(i\) in \((0,1,2,\ldots,len(alternate\_paths))\)do
20:\(weight1=weight2+W_{1}(path_{i}^{S\to D})\)
21:if\(weight2<num\leq weight1\)then
22:\(T_{recent}=T_{now}\)
23:\(path^{S\to D}=path_{i}^{S\to D}\)return\(path^{S\to D}\)
24:else
25:\(weight2=weight1\)
26:endif
27:endfor
28:else
29: mark this link is false
30:if this link is false then
31:\(T=A*W_{2}(path_{i}^{S\to D})\)
32:endif
33:endif
34:endfunction
```  
**Algorithm 1** Hopping Strategy Execution Algorithm  
This algorithm first sets the coefficient \(A\), the threshold \(X\), and \(B_{i,j}\) as the remaining bandwidth of the current communication path. Select paths that meet the path similarity constraint, selection cycle constraint, path remaining bandwidth constraint, and path remaining node capacity constraint from the path hopping space and store them in the alternative path space. Because the remaining bandwidth and node capacity of paths in the network are changing in real time and the current communication path used is different, its path similarity constraint is also different, and the alternative path hopping space is also different, so it is periodically updated, as shown in steps 2 to 13.