use of org.batfish.z3.expr.BasicRuleStatement in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testVisitPreOut.
@Test
public void testVisitPreOut() {
SynthesizerInput input = MockSynthesizerInput.builder().setIpsByHostname(ImmutableMap.of(NODE1, ImmutableSet.of(IP1, IP2), NODE2, ImmutableSet.of(IP3, IP4))).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOut.State.INSTANCE)));
// PostInNotMine
assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP1), new IpWildcard(IP2)))), ImmutableSet.of(new PostIn(NODE1)), new PreOut(NODE1))));
assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP3), new IpWildcard(IP4)))), ImmutableSet.of(new PostIn(NODE2)), new PreOut(NODE2))));
}
use of org.batfish.z3.expr.BasicRuleStatement in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testVisitNodeAccept.
@Test
public void testVisitNodeAccept() {
SynthesizerInput input = MockSynthesizerInput.builder().setEnabledNodes(ImmutableSet.of(NODE1, NODE2)).setIpsByHostname(ImmutableMap.of(NODE1, ImmutableSet.of(IP1, IP2), NODE2, ImmutableSet.of(IP3, IP4))).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeAccept.State.INSTANCE)));
// PostInForMe
assertThat(rules, hasItem(new BasicRuleStatement(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP1), new IpWildcard(IP2))), ImmutableSet.of(new PostIn(NODE1)), new NodeAccept(NODE1))));
assertThat(rules, hasItem(new BasicRuleStatement(HeaderSpaceMatchExpr.matchDstIp(ImmutableSet.of(new IpWildcard(IP3), new IpWildcard(IP4))), ImmutableSet.of(new PostIn(NODE2)), new NodeAccept(NODE2))));
}
use of org.batfish.z3.expr.BasicRuleStatement in project batfish by batfish.
the class Simplifier method visitBasicRuleStatement.
@Override
public Statement visitBasicRuleStatement(BasicRuleStatement basicRuleStatement) {
/**
* TODO: something smarter
*/
BooleanExpr originalPreconditionStateIndependentConstraints = basicRuleStatement.getPreconditionStateIndependentConstraints();
BooleanExpr simplifiedPreconditionStateIndependentConstraints = simplifyBooleanExpr(originalPreconditionStateIndependentConstraints);
if (originalPreconditionStateIndependentConstraints != simplifiedPreconditionStateIndependentConstraints) {
return simplifyStatement(new BasicRuleStatement(simplifiedPreconditionStateIndependentConstraints, basicRuleStatement.getPreconditionStates(), basicRuleStatement.getPostconditionState()));
} else if (simplifiedPreconditionStateIndependentConstraints == FalseExpr.INSTANCE) {
return VACUOUS_RULE;
} else {
return basicRuleStatement;
}
}
use of org.batfish.z3.expr.BasicRuleStatement in project batfish by batfish.
the class DefaultTransitionGenerator method visitAclDeny.
@Override
public void visitAclDeny(AclDeny.State aclDeny) {
// MatchDenyLine
_input.getAclActions().forEach((node, nodeAcls) -> nodeAcls.forEach((acl, linesActions) -> {
int lineNumber = 0;
for (LineAction linesAction : linesActions) {
if (linesAction == LineAction.REJECT) {
_rules.add(new BasicRuleStatement(new AclLineMatch(node, acl, lineNumber), new AclDeny(node, acl)));
}
lineNumber++;
}
}));
// MatchNoLines
_input.getAclActions().entrySet().stream().flatMap(aclActionsEntryByNode -> {
String hostname = aclActionsEntryByNode.getKey();
return aclActionsEntryByNode.getValue().entrySet().stream().map(aclActionsEntryByAclName -> {
String acl = aclActionsEntryByAclName.getKey();
List<LineAction> lineActions = aclActionsEntryByAclName.getValue();
AclDeny deny = new AclDeny(hostname, acl);
if (lineActions.isEmpty()) {
return new BasicRuleStatement(deny);
} else {
int lastLine = lineActions.size() - 1;
return new BasicRuleStatement(new AclLineNoMatch(hostname, acl, lastLine), deny);
}
});
}).forEach(_rules::add);
}
use of org.batfish.z3.expr.BasicRuleStatement in project batfish by batfish.
the class DefaultTransitionGenerator method visitNodeDrop.
@Override
public void visitNodeDrop(NodeDrop.State nodeDrop) {
// CopyNodeDropAcl
_input.getEnabledNodes().stream().map(hostname -> new BasicRuleStatement(new NodeDropAcl(hostname), new NodeDrop(hostname))).forEach(_rules::add);
// CopyNodeDropNoRoute
_input.getEnabledNodes().stream().map(hostname -> new BasicRuleStatement(new NodeDropNoRoute(hostname), new NodeDrop(hostname))).forEach(_rules::add);
// CopyNodeDropNullRoute
_input.getEnabledNodes().stream().map(hostname -> new BasicRuleStatement(new NodeDropNullRoute(hostname), new NodeDrop(hostname))).forEach(_rules::add);
}
Aggregations