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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations