Search in sources :

Example 1 with BooleanExpr

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

the class MultipathInconsistencyQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    addOriginateRules(rules);
    ImmutableList.Builder<BooleanExpr> queryPreconditions = ImmutableList.<BooleanExpr>builder().add(SaneExpr.INSTANCE).add(getSrcNattedConstraint());
    rules.add(new BasicRuleStatement(new AndExpr(queryPreconditions.build()), ImmutableSet.of(Accept.INSTANCE, Drop.INSTANCE), Query.INSTANCE));
    rules.add(new BasicRuleStatement(SaneExpr.INSTANCE, ImmutableSet.of(Accept.INSTANCE, NeighborUnreachable.INSTANCE), Query.INSTANCE));
    rules.add(new BasicRuleStatement(SaneExpr.INSTANCE, ImmutableSet.of(Drop.INSTANCE, NeighborUnreachable.INSTANCE), Query.INSTANCE));
    return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(rules.build()).build();
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) ImmutableList(com.google.common.collect.ImmutableList) QueryStatement(org.batfish.z3.expr.QueryStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 2 with BooleanExpr

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

the class BlacklistDstIpQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    ImmutableList.Builder<BooleanExpr> queryConditionsBuilder = ImmutableList.builder();
    queryConditionsBuilder.add(SaneExpr.INSTANCE);
    for (Ip blacklistIp : _blacklistIps) {
        BooleanExpr blacklistIpCondition = new NotExpr(new EqExpr(new VarIntExpr(BasicHeaderField.DST_IP), new LitIntExpr(blacklistIp)));
        queryConditionsBuilder.add(blacklistIpCondition);
    }
    return ReachabilityProgram.builder().setInput(input).setQueries(ImmutableList.of(new QueryStatement(Query.INSTANCE))).setRules(ImmutableList.of(new BasicRuleStatement(new AndExpr(queryConditionsBuilder.build()), ImmutableSet.of(), Query.INSTANCE))).build();
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) ImmutableList(com.google.common.collect.ImmutableList) EqExpr(org.batfish.z3.expr.EqExpr) Ip(org.batfish.datamodel.Ip) LitIntExpr(org.batfish.z3.expr.LitIntExpr) NotExpr(org.batfish.z3.expr.NotExpr) QueryStatement(org.batfish.z3.expr.QueryStatement) BooleanExpr(org.batfish.z3.expr.BooleanExpr) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 3 with BooleanExpr

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

the class EarliestMoreGeneralReachableLineQuerySynthesizer method getReachabilityProgram.

@Override
public ReachabilityProgram getReachabilityProgram(SynthesizerInput input) {
    int unreachableLineIndex = _unreachableLine.getLine();
    IpAccessListLine unreachableLine = _list.getLines().get(unreachableLineIndex);
    BooleanExpr matchUnreachableLineHeaderSpace = new HeaderSpaceMatchExpr(unreachableLine);
    ImmutableList.Builder<QueryStatement> queries = ImmutableList.builder();
    ImmutableList.Builder<RuleStatement> rules = ImmutableList.builder();
    for (AclLine earlierReachableLine : _earlierReachableLines) {
        int earlierLineIndex = earlierReachableLine.getLine();
        IpAccessListLine earlierLine = _list.getLines().get(earlierLineIndex);
        BooleanExpr matchEarlierLineHeaderSpace = new HeaderSpaceMatchExpr(earlierLine);
        NumberedQuery queryRel = new NumberedQuery(earlierLineIndex);
        rules.add(new BasicRuleStatement(new AndExpr(ImmutableList.of(new NotExpr(matchEarlierLineHeaderSpace), matchUnreachableLineHeaderSpace, SaneExpr.INSTANCE)), queryRel));
        QueryStatement query = new QueryStatement(queryRel);
        queries.add(query);
        _resultsByQueryIndex.add(earlierLineIndex);
    }
    return ReachabilityProgram.builder().setInput(input).setQueries(queries.build()).setRules(rules.build()).build();
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) NumberedQuery(org.batfish.z3.state.NumberedQuery) ImmutableList(com.google.common.collect.ImmutableList) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) RuleStatement(org.batfish.z3.expr.RuleStatement) IpAccessListLine(org.batfish.datamodel.IpAccessListLine) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) QueryStatement(org.batfish.z3.expr.QueryStatement) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr)

