# A New SDN-Based Routing Protocol for Improving Delay in Smart City Environments
## 5 SDN-Naive Bayes-Based Routing Protocol Working  
Considering the previously depicted network model, in this section, we elaborate on the evoked solution's operation steps. The controller performs all the work, from discovering the elements and their needs in the network until the control and maintenance of the communication, to ensure the system's optimized operation. To understand the working of the new routing protocol, we explain how to achieve a communication attempt between two vehicles, as shown in Figure 6.  
Figure 5: Network Model.  
Let's assume that the car noted Source Host wants to send a data to the vehicle named Destination Host. Therefore, the Source Host looks for the Destination Host in its flow table. If the node did not find the wanted entry, it sends a request, represented by arrow 1 in Figure 6, to the RSU relied on the area of node's location. In our case, the vehicle asks RSU1 that covered the Area_1. Since there is no previously installed rule for this flow, the RSU1 forwards the request to the controller by sending a packet-in (arrow 2) using OpenFlow protocol. Ones the packet arrived at the Ryu controller, the controller identifies the origin of the message by extracting source address and check, if there is a previous request of this node, which means its presence in the table of flows. Next, RYU responds by packet modification to update the node's flow table (arrow 3).  
Otherwise, the controller discovers that it does not have any previous knowledge of the source. Then, it adds it to its flow table and launches the process for finding the destination host attachment points. Nevertheless, if the destination is known, the controller sends a packet-out (arrow 3) to the source host with the routing path as rules for including them in the source's flow table. That is an optimistic assumption that the controller recognizes the destination. Generally, that is not the case, thus in other routing solutions, the controller floods the network with a request packet until reaching the target. However, our solution avoids this practice because it costs in packet overhead and increases the transmission delay.  
Our protocol uses the Naive Bayes model to predict the area where the destination node rests. The RYU furnishes the feature's value needed in the working of the ML algorithm that computes the corresponding RSU associated with the destination node online. When it identifies the corresponded RSU of the destination location zone, the prediction model provides the outcome to the controller. The controller sends a packet-out comprising the routing rules between the source and destination to nodes for installing the appropriate controls. However, the controller constructs the routing paths based on the delay cost of links that constitute constructed routing paths. The controller applies the shortest path routing algorithm to select the best route. As the delay is the primary information upon which our suggested solution depends, our protocol retrieves the network's statistics to provide link delay in real-time for the system's whole links. The controller performs statistics periodically based on frequency time, offering newer delay values and a detailed network overview. Immediately the routing paths constructed and sent to the RSUs, which in turn transmit them to the vehicles included in this routing (arrow 4). Each vehicle establishes a connection with the gateway vehicle to initiate the transfer of packets between a source and destination cars (arrow 5).  
Figure 6: SDN-Naive Bayes-based Routing Protocol Operation.