Java Code Examples for com.google.common.collect.ImmutableSortedMap#of()

The following examples show how to use com.google.common.collect.ImmutableSortedMap#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrcWriteValidation.java    From presto with Apache License 2.0 6 votes vote down vote up
public RowGroupStatistics(OrcWriteValidationMode validationMode, Map<OrcColumnId, ColumnStatistics> columnStatistics)
{
    this.validationMode = validationMode;

    requireNonNull(columnStatistics, "columnStatistics is null");
    if (validationMode == HASHED) {
        this.columnStatistics = ImmutableSortedMap.of();
        hash = hashColumnStatistics(ImmutableSortedMap.copyOf(columnStatistics));
    }
    else if (validationMode == DETAILED) {
        this.columnStatistics = ImmutableSortedMap.copyOf(columnStatistics);
        hash = 0;
    }
    else if (validationMode == BOTH) {
        this.columnStatistics = ImmutableSortedMap.copyOf(columnStatistics);
        hash = hashColumnStatistics(this.columnStatistics);
    }
    else {
        throw new IllegalArgumentException("Unsupported validation mode");
    }
}
 
Example 2
Source File: BatfishBDDDifferentialReachabilityTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Override
public SortedMap<String, Configuration> generateConfigs(boolean delta) {
  Configuration node1 = _cb.setHostname(NODE1).build();
  Vrf v1 = _vb.setOwner(node1).build();
  _ib.setOwner(node1).setVrf(v1);
  _ib.setName(PHYSICAL).setAddresses(NODE1_PHYSICAL_NETWORK).build();
  if (!delta) {
    v1.setStaticRoutes(
        ImmutableSortedSet.of(
            StaticRoute.builder()
                .setNetwork(DST_IP.toPrefix())
                .setNextHopInterface(PHYSICAL)
                .setAdministrativeCost(1)
                .build()));
  }

  Configuration node2 = _cb.setHostname(NODE2).build();
  Vrf v2 = _vb.setOwner(node2).build();
  _ib.setOwner(node2).setVrf(v2);
  _ib.setName(PHYSICAL)
      .setAddresses(NODE2_PHYSICAL_NETWORK, ConcreteInterfaceAddress.create(DST_IP, 32))
      .build();

  return ImmutableSortedMap.of(NODE1, node1, NODE2, node2);
}
 
Example 3
Source File: FileBasedStorage.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Map<String, VendorConfiguration> loadVendorConfigurations(NetworkSnapshot snapshot)
    throws IOException {
  _logger.info("\n*** DESERIALIZING VENDOR CONFIGURATION STRUCTURES ***\n");
  _logger.resetTimer();
  Map<Path, String> namesByPath = new TreeMap<>();
  Path serializedVendorConfigPath = getVendorConfigurationsPath(snapshot);
  if (!Files.exists(serializedVendorConfigPath)) {
    return ImmutableSortedMap.of();
  }
  try (DirectoryStream<Path> serializedConfigs =
      Files.newDirectoryStream(serializedVendorConfigPath)) {
    for (Path serializedConfig : serializedConfigs) {
      String name = serializedConfig.getFileName().toString();
      namesByPath.put(serializedConfig, name);
    }
  } catch (IOException e) {
    throw new BatfishException("Error reading vendor configs directory", e);
  }
  Map<String, VendorConfiguration> vendorConfigurations =
      deserializeObjects(namesByPath, VendorConfiguration.class);
  _logger.printElapsedTime();
  return vendorConfigurations;
}
 
Example 4
Source File: CommandAliasDescriptionTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void supportsEnvWithExeMacro() {
  ImmutableMap<String, StringWithMacros> env =
      ImmutableSortedMap.of(
          "apples",
          StringWithMacrosUtils.format("some"),
          "pears",
          StringWithMacrosUtils.format(
              "%s",
              ExecutableMacro.of(
                  BuildTargetWithOutputs.of(macroTarget, OutputLabel.defaultLabel()))));

  CommandAliasBuilder.BuildResult result =
      builder()
          .setExe(new ShBinaryBuilder(delegate).setMain(FakeSourcePath.of("sh/binary")).build())
          .setEnv(env)
          .addTarget(new ShBinaryBuilder(macroTarget).setMain(FakeSourcePath.of("exe")).build())
          .buildResult();

  assertThat(
      result.getEnvironment(),
      equalTo(ImmutableSortedMap.of("apples", "some", "pears", result.pathOf(macroTarget))));
  assertThat(result.getRuntimeDeps(), hasItem(macroTarget));
}
 
