Search in sources :

Example 21 with BasicRuleStatement

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

the class DefaultTransitionGeneratorTest method testVisitNodeDropNullRoute.

@Test
public void testVisitNodeDropNullRoute() {
    SynthesizerInput input = MockSynthesizerInput.builder().setNullRoutedIps(ImmutableMap.of(NODE1, ImmutableMap.of(VRF1, B1, VRF2, B2), NODE2, ImmutableMap.of(VRF1, B1, VRF2, B2))).build();
    Set<RuleStatement> rules = ImmutableSet.copyOf(DefaultTransitionGenerator.generateTransitions(input, ImmutableSet.of(NodeDropNullRoute.State.INSTANCE)));
    // DestinationRouting
    assertThat(rules, hasItem(new BasicRuleStatement(B1, ImmutableSet.of(new PostInVrf(NODE1, VRF1), new PreOut(NODE1)), new NodeDropNullRoute(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(B2, ImmutableSet.of(new PostInVrf(NODE1, VRF2), new PreOut(NODE1)), new NodeDropNullRoute(NODE1))));
    assertThat(rules, hasItem(new BasicRuleStatement(B1, ImmutableSet.of(new PostInVrf(NODE2, VRF1), new PreOut(NODE2)), new NodeDropNullRoute(NODE2))));
    assertThat(rules, hasItem(new BasicRuleStatement(B2, ImmutableSet.of(new PostInVrf(NODE2, VRF2), new PreOut(NODE2)), new NodeDropNullRoute(NODE2))));
}
Also used : PreOut(org.batfish.z3.state.PreOut) NodeDropNullRoute(org.batfish.z3.state.NodeDropNullRoute) 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) PostInVrf(org.batfish.z3.state.PostInVrf) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Test(org.junit.Test)

Example 22 with BasicRuleStatement

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

the class DefaultTransitionGenerator method visitDropAcl.

@Override
public void visitDropAcl(DropAcl.State dropAcl) {
    // CopyDropAclIn
    _rules.add(new BasicRuleStatement(DropAclIn.INSTANCE, DropAcl.INSTANCE));
    // CopyDropAclOut
    _rules.add(new BasicRuleStatement(DropAclOut.INSTANCE, DropAcl.INSTANCE));
// ProjectNodeDropAcl (unused for now)
// _rules.add(
// new RuleStatement(
// new OrExpr(
// _input
// .getEnabledNodes()
// .keySet()
// .stream()
// .map(NodeDropAcl::new)
// .collect(ImmutableList.toImmutableList())),
// DropAcl.INSTANCE));
}
Also used : BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 23 with BasicRuleStatement

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

the class DefaultTransitionGenerator method visitPostIn.

@Override
public void visitPostIn(PostIn.State postIn) {
    // CopyOriginate
    _input.getEnabledNodes().stream().map(hostname -> new BasicRuleStatement(new Originate(hostname), new PostIn(hostname))).forEach(_rules::add);
    // ProjectPostInInterface
    _input.getEnabledInterfaces().entrySet().stream().flatMap(enabledInterfacesByHostnameEntry -> {
        String hostname = enabledInterfacesByHostnameEntry.getKey();
        return enabledInterfacesByHostnameEntry.getValue().stream().map(ifaceName -> new BasicRuleStatement(new PostInInterface(hostname, ifaceName), new PostIn(hostname)));
    }).forEach(_rules::add);
}
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) PostIn(org.batfish.z3.state.PostIn) PostInInterface(org.batfish.z3.state.PostInInterface) Originate(org.batfish.z3.state.Originate) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement)

Example 24 with BasicRuleStatement

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

the class DefaultTransitionGenerator method visitNodeDropAcl.

@Override
public void visitNodeDropAcl(NodeDropAcl.State nodeDropAcl) {
    // CopyNodeDropAclIn
    _input.getEnabledNodes().stream().map(hostname -> new BasicRuleStatement(new NodeDropAclIn(hostname), new NodeDropAcl(hostname))).forEach(_rules::add);
    // CopyNodeDropAclOut
    _input.getEnabledNodes().stream().map(hostname -> new BasicRuleStatement(new NodeDropAclOut(hostname), new NodeDropAcl(hostname))).forEach(_rules::add);
}
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) NodeDropAcl(org.batfish.z3.state.NodeDropAcl) NodeDropAclIn(org.batfish.z3.state.NodeDropAclIn) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) NodeDropAclOut(org.batfish.z3.state.NodeDropAclOut)

