Search in sources :

Example 16 with BooleanExpr

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

the class RouteMapMatchIpv6PrefixListLine 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) {
        Prefix6List list = cc.getPrefix6Lists().get(listName);
        if (list != null) {
            list.getReferers().put(this, "route-map match prefix-list");
            disjuncts.add(new MatchPrefix6Set(new DestinationNetwork6(), new NamedPrefix6Set(listName)));
        } else {
            cc.undefined(CiscoStructureType.PREFIX6_LIST, listName, CiscoStructureUsage.ROUTE_MAP_MATCH_IPV6_PREFIX_LIST, _statementLine);
        }
    }
    return d.simplify();
}
Also used : MatchPrefix6Set(org.batfish.datamodel.routing_policy.expr.MatchPrefix6Set) Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) NamedPrefix6Set(org.batfish.datamodel.routing_policy.expr.NamedPrefix6Set) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) DestinationNetwork6(org.batfish.datamodel.routing_policy.expr.DestinationNetwork6)

Example 17 with BooleanExpr

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

the class RouteMapMatchProtocolLine method toBooleanExpr.

@Override
public BooleanExpr toBooleanExpr(Configuration c, CiscoConfiguration cc, Warnings w) {
    Disjunction d = new Disjunction();
    List<BooleanExpr> disjuncts = d.getDisjuncts();
    for (String protocol : _protocols) {
        disjuncts.add(new MatchProtocol(RoutingProtocol.fromProtocolName(protocol)));
    }
    return d.simplify();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol)

Example 18 with BooleanExpr

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

the class RouteMapMatchAsPathAccessListLine 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) {
        IpAsPathAccessList list = cc.getAsPathAccessLists().get(listName);
        if (list != null) {
            list.getReferers().put(this, "route-map match ip as-path access-list");
            disjuncts.add(new MatchAsPath(new NamedAsPathSet(listName)));
        } else {
            cc.undefined(CiscoStructureType.AS_PATH_ACCESS_LIST, listName, CiscoStructureUsage.ROUTE_MAP_MATCH_AS_PATH_ACCESS_LIST, _statementLine);
        }
    }
    return d.simplify();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) NamedAsPathSet(org.batfish.datamodel.routing_policy.expr.NamedAsPathSet) MatchAsPath(org.batfish.datamodel.routing_policy.expr.MatchAsPath) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Example 19 with BooleanExpr

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

the class RoutePolicyBooleanAnd method toBooleanExpr.

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

Example 20 with BooleanExpr

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

the class Optimizations method isDefaultBgpExport.

/*
   * Determine if a BGP neighbor uses the default export policy
   */
private boolean isDefaultBgpExport(Configuration conf, BgpNeighbor n) {
    // Check if valid neighbor
    if (n == null || n.getExportPolicy() == null) {
        return true;
    }
    // Ensure a single if statement
    RoutingPolicy pol = conf.getRoutingPolicies().get(n.getExportPolicy());
    List<Statement> stmts = pol.getStatements();
    if (stmts.size() != 1) {
        return false;
    }
    Statement s = stmts.get(0);
    if (!(s instanceof If)) {
        return false;
    }
    // Ensure that the true branch accepts and the false branch rejects
    If i = (If) s;
    BooleanExpr be = i.getGuard();
    List<Statement> trueStmts = i.getTrueStatements();
    List<Statement> falseStmts = i.getFalseStatements();
    if (trueStmts.size() != 1 || falseStmts.size() != 1) {
        return false;
    }
    Statement s1 = trueStmts.get(0);
    Statement s2 = falseStmts.get(0);
    if (!(s1 instanceof Statements.StaticStatement) || !(s2 instanceof Statements.StaticStatement)) {
        return false;
    }
    Statements.StaticStatement x = (Statements.StaticStatement) s1;
    Statements.StaticStatement y = (Statements.StaticStatement) s2;
    if (x.getType() != Statements.ExitAccept || y.getType() != Statements.ExitReject) {
        return false;
    }
    // Ensure condition just hands off to the common export policy
    if (!(be instanceof CallExpr)) {
        return false;
    }
    CallExpr ce = (CallExpr) be;
    return ce.getCalledPolicyName().contains(Graph.BGP_COMMON_FILTER_LIST_NAME);
}
Also used : Statement(org.batfish.datamodel.routing_policy.statement.Statement) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) CallExpr(org.batfish.datamodel.routing_policy.expr.CallExpr) Statements(org.batfish.datamodel.routing_policy.statement.Statements) If(org.batfish.datamodel.routing_policy.statement.If) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Aggregations

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