use of org.batfish.z3.state.NodeDropAclOut in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testVisitDropAclOut.
@Test
public void testVisitDropAclOut() {
SynthesizerInput input = MockSynthesizerInput.builder().setEnabledNodes(ImmutableSet.of(NODE1, NODE2)).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(DropAclOut.State.INSTANCE)));
assertThat(rules, hasItem(new BasicRuleStatement(new NodeDropAclOut(NODE1), DropAclOut.INSTANCE)));
assertThat(rules, hasItem(new BasicRuleStatement(new NodeDropAclOut(NODE2), DropAclOut.INSTANCE)));
}
use of org.batfish.z3.state.NodeDropAclOut in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testVisitNodeDropAcl.
@Test
public void testVisitNodeDropAcl() {
SynthesizerInput input = MockSynthesizerInput.builder().setEnabledNodes(ImmutableSet.of(NODE1, NODE2)).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeDropAcl.State.INSTANCE)));
Set<RuleStatement> expectedCopyNodeDropAclIn = ImmutableSet.of(new BasicRuleStatement(new NodeDropAclIn(NODE1), new NodeDropAcl(NODE1)), new BasicRuleStatement(new NodeDropAclIn(NODE2), new NodeDropAcl(NODE2)));
Set<RuleStatement> expectedCopyNodeDropAclOut = ImmutableSet.of(new BasicRuleStatement(new NodeDropAclOut(NODE1), new NodeDropAcl(NODE1)), new BasicRuleStatement(new NodeDropAclOut(NODE2), new NodeDropAcl(NODE2)));
assertThat(rules, equalTo(Sets.union(expectedCopyNodeDropAclIn, expectedCopyNodeDropAclOut)));
}
use of org.batfish.z3.state.NodeDropAclOut in project batfish by batfish.
the class DefaultTransitionGenerator method visitNodeDropAcl.
@Override
public void visitNodeDropAcl(NodeDropAcl.State nodeDropAcl) {
// CopyNodeDropAclIn
_input.getEnabledNodes().stream().map(hostname -> new BasicRuleStatement(new NodeDropAclIn(hostname), new NodeDropAcl(hostname))).forEach(_rules::add);
// CopyNodeDropAclOut
_input.getEnabledNodes().stream().map(hostname -> new BasicRuleStatement(new NodeDropAclOut(hostname), new NodeDropAcl(hostname))).forEach(_rules::add);
}
use of org.batfish.z3.state.NodeDropAclOut in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testVisitNodeDropAclOut.
@Test
public void testVisitNodeDropAclOut() {
SynthesizerInput input = MockSynthesizerInput.builder().setEnabledEdges(ImmutableSet.of(new Edge(NODE1, INTERFACE1, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE2), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE2))).setOutgoingAcls(ImmutableMap.of(NODE1, ImmutableMap.of(INTERFACE1, ACL1), NODE2, ImmutableMap.of(INTERFACE1, ACL1, INTERFACE2, ACL2))).setSourceNats(ImmutableMap.of(NODE1, ImmutableMap.of(INTERFACE1, ImmutableList.of(Maps.immutableEntry(new AclPermit(NODE1, NAT_ACL1), TrueExpr.INSTANCE), Maps.immutableEntry(new AclPermit(NODE1, NAT_ACL2), FalseExpr.INSTANCE)), INTERFACE2, ImmutableList.of(Maps.immutableEntry(new AclPermit(NODE1, NAT_ACL1), TrueExpr.INSTANCE), Maps.immutableEntry(new AclPermit(NODE1, NAT_ACL2), FalseExpr.INSTANCE))), NODE2, ImmutableMap.of(INTERFACE1, ImmutableList.of(Maps.immutableEntry(new AclPermit(NODE2, NAT_ACL1), TrueExpr.INSTANCE), Maps.immutableEntry(new AclPermit(NODE2, NAT_ACL1), FalseExpr.INSTANCE)), INTERFACE2, ImmutableList.of()))).setTopologyInterfaces(ImmutableMap.of(NODE1, ImmutableSet.of(INTERFACE1, INTERFACE2), NODE2, ImmutableSet.of(INTERFACE1, INTERFACE2))).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeDropAclOut.State.INSTANCE)));
// Just test the DropAclOut rules for Node2
Set<RuleStatement> node2DropAclOutRules = rules.stream().map(BasicRuleStatement.class::cast).filter(rule -> rule.getPostconditionState().equals(new NodeDropAclOut(NODE2))).collect(Collectors.toSet());
// FailOutgoingAclNoMatchSrcNat
assertThat(node2DropAclOutRules, containsInAnyOrder(new BasicRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(new AclDeny(NODE2, ACL1), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE1)), new NodeDropAclOut(NODE2)), new BasicRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(new AclDeny(NODE2, ACL2), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE2)), new NodeDropAclOut(NODE2))));
}
use of org.batfish.z3.state.NodeDropAclOut 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)));
}
});
}
Aggregations