## 4 Proposed Model
### Delay and Latency Model  
For mathematical analysis, the delay and the latency of data transfer were calculated by implementing several equations. In this process, the delay mainly occurred due to the burden of the requests put on the node, instead of its capacity. We chose node \(N\), which has the least burden of requests, to assign a request. The burden produces the time taken report after the execution of the request, which can be calculated through Equation (1). \[B_{c}=B_{c}^{strt}+B_{c}(Rt) \tag{1}\]  
where \(B_{c}^{strt}\) is the burden of node \(c\) at the starting time and is updated frequently, and \(B_{c}(Rt)\) is the overall time to process the request \((Rt)\) on the processing node \(c\), mathematically analyzed according to Equation (2). \[B_{c}(Rt)=e(Rt,N)+t(Rt,N) \tag{2}\]  
where \(e(Rt,N)\) is the time taken for the execution of the request's data transfer of \((Rt)\) on selected node \(c\) and \(t(Rt,N)\) is the transmission time for transferring the request data needed by a request \((Rt)\) to the chosen node \(N\). In our case, the chosen node is \(c\). In the balanced step, \(t(Rt,N)=0\) due to the location of the request. The execution time \(e(Rt,N)\) of processing a request in the selected node \(N\) is calculated according to Equation (3). \[e(Rt,N) =\frac{Complexity\ of\ request\ data\ transfer\ Rt}{Processing\ capacity\ of\ node\ c} \tag{3}\]  
The request execution time depends on the complexity of the request's data. This means that the more complex the data, the longer the execution time. The complexity of the request data transfer is collected from the \"Data Collector Module\" (DCM), and the processing capacity of the chosen node \(N\) is collected from the \"Resource Collector Module\" (RCM). The processing capacity is addressed as MIPS. To maintain the node burden, we iteratively changed the request location in different fog nodes and cloud data centers. We sent the request to a nearby fog node if the priority of the request was high, otherwise, it is sent to the cloud. AvgDelay is the time that surpassed the peak reply time for every one of the requests and is determined as in Equation (4). \[\text{AvgDelay}=\sum_{m=1}^{n}Delay\ (Rm)\frac{1}{No.\ of\ requests\ missing\ MaxResponse(n)} \tag{4}\]  
where \((Rm)\) is a lost request due to the exceedance of replay time. A direction failure of the request occurs when the distance between two communicating devices is greater than expected. We are able to establish the connection by using the following equation:  
\[dvf=\left(\sqrt{\left(av-af\right)^{2}+\left(bv-bf\right)^{2}}\right) \tag{5}\]  
where \(dvf\) represents the distance between the two communicating devices, such as a vehicle and a fog node, \(av\ and\ af\) represent the distance from the node receiving the requests, and \(bv,\ bf\) represent the distance from host node to the request sending vehicle. \[Rt_{R_{j}}=\left(\frac{ds_{j}}{R_{t}^{v22v}}\right) \tag{6}\]  
The above equation gives the request data communication latency between volunteer vehicles \"\(j\)\", where the \(ds_{j}\) request is the data input size assigned to the vehicle. Figure 3 presents a graphical view of our model. Here we installed fog servers in each location, including the playground and public parks. Also, we installed VANETs in all the vehicles to enable communication. The dashed lines show vehicle-to-vehicle and infrastructure communication through the 5G SDN, and the dotted lines represent the connection between the fog and the cloud data center. Here we create a scenario at the school building where a fog node is overloaded. We diverted the high priority request (represented in red dashed line) to a nearby node and sent the low priority request (described in blue dashed line) to the cloud for further processing. By applying this technique, we reduced the latency and delay by 20% and 35%, respectively, which resulted in seamless communication between devices. We used a 5G cellular network for data transmission to meet future requirements for high-speed data transfer.