Search in sources :

Example 1 with AstVisitor

use of org.batfish.symbolic.AstVisitor in project batfish by batfish.

the class Optimizations method computeKeepAdminDistance.

/*
   * Check if administrative distance needs to be kept for
   * every single message. If it is never set with a custom
   * value, then it can be inferred for the best choice based
   * on the default protocol value.
   */
private boolean computeKeepAdminDistance() {
    if (!Optimizations.ENABLE_SLICING_OPTIMIZATION) {
        return true;
    }
    AstVisitor v = new AstVisitor();
    Boolean[] val = new Boolean[1];
    val[0] = false;
    _encoderSlice.getGraph().getConfigurations().forEach((router, conf) -> conf.getRoutingPolicies().forEach((name, pol) -> v.visit(conf, pol.getStatements(), stmt -> {
        if (stmt instanceof SetOspfMetricType) {
            val[0] = true;
        }
    }, expr -> {
    })));
    return val[0];
}
Also used : BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) If(org.batfish.datamodel.routing_policy.statement.If) Statements(org.batfish.datamodel.routing_policy.statement.Statements) HashMap(java.util.HashMap) BatfishException(org.batfish.common.BatfishException) BgpProcess(org.batfish.datamodel.BgpProcess) ArrayList(java.util.ArrayList) Interface(org.batfish.datamodel.Interface) HashSet(java.util.HashSet) HeaderQuestion(org.batfish.datamodel.questions.smt.HeaderQuestion) RouteFilterLine(org.batfish.datamodel.RouteFilterLine) Map(java.util.Map) Configuration(org.batfish.datamodel.Configuration) Statement(org.batfish.datamodel.routing_policy.statement.Statement) Set(java.util.Set) Graph(org.batfish.symbolic.Graph) GraphEdge(org.batfish.symbolic.GraphEdge) List(java.util.List) AstVisitor(org.batfish.symbolic.AstVisitor) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) CallExpr(org.batfish.datamodel.routing_policy.expr.CallExpr) GeneratedRoute(org.batfish.datamodel.GeneratedRoute) Protocol(org.batfish.symbolic.Protocol) BgpNeighbor(org.batfish.datamodel.BgpNeighbor) SetLocalPreference(org.batfish.datamodel.routing_policy.statement.SetLocalPreference) Table2(org.batfish.symbolic.collections.Table2) Prefix(org.batfish.datamodel.Prefix) SetOspfMetricType(org.batfish.datamodel.routing_policy.statement.SetOspfMetricType) AstVisitor(org.batfish.symbolic.AstVisitor) SetOspfMetricType(org.batfish.datamodel.routing_policy.statement.SetOspfMetricType)

Example 2 with AstVisitor

use of org.batfish.symbolic.AstVisitor in project batfish by batfish.

the class Optimizations method computeKeepOspfType.

/*
   * Check if we need to keep around the OSPF type. If the type
   * is never set via redistribution, and there is a single area,
   * then it is unnecessary.
   */
private boolean computeKeepOspfType() {
    if (!Optimizations.ENABLE_SLICING_OPTIMIZATION) {
        return true;
    }
    // First check if the ospf metric type is ever set
    AstVisitor v = new AstVisitor();
    Boolean[] val = new Boolean[1];
    val[0] = false;
    _encoderSlice.getGraph().getConfigurations().forEach((router, conf) -> conf.getRoutingPolicies().forEach((name, pol) -> v.visit(conf, pol.getStatements(), stmt -> {
        if (stmt instanceof SetOspfMetricType) {
            val[0] = true;
        }
    }, expr -> {
    })));
    if (val[0]) {
        return true;
    }
    // Next see if the there are multiple ospf areas
    Set<Long> areaIds = new HashSet<>();
    _encoderSlice.getGraph().getConfigurations().forEach((router, conf) -> {
        Set<Long> ids = _encoderSlice.getGraph().getAreaIds().get(router);
        areaIds.addAll(ids);
    });
    return areaIds.size() > 1;
}
Also used : BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) If(org.batfish.datamodel.routing_policy.statement.If) Statements(org.batfish.datamodel.routing_policy.statement.Statements) HashMap(java.util.HashMap) BatfishException(org.batfish.common.BatfishException) BgpProcess(org.batfish.datamodel.BgpProcess) ArrayList(java.util.ArrayList) Interface(org.batfish.datamodel.Interface) HashSet(java.util.HashSet) HeaderQuestion(org.batfish.datamodel.questions.smt.HeaderQuestion) RouteFilterLine(org.batfish.datamodel.RouteFilterLine) Map(java.util.Map) Configuration(org.batfish.datamodel.Configuration) Statement(org.batfish.datamodel.routing_policy.statement.Statement) Set(java.util.Set) Graph(org.batfish.symbolic.Graph) GraphEdge(org.batfish.symbolic.GraphEdge) List(java.util.List) AstVisitor(org.batfish.symbolic.AstVisitor) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) CallExpr(org.batfish.datamodel.routing_policy.expr.CallExpr) GeneratedRoute(org.batfish.datamodel.GeneratedRoute) Protocol(org.batfish.symbolic.Protocol) BgpNeighbor(org.batfish.datamodel.BgpNeighbor) SetLocalPreference(org.batfish.datamodel.routing_policy.statement.SetLocalPreference) Table2(org.batfish.symbolic.collections.Table2) Prefix(org.batfish.datamodel.Prefix) SetOspfMetricType(org.batfish.datamodel.routing_policy.statement.SetOspfMetricType) AstVisitor(org.batfish.symbolic.AstVisitor) SetOspfMetricType(org.batfish.datamodel.routing_policy.statement.SetOspfMetricType) HashSet(java.util.HashSet)

