blob: d601aa6e4f12f15a5c87c929b531d190ab7499ea [file] [log] [blame]
yjimmyyb94f93b2016-07-11 16:03:48 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
yjimmyyb94f93b2016-07-11 16:03:48 -07003 *
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 */
16package org.onosproject.drivers.optical;
17
18import com.google.common.annotations.Beta;
yjimmyyb94f93b2016-07-11 16:03:48 -070019import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.link.LinkDescription;
22import org.onosproject.net.link.LinkProvider;
23import org.onosproject.net.link.LinkProviderRegistry;
24import org.onosproject.net.link.LinkProviderService;
25import org.onosproject.net.provider.ProviderId;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070026import org.osgi.service.component.annotations.Activate;
27import org.osgi.service.component.annotations.Component;
28import org.osgi.service.component.annotations.Deactivate;
29import org.osgi.service.component.annotations.Reference;
30import org.osgi.service.component.annotations.ReferenceCardinality;
yjimmyyb94f93b2016-07-11 16:03:48 -070031import org.slf4j.Logger;
32
33import static org.slf4j.LoggerFactory.getLogger;
34
35
36/**
37 * Interface to allow for optical device drivers to add/remove links to
38 * the store. Acts as a proxy to LinkProviderService.
39 *
40 * Registers a dummy LinkProvider to get an instance of LinkProviderService.
41 */
42@Beta
Ray Milkeyd84f89b2018-08-17 14:54:17 -070043@Component(immediate = true, service = OpticalAdjacencyLinkService.class)
yjimmyyb94f93b2016-07-11 16:03:48 -070044public class OpticalAdjacencyLinkManager implements OpticalAdjacencyLinkService {
45
46 private static final ProviderId PID =
47 new ProviderId("of", "org.onosproject.drivers.optical");
48
49 private final Logger log = getLogger(getClass());
50
51 private LinkProvider linkProvider = new StubLinkProvider();
52 private LinkProviderService linkProviderService;
53
Ray Milkeyd84f89b2018-08-17 14:54:17 -070054 @Reference(cardinality = ReferenceCardinality.MANDATORY)
yjimmyyb94f93b2016-07-11 16:03:48 -070055 protected LinkProviderRegistry linkProviderRegistry;
56
57 @Activate
58 public void activate() {
59 linkProviderService = linkProviderRegistry.register(linkProvider);
60 log.info("Started");
61 }
62
63 @Deactivate
64 public void deactivate() {
65 linkProviderRegistry.unregister(linkProvider);
66 log.info("Stopped");
67 }
68
69 /**
70 * Signals that an infrastructure link has been detected.
71 *
72 * @param linkDescription link information
73 */
74 @Override
75 public void linkDetected(LinkDescription linkDescription) {
76 linkProviderService.linkDetected(linkDescription);
77 }
78
79 /**
80 * Signals that an infrastructure link has disappeared.
81 *
82 * @param linkDescription link information
83 */
84 @Override
85 public void linkVanished(LinkDescription linkDescription) {
86 linkProviderService.linkVanished(linkDescription);
87 }
88
89 /**
90 * Signals that infrastructure links associated with the specified
91 * connect point have vanished.
92 *
93 * @param connectPoint connect point
94 */
95 @Override
96 public void linksVanished(ConnectPoint connectPoint) {
97 linkProviderService.linksVanished(connectPoint);
98 }
99
100 /**
101 * Signals that infrastructure links associated with the specified
102 * device have vanished.
103 *
104 * @param deviceId device identifier
105 */
106 @Override
107 public void linksVanished(DeviceId deviceId) {
108 linkProviderService.linksVanished(deviceId);
109 }
110
111 // Stub provider used to get LinkProviderService
112 private static final class StubLinkProvider implements LinkProvider {
113 @Override
114 public ProviderId id() {
115 return PID;
116 }
117 }
118}