Removed some sonar warnings in the new RIB code. 00/16200/4
authorDana Kutenicsova <dkutenic@cisco.com>
Mon, 9 Mar 2015 15:50:36 +0000 (16:50 +0100)
committerRobert Varga <nite@hq.sk>
Wed, 11 Mar 2015 21:40:43 +0000 (21:40 +0000)
- mostly attribute ordering, annotations are first
- final in method declaration is rarely necessary
- added default case to switch statements

Change-Id: I44abf4512fe64eb59504e0081d3dc88f23381960
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractExportPolicy.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractIPRIBSupport.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AbstractImportPolicy.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSessionImpl.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BestPathSelector.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BestPathState.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouterIds.java

index a6402b19775f288cc81856dd64ac84246997e101..8be46f93f0c7e503c4324d072b8b37b18c29f86f 100644 (file)
@@ -35,6 +35,8 @@ abstract class AbstractExportPolicy {
             case RrClient:
                 // Client iBGP -> eBGP, propagate
                 return attributes;
+            default:
+                break;
             }
             return attributes;
         }
@@ -70,6 +72,8 @@ abstract class AbstractExportPolicy {
             case RrClient:
                 // Client iBGP -> Non-Client iBGP, reflect
                 return toClientAttributes(attributes);
+            default:
+                break;
             }
             return attributes;
         }
@@ -94,9 +98,9 @@ abstract class AbstractExportPolicy {
             case RrClient:
                 // Client iBGP -> Client iBGP, reflect
                 return ToInternalExportPolicy.toClientAttributes(attributes);
+            default:
+                throw new IllegalStateException("Unhandled source role " + sourceRole);
             }
-
-            throw new IllegalStateException("Unhandled source role " + sourceRole);
         }
     }
 