Example 3 with AstVisitor

use of org.batfish.symbolic.AstVisitor in project batfish by batfish.

the class Optimizations method computeKeepLocalPref.

/*
   * Check if the BGP local preference is needed. If it is never set,
   * then the variable can be removed from the encoding.
   */
private boolean computeKeepLocalPref() {
    if (!Optimizations.ENABLE_SLICING_OPTIMIZATION) {
        return true;
    }
    Boolean[] val = new Boolean[1];
    val[0] = false;
    _encoderSlice.getGraph().getConfigurations().forEach((router, conf) -> conf.getRoutingPolicies().forEach((name, pol) -> {
        AstVisitor v = new AstVisitor();
        v.visit(conf, pol.getStatements(), stmt -> {
            if (stmt instanceof SetLocalPreference) {
                val[0] = true;
            }
        }, expr -> {
        });
    }));
    return val[0];
}
Also used : BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) If(org.batfish.datamodel.routing_policy.statement.If) Statements(org.batfish.datamodel.routing_policy.statement.Statements) HashMap(java.util.HashMap) BatfishException(org.batfish.common.BatfishException) BgpProcess(org.batfish.datamodel.BgpProcess) ArrayList(java.util.ArrayList) Interface(org.batfish.datamodel.Interface) HashSet(java.util.HashSet) HeaderQuestion(org.batfish.datamodel.questions.smt.HeaderQuestion) RouteFilterLine(org.batfish.datamodel.RouteFilterLine) Map(java.util.Map) Configuration(org.batfish.datamodel.Configuration) Statement(org.batfish.datamodel.routing_policy.statement.Statement) Set(java.util.Set) Graph(org.batfish.symbolic.Graph) GraphEdge(org.batfish.symbolic.GraphEdge) List(java.util.List) AstVisitor(org.batfish.symbolic.AstVisitor) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) CallExpr(org.batfish.datamodel.routing_policy.expr.CallExpr) GeneratedRoute(org.batfish.datamodel.GeneratedRoute) Protocol(org.batfish.symbolic.Protocol) BgpNeighbor(org.batfish.datamodel.BgpNeighbor) SetLocalPreference(org.batfish.datamodel.routing_policy.statement.SetLocalPreference) Table2(org.batfish.symbolic.collections.Table2) Prefix(org.batfish.datamodel.Prefix) SetOspfMetricType(org.batfish.datamodel.routing_policy.statement.SetOspfMetricType) SetLocalPreference(org.batfish.datamodel.routing_policy.statement.SetLocalPreference) AstVisitor(org.batfish.symbolic.AstVisitor)

Aggregations

ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 BatfishException (org.batfish.common.BatfishException)3 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)3 BgpProcess (org.batfish.datamodel.BgpProcess)3 Configuration (org.batfish.datamodel.Configuration)3 GeneratedRoute (org.batfish.datamodel.GeneratedRoute)3 Interface (org.batfish.datamodel.Interface)3 Prefix (org.batfish.datamodel.Prefix)3 RouteFilterLine (org.batfish.datamodel.RouteFilterLine)3 HeaderQuestion (org.batfish.datamodel.questions.smt.HeaderQuestion)3 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)3 BooleanExpr (org.batfish.datamodel.routing_policy.expr.BooleanExpr)3 CallExpr (org.batfish.datamodel.routing_policy.expr.CallExpr)3 If (org.batfish.datamodel.routing_policy.statement.If)3 SetLocalPreference (org.batfish.datamodel.routing_policy.statement.SetLocalPreference)3