Example 5
Source File: BatfishBDDDifferentialReachabilityTest.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Override
public SortedMap<String, Configuration> generateConfigs(boolean delta) {
  Configuration node1 = _cb.setHostname(NODE1).build();
  Vrf v1 = _vb.setOwner(node1).build();
  _ib.setOwner(node1).setVrf(v1);
  _ib.setName(PHYSICAL).setAddresses(NODE1_PHYSICAL_NETWORK).build();
  _ib = _nf.interfaceBuilder();

  if (delta) {
    v1.setStaticRoutes(
        ImmutableSortedSet.of(
            StaticRoute.builder()
                .setNetwork(DST_IP.toPrefix())
                .setNextHopInterface(PHYSICAL)
                .setAdministrativeCost(1)
                .build()));
  }

  Configuration node2 = _cb.setHostname(NODE2).build();
  Vrf v2 = _vb.setOwner(node2).build();
  _ib.setOwner(node2).setVrf(v2);
  _ib.setName(PHYSICAL)
      .setAddresses(NODE2_PHYSICAL_NETWORK, ConcreteInterfaceAddress.create(DST_IP, 32))
      .build();

  return ImmutableSortedMap.of(NODE1, node1, NODE2, node2);
}
 
Example 6
Source File: RoutesAnswererTest.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Test
public void testHasVrfFiltering() {
  SortedMap<String, SortedMap<String, GenericRib<AbstractRouteDecorator>>> ribs =
      ImmutableSortedMap.of(
          "n1",
          ImmutableSortedMap.of(
              Configuration.DEFAULT_VRF_NAME,
              new MockRib<>(
                  ImmutableSet.of(
                      StaticRoute.builder()
                          .setAdministrativeCost(1)
                          .setNetwork(Prefix.parse("1.1.1.0/24"))
                          .setNextHopInterface("Null")
                          .build())),
              "notDefaultVrf",
              new MockRib<>(
                  ImmutableSet.of(
                      StaticRoute.builder()
                          .setNetwork(Prefix.parse("2.2.2.0/24"))
                          .setNextHopInterface("Null")
                          .setAdministrativeCost(1)
                          .build()))));

  Multiset<Row> actual =
      getMainRibRoutes(
          ribs,
          ImmutableSet.of("n1"),
          null,
          RoutingProtocolSpecifier.ALL_PROTOCOLS_SPECIFIER,
          "^not.*",
          null);

  assertThat(actual, hasSize(1));
  assertThat(
      actual.iterator().next().getPrefix(COL_NETWORK), equalTo(Prefix.parse("2.2.2.0/24")));
}
 
Example 7
Source File: TracerouteEngineTest.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Test
public void testAcceptVrf() throws IOException {
  // Construct network
  NetworkFactory nf = new NetworkFactory();
  Configuration.Builder cb =
      nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
  Configuration config = cb.build();
  Vrf.Builder vb = nf.vrfBuilder().setOwner(config);
  Interface.Builder ib = nf.interfaceBuilder().setOwner(config);

  Vrf vrf1 = vb.build();
  Vrf vrf2 = vb.build();

  Interface i1 = ib.setVrf(vrf1).setAddress(ConcreteInterfaceAddress.parse("1.1.1.1/24")).build();
  Interface i2 = ib.setVrf(vrf2).setAddress(ConcreteInterfaceAddress.parse("2.2.2.2/24")).build();
  ib.setVrf(vrf2).setAddress(ConcreteInterfaceAddress.parse("3.3.3.3/24")).build();

  // Compute data plane
  SortedMap<String, Configuration> configs = ImmutableSortedMap.of(config.getHostname(), config);
  Batfish batfish = BatfishTestUtils.getBatfish(configs, _tempFolder);
  NetworkSnapshot snapshot = batfish.getSnapshot();
  batfish.computeDataPlane(snapshot);
  DataPlane dp = batfish.loadDataPlane(snapshot); // Construct flows
  Builder fb = builder().setDstIp(parse("3.3.3.3")).setIngressNode(config.getHostname());

  Flow flow1 = fb.setIngressInterface(i1.getName()).setIngressVrf(vrf1.getName()).build();
  Flow flow2 = fb.setIngressInterface(i2.getName()).setIngressVrf(vrf2.getName()).build();

  // Compute flow traces
  SortedMap<Flow, List<Trace>> traces =
      new TracerouteEngineImpl(dp, batfish.getTopologyProvider().getLayer3Topology(snapshot))
          .computeTraces(ImmutableSet.of(flow1, flow2), false);

  assertThat(traces, hasEntry(equalTo(flow1), contains(hasDisposition(NO_ROUTE))));
  assertThat(traces, hasEntry(equalTo(flow2), contains(hasDisposition(ACCEPTED))));
}
 
