Search in sources :

Example 6 with NotExpr

use of org.batfish.z3.expr.NotExpr in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testVisitAclLineNoMatch.

@Test
public void testVisitAclLineNoMatch() {
    SynthesizerInput input = MockSynthesizerInput.builder().setAclConditions(aclConditions()).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(AclLineNoMatch.State.INSTANCE)));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), new AclLineNoMatch(NODE1, ACL1, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 0)), new AclLineNoMatch(NODE1, ACL1, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 1)), new AclLineNoMatch(NODE1, ACL1, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL1, 2)), new AclLineNoMatch(NODE1, ACL1, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), new AclLineNoMatch(NODE1, ACL2, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 0)), new AclLineNoMatch(NODE1, ACL2, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 1)), new AclLineNoMatch(NODE1, ACL2, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE1, ACL2, 2)), new AclLineNoMatch(NODE1, ACL2, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), new AclLineNoMatch(NODE2, ACL1, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 0)), new AclLineNoMatch(NODE2, ACL1, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 1)), new AclLineNoMatch(NODE2, ACL1, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL1, 2)), new AclLineNoMatch(NODE2, ACL1, 3))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), new AclLineNoMatch(NODE2, ACL2, 0))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 0)), new AclLineNoMatch(NODE2, ACL2, 1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(FalseExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 1)), new AclLineNoMatch(NODE2, ACL2, 2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(TrueExpr.INSTANCE), ImmutableSet.of(new AclLineNoMatch(NODE2, ACL2, 2)), new AclLineNoMatch(NODE2, ACL2, 3))));
}
Also used : MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NotExpr(org.batfish.z3.expr.NotExpr) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 7 with NotExpr

use of org.batfish.z3.expr.NotExpr in project batfish by batfish.

the class DefaultTransitionGeneratorTest method testVisitNodeDropNoRoute.

@Test
public void testVisitNodeDropNoRoute() {
    SynthesizerInput input = MockSynthesizerInput.builder().setRoutableIps(ImmutableMap.of(NODE1, ImmutableMap.of(VRF1, B1, VRF2, B2), NODE2, ImmutableMap.of(VRF1, B1, VRF2, B2))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeDropNoRoute.State.INSTANCE)));
    // DestinationRouting
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(B1), ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new NodeDropNoRoute(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(B2), ImmutableSet.of(new PostInVrf(NODE1, VRF2), new PreOut(NODE1)), new NodeDropNoRoute(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(B1), ImmutableSet.of(new PostInVrf(NODE2, VRF1), new PreOut(NODE2)), new NodeDropNoRoute(NODE2))));
    assertThat(rules, hasItem(new BasicRuleStatement(new NotExpr(B2), ImmutableSet.of(new PostInVrf(NODE2, VRF2), new PreOut(NODE2)), new NodeDropNoRoute(NODE2))));
}
Also used : PreOut(org.batfish.z3.state.PreOut) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) MockSynthesizerInput(org.batfish.z3.MockSynthesizerInput) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NotExpr(org.batfish.z3.expr.NotExpr) PostInVrf(org.batfish.z3.state.PostInVrf) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 8 with NotExpr

use of org.batfish.z3.expr.NotExpr in project batfish by batfish.

the class Simplifier method visitNotExpr.

@Override
public BooleanExpr visitNotExpr(NotExpr notExpr) {
    BooleanExpr oldArg = notExpr.getArg();
    BooleanExpr newArg = simplifyBooleanExpr(oldArg);
    if (newArg == FalseExpr.INSTANCE) {
        return TrueExpr.INSTANCE;
    } else if (newArg == TrueExpr.INSTANCE) {
        return FalseExpr.INSTANCE;
    } else if (newArg instanceof NotExpr) {
        return ((NotExpr) newArg).getArg();
    } else if (newArg != oldArg) {
        return new NotExpr(newArg);
    } else {
        return notExpr;
    }
}
Also used : NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Example 9 with NotExpr

use of org.batfish.z3.expr.NotExpr in project batfish by batfish.

the class BoolExprTransformerTest method testVisitNotExpr.

@Test
public void testVisitNotExpr() {
    BooleanExpr p1Batfish = newBooleanAtom();
    BoolExpr p1Z3 = toBoolExpr(p1Batfish, _input, _nodContext);
    assertThat(toBoolExpr(new NotExpr(p1Batfish), _input, _nodContext), equalTo(_ctx.mkNot(p1Z3)));
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 10 with NotExpr

use of org.batfish.z3.expr.NotExpr in project batfish by batfish.

the class IpSpaceBooleanExprTransformerTest method testVisitIpWildcardSetIpSpace.

@Test
public void testVisitIpWildcardSetIpSpace() {
    IpWildcard includeWildcard = new IpWildcard("1.1.1.1");
    IpWildcard excludeWildcard = new IpWildcard("2.2.2.2");
    IpWildcardSetIpSpace ipSpace = IpWildcardSetIpSpace.builder().including(includeWildcard).excluding(excludeWildcard).build();
    BooleanExpr expr = ipSpace.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    BooleanExpr includeExpr = includeWildcard.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    BooleanExpr excludeExpr = excludeWildcard.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(expr, equalTo(new AndExpr(ImmutableList.of(new NotExpr(excludeExpr), includeExpr))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) AndExpr(org.batfish.z3.expr.AndExpr) IpWildcardSetIpSpace(org.batfish.datamodel.IpWildcardSetIpSpace) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Aggregations

NotExpr (org.batfish.z3.expr.NotExpr)13 BooleanExpr (org.batfish.z3.expr.BooleanExpr)9 Test (org.junit.Test)9 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 AndExpr (org.batfish.z3.expr.AndExpr)4 RuleStatement (org.batfish.z3.expr.RuleStatement)4 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)3 SynthesizerInput (org.batfish.z3.SynthesizerInput)3 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)3 Simplifier.simplifyBooleanExpr (org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr)3 ImmutableList (com.google.common.collect.ImmutableList)2 IpWildcard (org.batfish.datamodel.IpWildcard)2 IfExpr (org.batfish.z3.expr.IfExpr)2 QueryStatement (org.batfish.z3.expr.QueryStatement)2 PreOut (org.batfish.z3.state.PreOut)2 BoolExpr (com.microsoft.z3.BoolExpr)1 Ip (org.batfish.datamodel.Ip)1 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)1 IpWildcardSetIpSpace (org.batfish.datamodel.IpWildcardSetIpSpace)1 EqExpr (org.batfish.z3.expr.EqExpr)1