@Override protected String featureValueOf(Edge edge) { return edge.getInt1(); } }
private Map<String, Set<String>> computeTopologyInterfaces() { Map<String, Set<String>> topologyEdges = new HashMap<>(); _enabledEdges.forEach( enabledEdge -> topologyEdges .computeIfAbsent(enabledEdge.getNode1(), n -> new HashSet<>()) .add(enabledEdge.getInt1())); // freeze return toImmutableMap(topologyEdges, Entry::getKey, e -> ImmutableSet.copyOf(e.getValue())); }
private Set<Edge> computeEnabledEdges() { return _edges.stream() .filter( e -> { Set<String> enabledInterfaces1 = _enabledInterfaces.get(e.getNode1()); Set<String> enabledInterfaces2 = _enabledInterfaces.get(e.getNode2()); return enabledInterfaces1 != null && enabledInterfaces1.contains(e.getInt1()) && enabledInterfaces2 != null && enabledInterfaces2.contains(e.getInt2()); }) .collect(ImmutableSet.toImmutableSet()); }
private static SortedSet<VerboseEdge> getLayer3Edges( Map<String, Configuration> configs, Topology topology) { SortedSet<VerboseEdge> layer3Edges = new TreeSet<>(); for (Edge edge : topology.getEdges()) { Configuration n1 = configs.get(edge.getNode1()); Interface i1 = n1.getAllInterfaces().get(edge.getInt1()); Configuration n2 = configs.get(edge.getNode2()); Interface i2 = n2.getAllInterfaces().get(edge.getInt2()); layer3Edges.add(new VerboseEdge(i1, i2, edge)); } return layer3Edges; }
public PostOutEdge(Edge edge) { this(edge.getNode1(), edge.getInt1(), edge.getNode2(), edge.getInt2()); }
@VisibleForTesting Map<Edge, IpSpace> computeArpTrueEdgeNextHopIp( Map<String, Configuration> configurations, Map<String, Map<String, Map<Prefix, IpSpace>>> matchingIps) { try (ActiveSpan span = GlobalTracer.get() .buildSpan("ForwardingAnalysisImpl.computeArpTrueEdgeNextHopIp") .startActive()) { assert span != null; // avoid unused warning return _routesWithNextHopIpArpTrue.entrySet().stream() .collect( ImmutableMap.toImmutableMap( Entry::getKey /* edge */, routesWithNextHopIpArpTrueEntry -> { Edge edge = routesWithNextHopIpArpTrueEntry.getKey(); String hostname = edge.getNode1(); String iface = edge.getInt1(); String vrf = configurations.get(hostname).getAllInterfaces().get(iface).getVrfName(); Set<AbstractRoute> routes = routesWithNextHopIpArpTrueEntry.getValue(); return computeRouteMatchConditions(routes, matchingIps.get(hostname).get(vrf)); })); } }
private Stream<Edge> generateRules_PreOutVrf_PreOutEdge() { return _arpTrueEdgeBDDs.entrySet().stream() .map( entry -> { org.batfish.datamodel.Edge edge = entry.getKey(); BDD arpTrue = entry.getValue(); String node1 = edge.getNode1(); String iface1 = edge.getInt1(); String vrf1 = ifaceVrf(edge.getNode1(), edge.getInt1()); String node2 = edge.getNode2(); String iface2 = edge.getInt2(); return new Edge( new PreOutVrf(node1, vrf1), new PreOutEdge(node1, iface1, node2, iface2), arpTrue); }); }
public PreOutEdge(Edge edge) { this(edge.getNode1(), edge.getInt1(), edge.getNode2(), edge.getInt2()); }
@VisibleForTesting Map<String, Map<String, IpSpace>> computeSomeoneReplies(Topology topology) { try (ActiveSpan span = GlobalTracer.get() .buildSpan("ForwardingAnalysisImpl.computeSomeoneReplies") .startActive()) { assert span != null; // avoid unused warning Map<String, Map<String, AclIpSpace.Builder>> someoneRepliesByNode = new HashMap<>(); topology .getEdges() .forEach( edge -> someoneRepliesByNode .computeIfAbsent(edge.getNode1(), n -> new HashMap<>()) .computeIfAbsent(edge.getInt1(), i -> AclIpSpace.builder()) .thenPermitting((_arpReplies.get(edge.getNode2()).get(edge.getInt2())))); return someoneRepliesByNode.entrySet().stream() .collect( ImmutableMap.toImmutableMap( Entry::getKey /* hostname */, someoneRepliesByNodeEntry -> someoneRepliesByNodeEntry.getValue().entrySet().stream() .collect( ImmutableMap.toImmutableMap( Entry::getKey /* interface */, someoneRepliesByInterfaceEntry -> someoneRepliesByInterfaceEntry.getValue().build())))); } }
@VisibleForTesting static Row layer3EdgeToRow(Map<String, Configuration> configurations, Edge edge) { Interface interface1 = configurations.get(edge.getNode1()).getAllInterfaces().get(edge.getInt1()); Interface interface2 = configurations.get(edge.getNode2()).getAllInterfaces().get(edge.getInt2()); Set<Ip> ips1 = interface1.getAllAddresses().stream() .filter(Objects::nonNull) .map(InterfaceAddress::getIp) .collect(Collectors.toSet()); Set<Ip> ips2 = interface2.getAllAddresses().stream() .filter(Objects::nonNull) .map(InterfaceAddress::getIp) .collect(Collectors.toSet()); RowBuilder row = Row.builder(); row.put(COL_INTERFACE, new NodeInterfacePair(edge.getNode1(), edge.getInt1())) .put(COL_IPS, ips1) .put(COL_REMOTE_INTERFACE, new NodeInterfacePair(edge.getNode2(), edge.getInt2())) .put(COL_REMOTE_IPS, ips2); return row.build(); }
@Override public void visitPreOutEdgePostNat(PreOutEdgePostNat.State preOutEdgePostNat) { _input.getEnabledEdges().stream() .flatMap( edge -> { String node1 = edge.getNode1(); String node2 = edge.getNode2(); String iface1 = edge.getInt1(); String iface2 = edge.getInt2(); PreOutEdge preState = new PreOutEdge(node1, iface1, node2, iface2); StateExpr postState = new PreOutEdgePostNat(node1, iface1, node2, iface2); return TransformationTransitionGenerator.generateTransitions( node1, iface1, node2, iface2, "OUTGOING", _input.getAclLineMatchExprToBooleanExprs().get(node1), preState, postState, _input .getOutgoingTransformations() .getOrDefault(node1, ImmutableMap.of()) .get(iface1)) .stream(); }) .forEach(_rules::add); }
Set<AbstractRoute> routes = routesWithDestIpEdgeEntry.getValue(); String hostname = edge.getNode1(); String iface = edge.getInt1(); String vrf = configurations.get(hostname).getAllInterfaces().get(iface).getVrfName();
private Stream<Edge> generateRules_PreOutEdge_PreOutEdgePostNat() { return _forwardingAnalysis.getArpTrueEdge().keySet().stream() .flatMap( edge -> { String node1 = edge.getNode1(); String iface1 = edge.getInt1(); String node2 = edge.getNode2(); String iface2 = edge.getInt2(); String preNatAcl = _configs .get(node1) .getAllInterfaces() .get(iface1) .getPreTransformationOutgoingFilterName(); BDD aclPermit = ignorableAclPermitBDD(node1, preNatAcl); if (aclPermit.equals(_zero)) { return Stream.of(); } PreOutEdge preState = new PreOutEdge(node1, iface1, node2, iface2); PreOutEdgePostNat postState = new PreOutEdgePostNat(node1, iface1, node2, iface2); Transition transition = compose( constraint(aclPermit), _bddOutgoingTransformations.get(node1).get(iface1)); return Stream.of(new Edge(preState, postState, transition)); }); }
private Stream<Edge> generateRules_PreOutEdgePostNat_NodeDropAclOut() { if (_ignoreFilters) { return Stream.of(); } return _forwardingAnalysis.getArpTrueEdge().keySet().stream() .flatMap( edge -> { String node1 = edge.getNode1(); String iface1 = edge.getInt1(); String node2 = edge.getNode2(); String iface2 = edge.getInt2(); String aclName = _configs.get(node1).getAllInterfaces().get(iface1).getOutgoingFilterName(); if (aclName == null) { return Stream.of(); } BDD aclDenyBDD = ignorableAclDenyBDD(node1, aclName); return Stream.of( new Edge( new PreOutEdgePostNat(node1, iface1, node2, iface2), new NodeDropAclOut(node1), validSource(aclDenyBDD, node1), eraseSourceAfter(aclDenyBDD, node1))); }); }
private Stream<Edge> generateRules_PreOutEdge_NodeDropAclOut() { if (_ignoreFilters) { return Stream.of(); } return _forwardingAnalysis.getArpTrueEdge().keySet().stream() .flatMap( edge -> { String node1 = edge.getNode1(); String iface1 = edge.getInt1(); String node2 = edge.getNode2(); String iface2 = edge.getInt2(); String preNatAcl = _configs .get(node1) .getAllInterfaces() .get(iface1) .getPreTransformationOutgoingFilterName(); BDD denyPreNat = ignorableAclDenyBDD(node1, preNatAcl); if (denyPreNat.equals(_zero)) { return Stream.of(); } return Stream.of( exitNode( node1, new Edge( new PreOutEdge(node1, iface1, node2, iface2), new NodeDropAclOut(node1), denyPreNat))); }); }
static void checkTopology(Map<String, Configuration> configurations, Topology topology) { for (Edge edge : topology.getEdges()) { if (!configurations.containsKey(edge.getNode1())) { throw new BatfishException( String.format("Topology contains a non-existent node '%s'", edge.getNode1())); } if (!configurations.containsKey(edge.getNode2())) { throw new BatfishException( String.format("Topology contains a non-existent node '%s'", edge.getNode2())); } // nodes are valid, now checking corresponding interfaces Configuration config1 = configurations.get(edge.getNode1()); Configuration config2 = configurations.get(edge.getNode2()); if (!config1.getAllInterfaces().containsKey(edge.getInt1())) { throw new BatfishException( String.format( "Topology contains a non-existent interface '%s' on node '%s'", edge.getInt1(), edge.getNode1())); } if (!config2.getAllInterfaces().containsKey(edge.getInt2())) { throw new BatfishException( String.format( "Topology contains a non-existent interface '%s' on node '%s'", edge.getInt2(), edge.getNode2())); } } }
private Stream<Edge> generateRules_PreOutEdgePostNat_PreInInterface() { return _forwardingAnalysis.getArpTrueEdge().keySet().stream() .map( edge -> { String node1 = edge.getNode1(); String iface1 = edge.getInt1(); String node2 = edge.getNode2(); String iface2 = edge.getInt2(); BDD aclPermitBDD = ignorableAclPermitBDD( node1, _configs.get(node1).getAllInterfaces().get(iface1).getOutgoingFilterName()); assert aclPermitBDD != null; return new Edge( new PreOutEdgePostNat(node1, iface1, node2, iface2), new PreInInterface(node2, iface2), preInInterfaceBackward(aclPermitBDD, node1, node2, iface2), preInInterfaceForward(aclPermitBDD, node2, iface2)); }); }
continue; String fromIface = edge.getInt1(); String toNode = edge.getNode2(); String toIface = edge.getInt2();
@Test public void testGetterEquivalence() { assertThat(EDGE.getNode1(), equalTo(EDGE.getTail().getHostname())); assertThat(EDGE.getNode2(), equalTo(EDGE.getHead().getHostname())); assertThat(EDGE.getInt1(), equalTo(EDGE.getTail().getInterface())); assertThat(EDGE.getInt2(), equalTo(EDGE.getHead().getInterface())); }
/** Return an {@link EigrpEdge} if there is an EIGRP adjacency on {@code edge}. */ @Nonnull static Optional<EigrpEdge> edgeIfAdjacent(Edge edge, Map<String, Configuration> configurations) { // vertex1 Configuration c1 = configurations.get(edge.getNode1()); Interface iface1 = c1.getAllInterfaces().get(edge.getInt1()); EigrpInterfaceSettings eigrp1 = iface1.getEigrp(); // vertex2 Configuration c2 = configurations.get(edge.getNode2()); Interface iface2 = c2.getAllInterfaces().get(edge.getInt2()); EigrpInterfaceSettings eigrp2 = iface2.getEigrp(); if (eigrp1 == null || eigrp2 == null || !eigrp1.getEnabled() || !eigrp2.getEnabled() || eigrp1.getAsn() != eigrp2.getAsn() || eigrp1.getPassive() || eigrp2.getPassive()) { return empty(); } return Optional.of( new EigrpEdge( new EigrpInterface(c1.getHostname(), iface1), new EigrpInterface(c2.getHostname(), iface2))); }