blob: 0b3093018111dcdc213b84b534bf2ce296eb1f1a [file] [log] [blame]
/*
* Copyright 2017-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.drivers.p4runtime;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.LinkKey;
import org.onosproject.net.behaviour.LinkDiscovery;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.config.basics.BasicLinkConfig;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.link.DefaultLinkDescription;
import org.onosproject.net.link.LinkDescription;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Implementation of the LinkDiscovery behaviour that returns all link available in the network configuration
* subsystem, where this device is the source connect point.
*/
// TODO: remove this behavior as soon we get working Packet I/O on Tofino.
public class NetcfgLinkDiscovery extends AbstractHandlerBehaviour implements LinkDiscovery {
@Override
public Set<LinkDescription> getLinks() {
final NetworkConfigService configService = this.handler().get(NetworkConfigService.class);
return configService.getSubjects(LinkKey.class)
.stream()
.filter(linkKey -> linkKey.src().deviceId().equals(data().deviceId()))
.map(linkKey -> {
BasicLinkConfig linkConfig = configService.getConfig(linkKey, BasicLinkConfig.class);
return new DefaultLinkDescription(linkKey.src(), linkKey.dst(),
linkConfig.type(),
DefaultLinkDescription.EXPECTED,
DefaultAnnotations.EMPTY);
})
.collect(Collectors.toSet());
}
}