Search in sources :

Example 1 with BooleanExpr

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();
}
Also used : NamedPrefixSet(org.batfish.datamodel.routing_policy.expr.NamedPrefixSet) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) DestinationNetwork(org.batfish.datamodel.routing_policy.expr.DestinationNetwork) RouteFilterList(org.batfish.datamodel.RouteFilterList) MatchIpAccessList(org.batfish.datamodel.routing_policy.expr.MatchIpAccessList) MatchIpAccessList(org.batfish.datamodel.routing_policy.expr.MatchIpAccessList) IpAccessList(org.batfish.datamodel.IpAccessList) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Example 2 with BooleanExpr

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();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) MatchTag(org.batfish.datamodel.routing_policy.expr.MatchTag) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) LiteralInt(org.batfish.datamodel.routing_policy.expr.LiteralInt)

Example 3 with BooleanExpr

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();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) NamedCommunitySet(org.batfish.datamodel.routing_policy.expr.NamedCommunitySet) MatchCommunitySet(org.batfish.datamodel.routing_policy.expr.MatchCommunitySet) CommunityList(org.batfish.datamodel.CommunityList) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Example 4 with BooleanExpr

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();
}
Also used : Disjunction(org.batfish.datamodel.routing_policy.expr.Disjunction) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr)

Example 5 with BooleanExpr

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());
}
Also used : BatfishException(org.batfish.common.BatfishException) PrefixRange(org.batfish.datamodel.PrefixRange) StaticRoute(org.batfish.datamodel.StaticRoute) OspfArea(org.batfish.datamodel.OspfArea) InterfaceAddress(org.batfish.datamodel.InterfaceAddress) MatchPrefixSet(org.batfish.datamodel.routing_policy.expr.MatchPrefixSet) PrefixSetExpr(org.batfish.datamodel.routing_policy.expr.PrefixSetExpr) OspfProcess(org.batfish.datamodel.OspfProcess) RoutingPolicy(org.batfish.datamodel.routing_policy.RoutingPolicy) Prefix(org.batfish.datamodel.Prefix) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol) Not(org.batfish.datamodel.routing_policy.expr.Not) ExplicitPrefixSet(org.batfish.datamodel.routing_policy.expr.ExplicitPrefixSet) Conjunction(org.batfish.datamodel.routing_policy.expr.Conjunction) Interface(org.batfish.datamodel.Interface) BooleanExpr(org.batfish.datamodel.routing_policy.expr.BooleanExpr) HashSet(java.util.HashSet)

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