use of org.batfish.z3.expr.StateExpr in project batfish by batfish.
the class RelationCollectorTest method testVisitQueryStatement.
/**
* Test that collectRelations traverses the child of a QueryStatement.
*/
@Test
public void testVisitQueryStatement() {
StateExpr p1 = newStateExpr();
QueryStatement expr = new QueryStatement(p1);
Set<String> expectedRelations = ImmutableSet.of(getNodName(_input, p1));
assertThat(collectRelations(_input, expr), equalTo(expectedRelations));
}
use of org.batfish.z3.expr.StateExpr in project batfish by batfish.
the class RelationCollectorTest method testVisitBasicRuleStatement.
/**
* Test that collectRelations traverses the child of a BasicRuleStatement.
*/
@Test
public void testVisitBasicRuleStatement() {
StateExpr p1 = newStateExpr();
StateExpr p2 = newStateExpr();
BasicRuleStatement expr1 = new BasicRuleStatement(p1);
Set<String> expectedRelations1 = ImmutableSet.of(getNodName(_input, p1));
BasicRuleStatement expr2 = new BasicRuleStatement(p1, p2);
Set<String> expectedRelations2 = ImmutableSet.of(getNodName(_input, p1), getNodName(_input, p2));
assertThat(collectRelations(_input, expr1), equalTo(expectedRelations1));
assertThat(collectRelations(_input, expr2), equalTo(expectedRelations2));
}
use of org.batfish.z3.expr.StateExpr in project batfish by batfish.
the class DefaultTransitionGenerator method visitNodeDropAclOut.
@Override
public void visitNodeDropAclOut(NodeDropAclOut.State nodeDropAclOut) {
_input.getEnabledEdges().forEach(edge -> {
String node1 = edge.getNode1();
String iface1 = edge.getInt1();
String node2 = edge.getNode2();
String iface2 = edge.getInt2();
String outAcl = _input.getOutgoingAcls().get(node1).get(iface1);
// There has to be an ACL -- no ACL is an implicit Permit.
if (outAcl != null) {
Set<StateExpr> postTransformationPreStates = ImmutableSet.of(new AclDeny(node1, outAcl), new PreOutEdgePostNat(node1, iface1, node2, iface2));
_rules.add(new BasicRuleStatement(TrueExpr.INSTANCE, postTransformationPreStates, new NodeDropAclOut(node1)));
}
});
}
use of org.batfish.z3.expr.StateExpr in project batfish by batfish.
the class DefaultTransitionGenerator method visitPreOutEdgePostNat_generateMatchSourceNatRules.
private void visitPreOutEdgePostNat_generateMatchSourceNatRules(String node1, String iface1, String node2, String iface2) {
List<Entry<AclPermit, BooleanExpr>> sourceNats = _input.getSourceNats().get(node1).get(iface1);
for (int natNumber = 0; natNumber < sourceNats.size(); natNumber++) {
ImmutableSet.Builder<StateExpr> preStates = ImmutableSet.builder();
preStates.add(new PreOutEdge(node1, iface1, node2, iface2));
// does not match any previous source NAT.
sourceNats.subList(0, natNumber).stream().map(Entry::getKey).map(aclPermit -> new AclDeny(aclPermit.getHostname(), aclPermit.getAcl())).forEach(preStates::add);
// does match the current source NAT.
preStates.add(sourceNats.get(natNumber).getKey());
BooleanExpr transformationExpr = sourceNats.get(natNumber).getValue();
_rules.add(new TransformationRuleStatement(transformationExpr, preStates.build(), ImmutableSet.of(), new PreOutEdgePostNat(node1, iface1, node2, iface2)));
}
}
use of org.batfish.z3.expr.StateExpr in project batfish by batfish.
the class StandardReachabilityQuerySynthesizer method getReachabilityProgram.
@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
List<StateExpr> finalActions = computeFinalActions();
ImmutableList.Builder<BooleanExpr> queryPreconditions = ImmutableList.<BooleanExpr>builder().add(SaneExpr.INSTANCE).add(getSrcNattedConstraint());
finalActions.stream().map(finalAction -> new BasicRuleStatement(new AndExpr(queryPreconditions.build()), ImmutableSet.of(finalAction), Query.INSTANCE)).forEach(rules::add);
addOriginateRules(rules);
return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(rules.build()).build();
}
Aggregations