# A3C-R: A QoS-Oriented Energy-Saving Routing Algorithm for Software-Defined Networks
## 3 Modeling of QoS and Energy-Efficient Routing  
### Modeling of QoS Routing  
QoS is the guarantee of network transmission quality, which can provide better service quality according to different business requirements [17]. The process of defining and measuring QoS parameters mainly involves the collection of network link state information, through which the port and flow information of the switch can be obtained and processed as the input of the intelligent routing module. This paper mainly designs QoS parameter indicators including: delay, bandwidth and packet loss rate. The parameters of QoS are mainly calculated through the message transmission process between the controller and the switch. The message transmission process between the controller and the switch is shown in Figure 1. The specific calculation method of each QoS parameter is as follows:  
Delay  
The SDN controller can generate a Packet-out message and send a data packet including LLDP to the switch \(S_{2}\), through the switch \(S_{1}\), and the time stamp is \(t_{1}\). When the controller receives the Packet-in message received by the switch \(S_{2}\), the time stamp is \(t_{2}\), and the time of the message from \"controller-\(S_{1}\)-\(S_{2}\)-controller\" is \(T_{1}=t_{1}-t_{2}\). Similarly, the \"controller-\(S_{2}\)-\(S_{1}\)-controller\" time can be measured as \(T_{2}\). Then, the controller can measure the round-trip delays \(t_{c-s_{1}}\) and \(t_{c-s_{2}}\) of the switches \(S_{1}\) and \(S_{2}\), respectively, through the echo data packets, so the calculation formula of the link delay \(d_{(S_{1},S_{2})}\) of the switches \(S_{1}\) and \(S_{2}\) is shown in (1). \[d_{(S_{1},S_{2})}=\frac{1}{2}(T_{1}+T_{2}-t_{c-s_{1}}-t_{c-s_{2}}) \tag{1}\]  
Therefore, the delay function of path \(P\) can be defined as Formula (2). \[Delay(P)=\sum_{(i,j)\in P}d_{(i,j)} \tag{2}\]  
where \(d_{(i,j)}\) is the delay of link \((i,j)\). Bandwidth  
Bandwidth is a measure of the link's ability to transmit data per unit of time. We can use rx_Bytes to measure the number of bytes received by the port and use tx_Bytes to measure the number of bytes sent by the port. Suppose we use tx_Bytes to measure the number of bytes sent by switch \(S_{1}\) to \(S_{2}\) at time \(t_{1}\) to \(t_{2}\) as \(W_{t}\) and use rx_Bytes to measure the number of data packets received by switch \(S_{2}\) from \(S_{1}\) at time \(t_{1}\) to \(t_{2}\) as \(W_{t}\). Then, the average bandwidth and remaining bandwidth of the switches \(S_{1}\) and \(S_{2}\) used to transmit data in the \([t_{1},t_{2}]\) time interval are shown in Formula (3). \[\left\{ \begin{array}{l}b_{average}=\frac{\min\{W_{t},W_{t}\}}{t_{2}-t_{1}}\\ b_{remain}=b_{total}-b_{average}\end{array} \right. \tag{3}\]  
Since the minimum bandwidth requirement must be considered when transmitting data flows, the bandwidth of each link must not be less than the minimum bandwidth when selecting a path for routing. The bandwidth of path \(P\) is defined as shown in Formula (4). \[B(P)=\underset{(i,j)\in P}{min}\{b(i,j)\} \tag{4}\]  
where \(b_{(i,j)}\) is the available bandwidth on the link \((i,j)\). Figure 1: Message passing between controller and switch. The packet loss rate refers to the ratio of lost packets to the total number of packets within a period of time. We can use rx_packets to measure the number of packets received by the port and tx_packets to measure the number of packets sent by the port. Suppose we use tx_packets to measure the number of data packets sent by switch \(S_{1}\) to \(S_{2}\) at time \(t_{1}\) to \(t_{2}\) as \(\Delta p_{1}\) and use rx_packets to measure the number of data packets received by switch \(S_{2}\) from \(S_{1}\) at time \(t_{1}\) to \(t_{2}\) as \(\Delta p_{2}\). The packet loss rate of switches \(S_{1}\) and \(S_{2}\) in the \([t_{1},t_{2}]\) time interval is shown in Formula (5)  
\[l_{(S_{1},S_{2})}=\frac{\Delta p_{2}}{\Delta p_{1}} \tag{5}\]  
Therefore, we can define the packet loss rate function of path \(P\) as Formula (6).