@Test public void testWithAclIpSpaceWithCircularRef() { _c1.setIpSpaces( ImmutableSortedMap.of( "aclIpSpace", AclIpSpace.of(AclIpSpaceLine.permit(new IpSpaceReference("aclIpSpace"))))); _aclb .setLines( ImmutableList.of( ExprAclLine.accepting() .setMatchCondition( new MatchHeaderSpace( HeaderSpace.builder() .setSrcIps(new IpSpaceReference("aclIpSpace")) .build())) .build())) .build(); List<AclSpecs> aclSpecs = getAclSpecs(ImmutableSet.of("c1")); assertThat(aclSpecs, hasSize(1)); AclSpecs spec = aclSpecs.get(0); assertThat(spec.acl.getSanitizedAcl().getLines(), equalTo(ImmutableList.of(UNMATCHABLE))); }
@VisibleForTesting static List<AclSpecs> getAclSpecs( SortedMap<String, Configuration> configurations, Map<String, Set<IpAccessList>> specifiedAcls, FilterLineReachabilityRows answer) { List<AclSpecs.Builder> aclSpecs = new ArrayList<>(); for (String hostname : configurations.keySet()) { if (specifiedAcls.containsKey(hostname)) { Configuration c = configurations.get(hostname); Set<IpAccessList> acls = specifiedAcls.get(hostname); HeaderSpaceSanitizer headerSpaceSanitizer = new HeaderSpaceSanitizer(c.getIpSpaces()); Map<String, Interface> nodeInterfaces = c.getAllInterfaces(); Map<String, AclNode> aclNodeMap = new TreeMap<>(); for (IpAccessList acl : acls) { String aclName = acl.getName(); if (!aclNodeMap.containsKey(aclName)) { createAclNode( acl, aclNodeMap, c.getIpAccessLists(), headerSpaceSanitizer, nodeInterfaces.keySet()); } } Set<String> sanitizedAcls = new TreeSet<>(); for (AclNode node : aclNodeMap.values()) { if (!sanitizedAcls.contains(node.getName())) { List<ImmutableList<String>> cycles = sanitizeNode(node, new ArrayList<>(), sanitizedAcls, aclNodeMap); for (ImmutableList<String> cycleAcls : cycles) { answer.addCycle(hostname, cycleAcls); } } } for (IpAccessList acl : acls) { String aclName = acl.getName(); AclNode node = aclNodeMap.get(aclName); Set<String> referencedInterfaces = node.getInterfaceDependencies(); if (referencedInterfaces.size() < nodeInterfaces.size()) { String unreferencedIfaceName = "unreferencedInterface"; int n = 0; while (referencedInterfaces.contains(unreferencedIfaceName)) { unreferencedIfaceName = "unreferencedInterface" + n; n++; } referencedInterfaces = new TreeSet<>(referencedInterfaces); referencedInterfaces.add(unreferencedIfaceName); } CanonicalAcl currentAcl = new CanonicalAcl( node.getSanitizedAcl(), node.getAcl(), node.getFlatDependencies(), referencedInterfaces, node.getLinesWithUndefinedRefs(), node.getLinesInCycles()); boolean added = false; for (AclSpecs.Builder aclSpec : aclSpecs) { if (aclSpec.getAcl().equals(currentAcl)) { aclSpec.addSource(hostname, aclName); added = true; break; } } if (!added) { aclSpecs.add(AclSpecs.builder().setAcl(currentAcl).addSource(hostname, aclName)); } } } } return aclSpecs.stream().map(AclSpecs.Builder::build).collect(Collectors.toList()); }
FilterLineReachabilityAnswerer extends Answerer { @VisibleForTesting static List<AclSpecs> getAclSpecs( SortedMap<String, Configuration> configurations, Map<String, Set<IpAccessList>> specifiedAcls, FilterLineReachabilityRows answer) { List<AclSpecs.Builder> aclSpecs = new ArrayList<>(); for (String hostname : configurations.keySet()) { if (specifiedAcls.containsKey(hostname)) { Configuration c = configurations.get(hostname); Set<IpAccessList> acls = specifiedAcls.get(hostname); HeaderSpaceSanitizer headerSpaceSanitizer = new HeaderSpaceSanitizer(c.getIpSpaces()); Map<String, Interface> nodeInterfaces = c.getAllInterfaces(); Map<String, AclNode> aclNodeMap = new TreeMap<>(); for (IpAccessList acl : acls) { String aclName = acl.getName(); if (!aclNodeMap.containsKey(aclName)) { createAclNode( acl, aclNodeMap, c.getIpAccessLists(), headerSpaceSanitizer, nodeInterfaces.keySet()); } } Set<String> sanitizedAcls = new TreeSet<>(); for (AclNode node : aclNodeMap.values()) { if (!sanitizedAcls.contains(node.getName())) { List<ImmutableList<String>> cycles = sanitizeNode(node, new ArrayList<>(), sanitizedAcls, aclNodeMap); for (ImmutableList<String> cycleAcls : cycles) { answer.addCycle(hostname, cycleAcls); } } } for (IpAccessList acl : acls) { String aclName = acl.getName(); AclNode node = aclNodeMap.get(aclName); Set<String> referencedInterfaces = node.getInterfaceDependencies(); if (referencedInterfaces.size() < nodeInterfaces.size()) { String unreferencedIfaceName = "unreferencedInterface"; int n = 0; while (referencedInterfaces.contains(unreferencedIfaceName)) { unreferencedIfaceName = "unreferencedInterface" + n; n++; } referencedInterfaces = new TreeSet<>(referencedInterfaces); referencedInterfaces.add(unreferencedIfaceName); } CanonicalAcl currentAcl = new CanonicalAcl( node.getSanitizedAcl(), node.getAcl(), node.getFlatDependencies(), referencedInterfaces, node.getLinesWithUndefinedRefs(), node.getLinesInCycles()); boolean added = false; for (AclSpecs.Builder aclSpec : aclSpecs) { if (aclSpec.getAcl().equals(currentAcl)) { aclSpec.addSource(hostname, aclName); added = true; break; } } if (!added) { aclSpecs.add(AclSpecs.builder().setAcl(currentAcl).addSource(hostname, aclName)); } } } } return aclSpecs.stream().map(AclSpecs.Builder::build).collect(Collectors.toList()); } }
FilterLineReachabilityAnswerer extends Answerer { @VisibleForTesting static List<AclSpecs> getAclSpecs( SortedMap<String, Configuration> configurations, Map<String, Set<IpAccessList>> specifiedAcls, FilterLineReachabilityRows answer) { List<AclSpecs.Builder> aclSpecs = new ArrayList<>(); for (String hostname : configurations.keySet()) { if (specifiedAcls.containsKey(hostname)) { Configuration c = configurations.get(hostname); Set<IpAccessList> acls = specifiedAcls.get(hostname); HeaderSpaceSanitizer headerSpaceSanitizer = new HeaderSpaceSanitizer(c.getIpSpaces()); Map<String, Interface> nodeInterfaces = c.getAllInterfaces(); Map<String, AclNode> aclNodeMap = new TreeMap<>(); for (IpAccessList acl : acls) { String aclName = acl.getName(); if (!aclNodeMap.containsKey(aclName)) { createAclNode( acl, aclNodeMap, c.getIpAccessLists(), headerSpaceSanitizer, nodeInterfaces.keySet()); } } Set<String> sanitizedAcls = new TreeSet<>(); for (AclNode node : aclNodeMap.values()) { if (!sanitizedAcls.contains(node.getName())) { List<ImmutableList<String>> cycles = sanitizeNode(node, new ArrayList<>(), sanitizedAcls, aclNodeMap); for (ImmutableList<String> cycleAcls : cycles) { answer.addCycle(hostname, cycleAcls); } } } for (IpAccessList acl : acls) { String aclName = acl.getName(); AclNode node = aclNodeMap.get(aclName); Set<String> referencedInterfaces = node.getInterfaceDependencies(); if (referencedInterfaces.size() < nodeInterfaces.size()) { String unreferencedIfaceName = "unreferencedInterface"; int n = 0; while (referencedInterfaces.contains(unreferencedIfaceName)) { unreferencedIfaceName = "unreferencedInterface" + n; n++; } referencedInterfaces = new TreeSet<>(referencedInterfaces); referencedInterfaces.add(unreferencedIfaceName); } CanonicalAcl currentAcl = new CanonicalAcl( node.getSanitizedAcl(), node.getAcl(), node.getFlatDependencies(), referencedInterfaces, node.getLinesWithUndefinedRefs(), node.getLinesInCycles()); boolean added = false; for (AclSpecs.Builder aclSpec : aclSpecs) { if (aclSpec.getAcl().equals(currentAcl)) { aclSpec.addSource(hostname, aclName); added = true; break; } } if (!added) { aclSpecs.add(AclSpecs.builder().setAcl(currentAcl).addSource(hostname, aclName)); } } } } return aclSpecs.stream().map(AclSpecs.Builder::build).collect(Collectors.toList()); } FilterLineReachabilityAnswerer(Question question, IBatfish batfish); }
FilterLineReachabilityAnswerer extends Answerer { @VisibleForTesting static List<AclSpecs> getAclSpecs( SortedMap<String, Configuration> configurations, Map<String, Set<IpAccessList>> specifiedAcls, FilterLineReachabilityRows answer) { List<AclSpecs.Builder> aclSpecs = new ArrayList<>(); for (String hostname : configurations.keySet()) { if (specifiedAcls.containsKey(hostname)) { Configuration c = configurations.get(hostname); Set<IpAccessList> acls = specifiedAcls.get(hostname); HeaderSpaceSanitizer headerSpaceSanitizer = new HeaderSpaceSanitizer(c.getIpSpaces()); Map<String, Interface> nodeInterfaces = c.getAllInterfaces(); Map<String, AclNode> aclNodeMap = new TreeMap<>(); for (IpAccessList acl : acls) { String aclName = acl.getName(); if (!aclNodeMap.containsKey(aclName)) { createAclNode( acl, aclNodeMap, c.getIpAccessLists(), headerSpaceSanitizer, nodeInterfaces.keySet()); } } Set<String> sanitizedAcls = new TreeSet<>(); for (AclNode node : aclNodeMap.values()) { if (!sanitizedAcls.contains(node.getName())) { List<ImmutableList<String>> cycles = sanitizeNode(node, new ArrayList<>(), sanitizedAcls, aclNodeMap); for (ImmutableList<String> cycleAcls : cycles) { answer.addCycle(hostname, cycleAcls); } } } for (IpAccessList acl : acls) { String aclName = acl.getName(); AclNode node = aclNodeMap.get(aclName); Set<String> referencedInterfaces = node.getInterfaceDependencies(); if (referencedInterfaces.size() < nodeInterfaces.size()) { String unreferencedIfaceName = "unreferencedInterface"; int n = 0; while (referencedInterfaces.contains(unreferencedIfaceName)) { unreferencedIfaceName = "unreferencedInterface" + n; n++; } referencedInterfaces = new TreeSet<>(referencedInterfaces); referencedInterfaces.add(unreferencedIfaceName); } CanonicalAcl currentAcl = new CanonicalAcl( node.getSanitizedAcl(), node.getAcl(), node.getFlatDependencies(), referencedInterfaces, node.getLinesWithUndefinedRefs(), node.getLinesInCycles()); boolean added = false; for (AclSpecs.Builder aclSpec : aclSpecs) { if (aclSpec.getAcl().equals(currentAcl)) { aclSpec.addSource(hostname, aclName); added = true; break; } } if (!added) { aclSpecs.add(AclSpecs.builder().setAcl(currentAcl).addSource(hostname, aclName)); } } } } return aclSpecs.stream().map(AclSpecs.Builder::build).collect(Collectors.toList()); } FilterLineReachabilityAnswerer(Question question, IBatfish batfish); @Override TableAnswerElement answer(NetworkSnapshot snapshot); }
FilterLineReachabilityAnswerer extends Answerer { @VisibleForTesting static List<AclSpecs> getAclSpecs( SortedMap<String, Configuration> configurations, Map<String, Set<IpAccessList>> specifiedAcls, FilterLineReachabilityRows answer) { List<AclSpecs.Builder> aclSpecs = new ArrayList<>(); for (String hostname : configurations.keySet()) { if (specifiedAcls.containsKey(hostname)) { Configuration c = configurations.get(hostname); Set<IpAccessList> acls = specifiedAcls.get(hostname); HeaderSpaceSanitizer headerSpaceSanitizer = new HeaderSpaceSanitizer(c.getIpSpaces()); Map<String, Interface> nodeInterfaces = c.getAllInterfaces(); Map<String, AclNode> aclNodeMap = new TreeMap<>(); for (IpAccessList acl : acls) { String aclName = acl.getName(); if (!aclNodeMap.containsKey(aclName)) { createAclNode( acl, aclNodeMap, c.getIpAccessLists(), headerSpaceSanitizer, nodeInterfaces.keySet()); } } Set<String> sanitizedAcls = new TreeSet<>(); for (AclNode node : aclNodeMap.values()) { if (!sanitizedAcls.contains(node.getName())) { List<ImmutableList<String>> cycles = sanitizeNode(node, new ArrayList<>(), sanitizedAcls, aclNodeMap); for (ImmutableList<String> cycleAcls : cycles) { answer.addCycle(hostname, cycleAcls); } } } for (IpAccessList acl : acls) { String aclName = acl.getName(); AclNode node = aclNodeMap.get(aclName); Set<String> referencedInterfaces = node.getInterfaceDependencies(); if (referencedInterfaces.size() < nodeInterfaces.size()) { String unreferencedIfaceName = "unreferencedInterface"; int n = 0; while (referencedInterfaces.contains(unreferencedIfaceName)) { unreferencedIfaceName = "unreferencedInterface" + n; n++; } referencedInterfaces = new TreeSet<>(referencedInterfaces); referencedInterfaces.add(unreferencedIfaceName); } CanonicalAcl currentAcl = new CanonicalAcl( node.getSanitizedAcl(), node.getAcl(), node.getFlatDependencies(), referencedInterfaces, node.getLinesWithUndefinedRefs(), node.getLinesInCycles()); boolean added = false; for (AclSpecs.Builder aclSpec : aclSpecs) { if (aclSpec.getAcl().equals(currentAcl)) { aclSpec.addSource(hostname, aclName); added = true; break; } } if (!added) { aclSpecs.add(AclSpecs.builder().setAcl(currentAcl).addSource(hostname, aclName)); } } } } return aclSpecs.stream().map(AclSpecs.Builder::build).collect(Collectors.toList()); } FilterLineReachabilityAnswerer(Question question, IBatfish batfish); @Override TableAnswerElement answer(NetworkSnapshot snapshot);  }