blob: 202511d1e8d89a80596fb1c23acb0b7e5c2c609d [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 /**
21 * Creates Flow object using specified ID.
22 *
23 * @param id the ID to be assigned
24 */
25 public Flow(FlowId id) {
26 this.id = checkNotNull(id);
27 }
28
Toshio Koidea03915e2014-07-01 18:39:52 -070029 /**
30 * Gets ID for this flow object.
31 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070032 * @return ID for this object
Toshio Koidea03915e2014-07-01 18:39:52 -070033 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070034 public FlowId getId() {
35 return id;
36 }
Toshio Koidea03915e2014-07-01 18:39:52 -070037
38 /**
39 * Gets traffic filter for this flow object.
40 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070041 * @return a traffic filter for this flow object
Toshio Koidea03915e2014-07-01 18:39:52 -070042 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070043 public abstract Match getMatch();
Toshio Koidea03915e2014-07-01 18:39:52 -070044
45 /**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070046 * Compiles this object to MatchAction operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070047 * <p>
Toshio Koide5c5ca102014-08-19 00:49:52 -070048 * This method is called by FlowManagerModule to create MatchAction
49 * operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070050 *
Toshio Koided7d550c2014-08-21 16:08:55 -070051 * @param op {@link FlowBatchOperation}'s operator to be used for compiling
52 * this object
53 * @param maIdGenerator ID generator to be used for generating MatchAction
54 * objects.
55 * @param maoIdGenerator ID generator to be used for generating
56 * {@link MatchActionOperations} objects.
57 * @return a list of {@link MatchActionOperations} objects to realize this
58 * flow
Toshio Koidea03915e2014-07-01 18:39:52 -070059 */
Toshio Koided7d550c2014-08-21 16:08:55 -070060 public abstract List<MatchActionOperations> compile(
61 FlowBatchOperation.Operator op,
62 MatchActionIdGenerator maIdGenerator,
63 MatchActionOperationsIdGenerator maoIdGenerator);
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070064
65 /**
66 * Generates a hash code using the FlowId.
67 *
68 * @return hashcode
69 */
70 @Override
71 public int hashCode() {
72 return (id == null) ? 0 : id.hashCode();
73 }
74
75 /**
76 * Compares two flow objects by type (class) and FlowId.
77 *
78 * @param obj other Flow object
79 * @return true if equal, false otherwise
80 */
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj) {
84 return true;
85 }
Toshio Koide08808102014-08-18 18:29:47 -070086 if (!(obj instanceof Flow)) {
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070087 return false;
88 }
89 Flow other = (Flow) obj;
90 if (id == null) {
91 if (other.id != null) {
92 return false;
93 }
94 } else if (!id.equals(other.id)) {
95 return false;
96 }
97 return true;
98 }
Toshio Koidea03915e2014-07-01 18:39:52 -070099}