@Test public void testGetMatchingInterface() throws Exception { IpAddress ip = Ip4Address.valueOf("192.168.1.100"); Interface matchingIntf = createInterface(1); assertEquals(matchingIntf, interfaceManager.getMatchingInterface(ip)); ip = Ip4Address.valueOf("1.1.1.1"); assertNull(interfaceManager.getMatchingInterface(ip)); }
@Override public Interface getMatchingInterface(IpAddress ip) { Optional<Interface> match = interfaces.values() .stream() .flatMap(set -> set.stream()) .filter(intf -> intf.ipAddresses() .stream() .anyMatch(intfIp -> intfIp.subnetAddress().contains(ip))) .findFirst(); return match.orElse(null); }
InterfaceManager extends ListenerRegistry<InterfaceEvent, InterfaceListener> implements InterfaceService, InterfaceAdminService { @Override public Interface getMatchingInterface(IpAddress ip) { Optional<Interface> match = interfaces.values() .stream() .flatMap(set -> set.stream()) .filter(intf -> intf.ipAddresses() .stream() .anyMatch(intfIp -> intfIp.subnetAddress().contains(ip))) .findFirst(); return match.orElse(null); } }
InterfaceManager extends ListenerRegistry<InterfaceEvent, InterfaceListener> implements InterfaceService, InterfaceAdminService { @Override public Interface getMatchingInterface(IpAddress ip) { Optional<Interface> match = interfaces.values() .stream() .flatMap(set -> set.stream()) .filter(intf -> intf.ipAddresses() .stream() .anyMatch(intfIp -> intfIp.subnetAddress().contains(ip))) .findFirst(); return match.orElse(null); }  }
InterfaceManager extends ListenerRegistry<InterfaceEvent, InterfaceListener> implements InterfaceService, InterfaceAdminService { @Override public Interface getMatchingInterface(IpAddress ip) { Optional<Interface> match = interfaces.values() .stream() .flatMap(set -> set.stream()) .filter(intf -> intf.ipAddresses() .stream() .anyMatch(intfIp -> intfIp.subnetAddress().contains(ip))) .findFirst(); return match.orElse(null); }  @Activate void activate(); @Deactivate void deactivate(); @Override Set<Interface> getInterfaces(); @Override Interface getInterfaceByName(ConnectPoint connectPoint, String name); @Override Set<Interface> getInterfacesByPort(ConnectPoint port); @Override Set<Interface> getInterfacesByIp(IpAddress ip); @Override Interface getMatchingInterface(IpAddress ip); @Override Set<Interface> getInterfacesByVlan(VlanId vlan); @Override void add(Interface intf); @Override boolean remove(ConnectPoint connectPoint, String name); }
InterfaceManager extends ListenerRegistry<InterfaceEvent, InterfaceListener> implements InterfaceService, InterfaceAdminService { @Override public Interface getMatchingInterface(IpAddress ip) { Optional<Interface> match = interfaces.values() .stream() .flatMap(set -> set.stream()) .filter(intf -> intf.ipAddresses() .stream() .anyMatch(intfIp -> intfIp.subnetAddress().contains(ip))) .findFirst(); return match.orElse(null); }  @Activate void activate(); @Deactivate void deactivate(); @Override Set<Interface> getInterfaces(); @Override Interface getInterfaceByName(ConnectPoint connectPoint, String name); @Override Set<Interface> getInterfacesByPort(ConnectPoint port); @Override Set<Interface> getInterfacesByIp(IpAddress ip); @Override Interface getMatchingInterface(IpAddress ip); @Override Set<Interface> getInterfacesByVlan(VlanId vlan); @Override void add(Interface intf); @Override boolean remove(ConnectPoint connectPoint, String name);  }