blob: e0cf677b2234abfbaaea717d40ad5f367db28b2c [file] [log] [blame]
Thomas Vachuska1fb982f2014-10-22 14:09:17 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska1fb982f2014-10-22 14:09:17 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska1fb982f2014-10-22 14:09:17 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070015 */
16package org.onlab.onos.net.intent;
17
Brian O'Connorfa81eae2014-10-30 13:20:05 -070018
19import java.util.Objects;
20
21import static com.google.common.base.MoreObjects.toStringHelper;
22
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070023/**
24 * Abstraction of an intent-related operation, e.g. add, remove, replace.
25 */
Ray Milkeyc8f481f2014-11-18 15:37:12 -080026public final class IntentOperation {
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070027
28 private final Type type;
29 private final IntentId intentId;
30 private final Intent intent;
31
32 /**
33 * Operation type.
34 */
Brian O'Connorfa81eae2014-10-30 13:20:05 -070035 public enum Type {
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070036 /**
37 * Indicates that an intent should be added.
38 */
39 SUBMIT,
40
41 /**
42 * Indicates that an intent should be removed.
43 */
44 WITHDRAW,
45
46 /**
47 * Indicates that an intent should be replaced with another.
48 */
Brian O'Connorfa81eae2014-10-30 13:20:05 -070049 REPLACE,
50
51 /**
52 * Indicates that an intent should be updated (i.e. recompiled/reinstalled).
53 */
54 UPDATE,
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070055 }
56
57 /**
58 * Creates an intent operation.
59 *
Brian O'Connorfa81eae2014-10-30 13:20:05 -070060 * @param type operation type
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070061 * @param intentId identifier of the intent subject to the operation
Brian O'Connorfa81eae2014-10-30 13:20:05 -070062 * @param intent intent subject
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070063 */
64 IntentOperation(Type type, IntentId intentId, Intent intent) {
65 this.type = type;
66 this.intentId = intentId;
67 this.intent = intent;
68 }
69
70 /**
71 * Returns the type of the operation.
72 *
73 * @return operation type
74 */
75 public Type type() {
76 return type;
77 }
78
79 /**
80 * Returns the identifier of the intent to which this operation applies.
81 *
82 * @return intent identifier
83 */
84 public IntentId intentId() {
85 return intentId;
86 }
87
88 /**
89 * Returns the intent to which this operation applied. For remove,
90 * this can be null.
91 *
92 * @return intent that is the subject of the operation; null for remove
93 */
94 public Intent intent() {
95 return intent;
96 }
97
Brian O'Connorfa81eae2014-10-30 13:20:05 -070098 @Override
99 public int hashCode() {
100 return Objects.hash(type, intentId, intent);
101 }
102
103 @Override
104 public boolean equals(Object obj) {
105 if (this == obj) {
106 return true;
107 }
108 if (obj == null || getClass() != obj.getClass()) {
109 return false;
110 }
111 final IntentOperation other = (IntentOperation) obj;
112 return Objects.equals(this.type, other.type) &&
113 Objects.equals(this.intentId, other.intentId) &&
114 Objects.equals(this.intent, other.intent);
115 }
116
117
118 @Override
119 public String toString() {
120 return toStringHelper(this)
121 .add("type", type)
122 .add("intentId", intentId)
123 .add("intent", intent)
124 .toString();
125 }
Thomas Vachuska1fb982f2014-10-22 14:09:17 -0700126}