Search in sources :

Example 6 with RoutingProtocol

use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitRo_redistribute_static.

@Override
public void exitRo_redistribute_static(Ro_redistribute_staticContext ctx) {
    OspfProcess proc = _currentOspfProcess;
    RoutingProtocol sourceProtocol = RoutingProtocol.STATIC;
    OspfRedistributionPolicy r = new OspfRedistributionPolicy(sourceProtocol);
    proc.getRedistributionPolicies().put(sourceProtocol, r);
    if (ctx.metric != null) {
        int metric = toInteger(ctx.metric);
        r.setMetric(metric);
    }
    if (ctx.map != null) {
        String map = ctx.map.getText();
        int mapLine = ctx.map.getLine();
        r.setRouteMap(map);
        r.setRouteMapLine(mapLine);
    }
    if (ctx.type != null) {
        int typeInt = toInteger(ctx.type);
        OspfMetricType type = OspfMetricType.fromInteger(typeInt);
        r.setOspfMetricType(type);
    } else {
        r.setOspfMetricType(OspfRedistributionPolicy.DEFAULT_METRIC_TYPE);
    }
    if (ctx.tag != null) {
        long tag = toLong(ctx.tag);
        r.setTag(tag);
    }
    r.setSubnets(ctx.subnets != null);
}
Also used : RoutingProtocol(org.batfish.datamodel.RoutingProtocol) OspfMetricType(org.batfish.datamodel.OspfMetricType) RoutePolicySetOspfMetricType(org.batfish.representation.cisco.RoutePolicySetOspfMetricType) OspfRedistributionPolicy(org.batfish.representation.cisco.OspfRedistributionPolicy) OspfProcess(org.batfish.representation.cisco.OspfProcess)

Example 7 with RoutingProtocol

use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitRedistribute_static_is_stanza.

@Override
public void exitRedistribute_static_is_stanza(Redistribute_static_is_stanzaContext ctx) {
    IsisProcess proc = currentVrf().getIsisProcess();
    RoutingProtocol sourceProtocol = RoutingProtocol.STATIC;
    IsisRedistributionPolicy r = new IsisRedistributionPolicy(sourceProtocol);
    proc.getRedistributionPolicies().put(sourceProtocol, r);
    if (ctx.metric != null) {
        int metric = toInteger(ctx.metric);
        r.setMetric(metric);
    }
    if (ctx.map != null) {
        String map = ctx.map.getText();
        r.setMap(map);
    }
    if (ctx.LEVEL_1() != null) {
        r.setLevel(IsisLevel.LEVEL_1);
    } else if (ctx.LEVEL_2() != null) {
        r.setLevel(IsisLevel.LEVEL_2);
    } else if (ctx.LEVEL_1_2() != null) {
        r.setLevel(IsisLevel.LEVEL_1_2);
    } else {
        r.setLevel(IsisRedistributionPolicy.DEFAULT_LEVEL);
    }
}
Also used : RoutingProtocol(org.batfish.datamodel.RoutingProtocol) IsisProcess(org.batfish.representation.cisco.IsisProcess) IsisRedistributionPolicy(org.batfish.representation.cisco.IsisRedistributionPolicy)

Example 8 with RoutingProtocol

use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.

the class CiscoControlPlaneExtractor method exitRo_redistribute_connected.

@Override
public void exitRo_redistribute_connected(Ro_redistribute_connectedContext ctx) {
    OspfProcess proc = _currentOspfProcess;
    RoutingProtocol sourceProtocol = RoutingProtocol.CONNECTED;
    OspfRedistributionPolicy r = new OspfRedistributionPolicy(sourceProtocol);
    proc.getRedistributionPolicies().put(sourceProtocol, r);
    if (ctx.metric != null) {
        int metric = toInteger(ctx.metric);
        r.setMetric(metric);
    }
    if (ctx.map != null) {
        String map = ctx.map.getText();
        int mapLine = ctx.map.getLine();
        r.setRouteMap(map);
        r.setRouteMapLine(mapLine);
    }
    if (ctx.type != null) {
        int typeInt = toInteger(ctx.type);
        OspfMetricType type = OspfMetricType.fromInteger(typeInt);
        r.setOspfMetricType(type);
    } else {
        r.setOspfMetricType(OspfRedistributionPolicy.DEFAULT_METRIC_TYPE);
    }
    if (ctx.tag != null) {
        long tag = toLong(ctx.tag);
        r.setTag(tag);
    }
    r.setSubnets(ctx.subnets != null);
}
Also used : RoutingProtocol(org.batfish.datamodel.RoutingProtocol) OspfMetricType(org.batfish.datamodel.OspfMetricType) RoutePolicySetOspfMetricType(org.batfish.representation.cisco.RoutePolicySetOspfMetricType) OspfRedistributionPolicy(org.batfish.representation.cisco.OspfRedistributionPolicy) OspfProcess(org.batfish.representation.cisco.OspfProcess)

Example 9 with RoutingProtocol

use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.

the class NxosRoutingTableExtractor method exitRoute.

