Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 3 | import static com.google.common.base.Preconditions.checkNotNull; |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 4 | |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 5 | import java.util.HashSet; |
| 6 | import java.util.Set; |
| 7 | |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 8 | import net.onrc.onos.api.batchoperation.BatchOperation; |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * The MatchActionOperations class holds a list of MatchActionOperationEntry |
| 12 | * objects to be executed together as one set. |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 13 | */ |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 14 | public class MatchActionOperations |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 15 | extends BatchOperation<MatchActionOperationEntry> { |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 16 | |
| 17 | private final MatchActionOperationsId id; |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 18 | private MatchActionOperationsState state; |
| 19 | private final Set<MatchActionOperationsId> dependencies; |
| 20 | |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 21 | /** |
| 22 | * The MatchAction operators. |
| 23 | */ |
| 24 | public enum Operator { |
Ray Milkey | a313cde | 2014-09-05 09:02:52 -0700 | [diff] [blame] | 25 | /** Add a new match action. */ |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 26 | ADD, |
Ray Milkey | a313cde | 2014-09-05 09:02:52 -0700 | [diff] [blame] | 27 | |
| 28 | /** Remove an existing match action. */ |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 29 | REMOVE, |
Sangho Shin | 5be3e53 | 2014-10-03 17:20:58 -0700 | [diff] [blame] | 30 | |
| 31 | /*** Modify an existing match action entry strictly matching wildcards |
| 32 | * and priority (works as MODIFY StRICT). */ |
| 33 | MODIFY, |
| 34 | |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Constructs a MatchActionOperations object from an id. Internal |
| 39 | * constructor called by a public factory method. |
| 40 | * |
| 41 | * @param newId match action operations identifier for this instance |
| 42 | */ |
Ray Milkey | 9ed4b96 | 2014-08-20 15:43:40 -0700 | [diff] [blame] | 43 | public MatchActionOperations(final MatchActionOperationsId newId) { |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 44 | id = checkNotNull(newId); |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 45 | state = MatchActionOperationsState.INIT; |
| 46 | dependencies = new HashSet<>(); |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
Brian O'Connor | 0efc906 | 2014-09-02 14:47:28 -0700 | [diff] [blame] | 50 | * no-arg constructor for Kryo. |
| 51 | */ |
| 52 | protected MatchActionOperations() { |
| 53 | id = null; |
| 54 | dependencies = null; |
| 55 | } |
| 56 | |
| 57 | /** |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 58 | * Gets the identifier for the Match Action Operations object. |
| 59 | * |
| 60 | * @return identifier for the Opertions object |
| 61 | */ |
| 62 | public MatchActionOperationsId getOperationsId() { |
| 63 | return id; |
| 64 | } |
| 65 | |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Gets the state of the Match Action Operations. |
| 68 | * |
| 69 | * @return state of the operations |
| 70 | */ |
| 71 | public MatchActionOperationsState getState() { |
| 72 | return state; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Sets the state of the Match Action Operations. |
| 77 | * |
| 78 | * @param newState new state of the operations |
| 79 | */ |
| 80 | public void setState(final MatchActionOperationsState newState) { |
| 81 | state = newState; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Gets the set of IDs of operations that are dependent on this |
| 86 | * operation. |
| 87 | * |
| 88 | * @return set of operations IDs of dependent operations |
| 89 | */ |
| 90 | public Set<MatchActionOperationsId> getDependencies() { |
| 91 | return dependencies; |
| 92 | } |
| 93 | |
Ray Milkey | a313cde | 2014-09-05 09:02:52 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Adds a dependency to this set of Operations. |
| 96 | * |
| 97 | * @param dependentOperationId Identifier of the Operations that must |
| 98 | * complete before this one can be installed |
| 99 | */ |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 100 | public void addDependency(MatchActionOperationsId dependentOperationId) { |
| 101 | dependencies.add(dependentOperationId); |
| 102 | } |
| 103 | |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 104 | @Override |
| 105 | public int hashCode() { |
| 106 | return id.hashCode(); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public boolean equals(Object obj) { |
| 111 | if (obj instanceof MatchActionOperations) { |
| 112 | final MatchActionOperations other = (MatchActionOperations) obj; |
| 113 | return (id.equals(other.id)); |
| 114 | } |
| 115 | return false; |
| 116 | } |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 117 | } |