@Test public void testForNetwork() { NetworkFactory nf = new NetworkFactory(); Configuration c1 = createConfig(nf, ALL_IFACES); Configuration c2 = createConfig(nf, ALL_IFACES); Configuration c3 = createConfig(nf, ImmutableSet.of()); Map<String, Configuration> configs = ImmutableMap.of(c1.getHostname(), c1, c2.getHostname(), c2, c3.getHostname(), c3); Map<String, BDDSourceManager> bddSrcMgrs = BDDSourceManager.forNetwork(PKT, configs, false); Map<String, BDDOutgoingOriginalFlowFilterManager> mgrs = BDDOutgoingOriginalFlowFilterManager.forNetwork(PKT, configs, bddSrcMgrs); BDDOutgoingOriginalFlowFilterManager mgr1 = mgrs.get(c1.getHostname()); BDDOutgoingOriginalFlowFilterManager mgr2 = mgrs.get(c2.getHostname()); BDDOutgoingOriginalFlowFilterManager mgr3 = mgrs.get(c3.getHostname()); assertTrue(!mgr1.isTrivial() && !mgr2.isTrivial()); assertTrue(mgr1.erase(mgr2.outgoingOriginalFlowFiltersConstraint()).isOne()); assertTrue(mgr3.isTrivial()); }
public static Map<String, BDDOutgoingOriginalFlowFilterManager> forNetwork( BDDPacket pkt, Map<String, Configuration> configs, Map<String, BDDSourceManager> srcMgrs) { ImmutableMap.Builder<String, Set<String>> finiteDomainValues = ImmutableMap.builder(); Map<String, String> repActiveIfacesWithoutOrigFlowFilters = new HashMap<>(); Map<String, Map<String, BDD>> filterBdds = new HashMap<>(); for (Configuration c : configs.values()) { String hostname = c.getHostname(); Set<String> activeWithFilters = c.getAllInterfaces().values().stream() .filter(iface -> iface.getActive() && iface.getOutgoingOriginalFlowFilter() != null) .map(Interface::getName) .collect(ImmutableSet.toImmutableSet()); String repActiveIfaceWithoutFilter = activeWithFilters.isEmpty() ? null : c.getActiveInterfaces().keySet().stream() .filter(iface -> !activeWithFilters.contains(iface)) .findAny() .orElse(null); if (repActiveIfaceWithoutFilter != null) { repActiveIfacesWithoutOrigFlowFilters.put(hostname, repActiveIfaceWithoutFilter); finiteDomainValues.put( hostname, ImmutableSet.<String>builder() .addAll(activeWithFilters) .add(repActiveIfaceWithoutFilter) .build()); } else { finiteDomainValues.put(hostname, activeWithFilters); } filterBdds.put(hostname, buildFilterBdds(pkt, c, srcMgrs.get(hostname))); } Map<String, BDDFiniteDomain<String>> finiteDomains = BDDFiniteDomain.domainsWithSharedVariable(pkt, VAR_NAME, finiteDomainValues.build()); BDD permitVar = allocatePermitVar(pkt); return toImmutableMap( configs.keySet(), Function.identity(), hostname -> new BDDOutgoingOriginalFlowFilterManager( finiteDomains.get(hostname), repActiveIfacesWithoutOrigFlowFilters.get(hostname), filterBdds.get(hostname), permitVar)); }
BDDOutgoingOriginalFlowFilterManager { public static Map<String, BDDOutgoingOriginalFlowFilterManager> forNetwork( BDDPacket pkt, Map<String, Configuration> configs, Map<String, BDDSourceManager> srcMgrs) { ImmutableMap.Builder<String, Set<String>> finiteDomainValues = ImmutableMap.builder(); Map<String, String> repActiveIfacesWithoutOrigFlowFilters = new HashMap<>(); Map<String, Map<String, BDD>> filterBdds = new HashMap<>(); for (Configuration c : configs.values()) { String hostname = c.getHostname(); Set<String> activeWithFilters = c.getAllInterfaces().values().stream() .filter(iface -> iface.getActive() && iface.getOutgoingOriginalFlowFilter() != null) .map(Interface::getName) .collect(ImmutableSet.toImmutableSet()); String repActiveIfaceWithoutFilter = activeWithFilters.isEmpty() ? null : c.getActiveInterfaces().keySet().stream() .filter(iface -> !activeWithFilters.contains(iface)) .findAny() .orElse(null); if (repActiveIfaceWithoutFilter != null) { repActiveIfacesWithoutOrigFlowFilters.put(hostname, repActiveIfaceWithoutFilter); finiteDomainValues.put( hostname, ImmutableSet.<String>builder() .addAll(activeWithFilters) .add(repActiveIfaceWithoutFilter) .build()); } else { finiteDomainValues.put(hostname, activeWithFilters); } filterBdds.put(hostname, buildFilterBdds(pkt, c, srcMgrs.get(hostname))); } Map<String, BDDFiniteDomain<String>> finiteDomains = BDDFiniteDomain.domainsWithSharedVariable(pkt, VAR_NAME, finiteDomainValues.build()); BDD permitVar = allocatePermitVar(pkt); return toImmutableMap( configs.keySet(), Function.identity(), hostname -> new BDDOutgoingOriginalFlowFilterManager( finiteDomains.get(hostname), repActiveIfacesWithoutOrigFlowFilters.get(hostname), filterBdds.get(hostname), permitVar)); } }
BDDOutgoingOriginalFlowFilterManager { public static Map<String, BDDOutgoingOriginalFlowFilterManager> forNetwork( BDDPacket pkt, Map<String, Configuration> configs, Map<String, BDDSourceManager> srcMgrs) { ImmutableMap.Builder<String, Set<String>> finiteDomainValues = ImmutableMap.builder(); Map<String, String> repActiveIfacesWithoutOrigFlowFilters = new HashMap<>(); Map<String, Map<String, BDD>> filterBdds = new HashMap<>(); for (Configuration c : configs.values()) { String hostname = c.getHostname(); Set<String> activeWithFilters = c.getAllInterfaces().values().stream() .filter(iface -> iface.getActive() && iface.getOutgoingOriginalFlowFilter() != null) .map(Interface::getName) .collect(ImmutableSet.toImmutableSet()); String repActiveIfaceWithoutFilter = activeWithFilters.isEmpty() ? null : c.getActiveInterfaces().keySet().stream() .filter(iface -> !activeWithFilters.contains(iface)) .findAny() .orElse(null); if (repActiveIfaceWithoutFilter != null) { repActiveIfacesWithoutOrigFlowFilters.put(hostname, repActiveIfaceWithoutFilter); finiteDomainValues.put( hostname, ImmutableSet.<String>builder() .addAll(activeWithFilters) .add(repActiveIfaceWithoutFilter) .build()); } else { finiteDomainValues.put(hostname, activeWithFilters); } filterBdds.put(hostname, buildFilterBdds(pkt, c, srcMgrs.get(hostname))); } Map<String, BDDFiniteDomain<String>> finiteDomains = BDDFiniteDomain.domainsWithSharedVariable(pkt, VAR_NAME, finiteDomainValues.build()); BDD permitVar = allocatePermitVar(pkt); return toImmutableMap( configs.keySet(), Function.identity(), hostname -> new BDDOutgoingOriginalFlowFilterManager( finiteDomains.get(hostname), repActiveIfacesWithoutOrigFlowFilters.get(hostname), filterBdds.get(hostname), permitVar)); } private  BDDOutgoingOriginalFlowFilterManager(
      BDDFiniteDomain<String> finiteDomain,
      @Nullable String activeButNoOriginalFlowFilterRepresentative,
      Map<String, BDD> filterBdds,
      BDD permitVar); }