Example 8
Source File: ExopackageInstallerIntegrationTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testExoModuleInstall() throws Exception {
  currentBuildState =
      new ExoState(
          "apk-content\n",
          createFakeManifest("manifest-content\n"),
          ImmutableList.of(),
          ImmutableSortedMap.of(),
          ImmutableList.of(),
          ImmutableList.of("module_1\n", "module_2\n"));

  checkExoInstall(1, 0, 0, 0, 2);
}
 
Example 9
Source File: RustCompileTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private FakeRustCompileRule(
    BuildTarget target,
    ImmutableSortedSet<SourcePath> srcs,
    String rootModule,
    SourcePathRuleFinder ruleFinder) {
  super(
      target,
      new FakeProjectFilesystem(),
      ruleFinder,
      String.format("lib%s.rlib", target.getShortName()),
      fakeTool(),
      fakeLinker(),
      Stream.of("--crate-name", target.getShortName(), "--crate-type", "rlib")
          .map(StringArg::of)
          .collect(ImmutableList.toImmutableList()),
      /* depArgs */ ImmutableList.of(),
      /* linkerFlags */
      ImmutableList.of(),
      ImmutableSortedMap.of(),
      srcs.stream()
          .collect(
              ImmutableSortedMap.toImmutableSortedMap(
                  Comparator.naturalOrder(), src -> src, src -> Optional.empty())),
      rootModule,
      RustBuckConfig.RemapSrcPaths.NO,
      Optional.empty());
}
 
Example 10
Source File: Interface.java    From batfish with Apache License 2.0 5 votes vote down vote up
private Builder(@Nullable Supplier<String> nameGenerator) {
  _active = true;
  _addressMetadata = ImmutableMap.of();
  _additionalArpIps = EmptyIpSpace.INSTANCE;
  _autoState = true;
  _channelGroupMembers = ImmutableSortedSet.of();
  _declaredNames = ImmutableSortedSet.of();
  _dhcpRelayAddresses = ImmutableSortedSet.of();
  _hsrpGroups = ImmutableMap.of();
  _nameGenerator = nameGenerator;
  _secondaryAddresses = ImmutableSet.of();
  _vrrpGroups = ImmutableSortedMap.of();
}
 
Example 11
Source File: Zone.java    From batfish with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public Zone(@JsonProperty(PROP_NAME) String name) {
  super(name);
  _inboundInterfaceFiltersNames = ImmutableSortedMap.of();
  _interfaces = ImmutableSortedSet.of();
  _toZonePoliciesNames = ImmutableSortedMap.of();
}
 
Example 12
Source File: ExopackageInstallerIntegrationTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testExoResourcesInstall() throws Exception {
  currentBuildState =
      new ExoState(
          "apk-content\n",
          createFakeManifest("manifest-content\n"),
          ImmutableList.of(),
          ImmutableSortedMap.of(),
          ImmutableList.of("exo-resources.apk\n", "exo-assets0\n", "exo-assets1\n"),
          ImmutableList.of());

  checkExoInstall(1, 0, 0, 3, 0);
}
 
