Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.group; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import org.onosproject.core.GroupId; |
| 21 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 22 | /** |
| 23 | * Group operation definition to be used between core and provider |
| 24 | * layers of group subsystem. |
| 25 | * |
| 26 | */ |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 27 | public 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 Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 72 | * @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 Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 87 | * @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 Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 102 | * @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 Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 111 | * Returns group operation type. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 112 | * |
| 113 | * @return GroupOpType group operation type |
| 114 | */ |
| 115 | public Type opType() { |
| 116 | return this.opType; |
| 117 | } |
| 118 | |
| 119 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 120 | * Returns group identifier attribute of the operation. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 121 | * |
| 122 | * @return GroupId group identifier |
| 123 | */ |
| 124 | public GroupId groupId() { |
| 125 | return this.groupId; |
| 126 | } |
| 127 | |
| 128 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 129 | * Returns group type attribute of the operation. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 130 | * |
| 131 | * @return GroupType group type |
| 132 | */ |
| 133 | public GroupDescription.Type groupType() { |
| 134 | return this.groupType; |
| 135 | } |
| 136 | |
| 137 | /** |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame^] | 138 | * Returns group buckets associated with the operation. |
Srikanth Vavilapalli | 56db94f | 2015-01-22 22:30:17 -0800 | [diff] [blame] | 139 | * |
| 140 | * @return GroupBuckets group buckets |
| 141 | */ |
| 142 | public GroupBuckets buckets() { |
| 143 | return this.buckets; |
| 144 | } |
| 145 | } |