blob: 7d9063f8b4d5dc01ba46e1f2e00fd2a52a4bbfb2 [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,
30 }
31
Ray Milkeyc127a5a2014-08-20 11:22:12 -070032 /**
33 * Constructs a MatchActionOperations object from an id. Internal
34 * constructor called by a public factory method.
35 *
36 * @param newId match action operations identifier for this instance
37 */
Ray Milkey9ed4b962014-08-20 15:43:40 -070038 public MatchActionOperations(final MatchActionOperationsId newId) {
Ray Milkeyc127a5a2014-08-20 11:22:12 -070039 id = checkNotNull(newId);
Ray Milkey18b44ac2014-08-22 08:29:47 -070040 state = MatchActionOperationsState.INIT;
41 dependencies = new HashSet<>();
Ray Milkeyc127a5a2014-08-20 11:22:12 -070042 }
43
44 /**
Brian O'Connor0efc9062014-09-02 14:47:28 -070045 * no-arg constructor for Kryo.
46 */
47 protected MatchActionOperations() {
48 id = null;
49 dependencies = null;
50 }
51
52 /**
Ray Milkeyc127a5a2014-08-20 11:22:12 -070053 * Gets the identifier for the Match Action Operations object.
54 *
55 * @return identifier for the Opertions object
56 */
57 public MatchActionOperationsId getOperationsId() {
58 return id;
59 }
60
Ray Milkey18b44ac2014-08-22 08:29:47 -070061 /**
62 * Gets the state of the Match Action Operations.
63 *
64 * @return state of the operations
65 */
66 public MatchActionOperationsState getState() {
67 return state;
68 }
69
70 /**
71 * Sets the state of the Match Action Operations.
72 *
73 * @param newState new state of the operations
74 */
75 public void setState(final MatchActionOperationsState newState) {
76 state = newState;
77 }
78
79 /**
80 * Gets the set of IDs of operations that are dependent on this
81 * operation.
82 *
83 * @return set of operations IDs of dependent operations
84 */
85 public Set<MatchActionOperationsId> getDependencies() {
86 return dependencies;
87 }
88
Ray Milkeya313cde2014-09-05 09:02:52 -070089 /**
90 * Adds a dependency to this set of Operations.
91 *
92 * @param dependentOperationId Identifier of the Operations that must
93 * complete before this one can be installed
94 */
Ray Milkey18b44ac2014-08-22 08:29:47 -070095 public void addDependency(MatchActionOperationsId dependentOperationId) {
96 dependencies.add(dependentOperationId);
97 }
98
Ray Milkeyc127a5a2014-08-20 11:22:12 -070099 @Override
100 public int hashCode() {
101 return id.hashCode();
102 }
103
104 @Override
105 public boolean equals(Object obj) {
106 if (obj instanceof MatchActionOperations) {
107 final MatchActionOperations other = (MatchActionOperations) obj;
108 return (id.equals(other.id));
109 }
110 return false;
111 }
Brian O'Connordee2e6b2014-08-12 11:34:51 -0700112}