blob: 9d7e35a547dc487be245467bc827ac8d18ede324 [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;
25import 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 */
48@Component(immediate = true)
49public 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}