Search in sources :

Example 1 with VarIntExpr

use of org.batfish.z3.expr.VarIntExpr 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 2 with VarIntExpr

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

the class SimplifierTest method testSimplifyEqSame.

/**
 * Test that an EQ node with syntactically equal LHS and RHS simplifies to TRUE.
 */
@Test
public void testSimplifyEqSame() {
    IntExpr i1 = new VarIntExpr(BasicHeaderField.DST_IP);
    EqExpr eq = new EqExpr(i1, i1);
    assertThat(simplifyBooleanExpr(eq), equalTo(TrueExpr.INSTANCE));
}
Also used : VarIntExpr(org.batfish.z3.expr.VarIntExpr) EqExpr(org.batfish.z3.expr.EqExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) Test(org.junit.Test)

Example 3 with VarIntExpr

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

the class DefaultTransitionGenerator method visitPreOutEdgePostNat_generateNoMatchSourceNatRules.

private void visitPreOutEdgePostNat_generateNoMatchSourceNatRules(String node1, String iface1, String node2, String iface2) {
    List<Entry<AclPermit, BooleanExpr>> sourceNats = _input.getSourceNats().getOrDefault(node1, ImmutableMap.of()).getOrDefault(iface1, ImmutableList.of());
    ImmutableSet.Builder<StateExpr> preStates = ImmutableSet.builder();
    preStates.add(new PreOutEdge(node1, iface1, node2, iface2));
    sourceNats.stream().map(Entry::getKey).map(aclPermit -> new AclDeny(aclPermit.getHostname(), aclPermit.getAcl())).forEach(preStates::add);
    _rules.add(new TransformationRuleStatement(new EqExpr(new VarIntExpr(TransformationHeaderField.NEW_SRC_IP), new VarIntExpr(TransformationHeaderField.NEW_SRC_IP.getCurrent())), preStates.build(), ImmutableSet.of(), new PreOutEdgePostNat(node1, iface1, node2, iface2)));
}
Also used : DropAclIn(org.batfish.z3.state.DropAclIn) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut) AclLineMatch(org.batfish.z3.state.AclLineMatch) Drop(org.batfish.z3.state.Drop) NodeDropAcl(org.batfish.z3.state.NodeDropAcl) NodeDropNoRoute(org.batfish.z3.state.NodeDropNoRoute) NumberedQuery(org.batfish.z3.state.NumberedQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) PostIn(org.batfish.z3.state.PostIn) AclLineNoMatch(org.batfish.z3.state.AclLineNoMatch) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) State(org.batfish.z3.expr.StateExpr.State) Originate(org.batfish.z3.state.Originate) NodeDropNullRoute(org.batfish.z3.state.NodeDropNullRoute) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Query(org.batfish.z3.state.Query) PostOutEdge(org.batfish.z3.state.PostOutEdge) List(java.util.List) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) OriginateVrf(org.batfish.z3.state.OriginateVrf) PreOutEdge(org.batfish.z3.state.PreOutEdge) Entry(java.util.Map.Entry) NodeDrop(org.batfish.z3.state.NodeDrop) NodeNeighborUnreachable(org.batfish.z3.state.NodeNeighborUnreachable) IpWildcard(org.batfish.datamodel.IpWildcard) TransformationHeaderField(org.batfish.z3.TransformationHeaderField) TrueExpr(org.batfish.z3.expr.TrueExpr) DropAcl(org.batfish.z3.state.DropAcl) DropNullRoute(org.batfish.z3.state.DropNullRoute) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) NodeAccept(org.batfish.z3.state.NodeAccept) ImmutableList(com.google.common.collect.ImmutableList) StateExpr(org.batfish.z3.expr.StateExpr) LineAction(org.batfish.datamodel.LineAction) RuleStatement(org.batfish.z3.expr.RuleStatement) DropAclOut(org.batfish.z3.state.DropAclOut) Debug(org.batfish.z3.state.Debug) DropNoRoute(org.batfish.z3.state.DropNoRoute) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Accept(org.batfish.z3.state.Accept) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) PreOut(org.batfish.z3.state.PreOut) AclDeny(org.batfish.z3.state.AclDeny) NotExpr(org.batfish.z3.expr.NotExpr) AclPermit(org.batfish.z3.state.AclPermit) VarIntExpr(org.batfish.z3.expr.VarIntExpr) PreInInterface(org.batfish.z3.state.PreInInterface) PostInVrf(org.batfish.z3.state.PostInVrf) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NeighborUnreachable(org.batfish.z3.state.NeighborUnreachable) EqExpr(org.batfish.z3.expr.EqExpr) PostInInterface(org.batfish.z3.state.PostInInterface) AclDeny(org.batfish.z3.state.AclDeny) VarIntExpr(org.batfish.z3.expr.VarIntExpr) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) StateExpr(org.batfish.z3.expr.StateExpr) Entry(java.util.Map.Entry) PreOutEdge(org.batfish.z3.state.PreOutEdge) ImmutableSet(com.google.common.collect.ImmutableSet) EqExpr(org.batfish.z3.expr.EqExpr) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat)