Example 13
Source File: JsBundleDescription.java    From buck with Apache License 2.0 4 votes vote down vote up
private BuildRule createAndroidResources(
    ToolchainProvider toolchainProvider,
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    ActionGraphBuilder graphBuilder,
    JsBundle jsBundle,
    String rDotJavaPackage) {
  if (buildTarget.getFlavors().contains(AndroidResourceDescription.AAPT2_COMPILE_FLAVOR)) {
    AndroidPlatformTarget androidPlatformTarget =
        toolchainProvider.getByName(
            AndroidPlatformTarget.DEFAULT_NAME,
            buildTarget.getTargetConfiguration(),
            AndroidPlatformTarget.class);
    ToolProvider aapt2ToolProvider = androidPlatformTarget.getAapt2ToolProvider();
    return new Aapt2Compile(
        buildTarget,
        projectFilesystem,
        graphBuilder,
        aapt2ToolProvider.resolve(graphBuilder, buildTarget.getTargetConfiguration()),
        jsBundle.getSourcePathToResources(),
        /* skipCrunchPngs */ false,
        androidBuckConfig.getFailOnLegacyAaptErrors());
  }

  BuildRuleParams params =
      new BuildRuleParams(
          ImmutableSortedSet::of, () -> ImmutableSortedSet.of(jsBundle), ImmutableSortedSet.of());

  return new AndroidResource(
      buildTarget,
      projectFilesystem,
      params,
      graphBuilder,
      ImmutableSortedSet.of(), // deps
      jsBundle.getSourcePathToResources(),
      ImmutableSortedMap.of(), // resSrcs
      rDotJavaPackage,
      null,
      ImmutableSortedMap.of(),
      null,
      false);
}
 
Example 14
Source File: HeaderSearchPathAttributes.java    From buck with Apache License 2.0 4 votes vote down vote up
/** Target relative Path to SourcePath for all public headers. */
@Value.Default
ImmutableSortedMap<Path, SourcePath> publicCxxHeaders() {
  return ImmutableSortedMap.of();
}
 
Example 15
Source File: MockBatfish.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Override
public SortedMap<String, Configuration> loadConfigurations(NetworkSnapshot snapshot) {
  assertTrue(snapshot.equals(getSnapshot()) || snapshot.equals(getReferenceSnapshot()));
  Configuration config = snapshot.equals(getSnapshot()) ? _baseConfig : _deltaConfig;
  return ImmutableSortedMap.of(config.getHostname(), config);
}
 
Example 16
Source File: TwoNodeNetworkWithTwoLinks.java    From batfish with Apache License 2.0 4 votes vote down vote up
public static Batfish create(TemporaryFolder temp) throws IOException {
  NetworkFactory nf = new NetworkFactory();
  Builder cb = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
  Interface.Builder ib = nf.interfaceBuilder().setBandwidth(1E9d);
  Vrf.Builder vb = nf.vrfBuilder().setName(Configuration.DEFAULT_VRF_NAME);

  Configuration dstNode = cb.setHostname(DST_NODE).build();
  Configuration srcNode = cb.setHostname(SRC_NODE).build();
  Vrf dstVrf = vb.setOwner(dstNode).build();
  Vrf srcVrf = vb.setOwner(srcNode).build();

  // first link
  ib.setOwner(srcNode)
      .setVrf(srcVrf)
      .setAddress(
          ConcreteInterfaceAddress.create(
              LINK_1_NETWORK.getStartIp(), LINK_1_NETWORK.getPrefixLength()))
      .build();
  ib.setOwner(dstNode)
      .setVrf(dstVrf)
      .setAddress(
          ConcreteInterfaceAddress.create(
              LINK_1_NETWORK.getEndIp(), LINK_1_NETWORK.getPrefixLength()))
      .build();

  // second link
  ib.setOwner(srcNode)
      .setVrf(srcVrf)
      .setAddress(
          ConcreteInterfaceAddress.create(
              LINK_2_NETWORK.getStartIp(), LINK_2_NETWORK.getPrefixLength()))
      .build();
  ib.setOwner(dstNode)
      .setVrf(dstVrf)
      .setAddress(
          ConcreteInterfaceAddress.create(
              LINK_2_NETWORK.getEndIp(), LINK_2_NETWORK.getPrefixLength()))
      .build();

  // destination for the first link
  ib.setOwner(dstNode)
      .setVrf(dstVrf)
      .setAddress(
          ConcreteInterfaceAddress.create(
              DST_PREFIX_1.getStartIp(), DST_PREFIX_1.getPrefixLength()))
      .build();

  // destination for the second link
  ib.setOwner(dstNode)
      .setVrf(dstVrf)
      .setAddress(
          ConcreteInterfaceAddress.create(
              DST_PREFIX_2.getStartIp(), DST_PREFIX_2.getPrefixLength()))
      .build();

  StaticRoute.Builder bld = StaticRoute.builder().setAdministrativeCost(1);
  srcVrf.setStaticRoutes(
      ImmutableSortedSet.of(
          bld.setNetwork(DST_PREFIX_1).setNextHopIp(LINK_1_NETWORK.getEndIp()).build(),
          bld.setNetwork(DST_PREFIX_2).setNextHopIp(LINK_2_NETWORK.getEndIp()).build()));

  SortedMap<String, Configuration> configs =
      ImmutableSortedMap.of(srcNode.getHostname(), srcNode, dstNode.getHostname(), dstNode);
  return BatfishTestUtils.getBatfish(configs, temp);
}
 