index cfd14de4fb73a50626d9fd73fee75d8d16a23387..4cae38aeb4bfb7bc07d2209f9a8576f480e2dc4c 100644 (file)
@@ -100,7 +100,7 @@ abstract class AbstractIPRIBSupport extends AbstractRIBSupport {
                 final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
                 if (routes instanceof MapNode) {
                     final YangInstanceIdentifier base = tablePath.node(ROUTES).node(routesContainerIdentifier());
-                    for (MapEntryNode e : ((MapNode)routes).getValue()) {
+                    for (final MapEntryNode e : ((MapNode)routes).getValue()) {
                         function.apply(tx, base, e, attributes);
                     }
                 } else {
index d917450cd5e80d938a78f85070b272ce67378c5b..7851fb3579d5044ee0408c041a43abf689b79f5f 100644 (file)
@@ -65,5 +65,5 @@ abstract class AbstractImportPolicy {
      * @param attributes received attributes
      * @return Filtered attributes, or null if the advertisement should be ignored.
      */
-    abstract @Nullable ContainerNode effectiveAttributes(@Nullable ContainerNode attributes);
+    @Nullable abstract ContainerNode effectiveAttributes(@Nullable ContainerNode attributes);
 }
\ No newline at end of file
index ba4e1a455240002b643c0f7062a011f78f100c9b..1603cabbce7c31547d7cbef861ed684ffb6afe24 100644 (file)
@@ -227,7 +227,7 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
     }
 
     @GuardedBy("this")
-    private final void writeEpilogue(final ChannelFuture future, final Notification msg) {
+    private void writeEpilogue(final ChannelFuture future, final Notification msg) {
         future.addListener(
             new ChannelFutureListener() {
                 @Override
@@ -406,6 +406,6 @@ public class BGPSessionImpl extends AbstractProtocolSession<Notification> implem
     }
 
     ChannelOutputLimiter getLimiter() {
-        return limiter;
+        return this.limiter;
     }
 }
index 09562a0e081c04433a01ce8805747a88b96ecfcb..279958b77cc8235b37317f606734e3377b85da92 100644 (file)
@@ -76,7 +76,7 @@ final class BestPathSelector {
      * @param state attributes of the new route
      * @return true if the existing path is better, false if the new path is better
      */
-    private boolean selectPath(final @Nonnull UnsignedInteger originatorId, final @Nonnull BestPathState state) {
+    private boolean selectPath(@Nonnull final UnsignedInteger originatorId, @Nonnull final BestPathState state) {
         // 1. prefer path with accessible nexthop
         // - we assume that all nexthops are accessible
 
@@ -86,16 +86,14 @@ final class BestPathSelector {
          * FIXME: for eBGP cases (when the LOCAL_PREF is missing), we should assign a policy-based preference
          *        before we ever get here.
          */
-        if (bestState.getLocalPref() == null && state.getLocalPref() != null) {
+        if (this.bestState.getLocalPref() == null && state.getLocalPref() != null) {
             return true;
         }
-        if (bestState.getLocalPref() != null && state.getLocalPref() == null) {
+        if (this.bestState.getLocalPref() != null && state.getLocalPref() == null) {
             return false;
         }
-        if (state.getLocalPref() != null) {
-            if (state.getLocalPref() > this.bestState.getLocalPref()) {
-                return true;
-            }
+        if (state.getLocalPref() != null && state.getLocalPref() > this.bestState.getLocalPref()) {
+            return true;
         }
 
         // 3. prefer learned path
index eeecaccb02e8883ccc598fd041c1414630c4e861..e928ee4d459b8fc2094e04f978deab11f831fb0c 100644 (file)
@@ -43,54 +43,54 @@ final class BestPathState {
     private Long localPref;
     private Long multiExitDisc;
     private BgpOrigin origin;
-    private final Long peerAs = 0L;
-    private final int asPathLength = 0;
+    private static final Long peerAs = 0L;
+    private static final int asPathLength = 0;
     private boolean resolved;
 
     BestPathState(final ContainerNode attributes) {
         this.attributes = Preconditions.checkNotNull(attributes);
     }
 
+    private static BgpOrigin fromString(final String originStr) {
+        switch (originStr) {
+        case "igp":
+            return BgpOrigin.Igp;
+        case "egp":
+            return BgpOrigin.Egp;
+        case "incomplete":
+            return BgpOrigin.Incomplete;
+        default:
+            throw new IllegalArgumentException("Unhandleed origin value " + originStr);
+        }
+    }
+
     private void resolveValues() {
-        if (resolved) {
+        if (this.resolved) {
             return;
         }
 
-        final Optional<NormalizedNode<?, ?>> maybeLocalPref = NormalizedNodes.findNode(attributes, LOCAL_PREF);
+        final Optional<NormalizedNode<?, ?>> maybeLocalPref = NormalizedNodes.findNode(this.attributes, LOCAL_PREF);
         if (maybeLocalPref.isPresent()) {
-            localPref = (Long) ((LeafNode<?>)maybeLocalPref.get()).getValue();
+            this.localPref = (Long) ((LeafNode<?>)maybeLocalPref.get()).getValue();
         } else {
-            localPref = null;
+            this.localPref = null;
         }
 
-        final Optional<NormalizedNode<?, ?>> maybeMultiExitDisc = NormalizedNodes.findNode(attributes, MED);
+        final Optional<NormalizedNode<?, ?>> maybeMultiExitDisc = NormalizedNodes.findNode(this.attributes, MED);
         if (maybeMultiExitDisc.isPresent()) {
-            multiExitDisc = (Long) ((LeafNode<?>)maybeMultiExitDisc.get()).getValue();
+            this.multiExitDisc = (Long) ((LeafNode<?>)maybeMultiExitDisc.get()).getValue();
         } else {
-            multiExitDisc = null;
+            this.multiExitDisc = null;
         }
 
-        final Optional<NormalizedNode<?, ?>> maybeOrigin = NormalizedNodes.findNode(attributes, ORIGIN);
+        final Optional<NormalizedNode<?, ?>> maybeOrigin = NormalizedNodes.findNode(this.attributes, ORIGIN);
         if (maybeOrigin.isPresent()) {
-            final String originStr = (String) ((LeafNode<?>)maybeOrigin.get()).getValue();
-            switch (originStr) {
-            case "igp":
-                origin = BgpOrigin.Igp;
-                break;
-            case "egp":
-                origin = BgpOrigin.Egp;
-                break;
-            case "incomplete":
-                origin = BgpOrigin.Incomplete;
-                break;
-            default:
-                throw new IllegalArgumentException("Unhandleed origin value " + originStr);
-            }
+            this.origin = fromString((String) ((LeafNode<?>)maybeOrigin.get()).getValue());
         } else {
-            origin = null;
+            this.origin = null;
         }
 
-        final Optional<NormalizedNode<?, ?>> maybeSegments = NormalizedNodes.findNode(attributes, AS_PATH);
+        final Optional<NormalizedNode<?, ?>> maybeSegments = NormalizedNodes.findNode(this.attributes, AS_PATH);
         if (maybeSegments.isPresent()) {
             final UnkeyedListNode segments = (UnkeyedListNode) maybeSegments.get();
 
@@ -98,34 +98,34 @@ final class BestPathState {
                 // FIXME: peer AS number
 
                 // FIXME: asPathLength = countAsPath(this.bestState.getAsPath().getSegments());
-                boolean haveSegment;
-                for (UnkeyedListEntryNode s : segments.getValue()) {
+                final boolean haveSegment;
+                for (final UnkeyedListEntryNode s : segments.getValue()) {
 
                 }
             }
         }
 
-        resolved = true;
+        this.resolved = true;
     }
 
     Long getLocalPref() {
         resolveValues();
-        return localPref;
+        return this.localPref;
     }
 
     Long getMultiExitDisc() {
         resolveValues();
-        return multiExitDisc;
+        return this.multiExitDisc;
     }
 
     BgpOrigin getOrigin() {
         resolveValues();
-        return origin;
+        return this.origin;
     }
 
     Long getPeerAs() {
         resolveValues();
-        return peerAs;
+        return this.peerAs;
     }
 
     int getAsPathLength() {
index 2628b23bf857471936f7998e766684ee00292a26..3662ac60376e8490717d7a04a29cdea635a65b36 100644 (file)
@@ -61,40 +61,38 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
          * calculations when multiple peers have changed a particular entry.
          */
         final Map<RouteUpdateKey, RouteEntry> toUpdate = new HashMap<>();
-        for (DataTreeCandidate tc : changes) {
+        for (final DataTreeCandidate tc : changes) {
             final YangInstanceIdentifier path = tc.getRootPath();
             final PathArgument routeId = path.getLastPathArgument();
             final NodeIdentifierWithPredicates peerKey = IdentifierUtils.peerKey(path);
             final PeerId peerId = IdentifierUtils.peerId(peerKey);
             final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId);
 
-            RouteEntry entry = routeEntries.get(routeId);
+            RouteEntry entry = this.routeEntries.get(routeId);
             if (tc.getRootNode().getDataAfter().isPresent()) {
                 if (entry == null) {
                     entry = new RouteEntry();
-                    routeEntries.put(routeId, entry);
+                    this.routeEntries.put(routeId, entry);
                 }
 
                 entry.addRoute(routerId, (ContainerNode) tc.getRootNode().getDataAfter().get());
-            } else if (entry != null) {
-                if (entry.removeRoute(routerId)) {
-                    routeEntries.remove(routeId);
-                    entry = null;
-                }
+            } else if (entry != null && entry.removeRoute(routerId)) {
+                this.routeEntries.remove(routeId);
+                entry = null;
             }
 
             toUpdate.put(new RouteUpdateKey(peerId, routeId), entry);
         }
 
-        final DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
+        final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
 
         // Now walk all updated entries
-        for (Entry<RouteUpdateKey, RouteEntry> e : toUpdate.entrySet()) {
+        for (final Entry<RouteUpdateKey, RouteEntry> e : toUpdate.entrySet()) {
             final RouteEntry entry = e.getValue();
             final NormalizedNode<?, ?> value;
 
             if (entry != null) {
-                if (!entry.selectBest(ourAs)) {
+                if (!entry.selectBest(this.ourAs)) {
                     // Best path has not changed, no need to do anything else. Proceed to next route.
                     continue;
                 }
@@ -105,9 +103,9 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
             }
 
             if (value != null) {
-                tx.put(LogicalDatastoreType.OPERATIONAL, target.node(e.getKey().getRouteId()), value);
+                tx.put(LogicalDatastoreType.OPERATIONAL, this.target.node(e.getKey().getRouteId()), value);
             } else {
-                tx.delete(LogicalDatastoreType.OPERATIONAL, target.node(e.getKey().getRouteId()));
+                tx.delete(LogicalDatastoreType.OPERATIONAL, this.target.node(e.getKey().getRouteId()));
             }
 
             /*
@@ -126,7 +124,7 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
                     final PeerId peerId = e.getKey().getPeerId();
                     final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(peerId, attributes);
 
-                    for (Entry<PeerId, YangInstanceIdentifier> pid : peerGroup.getPeers()) {
+                    for (final Entry<PeerId, YangInstanceIdentifier> pid : peerGroup.getPeers()) {
                         // This points to adj-rib-out for a particular peer/table combination
                         final YangInstanceIdentifier routeTarget = pid.getValue().node(e.getKey().getRouteId());
 
index ddaeb43ff054dce3d101931b3998f732ee0ab28f..a638c693663954950b4e4b75d3348f498abd9fab 100644 (file)
@@ -42,11 +42,11 @@ final class RouterIds {
      * @param address Router ID as a dotted-quad
      * @return Router ID as an {@link UnsignedInteger}
      */
-    public static UnsignedInteger routerIdForAddress(final @Nonnull String address) {
+    public static UnsignedInteger routerIdForAddress(@Nonnull final String address) {
         return ROUTER_IDS.getUnchecked(address);
     }
 
-    public static UnsignedInteger routerIdForPeerId(final @Nonnull PeerId peerId) {
+    public static UnsignedInteger routerIdForPeerId(@Nonnull final PeerId peerId) {
         Preconditions.checkArgument(peerId.getValue().startsWith(BGP_PREFIX), "Unhandled peer ID %s", peerId);
         return BGP_ROUTER_IDS.getUnchecked(peerId);
     }