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; |
Toshio Koide | d7d550c | 2014-08-21 16:08:55 -0700 | [diff] [blame^] | 8 | import net.onrc.onos.core.matchaction.MatchActionIdGenerator; |
Ray Milkey | 42ae1b5 | 2014-08-15 16:37:06 -0700 | [diff] [blame] | 9 | import net.onrc.onos.core.matchaction.MatchActionOperations; |
Toshio Koide | d7d550c | 2014-08-21 16:08:55 -0700 | [diff] [blame^] | 10 | import net.onrc.onos.core.matchaction.MatchActionOperationsIdGenerator; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame] | 11 | import net.onrc.onos.core.matchaction.match.Match; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 12 | |
| 13 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 14 | * An abstract class to define flow object which is managed by |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 15 | * FlowManagerModule. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 16 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 17 | public 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Gets ID for this flow object. |
| 31 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 32 | * @return ID for this object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 33 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 34 | public FlowId getId() { |
| 35 | return id; |
| 36 | } |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Gets traffic filter for this flow object. |
| 40 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 41 | * @return a traffic filter for this flow object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 42 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 43 | public abstract Match getMatch(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 46 | * Compiles this object to MatchAction operations. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 47 | * <p> |
Toshio Koide | 5c5ca10 | 2014-08-19 00:49:52 -0700 | [diff] [blame] | 48 | * This method is called by FlowManagerModule to create MatchAction |
| 49 | * operations. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 50 | * |
Toshio Koide | d7d550c | 2014-08-21 16:08:55 -0700 | [diff] [blame^] | 51 | * @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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 59 | */ |
Toshio Koide | d7d550c | 2014-08-21 16:08:55 -0700 | [diff] [blame^] | 60 | public abstract List<MatchActionOperations> compile( |
| 61 | FlowBatchOperation.Operator op, |
| 62 | MatchActionIdGenerator maIdGenerator, |
| 63 | MatchActionOperationsIdGenerator maoIdGenerator); |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 64 | |
| 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 Koide | 0880810 | 2014-08-18 18:29:47 -0700 | [diff] [blame] | 86 | if (!(obj instanceof Flow)) { |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 87 | 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 99 | } |