blob: 856062544b4748982c95206a8726dfc30d3495c5 [file] [log] [blame]
Thomas Vachuska84922b32016-02-18 13:52:11 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
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
19import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.onosproject.net.DeviceId;
Andrea Campanella6c71a052016-04-22 11:56:31 -070025import org.onosproject.net.device.DeviceDescription;
Thomas Vachuska84922b32016-02-18 13:52:11 -080026import org.onosproject.net.device.DeviceDescriptionDiscovery;
27import org.onosproject.net.device.DeviceProvider;
28import org.onosproject.net.device.DeviceProviderRegistry;
29import org.onosproject.net.device.DeviceProviderService;
30import org.onosproject.net.driver.DriverHandler;
31import org.onosproject.net.driver.DriverService;
32import org.onosproject.net.provider.AbstractProvider;
33import org.onosproject.net.provider.ProviderId;
34import org.slf4j.Logger;
35import 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)
50public 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 Campanella6c71a052016-04-22 11:56:31 -070097 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 Vachuska84922b32016-02-18 13:52:11 -0800103 providerService.updatePorts(deviceId, discovery.discoverPortDetails());
Thomas Vachuska84922b32016-02-18 13:52:11 -0800104
Andrea Campanella6c71a052016-04-22 11:56:31 -0700105 }
Thomas Vachuska84922b32016-02-18 13:52:11 -0800106 // 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}