blob: 44d7e88df9efa81f14d3a229fc54187761fb9bee [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
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080022/**
23 * Group operation definition to be used between core and provider
24 * layers of group subsystem.
25 *
26 */
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080027public final class GroupOperation {
28 private final Type opType;
29 private final GroupId groupId;
30 private final GroupDescription.Type groupType;
31 private final GroupBuckets buckets;
32
33 public enum Type {
34 /**
35 * Create a group in a device with the specified parameters.
36 */
37 ADD,
38 /**
39 * Modify a group in a device with the specified parameters.
40 */
41 MODIFY,
42 /**
43 * Delete a specified group.
44 */
45 DELETE
46 }
47
48 /**
49 * Group operation constructor with the parameters.
50 *
51 * @param opType group operation type
52 * @param groupId group Identifier
53 * @param groupType type of the group
54 * @param buckets immutable list of group buckets to be part of group
55 */
56 private GroupOperation(Type opType,
57 GroupId groupId,
58 GroupDescription.Type groupType,
59 GroupBuckets buckets) {
60 this.opType = checkNotNull(opType);
61 this.groupId = checkNotNull(groupId);
62 this.groupType = checkNotNull(groupType);
63 this.buckets = buckets;
64 }
65
66 /**
67 * Creates ADD group operation object.
68 *
69 * @param groupId group Identifier
70 * @param groupType type of the group
71 * @param buckets immutable list of group buckets to be part of group
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080072 * @return add group operation object
73 */
74 public static GroupOperation createAddGroupOperation(GroupId groupId,
75 GroupDescription.Type groupType,
76 GroupBuckets buckets) {
77 checkNotNull(buckets);
78 return new GroupOperation(Type.ADD, groupId, groupType, buckets);
79 }
80
81 /**
82 * Creates MODIFY group operation object.
83 *
84 * @param groupId group Identifier
85 * @param groupType type of the group
86 * @param buckets immutable list of group buckets to be part of group
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080087 * @return modify group operation object
88 */
89 public static GroupOperation createModifyGroupOperation(GroupId groupId,
90 GroupDescription.Type groupType,
91 GroupBuckets buckets) {
92 checkNotNull(buckets);
93 return new GroupOperation(Type.MODIFY, groupId, groupType, buckets);
94
95 }
96
97 /**
98 * Creates DELETE group operation object.
99 *
100 * @param groupId group Identifier
101 * @param groupType type of the group
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800102 * @return delete group operation object
103 */
104 public static GroupOperation createDeleteGroupOperation(GroupId groupId,
105 GroupDescription.Type groupType) {
106 return new GroupOperation(Type.DELETE, groupId, groupType, null);
107
108 }
109
110 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800111 * Returns group operation type.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800112 *
113 * @return GroupOpType group operation type
114 */
115 public Type opType() {
116 return this.opType;
117 }
118
119 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800120 * Returns group identifier attribute of the operation.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800121 *
122 * @return GroupId group identifier
123 */
124 public GroupId groupId() {
125 return this.groupId;
126 }
127
128 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800129 * Returns group type attribute of the operation.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800130 *
131 * @return GroupType group type
132 */
133 public GroupDescription.Type groupType() {
134 return this.groupType;
135 }
136
137 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800138 * Returns group buckets associated with the operation.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800139 *
140 * @return GroupBuckets group buckets
141 */
142 public GroupBuckets buckets() {
143 return this.buckets;
144 }
145}