Example 17
Source File: BDDReachabilityAnalysisFactoryTest.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Test
public void testEdgeWithPreNatAcl() throws IOException {
  /*
   * Pre-NAT out ACL permits dest source ports 50 - 150
   * Source NAT will write source IP to 5.5.5.5 if source port is 100
   * Post-NAT out ACL permits dest port 80
   */
  NetworkFactory nf = new NetworkFactory();
  Configuration.Builder cb =
      nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS);
  Configuration config = cb.build();
  Vrf vrf = nf.vrfBuilder().setOwner(config).build();
  Ip poolIp = Ip.parse("5.5.5.5");
  HeaderSpace postNatOutAclHeaderSpace =
      HeaderSpace.builder().setDstPorts(ImmutableList.of(SubRange.singleton(80))).build();
  HeaderSpace natMatchHeaderSpace =
      HeaderSpace.builder().setSrcPorts(ImmutableList.of(SubRange.singleton(100))).build();
  HeaderSpace preNatOutAclHeaderSpace =
      HeaderSpace.builder().setSrcPorts(ImmutableList.of(new SubRange(50, 150))).build();
  Interface iface =
      nf.interfaceBuilder()
          .setOwner(config)
          .setVrf(vrf)
          .setActive(true)
          .setAddress(ConcreteInterfaceAddress.parse("1.0.0.0/31"))
          .setPreTransformationOutgoingFilter(
              nf.aclBuilder()
                  .setOwner(config)
                  .setLines(ImmutableList.of(acceptingHeaderSpace(preNatOutAclHeaderSpace)))
                  .build())
          .setOutgoingFilter(
              nf.aclBuilder()
                  .setOwner(config)
                  .setLines(ImmutableList.of(acceptingHeaderSpace(postNatOutAclHeaderSpace)))
                  .build())
          .setOutgoingTransformation(
              when(match(natMatchHeaderSpace)).apply(assignSourceIp(poolIp, poolIp)).build())
          .build();
  String ifaceName = iface.getName();
  Prefix staticRoutePrefix = Prefix.parse("3.3.3.3/32");
  vrf.setStaticRoutes(
      ImmutableSortedSet.of(
          StaticRoute.builder()
              .setNextHopInterface(ifaceName)
              .setAdministrativeCost(1)
              .setNetwork(staticRoutePrefix)
              .build()));

  Configuration peer = cb.build();
  Vrf vrf2 = nf.vrfBuilder().setOwner(peer).build();
  Interface peerIface =
      nf.interfaceBuilder()
          .setOwner(peer)
          .setVrf(vrf2)
          .setAddress(ConcreteInterfaceAddress.parse("1.0.0.1/31"))
          .build();

  String hostname = config.getHostname();
  String peername = peer.getHostname();
  String peerIfaceName = peerIface.getName();

  SortedMap<String, Configuration> configs =
      ImmutableSortedMap.of(hostname, config, peername, peer);
  BDDReachabilityAnalysisFactory factory = makeBddReachabilityAnalysisFactory(configs);

  BDDReachabilityAnalysis analysis =
      factory.bddReachabilityAnalysis(
          IpSpaceAssignment.builder()
              .assign(new InterfaceLocation(hostname, ifaceName), UniverseIpSpace.INSTANCE)
              .build());

  HeaderSpaceToBDD toBDD = new HeaderSpaceToBDD(PKT, ImmutableMap.of());
  IpSpaceToBDD srcToBdd = toBDD.getSrcIpSpaceToBdd();

  BDD preNatOutAclBdd = toBDD.toBDD(preNatOutAclHeaderSpace);
  BDD natMatchBdd = toBDD.toBDD(natMatchHeaderSpace);
  BDD poolIpBdd = srcToBdd.toBDD(poolIp);
  BDD origSrcIpBdd = srcToBdd.toBDD(Ip.parse("6.6.6.6"));

  Map<StateExpr, Transition> preOutEdgeOutEdges =
      analysis
          .getForwardEdgeMap()
          .get(new PreOutEdge(hostname, ifaceName, peername, peerIfaceName));

  Transition transition =
      preOutEdgeOutEdges.get(new PreOutEdgePostNat(hostname, ifaceName, peername, peerIfaceName));
  assertThat(
      transition.transitForward(origSrcIpBdd),
      equalTo(preNatOutAclBdd.and(natMatchBdd.ite(poolIpBdd, origSrcIpBdd))));

  transition = preOutEdgeOutEdges.get(new NodeDropAclOut(hostname));
  assertThat(transition.transitForward(ONE), equalTo(preNatOutAclBdd.not()));
}
 
Example 18
Source File: BDDReachabilityAnalysisFactoryTest.java    From batfish with Apache License 2.0 4 votes vote down vote up
/**
 * Test correctly handling of DestinationNat rules with null pools. If the packet matches the
 * rule, then the packet is not natted and no further rules are applied.
 */
@Test
public void testDestNatNullPool() throws IOException {
  NetworkFactory nf = new NetworkFactory();
  Configuration config =
      nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build();
  Vrf vrf = nf.vrfBuilder().setOwner(config).build();
  Ip poolIp = Ip.parse("5.5.5.5");
  HeaderSpace ingressAclHeaderSpace =
      HeaderSpace.builder().setSrcIps(Prefix.parse("2.0.0.0/8").toIpSpace()).build();
  HeaderSpace nat1MatchHeaderSpace =
      HeaderSpace.builder().setSrcPorts(ImmutableList.of(SubRange.singleton(105))).build();
  HeaderSpace nat2MatchHeaderSpace =
      HeaderSpace.builder().setSrcPorts(ImmutableList.of(new SubRange(100, 110))).build();
  Interface iface =
      nf.interfaceBuilder()
          .setOwner(config)
          .setVrf(vrf)
          .setActive(true)
          .setAddress(ConcreteInterfaceAddress.parse("1.0.0.0/8"))
          .setIncomingFilter(
              nf.aclBuilder()
                  .setOwner(config)
                  .setLines(ImmutableList.of(acceptingHeaderSpace(ingressAclHeaderSpace)))
                  .build())
          .setIncomingTransformation(
              when(match(nat1MatchHeaderSpace))
                  .apply(NOOP_DEST_NAT)
                  .setOrElse(
                      when(match(nat2MatchHeaderSpace))
                          .apply(assignDestinationIp(poolIp, poolIp))
                          .build())
                  .build())
          .build();

  SortedMap<String, Configuration> configs = ImmutableSortedMap.of(config.getHostname(), config);
  BDDReachabilityAnalysisFactory factory = makeBddReachabilityAnalysisFactory(configs);

  BDDReachabilityAnalysis analysis =
      factory.bddReachabilityAnalysis(
          IpSpaceAssignment.builder()
              .assign(
                  new InterfaceLinkLocation(config.getHostname(), iface.getName()),
                  UniverseIpSpace.INSTANCE)
              .build());
  Transition transition =
      analysis
          .getForwardEdgeMap()
          .get(new PreInInterface(config.getHostname(), iface.getName()))
          .get(new PostInInterface(config.getHostname(), iface.getName()));

  HeaderSpaceToBDD toBDD = new HeaderSpaceToBDD(PKT, ImmutableMap.of());
  BDD ingressAclBdd = toBDD.toBDD(ingressAclHeaderSpace);
  BDD nat1MatchBdd = toBDD.toBDD(nat1MatchHeaderSpace);
  BDD nat2MatchBdd = toBDD.toBDD(nat2MatchHeaderSpace);
  BDD origDstIpBdd = toBDD.getDstIpSpaceToBdd().toBDD(Ip.parse("6.6.6.6"));
  BDD poolIpBdd = toBDD.getDstIpSpaceToBdd().toBDD(poolIp);

  assertThat(
      transition.transitForward(origDstIpBdd),
      equalTo(
          ingressAclBdd.and(nat1MatchBdd.not().and(nat2MatchBdd).ite(poolIpBdd, origDstIpBdd))));
}
 
