blob: 6ea85a10ef35566a61a07ab36ed08d0acfb5ba66 [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 Koidefad1cd52014-08-07 17:10:07 -07004import net.onrc.onos.api.batchoperation.BatchOperationTarget;
Ray Milkey42ae1b52014-08-15 16:37:06 -07005import net.onrc.onos.core.matchaction.MatchActionOperations;
Toshio Koided8b077a2014-08-13 10:47:21 -07006import net.onrc.onos.core.matchaction.match.Match;
Toshio Koidea03915e2014-07-01 18:39:52 -07007
8/**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -07009 * An abstract class to define flow object which is managed by
Toshio Koidea03915e2014-07-01 18:39:52 -070010 * FlowManagerModule.
Toshio Koidea03915e2014-07-01 18:39:52 -070011 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070012public abstract class Flow implements BatchOperationTarget {
13 private final FlowId id;
14
15 /**
16 * Creates Flow object using specified ID.
17 *
18 * @param id the ID to be assigned
19 */
20 public Flow(FlowId id) {
21 this.id = checkNotNull(id);
22 }
23
Toshio Koidea03915e2014-07-01 18:39:52 -070024 /**
25 * Gets ID for this flow object.
26 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070027 * @return ID for this object
Toshio Koidea03915e2014-07-01 18:39:52 -070028 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070029 public FlowId getId() {
30 return id;
31 }
Toshio Koidea03915e2014-07-01 18:39:52 -070032
33 /**
34 * Gets traffic filter for this flow object.
35 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070036 * @return a traffic filter for this flow object
Toshio Koidea03915e2014-07-01 18:39:52 -070037 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070038 public abstract Match getMatch();
Toshio Koidea03915e2014-07-01 18:39:52 -070039
40 /**
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070041 * Compiles this object to MatchAction operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070042 * <p>
Ray Milkey42ae1b52014-08-15 16:37:06 -070043 * This method is called by FlowManagerModule to create MatchAction operations.
Toshio Koidea03915e2014-07-01 18:39:52 -070044 *
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070045 * @return a MatchActionOperations of this flow object
Toshio Koidea03915e2014-07-01 18:39:52 -070046 */
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070047 public abstract MatchActionOperations compile();
48
49 /**
50 * Generates a hash code using the FlowId.
51 *
52 * @return hashcode
53 */
54 @Override
55 public int hashCode() {
56 return (id == null) ? 0 : id.hashCode();
57 }
58
59 /**
60 * Compares two flow objects by type (class) and FlowId.
61 *
62 * @param obj other Flow object
63 * @return true if equal, false otherwise
64 */
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
Toshio Koide08808102014-08-18 18:29:47 -070070 if (!(obj instanceof Flow)) {
Toshio Koide9aa4c0f2014-08-11 16:06:44 -070071 return false;
72 }
73 Flow other = (Flow) obj;
74 if (id == null) {
75 if (other.id != null) {
76 return false;
77 }
78 } else if (!id.equals(other.id)) {
79 return false;
80 }
81 return true;
82 }
Toshio Koidea03915e2014-07-01 18:39:52 -070083}