# JSSTR: A Joint Server Selection and Traffic Routing Algorithm for the Software-Defined Data Center
## 5 Joint Server Selection and Traffic Routing Algorithm
### Implementation  
To validate our design, the proposed algorithm has been implemented as a module of the RYU controller. As shown in Figure 4, the implemented JSSTR is composed of the server and routing path calculator, flow entry installer, information maintainer, server monitor and network monitor. It should be noted that in Figure 4, NAT is the abbreviation of Network Address Translation. When the OpenFlow switch receives a packet, the switch will find out whether there is a flow entry in the switch that can match that packet. If there is no matched flow entry, the packet will be sent to the SDN controller. After that, the server and routing path calculator firstly gets the information of the network devices and servers from the information maintainer. Using this information, the destination server and routing path are calculated by the JSSTR algorithm. Subsequently, the flow entry installer generates the corresponding forwarding rules and installs flow entries in the relevant switches. Finally, the traffic between the user and server will be transmitted by the established routing path, and the server will provide service for this user. The detailed description of the main components is given below. Server and routing path calculator: The destination server and routing path calculation are implemented in this module. When the SDN controller receives a new packet, this packet will be firstly sent to this module. The relevant information (e.g., source IP address, destination IP address, protocol type of network layer, and so on) will be parsed from the packet. Afterwards, the detailed information of all links and servers will be obtained from the information maintainer. Then, the JSSTR algorithm implemented in the server and routing path calculator can calculate the destination server and routing path. Flow entry installer: This module generates and installs forwarding rules for the processed packet based on the calculation result made by the server and routing path calculator. Basically, the main forwarding rules include forwarding packets to a specified port and executing the NAT strategy. For the switch that connects to users, the NAT strategy will be executed on the packets transmitted through it. More specifically, for packets sent from the user to the server, its source IP address and MAC address will be modified to the switch's IP and MAC address. Meanwhile, its destination IP and MAC address will be modified to the destination server's IP and MAC address. In contrast, for packets sent from the server to the user, the source IP and MAC address will be modified to the gateway's IP  
Figure 4: The implementation of the Joint Server Selection and Traffic Routing (JSSTR) algorithm. and MAC address. In addition, the destination IP and MAC address will be modified to the user's IP and MAC address. The NAT strategy is only executed in the switches that connect to users. For other switches, they just forward the arriving packets without modifying the IP or MAC address of these packets. Information maintainer: This module is responsible for storing the link and server information and providing this information to the server and routing path calculator. After receiving messages sent from the network monitor and server monitor, this module will parse these messages to get and store the bandwidth usage of the links and resource usage of the servers. When the server and routing path calculator needs the link and server information, the relevant information will be provided. Server monitor: The server monitor is designed to collect the server information by the controller. In this work, a program written in Python is used to simulate and monitor the resource usage of these servers. In order to quickly respond to the user request, the server monitor periodically collects the CPU information, memory information and hard disk information and sends this information to the information maintainer.