blob: 8b3cae4fbb798f7dd7935cdee0deca82b530e1b5 [file] [log] [blame]
Thomas Vachuska84922b32016-02-18 13:52:11 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuska84922b32016-02-18 13:52:11 -08003 *
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
17package org.onosproject.common.net;
18
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.osgi.service.component.annotations.Activate;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070020import org.osgi.service.component.annotations.Deactivate;
21import org.osgi.service.component.annotations.Reference;
22import org.osgi.service.component.annotations.ReferenceCardinality;
Thomas Vachuska84922b32016-02-18 13:52:11 -080023import org.onosproject.net.DeviceId;
Andrea Campanella6c71a052016-04-22 11:56:31 -070024import org.onosproject.net.device.DeviceDescription;
Thomas Vachuska84922b32016-02-18 13:52:11 -080025import org.onosproject.net.device.DeviceDescriptionDiscovery;
26import org.onosproject.net.device.DeviceProvider;
27import org.onosproject.net.device.DeviceProviderRegistry;
28import org.onosproject.net.device.DeviceProviderService;
29import org.onosproject.net.driver.DriverHandler;
30import org.onosproject.net.driver.DriverService;
31import org.onosproject.net.provider.AbstractProvider;
32import org.onosproject.net.provider.ProviderId;
33import org.slf4j.Logger;
34import 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 */
Thomas Vachuska84922b32016-02-18 13:52:11 -080048public abstract class AbstractDeviceProvider extends AbstractProvider
49 implements DeviceProvider {
50
51 protected final Logger log = LoggerFactory.getLogger(getClass());
52
Ray Milkeyd84f89b2018-08-17 14:54:17 -070053 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuska84922b32016-02-18 13:52:11 -080054 protected DeviceProviderRegistry providerRegistry;
55
Ray Milkeyd84f89b2018-08-17 14:54:17 -070056 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuska84922b32016-02-18 13:52:11 -080057 protected DriverService driverService;
58
59 protected DeviceProviderService providerService;
60
61 /**
62 * Creates a provider with the supplied identifier.
63 *
64 * @param id provider id
65 */
66 protected AbstractDeviceProvider(ProviderId id) {
67 super(id);
68 }
69
70 @Activate
71 protected void activate() {
72 providerService = providerRegistry.register(this);
73
74 log.info("Started");
75 }
76
77 @Deactivate
78 protected void deactivate() {
79 providerRegistry.unregister(this);
80 providerService = null;
81
82 log.info("Stopped");
83 }
84
85 /**
86 * Discovers the device details using the device discovery behaviour of
87 * the supplied driver handler context for interacting with a specific
88 * device.
89 *
90 * @param handler driver handler context
91 */
92 protected void discoverDevice(DriverHandler handler) {
93 DeviceId deviceId = handler.data().deviceId();
94 DeviceDescriptionDiscovery discovery = handler.behaviour(DeviceDescriptionDiscovery.class);
Andrea Campanella6c71a052016-04-22 11:56:31 -070095 DeviceDescription description = discovery.discoverDeviceDetails();
96 if (description != null) {
97 providerService.deviceConnected(deviceId, description);
98 } else {
99 log.info("No other description given for device {}", deviceId);
100 }
Thomas Vachuska84922b32016-02-18 13:52:11 -0800101 providerService.updatePorts(deviceId, discovery.discoverPortDetails());
Thomas Vachuska84922b32016-02-18 13:52:11 -0800102
Andrea Campanella6c71a052016-04-22 11:56:31 -0700103 }
Thomas Vachuska84922b32016-02-18 13:52:11 -0800104 // TODO: inspect NETCONF, SNMP, RESTSB device providers for additional common patterns
105 // TODO: provide base for port status update
106 // TODO: integrate with network config for learning about management addresses to probe
107
108}