Thomas Vachuska
Committed by Gerrit Code Review

Creating an abstract device provider base.

Change-Id: I67b7e18676fba6388c0b317ea84ed7cab041d324
/*
* Copyright 2014-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.device;
import org.onosproject.net.driver.HandlerBehaviour;
import java.util.List;
/**
* Handler behaviour capable of creating device and port descriptions.
* These descriptions should be appropriately annotated to support downstream
* projections of the respective devices and their ports.
*/
public interface DeviceDescriptionDiscovery extends HandlerBehaviour {
/**
* Returns device description appropriately annotated to support
* downstream model extension via projections of the resulting device,
* as in the following example.
* <pre>
* MicrowaveDevice device = deviceService.get(id).as(MicrowaveDevice.class);
* </pre>
*
* @return annotated device description
*/
DeviceDescription discoverDeviceDetails();
/**
* Returns list of port descriptions appropriately annotated to support
* downstream model extension via projections of their parent device,
* as in the following example.
* <pre>
* MicrowaveDevice device = deviceService.get(id).as(MicrowaveDevice.class);
* List&lt;MicrowavePort&gt; ports = device.microwavePorts(deviceService.getPorts(id));
* </pre>
*
* @return annotated device description
*/
List<PortDescription> discoverPortDetails();
}
......@@ -23,7 +23,7 @@ public abstract class AbstractProvider implements Provider {
private final ProviderId providerId;
/**
* Creates a provider with the supplier identifier.
* Creates a provider with the supplied identifier.
*
* @param id provider id
*/
......
/*
* Copyright 2014-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.common.net;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceDescriptionDiscovery;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Base device provider capable of engaging
* {@link org.onosproject.net.device.DeviceDescriptionDiscovery}
* driver behaviour to discover device and port details.
* <p>
* Assumes that derived classes will provide code to learn/generate
* device identifier. Also assumes that derived classes will either obtain
* the primordial device information sufficient to locate the correct driver,
* or that they will know which driver should be used, e.g. from network
* configuration.
* </p>
*/
@Component(immediate = true)
public abstract class AbstractDeviceProvider extends AbstractProvider
implements DeviceProvider {
protected final Logger log = LoggerFactory.getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry providerRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DriverService driverService;
protected DeviceProviderService providerService;
/**
* Creates a provider with the supplied identifier.
*
* @param id provider id
*/
protected AbstractDeviceProvider(ProviderId id) {
super(id);
}
@Activate
protected void activate() {
providerService = providerRegistry.register(this);
log.info("Started");
}
@Deactivate
protected void deactivate() {
providerRegistry.unregister(this);
providerService = null;
log.info("Stopped");
}
/**
* Discovers the device details using the device discovery behaviour of
* the supplied driver handler context for interacting with a specific
* device.
*
* @param handler driver handler context
*/
protected void discoverDevice(DriverHandler handler) {
DeviceId deviceId = handler.data().deviceId();
DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class);
providerService.deviceConnected(deviceId, discovery.discoverDeviceDetails());
providerService.updatePorts(deviceId, discovery.discoverPortDetails());
}
// TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns
// TODO: provide base for port status update
// TODO: integrate with network config for learning about management addresses to probe
}
/*
* Copyright 2014-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.
*/
/**
* Set of common network core facilities.
*/
package org.onosproject.common.net;
\ No newline at end of file