Jonathan Hart
Committed by Gerrit Code Review

Add API to look up interface by name

Change-Id: I03fcae92e83f5b804bca21a105d4d1ee8295f2ad
......@@ -39,6 +39,15 @@ public interface InterfaceService
Set<Interface> getInterfaces();
/**
* Returns the interface with the given name.
*
* @param connectPoint connect point of the interface
* @param name name of the interface
* @return interface if it exists, otherwise null
*/
Interface getInterfaceByName(ConnectPoint connectPoint, String name);
/**
* Returns the set of interfaces configured on the given port.
*
* @param port connect point
......
......@@ -102,6 +102,17 @@ public class InterfaceManager extends ListenerRegistry<InterfaceEvent, Interface
}
@Override
public Interface getInterfaceByName(ConnectPoint connectPoint, String name) {
Optional<Interface> intf =
interfaces.getOrDefault(connectPoint, Collections.emptySet())
.stream()
.filter(i -> i.name().equals(name))
.findAny();
return intf.isPresent() ? intf.get() : null;
}
@Override
public Set<Interface> getInterfacesByPort(ConnectPoint port) {
Set<Interface> intfs = interfaces.get(port);
if (intfs == null) {
......