Andrea Campanella
Committed by Gerrit Code Review

ONOS-3759 Group default provider

Change-Id: I318c8036a1836d13f57187bfd28464c740e09f08
/*
* Copyright 2016 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 org.onosproject.net.DeviceId;
import org.onosproject.net.driver.HandlerBehaviour;
/**
* Group programmable device behaviour.
*/
public interface GroupProgrammable extends HandlerBehaviour {
/**
* Performs the Group operations for the specified device.
*
* @param deviceId ID of the device
* @param groupOps operations to be performed
*/
void performGroupOperation(DeviceId deviceId, GroupOperations groupOps);
}
/*
* Copyright 2016 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.impl;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.group.GroupOperations;
import org.onosproject.net.group.GroupProgrammable;
import org.onosproject.net.group.GroupProvider;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Driver-based Group rule provider.
*/
public class GroupDriverProvider extends AbstractProvider implements GroupProvider {
private final Logger log = LoggerFactory.getLogger(getClass());
// To be extracted for reuse as we deal with other.
private static final String SCHEME = "default";
private static final String PROVIDER_NAME = "org.onosproject.provider";
protected DeviceService deviceService;
public GroupDriverProvider() {
super(new ProviderId(SCHEME, PROVIDER_NAME));
}
/**
* Initializes the provider with the necessary device service.
*
* @param deviceService device service
*/
void init(DeviceService deviceService) {
this.deviceService = deviceService;
}
@Override
public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
GroupProgrammable programmable = getGroupProgrammable(deviceId);
if (programmable != null) {
programmable.performGroupOperation(deviceId, groupOps);
}
}
private GroupProgrammable getGroupProgrammable(DeviceId deviceId) {
GroupProgrammable programmable = deviceService.getDevice(deviceId).as(GroupProgrammable.class);
if (programmable == null) {
log.warn("Device {} is not group programmable");
}
return programmable;
}
}
......@@ -87,6 +87,7 @@ public class GroupManager
@Property(name = "purgeOnDisconnection", boolValue = false,
label = "Purge entries associated with a device when the device goes offline")
private boolean purgeOnDisconnection = false;
private final GroupDriverProvider defaultProvider = new GroupDriverProvider();
@Activate
public void activate(ComponentContext context) {
......@@ -111,6 +112,12 @@ public class GroupManager
if (context != null) {
readComponentConfiguration(context);
}
defaultProvider.init(deviceService);
}
@Override
protected GroupProvider defaultProvider() {
return defaultProvider;
}
/**
......