blob: 0b3093018111dcdc213b84b534bf2ce296eb1f1a [file] [log] [blame]
Carmelo Cascone4fc9e742017-09-06 21:56:57 +02001/*
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
17package org.onosproject.drivers.p4runtime;
18
19import org.onosproject.net.DefaultAnnotations;
20import org.onosproject.net.LinkKey;
21import org.onosproject.net.behaviour.LinkDiscovery;
22import org.onosproject.net.config.NetworkConfigService;
23import org.onosproject.net.config.basics.BasicLinkConfig;
24import org.onosproject.net.driver.AbstractHandlerBehaviour;
25import org.onosproject.net.link.DefaultLinkDescription;
26import org.onosproject.net.link.LinkDescription;
27
28import java.util.Set;
29import 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.
36public 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}