Search in sources :

Example 1 with StateExpr

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

the class ReachabilityProgramOptimizerTest method freshQueryStateExpr.

private StateExpr freshQueryStateExpr() {
    StateExpr stateExpr = freshStateExpr();
    _queries.add(new QueryStatement(stateExpr));
    return stateExpr;
}
Also used : TestStateExpr(org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr)

Example 2 with StateExpr

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

the class RelationCollectorTest method testTestStateExpr.

@Test
public void testTestStateExpr() {
    StateExpr b1 = newStateExpr();
    StateExpr b2 = newStateExpr();
    assertThat(b1, Matchers.not(equalTo(b2)));
}
Also used : StateExpr(org.batfish.z3.expr.StateExpr) Test(org.junit.Test)

Example 3 with StateExpr

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

the class RelationCollectorTest method testVisitTransformationRuleStatement.

/**
 * Test that collectRelations traverses the child of a TransformationRuleStatement.
 */
@Test
public void testVisitTransformationRuleStatement() {
    StateExpr b1 = newStateExpr();
    StateExpr b2 = newStateExpr();
    StateExpr t1 = newStateExpr();
    TransformationRuleStatement expr1 = new TransformationRuleStatement(t1);
    Set<String> expectedRelations1 = ImmutableSet.of(getNodName(_input, t1));
    TransformationRuleStatement expr2 = new TransformationRuleStatement(TrueExpr.INSTANCE, ImmutableSet.of(b1), ImmutableSet.of(b2), t1);
    Set<String> expectedRelations2 = ImmutableSet.of(getNodName(_input, b1), getNodName(_input, b2), getNodName(_input, t1));
    assertThat(collectRelations(_input, expr1), equalTo(expectedRelations1));
    assertThat(collectRelations(_input, expr2), equalTo(expectedRelations2));
}
Also used : StateExpr(org.batfish.z3.expr.StateExpr) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) Test(org.junit.Test)

Example 4 with StateExpr

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

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

the class ReachabilityProgramOptimizerTest method pruneIrrelevant.

/*
   * No query statement, so everything is irrelevant
   */
@Test
public void pruneIrrelevant() {
    StateExpr state1 = freshStateExpr();
    addRuleFor(state1);
    StateExpr state2 = freshStateExpr();
    addRuleFor(state2, state1);
    Set<RuleStatement> rules = optimize();
    assertThat(rules, empty());
}
Also used : TestStateExpr(org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 StateExpr (org.batfish.z3.expr.StateExpr)9 TestStateExpr (org.batfish.z3.expr.visitors.RelationCollectorTest.TestStateExpr)7 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)5 ImmutableList (com.google.common.collect.ImmutableList)4 NodeAccept (org.batfish.z3.state.NodeAccept)4 NodeDrop (org.batfish.z3.state.NodeDrop)4 NodeDropAclOut (org.batfish.z3.state.NodeDropAclOut)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 BooleanExpr (org.batfish.z3.expr.BooleanExpr)3 RuleStatement (org.batfish.z3.expr.RuleStatement)3 Accept (org.batfish.z3.state.Accept)3 AclDeny (org.batfish.z3.state.AclDeny)3 Debug (org.batfish.z3.state.Debug)3 Drop (org.batfish.z3.state.Drop)3 DropAcl (org.batfish.z3.state.DropAcl)3 DropAclIn (org.batfish.z3.state.DropAclIn)3