## 2 Methods
### Wireless bandwidth allocation
#### 2.2.4 Route Establishment and Data Transmission  
Our algorithm adopts the cross-layer computation principle for the route establishment process. Depending on the vehicle's velocity and position, wireless bandwidth allocation and longest link duration, an optimized path is chosen by the local controllers cooperating with SDN controllers for data flow transmission. Algorithm 1 shows the detail of the route discovery in our algorithm. These cross-layer metrics mentioned above are used to establish the routing path from source vehicle to destination vehicle, as shown in lines 12-14. Note that, the distance between source vehicle and destination vehicle is limited (lines 5 and 6), and the stack structure 'PathSet' could be used to store the route (lines 19-23). Algorithm 2 describes the whole session process of the proposed SDVN routing protocol, which can be divided into following four steps:  
1. each vehicle sends \"state updating\" messages (line 2),
2. the source vehicle sends RREQ packet (line 3),
3. the local controllers distribute RREP packets for link establishment (lines 4-10),
4. route refreshing phase (lines 11-14). When link damage is detected (line 11), check whether the P2P path can be repaired. If it can be repaired, continue to perform the data transmission along the repaired path. For instance, there is a vehicle \(v_{new}\) that can replace the broken node \(v_{i}\) while other nodes on the routing path have not changed, then the repaired path is \(s<->v_{1}<->\ldots<->v_{i-1}<->v_{new}<->v_{i+1}<->\ldots<->v_{n}<->d\). If the P2P path cannot be repaired, restart the routing discovery process to find another new P2P path. Figure 3 shows how the source selects the local controller and communicates with the SDN controller to find the final route from among all the paths between source and destination. Figure 2: Route reply (RREP) packet. ```
Input: NodeSet Output: Routing path from source vehicle to destination Initialize: CycleSet, PathSet, Head, Tail Notation: NodeSet: The vehicle's location at current cycle CycleSet: The prediction of vehicle's location at next cycle PathSet: The stack used to store routing path
1 Begin
2 if NodeSet is empty
3 say 'error' and go to 25
4 end if
5 if Distance (Source_node, Destination_ node) >Distance_Threshold
6 say 'error' and go to 25
7 CycleSet = calculate NodeSet location after Cycle
8 Head = Source_node
9 Tail = Destination_node
10 Push (PathSet, Head)
11 Sort CycleSet by Distance (CycleSet, Head)
12 for each Node\({}_{i}\)\(\in\) CycleSet from Head to Tail
13 if Distance (Head, Node\({}_{i}\)\(\cdot\)(x, y)) < Communication Radius of Vehicle AND Node\({}_{i}\)\(\cdot\)\(P_{forwarding}\) > threshold value \(P^{\prime}\)
14 if Available_bandwith \(BW_{\text{Nodei,head}}\) > threshold \(BW^{\prime}\)AND \(CLT_{i,Head}\) > interval time \(T^{\prime}\)
15 Push (PathSet, Node\({}_{i}\)) AND Head = Node\({}_{i}\)
16 end if
17 end if
18 end for
19 check if PathSet.top! = Tail AND PathSet.top! = Null
20 Node\({}_{x}\) = pop(PathSet) AND delete Node\({}_{x}\) from CycleSet AND Head = PathSet.top AND go to 12
21 end if
22 if PathSet.top = Null say' error' and go to 25
23 end if
24 say'success'
25 END Algorithm 1
```  
**Algorithm 1** route discovery process. ```
Input: Source vehicle \(v\) Output: Forward the data packet toward destination vehicle Notation: PathSet: The data structure used to store routing path CSI: The channel state information Next_Hop: The next hop vehicle
1. Begin
2. Each vehicle periodically unicasts message \"Hello_msg\" to nearest RSU with fields: velocity, location, pseudo-ID, CSI
3. The source vehicle \(s\) generates data to send AND sends RREQ message to nearest RSU
4. The local controllers cooperate with SDN controllers establish Pathset by Algorithm 1 OR repair the damaged path
5.