@Test public void testFinalHeaderSpaceBdd() throws IOException { 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 srcNatPoolIp = Ip.parse("5.5.5.5"); Ip dstNatPoolIp = Ip.parse("6.6.6.6"); nf.interfaceBuilder() .setOwner(config) .setVrf(vrf) .setActive(true) .setAddress(ConcreteInterfaceAddress.parse("1.0.0.0/31")) .setOutgoingTransformation( always().apply(assignSourceIp(srcNatPoolIp, srcNatPoolIp)).build()) .setIncomingTransformation( always().apply(assignDestinationIp(dstNatPoolIp, dstNatPoolIp)).build()) .build(); String hostname = config.getHostname(); SortedMap<String, Configuration> configs = ImmutableSortedMap.of(hostname, config); BDDReachabilityAnalysisFactory factory = makeBddReachabilityAnalysisFactory(configs); BDD one = PKT.getFactory().one(); assertThat(factory.computeFinalHeaderSpaceBdd(one), equalTo(one)); BDD dstIp1 = PKT.getDstIp().value(1); BDD dstNatPoolIpBdd = PKT.getDstIp().value(dstNatPoolIp.asLong()); BDD srcIp1 = PKT.getSrcIp().value(1); BDD srcNatPoolIpBdd = PKT.getSrcIp().value(srcNatPoolIp.asLong()); assertThat(factory.computeFinalHeaderSpaceBdd(dstIp1), equalTo(dstIp1.or(dstNatPoolIpBdd))); assertThat(factory.computeFinalHeaderSpaceBdd(srcIp1), equalTo(srcIp1.or(srcNatPoolIpBdd))); assertThat( factory.computeFinalHeaderSpaceBdd(dstIp1.and(srcIp1)), equalTo( dstIp1 .and(srcIp1) .or(dstIp1.and(srcNatPoolIpBdd)) .or(dstNatPoolIpBdd.and(srcIp1)) .or(dstNatPoolIpBdd.and(srcNatPoolIpBdd)))); }
@VisibleForTesting BDD computeFinalHeaderSpaceBdd(BDD initialHeaderSpaceBdd) { Span span = GlobalTracer.get() .buildSpan("BDDReachabilityAnalysisFactory.computeFinalHeaderSpaceBdd") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; BDD finalHeaderSpace = initialHeaderSpaceBdd; BDD noDstIp = finalHeaderSpace.exist(_dstIpVars); if (!noDstIp.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationIpRanges.get(IpField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstIp.and(dstTransformationRange)); } } BDD noSrcIp = finalHeaderSpace.exist(_sourceIpVars); if (!noSrcIp.equals(finalHeaderSpace)) { BDD srcNatPoolIps = _transformationIpRanges.getOrDefault(IpField.SOURCE, _zero); if (!srcNatPoolIps.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcIp.and(srcNatPoolIps)); } } BDD noDstPort = finalHeaderSpace.exist(_dstPortVars); if (!noDstPort.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationPortRanges.get(PortField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstPort.and(dstTransformationRange)); } } BDD noSrcPort = finalHeaderSpace.exist(_sourcePortVars); if (!noSrcPort.equals(finalHeaderSpace)) { BDD srcNatPool = _transformationPortRanges.getOrDefault(PortField.SOURCE, _zero); if (!srcNatPool.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcPort.and(srcNatPool)); } } return finalHeaderSpace; } finally { span.finish(); } }
BDDReachabilityAnalysisFactory { @VisibleForTesting BDD computeFinalHeaderSpaceBdd(BDD initialHeaderSpaceBdd) { Span span = GlobalTracer.get() .buildSpan("BDDReachabilityAnalysisFactory.computeFinalHeaderSpaceBdd") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; BDD finalHeaderSpace = initialHeaderSpaceBdd; BDD noDstIp = finalHeaderSpace.exist(_dstIpVars); if (!noDstIp.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationIpRanges.get(IpField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstIp.and(dstTransformationRange)); } } BDD noSrcIp = finalHeaderSpace.exist(_sourceIpVars); if (!noSrcIp.equals(finalHeaderSpace)) { BDD srcNatPoolIps = _transformationIpRanges.getOrDefault(IpField.SOURCE, _zero); if (!srcNatPoolIps.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcIp.and(srcNatPoolIps)); } } BDD noDstPort = finalHeaderSpace.exist(_dstPortVars); if (!noDstPort.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationPortRanges.get(PortField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstPort.and(dstTransformationRange)); } } BDD noSrcPort = finalHeaderSpace.exist(_sourcePortVars); if (!noSrcPort.equals(finalHeaderSpace)) { BDD srcNatPool = _transformationPortRanges.getOrDefault(PortField.SOURCE, _zero); if (!srcNatPool.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcPort.and(srcNatPool)); } } return finalHeaderSpace; } finally { span.finish(); } } }
BDDReachabilityAnalysisFactory { @VisibleForTesting BDD computeFinalHeaderSpaceBdd(BDD initialHeaderSpaceBdd) { Span span = GlobalTracer.get() .buildSpan("BDDReachabilityAnalysisFactory.computeFinalHeaderSpaceBdd") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; BDD finalHeaderSpace = initialHeaderSpaceBdd; BDD noDstIp = finalHeaderSpace.exist(_dstIpVars); if (!noDstIp.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationIpRanges.get(IpField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstIp.and(dstTransformationRange)); } } BDD noSrcIp = finalHeaderSpace.exist(_sourceIpVars); if (!noSrcIp.equals(finalHeaderSpace)) { BDD srcNatPoolIps = _transformationIpRanges.getOrDefault(IpField.SOURCE, _zero); if (!srcNatPoolIps.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcIp.and(srcNatPoolIps)); } } BDD noDstPort = finalHeaderSpace.exist(_dstPortVars); if (!noDstPort.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationPortRanges.get(PortField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstPort.and(dstTransformationRange)); } } BDD noSrcPort = finalHeaderSpace.exist(_sourcePortVars); if (!noSrcPort.equals(finalHeaderSpace)) { BDD srcNatPool = _transformationPortRanges.getOrDefault(PortField.SOURCE, _zero); if (!srcNatPool.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcPort.and(srcNatPool)); } } return finalHeaderSpace; } finally { span.finish(); } } BDDReachabilityAnalysisFactory(
      BDDPacket packet,
      Map<String, Configuration> configs,
      ForwardingAnalysis forwardingAnalysis,
      IpsRoutedOutInterfacesFactory ipsRoutedOutInterfacesFactory,
      boolean ignoreFilters,
      boolean initializeSessions); }
