use of org.batfish.z3.expr.BasicRuleStatement 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.BasicRuleStatement in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testVisitPostInInterface.
@Test
public void testVisitPostInInterface() {
SynthesizerInput input = MockSynthesizerInput.builder().setIncomingAcls(ImmutableMap.of(NODE1, ImmutableMap.of(INTERFACE1, ACL1, INTERFACE2, ACL2), NODE2, ImmutableMap.of(INTERFACE1, ACL1, INTERFACE2, ACL2))).setTopologyInterfaces(ImmutableMap.of(NODE1, ImmutableSet.of(INTERFACE1, INTERFACE2, INTERFACE3), NODE2, ImmutableSet.of(INTERFACE1, INTERFACE2, INTERFACE3))).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PostInInterface.State.INSTANCE)));
// PassIncomingAcl
assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclPermit(NODE1, ACL1), new PreInInterface(NODE1, INTERFACE1)), new PostInInterface(NODE1, INTERFACE1))));
assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclPermit(NODE1, ACL2), new PreInInterface(NODE1, INTERFACE2)), new PostInInterface(NODE1, INTERFACE2))));
assertThat(rules, hasItem(new BasicRuleStatement(new PreInInterface(NODE1, INTERFACE3), new PostInInterface(NODE1, INTERFACE3))));
assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclPermit(NODE2, ACL1), new PreInInterface(NODE2, INTERFACE1)), new PostInInterface(NODE2, INTERFACE1))));
assertThat(rules, hasItem(new BasicRuleStatement(ImmutableSet.of(new AclPermit(NODE2, ACL2), new PreInInterface(NODE2, INTERFACE2)), new PostInInterface(NODE2, INTERFACE2))));
assertThat(rules, hasItem(new BasicRuleStatement(new PreInInterface(NODE2, INTERFACE3), new PostInInterface(NODE2, INTERFACE3))));
}
use of org.batfish.z3.expr.BasicRuleStatement in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testVisitDropNoRoute.
@Test
public void testVisitDropNoRoute() {
SynthesizerInput input = MockSynthesizerInput.builder().setEnabledNodes(ImmutableSet.of(NODE1, NODE2)).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(DropNoRoute.State.INSTANCE)));
assertThat(rules, hasItem(new BasicRuleStatement(new NodeDropNoRoute(NODE1), DropNoRoute.INSTANCE)));
assertThat(rules, hasItem(new BasicRuleStatement(new NodeDropNoRoute(NODE2), DropNoRoute.INSTANCE)));
}
use of org.batfish.z3.expr.BasicRuleStatement 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.expr.BasicRuleStatement in project batfish by batfish.
the class DefaultTransitionGeneratorTest method testVisitNodeNeighborUnreachable.
@Test
public void testVisitNodeNeighborUnreachable() {
SynthesizerInput input = MockSynthesizerInput.builder().setNeighborUnreachable(ImmutableMap.of(NODE1, ImmutableMap.of(VRF1, ImmutableMap.of(INTERFACE1, b(1), INTERFACE2, b(2)), VRF2, ImmutableMap.of(INTERFACE3, b(3))), NODE2, ImmutableMap.of(VRF1, ImmutableMap.of(INTERFACE1, b(4))))).build();
Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeNeighborUnreachable.State.INSTANCE)));
assertThat(rules, hasItem(new BasicRuleStatement(b(1), ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new NodeNeighborUnreachable(NODE1))));
assertThat(rules, hasItem(new BasicRuleStatement(b(2), ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new NodeNeighborUnreachable(NODE1))));
assertThat(rules, hasItem(new BasicRuleStatement(b(3), ImmutableSet.of(new PostInVrf(NODE1, VRF2), new PreOut(NODE1)), new NodeNeighborUnreachable(NODE1))));
assertThat(rules, hasItem(new BasicRuleStatement(b(4), ImmutableSet.of(new PostInVrf(NODE2, VRF1), new PreOut(NODE2)), new NodeNeighborUnreachable(NODE2))));
}
Aggregations