Example 4 with VarIntExpr

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

the class SimplifierTest method testSimplifyEqPreserveUnalteredInstance.

/**
 * Test that an EQ node with LHS and RHS not statically determinable is unchanged by
 * simplification.
 */
@Test
public void testSimplifyEqPreserveUnalteredInstance() {
    IntExpr i1 = new VarIntExpr(BasicHeaderField.DST_IP);
    IntExpr i2 = new VarIntExpr(BasicHeaderField.SRC_IP);
    EqExpr eq = new EqExpr(i1, i2);
    assertThat(simplifyBooleanExpr(eq), sameInstance(eq));
}
Also used : VarIntExpr(org.batfish.z3.expr.VarIntExpr) EqExpr(org.batfish.z3.expr.EqExpr) IntExpr(org.batfish.z3.expr.IntExpr) VarIntExpr(org.batfish.z3.expr.VarIntExpr) LitIntExpr(org.batfish.z3.expr.LitIntExpr) Test(org.junit.Test)

Example 5 with VarIntExpr

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

the class DefaultTransitionGeneratorTest method testPreOutEdgePostNat.

@Test
public void testPreOutEdgePostNat() {
    SynthesizerInput input = MockSynthesizerInput.builder().setEnabledEdges(ImmutableSet.of(new Edge(NODE1, INTERFACE1, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE1, NODE2, INTERFACE2), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE1), new Edge(NODE1, INTERFACE2, NODE2, INTERFACE2), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE1, NODE1, INTERFACE2), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE1), new Edge(NODE2, INTERFACE2, NODE1, INTERFACE2))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(PreOutEdgePostNat.State.INSTANCE)));
    BooleanExpr newSrcIpEqualsCurrentSrcIp = new EqExpr(new VarIntExpr(TransformationHeaderField.NEW_SRC_IP), new VarIntExpr(TransformationHeaderField.NEW_SRC_IP.getCurrent()));
    // PreOutEdgePostNatForTopologyEdges
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE1, NODE2, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE1, NODE2, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE2, NODE2, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE2, NODE2, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE1, INTERFACE2, NODE2, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE1, INTERFACE2, NODE2, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE1, NODE1, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE1, NODE1, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE1, NODE1, INTERFACE2))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE2, NODE1, INTERFACE1)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE1))));
    assertThat(rules, hasItem(new TransformationRuleStatement(newSrcIpEqualsCurrentSrcIp, ImmutableSet.of(new PreOutEdge(NODE2, INTERFACE2, NODE1, INTERFACE2)), ImmutableSet.of(), new PreOutEdgePostNat(NODE2, INTERFACE2, NODE1, INTERFACE2))));
}
Also used : VarIntExpr(org.batfish.z3.expr.VarIntExpr) PreOutEdge(org.batfish.z3.state.PreOutEdge) 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) EqExpr(org.batfish.z3.expr.EqExpr) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) Edge(org.batfish.datamodel.Edge) PostOutEdge(org.batfish.z3.state.PostOutEdge) PreOutEdge(org.batfish.z3.state.PreOutEdge) BooleanExpr(org.batfish.z3.expr.BooleanExpr) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) Test(org.junit.Test)

Aggregations

EqExpr (org.batfish.z3.expr.EqExpr)6 VarIntExpr (org.batfish.z3.expr.VarIntExpr)6 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)4 SynthesizerInput (org.batfish.z3.SynthesizerInput)3 BooleanExpr (org.batfish.z3.expr.BooleanExpr)3 LitIntExpr (org.batfish.z3.expr.LitIntExpr)3 RuleStatement (org.batfish.z3.expr.RuleStatement)3 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)3 Test (org.junit.Test)3 ImmutableList (com.google.common.collect.ImmutableList)2 Edge (org.batfish.datamodel.Edge)2 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)2 IntExpr (org.batfish.z3.expr.IntExpr)2 NotExpr (org.batfish.z3.expr.NotExpr)2 AclDeny (org.batfish.z3.state.AclDeny)2 AclPermit (org.batfish.z3.state.AclPermit)2 PostOutEdge (org.batfish.z3.state.PostOutEdge)2 PreOutEdge (org.batfish.z3.state.PreOutEdge)2 PreOutEdgePostNat (org.batfish.z3.state.PreOutEdgePostNat)2 ImmutableMap (com.google.common.collect.ImmutableMap)1