Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.flowmanager; |
| 2 | |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 3 | import static com.google.common.base.Preconditions.checkNotNull; |
Toshio Koide | fad1cd5 | 2014-08-07 17:10:07 -0700 | [diff] [blame] | 4 | import net.onrc.onos.api.batchoperation.BatchOperationTarget; |
Ray Milkey | 42ae1b5 | 2014-08-15 16:37:06 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.matchaction.MatchActionOperations; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame] | 6 | import net.onrc.onos.core.matchaction.match.Match; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 7 | |
| 8 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 9 | * An abstract class to define flow object which is managed by |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 10 | * FlowManagerModule. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 11 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 12 | public 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Gets ID for this flow object. |
| 26 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 27 | * @return ID for this object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 28 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 29 | public FlowId getId() { |
| 30 | return id; |
| 31 | } |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Gets traffic filter for this flow object. |
| 35 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 36 | * @return a traffic filter for this flow object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 37 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 38 | public abstract Match getMatch(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 41 | * Compiles this object to MatchAction operations. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 42 | * <p> |
Ray Milkey | 42ae1b5 | 2014-08-15 16:37:06 -0700 | [diff] [blame] | 43 | * This method is called by FlowManagerModule to create MatchAction operations. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 44 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 45 | * @return a MatchActionOperations of this flow object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 46 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame^] | 47 | 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 | } |
| 70 | if ((obj == null) || !(obj instanceof Flow)) { |
| 71 | 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 83 | } |