Committed by
Gerrit Code Review
Creating an abstract device provider base.
Change-Id: I67b7e18676fba6388c0b317ea84ed7cab041d324
Showing
4 changed files
with
180 additions
and
1 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2014-2016 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 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.net.device; | ||
| 18 | + | ||
| 19 | +import org.onosproject.net.driver.HandlerBehaviour; | ||
| 20 | + | ||
| 21 | +import java.util.List; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Handler behaviour capable of creating device and port descriptions. | ||
| 25 | + * These descriptions should be appropriately annotated to support downstream | ||
| 26 | + * projections of the respective devices and their ports. | ||
| 27 | + */ | ||
| 28 | +public interface DeviceDescriptionDiscovery extends HandlerBehaviour { | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * Returns device description appropriately annotated to support | ||
| 32 | + * downstream model extension via projections of the resulting device, | ||
| 33 | + * as in the following example. | ||
| 34 | + * <pre> | ||
| 35 | + * MicrowaveDevice device = deviceService.get(id).as(MicrowaveDevice.class); | ||
| 36 | + * </pre> | ||
| 37 | + * | ||
| 38 | + * @return annotated device description | ||
| 39 | + */ | ||
| 40 | + DeviceDescription discoverDeviceDetails(); | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Returns list of port descriptions appropriately annotated to support | ||
| 44 | + * downstream model extension via projections of their parent device, | ||
| 45 | + * as in the following example. | ||
| 46 | + * <pre> | ||
| 47 | + * MicrowaveDevice device = deviceService.get(id).as(MicrowaveDevice.class); | ||
| 48 | + * List<MicrowavePort> ports = device.microwavePorts(deviceService.getPorts(id)); | ||
| 49 | + * </pre> | ||
| 50 | + * | ||
| 51 | + * @return annotated device description | ||
| 52 | + */ | ||
| 53 | + List<PortDescription> discoverPortDetails(); | ||
| 54 | + | ||
| 55 | +} |
| ... | @@ -23,7 +23,7 @@ public abstract class AbstractProvider implements Provider { | ... | @@ -23,7 +23,7 @@ public abstract class AbstractProvider implements Provider { |
| 23 | private final ProviderId providerId; | 23 | private final ProviderId providerId; |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | - * Creates a provider with the supplier identifier. | 26 | + * Creates a provider with the supplied identifier. |
| 27 | * | 27 | * |
| 28 | * @param id provider id | 28 | * @param id provider id |
| 29 | */ | 29 | */ | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2014-2016 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 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.common.net; | ||
| 18 | + | ||
| 19 | +import org.apache.felix.scr.annotations.Activate; | ||
| 20 | +import org.apache.felix.scr.annotations.Component; | ||
| 21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 22 | +import org.apache.felix.scr.annotations.Reference; | ||
| 23 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 24 | +import org.onosproject.net.DeviceId; | ||
| 25 | +import org.onosproject.net.device.DeviceDescriptionDiscovery; | ||
| 26 | +import org.onosproject.net.device.DeviceProvider; | ||
| 27 | +import org.onosproject.net.device.DeviceProviderRegistry; | ||
| 28 | +import org.onosproject.net.device.DeviceProviderService; | ||
| 29 | +import org.onosproject.net.driver.DriverHandler; | ||
| 30 | +import org.onosproject.net.driver.DriverService; | ||
| 31 | +import org.onosproject.net.provider.AbstractProvider; | ||
| 32 | +import org.onosproject.net.provider.ProviderId; | ||
| 33 | +import org.slf4j.Logger; | ||
| 34 | +import org.slf4j.LoggerFactory; | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * Base device provider capable of engaging | ||
| 38 | + * {@link org.onosproject.net.device.DeviceDescriptionDiscovery} | ||
| 39 | + * driver behaviour to discover device and port details. | ||
| 40 | + * <p> | ||
| 41 | + * Assumes that derived classes will provide code to learn/generate | ||
| 42 | + * device identifier. Also assumes that derived classes will either obtain | ||
| 43 | + * the primordial device information sufficient to locate the correct driver, | ||
| 44 | + * or that they will know which driver should be used, e.g. from network | ||
| 45 | + * configuration. | ||
| 46 | + * </p> | ||
| 47 | + */ | ||
| 48 | +@Component(immediate = true) | ||
| 49 | +public abstract class AbstractDeviceProvider extends AbstractProvider | ||
| 50 | + implements DeviceProvider { | ||
| 51 | + | ||
| 52 | + protected final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 53 | + | ||
| 54 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 55 | + protected DeviceProviderRegistry providerRegistry; | ||
| 56 | + | ||
| 57 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 58 | + protected DriverService driverService; | ||
| 59 | + | ||
| 60 | + protected DeviceProviderService providerService; | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Creates a provider with the supplied identifier. | ||
| 64 | + * | ||
| 65 | + * @param id provider id | ||
| 66 | + */ | ||
| 67 | + protected AbstractDeviceProvider(ProviderId id) { | ||
| 68 | + super(id); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + @Activate | ||
| 72 | + protected void activate() { | ||
| 73 | + providerService = providerRegistry.register(this); | ||
| 74 | + | ||
| 75 | + log.info("Started"); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Deactivate | ||
| 79 | + protected void deactivate() { | ||
| 80 | + providerRegistry.unregister(this); | ||
| 81 | + providerService = null; | ||
| 82 | + | ||
| 83 | + log.info("Stopped"); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * Discovers the device details using the device discovery behaviour of | ||
| 88 | + * the supplied driver handler context for interacting with a specific | ||
| 89 | + * device. | ||
| 90 | + * | ||
| 91 | + * @param handler driver handler context | ||
| 92 | + */ | ||
| 93 | + protected void discoverDevice(DriverHandler handler) { | ||
| 94 | + DeviceId deviceId = handler.data().deviceId(); | ||
| 95 | + DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class); | ||
| 96 | + providerService.deviceConnected(deviceId, discovery.discoverDeviceDetails()); | ||
| 97 | + providerService.updatePorts(deviceId, discovery.discoverPortDetails()); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + // TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns | ||
| 101 | + // TODO: provide base for port status update | ||
| 102 | + // TODO: integrate with network config for learning about management addresses to probe | ||
| 103 | + | ||
| 104 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014-2016 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 | + */ | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Set of common network core facilities. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.common.net; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment