@Override public Set<Location> resolve(SpecifierContext ctxt) { return _inner.resolve(ctxt).stream() .map(ToInterfaceLinkLocationSpecifier::toInterfaceLinkLocation) .collect(ImmutableSet.toImmutableSet()); }
@Override public IpSpaceAssignment resolve(Set<Location> key, SpecifierContext ctxt) { Set<Location> locations = _locationSpecifier.resolve(ctxt); checkArgument(!locations.isEmpty(), "No such locations"); IpSpace ipSpace = AclIpSpace.union( InferFromLocationIpSpaceSpecifier.INSTANCE.resolve(locations, ctxt).getEntries() .stream() .map(Entry::getIpSpace) .collect(Collectors.toList())); return IpSpaceAssignment.builder() .assign(key, firstNonNull(ipSpace, EmptyIpSpace.INSTANCE)) .build(); } }
private Set<String> resolveSources(SearchFiltersParameters parameters, String node) { LocationVisitor<String> locationToSource = new LocationVisitor<String>() { @Override public String visitInterfaceLinkLocation(InterfaceLinkLocation interfaceLinkLocation) { return interfaceLinkLocation.getInterfaceName(); } @Override public String visitInterfaceLocation(InterfaceLocation interfaceLocation) { return SOURCE_ORIGINATING_FROM_DEVICE; } }; return parameters.getStartLocationSpecifier().resolve(specifierContext()).stream() .filter(LocationVisitor.onNode(node)::visit) .map(locationToSource::visit) .collect(ImmutableSet.toImmutableSet()); }
/** Generate a set of flows to do traceroute */ @VisibleForTesting Set<Flow> getFlows(String tag) { Set<Location> srcLocations = LocationSpecifierFactory.load(SRC_LOCATION_SPECIFIER_FACTORY) .buildLocationSpecifier(_sourceLocationStr) .resolve(_specifierContext); ImmutableSet.Builder<Flow> setBuilder = ImmutableSet.builder(); ImmutableSet.Builder<String> allProblems = ImmutableSet.builder(); // Perform cross-product of all locations to flows for (Location srcLocation : srcLocations) { try { Flow.Builder flowBuilder = headerConstraintsToFlow(_packetHeaderConstraints, srcLocation); setSourceLocation(flowBuilder, srcLocation); flowBuilder.setTag(tag); setBuilder.add(flowBuilder.build()); } catch (IllegalArgumentException e) { // Try to ignore silently if possible allProblems.add(e.getMessage()); } } Set<Flow> flows = setBuilder.build(); checkArgument( !flows.isEmpty(), "Could not construct a flow for traceroute. Found issues: %s", String.join(",", allProblems.build())); return flows; }
@VisibleForTesting static IpSpaceAssignment initSourceIpAssignment( String sourceLocation, String sourceIps, SpecifierContext specifierContext) { /* construct specifiers */ LocationSpecifier sourceLocationSpecifier = LocationSpecifierFactory.load(SRC_LOCATION_SPECIFIER_FACTORY) .buildLocationSpecifier(sourceLocation); IpSpaceSpecifier sourceIpSpaceSpecifier = IpSpaceSpecifierFactory.load(IP_SPECIFIER_FACTORY).buildIpSpaceSpecifier(sourceIps); /* resolve specifiers */ Set<Location> sourceLocations = sourceLocationSpecifier.resolve(specifierContext); return sourceIpSpaceSpecifier.resolve(sourceLocations, specifierContext); }
@VisibleForTesting static IpSpaceAssignment initSourceIpAssignment( TestFiltersQuestion question, SpecifierContext ctxt) { /* construct specifiers */ LocationSpecifier sourceLocationSpecifier = question.getStartLocationSpecifier(); IpSpaceSpecifier sourceIpSpaceSpecifier = IpSpaceSpecifierFactory.load(IP_SPECIFIER_FACTORY) .buildIpSpaceSpecifier(question.getHeaders().getSrcIps()); /* resolve specifiers */ Set<Location> sourceLocations = sourceLocationSpecifier.resolve(ctxt); return sourceIpSpaceSpecifier.resolve(sourceLocations, ctxt); }
@VisibleForTesting static TableAnswerElement resolveLocation(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata(COL_LOCATION, Schema.STRING, "Location", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); Set<Location> locations = question.getLocationSpecifier().resolve(context); for (Location location : locations) { table.addRow(Row.of(columnMap, COL_LOCATION, location.toString())); } return table; }
@VisibleForTesting IpSpaceAssignment resolveSourceIpSpaceAssignment() throws InvalidReachabilityParametersException { Set<Location> sourceLocations = _params.getSourceLocationSpecifier().resolve(_context).stream() .filter(l -> isActive(l, _configs)) .collect(ImmutableSet.toImmutableSet()); if (sourceLocations.isEmpty()) { throw new InvalidReachabilityParametersException("No matching source locations"); } // resolve the IpSpaceSpecifier, and filter out entries with empty IpSpaces IpSpaceAssignment sourceIpSpaceAssignment = IpSpaceAssignment.of( _params.getSourceIpSpaceSpecifier().resolve(sourceLocations, _context).getEntries() .stream() .filter( entry -> _ipSpaceRepresentative.getRepresentative(entry.getIpSpace()).isPresent()) .collect(ImmutableList.toImmutableList())); if (sourceIpSpaceAssignment.getEntries().isEmpty()) { throw new InvalidReachabilityParametersException("All sources have empty source IpSpaces"); } return sourceIpSpaceAssignment; }
String node = c.getHostname(); Set<Location> srcLocations = question.getStartLocationSpecifier().resolve(_batfish.specifierContext()).stream() .filter(LocationVisitor.onNode(node)::visit) .collect(Collectors.toSet());
@VisibleForTesting static TableAnswerElement resolveIpSpace(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata(COL_IP_SPACE, Schema.STRING, "IP space", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); // this will yield all default locations for the factory Set<Location> locations = question.getLocationSpecifier().resolve(context); IpSpaceAssignment ipSpaceAssignment = question.getIpSpaceSpecifier().resolve(locations, context); for (IpSpaceAssignment.Entry entry : ipSpaceAssignment.getEntries()) { table.addRow(Row.of(columnMap, COL_IP_SPACE, Objects.toString(entry.getIpSpace()))); } return table; }
@VisibleForTesting static TableAnswerElement resolveIpSpaceOfLocation( SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_LOCATIONS, Schema.STRING, "Resolution", false, false), new ColumnMetadata(COL_IP_SPACE, Schema.STRING, "IP space", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); Set<Location> locations = question.getLocationSpecifier().resolve(context); IpSpaceAssignment ipSpaceAssignment = question.getIpSpaceSpecifier().resolve(locations, context); for (IpSpaceAssignment.Entry entry : ipSpaceAssignment.getEntries()) { table.addRow( Row.of( columnMap, COL_LOCATIONS, entry.getLocations().toString(), COL_IP_SPACE, Objects.toString(entry.getIpSpace()))); } return table; }
Set<String> forbiddenTransitNodes = pathConstraints.getForbiddenLocations().resolve(ctxt); Set<String> requiredTransitNodes = pathConstraints.getTransitLocations().resolve(ctxt); Set<Location> startLocations = pathConstraints.getStartLocation().resolve(ctxt); Set<String> finalNodes = pathConstraints.getEndLocation().resolve(ctxt);
Set<String> forbiddenTransitNodes = pathConstraints.getForbiddenLocations().resolve(ctxt); Set<String> requiredTransitNodes = pathConstraints.getTransitLocations().resolve(ctxt); Set<Location> startLocations = pathConstraints.getStartLocation().resolve(ctxt); Set<String> finalNodes = pathConstraints.getEndLocation().resolve(ctxt);