BDDReachabilityAnalysisFactory { @VisibleForTesting BDD computeFinalHeaderSpaceBdd(BDD initialHeaderSpaceBdd) { Span span = GlobalTracer.get() .buildSpan("BDDReachabilityAnalysisFactory.computeFinalHeaderSpaceBdd") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; BDD finalHeaderSpace = initialHeaderSpaceBdd; BDD noDstIp = finalHeaderSpace.exist(_dstIpVars); if (!noDstIp.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationIpRanges.get(IpField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstIp.and(dstTransformationRange)); } } BDD noSrcIp = finalHeaderSpace.exist(_sourceIpVars); if (!noSrcIp.equals(finalHeaderSpace)) { BDD srcNatPoolIps = _transformationIpRanges.getOrDefault(IpField.SOURCE, _zero); if (!srcNatPoolIps.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcIp.and(srcNatPoolIps)); } } BDD noDstPort = finalHeaderSpace.exist(_dstPortVars); if (!noDstPort.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationPortRanges.get(PortField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstPort.and(dstTransformationRange)); } } BDD noSrcPort = finalHeaderSpace.exist(_sourcePortVars); if (!noSrcPort.equals(finalHeaderSpace)) { BDD srcNatPool = _transformationPortRanges.getOrDefault(PortField.SOURCE, _zero); if (!srcNatPool.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcPort.and(srcNatPool)); } } return finalHeaderSpace; } finally { span.finish(); } } BDDReachabilityAnalysisFactory(
      BDDPacket packet,
      Map<String, Configuration> configs,
      ForwardingAnalysis forwardingAnalysis,
      IpsRoutedOutInterfacesFactory ipsRoutedOutInterfacesFactory,
      boolean ignoreFilters,
      boolean initializeSessions); BDDReachabilityAnalysis bddReachabilityAnalysis(IpSpaceAssignment srcIpSpaceAssignment); BDDReachabilityAnalysis bddReachabilityAnalysis(
      IpSpaceAssignment srcIpSpaceAssignment, boolean useInterfaceRoots); BDDLoopDetectionAnalysis bddLoopDetectionAnalysis(IpSpaceAssignment srcIpSpaceAssignment); Map<IngressLocation, BDD> getAllBDDs(
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> finalNodes,
      Set<FlowDisposition> actions); @VisibleForTesting BDDReachabilityAnalysis bddReachabilityAnalysis(
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> finalNodes,
      Set<FlowDisposition> actions); @VisibleForTesting BDDReachabilityAnalysis bddReachabilityAnalysis(
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> finalNodes,
      Set<FlowDisposition> actions,
      boolean useInterfaceRoots); Map<String, BDDOutgoingOriginalFlowFilterManager> getBddOutgoingOriginalFlowFilterManagers(); Map<String, BDDSourceManager> getBDDSourceManagers(); @Nullable LastHopOutgoingInterfaceManager getLastHopManager(); }
