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 | 5c5ca10 | 2014-08-19 00:49:52 -0700 | [diff] [blame^] | 4 | |
| 5 | import java.util.List; |
| 6 | |
Toshio Koide | fad1cd5 | 2014-08-07 17:10:07 -0700 | [diff] [blame] | 7 | import net.onrc.onos.api.batchoperation.BatchOperationTarget; |
Ray Milkey | 42ae1b5 | 2014-08-15 16:37:06 -0700 | [diff] [blame] | 8 | import net.onrc.onos.core.matchaction.MatchActionOperations; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame] | 9 | import net.onrc.onos.core.matchaction.match.Match; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 10 | |
| 11 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 12 | * An abstract class to define flow object which is managed by |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 13 | * FlowManagerModule. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 14 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 15 | public 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Gets ID for this flow object. |
| 29 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 30 | * @return ID for this object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 31 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 32 | public FlowId getId() { |
| 33 | return id; |
| 34 | } |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Gets traffic filter for this flow object. |
| 38 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 39 | * @return a traffic filter for this flow object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 40 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 41 | public abstract Match getMatch(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 44 | * Compiles this object to MatchAction operations. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 45 | * <p> |
Toshio Koide | 5c5ca10 | 2014-08-19 00:49:52 -0700 | [diff] [blame^] | 46 | * This method is called by FlowManagerModule to create MatchAction |
| 47 | * operations. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 48 | * |
Toshio Koide | 5c5ca10 | 2014-08-19 00:49:52 -0700 | [diff] [blame^] | 49 | * @param op FlowBatchOperation.Operator to be used for compiling this object |
| 50 | * @return a list of MatchActionOperations objects to realize this flow |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 51 | */ |
Toshio Koide | 5c5ca10 | 2014-08-19 00:49:52 -0700 | [diff] [blame^] | 52 | public abstract List<MatchActionOperations> compile(FlowBatchOperation.Operator op); |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 53 | |
| 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 Koide | 0880810 | 2014-08-18 18:29:47 -0700 | [diff] [blame] | 75 | if (!(obj instanceof Flow)) { |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 76 | 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 88 | } |