BDDOutgoingOriginalFlowFilterManager { public static Map<String, BDDOutgoingOriginalFlowFilterManager> forNetwork( BDDPacket pkt, Map<String, Configuration> configs, Map<String, BDDSourceManager> srcMgrs) { ImmutableMap.Builder<String, Set<String>> finiteDomainValues = ImmutableMap.builder(); Map<String, String> repActiveIfacesWithoutOrigFlowFilters = new HashMap<>(); Map<String, Map<String, BDD>> filterBdds = new HashMap<>(); for (Configuration c : configs.values()) { String hostname = c.getHostname(); Set<String> activeWithFilters = c.getAllInterfaces().values().stream() .filter(iface -> iface.getActive() && iface.getOutgoingOriginalFlowFilter() != null) .map(Interface::getName) .collect(ImmutableSet.toImmutableSet()); String repActiveIfaceWithoutFilter = activeWithFilters.isEmpty() ? null : c.getActiveInterfaces().keySet().stream() .filter(iface -> !activeWithFilters.contains(iface)) .findAny() .orElse(null); if (repActiveIfaceWithoutFilter != null) { repActiveIfacesWithoutOrigFlowFilters.put(hostname, repActiveIfaceWithoutFilter); finiteDomainValues.put( hostname, ImmutableSet.<String>builder() .addAll(activeWithFilters) .add(repActiveIfaceWithoutFilter) .build()); } else { finiteDomainValues.put(hostname, activeWithFilters); } filterBdds.put(hostname, buildFilterBdds(pkt, c, srcMgrs.get(hostname))); } Map<String, BDDFiniteDomain<String>> finiteDomains = BDDFiniteDomain.domainsWithSharedVariable(pkt, VAR_NAME, finiteDomainValues.build()); BDD permitVar = allocatePermitVar(pkt); return toImmutableMap( configs.keySet(), Function.identity(), hostname -> new BDDOutgoingOriginalFlowFilterManager( finiteDomains.get(hostname), repActiveIfacesWithoutOrigFlowFilters.get(hostname), filterBdds.get(hostname), permitVar)); } private  BDDOutgoingOriginalFlowFilterManager(
      BDDFiniteDomain<String> finiteDomain,
      @Nullable String activeButNoOriginalFlowFilterRepresentative,
      Map<String, BDD> filterBdds,
      BDD permitVar); static BDDOutgoingOriginalFlowFilterManager empty(BDDPacket pkt); static Map<String, BDDOutgoingOriginalFlowFilterManager> forNetwork(
      BDDPacket pkt, Map<String, Configuration> configs, Map<String, BDDSourceManager> srcMgrs); BDD outgoingOriginalFlowFiltersConstraint(); BDD erase(BDD bdd); BDD permittedByOriginalFlowEgressFilter(String iface); BDD deniedByOriginalFlowEgressFilter(String iface); boolean isTrivial(); }
