@Test public void testSourceAndLastHopConstraint() { Interface iface = _ib.build(); String iName = iface.getName(); Map<String, BDDSourceManager> srcManagers = BDDSourceManager.forNetwork(_bddPacket, _configs, true); BDDSourceManager srcManager = srcManagers.get(HOSTNAME); String neighbor1 = "neighbor1"; String neighbor2 = "neighbor2"; String neighborIface = "neighborIface"; NodeInterfacePair lastHop1 = NodeInterfacePair.of(neighbor1, neighborIface); NodeInterfacePair lastHop2 = NodeInterfacePair.of(neighbor2, neighborIface); _lastHopManager = new LastHopOutgoingInterfaceManager( _bddPacket, _configs, ImmutableSet.of( new Edge(lastHop1, NodeInterfacePair.of(HOSTNAME, iName)), new Edge(lastHop2, NodeInterfacePair.of(HOSTNAME, iName)))); BDDReverseTransformationRangesImpl ranges = new BDDReverseTransformationRangesImpl( _configs, ImmutableMap.of(), _bddPacket, null, srcManagers, _lastHopManager); assertThat( ranges.sourceAndLastHopConstraint(HOSTNAME, null, null), equalTo(srcManager.getOriginatingFromDeviceBDD())); assertThat( ranges.sourceAndLastHopConstraint(HOSTNAME, iName, null), equalTo( srcManager .getSourceInterfaceBDD(iName) .and(_lastHopManager.getNoLastHopOutgoingInterfaceBdd(HOSTNAME, iName)))); assertThat( ranges.sourceAndLastHopConstraint(HOSTNAME, iName, lastHop1), equalTo( srcManager .getSourceInterfaceBDD(iName) .and( _lastHopManager.getLastHopOutgoingInterfaceBdd( HOSTNAME, iName, neighbor1, neighborIface)))); assertThat( ranges.sourceAndLastHopConstraint(HOSTNAME, iName, lastHop2), equalTo( srcManager .getSourceInterfaceBDD(iName) .and( _lastHopManager.getLastHopOutgoingInterfaceBdd( HOSTNAME, iName, neighbor2, neighborIface)))); }
@VisibleForTesting BDD sourceAndLastHopConstraint( String node, @Nullable String inIface, @Nullable NodeInterfacePair lastHop) { checkArgument(inIface != null || lastHop == null, "Can't have a lastHop without an inIface"); BDDSourceManager srcMgr = _srcManagers.get(node); if (inIface == null) { return srcMgr.getOriginatingFromDeviceBDD(); } BDD srcBdd = srcMgr.getSourceInterfaceBDD(inIface); if (lastHop == null) { return srcBdd.and(_lastHopManager.getNoLastHopOutgoingInterfaceBdd(node, inIface)); } else { return srcBdd.and( _lastHopManager.getLastHopOutgoingInterfaceBdd( lastHop.getHostname(), lastHop.getInterface(), node, inIface)); } }
BDDReverseTransformationRangesImpl implements BDDReverseTransformationRanges { @VisibleForTesting BDD sourceAndLastHopConstraint( String node, @Nullable String inIface, @Nullable NodeInterfacePair lastHop) { checkArgument(inIface != null || lastHop == null, "Can't have a lastHop without an inIface"); BDDSourceManager srcMgr = _srcManagers.get(node); if (inIface == null) { return srcMgr.getOriginatingFromDeviceBDD(); } BDD srcBdd = srcMgr.getSourceInterfaceBDD(inIface); if (lastHop == null) { return srcBdd.and(_lastHopManager.getNoLastHopOutgoingInterfaceBdd(node, inIface)); } else { return srcBdd.and( _lastHopManager.getLastHopOutgoingInterfaceBdd( lastHop.getHostname(), lastHop.getInterface(), node, inIface)); } } }
BDDReverseTransformationRangesImpl implements BDDReverseTransformationRanges { @VisibleForTesting BDD sourceAndLastHopConstraint( String node, @Nullable String inIface, @Nullable NodeInterfacePair lastHop) { checkArgument(inIface != null || lastHop == null, "Can't have a lastHop without an inIface"); BDDSourceManager srcMgr = _srcManagers.get(node); if (inIface == null) { return srcMgr.getOriginatingFromDeviceBDD(); } BDD srcBdd = srcMgr.getSourceInterfaceBDD(inIface); if (lastHop == null) { return srcBdd.and(_lastHopManager.getNoLastHopOutgoingInterfaceBdd(node, inIface)); } else { return srcBdd.and( _lastHopManager.getLastHopOutgoingInterfaceBdd( lastHop.getHostname(), lastHop.getInterface(), node, inIface)); } } BDDReverseTransformationRangesImpl(
      Map<String, Configuration> configs,
      Map<StateExpr, BDD> forwardReachableSets,
      BDDPacket bddPacket,
      @Nullable Map<String, Map<String, Supplier<BDD>>> forwardFlowFilterBdds,
      Map<String, BDDSourceManager> srcManagers,
      LastHopOutgoingInterfaceManager lastHopManager); }
