Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.app; |
| 2 | |
| 3 | /** |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 4 | * This code is valid for the architectural study purpose only. |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame] | 5 | * @author Toshio Koide (t-koide@onlab.us) |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 6 | */ |
| 7 | public class ShortestPath implements BaseApplication { |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame] | 8 | NetworkGraph graph; |
| 9 | |
| 10 | /** |
| 11 | * Instantiate SimpleTrafficEngineering application |
| 12 | * |
| 13 | * 1. store NetworkGraph as a cache |
| 14 | * |
| 15 | * @param graph |
| 16 | */ |
| 17 | public ShortestPath(NetworkGraph graph) { |
| 18 | this.graph = graph; |
| 19 | } |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 20 | |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame] | 21 | /** |
| 22 | * Allocate specified bandwidth between specified switch ports |
| 23 | * |
| 24 | * @param srcPort |
| 25 | * @param dstPort |
| 26 | * @param bandWidth |
| 27 | * @return |
| 28 | */ |
| 29 | public ShortestPathFlow install(SwitchPort srcPort, SwitchPort dstPort) { |
| 30 | ShortestPathFlow flow = new ShortestPathFlow(this.graph, null, srcPort, dstPort); |
| 31 | |
| 32 | // 1. store Flow object to NetworkGraph |
| 33 | if (!graph.addFlow(flow)) { |
| 34 | return flow; |
| 35 | } |
| 36 | |
| 37 | // 2. calculate path from srcPort to dstPort under condition of bandWidth |
| 38 | if (!flow.calcPath()) { |
| 39 | return flow; |
| 40 | } |
| 41 | |
| 42 | // debug (show path) |
| 43 | System.out.println("path was calculated:"); |
| 44 | System.out.println("[Flow] " + flow.toString()); |
| 45 | |
| 46 | // 3. install path in NetworkGraph |
| 47 | if (!flow.installPath()) { |
| 48 | return flow; |
| 49 | } |
| 50 | |
| 51 | // debug (show path) |
| 52 | System.out.println("path was installed."); |
| 53 | System.out.println("[Flow] " + flow.toString()); |
| 54 | |
| 55 | // (then, flow entries are created and installed from stored path information in the Flow object by another processes) |
| 56 | return flow; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Release specified Flow object |
| 61 | * |
| 62 | * @param flow |
| 63 | */ |
| 64 | public void release(ShortestPathFlow flow) { |
| 65 | // 1. release bandwidth (remove property of links) in NetworkGraph |
| 66 | flow.uninstallPath(); |
| 67 | |
| 68 | // debug (show path) |
| 69 | System.out.println("path was released."); |
| 70 | System.out.println("[Flow] " + flow.toString()); |
| 71 | |
| 72 | // 2. deactivate Flow object |
| 73 | |
| 74 | // (then, flow entries are removed by another processes) |
| 75 | // (retain flow object in NetworkGraph as a removed flow object) |
| 76 | } |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 77 | } |