Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame^] | 1 | package net.onrc.onos.ofcontroller.app; |
| 2 | |
| 3 | /** |
| 4 | * This code is valid for the architectural study purpose only. |
| 5 | * @author Toshio Koide (t-koide@onlab.us) |
| 6 | */ |
| 7 | public class SimpleTrafficEngineering implements BaseApplication { |
| 8 | NetworkGraph graph; |
| 9 | |
| 10 | /** |
| 11 | * Instantiate SimpleTrafficEngineering application |
| 12 | * |
| 13 | * 1. store NetworkGraph as a cache |
| 14 | * |
| 15 | * @param graph |
| 16 | */ |
| 17 | public SimpleTrafficEngineering(NetworkGraph graph) { |
| 18 | this.graph = graph; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Allocate specified bandwidth between specified switch ports |
| 23 | * |
| 24 | * @param srcPort |
| 25 | * @param dstPort |
| 26 | * @param bandWidth |
| 27 | * @return |
| 28 | */ |
| 29 | public ConstrainedFlow allocate(SwitchPort srcPort, SwitchPort dstPort, double bandWidth) { |
| 30 | ConstrainedFlow flow = new ConstrainedFlow(this.graph, null, srcPort, dstPort, bandWidth); |
| 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. allocate bandwidth in NetworkGraph |
| 47 | if (!flow.installPath()) { |
| 48 | return flow; |
| 49 | } |
| 50 | |
| 51 | // debug (show path) |
| 52 | System.out.println("bandwidth was allocated."); |
| 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(ConstrainedFlow flow) { |
| 65 | // 1. release bandwidth (remove property of links) in NetworkGraph |
| 66 | flow.uninstallPath(); |
| 67 | |
| 68 | // debug (show path) |
| 69 | System.out.println("bandwidth 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 | } |
| 77 | } |