use of org.batfish.datamodel.routing_policy.expr.BooleanExpr 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();
}
use of org.batfish.datamodel.routing_policy.expr.BooleanExpr 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();
}
use of org.batfish.datamodel.routing_policy.expr.BooleanExpr 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();
}
use of org.batfish.datamodel.routing_policy.expr.BooleanExpr 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();
}
use of org.batfish.datamodel.routing_policy.expr.BooleanExpr in project batfish by batfish.
the class Graph method getOriginatedNetworks.
/*
* Collects and returns all originated prefixes for the given
* router as well as the protocol. Static routes and connected
* routes are treated as originating the prefix.
*/
public static Set<Prefix> getOriginatedNetworks(Configuration conf, Protocol proto) {
Set<Prefix> acc = new HashSet<>();
if (proto.isOspf()) {
OspfProcess ospf = conf.getDefaultVrf().getOspfProcess();
for (OspfArea area : ospf.getAreas().values()) {
for (String ifaceName : area.getInterfaces()) {
Interface iface = conf.getInterfaces().get(ifaceName);
if (iface.getActive() && iface.getOspfEnabled()) {
acc.add(iface.getAddress().getPrefix());
}
}
}
return acc;
}
if (proto.isBgp()) {
RoutingPolicy defaultPol = findCommonRoutingPolicy(conf, Protocol.BGP);
if (defaultPol != null) {
AstVisitor v = new AstVisitor();
v.visit(conf, defaultPol.getStatements(), stmt -> {
}, expr -> {
if (expr instanceof Conjunction) {
Conjunction c = (Conjunction) expr;
if (c.getConjuncts().size() >= 2) {
BooleanExpr be1 = c.getConjuncts().get(0);
BooleanExpr be2 = c.getConjuncts().get(1);
if (be1 instanceof MatchPrefixSet && be2 instanceof Not) {
MatchPrefixSet mps = (MatchPrefixSet) be1;
Not n = (Not) be2;
if (n.getExpr() instanceof MatchProtocol) {
MatchProtocol mp = (MatchProtocol) n.getExpr();
if (mp.getProtocol() == RoutingProtocol.BGP) {
PrefixSetExpr e = mps.getPrefixSet();
if (e instanceof ExplicitPrefixSet) {
ExplicitPrefixSet eps = (ExplicitPrefixSet) e;
Set<PrefixRange> ranges = eps.getPrefixSpace().getPrefixRanges();
for (PrefixRange r : ranges) {
acc.add(r.getPrefix());
}
}
}
}
}
}
}
});
}
return acc;
}
if (proto.isConnected()) {
for (Interface iface : conf.getInterfaces().values()) {
InterfaceAddress address = iface.getAddress();
if (address != null) {
acc.add(address.getPrefix());
}
}
return acc;
}
if (proto.isStatic()) {
for (StaticRoute sr : conf.getDefaultVrf().getStaticRoutes()) {
if (sr.getNetwork() != null) {
acc.add(sr.getNetwork());
}
}
return acc;
}
throw new BatfishException("ERROR: getOriginatedNetworks: " + proto.name());
}
Aggregations