BDDReachabilityAnalysisFactory { @VisibleForTesting BDD computeFinalHeaderSpaceBdd(BDD initialHeaderSpaceBdd) { Span span = GlobalTracer.get() .buildSpan("BDDReachabilityAnalysisFactory.computeFinalHeaderSpaceBdd") .start(); try (Scope scope = GlobalTracer.get().scopeManager().activate(span)) { assert scope != null; BDD finalHeaderSpace = initialHeaderSpaceBdd; BDD noDstIp = finalHeaderSpace.exist(_dstIpVars); if (!noDstIp.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationIpRanges.get(IpField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstIp.and(dstTransformationRange)); } } BDD noSrcIp = finalHeaderSpace.exist(_sourceIpVars); if (!noSrcIp.equals(finalHeaderSpace)) { BDD srcNatPoolIps = _transformationIpRanges.getOrDefault(IpField.SOURCE, _zero); if (!srcNatPoolIps.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcIp.and(srcNatPoolIps)); } } BDD noDstPort = finalHeaderSpace.exist(_dstPortVars); if (!noDstPort.equals(finalHeaderSpace)) { BDD dstTransformationRange = _transformationPortRanges.get(PortField.DESTINATION); if (dstTransformationRange != null) { finalHeaderSpace = finalHeaderSpace.or(noDstPort.and(dstTransformationRange)); } } BDD noSrcPort = finalHeaderSpace.exist(_sourcePortVars); if (!noSrcPort.equals(finalHeaderSpace)) { BDD srcNatPool = _transformationPortRanges.getOrDefault(PortField.SOURCE, _zero); if (!srcNatPool.isZero()) { finalHeaderSpace = finalHeaderSpace.or(noSrcPort.and(srcNatPool)); } } return finalHeaderSpace; } finally { span.finish(); } } BDDReachabilityAnalysisFactory(
      BDDPacket packet,
      Map<String, Configuration> configs,
      ForwardingAnalysis forwardingAnalysis,
      IpsRoutedOutInterfacesFactory ipsRoutedOutInterfacesFactory,
      boolean ignoreFilters,
      boolean initializeSessions); BDDReachabilityAnalysis bddReachabilityAnalysis(IpSpaceAssignment srcIpSpaceAssignment); BDDReachabilityAnalysis bddReachabilityAnalysis(
      IpSpaceAssignment srcIpSpaceAssignment, boolean useInterfaceRoots); BDDLoopDetectionAnalysis bddLoopDetectionAnalysis(IpSpaceAssignment srcIpSpaceAssignment); Map<IngressLocation, BDD> getAllBDDs(
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> finalNodes,
      Set<FlowDisposition> actions); @VisibleForTesting BDDReachabilityAnalysis bddReachabilityAnalysis(
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> finalNodes,
      Set<FlowDisposition> actions); @VisibleForTesting BDDReachabilityAnalysis bddReachabilityAnalysis(
      IpSpaceAssignment srcIpSpaceAssignment,
      AclLineMatchExpr initialHeaderSpace,
      Set<String> forbiddenTransitNodes,
      Set<String> requiredTransitNodes,
      Set<String> finalNodes,
      Set<FlowDisposition> actions,
      boolean useInterfaceRoots); Map<String, BDDOutgoingOriginalFlowFilterManager> getBddOutgoingOriginalFlowFilterManagers(); Map<String, BDDSourceManager> getBDDSourceManagers(); @Nullable LastHopOutgoingInterfaceManager getLastHopManager();  }