@Override
public void exitRoute(RouteContext ctx) {
    if (ctx.protocol().LOCAL() != null) {
        return;
    }
    if (_currentVrfRoutes == null) {
        initVrf(Configuration.DEFAULT_VRF_NAME);
    }
    RoutingProtocol protocol = toProtocol(ctx.protocol());
    String nextHopInterface = Route.UNSET_NEXT_HOP_INTERFACE;
    if (ctx.nexthopint != null) {
        nextHopInterface = ctx.nexthopint.getText();
    }
    int admin = toInteger(ctx.admin);
    int cost = toInteger(ctx.cost);
    Ip nextHopIp = Route.UNSET_ROUTE_NEXT_HOP_IP;
    if (protocol != RoutingProtocol.CONNECTED && ctx.nexthop != null) {
        nextHopIp = new Ip(ctx.nexthop.getText());
    }
    RouteBuilder rb = new RouteBuilder();
    rb.setNode(_hostname);
    rb.setNetwork(_currentPrefix);
    if (protocol == RoutingProtocol.CONNECTED || (protocol == RoutingProtocol.STATIC && nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) || Interface.NULL_INTERFACE_NAME.equals(nextHopInterface)) {
        rb.setNextHop(Configuration.NODE_NONE_NAME);
    }
    if (!nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) {
        rb.setNextHopIp(nextHopIp);
        String nextHop = _ipOwners.get(nextHopIp);
        if (nextHop != null) {
            rb.setNextHop(nextHop);
        }
    }
    if (nextHopInterface != null) {
        rb.setNextHopInterface(nextHopInterface);
    }
    rb.setAdministrativeCost(admin);
    rb.setCost(cost);
    rb.setProtocol(protocol);
    rb.setTag(Route.UNSET_ROUTE_TAG);
    rb.setVrf(_currentVrfName);
    Route route = rb.build();
    _currentVrfRoutes.add(route);
}
Also used : RoutingProtocol(org.batfish.datamodel.RoutingProtocol) RouteBuilder(org.batfish.datamodel.RouteBuilder) Ip(org.batfish.datamodel.Ip) Route(org.batfish.datamodel.Route)

Example 10 with RoutingProtocol

use of org.batfish.datamodel.RoutingProtocol in project batfish by batfish.

the class Graph method findRedistributedProtocols.

/*
   * Find the set of all protocols that might be redistributed into
   * protocol p given the current configuration and routing policy.
   * This is based on structure of the AST.
   */
public Set<Protocol> findRedistributedProtocols(Configuration conf, RoutingPolicy pol, Protocol p) {
    Set<Protocol> protos = new HashSet<>();
    AstVisitor v = new AstVisitor();
    v.visit(conf, pol.getStatements(), stmt -> {
    }, expr -> {
        if (expr instanceof MatchProtocol) {
            MatchProtocol mp = (MatchProtocol) expr;
            RoutingProtocol other = mp.getProtocol();
            Protocol otherP = Protocol.fromRoutingProtocol(other);
            if (otherP != null && otherP != p) {
                switch(other) {
                    case BGP:
                        protos.add(otherP);
                        break;
                    case OSPF:
                        protos.add(otherP);
                        break;
                    case STATIC:
                        protos.add(otherP);
                        break;
                    case CONNECTED:
                        protos.add(otherP);
                        break;
                    default:
                        throw new BatfishException("Unrecognized protocol: " + other.protocolName());
                }
            }
        }
    });
    return protos;
}
Also used : BatfishException(org.batfish.common.BatfishException) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol) RoutingProtocol(org.batfish.datamodel.RoutingProtocol) HashSet(java.util.HashSet) MatchProtocol(org.batfish.datamodel.routing_policy.expr.MatchProtocol)

Aggregations

RoutingProtocol (org.batfish.datamodel.RoutingProtocol)19 BatfishException (org.batfish.common.BatfishException)10 Ip (org.batfish.datamodel.Ip)7 Prefix (org.batfish.datamodel.Prefix)6 RedFlagBatfishException (org.batfish.common.RedFlagBatfishException)5 BgpProcess (org.batfish.representation.cisco.BgpProcess)5 TreeSet (java.util.TreeSet)4 BgpRedistributionPolicy (org.batfish.representation.cisco.BgpRedistributionPolicy)4 AsPath (org.batfish.datamodel.AsPath)3 BgpAdvertisement (org.batfish.datamodel.BgpAdvertisement)3 BgpAdvertisementType (org.batfish.datamodel.BgpAdvertisement.BgpAdvertisementType)3 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)3 BgpRoute (org.batfish.datamodel.BgpRoute)3 OriginType (org.batfish.datamodel.OriginType)3 OspfMetricType (org.batfish.datamodel.OspfMetricType)3 Route (org.batfish.datamodel.Route)3 RouteBuilder (org.batfish.datamodel.RouteBuilder)3 RoutingPolicy (org.batfish.datamodel.routing_policy.RoutingPolicy)3 IsisRedistributionPolicy (org.batfish.representation.cisco.IsisRedistributionPolicy)3 AbstractRoute (org.batfish.datamodel.AbstractRoute)2