@Override public Set<IpAccessList> resolve(String node, SpecifierContext ctxt) { checkArgument( ctxt.getConfigs().containsKey(node), "SpecifierContext does not have configs for node " + node); Configuration config = ctxt.getConfigs().get(node); FilterGroup filterGroup = ctxt.getReferenceBook(_bookName) .orElseThrow( () -> new NoSuchElementException("ReferenceBook '" + _bookName + "' not found")) .getFilterGroup(_filterGroupName) .orElseThrow( () -> new NoSuchElementException( "FilterGroup '" + _filterGroupName + "' not found in ReferenceBook '" + _bookName + "'")); return config.getIpAccessLists().values().stream() .filter( filter -> filterGroup.getFilters().stream() .anyMatch(specifier -> specifier.matches(filter, config))) .collect(Collectors.toSet()); } }
@Override public Set<Interface> resolve(Set<String> nodes, SpecifierContext ctxt) { InterfaceGroup interfaceGroup = ctxt.getReferenceBook(_bookName) .orElseThrow( () -> new NoSuchElementException("ReferenceBook '" + _bookName + "' not found")) .getInterfaceGroup(_interfaceGroupName) .orElseThrow( () -> new NoSuchElementException( "InterfaceGroup '" + _interfaceGroupName + "' not found in ReferenceBook '" + _bookName + "'")); return nodes.stream() .map(n -> ctxt.getConfigs().get(n).getAllInterfaces().values()) .flatMap(Collection::stream) // we have a stream of Interfaces now .filter( v -> interfaceGroup .getInterfaces() .contains(new NodeInterfacePair(v.getOwner().getHostname(), v.getName()))) .collect(Collectors.toSet()); } }
@Override public IpSpaceAssignment resolve(Set<Location> locations, SpecifierContext ctxt) { AddressGroup addressGroup = ctxt.getReferenceBook(_bookName) .orElseThrow( () -> new NoSuchElementException("ReferenceBook '" + _bookName + "' not found")) .getAddressGroup(_addressGroupName) .orElseThrow( () -> new NoSuchElementException( "AddressGroup '" + _addressGroupName + "' not found in ReferenceBook '" + _bookName + "'")); return IpSpaceAssignment.builder() .assign( locations, firstNonNull( AclIpSpace.union( addressGroup.getAddresses().stream() .map(add -> new IpWildcard(add).toIpSpace()) .collect(Collectors.toList())), EmptyIpSpace.INSTANCE)) .build(); } }