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; |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 8 | import net.onrc.onos.core.matchaction.MatchActionId; |
Ray Milkey | 42ae1b5 | 2014-08-15 16:37:06 -0700 | [diff] [blame] | 9 | import net.onrc.onos.core.matchaction.MatchActionOperations; |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 10 | import net.onrc.onos.core.matchaction.MatchActionOperationsId; |
Toshio Koide | d8b077a | 2014-08-13 10:47:21 -0700 | [diff] [blame] | 11 | import net.onrc.onos.core.matchaction.match.Match; |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 12 | import net.onrc.onos.core.util.IdGenerator; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 13 | |
| 14 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 15 | * An abstract class to define flow object which is managed by |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 16 | * FlowManagerModule. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 17 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 18 | public abstract class Flow implements BatchOperationTarget { |
| 19 | private final FlowId id; |
| 20 | |
| 21 | /** |
Toshio Koide | 2c67a2d | 2014-08-27 11:30:56 -0700 | [diff] [blame] | 22 | * Default constructor for Kryo deserialization. |
| 23 | */ |
| 24 | @Deprecated |
| 25 | protected Flow() { |
| 26 | id = null; |
| 27 | } |
| 28 | |
| 29 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 30 | * Creates Flow object using specified ID. |
| 31 | * |
| 32 | * @param id the ID to be assigned |
| 33 | */ |
| 34 | public Flow(FlowId id) { |
| 35 | this.id = checkNotNull(id); |
| 36 | } |
| 37 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 38 | /** |
| 39 | * Gets ID for this flow object. |
| 40 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 41 | * @return ID for this 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 FlowId getId() { |
| 44 | return id; |
| 45 | } |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Gets traffic filter for this flow object. |
| 49 | * |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 50 | * @return a traffic filter for this flow object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 51 | */ |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 52 | public abstract Match getMatch(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 55 | * Compiles this object to MatchAction operations. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 56 | * <p> |
Toshio Koide | 5c5ca10 | 2014-08-19 00:49:52 -0700 | [diff] [blame] | 57 | * This method is called by FlowManagerModule to create MatchAction |
| 58 | * operations. |
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 | * @param op {@link FlowBatchOperation}'s operator to be used for compiling |
| 61 | * this object |
| 62 | * @param maIdGenerator ID generator to be used for generating MatchAction |
| 63 | * objects. |
| 64 | * @param maoIdGenerator ID generator to be used for generating |
| 65 | * {@link MatchActionOperations} objects. |
| 66 | * @return a list of {@link MatchActionOperations} objects to realize this |
| 67 | * flow |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 68 | */ |
Toshio Koide | d7d550c | 2014-08-21 16:08:55 -0700 | [diff] [blame] | 69 | public abstract List<MatchActionOperations> compile( |
| 70 | FlowBatchOperation.Operator op, |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 71 | IdGenerator<MatchActionId> maIdGenerator, |
| 72 | IdGenerator<MatchActionOperationsId> maoIdGenerator); |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Generates a hash code using the FlowId. |
| 76 | * |
| 77 | * @return hashcode |
| 78 | */ |
| 79 | @Override |
| 80 | public int hashCode() { |
| 81 | return (id == null) ? 0 : id.hashCode(); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Compares two flow objects by type (class) and FlowId. |
| 86 | * |
| 87 | * @param obj other Flow object |
| 88 | * @return true if equal, false otherwise |
| 89 | */ |
| 90 | @Override |
| 91 | public boolean equals(Object obj) { |
| 92 | if (this == obj) { |
| 93 | return true; |
| 94 | } |
Toshio Koide | 0880810 | 2014-08-18 18:29:47 -0700 | [diff] [blame] | 95 | if (!(obj instanceof Flow)) { |
Toshio Koide | 9aa4c0f | 2014-08-11 16:06:44 -0700 | [diff] [blame] | 96 | return false; |
| 97 | } |
| 98 | Flow other = (Flow) obj; |
| 99 | if (id == null) { |
| 100 | if (other.id != null) { |
| 101 | return false; |
| 102 | } |
| 103 | } else if (!id.equals(other.id)) { |
| 104 | return false; |
| 105 | } |
| 106 | return true; |
| 107 | } |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 108 | } |