blob: 6551f36391b64d6b5ac0464af959b34903ef879e [file] [log] [blame]
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -07003 *
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.store.group.impl;
17
18import org.onosproject.net.DeviceId;
19import org.onosproject.net.group.GroupBuckets;
20import org.onosproject.net.group.GroupDescription;
21import org.onosproject.net.group.GroupKey;
22import 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 */
28public 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,
helenyrwua1c41152016-08-18 16:16:14 -070043 DELETE,
44 FAILOVER
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -070045 }
46
47 private GroupStoreMessage(Type type,
48 DeviceId deviceId,
49 GroupKey appCookie,
50 GroupDescription groupDesc,
51 UpdateType updateType,
52 GroupBuckets updateBuckets,
53 GroupKey newAppCookie) {
54 this.type = type;
55 this.deviceId = deviceId;
56 this.appCookie = appCookie;
57 this.groupDesc = groupDesc;
58 this.updateType = updateType;
59 this.updateBuckets = updateBuckets;
60 this.newAppCookie = newAppCookie;
61 }
62
63 /**
64 * Creates a group store message for group ADD request.
65 *
66 * @param deviceId device identifier in which group to be added
67 * @param desc group creation parameters
68 * @return constructed group store message
69 */
70 public static GroupStoreMessage createGroupAddRequestMsg(DeviceId deviceId,
71 GroupDescription desc) {
72 return new GroupStoreMessage(Type.ADD,
73 deviceId,
74 null,
75 desc,
76 null,
77 null,
78 null);
79 }
80
81 /**
82 * Creates a group store message for group UPDATE request.
83 *
84 * @param deviceId the device ID
85 * @param appCookie the current group key
86 * @param updateType update (add or delete) type
87 * @param updateBuckets group buckets for updates
88 * @param newAppCookie optional new group key
89 * @return constructed group store message
90 */
91 public static GroupStoreMessage createGroupUpdateRequestMsg(DeviceId deviceId,
92 GroupKey appCookie,
93 UpdateType updateType,
94 GroupBuckets updateBuckets,
95 GroupKey newAppCookie) {
96 return new GroupStoreMessage(Type.UPDATE,
97 deviceId,
98 appCookie,
99 null,
100 updateType,
101 updateBuckets,
102 newAppCookie);
103 }
104
105 /**
106 * Creates a group store message for group DELETE request.
107 *
108 * @param deviceId the device ID
109 * @param appCookie the group key
110 * @return constructed group store message
111 */
112 public static GroupStoreMessage createGroupDeleteRequestMsg(DeviceId deviceId,
113 GroupKey appCookie) {
114 return new GroupStoreMessage(Type.DELETE,
115 deviceId,
116 appCookie,
117 null,
118 null,
119 null,
120 null);
121 }
122
helenyrwua1c41152016-08-18 16:16:14 -0700123 public static GroupStoreMessage createGroupFailoverMsg(DeviceId deviceId,
124 GroupDescription desc) {
125 return new GroupStoreMessage(Type.FAILOVER,
126 deviceId,
127 desc.appCookie(),
128 desc,
129 null,
130 null,
131 desc.appCookie());
132 }
133
134
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700135 /**
136 * Returns the device identifier of this group request.
137 *
138 * @return device identifier
139 */
140 public DeviceId deviceId() {
141 return deviceId;
142 }
143
144 /**
145 * Returns the application cookie associated with this group request.
146 *
147 * @return application cookie
148 */
149 public GroupKey appCookie() {
150 return appCookie;
151 }
152
153 /**
154 * Returns the group create parameters associated with this group request.
155 *
156 * @return group create parameters
157 */
158 public GroupDescription groupDesc() {
159 return groupDesc;
160 }
161
162 /**
163 * Returns the group buckets to be updated as part of this group request.
164 *
165 * @return group buckets to be updated
166 */
167 public GroupBuckets updateBuckets() {
168 return updateBuckets;
169 }
170
171 /**
172 * Returns the update group operation type.
173 *
174 * @return update operation type
175 */
176 public UpdateType updateType() {
177 return updateType;
178 }
179
180 /**
181 * Returns the new application cookie associated with this group operation.
182 *
183 * @return new application cookie
184 */
185 public GroupKey newAppCookie() {
186 return newAppCookie;
187 }
188
189 /**
190 * Returns the type of this group operation.
191 *
192 * @return group message type
193 */
194 public Type type() {
195 return type;
196 }
197}