Search in sources :

Example 11 with NotExpr

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

the class SimplifierTest method testSimplifyIfStaticallyTrue.

/**
 * Test that an IF with antecedent statically FALSE, or consequent statically TRUE, or antecedent
 * statically equal to consequent simplifies to TRUE.
 */
@Test
public void testSimplifyIfStaticallyTrue() {
    BooleanExpr p1 = newAtom();
    // Antecedent is false
    assertThat(simplifyBooleanExpr(new IfExpr(FalseExpr.INSTANCE, newAtom())), equalTo(TrueExpr.INSTANCE));
    assertThat(simplifyBooleanExpr(new IfExpr(new NotExpr(new NotExpr(FalseExpr.INSTANCE)), newAtom())), equalTo(TrueExpr.INSTANCE));
    // Consequent is true
    assertThat(simplifyBooleanExpr(new IfExpr(newAtom(), TrueExpr.INSTANCE)), equalTo(TrueExpr.INSTANCE));
    assertThat(simplifyBooleanExpr(new IfExpr(newAtom(), new NotExpr(FalseExpr.INSTANCE))), equalTo(TrueExpr.INSTANCE));
    // Antecedent == Consequent
    assertThat(simplifyBooleanExpr(new IfExpr(p1, p1)), equalTo(TrueExpr.INSTANCE));
    assertThat(simplifyBooleanExpr(new IfExpr(new NotExpr(new NotExpr(p1)), p1)), equalTo(TrueExpr.INSTANCE));
}
Also used : IfExpr(org.batfish.z3.expr.IfExpr) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Example 12 with NotExpr

use of org.batfish.z3.expr.NotExpr 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))));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) PostIn(org.batfish.z3.state.PostIn) PreOut(org.batfish.z3.state.PreOut) 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) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 13 with NotExpr

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

the class IpSpaceBooleanExprTransformer method visitIpWildcardSetIpSpace.

@Override
public BooleanExpr visitIpWildcardSetIpSpace(IpWildcardSetIpSpace ipWildcardSetIpSpace) {
    BooleanExpr matchBlacklist = HeaderSpaceMatchExpr.matchIp(ipWildcardSetIpSpace.getBlacklist(), _useSrc, _useDst);
    BooleanExpr matchWhitelist = HeaderSpaceMatchExpr.matchIp(ipWildcardSetIpSpace.getWhitelist(), _useSrc, _useDst);
    return new AndExpr(ImmutableList.of(new NotExpr(matchBlacklist), matchWhitelist));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

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