Stylistic changes to reduce code nesting
@@ -235,12 +235,16 @@ public class VirtualRouter extends ComparableStructure<String> {
static Long computeUpdatedOspfSummaryMetric(
OspfAreaRoute route, Prefix areaPrefix, @Nullable Long currentMetric, long areaNum) {
Prefix contributingRoutePrefix = route.getNetwork();
- // Compute for different areas only and if area prefix contains the route prefix
- if (areaNum != route.getArea() && areaPrefix.containsPrefix(contributingRoutePrefix)) {
+ // Only update metric for different areas and if the area prefix contains the route prefix
+ if (areaNum == route.getArea() || !areaPrefix.containsPrefix(contributingRoutePrefix)) {
+ return currentMetric;
+ }
long contributingRouteMetric = route.getMetric();
+ // Definitely update if we have no previous metric
if (currentMetric == null) {
return contributingRouteMetric;
- } else {
+ }
+ // Otherwise just take the best between route and current metrics
/*
* NOTE: The min function is used to compute the metric according to RFC 1583.
* HOWEVER, Cisco claims to have switched to using max function in IOS v.12.0 and later,
@@ -250,10 +254,6 @@ public class VirtualRouter extends ComparableStructure<String> {
*/
return Math.min(currentMetric, contributingRouteMetric);
}
- }
- // No changes, return current metric
- return currentMetric;
- }
boolean computeInterAreaSummaries() {
OspfProcess proc = _vrf.getOspfProcess();
