blob: 65dc00e9e9133871dce9ef3c9feb742932c15073 [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;
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -07008import net.onrc.onos.core.matchaction.MatchActionId;
Ray Milkey42ae1b52014-08-15 16:37:06 -07009import net.onrc.onos.core.matchaction.MatchActionOperations;
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070010import net.onrc.onos.core.matchaction.MatchActionOperationsId;
Toshio Koided8b077a2014-08-13 10:47:21 -070011import net.onrc.onos.core.matchaction.match.Match;
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070012import net.onrc.onos.core.util.IdGenerator;
Toshio Koidea03915e2014-07-01 18:39:52 -070013
14/**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070015 * An abstract class to define flow object which is managed by
Toshio Koidea03915e2014-07-01 18:39:52 -070016 * FlowManagerModule.
Toshio Koidea03915e2014-07-01 18:39:52 -070017 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070018public abstract class Flow implements BatchOperationTarget {
19 private final FlowId id;
20
21 /**
Toshio Koide2c67a2d2014-08-27 11:30:56 -070022 * Default constructor for Kryo deserialization.
23 */
24 @Deprecated
25 protected Flow() {
26 id = null;
27 }
28
29 /**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070030 * Creates Flow object using specified ID.
31 *
32 * @param id the ID to be assigned
33 */
34 public Flow(FlowId id) {
35 this.id = checkNotNull(id);
36 }
37
Toshio Koidea03915e2014-07-01 18:39:52 -070038 /**
39 * Gets ID for this flow object.
40 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070041 * @return ID for this object
Toshio Koidea03915e2014-07-01 18:39:52 -070042 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070043 public FlowId getId() {
44 return id;
45 }
Toshio Koidea03915e2014-07-01 18:39:52 -070046
47 /**
48 * Gets traffic filter for this flow object.
49 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070050 * @return a traffic filter for this flow object
Toshio Koidea03915e2014-07-01 18:39:52 -070051 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070052 public abstract Match getMatch();
Toshio Koidea03915e2014-07-01 18:39:52 -070053
54 /**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070055 * Compiles this object to MatchAction operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070056 * <p>
Toshio Koide5c5ca102014-08-19 00:49:52 -070057 * This method is called by FlowManagerModule to create MatchAction
58 * operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070059 *
Toshio Koided7d550c2014-08-21 16:08:55 -070060 * @param op {@link FlowBatchOperation}'s operator to be used for compiling
61 * this object
62 * @param maIdGenerator ID generator to be used for generating MatchAction
63 * objects.
64 * @param maoIdGenerator ID generator to be used for generating
65 * {@link MatchActionOperations} objects.
66 * @return a list of {@link MatchActionOperations} objects to realize this
67 * flow
Toshio Koidea03915e2014-07-01 18:39:52 -070068 */
Toshio Koided7d550c2014-08-21 16:08:55 -070069 public abstract List<MatchActionOperations> compile(
70 FlowBatchOperation.Operator op,
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070071 IdGenerator<MatchActionId> maIdGenerator,
72 IdGenerator<MatchActionOperationsId> maoIdGenerator);
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070073
74 /**
75 * Generates a hash code using the FlowId.
76 *
77 * @return hashcode
78 */
79 @Override
80 public int hashCode() {
81 return (id == null) ? 0 : id.hashCode();
82 }
83
84 /**
85 * Compares two flow objects by type (class) and FlowId.
86 *
87 * @param obj other Flow object
88 * @return true if equal, false otherwise
89 */
90 @Override
91 public boolean equals(Object obj) {
92 if (this == obj) {
93 return true;
94 }
Toshio Koide08808102014-08-18 18:29:47 -070095 if (!(obj instanceof Flow)) {
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070096 return false;
97 }
98 Flow other = (Flow) obj;
99 if (id == null) {
100 if (other.id != null) {
101 return false;
102 }
103 } else if (!id.equals(other.id)) {
104 return false;
105 }
106 return true;
107 }
Toshio Koidea03915e2014-07-01 18:39:52 -0700108}