Search in sources :

Example 6 with OspfAreaSummary

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

the class VirtualRouter method computeInterAreaSummaries.

boolean computeInterAreaSummaries() {
    OspfProcess proc = _vrf.getOspfProcess();
    boolean changed = false;
    // Ensure we have a running OSPF process on the VRF, otherwise bail.
    if (proc == null) {
        return false;
    }
    // Admin cost for the given protocol
    int admin = RoutingProtocol.OSPF_IA.getSummaryAdministrativeCost(_c.getConfigurationFormat());
    // Determine whether to use min metric by default, based on RFC1583 compatibility setting.
    // Routers (at least Cisco and Juniper) default to min metric unless using RFC2328 with
    // RFC1583 compatibility explicitly disabled, in which case they default to max.
    boolean useMin = MoreObjects.firstNonNull(proc.getRfc1583Compatible(), true);
    // Compute summaries for each area
    for (Entry<Long, OspfArea> e : proc.getAreas().entrySet()) {
        long areaNum = e.getKey();
        OspfArea area = e.getValue();
        for (Entry<Prefix, OspfAreaSummary> e2 : area.getSummaries().entrySet()) {
            Prefix prefix = e2.getKey();
            OspfAreaSummary summary = e2.getValue();
            // Only advertised summaries can contribute
            if (!summary.getAdvertised()) {
                continue;
            }
            Long metric = summary.getMetric();
            if (summary.getMetric() == null) {
                // No metric was configured; compute it from any possible contributing routes.
                for (OspfIntraAreaRoute contributingRoute : _ospfIntraAreaRib.getRoutes()) {
                    metric = computeUpdatedOspfSummaryMetric(contributingRoute, prefix, metric, areaNum, useMin);
                }
                for (OspfInterAreaRoute contributingRoute : _ospfInterAreaRib.getRoutes()) {
                    metric = computeUpdatedOspfSummaryMetric(contributingRoute, prefix, metric, areaNum, useMin);
                }
            }
            // No routes contributed to the summary, nothing to construct
            if (metric == null) {
                continue;
            }
            // Non-null metric means we generate a new summary and put it in the RIB
            OspfInterAreaRoute summaryRoute = new OspfInterAreaRoute(prefix, Ip.ZERO, admin, metric, areaNum);
            if (_ospfInterAreaStagingRib.mergeRoute(summaryRoute)) {
                changed = true;
            }
        }
    }
    return changed;
}
Also used : OspfArea(org.batfish.datamodel.OspfArea) OspfAreaSummary(org.batfish.datamodel.OspfAreaSummary) OspfIntraAreaRoute(org.batfish.datamodel.OspfIntraAreaRoute) OspfInterAreaRoute(org.batfish.datamodel.OspfInterAreaRoute) OspfProcess(org.batfish.datamodel.OspfProcess) Prefix(org.batfish.datamodel.Prefix)

Aggregations

OspfAreaSummary (org.batfish.datamodel.OspfAreaSummary)6 Prefix (org.batfish.datamodel.Prefix)5 LiteralLong (org.batfish.datamodel.routing_policy.expr.LiteralLong)3 Ip (org.batfish.datamodel.Ip)2 OspfArea (org.batfish.datamodel.OspfArea)2 VarLong (org.batfish.datamodel.routing_policy.expr.VarLong)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Configuration (org.batfish.datamodel.Configuration)1 GeneratedRoute (org.batfish.datamodel.GeneratedRoute)1 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)1 OspfInterAreaRoute (org.batfish.datamodel.OspfInterAreaRoute)1 OspfIntraAreaRoute (org.batfish.datamodel.OspfIntraAreaRoute)1 OspfMetricType (org.batfish.datamodel.OspfMetricType)1