blob: 25af506e18da520f48c766c34d92a5aa8582ddae [file] [log] [blame]
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.group;
import static com.google.common.base.Preconditions.checkNotNull;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
/**
* Default implementation of group description interface.
*/
public class DefaultGroupDescription implements GroupDescription {
private final GroupDescription.Type type;
private final GroupBuckets buckets;
private final GroupKey appCookie;
private final ApplicationId appId;
private final DeviceId deviceId;
/**
* Constructor to be used by north bound applications.
* NOTE: The caller of this subsystem MUST ensure the appCookie
* provided in this API is immutable
*
* @param deviceId device identifier
* @param type type of the group
* @param buckets immutable list of group bucket
* @param appCookie immutable application cookie to be associated with the group
* @param appId application id
*/
public DefaultGroupDescription(DeviceId deviceId,
GroupDescription.Type type,
GroupBuckets buckets,
GroupKey appCookie,
ApplicationId appId) {
this.type = checkNotNull(type);
this.deviceId = checkNotNull(deviceId);
this.buckets = checkNotNull(buckets);
this.appCookie = checkNotNull(appCookie);
this.appId = checkNotNull(appId);
}
/**
* Constructor to be used by group subsystem internal components.
* Creates group description object from another object of same type.
*
* @param groupDesc group description object
*
*/
public DefaultGroupDescription(GroupDescription groupDesc) {
this.type = checkNotNull(groupDesc.type());
this.deviceId = checkNotNull(groupDesc.deviceId());
this.buckets = checkNotNull(groupDesc.buckets());
this.appCookie = checkNotNull(groupDesc.appCookie());
this.appId = checkNotNull(groupDesc.appId());
}
/**
* Returns type of a group object.
*
* @return GroupType group type
*/
@Override
public GroupDescription.Type type() {
return this.type;
}
/**
* Returns device identifier on which this group object is created.
*
* @return DeviceId device identifier
*/
@Override
public DeviceId deviceId() {
return this.deviceId;
}
/**
* Returns application identifier that has created this group object.
*
* @return ApplicationId application identifier
*/
@Override
public ApplicationId appId() {
return this.appId;
}
/**
* Returns application cookie associated with a group object.
*
* @return GroupKey application cookie
*/
@Override
public GroupKey appCookie() {
return this.appCookie;
}
/**
* Returns group buckets of a group.
*
* @return GroupBuckets immutable list of group bucket
*/
@Override
public GroupBuckets buckets() {
return this.buckets;
}
}