blob: ae3cb7ed2c4043b7678a981241b6aee7b6f99b6e [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;
Ray Milkey42ae1b52014-08-15 16:37:06 -07008import net.onrc.onos.core.matchaction.MatchActionOperations;
Toshio Koided8b077a2014-08-13 10:47:21 -07009import net.onrc.onos.core.matchaction.match.Match;
Toshio Koidea03915e2014-07-01 18:39:52 -070010
11/**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070012 * An abstract class to define flow object which is managed by
Toshio Koidea03915e2014-07-01 18:39:52 -070013 * FlowManagerModule.
Toshio Koidea03915e2014-07-01 18:39:52 -070014 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070015public abstract class Flow implements BatchOperationTarget {
16 private final FlowId id;
17
18 /**
19 * Creates Flow object using specified ID.
20 *
21 * @param id the ID to be assigned
22 */
23 public Flow(FlowId id) {
24 this.id = checkNotNull(id);
25 }
26
Toshio Koidea03915e2014-07-01 18:39:52 -070027 /**
28 * Gets ID for this flow object.
29 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070030 * @return ID for this object
Toshio Koidea03915e2014-07-01 18:39:52 -070031 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070032 public FlowId getId() {
33 return id;
34 }
Toshio Koidea03915e2014-07-01 18:39:52 -070035
36 /**
37 * Gets traffic filter for this flow object.
38 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070039 * @return a traffic filter for this flow object
Toshio Koidea03915e2014-07-01 18:39:52 -070040 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070041 public abstract Match getMatch();
Toshio Koidea03915e2014-07-01 18:39:52 -070042
43 /**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070044 * Compiles this object to MatchAction operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070045 * <p>
Toshio Koide5c5ca102014-08-19 00:49:52 -070046 * This method is called by FlowManagerModule to create MatchAction
47 * operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070048 *
Toshio Koide5c5ca102014-08-19 00:49:52 -070049 * @param op FlowBatchOperation.Operator to be used for compiling this object
50 * @return a list of MatchActionOperations objects to realize this flow
Toshio Koidea03915e2014-07-01 18:39:52 -070051 */
Toshio Koide5c5ca102014-08-19 00:49:52 -070052 public abstract List<MatchActionOperations> compile(FlowBatchOperation.Operator op);
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070053
54 /**
55 * Generates a hash code using the FlowId.
56 *
57 * @return hashcode
58 */
59 @Override
60 public int hashCode() {
61 return (id == null) ? 0 : id.hashCode();
62 }
63
64 /**
65 * Compares two flow objects by type (class) and FlowId.
66 *
67 * @param obj other Flow object
68 * @return true if equal, false otherwise
69 */
70 @Override
71 public boolean equals(Object obj) {
72 if (this == obj) {
73 return true;
74 }
Toshio Koide08808102014-08-18 18:29:47 -070075 if (!(obj instanceof Flow)) {
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070076 return false;
77 }
78 Flow other = (Flow) obj;
79 if (id == null) {
80 if (other.id != null) {
81 return false;
82 }
83 } else if (!id.equals(other.id)) {
84 return false;
85 }
86 return true;
87 }
Toshio Koidea03915e2014-07-01 18:39:52 -070088}