Thomas Vachuska | 84922b3 | 2016-02-18 13:52:11 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Thomas Vachuska | 84922b3 | 2016-02-18 13:52:11 -0800 | [diff] [blame] | 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; |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame^] | 25 | import org.onosproject.net.device.DeviceDescription; |
Thomas Vachuska | 84922b3 | 2016-02-18 13:52:11 -0800 | [diff] [blame] | 26 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
| 27 | import org.onosproject.net.device.DeviceProvider; |
| 28 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 29 | import org.onosproject.net.device.DeviceProviderService; |
| 30 | import org.onosproject.net.driver.DriverHandler; |
| 31 | import org.onosproject.net.driver.DriverService; |
| 32 | import org.onosproject.net.provider.AbstractProvider; |
| 33 | import org.onosproject.net.provider.ProviderId; |
| 34 | import org.slf4j.Logger; |
| 35 | import org.slf4j.LoggerFactory; |
| 36 | |
| 37 | /** |
| 38 | * Base device provider capable of engaging |
| 39 | * {@link org.onosproject.net.device.DeviceDescriptionDiscovery} |
| 40 | * driver behaviour to discover device and port details. |
| 41 | * <p> |
| 42 | * Assumes that derived classes will provide code to learn/generate |
| 43 | * device identifier. Also assumes that derived classes will either obtain |
| 44 | * the primordial device information sufficient to locate the correct driver, |
| 45 | * or that they will know which driver should be used, e.g. from network |
| 46 | * configuration. |
| 47 | * </p> |
| 48 | */ |
| 49 | @Component(immediate = true) |
| 50 | public abstract class AbstractDeviceProvider extends AbstractProvider |
| 51 | implements DeviceProvider { |
| 52 | |
| 53 | protected final Logger log = LoggerFactory.getLogger(getClass()); |
| 54 | |
| 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 56 | protected DeviceProviderRegistry providerRegistry; |
| 57 | |
| 58 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 59 | protected DriverService driverService; |
| 60 | |
| 61 | protected DeviceProviderService providerService; |
| 62 | |
| 63 | /** |
| 64 | * Creates a provider with the supplied identifier. |
| 65 | * |
| 66 | * @param id provider id |
| 67 | */ |
| 68 | protected AbstractDeviceProvider(ProviderId id) { |
| 69 | super(id); |
| 70 | } |
| 71 | |
| 72 | @Activate |
| 73 | protected void activate() { |
| 74 | providerService = providerRegistry.register(this); |
| 75 | |
| 76 | log.info("Started"); |
| 77 | } |
| 78 | |
| 79 | @Deactivate |
| 80 | protected void deactivate() { |
| 81 | providerRegistry.unregister(this); |
| 82 | providerService = null; |
| 83 | |
| 84 | log.info("Stopped"); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Discovers the device details using the device discovery behaviour of |
| 89 | * the supplied driver handler context for interacting with a specific |
| 90 | * device. |
| 91 | * |
| 92 | * @param handler driver handler context |
| 93 | */ |
| 94 | protected void discoverDevice(DriverHandler handler) { |
| 95 | DeviceId deviceId = handler.data().deviceId(); |
| 96 | DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class); |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame^] | 97 | DeviceDescription description = discovery.discoverDeviceDetails(); |
| 98 | if (description != null) { |
| 99 | providerService.deviceConnected(deviceId, description); |
| 100 | } else { |
| 101 | log.info("No other description given for device {}", deviceId); |
| 102 | } |
Thomas Vachuska | 84922b3 | 2016-02-18 13:52:11 -0800 | [diff] [blame] | 103 | providerService.updatePorts(deviceId, discovery.discoverPortDetails()); |
Thomas Vachuska | 84922b3 | 2016-02-18 13:52:11 -0800 | [diff] [blame] | 104 | |
Andrea Campanella | 6c71a05 | 2016-04-22 11:56:31 -0700 | [diff] [blame^] | 105 | } |
Thomas Vachuska | 84922b3 | 2016-02-18 13:52:11 -0800 | [diff] [blame] | 106 | // TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns |
| 107 | // TODO: provide base for port status update |
| 108 | // TODO: integrate with network config for learning about management addresses to probe |
| 109 | |
| 110 | } |