# SDN-Based Routing Framework for Elephant and Mice Flows Using Unsupervised Machine Learning
## 3 Proposed Methodology
### Architecture Implementation
\(\mathrm{FT}\): a string indicates mice or elephant flow
4. \(\mathrm{CF}\): set of current flows
5. \(\mathrm{RF}\): set of representative flows
6. \(\mathrm{AL}\): a float number represents the acceptable delay of \(\mathrm{cf}\in\mathrm{CF}\)
7. \(\mathrm{FT}\leftarrow\emptyset\)
8. \(\mathrm{RF}\leftarrow\emptyset\)
9. \(\mathrm{AL}\leftarrow\emptyset\)
10. \(\mathrm{for}\) each \(\mathrm{cid}\in\mathrm{CID}\)do
11. \(\mathrm{for}\) each \(\mathrm{cf}\in\mathrm{CF}\)do
12. \(\mathrm{for}\) each \(\mathrm{ppr}\in\mathrm{PPR}\)do
13. \(\mathrm{if}\)\(\mathrm{cf.packetCount}>15\) and \(\mathrm{cf.flowDuration}>5\) and \(\mathrm{cf.avgPacketSize}\geq 10\)then
14. \(\mathrm{FT}\leftarrow\) 'elephant'
15. \(\mathrm{else}\)
16. \(\mathrm{FT}\leftarrow\)'mice'
17. \(\mathrm{AL}\leftarrow\mathrm{cf.latency}\)
18. \(\mathrm{end}\) if
19. \(\mathrm{end}\) for
20. \(\mathrm{end}\) for
21. \(\mathrm{RF}\leftarrow\) kmeansModel.Lefts[\(\mathrm{cid}\)]
22. \(\mathrm{end}\) for
```  
**Algorithm 4** Flow Identification  
After the flow identification process has ended, selecting the best path for each representative flow, installing the determined path, and updating the cost of the path recursively are the main steps of the routing process, which will be executed by calling Algorithms 5 and 6. The first step of the routing process is checking the type of flow. If it is a mice flow, the available paths, which have been found by calling the FAPBS and FAS algorithms, are sorted with respect to length, and the shortest path will be selected as the best. Otherwise, it is an elephant flow, and the best N paths will be chosen based on the 1/bandwidth, as shown in Section 4.1.6. As a result, for each type of flow, we have the best path based on acceptable delay and available bandwidth for a particular source and destination. Then, the best path is installed for each of the elephant and mice flows (Algorithm 5). This is performed by sending a message containing the information of the selected path to the SDN controller in order to determine the required switches. Finally, an updated version of the input paths contains each path associated with the cost of the path. The process of updating is based on the paths, which is the output of the FAPBS algorithm and available bandwidth as a 2D array containing available bandwidth between every two switches. This is summarized in Algorithm 6. ```
1. \(\quad\)source: source switch
2. \(\quad\)destination: destination switch
3. \(\quad\)acceptableLatency: acceptable delay
4. \(\quad\)FT: a string indicates mice or elephant flow
5. \(\quad\)paths: set of paths between each two switches
6. \(\quad\)N: integer, determine number of paths to be selected
7. \(\quad\)RT: routing table
8. \(\quad\)N \(\leftarrow\)\(\mathcal{O}\)
9. \(\quad\)cost \(\leftarrow\)\(\mathcal{O}\)
10. \(\quad\)availablePaths \(\leftarrow\) paths(\({}^{\prime}\)sourceTOdestination\({}^{\prime}\))
11. \(\quad\)ifFT matches'mice' then
12. \(\quad\)path \(\leftarrow\) availablePaths.sort(key = len, ascending = False)[0]
13. \(\quad\)Else
14. \(\quad\)path \(\leftarrow\) availablePaths.sort(key = cost,ascending = False)[0 N]
15. \(\quad\)endif
16. \(\quad\)RT \(\leftarrow\) path /*path installing*/
```  
**Algorithm 6** updateCost