Example 19
Source File: TestFiltersAnswererTest.java    From batfish with Apache License 2.0 4 votes vote down vote up
@Test
public void testIndirection() {
  Configuration c = _cb.build();
  IpAccessList.Builder aclb = _nf.aclBuilder().setOwner(c);

  /*
  Reference ACL contains 1 line: Permit 1.0.0.0/32
  Main ACL contains 2 lines:
  0. Permit anything that reference ACL permits
  1. Permit 1.0.0.0/24
   */

  IpAccessList referencedAcl =
      aclb.setLines(
              ImmutableList.of(
                  acceptingHeaderSpace(
                      HeaderSpace.builder()
                          .setSrcIps(Prefix.parse("1.0.0.0/32").toIpSpace())
                          .build())))
          .setName("acl1")
          .build();
  IpAccessList acl =
      aclb.setLines(
              ImmutableList.of(
                  ExprAclLine.accepting()
                      .setMatchCondition(new PermittedByAcl(referencedAcl.getName()))
                      .build(),
                  acceptingHeaderSpace(
                      HeaderSpace.builder()
                          .setSrcIps(Prefix.parse("1.0.0.0/24").toIpSpace())
                          .build())))
          .setName("acl2")
          .build();

  MockBatfish batfish = new MockBatfish(ImmutableSortedMap.of(c.getHostname(), c));

  assertThat(c, hasIpAccessLists(hasEntry(referencedAcl.getName(), referencedAcl)));
  assertThat(c, hasIpAccessLists(hasEntry(acl.getName(), acl)));

  TestFiltersQuestion question =
      new TestFiltersQuestion(
          null, null, PacketHeaderConstraints.builder().setSrcIp("1.0.0.4").build(), null);
  TestFiltersAnswerer answerer = new TestFiltersAnswerer(question, batfish);
  TableAnswerElement answer = answerer.answer(batfish.getSnapshot());

  /*
   * Trace should be present for referencing acl with one event:
   * Permitted by referencing acl
   *
   * NO event for referenced ACL since its action was not match (default deny)
   */
  assertThat(
      answer,
      hasRows(
          forAll(
              hasColumn(COL_FILTER_NAME, equalTo(acl.getName()), Schema.STRING),
              hasColumn(
                  TestFiltersAnswerer.COL_TRACE, empty(), Schema.list(Schema.TRACE_TREE)))));
  /* Trace should be present for referenced acl with one event: not matching the referenced acl */
  assertThat(
      answer,
      hasRows(
          forAll(
              hasColumn(COL_FILTER_NAME, equalTo(referencedAcl.getName()), Schema.STRING),
              hasColumn(
                  TestFiltersAnswerer.COL_TRACE, empty(), Schema.list(Schema.TRACE_TREE)))));
}
 
Example 20
Source File: FakeJavaLibrary.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public ImmutableSortedMap<String, HashCode> getClassNamesToHashes() {
  return ImmutableSortedMap.of();
}