Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.app; |
| 2 | |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 3 | import java.util.Map; |
| 4 | |
| 5 | /** |
| 6 | * Base class for Flow representation |
| 7 | * This code is valid for the architectural study purpose only. |
| 8 | * @author Toshio Koide (t-koide@onlab.us) |
| 9 | */ |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame^] | 10 | public abstract class Flow extends NetworkGraphEntity { |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 11 | public enum FlowState { |
| 12 | Created, |
| 13 | Configuring, |
| 14 | Configured, |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame^] | 15 | PathCalculating, |
| 16 | PathCalculated, |
| 17 | PathCalculationFailed, |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 18 | PathInstalled, |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame^] | 19 | PathInstallationFailed, |
| 20 | FlowEntriesCalculating, |
| 21 | FlowEntriesCalculated, |
| 22 | FlowEntriesCalculationFailed, |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 23 | FlowEntriesInstalling, |
| 24 | FlowEntriesInstalled, |
| 25 | FlowEntriesInstallationFailed, |
| 26 | FlowEntriesRemoving, |
| 27 | FlowEntriesRemoved, |
| 28 | FlowEntriesRemovalFailed, |
| 29 | PathRemoved, |
| 30 | PathRemovalFailed, |
| 31 | } |
| 32 | |
| 33 | protected FlowState state = FlowState.Created; |
| 34 | |
| 35 | // configurations |
| 36 | protected SwitchPort srcPort = null; |
| 37 | protected SwitchPort dstPort = null; |
| 38 | |
| 39 | // path |
| 40 | protected Path path = new Path(); |
| 41 | |
| 42 | // flow entries |
| 43 | protected Map<SwitchPort, FlowEntry> flowEntries = null; |
| 44 | |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame^] | 45 | // abstract methods |
| 46 | abstract boolean calcPath(); |
| 47 | abstract void calcFlowEntries(); |
| 48 | |
| 49 | |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 50 | public Flow(NetworkGraph graph, String name, SwitchPort srcPort, SwitchPort dstPort) { |
| 51 | super(graph); |
| 52 | this.srcPort = srcPort; |
| 53 | this.dstPort = dstPort; |
| 54 | state = FlowState.Created; |
| 55 | } |
| 56 | |
| 57 | FlowState getState() { |
| 58 | return state; |
| 59 | } |
| 60 | |
| 61 | boolean isState(FlowState state) { |
| 62 | return this.state == state; |
| 63 | } |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame^] | 64 | |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 65 | public Path getPath() { |
| 66 | return path; |
| 67 | } |
| 68 | |
| 69 | public boolean installPath() { |
| 70 | for (Link link: path) { |
| 71 | link.addFlow(this); |
| 72 | } |
| 73 | state = FlowState.PathInstalled; |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | public boolean uninstallPath() { |
| 78 | for (Link link: path) { |
| 79 | link.removeFlow(this); |
| 80 | } |
| 81 | state = FlowState.PathRemoved; |
| 82 | return true; |
| 83 | } |
| 84 | |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame^] | 85 | /** |
| 86 | * not implemented yet |
| 87 | */ |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 88 | public void installFlowEntries() { |
| 89 | state = FlowState.FlowEntriesInstalled; |
| 90 | } |
| 91 | |
Toshio Koide | 25ce96a | 2014-01-30 17:52:09 -0800 | [diff] [blame^] | 92 | /** |
| 93 | * not implemented yet |
| 94 | */ |
Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 95 | public void uninstallFlowEntries() { |
| 96 | state = FlowState.FlowEntriesRemoved; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public String toString() { |
| 101 | return String.format("srcPort:%s, dstPort:%s, Path: %s", |
| 102 | srcPort.toString(), |
| 103 | dstPort.toString(), |
| 104 | path.toString()); |
| 105 | } |
| 106 | } |