use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyAndExprNestedConjuncts.
/**
* Test that nested ANDs get flattened into one AND.
*/
@Test
public void testSimplifyAndExprNestedConjuncts() {
BooleanExpr p1 = newAtom();
BooleanExpr p2 = newAtom();
BooleanExpr p3 = newAtom();
AndExpr leftNested = new AndExpr(of(new AndExpr(of(p1, p2)), p3));
AndExpr rightNested = new AndExpr(of(p1, new AndExpr(of(p2, p3))));
assertThat(leftNested, not(equalTo(rightNested)));
assertThat(simplifyBooleanExpr(leftNested), equalTo(new AndExpr(of(p1, p2, p3))));
assertThat(simplifyBooleanExpr(rightNested), equalTo(new AndExpr(of(p1, p2, p3))));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyOrTrue.
/**
* Test that an OR node with a TRUE child simplifies to TRUE.
*/
@Test
public void testSimplifyOrTrue() {
BooleanExpr p1 = newAtom();
OrExpr or = new OrExpr(of(p1, TrueExpr.INSTANCE));
assertThat(simplifyBooleanExpr(or), equalTo(TrueExpr.INSTANCE));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testPreOutEdgePostNat.
@Test
public void testPreOutEdgePostNat() {
SynthesizerInput input = MockSynthesizerInput.builder().setEnabledEdges(ImmutableSet.of(new Edge(NODE1, INTERFACE1, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE1, NODE2, INTERFACE2), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE2), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE2), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE2))).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOutEdgePostNat.State.INSTANCE)));
BooleanExpr newSrcIpEqualsCurrentSrcIp = new EqExpr(new VarIntExpr(TransformationHeaderField.NEW_SRC_IP), new VarIntExpr(TransformationHeaderField.NEW_SRC_IP.getCurrent()));
// PreOutEdgePostNatForTopologyEdges
assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE1))));
assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE2))));
assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE2, NODE2, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE2, NODE2, INTERFACE1))));
assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE2, NODE2, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE2, NODE2, INTERFACE2))));
assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE1, NODE1, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE1))));
assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE1, NODE1, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE2))));
assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE2, NODE1, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE1))));
assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE2, NODE1, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE2))));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class SynthesizerInputImpl method computeSourceNats.
private Map<String, Map<String, List<Entry<AclPermit, BooleanExpr>>>> computeSourceNats() {
return toImmutableMap(_topologyInterfaces, Entry::getKey, topologyInterfacesEntryByHostname -> {
String hostname = topologyInterfacesEntryByHostname.getKey();
Set<String> ifaces = topologyInterfacesEntryByHostname.getValue();
Configuration c = _configurations.get(hostname);
return toImmutableMap(ifaces, Function.identity(), ifaceName -> c.getInterfaces().get(ifaceName).getSourceNats().stream().map(sourceNat -> {
IpAccessList acl = sourceNat.getAcl();
String aclName = acl == null ? DEFAULT_SOURCE_NAT_ACL.getName() : acl.getName();
AclPermit preconditionPreTransformationState = new AclPermit(hostname, aclName);
BooleanExpr transformationConstraint = new RangeMatchExpr(TransformationHeaderField.NEW_SRC_IP, TransformationHeaderField.NEW_SRC_IP.getSize(), ImmutableSet.of(Range.closed(sourceNat.getPoolIpFirst().asLong(), sourceNat.getPoolIpLast().asLong())));
return Maps.immutableEntry(preconditionPreTransformationState, transformationConstraint);
}).collect(ImmutableList.toImmutableList()));
});
}
use of org.batfish.z3.expr.BooleanExpr 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