Search in sources :

Example 1 with BufferedStatement

use of org.batfish.datamodel.routing_policy.statement.BufferedStatement in project batfish by batfish.

the class RoutingPolicyTests method testRoutingPolicyDeepCircularReference.

/**
 * Policy with actual circular reference deep in the policy
 */
@Test
public void testRoutingPolicyDeepCircularReference() {
    String parentPolicyName = "parent";
    CallStatement callStatement = new CallStatement(parentPolicyName);
    BufferedStatement bs = new BufferedStatement(callStatement);
    WithEnvironmentExpr we1 = new WithEnvironmentExpr();
    we1.setPostStatements(ImmutableList.of(bs));
    If if1 = new If();
    if1.setGuard(we1);
    WithEnvironmentExpr we2 = new WithEnvironmentExpr();
    we2.setPostTrueStatements(ImmutableList.of(if1));
    If if2 = new If();
    if2.setGuard(we2);
    If if3 = new If();
    if3.setTrueStatements(ImmutableList.of(if2));
    If if4 = new If();
    if4.setFalseStatements(ImmutableList.of(if3));
    WithEnvironmentExpr we3 = new WithEnvironmentExpr();
    we3.setPreStatements(ImmutableList.of(if4));
    WithEnvironmentExpr we4 = new WithEnvironmentExpr();
    we4.setExpr(we3);
    Conjunction conj = new Conjunction();
    conj.setConjuncts(ImmutableList.of(we4));
    ConjunctionChain conjunctionChain = new ConjunctionChain(ImmutableList.of(conj));
    Disjunction disjunction = new Disjunction();
    disjunction.setDisjuncts(ImmutableList.of(conjunctionChain));
    DisjunctionChain disjunctionChain = new DisjunctionChain(ImmutableList.of(disjunction));
    Not not = new Not(disjunctionChain);
    If if5 = new If();
    if5.setGuard(not);
    _rpb.setName(parentPolicyName).setStatements(ImmutableList.of(if5)).build();
    _c.computeRoutingPolicySources(_w);
    /*
     * A circular reference warning should be emitted containing the name of the circularly
     * referenced policy.
     */
    assertThat(_w.getRedFlagWarnings(), not(empty()));
    assertThat(_w.getRedFlagWarnings().iterator().next().getText(), containsString(parentPolicyName));
}
Also used : BufferedStatement(org.batfish.datamodel.routing_policy.statement.BufferedStatement) Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) Not(org.batfish.datamodel.routing_policy.expr.Not) Conjunction(org.batfish.datamodel.routing_policy.expr.Conjunction) Matchers.containsString(org.hamcrest.Matchers.containsString) CallStatement(org.batfish.datamodel.routing_policy.statement.CallStatement) ConjunctionChain(org.batfish.datamodel.routing_policy.expr.ConjunctionChain) DisjunctionChain(org.batfish.datamodel.routing_policy.expr.DisjunctionChain) WithEnvironmentExpr(org.batfish.datamodel.routing_policy.expr.WithEnvironmentExpr) If(org.batfish.datamodel.routing_policy.statement.If) Test(org.junit.Test)

Example 2 with BufferedStatement

use of org.batfish.datamodel.routing_policy.statement.BufferedStatement in project batfish by batfish.

the class RoutePolicySetStatement method applyTo.

@Override
public final void applyTo(List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) {
    Statement setStatement = toSetStatement(cc, c, w);
    Statement bufferedStatement = new BufferedStatement(setStatement);
    If ifStatement = new If();
    ifStatement.setGuard(BooleanExprs.CallExprContext.toStaticBooleanExpr());
    ifStatement.setTrueStatements(Collections.singletonList(Statements.SetLocalDefaultActionAccept.toStaticStatement()));
    ifStatement.setFalseStatements(Collections.singletonList(Statements.SetDefaultActionAccept.toStaticStatement()));
    statements.add(bufferedStatement);
    statements.add(ifStatement);
}
Also used : BufferedStatement(org.batfish.datamodel.routing_policy.statement.BufferedStatement) BufferedStatement(org.batfish.datamodel.routing_policy.statement.BufferedStatement) Statement(org.batfish.datamodel.routing_policy.statement.Statement) If(org.batfish.datamodel.routing_policy.statement.If)

Aggregations

BufferedStatement (org.batfish.datamodel.routing_policy.statement.BufferedStatement)2 If (org.batfish.datamodel.routing_policy.statement.If)2 Conjunction (org.batfish.datamodel.routing_policy.expr.Conjunction)1 ConjunctionChain (org.batfish.datamodel.routing_policy.expr.ConjunctionChain)1 Disjunction (org.batfish.datamodel.routing_policy.expr.Disjunction)1 DisjunctionChain (org.batfish.datamodel.routing_policy.expr.DisjunctionChain)1 Not (org.batfish.datamodel.routing_policy.expr.Not)1 WithEnvironmentExpr (org.batfish.datamodel.routing_policy.expr.WithEnvironmentExpr)1 CallStatement (org.batfish.datamodel.routing_policy.statement.CallStatement)1 Statement (org.batfish.datamodel.routing_policy.statement.Statement)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1