Code cleanup: Duplicate Code 10/58010/3
authormatcauf <mcauffiez@inocybe.ca>
Fri, 26 May 2017 19:03:21 +0000 (15:03 -0400)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Thu, 1 Jun 2017 20:07:58 +0000 (20:07 +0000)
Remove duplicated code

Change-Id: I318e391e95bc892ebcf6af3081a455e84843c93a
Signed-off-by: matcauf <mcauffiez@inocybe.ca>
(cherry picked from commit 54c65cb54ea79c7681d3dee6c0a289bd90f8b5b3)

bgp/bmp-parser-impl/src/main/java/org/opendaylight/protocol/bmp/parser/message/PeerDownHandler.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/StrictBGPPeerRegistry.java

index fdcf7c03c2fc798c99a7713f2d1429d505ea2f6a..bfbb95a471d6919b2e303c4566357d4f9954b98c 100644 (file)
@@ -85,9 +85,6 @@ public class PeerDownHandler extends AbstractBmpPerPeerMessageParser<PeerDownNot
                 peerDown.setData(new FsmEventCodeBuilder().setFsmEventCode(bytes.readUnsignedShort()).build());
                 break;
             case REASON_THREE:
-                peerDown.setLocalSystemClosed(false);
-                peerDown.setData(parseBgpNotificationMessage(bytes));
-                break;
             case REASON_FOUR:
                 peerDown.setLocalSystemClosed(false);
                 peerDown.setData(parseBgpNotificationMessage(bytes));
index 541da34782198d94fcf165aac09fc67091f64d50..18161d630940523b143b91b2c64b671b7571761c 100644 (file)
@@ -153,7 +153,8 @@ public final class StrictBGPPeerRegistry implements BGPPeerRegistry {
                         BGPError.CEASE);
 
                 // Session reestablished with lower source bgp id, dropping current
-            } else if (previousConnection.isHigherDirection(currentConnection)) {
+            } else if (previousConnection.isHigherDirection(currentConnection) ||
+                    previousConnection.hasHigherAsNumber(currentConnection)) {
                 LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
                 throw new BGPDocumentedException(
                     String.format("BGP session with %s initiated %s has to be dropped. Opposite session already present",
@@ -161,22 +162,12 @@ public final class StrictBGPPeerRegistry implements BGPPeerRegistry {
                         BGPError.CEASE);
 
                 // Session reestablished with higher source bgp id, dropping previous
-            } else if (currentConnection.isHigherDirection(previousConnection)) {
+            } else if (currentConnection.isHigherDirection(previousConnection) ||
+                    currentConnection.hasHigherAsNumber(previousConnection)) {
                 LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
                 this.peers.get(ip).releaseConnection();
                 return this.peers.get(ip);
-
-            } else if (previousConnection.hasHigherAsNumber(currentConnection)) {
-                LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
-                throw new BGPDocumentedException(
-                    String.format("BGP session with %s initiated %s has to be dropped. Opposite session already present",
-                        ip, currentConnection),
-                        BGPError.CEASE);
-            } else if (currentConnection.hasHigherAsNumber(previousConnection)) {
-                LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
-                this.peers.get(ip).releaseConnection();
-                return this.peers.get(ip);
-            // Session reestablished with same source bgp id, dropping current as duplicate
+                // Session reestablished with same source bgp id, dropping current as duplicate
             } else {
                 LOG.warn("BGP session with %s initiated from %s to %s has to be dropped. Same session already present", ip, sourceId, remoteId);
                 throw new BGPDocumentedException(