Example 25 with BasicRuleStatement

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

the class BoolExprTransformer method visitBasicRuleStatement.

@Override
public BoolExpr visitBasicRuleStatement(BasicRuleStatement basicRuleStatement) {
    Context ctx = _nodContext.getContext();
    ImmutableList.Builder<BoolExpr> preconditions = ImmutableList.<BoolExpr>builder().add(toBoolExpr(basicRuleStatement.getPreconditionStateIndependentConstraints(), _input, _nodContext));
    basicRuleStatement.getPreconditionStates().stream().map(preconditionState -> toBoolExpr(preconditionState, _input, _nodContext)).forEach(preconditions::add);
    return ctx.mkImplies(ctx.mkAnd(preconditions.build().stream().toArray(BoolExpr[]::new)), toBoolExpr(basicRuleStatement.getPostconditionState(), _input, _nodContext));
}
Also used : Context(com.microsoft.z3.Context) NodContext(org.batfish.z3.NodContext) Statement(org.batfish.z3.expr.Statement) Arrays(java.util.Arrays) PrefixMatchExpr(org.batfish.z3.expr.PrefixMatchExpr) TransformationHeaderField(org.batfish.z3.TransformationHeaderField) OrExpr(org.batfish.z3.expr.OrExpr) TrueExpr(org.batfish.z3.expr.TrueExpr) Context(com.microsoft.z3.Context) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) GenericStatementVisitor(org.batfish.z3.expr.GenericStatementVisitor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) BoolExpr(com.microsoft.z3.BoolExpr) StateExpr(org.batfish.z3.expr.StateExpr) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) Parameterizer(org.batfish.z3.state.visitors.Parameterizer) IfExpr(org.batfish.z3.expr.IfExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) FalseExpr(org.batfish.z3.expr.FalseExpr) ImmutableMap(com.google.common.collect.ImmutableMap) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) IfThenElse(org.batfish.z3.expr.IfThenElse) Set(java.util.Set) NotExpr(org.batfish.z3.expr.NotExpr) Comment(org.batfish.z3.expr.Comment) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) SaneExpr(org.batfish.z3.expr.SaneExpr) AndExpr(org.batfish.z3.expr.AndExpr) NodContext(org.batfish.z3.NodContext) CurrentIsOriginalExpr(org.batfish.z3.expr.CurrentIsOriginalExpr) EqExpr(org.batfish.z3.expr.EqExpr) Expr(com.microsoft.z3.Expr) QueryStatement(org.batfish.z3.expr.QueryStatement) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) Type(org.batfish.z3.state.StateParameter.Type) BoolExpr(com.microsoft.z3.BoolExpr) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)44 RuleStatement (org.batfish.z3.expr.RuleStatement)37 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)35 SynthesizerInput (org.batfish.z3.SynthesizerInput)34 Test (org.junit.Test)29 MockSynthesizerInput (org.batfish.z3.MockSynthesizerInput)28 ImmutableList (com.google.common.collect.ImmutableList)12 BooleanExpr (org.batfish.z3.expr.BooleanExpr)12 NotExpr (org.batfish.z3.expr.NotExpr)12 PreOut (org.batfish.z3.state.PreOut)11 AclLineMatch (org.batfish.z3.state.AclLineMatch)10 NodeDropAclIn (org.batfish.z3.state.NodeDropAclIn)10 NodeDropAclOut (org.batfish.z3.state.NodeDropAclOut)10 NodeDropNoRoute (org.batfish.z3.state.NodeDropNoRoute)10 NodeDropNullRoute (org.batfish.z3.state.NodeDropNullRoute)10 StateExpr (org.batfish.z3.expr.StateExpr)9 AclDeny (org.batfish.z3.state.AclDeny)9 AclLineNoMatch (org.batfish.z3.state.AclLineNoMatch)9 AclPermit (org.batfish.z3.state.AclPermit)9 NodeAccept (org.batfish.z3.state.NodeAccept)9