blob: 826447ad25bae88e7d04851c38b11558868408b2 [file] [log] [blame]
Toshio Koide5f260652014-01-30 14:41:12 -08001package net.onrc.onos.ofcontroller.app;
2
Toshio Koide5f260652014-01-30 14:41:12 -08003import 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 Koide25ce96a2014-01-30 17:52:09 -080010public abstract class Flow extends NetworkGraphEntity {
Toshio Koide5f260652014-01-30 14:41:12 -080011 public enum FlowState {
12 Created,
13 Configuring,
14 Configured,
Toshio Koide25ce96a2014-01-30 17:52:09 -080015 PathCalculating,
16 PathCalculated,
17 PathCalculationFailed,
Toshio Koide5f260652014-01-30 14:41:12 -080018 PathInstalled,
Toshio Koide25ce96a2014-01-30 17:52:09 -080019 PathInstallationFailed,
20 FlowEntriesCalculating,
21 FlowEntriesCalculated,
22 FlowEntriesCalculationFailed,
Toshio Koide5f260652014-01-30 14:41:12 -080023 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 Koide25ce96a2014-01-30 17:52:09 -080045 // abstract methods
46 abstract boolean calcPath();
47 abstract void calcFlowEntries();
48
49
Toshio Koide5f260652014-01-30 14:41:12 -080050 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 Koide25ce96a2014-01-30 17:52:09 -080064
Toshio Koide5f260652014-01-30 14:41:12 -080065 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 Koide25ce96a2014-01-30 17:52:09 -080085 /**
86 * not implemented yet
87 */
Toshio Koide5f260652014-01-30 14:41:12 -080088 public void installFlowEntries() {
89 state = FlowState.FlowEntriesInstalled;
90 }
91
Toshio Koide25ce96a2014-01-30 17:52:09 -080092 /**
93 * not implemented yet
94 */
Toshio Koide5f260652014-01-30 14:41:12 -080095 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}