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];
}
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;
}
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];
}
Aggregations