BDDReverseTransformationRangesImpl implements BDDReverseTransformationRanges { @VisibleForTesting BDD sourceAndLastHopConstraint( String node, @Nullable String inIface, @Nullable NodeInterfacePair lastHop) { checkArgument(inIface != null || lastHop == null, "Can't have a lastHop without an inIface"); BDDSourceManager srcMgr = _srcManagers.get(node); if (inIface == null) { return srcMgr.getOriginatingFromDeviceBDD(); } BDD srcBdd = srcMgr.getSourceInterfaceBDD(inIface); if (lastHop == null) { return srcBdd.and(_lastHopManager.getNoLastHopOutgoingInterfaceBdd(node, inIface)); } else { return srcBdd.and( _lastHopManager.getLastHopOutgoingInterfaceBdd( lastHop.getHostname(), lastHop.getInterface(), node, inIface)); } } BDDReverseTransformationRangesImpl(
      Map<String, Configuration> configs,
      Map<StateExpr, BDD> forwardReachableSets,
      BDDPacket bddPacket,
      @Nullable Map<String, Map<String, Supplier<BDD>>> forwardFlowFilterBdds,
      Map<String, BDDSourceManager> srcManagers,
      LastHopOutgoingInterfaceManager lastHopManager); @Override BDD reverseIncomingTransformationRange(
      String node, String iface, @Nullable String inIface, @Nullable NodeInterfacePair lastHop); @Override BDD reverseOutgoingTransformationRange(
      String node, String iface, @Nullable String inIface, @Nullable NodeInterfacePair lastHop); }
BDDReverseTransformationRangesImpl implements BDDReverseTransformationRanges { @VisibleForTesting BDD sourceAndLastHopConstraint( String node, @Nullable String inIface, @Nullable NodeInterfacePair lastHop) { checkArgument(inIface != null || lastHop == null, "Can't have a lastHop without an inIface"); BDDSourceManager srcMgr = _srcManagers.get(node); if (inIface == null) { return srcMgr.getOriginatingFromDeviceBDD(); } BDD srcBdd = srcMgr.getSourceInterfaceBDD(inIface); if (lastHop == null) { return srcBdd.and(_lastHopManager.getNoLastHopOutgoingInterfaceBdd(node, inIface)); } else { return srcBdd.and( _lastHopManager.getLastHopOutgoingInterfaceBdd( lastHop.getHostname(), lastHop.getInterface(), node, inIface)); } } BDDReverseTransformationRangesImpl(
      Map<String, Configuration> configs,
      Map<StateExpr, BDD> forwardReachableSets,
      BDDPacket bddPacket,
      @Nullable Map<String, Map<String, Supplier<BDD>>> forwardFlowFilterBdds,
      Map<String, BDDSourceManager> srcManagers,
      LastHopOutgoingInterfaceManager lastHopManager); @Override BDD reverseIncomingTransformationRange(
      String node, String iface, @Nullable String inIface, @Nullable NodeInterfacePair lastHop); @Override BDD reverseOutgoingTransformationRange(
      String node, String iface, @Nullable String inIface, @Nullable NodeInterfacePair lastHop);  }