blob: 071d89fefe49d2c164251ddd925f5944e97aa23d [file] [log] [blame]
Toshio Koide5f260652014-01-30 14:41:12 -08001package net.onrc.onos.ofcontroller.app;
2
3import java.util.HashMap;
4import java.util.Map;
5
6/**
7 * Base class for Flow representation
8 * This code is valid for the architectural study purpose only.
9 * @author Toshio Koide (t-koide@onlab.us)
10 */
11public class Flow extends NetworkGraphEntity {
12 public enum FlowState {
13 Created,
14 Configuring,
15 Configured,
16 PathCalcurating,
17 PathCalcurated,
18 PathCalcurationFailed,
19 PathInstalled,
20 PathInstlationFailed,
21 FlowEntriesCalcurating,
22 FlowEntriesCalcurated,
23 FlowEntriesCalcuratinFailed,
24 FlowEntriesInstalling,
25 FlowEntriesInstalled,
26 FlowEntriesInstallationFailed,
27 FlowEntriesRemoving,
28 FlowEntriesRemoved,
29 FlowEntriesRemovalFailed,
30 PathRemoved,
31 PathRemovalFailed,
32 }
33
34 protected FlowState state = FlowState.Created;
35
36 // configurations
37 protected SwitchPort srcPort = null;
38 protected SwitchPort dstPort = null;
39
40 // path
41 protected Path path = new Path();
42
43 // flow entries
44 protected Map<SwitchPort, FlowEntry> flowEntries = null;
45
46 public Flow(NetworkGraph graph, String name, SwitchPort srcPort, SwitchPort dstPort) {
47 super(graph);
48 this.srcPort = srcPort;
49 this.dstPort = dstPort;
50 state = FlowState.Created;
51 }
52
53 FlowState getState() {
54 return state;
55 }
56
57 boolean isState(FlowState state) {
58 return this.state == state;
59 }
60
61 boolean calcPath() {
62 state = FlowState.PathCalcurated;
63 return true;
64 }
65
66 public Path getPath() {
67 return path;
68 }
69
70 public boolean installPath() {
71 for (Link link: path) {
72 link.addFlow(this);
73 }
74 state = FlowState.PathInstalled;
75 return true;
76 }
77
78 public boolean uninstallPath() {
79 for (Link link: path) {
80 link.removeFlow(this);
81 }
82 state = FlowState.PathRemoved;
83 return true;
84 }
85
86 public void calcFlowEntries() {
87 flowEntries = new HashMap<SwitchPort, FlowEntry>();
88 state = FlowState.FlowEntriesCalcurated;
89 }
90
91 public void installFlowEntries() {
92 state = FlowState.FlowEntriesInstalled;
93 }
94
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}