# QoS Aware and Fault Tolerance Based Software-Defined Vehicular Networks Using Cloud-Fog Computing
## 4 Proposed Solution
### Qaft-SDVN Proposed Model
Messages priority is calculated according to deadline and size; priority is calculated of the generated messages, if the priority is less or equal to the priority of deadline and size of the messages that are given in the table, then we assign it to list 1 otherwise to list 2. The following Algorithm 3 is used for messages forwarding according to priority assign to them:```
Input:\(W_{1}\) & \(W_{2}\) (Two list one of safety messages while the other one of non-safety messages) Output:Sending messages receipt and database storage
1. For 1 to n
2. Send \(W_{1}\) (ascending order)//Send priority basis/safety messages
3. Send to Fog Nodes by using Algorithm 4
4. End of for loop
5. For 1 to n
6. Send \(W_{2}\) (first come first serve basis)
7. Send to Fog Nodes by using Algorithm 4
8. End of for loop
9. Save record to cloud for future use
```

**Algorithm 3** Messages forwarding to vehicles for information and cloud

Algorithm three works based on received messages; the input consists of two lists from Algorithms 1 and 2. The first safety messages that are provided in Table 1 are sent. Then, the second list of normal messages is sent according to a first-come and first-serve basis. ```
Input:\(W_{1}\) & \(W_{2}\) (Two list one of safety messages while the other one of non-safety messages) Output:\(\epsilon\) (Successful messages)
1. For 1 to n
2. If Source received Ack
3. Then assign \(M_{i}\) to \(\epsilon\) (Successful messages) // No action
4. Else
5. {
6. assign \(M_{i}\) to \(\phi\) (Failed tasks/messages) // resend messages
7. Call Algorithm 3
8. } 9. End of for loop
10. Return \(\epsilon\)
```

**Algorithm 4** Fault-Tolerance Mechanism for SDVN

In step 3, we call Algorithm 4 for fault tolerance; if any message failed and did not reach the proper destination, then we provided a mechanism in algorithm four that will solve it accordingly. Algorithm 4 is provided to tackle fault tolerance of the sent messages of vehicles. Algorithm 4 is used for failed and successful tasks; if the source receives the acknowledgment, then we assign it the list of successful messages; otherwise, we assign it to failed tasks/messages list and further resend according to Algorithm 3. ## 5 Simulation Setup and Results

This section consists of resource modeling, application modeling, performance parameters, and results. Results are provided based on different scenarios. ### Resource Modeling

For the implementation and simulation of the proposed model, we need a real VANET environment, but a real environment is costly and cannot be created easily. So, for a simulation of the proposed model, we used CloudSim [32] & iFogSim [33]. Further pricing mechanism and resources allocation mechanism was obtained from [34; 35; 36]. We used vehicles for sending messages, SDN nodes, SDN controller, fog nodes in which we placed SDN nodes, and Cloud for heavy processing and storage. Further detail of the simulation environment is provided in Table 3.

### Application Modeling

Multiple vehicles are considered to send messages to nearby fog nodes in which SDN nodes and controllers are fixed. The following Table 4 consists of the application model for the proposed model:

The following Table 5 consist of each datacenter power that will be used for tasks execution:

### Simulation Process

In the simulation of the proposed model first, we created datacenters of clouds and their sub datacenters of fog. We created different vehicles which send data to nearby RSU/Gateways. Random tasks. Tasks are also created randomly as provided in the above table. Randomly the messages/data are sent to RSU/Gateways by the vehicles. The RSU/Gateway prioritizes the data in safety and non-safety messages by using a priority algorithm. The RSU/Gateway further forwards safety messages to the fog node while non-safety messages to the cloud. Fog node used the least priority first policy for the execution of the data while Cloud used FCFS scheduling model for execution of the offloaded data.