Search in sources :

Example 1 with Expr

use of org.batfish.z3.expr.Expr 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)

Example 2 with Expr

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

the class BoolExprTransformerTest method testVisitPrefixMatchExpr.

@Test
public void testVisitPrefixMatchExpr() {
    BooleanExpr expr = new PrefixMatchExpr(BasicHeaderField.SRC_IP, Prefix.parse("1.2.3.4/5"));
    assertThat(toBoolExpr(expr, _input, _nodContext), instanceOf(BoolExpr.class));
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) BoolExprTransformer.toBoolExpr(org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr) PrefixMatchExpr(org.batfish.z3.expr.PrefixMatchExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 3 with Expr

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

the class IpSpaceBooleanExprTransformerTest method testVisitUniverseIpSpace.

@Test
public void testVisitUniverseIpSpace() {
    BooleanExpr expr = UniverseIpSpace.INSTANCE.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(expr, equalTo(TrueExpr.INSTANCE));
}
Also used : BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 4 with Expr

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

the class IpSpaceBooleanExprTransformerTest method testVisitAclIpSpace.

@Test
public void testVisitAclIpSpace() {
    AclIpSpace ipSpace = AclIpSpace.builder().thenRejecting(UniverseIpSpace.INSTANCE).thenPermitting(EmptyIpSpace.INSTANCE).build();
    BooleanExpr expr = ipSpace.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(expr, equalTo(new IfThenElse(// Matches UniverseIpSpace
    TrueExpr.INSTANCE, // Reject
    FalseExpr.INSTANCE, new IfThenElse(// Matches EmptyIpSpace
    FalseExpr.INSTANCE, // Accept
    TrueExpr.INSTANCE, // Matches nothing so reject
    FalseExpr.INSTANCE))));
}
Also used : AclIpSpace(org.batfish.datamodel.AclIpSpace) IfThenElse(org.batfish.z3.expr.IfThenElse) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 5 with Expr

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

the class IpSpaceBooleanExprTransformerTest method testVisitEmptyIpSpace.

@Test
public void testVisitEmptyIpSpace() {
    BooleanExpr expr = EmptyIpSpace.INSTANCE.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(expr, equalTo(FalseExpr.INSTANCE));
}
Also used : BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Aggregations

BooleanExpr (org.batfish.z3.expr.BooleanExpr)8 Test (org.junit.Test)8 AndExpr (org.batfish.z3.expr.AndExpr)5 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)5 NotExpr (org.batfish.z3.expr.NotExpr)5 PrefixMatchExpr (org.batfish.z3.expr.PrefixMatchExpr)5 StateExpr (org.batfish.z3.expr.StateExpr)5 BitVecExpr (org.batfish.z3.expr.BitVecExpr)4 CurrentIsOriginalExpr (org.batfish.z3.expr.CurrentIsOriginalExpr)4 EqExpr (org.batfish.z3.expr.EqExpr)4 Expr (org.batfish.z3.expr.Expr)4 ExtractExpr (org.batfish.z3.expr.ExtractExpr)4 FalseExpr (org.batfish.z3.expr.FalseExpr)4 IdExpr (org.batfish.z3.expr.IdExpr)4 IfExpr (org.batfish.z3.expr.IfExpr)4 IpSpaceMatchExpr (org.batfish.z3.expr.IpSpaceMatchExpr)4 ListExpr (org.batfish.z3.expr.ListExpr)4 LitIntExpr (org.batfish.z3.expr.LitIntExpr)4 OrExpr (org.batfish.z3.expr.OrExpr)4 RangeMatchExpr (org.batfish.z3.expr.RangeMatchExpr)4