use of org.batfish.z3.expr.IpSpaceMatchExpr in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeNeighborUnreachable.
@Test
public void testComputeNeighborUnreachable() {
Configuration node = _cb.build();
Vrf vrf = _vb.setOwner(node).build();
Interface iface1 = _ib.setOwner(node).setVrf(vrf).build();
Interface iface2 = _ib.build();
IpSpace ipSpace1 = Ip.ZERO;
IpSpace ipSpace2 = Ip.MAX;
IpSpaceMatchExpr m1 = new IpSpaceMatchExpr(ipSpace1, false, true);
IpSpaceMatchExpr m2 = new IpSpaceMatchExpr(ipSpace2, false, true);
SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(node.getName(), node)).build();
SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().setNeighborUnreachable(ImmutableMap.of(node.getName(), ImmutableMap.of(vrf.getName(), ImmutableMap.of(iface1.getName(), ipSpace1, iface2.getName(), ipSpace2)))).build()).setTopology(new Topology(ImmutableSortedSet.of())).build();
assertThat(inputWithoutDataPlane, hasNeighborUnreachable(nullValue()));
assertThat(inputWithDataPlane, hasNeighborUnreachable(equalTo(ImmutableMap.of(node.getHostname(), ImmutableMap.of(vrf.getName(), ImmutableMap.of(iface1.getName(), m1, iface2.getName(), m2))))));
}
use of org.batfish.z3.expr.IpSpaceMatchExpr in project batfish by batfish.
the class SynthesizerInputImplTest method testComputeArpTrueEdge.
@Test
public void testComputeArpTrueEdge() {
Configuration srcNode = _cb.build();
Vrf srcVrf = _vb.setOwner(srcNode).build();
Interface srcInterface = _ib.setOwner(srcNode).setVrf(srcVrf).build();
String nextHop1 = "nextHop1";
String nextHopInterface1 = "nextHopInterface1";
String nextHop2 = "nextHop2";
String nextHopInterface2 = "nextHopInterface2";
IpSpace ipSpace1 = Ip.ZERO;
IpSpace ipSpace2 = Ip.MAX;
IpSpaceMatchExpr m1 = new IpSpaceMatchExpr(ipSpace1, false, true);
IpSpaceMatchExpr m2 = new IpSpaceMatchExpr(ipSpace2, false, true);
Edge edge1 = new Edge(srcNode.getHostname(), srcInterface.getName(), nextHop1, nextHopInterface1);
Edge edge2 = new Edge(srcNode.getHostname(), srcInterface.getName(), nextHop2, nextHopInterface2);
SynthesizerInput inputWithoutDataPlane = _inputBuilder.setConfigurations(ImmutableMap.of(srcNode.getName(), srcNode)).build();
SynthesizerInput inputWithDataPlane = _inputBuilder.setForwardingAnalysis(MockForwardingAnalysis.builder().setArpTrueEdge(ImmutableMap.of(edge1, ipSpace1, edge2, ipSpace2)).build()).setTopology(new Topology(ImmutableSortedSet.of(edge1, edge2))).build();
assertThat(inputWithoutDataPlane, hasArpTrueEdge(nullValue()));
assertThat(inputWithDataPlane, hasArpTrueEdge(equalTo(ImmutableMap.of(srcNode.getHostname(), ImmutableMap.of(srcVrf.getName(), ImmutableMap.of(srcInterface.getName(), ImmutableMap.of(nextHop1, ImmutableMap.of(nextHopInterface1, m1), nextHop2, ImmutableMap.of(nextHopInterface2, m2))))))));
}
use of org.batfish.z3.expr.IpSpaceMatchExpr in project batfish by batfish.
the class SynthesizerInputImpl method computeArpTrueEdge.
private Map<String, Map<String, Map<String, Map<String, Map<String, BooleanExpr>>>>> computeArpTrueEdge(Map<Edge, IpSpace> arpTrueEdge) {
Map<String, Map<String, Map<String, Map<String, Map<String, BooleanExpr>>>>> output = new HashMap<>();
arpTrueEdge.forEach((edge, ipSpace) -> {
ipSpace = _ipSpaceSpecializer.specialize(ipSpace);
if (ipSpace instanceof EmptyIpSpace) {
return;
}
String hostname = edge.getNode1();
String outInterface = edge.getInt1();
String vrf = _configurations.get(hostname).getInterfaces().get(outInterface).getVrfName();
String recvNode = edge.getNode2();
String recvInterface = edge.getInt2();
output.computeIfAbsent(hostname, n -> new HashMap<>()).computeIfAbsent(vrf, n -> new HashMap<>()).computeIfAbsent(outInterface, n -> new HashMap<>()).computeIfAbsent(recvNode, n -> new HashMap<>()).put(recvInterface, new IpSpaceMatchExpr(ipSpace, false, true));
});
// freeze
return toImmutableMap(output, Entry::getKey, /* node */
outputByHostnameEntry -> toImmutableMap(outputByHostnameEntry.getValue(), Entry::getKey, /* vrf */
outputByVrfEntry -> toImmutableMap(outputByVrfEntry.getValue(), Entry::getKey, /* outInterface */
outputByOutInterfaceEntry -> toImmutableMap(outputByOutInterfaceEntry.getValue(), Entry::getKey, /* recvNode */
outputByRecvNodeEntry -> toImmutableMap(outputByRecvNodeEntry.getValue(), Entry::getKey, /* recvInterface */
Entry::getValue)))));
}
Aggregations