blob: 8d374c1b985907838d2c01c6ed3e0c17d5c3ecdf [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
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080020import java.util.Objects;
21
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.DeviceId;
24
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080025/**
26 * Default implementation of group description interface.
27 */
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080028public class DefaultGroupDescription implements GroupDescription {
29 private final GroupDescription.Type type;
30 private final GroupBuckets buckets;
31 private final GroupKey appCookie;
32 private final ApplicationId appId;
33 private final DeviceId deviceId;
34
35 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080036 * Constructor to be used by north bound applications.
37 * NOTE: The caller of this subsystem MUST ensure the appCookie
38 * provided in this API is immutable
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080039 *
40 * @param deviceId device identifier
41 * @param type type of the group
42 * @param buckets immutable list of group bucket
43 * @param appCookie immutable application cookie to be associated with the group
44 * @param appId application id
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080045 */
46 public DefaultGroupDescription(DeviceId deviceId,
47 GroupDescription.Type type,
48 GroupBuckets buckets,
49 GroupKey appCookie,
50 ApplicationId appId) {
51 this.type = checkNotNull(type);
52 this.deviceId = checkNotNull(deviceId);
53 this.buckets = checkNotNull(buckets);
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080054 this.appCookie = appCookie;
55 this.appId = appId;
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080056 }
57
58 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080059 * Constructor to be used by group subsystem internal components.
60 * Creates group description object from another object of same type.
61 *
62 * @param groupDesc group description object
63 *
64 */
65 public DefaultGroupDescription(GroupDescription groupDesc) {
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -080066 this.type = groupDesc.type();
67 this.deviceId = groupDesc.deviceId();
68 this.buckets = groupDesc.buckets();
69 this.appCookie = groupDesc.appCookie();
70 this.appId = groupDesc.appId();
71 }
72
73 /**
74 * Constructor to be used by group subsystem internal components.
75 * Creates group description object from the information retrieved
76 * from data plane.
77 *
78 * @param deviceId device identifier
79 * @param type type of the group
80 * @param buckets immutable list of group bucket
81 *
82 */
83 public DefaultGroupDescription(DeviceId deviceId,
84 GroupDescription.Type type,
85 GroupBuckets buckets) {
86 this(deviceId, type, buckets, null, null);
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -080087 }
88
89 /**
90 * Returns type of a group object.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -080091 *
92 * @return GroupType group type
93 */
94 @Override
95 public GroupDescription.Type type() {
96 return this.type;
97 }
98
99 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800100 * Returns device identifier on which this group object is created.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800101 *
102 * @return DeviceId device identifier
103 */
104 @Override
105 public DeviceId deviceId() {
106 return this.deviceId;
107 }
108
109 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800110 * Returns application identifier that has created this group object.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800111 *
112 * @return ApplicationId application identifier
113 */
114 @Override
115 public ApplicationId appId() {
116 return this.appId;
117 }
118
119 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800120 * Returns application cookie associated with a group object.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800121 *
122 * @return GroupKey application cookie
123 */
124 @Override
125 public GroupKey appCookie() {
126 return this.appCookie;
127 }
128
129 /**
Srikanth Vavilapalli0599d512015-01-30 12:57:56 -0800130 * Returns group buckets of a group.
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800131 *
132 * @return GroupBuckets immutable list of group bucket
133 */
134 @Override
135 public GroupBuckets buckets() {
136 return this.buckets;
137 }
138
Srikanth Vavilapalli45c27c82015-01-30 12:57:56 -0800139 @Override
140 /*
141 * The deviceId, type and buckets are used for hash.
142 *
143 * (non-Javadoc)
144 * @see java.lang.Object#equals(java.lang.Object)
145 */
146 public int hashCode() {
147 return Objects.hash(deviceId, type, buckets);
148 }
149
150 @Override
151 /*
152 * The deviceId, type and buckets should be same.
153 *
154 * (non-Javadoc)
155 * @see java.lang.Object#equals(java.lang.Object)
156 */
157 public boolean equals(Object obj) {
158 if (this == obj) {
159 return true;
160 }
161 if (obj instanceof DefaultGroupDescription) {
162 DefaultGroupDescription that = (DefaultGroupDescription) obj;
163 return Objects.equals(deviceId, that.deviceId) &&
164 Objects.equals(type, that.type) &&
165 Objects.equals(buckets, that.buckets);
166
167 }
168 return false;
169 }
170
Srikanth Vavilapalli56db94f2015-01-22 22:30:17 -0800171}