Ray Milkey | cd6ab18 | 2016-02-03 11:13:09 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Ray Milkey | cd6ab18 | 2016-02-03 11:13:09 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.net.link; |
| 17 | |
| 18 | import java.util.HashMap; |
| 19 | import java.util.List; |
| 20 | import java.util.Map; |
| 21 | |
| 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.LinkKey; |
| 25 | import org.onosproject.net.provider.AbstractProviderService; |
| 26 | |
| 27 | import com.google.common.collect.Lists; |
| 28 | import com.google.common.collect.Maps; |
| 29 | |
| 30 | public 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 | } |