Carmelo Cascone | 4fc9e74 | 2017-09-06 21:56:57 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.drivers.p4runtime; |
| 18 | |
| 19 | import org.onosproject.net.DefaultAnnotations; |
| 20 | import org.onosproject.net.LinkKey; |
| 21 | import org.onosproject.net.behaviour.LinkDiscovery; |
| 22 | import org.onosproject.net.config.NetworkConfigService; |
| 23 | import org.onosproject.net.config.basics.BasicLinkConfig; |
| 24 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 25 | import org.onosproject.net.link.DefaultLinkDescription; |
| 26 | import org.onosproject.net.link.LinkDescription; |
| 27 | |
| 28 | import java.util.Set; |
| 29 | import java.util.stream.Collectors; |
| 30 | |
| 31 | /** |
| 32 | * Implementation of the LinkDiscovery behaviour that returns all link available in the network configuration |
| 33 | * subsystem, where this device is the source connect point. |
| 34 | */ |
| 35 | // TODO: remove this behavior as soon we get working Packet I/O on Tofino. |
| 36 | public class NetcfgLinkDiscovery extends AbstractHandlerBehaviour implements LinkDiscovery { |
| 37 | |
| 38 | @Override |
| 39 | public Set<LinkDescription> getLinks() { |
| 40 | final NetworkConfigService configService = this.handler().get(NetworkConfigService.class); |
| 41 | return configService.getSubjects(LinkKey.class) |
| 42 | .stream() |
| 43 | .filter(linkKey -> linkKey.src().deviceId().equals(data().deviceId())) |
| 44 | .map(linkKey -> { |
| 45 | BasicLinkConfig linkConfig = configService.getConfig(linkKey, BasicLinkConfig.class); |
| 46 | return new DefaultLinkDescription(linkKey.src(), linkKey.dst(), |
| 47 | linkConfig.type(), |
| 48 | DefaultLinkDescription.EXPECTED, |
| 49 | DefaultAnnotations.EMPTY); |
| 50 | }) |
| 51 | .collect(Collectors.toSet()); |
| 52 | } |
| 53 | } |