Search in sources :

Example 1 with OspfExternalType2Route

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

the class VirtualRouter method propagateOspfExternalRoutes.

public boolean propagateOspfExternalRoutes(Map<String, Node> nodes, Topology topology) {
    boolean changed = false;
    String node = _c.getHostname();
    OspfProcess proc = _vrf.getOspfProcess();
    if (proc != null) {
        int admin = RoutingProtocol.OSPF.getDefaultAdministrativeCost(_c.getConfigurationFormat());
        SortedSet<Edge> edges = topology.getNodeEdges().get(node);
        if (edges == null) {
            // there are no edges, so OSPF won't produce anything
            return false;
        }
        for (Edge edge : edges) {
            if (!edge.getNode1().equals(node)) {
                continue;
            }
            String connectingInterfaceName = edge.getInt1();
            Interface connectingInterface = _vrf.getInterfaces().get(connectingInterfaceName);
            if (connectingInterface == null) {
                // wrong vrf, so skip
                continue;
            }
            String neighborName = edge.getNode2();
            Node neighbor = nodes.get(neighborName);
            String neighborInterfaceName = edge.getInt2();
            OspfArea area = connectingInterface.getOspfArea();
            Configuration nc = neighbor._c;
            Interface neighborInterface = nc.getInterfaces().get(neighborInterfaceName);
            String neighborVrfName = neighborInterface.getVrfName();
            VirtualRouter neighborVirtualRouter = nodes.get(neighborName)._virtualRouters.get(neighborVrfName);
            OspfArea neighborArea = neighborInterface.getOspfArea();
            if (connectingInterface.getOspfEnabled() && !connectingInterface.getOspfPassive() && neighborInterface.getOspfEnabled() && !neighborInterface.getOspfPassive() && area != null && neighborArea != null && area.getName().equals(neighborArea.getName())) {
                /*
           * We have an ospf neighbor relationship on this edge. So we
           * should add all ospf external type 1(2) routes from this
           * neighbor into our ospf external type 1(2) staging rib. For
           * type 1, the cost of the route increases each time. For type 2,
           * the cost remains constant, but we must keep track of cost to
           * advertiser as a tie-breaker.
           */
                long connectingInterfaceCost = connectingInterface.getOspfCost();
                long incrementalCost = proc.getMaxMetricTransitLinks() != null ? proc.getMaxMetricTransitLinks() : connectingInterfaceCost;
                for (OspfExternalType1Route neighborRoute : neighborVirtualRouter._prevOspfExternalType1Rib.getRoutes()) {
                    long oldArea = neighborRoute.getArea();
                    long connectionArea = area.getName();
                    long newArea;
                    long baseMetric = neighborRoute.getMetric();
                    long baseCostToAdvertiser = neighborRoute.getCostToAdvertiser();
                    newArea = connectionArea;
                    if (oldArea != OspfRoute.NO_AREA) {
                        Long maxMetricSummaryNetworks = neighborVirtualRouter._vrf.getOspfProcess().getMaxMetricSummaryNetworks();
                        if (connectionArea != oldArea) {
                            if (connectionArea != 0L && oldArea != 0L) {
                                continue;
                            }
                            if (maxMetricSummaryNetworks != null) {
                                baseMetric = maxMetricSummaryNetworks + neighborRoute.getLsaMetric();
                                baseCostToAdvertiser = maxMetricSummaryNetworks;
                            }
                        }
                    }
                    long newMetric = baseMetric + incrementalCost;
                    long newCostToAdvertiser = baseCostToAdvertiser + incrementalCost;
                    OspfExternalType1Route newRoute = new OspfExternalType1Route(neighborRoute.getNetwork(), neighborInterface.getAddress().getIp(), admin, newMetric, neighborRoute.getLsaMetric(), newArea, newCostToAdvertiser, neighborRoute.getAdvertiser());
                    if (_ospfExternalType1StagingRib.mergeRoute(newRoute)) {
                        changed = true;
                    }
                }
                for (OspfExternalType2Route neighborRoute : neighborVirtualRouter._prevOspfExternalType2Rib.getRoutes()) {
                    long oldArea = neighborRoute.getArea();
                    long connectionArea = area.getName();
                    long newArea;
                    long baseCostToAdvertiser = neighborRoute.getCostToAdvertiser();
                    if (oldArea == OspfRoute.NO_AREA) {
                        newArea = connectionArea;
                    } else {
                        newArea = oldArea;
                        Long maxMetricSummaryNetworks = neighborVirtualRouter._vrf.getOspfProcess().getMaxMetricSummaryNetworks();
                        if (connectionArea != oldArea && maxMetricSummaryNetworks != null) {
                            baseCostToAdvertiser = maxMetricSummaryNetworks;
                        }
                    }
                    long newCostToAdvertiser = baseCostToAdvertiser + incrementalCost;
                    OspfExternalType2Route newRoute = new OspfExternalType2Route(neighborRoute.getNetwork(), neighborInterface.getAddress().getIp(), admin, neighborRoute.getMetric(), neighborRoute.getLsaMetric(), newArea, newCostToAdvertiser, neighborRoute.getAdvertiser());
                    if (_ospfExternalType2StagingRib.mergeRoute(newRoute)) {
                        changed = true;
                    }
                }
            }
        }
    }
    return changed;
}
Also used : OspfExternalType2Route(org.batfish.datamodel.OspfExternalType2Route) OspfArea(org.batfish.datamodel.OspfArea) Configuration(org.batfish.datamodel.Configuration) OspfProcess(org.batfish.datamodel.OspfProcess) OspfExternalType1Route(org.batfish.datamodel.OspfExternalType1Route) Edge(org.batfish.datamodel.Edge) Interface(org.batfish.datamodel.Interface)

Aggregations

Configuration (org.batfish.datamodel.Configuration)1 Edge (org.batfish.datamodel.Edge)1 Interface (org.batfish.datamodel.Interface)1 OspfArea (org.batfish.datamodel.OspfArea)1 OspfExternalType1Route (org.batfish.datamodel.OspfExternalType1Route)1 OspfExternalType2Route (org.batfish.datamodel.OspfExternalType2Route)1 OspfProcess (org.batfish.datamodel.OspfProcess)1