blob: d8723d25cc067aa6feaa38e34f1b30c35857c77d [file] [log] [blame]
Toshio Koide5f260652014-01-30 14:41:12 -08001package net.onrc.onos.ofcontroller.app;
2
3/**
Toshio Koide5f260652014-01-30 14:41:12 -08004 * This code is valid for the architectural study purpose only.
Toshio Koide25ce96a2014-01-30 17:52:09 -08005 * @author Toshio Koide (t-koide@onlab.us)
Toshio Koide5f260652014-01-30 14:41:12 -08006 */
7public class ShortestPath implements BaseApplication {
Toshio Koide25ce96a2014-01-30 17:52:09 -08008 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 Koide5f260652014-01-30 14:41:12 -080020
Toshio Koide25ce96a2014-01-30 17:52:09 -080021 /**
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 Koide5f260652014-01-30 14:41:12 -080077}