blob: 8608adbd90a27f5d94bb3f2ce6c07531c845db21 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.api.flowmanager;
2
Toshio Koide9aa4c0f2014-08-11 16:06:44 -07003import static com.google.common.base.Preconditions.checkNotNull;
Toshio Koide5c5ca102014-08-19 00:49:52 -07004
5import java.util.List;
6
Toshio Koidefad1cd52014-08-07 17:10:07 -07007import net.onrc.onos.api.batchoperation.BatchOperationTarget;
Toshio Koided7d550c2014-08-21 16:08:55 -07008import net.onrc.onos.core.matchaction.MatchActionIdGenerator;
Ray Milkey42ae1b52014-08-15 16:37:06 -07009import net.onrc.onos.core.matchaction.MatchActionOperations;
Toshio Koided7d550c2014-08-21 16:08:55 -070010import net.onrc.onos.core.matchaction.MatchActionOperationsIdGenerator;
Toshio Koided8b077a2014-08-13 10:47:21 -070011import net.onrc.onos.core.matchaction.match.Match;
Toshio Koidea03915e2014-07-01 18:39:52 -070012
13/**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070014 * An abstract class to define flow object which is managed by
Toshio Koidea03915e2014-07-01 18:39:52 -070015 * FlowManagerModule.
Toshio Koidea03915e2014-07-01 18:39:52 -070016 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070017public abstract class Flow implements BatchOperationTarget {
18 private final FlowId id;
19
20 /**
Toshio Koide2c67a2d2014-08-27 11:30:56 -070021 * Default constructor for Kryo deserialization.
22 */
23 @Deprecated
24 protected Flow() {
25 id = null;
26 }
27
28 /**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070029 * Creates Flow object using specified ID.
30 *
31 * @param id the ID to be assigned
32 */
33 public Flow(FlowId id) {
34 this.id = checkNotNull(id);
35 }
36
Toshio Koidea03915e2014-07-01 18:39:52 -070037 /**
38 * Gets ID for this flow object.
39 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070040 * @return ID for this object
Toshio Koidea03915e2014-07-01 18:39:52 -070041 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070042 public FlowId getId() {
43 return id;
44 }
Toshio Koidea03915e2014-07-01 18:39:52 -070045
46 /**
47 * Gets traffic filter for this flow object.
48 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070049 * @return a traffic filter for this flow object
Toshio Koidea03915e2014-07-01 18:39:52 -070050 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070051 public abstract Match getMatch();
Toshio Koidea03915e2014-07-01 18:39:52 -070052
53 /**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070054 * Compiles this object to MatchAction operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070055 * <p>
Toshio Koide5c5ca102014-08-19 00:49:52 -070056 * This method is called by FlowManagerModule to create MatchAction
57 * operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070058 *
Toshio Koided7d550c2014-08-21 16:08:55 -070059 * @param op {@link FlowBatchOperation}'s operator to be used for compiling
60 * this object
61 * @param maIdGenerator ID generator to be used for generating MatchAction
62 * objects.
63 * @param maoIdGenerator ID generator to be used for generating
64 * {@link MatchActionOperations} objects.
65 * @return a list of {@link MatchActionOperations} objects to realize this
66 * flow
Toshio Koidea03915e2014-07-01 18:39:52 -070067 */
Toshio Koided7d550c2014-08-21 16:08:55 -070068 public abstract List<MatchActionOperations> compile(
69 FlowBatchOperation.Operator op,
70 MatchActionIdGenerator maIdGenerator,
71 MatchActionOperationsIdGenerator maoIdGenerator);
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070072
73 /**
74 * Generates a hash code using the FlowId.
75 *
76 * @return hashcode
77 */
78 @Override
79 public int hashCode() {
80 return (id == null) ? 0 : id.hashCode();
81 }
82
83 /**
84 * Compares two flow objects by type (class) and FlowId.
85 *
86 * @param obj other Flow object
87 * @return true if equal, false otherwise
88 */
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj) {
92 return true;
93 }
Toshio Koide08808102014-08-18 18:29:47 -070094 if (!(obj instanceof Flow)) {
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070095 return false;
96 }
97 Flow other = (Flow) obj;
98 if (id == null) {
99 if (other.id != null) {
100 return false;
101 }
102 } else if (!id.equals(other.id)) {
103 return false;
104 }
105 return true;
106 }
Toshio Koidea03915e2014-07-01 18:39:52 -0700107}