blob: a99ed076533357e555b6aa10dd3165657c761541 [file] [log] [blame]
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
16package org.onosproject.net.group;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import org.onosproject.core.GroupId;
21
22public final class GroupOperation {
23 private final Type opType;
24 private final GroupId groupId;
25 private final GroupDescription.Type groupType;
26 private final GroupBuckets buckets;
27
28 public enum Type {
29 /**
30 * Create a group in a device with the specified parameters.
31 */
32 ADD,
33 /**
34 * Modify a group in a device with the specified parameters.
35 */
36 MODIFY,
37 /**
38 * Delete a specified group.
39 */
40 DELETE
41 }
42
43 /**
44 * Group operation constructor with the parameters.
45 *
46 * @param opType group operation type
47 * @param groupId group Identifier
48 * @param groupType type of the group
49 * @param buckets immutable list of group buckets to be part of group
50 */
51 private GroupOperation(Type opType,
52 GroupId groupId,
53 GroupDescription.Type groupType,
54 GroupBuckets buckets) {
55 this.opType = checkNotNull(opType);
56 this.groupId = checkNotNull(groupId);
57 this.groupType = checkNotNull(groupType);
58 this.buckets = buckets;
59 }
60
61 /**
62 * Creates ADD group operation object.
63 *
64 * @param groupId group Identifier
65 * @param groupType type of the group
66 * @param buckets immutable list of group buckets to be part of group
67 *
68 * @return add group operation object
69 */
70 public static GroupOperation createAddGroupOperation(GroupId groupId,
71 GroupDescription.Type groupType,
72 GroupBuckets buckets) {
73 checkNotNull(buckets);
74 return new GroupOperation(Type.ADD, groupId, groupType, buckets);
75 }
76
77 /**
78 * Creates MODIFY group operation object.
79 *
80 * @param groupId group Identifier
81 * @param groupType type of the group
82 * @param buckets immutable list of group buckets to be part of group
83 *
84 * @return modify group operation object
85 */
86 public static GroupOperation createModifyGroupOperation(GroupId groupId,
87 GroupDescription.Type groupType,
88 GroupBuckets buckets) {
89 checkNotNull(buckets);
90 return new GroupOperation(Type.MODIFY, groupId, groupType, buckets);
91
92 }
93
94 /**
95 * Creates DELETE group operation object.
96 *
97 * @param groupId group Identifier
98 * @param groupType type of the group
99 *
100 * @return delete group operation object
101 */
102 public static GroupOperation createDeleteGroupOperation(GroupId groupId,
103 GroupDescription.Type groupType) {
104 return new GroupOperation(Type.DELETE, groupId, groupType, null);
105
106 }
107
108 /**
109 * Return group operation type.
110 *
111 * @return GroupOpType group operation type
112 */
113 public Type opType() {
114 return this.opType;
115 }
116
117 /**
118 * Return group identifier attribute of the operation.
119 *
120 * @return GroupId group identifier
121 */
122 public GroupId groupId() {
123 return this.groupId;
124 }
125
126 /**
127 * Return group type attribute of the operation.
128 *
129 * @return GroupType group type
130 */
131 public GroupDescription.Type groupType() {
132 return this.groupType;
133 }
134
135 /**
136 * Return group buckets associated with the operation.
137 *
138 * @return GroupBuckets group buckets
139 */
140 public GroupBuckets buckets() {
141 return this.buckets;
142 }
143}