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