blob: e912956d2db1ddafaa3233669072af9f47fc12b7 [file] [log] [blame]
Brian O'Connordee2e6b2014-08-12 11:34:51 -07001package net.onrc.onos.core.matchaction;
2
Brian O'Connor0efc9062014-09-02 14:47:28 -07003import static com.google.common.base.Preconditions.checkNotNull;
Brian O'Connordee2e6b2014-08-12 11:34:51 -07004
Ray Milkey18b44ac2014-08-22 08:29:47 -07005import java.util.HashSet;
6import java.util.Set;
7
Brian O'Connor0efc9062014-09-02 14:47:28 -07008import net.onrc.onos.api.batchoperation.BatchOperation;
Ray Milkeyc127a5a2014-08-20 11:22:12 -07009
10/**
11 * The MatchActionOperations class holds a list of MatchActionOperationEntry
12 * objects to be executed together as one set.
Ray Milkeyc127a5a2014-08-20 11:22:12 -070013 */
Ray Milkey18b44ac2014-08-22 08:29:47 -070014public class MatchActionOperations
Brian O'Connordee2e6b2014-08-12 11:34:51 -070015 extends BatchOperation<MatchActionOperationEntry> {
Ray Milkeyc127a5a2014-08-20 11:22:12 -070016
17 private final MatchActionOperationsId id;
Ray Milkey18b44ac2014-08-22 08:29:47 -070018 private MatchActionOperationsState state;
19 private final Set<MatchActionOperationsId> dependencies;
20
Brian O'Connordee2e6b2014-08-12 11:34:51 -070021 /**
22 * The MatchAction operators.
23 */
24 public enum Operator {
Ray Milkeya313cde2014-09-05 09:02:52 -070025 /** Add a new match action. */
Brian O'Connordee2e6b2014-08-12 11:34:51 -070026 ADD,
Ray Milkeya313cde2014-09-05 09:02:52 -070027
28 /** Remove an existing match action. */
Brian O'Connordee2e6b2014-08-12 11:34:51 -070029 REMOVE,
Sangho Shin5be3e532014-10-03 17:20:58 -070030
31 /*** Modify an existing match action entry strictly matching wildcards
32 * and priority (works as MODIFY StRICT). */
33 MODIFY,
34
Brian O'Connordee2e6b2014-08-12 11:34:51 -070035 }
36
Ray Milkeyc127a5a2014-08-20 11:22:12 -070037 /**
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 Milkey9ed4b962014-08-20 15:43:40 -070043 public MatchActionOperations(final MatchActionOperationsId newId) {
Ray Milkeyc127a5a2014-08-20 11:22:12 -070044 id = checkNotNull(newId);
Ray Milkey18b44ac2014-08-22 08:29:47 -070045 state = MatchActionOperationsState.INIT;
46 dependencies = new HashSet<>();
Ray Milkeyc127a5a2014-08-20 11:22:12 -070047 }
48
49 /**
Brian O'Connor0efc9062014-09-02 14:47:28 -070050 * no-arg constructor for Kryo.
51 */
52 protected MatchActionOperations() {
53 id = null;
54 dependencies = null;
55 }
56
57 /**
Ray Milkeyc127a5a2014-08-20 11:22:12 -070058 * 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 Milkey18b44ac2014-08-22 08:29:47 -070066 /**
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 Milkeya313cde2014-09-05 09:02:52 -070094 /**
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 Milkey18b44ac2014-08-22 08:29:47 -0700100 public void addDependency(MatchActionOperationsId dependentOperationId) {
101 dependencies.add(dependentOperationId);
102 }
103
Ray Milkeyc127a5a2014-08-20 11:22:12 -0700104 @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'Connordee2e6b2014-08-12 11:34:51 -0700117}