BDDOutgoingOriginalFlowFilterManager { public static Map<String, BDDOutgoingOriginalFlowFilterManager> forNetwork( BDDPacket pkt, Map<String, Configuration> configs, Map<String, BDDSourceManager> srcMgrs) { ImmutableMap.Builder<String, Set<String>> finiteDomainValues = ImmutableMap.builder(); Map<String, String> repActiveIfacesWithoutOrigFlowFilters = new HashMap<>(); Map<String, Map<String, BDD>> filterBdds = new HashMap<>(); for (Configuration c : configs.values()) { String hostname = c.getHostname(); Set<String> activeWithFilters = c.getAllInterfaces().values().stream() .filter(iface -> iface.getActive() && iface.getOutgoingOriginalFlowFilter() != null) .map(Interface::getName) .collect(ImmutableSet.toImmutableSet()); String repActiveIfaceWithoutFilter = activeWithFilters.isEmpty() ? null : c.getActiveInterfaces().keySet().stream() .filter(iface -> !activeWithFilters.contains(iface)) .findAny() .orElse(null); if (repActiveIfaceWithoutFilter != null) { repActiveIfacesWithoutOrigFlowFilters.put(hostname, repActiveIfaceWithoutFilter); finiteDomainValues.put( hostname, ImmutableSet.<String>builder() .addAll(activeWithFilters) .add(repActiveIfaceWithoutFilter) .build()); } else { finiteDomainValues.put(hostname, activeWithFilters); } filterBdds.put(hostname, buildFilterBdds(pkt, c, srcMgrs.get(hostname))); } Map<String, BDDFiniteDomain<String>> finiteDomains = BDDFiniteDomain.domainsWithSharedVariable(pkt, VAR_NAME, finiteDomainValues.build()); BDD permitVar = allocatePermitVar(pkt); return toImmutableMap( configs.keySet(), Function.identity(), hostname -> new BDDOutgoingOriginalFlowFilterManager( finiteDomains.get(hostname), repActiveIfacesWithoutOrigFlowFilters.get(hostname), filterBdds.get(hostname), permitVar)); } private  BDDOutgoingOriginalFlowFilterManager(
      BDDFiniteDomain<String> finiteDomain,
      @Nullable String activeButNoOriginalFlowFilterRepresentative,
      Map<String, BDD> filterBdds,
      BDD permitVar); static BDDOutgoingOriginalFlowFilterManager empty(BDDPacket pkt); static Map<String, BDDOutgoingOriginalFlowFilterManager> forNetwork(
      BDDPacket pkt, Map<String, Configuration> configs, Map<String, BDDSourceManager> srcMgrs); BDD outgoingOriginalFlowFiltersConstraint(); BDD erase(BDD bdd); BDD permittedByOriginalFlowEgressFilter(String iface); BDD deniedByOriginalFlowEgressFilter(String iface); boolean isTrivial();  }