@Test public void testGetFlows() { NetworkFactory nf = new NetworkFactory(); Configuration config = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build(); Vrf vrf = nf.vrfBuilder().build(); Interface.Builder ifaceBuilder = nf.interfaceBuilder().setOwner(config).setVrf(vrf); Interface activeIface = ifaceBuilder.setActive(true).build(); Interface inactiveIface = ifaceBuilder.setActive(false).build(); SortedMap<String, Configuration> configs = ImmutableSortedMap.of(config.getHostname(), config); IBatfish batfish = new IBatfishTestAdapter() { @Override public SortedMap<String, Configuration> loadConfigurations(NetworkSnapshot snapshot) { return configs; } @Override public Map<Location, LocationInfo> getLocationInfo(NetworkSnapshot networkSnapshot) { return ImmutableMap.of(); } }; SpecifierContextImpl ctxt = new SpecifierContextImpl( batfish, new NetworkSnapshot(new NetworkId("network"), new SnapshotId("snapshot"))); PacketHeaderConstraints headerConstraints = PacketHeaderConstraints.builder().setSrcIp("1.1.1.1").setDstIp("2.2.2.2").build(); String sourceLocationStr = "enter(/.*/)"; Set<Location> specifiedLocations = SpecifierFactories.getLocationSpecifierOrDefault( sourceLocationStr, AllInterfacesLocationSpecifier.INSTANCE) .resolve(ctxt); assertThat( specifiedLocations, containsInAnyOrder( new InterfaceLinkLocation(config.getHostname(), activeIface.getName()), new InterfaceLinkLocation(config.getHostname(), inactiveIface.getName()))); TracerouteAnswererHelper helper = new TracerouteAnswererHelper(headerConstraints, sourceLocationStr, ctxt); Set<Flow> flows = helper.getFlows(); assertThat( flows, contains( allOf( hasIngressNode(config.getHostname()), hasIngressInterface(activeIface.getName())))); }
@VisibleForTesting Set<Flow> getFlows() { Set<Location> srcLocations = SpecifierFactories.getLocationSpecifierOrDefault( _sourceLocationStr, AllInterfacesLocationSpecifier.INSTANCE) .resolve(_specifierContext).stream() .filter(_isActiveLocation::visit) .collect(Collectors.toSet()); checkArgument( !srcLocations.isEmpty(), "Found no active locations matching %s", _sourceLocationStr); ImmutableSet.Builder<Flow> setBuilder = ImmutableSet.builder(); ImmutableSet.Builder<String> allProblems = ImmutableSet.builder(); for (Location srcLocation : srcLocations) { try { Flow.Builder flowBuilder = _flowBuilder; setSrcIp(_packetHeaderConstraints, srcLocation, flowBuilder); setStartLocation(_specifierContext.getConfigs(), flowBuilder, srcLocation); setBuilder.add(flowBuilder.build()); } catch (IllegalArgumentException e) { 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; }
TracerouteAnswererHelper { @VisibleForTesting Set<Flow> getFlows() { Set<Location> srcLocations = SpecifierFactories.getLocationSpecifierOrDefault( _sourceLocationStr, AllInterfacesLocationSpecifier.INSTANCE) .resolve(_specifierContext).stream() .filter(_isActiveLocation::visit) .collect(Collectors.toSet()); checkArgument( !srcLocations.isEmpty(), "Found no active locations matching %s", _sourceLocationStr); ImmutableSet.Builder<Flow> setBuilder = ImmutableSet.builder(); ImmutableSet.Builder<String> allProblems = ImmutableSet.builder(); for (Location srcLocation : srcLocations) { try { Flow.Builder flowBuilder = _flowBuilder; setSrcIp(_packetHeaderConstraints, srcLocation, flowBuilder); setStartLocation(_specifierContext.getConfigs(), flowBuilder, srcLocation); setBuilder.add(flowBuilder.build()); } catch (IllegalArgumentException e) { 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; } }
TracerouteAnswererHelper { @VisibleForTesting Set<Flow> getFlows() { Set<Location> srcLocations = SpecifierFactories.getLocationSpecifierOrDefault( _sourceLocationStr, AllInterfacesLocationSpecifier.INSTANCE) .resolve(_specifierContext).stream() .filter(_isActiveLocation::visit) .collect(Collectors.toSet()); checkArgument( !srcLocations.isEmpty(), "Found no active locations matching %s", _sourceLocationStr); ImmutableSet.Builder<Flow> setBuilder = ImmutableSet.builder(); ImmutableSet.Builder<String> allProblems = ImmutableSet.builder(); for (Location srcLocation : srcLocations) { try { Flow.Builder flowBuilder = _flowBuilder; setSrcIp(_packetHeaderConstraints, srcLocation, flowBuilder); setStartLocation(_specifierContext.getConfigs(), flowBuilder, srcLocation); setBuilder.add(flowBuilder.build()); } catch (IllegalArgumentException e) { 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; } TracerouteAnswererHelper(
      PacketHeaderConstraints packetHeaderConstraints,
      String sourceLocationStr,
      SpecifierContext specifierContext); }
TracerouteAnswererHelper { @VisibleForTesting Set<Flow> getFlows() { Set<Location> srcLocations = SpecifierFactories.getLocationSpecifierOrDefault( _sourceLocationStr, AllInterfacesLocationSpecifier.INSTANCE) .resolve(_specifierContext).stream() .filter(_isActiveLocation::visit) .collect(Collectors.toSet()); checkArgument( !srcLocations.isEmpty(), "Found no active locations matching %s", _sourceLocationStr); ImmutableSet.Builder<Flow> setBuilder = ImmutableSet.builder(); ImmutableSet.Builder<String> allProblems = ImmutableSet.builder(); for (Location srcLocation : srcLocations) { try { Flow.Builder flowBuilder = _flowBuilder; setSrcIp(_packetHeaderConstraints, srcLocation, flowBuilder); setStartLocation(_specifierContext.getConfigs(), flowBuilder, srcLocation); setBuilder.add(flowBuilder.build()); } catch (IllegalArgumentException e) { 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; } TracerouteAnswererHelper(
      PacketHeaderConstraints packetHeaderConstraints,
      String sourceLocationStr,
      SpecifierContext specifierContext);  }
TracerouteAnswererHelper { @VisibleForTesting Set<Flow> getFlows() { Set<Location> srcLocations = SpecifierFactories.getLocationSpecifierOrDefault( _sourceLocationStr, AllInterfacesLocationSpecifier.INSTANCE) .resolve(_specifierContext).stream() .filter(_isActiveLocation::visit) .collect(Collectors.toSet()); checkArgument( !srcLocations.isEmpty(), "Found no active locations matching %s", _sourceLocationStr); ImmutableSet.Builder<Flow> setBuilder = ImmutableSet.builder(); ImmutableSet.Builder<String> allProblems = ImmutableSet.builder(); for (Location srcLocation : srcLocations) { try { Flow.Builder flowBuilder = _flowBuilder; setSrcIp(_packetHeaderConstraints, srcLocation, flowBuilder); setStartLocation(_specifierContext.getConfigs(), flowBuilder, srcLocation); setBuilder.add(flowBuilder.build()); } catch (IllegalArgumentException e) { 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; } TracerouteAnswererHelper(
      PacketHeaderConstraints packetHeaderConstraints,
      String sourceLocationStr,
      SpecifierContext specifierContext);   }