Example 4 with BooleanExpr

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

the class BoolExprTransformerTest method testVisitAndExpr.

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

Example 5 with BooleanExpr

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

the class BoolExprTransformerTest method testVisitHeaderSpaceMatchExpr.

@Test
public void testVisitHeaderSpaceMatchExpr() {
    long ipCounter = 1L;
    int intCounter = 1;
    HeaderSpace.Builder<?, ?> hb = IpAccessListLine.builder();
    BooleanExpr expr = new HeaderSpaceMatchExpr(hb.setDscps(ImmutableSet.of(intCounter++, intCounter++)).setDstIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setDstPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setDstProtocols(ImmutableSet.of(Protocol.DNS, Protocol.HTTP)).setEcns(ImmutableSet.of(intCounter++, intCounter++)).setFragmentOffsets(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setIcmpCodes(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setIcmpTypes(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setIpProtocols(ImmutableSet.of(IpProtocol.AHP, IpProtocol.ARGUS)).setNegate(true).setNotDscps(ImmutableSet.of(intCounter++, intCounter++)).setNotDstIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setNotDstPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotDstProtocols(ImmutableSet.of(Protocol.HTTPS, Protocol.TELNET)).setNotEcns(ImmutableSet.of(intCounter++, intCounter++)).setNotFragmentOffsets(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotIcmpCodes(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotIcmpTypes(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotIpProtocols(ImmutableSet.of(IpProtocol.BNA, IpProtocol.XNET)).setNotPacketLengths(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotSrcIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setNotSrcPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setNotSrcProtocols(ImmutableSet.of(Protocol.SSH, Protocol.TCP)).setPacketLengths(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setSrcIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setSrcOrDstIps(ImmutableSet.of(new IpWildcard(new Ip(ipCounter++)), new IpWildcard(new Ip(ipCounter++)))).setSrcOrDstPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setSrcOrDstProtocols(ImmutableSet.of(Protocol.UDP, Protocol.HTTP)).setSrcPorts(ImmutableSet.of(new SubRange(intCounter++, intCounter++), new SubRange(intCounter++, intCounter++))).setSrcProtocols(ImmutableSet.of(Protocol.HTTPS, Protocol.DNS)).setStates(ImmutableSet.of(State.ESTABLISHED, State.NEW)).setTcpFlags(ImmutableSet.of(TcpFlags.builder().setAck(true).setUseAck(true).build(), TcpFlags.builder().setUseCwr(true).build())).build());
    assertThat(toBoolExpr(expr, _input, _nodContext), instanceOf(BoolExpr.class));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) Ip(org.batfish.datamodel.Ip) HeaderSpace(org.batfish.datamodel.HeaderSpace) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) SubRange(org.batfish.datamodel.SubRange) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Aggregations

BooleanExpr (org.batfish.z3.expr.BooleanExpr)43 Test (org.junit.Test)27 AndExpr (org.batfish.z3.expr.AndExpr)14 NotExpr (org.batfish.z3.expr.NotExpr)13 Simplifier.simplifyBooleanExpr (org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr)13 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)10 ImmutableList (com.google.common.collect.ImmutableList)9 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)8 BoolExpr (com.microsoft.z3.BoolExpr)7 IfExpr (org.batfish.z3.expr.IfExpr)7 VarIntExpr (org.batfish.z3.expr.VarIntExpr)7 BoolExprTransformer.toBoolExpr (org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr)7 List (java.util.List)6 IpWildcard (org.batfish.datamodel.IpWildcard)6 EqExpr (org.batfish.z3.expr.EqExpr)6 OrExpr (org.batfish.z3.expr.OrExpr)6 QueryStatement (org.batfish.z3.expr.QueryStatement)6 RuleStatement (org.batfish.z3.expr.RuleStatement)6 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)6 Ip (org.batfish.datamodel.Ip)5