blob: 142efff66804aeac5c70776af54acb01aeaeedbd [file] [log] [blame]
Ray Milkeycd6ab182016-02-03 11:13:09 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Ray Milkeycd6ab182016-02-03 11:13:09 -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 */
16package org.onosproject.net.link;
17
18import java.util.HashMap;
19import java.util.List;
20import java.util.Map;
21
22import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.LinkKey;
25import org.onosproject.net.provider.AbstractProviderService;
26
27import com.google.common.collect.Lists;
28import com.google.common.collect.Maps;
29
30public class LinkProviderServiceAdapter
31 extends AbstractProviderService<LinkProvider>
32 implements LinkProviderService {
33
34 List<DeviceId> vanishedDpid = Lists.newLinkedList();
35 List<Long> vanishedPort = Lists.newLinkedList();
36 Map<DeviceId, DeviceId> discoveredLinks = Maps.newHashMap();
37 Map<LinkKey, LinkDescription> discoveredLinkDescriptions = new HashMap<>();
38
39 protected LinkProviderServiceAdapter(LinkProvider provider) {
40 super(provider);
41 }
42
43 @Override
44 public void linkDetected(LinkDescription linkDescription) {
45 LinkKey key = LinkKey.linkKey(linkDescription.src(), linkDescription.dst());
46 discoveredLinkDescriptions.put(key, linkDescription);
47 DeviceId sDid = linkDescription.src().deviceId();
48 DeviceId dDid = linkDescription.dst().deviceId();
49 discoveredLinks.put(sDid, dDid);
50 }
51
52 @Override
53 public void linkVanished(LinkDescription linkDescription) {
54 LinkKey key = LinkKey.linkKey(linkDescription.src(), linkDescription.dst());
55 discoveredLinkDescriptions.remove(key);
56 }
57
58 @Override
59 public void linksVanished(ConnectPoint connectPoint) {
60 vanishedPort.add(connectPoint.port().toLong());
61
62 }
63
64 @Override
65 public void linksVanished(DeviceId deviceId) {
66 vanishedDpid.add(deviceId);
67 }
68
69 public List<DeviceId> vanishedDpid() {
70 return vanishedDpid;
71 }
72
73 public List<Long> vanishedPort() {
74 return vanishedPort;
75 }
76
77 public Map<DeviceId, DeviceId> discoveredLinks() {
78 return discoveredLinks;
79 }
80
81 public Map<LinkKey, LinkDescription> discoveredLinkDescriptions() {
82 return discoveredLinkDescriptions;
83 }
84}