blob: 25af506e18da520f48c766c34d92a5aa8582ddae [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.ApplicationId;
21import org.onosproject.net.DeviceId;
22
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080023/**
24 * Default implementation of group description interface.
25 */
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080026public class DefaultGroupDescription implements GroupDescription {
27 private final GroupDescription.Type type;
28 private final GroupBuckets buckets;
29 private final GroupKey appCookie;
30 private final ApplicationId appId;
31 private final DeviceId deviceId;
32
33 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080034 * Constructor to be used by north bound applications.
35 * NOTE: The caller of this subsystem MUST ensure the appCookie
36 * provided in this API is immutable
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080037 *
38 * @param deviceId device identifier
39 * @param type type of the group
40 * @param buckets immutable list of group bucket
41 * @param appCookie immutable application cookie to be associated with the group
42 * @param appId application id
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080043 */
44 public DefaultGroupDescription(DeviceId deviceId,
45 GroupDescription.Type type,
46 GroupBuckets buckets,
47 GroupKey appCookie,
48 ApplicationId appId) {
49 this.type = checkNotNull(type);
50 this.deviceId = checkNotNull(deviceId);
51 this.buckets = checkNotNull(buckets);
52 this.appCookie = checkNotNull(appCookie);
53 this.appId = checkNotNull(appId);
54 }
55
56 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080057 * Constructor to be used by group subsystem internal components.
58 * Creates group description object from another object of same type.
59 *
60 * @param groupDesc group description object
61 *
62 */
63 public DefaultGroupDescription(GroupDescription groupDesc) {
64 this.type = checkNotNull(groupDesc.type());
65 this.deviceId = checkNotNull(groupDesc.deviceId());
66 this.buckets = checkNotNull(groupDesc.buckets());
67 this.appCookie = checkNotNull(groupDesc.appCookie());
68 this.appId = checkNotNull(groupDesc.appId());
69 }
70
71 /**
72 * Returns type of a group object.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080073 *
74 * @return GroupType group type
75 */
76 @Override
77 public GroupDescription.Type type() {
78 return this.type;
79 }
80
81 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080082 * Returns device identifier on which this group object is created.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080083 *
84 * @return DeviceId device identifier
85 */
86 @Override
87 public DeviceId deviceId() {
88 return this.deviceId;
89 }
90
91 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080092 * Returns application identifier that has created this group object.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080093 *
94 * @return ApplicationId application identifier
95 */
96 @Override
97 public ApplicationId appId() {
98 return this.appId;
99 }
100
101 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800102 * Returns application cookie associated with a group object.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800103 *
104 * @return GroupKey application cookie
105 */
106 @Override
107 public GroupKey appCookie() {
108 return this.appCookie;
109 }
110
111 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800112 * Returns group buckets of a group.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800113 *
114 * @return GroupBuckets immutable list of group bucket
115 */
116 @Override
117 public GroupBuckets buckets() {
118 return this.buckets;
119 }
120
121}