# Transparent Redirections in Content Delivery Networks
## 3 SDN Based Transparent Redirection
### SDN Based TCP Session Handoff
In part 2 of Figure 6, the request router sends out the request towards the surrogate server via an already pre-established TCP session (this session was chosen by the controller). The message is sent out and sent to the controller in a Packet IN message. At this point, the controller has all the required information to perform the handoff. The controller installs flow mods to the core forwarder, where the surrogate is connected, and to the access forwarder, where the client is connected. The following flow mods are installed:  
* Flow mod 2: rewrites destination IP, port and MAC address for the communication from the surrogate server towards the client, where the IP, port and MAC address are rewritten to mimic the request router. Sequence number and Acknowledge number is incremented to synchronize with the TCP session established between the client and request router. * Flow mod 3: rewrites the source IP, port and MAC address to match the parameters of the client. The packet sent out from the surrogate server is originally destined to the request router. * Flow mod 4: rewrites source IP, port and MAC address to match the parameters of the request router for the communication from the client towards the surrogate server. Sequence and acknowledgement numbers are incremented to synchronize with the TCP session between the request router and the surrogate server. * Flow mod 5: rewrites the destination IP, port and MAC address to match the parameters of the surrogate server as the outgoing packet from the client is destined to the request router. * Flow mod 6 and 7 blocks any further communication from the request router towards the client or surrogate server over the two established TCP sessions. If there are several other forwarders between the core and the access switch, the intermediary routers forward the packets based on the destination IP address. The destination IP address is correctly updated on the core and access forwarders for the right routing direction. At this point, all the flow mods are prepared for the synchronization and the corresponding communication continues between the client and the surrogate server exclusively without sending the packets to the SDN controller. In part 3 of Figure 6, the modified request is sent out from the controller to the surrogate server, which parses the request and sends a response upon a valid request. The response and acknowledgement packets are forwarded through the network and the parameters are rewritten on the core and access forwarders based on the flow mods from part 2. To correctly finish the handoff procedure, it is crucial to mitigate the initial TCP sessions established with the request router. To mitigate the sessions the controller generates TCP packets with RST flags set for both TCP sessions, which are sent out via PACKET OUT messages in part 4 of Figure 6. Once the session is mitigated, the request router creates a new TCP session towards the surrogate server to maintain the pool of available TCP sessions. To calculate the synchronization values of the sequence and acknowledgement numbers the following formulas are used:  
\[\text{Sinc\_cs}=\left((2^{32})+\left(\text{Srs}-\text{Scr}\right)+\left(\text{Rrs }-\text{Rcr}\right)\right)\text{mod}\ (2^{32}) \tag{1}\]  
\[\text{Ainc\_sc}=\left((2^{32})-\text{Sinc\_cs}\right)\text{mod}\ (2^{32}) \tag{2}\]  
\[\text{Sinc\_sc}=\left((2^{32})+\left(\text{Src}-\text{Ssr}\right)\right)\text{ mod}\ (2^{32}) \tag{3}\]  
\[\text{Ainc\_cs}=\left((2^{32})-\text{Sinc\_sc}\right)\text{mod}\ (2^{32}) \tag{4}\]  
Figure 6: TCP Session handoff procedure. where:  
* Srs: Initial sequence number from request router to the surrogate server;
* Scr: Initial sequence number from client to the request router;
* Rrs: Request size from the request router to the surrogate server;
* Rcr: Request size from client to the request router;
* Src: Initial sequence number from the request router to the client;
* Ssr: Initial sequence number from the surrogate server to the request router. As the sequence and acknowledge numbers are 4-byte numbers.