Srikanth Vavilapalli | 717361f | 2015-03-16 12:06:04 -0700 | [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.store.group.impl; |
| 17 | |
| 18 | import org.onosproject.net.DeviceId; |
| 19 | import org.onosproject.net.group.GroupBuckets; |
| 20 | import org.onosproject.net.group.GroupDescription; |
| 21 | import org.onosproject.net.group.GroupKey; |
| 22 | import org.onosproject.net.group.GroupStore.UpdateType; |
| 23 | |
| 24 | /** |
| 25 | * Format of the Group store message that is used to |
| 26 | * communicate with the peer nodes in the cluster. |
| 27 | */ |
| 28 | public final class GroupStoreMessage { |
| 29 | private final DeviceId deviceId; |
| 30 | private final GroupKey appCookie; |
| 31 | private final GroupDescription groupDesc; |
| 32 | private final UpdateType updateType; |
| 33 | private final GroupBuckets updateBuckets; |
| 34 | private final GroupKey newAppCookie; |
| 35 | private final Type type; |
| 36 | |
| 37 | /** |
| 38 | * Type of group store request. |
| 39 | */ |
| 40 | public enum Type { |
| 41 | ADD, |
| 42 | UPDATE, |
| 43 | DELETE |
| 44 | } |
| 45 | |
| 46 | private GroupStoreMessage(Type type, |
| 47 | DeviceId deviceId, |
| 48 | GroupKey appCookie, |
| 49 | GroupDescription groupDesc, |
| 50 | UpdateType updateType, |
| 51 | GroupBuckets updateBuckets, |
| 52 | GroupKey newAppCookie) { |
| 53 | this.type = type; |
| 54 | this.deviceId = deviceId; |
| 55 | this.appCookie = appCookie; |
| 56 | this.groupDesc = groupDesc; |
| 57 | this.updateType = updateType; |
| 58 | this.updateBuckets = updateBuckets; |
| 59 | this.newAppCookie = newAppCookie; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Creates a group store message for group ADD request. |
| 64 | * |
| 65 | * @param deviceId device identifier in which group to be added |
| 66 | * @param desc group creation parameters |
| 67 | * @return constructed group store message |
| 68 | */ |
| 69 | public static GroupStoreMessage createGroupAddRequestMsg(DeviceId deviceId, |
| 70 | GroupDescription desc) { |
| 71 | return new GroupStoreMessage(Type.ADD, |
| 72 | deviceId, |
| 73 | null, |
| 74 | desc, |
| 75 | null, |
| 76 | null, |
| 77 | null); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Creates a group store message for group UPDATE request. |
| 82 | * |
| 83 | * @param deviceId the device ID |
| 84 | * @param appCookie the current group key |
| 85 | * @param updateType update (add or delete) type |
| 86 | * @param updateBuckets group buckets for updates |
| 87 | * @param newAppCookie optional new group key |
| 88 | * @return constructed group store message |
| 89 | */ |
| 90 | public static GroupStoreMessage createGroupUpdateRequestMsg(DeviceId deviceId, |
| 91 | GroupKey appCookie, |
| 92 | UpdateType updateType, |
| 93 | GroupBuckets updateBuckets, |
| 94 | GroupKey newAppCookie) { |
| 95 | return new GroupStoreMessage(Type.UPDATE, |
| 96 | deviceId, |
| 97 | appCookie, |
| 98 | null, |
| 99 | updateType, |
| 100 | updateBuckets, |
| 101 | newAppCookie); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Creates a group store message for group DELETE request. |
| 106 | * |
| 107 | * @param deviceId the device ID |
| 108 | * @param appCookie the group key |
| 109 | * @return constructed group store message |
| 110 | */ |
| 111 | public static GroupStoreMessage createGroupDeleteRequestMsg(DeviceId deviceId, |
| 112 | GroupKey appCookie) { |
| 113 | return new GroupStoreMessage(Type.DELETE, |
| 114 | deviceId, |
| 115 | appCookie, |
| 116 | null, |
| 117 | null, |
| 118 | null, |
| 119 | null); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns the device identifier of this group request. |
| 124 | * |
| 125 | * @return device identifier |
| 126 | */ |
| 127 | public DeviceId deviceId() { |
| 128 | return deviceId; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns the application cookie associated with this group request. |
| 133 | * |
| 134 | * @return application cookie |
| 135 | */ |
| 136 | public GroupKey appCookie() { |
| 137 | return appCookie; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Returns the group create parameters associated with this group request. |
| 142 | * |
| 143 | * @return group create parameters |
| 144 | */ |
| 145 | public GroupDescription groupDesc() { |
| 146 | return groupDesc; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns the group buckets to be updated as part of this group request. |
| 151 | * |
| 152 | * @return group buckets to be updated |
| 153 | */ |
| 154 | public GroupBuckets updateBuckets() { |
| 155 | return updateBuckets; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns the update group operation type. |
| 160 | * |
| 161 | * @return update operation type |
| 162 | */ |
| 163 | public UpdateType updateType() { |
| 164 | return updateType; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Returns the new application cookie associated with this group operation. |
| 169 | * |
| 170 | * @return new application cookie |
| 171 | */ |
| 172 | public GroupKey newAppCookie() { |
| 173 | return newAppCookie; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Returns the type of this group operation. |
| 178 | * |
| 179 | * @return group message type |
| 180 | */ |
| 181 | public Type type() { |
| 182 | return type; |
| 183 | } |
| 184 | } |