Search in sources :

Example 1 with Disjunction

use of org.batfish.datamodel.routing_policy.expr.Disjunction 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 Disjunction

use of org.batfish.datamodel.routing_policy.expr.Disjunction in project batfish by batfish.

the class RouteMapMatchIpAccessListLine method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(Configuration c, CiscoConfiguration cc, Warnings w) {
    Disjunction d = new Disjunction();
    List<BooleanExpr> disjuncts = d.getDisjuncts();
    for (String listName : _listNames) {
        Object list;
        IpAccessList ipAccessList = null;
        RouteFilterList routeFilterList = null;
        if (_routing) {
            routeFilterList = c.getRouteFilterLists().get(listName);
            list = routeFilterList;
        } else {
            ipAccessList = c.getIpAccessLists().get(listName);
            list = ipAccessList;
        }
        if (list == null) {
            cc.undefined(CiscoStructureType.IP_ACCESS_LIST, listName, CiscoStructureUsage.ROUTE_MAP_MATCH_IP_ACCESS_LIST, _statementLine);
        } else {
            String msg = "route-map match ip access-list line";
            ExtendedAccessList extendedAccessList = cc.getExtendedAcls().get(listName);
            if (extendedAccessList != null) {
                extendedAccessList.getReferers().put(this, msg);
            }
            StandardAccessList standardAccessList = cc.getStandardAcls().get(listName);
            if (standardAccessList != null) {
                standardAccessList.getReferers().put(this, msg);
            }
            if (_routing) {
                disjuncts.add(new MatchPrefixSet(new DestinationNetwork(), new NamedPrefixSet(listName)));
            } else {
                disjuncts.add(new MatchIpAccessList(listName));
            }
        }
    }
    return d.simplify();
}
Also used : NamedPrefixSet(org.batfish.datamodel.routing_policy.expr.NamedPrefixSet) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) DestinationNetwork(org.batfish.datamodel.routing_policy.expr.DestinationNetwork) RouteFilterList(org.batfish.datamodel.RouteFilterList) MatchIpAccessList(org.batfish.datamodel.routing_policy.expr.MatchIpAccessList) MatchIpAccessList(org.batfish.datamodel.routing_policy.expr.MatchIpAccessList) IpAccessList(org.batfish.datamodel.IpAccessList) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Example 3 with Disjunction

use of org.batfish.datamodel.routing_policy.expr.Disjunction in project batfish by batfish.

the class RouteMapMatchTagLine method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(Configuration c, CiscoConfiguration cc, Warnings w) {
    Disjunction d = new Disjunction();
    List<BooleanExpr> disjuncts = d.getDisjuncts();
    for (int tag : _tags) {
        disjuncts.add(new MatchTag(IntComparator.EQ, new LiteralInt(tag)));
    }
    return d.simplify();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) MatchTag(org.batfish.datamodel.routing_policy.expr.MatchTag) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) LiteralInt(org.batfish.datamodel.routing_policy.expr.LiteralInt)

Example 4 with Disjunction

use of org.batfish.datamodel.routing_policy.expr.Disjunction in project batfish by batfish.

the class RouteMapMatchCommunityListLine method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(Configuration c, CiscoConfiguration cc, Warnings w) {
    Disjunction d = new Disjunction();
    List<BooleanExpr> disjuncts = d.getDisjuncts();
    for (String listName : _listNames) {
        CommunityList list = c.getCommunityLists().get(listName);
        if (list != null) {
            String msg = "match community line";
            StandardCommunityList standardCommunityList = cc.getStandardCommunityLists().get(listName);
            if (standardCommunityList != null) {
                standardCommunityList.getReferers().put(this, msg);
            }
            ExpandedCommunityList expandedCommunityList = cc.getExpandedCommunityLists().get(listName);
            if (expandedCommunityList != null) {
                expandedCommunityList.getReferers().put(this, msg);
            }
            disjuncts.add(new MatchCommunitySet(new NamedCommunitySet(listName)));
        } else {
            cc.undefined(CiscoStructureType.COMMUNITY_LIST, listName, CiscoStructureUsage.ROUTE_MAP_MATCH_COMMUNITY_LIST, _statementLine);
        }
    }
    return d.simplify();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) MatchCommunitySet(org.batfish.datamodel.routing_policy.expr.MatchCommunitySet) CommunityList(org.batfish.datamodel.CommunityList) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Example 5 with Disjunction

use of org.batfish.datamodel.routing_policy.expr.Disjunction in project batfish by batfish.

the class RoutePolicyBooleanOr method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(CiscoConfiguration cc, Configuration c, Warnings w) {
    Disjunction disj = new Disjunction();
    BooleanExpr left = _left.toBooleanExpr(cc, c, w);
    BooleanExpr right = _right.toBooleanExpr(cc, c, w);
    List<BooleanExpr> disjuncts = disj.getDisjuncts();
    disjuncts.add(left);
    disjuncts.add(right);
    return disj.simplify();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Aggregations

Disjunction (org.batfish.datamodel.routing_policy.expr.Disjunction)24 BooleanExpr (org.batfish.datamodel.routing_policy.expr.BooleanExpr)18 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)10 If (org.batfish.datamodel.routing_policy.statement.If)10 Conjunction (org.batfish.datamodel.routing_policy.expr.Conjunction)8 MatchProtocol (org.batfish.datamodel.routing_policy.expr.MatchProtocol)8 CallExpr (org.batfish.datamodel.routing_policy.expr.CallExpr)7 MatchPrefixSet (org.batfish.datamodel.routing_policy.expr.MatchPrefixSet)7 ArrayList (java.util.ArrayList)6 MatchPrefix6Set (org.batfish.datamodel.routing_policy.expr.MatchPrefix6Set)6 Not (org.batfish.datamodel.routing_policy.expr.Not)6 DestinationNetwork (org.batfish.datamodel.routing_policy.expr.DestinationNetwork)5 DisjunctionChain (org.batfish.datamodel.routing_policy.expr.DisjunctionChain)5 BatfishException (org.batfish.common.BatfishException)4 ConjunctionChain (org.batfish.datamodel.routing_policy.expr.ConjunctionChain)4 DestinationNetwork6 (org.batfish.datamodel.routing_policy.expr.DestinationNetwork6)4 MatchAsPath (org.batfish.datamodel.routing_policy.expr.MatchAsPath)4 NamedPrefixSet (org.batfish.datamodel.routing_policy.expr.NamedPrefixSet)4 Statement (org.batfish.datamodel.routing_policy.statement.Statement)4 BigInteger (java.math.BigInteger)3