Bug-1409: Fix empty Update message (EOR) handling. 10/9310/3
authorMilos Fabian <milfabia@cisco.com>
Fri, 25 Jul 2014 11:07:36 +0000 (13:07 +0200)
committerMilos Fabian <milfabia@cisco.com>
Mon, 28 Jul 2014 09:43:44 +0000 (11:43 +0200)
-Processing of EOR in BGPSynchronization#updReceived ends up with NPE
-fixed behaviour - synchronize Ipv4 Unicast

Change-Id: I6b85cbcfd8ff9ec00c99b9f11b4bb2dce75ef334
Signed-off-by: Milos Fabian <milfabia@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSynchronization.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java

index 9745b1c8395bc01d2f9f9f801aa045125fe7ff15..e335d413f815b70f6546b5418d29042c8ccc8f36 100644 (file)
@@ -9,11 +9,9 @@ package org.opendaylight.protocol.bgp.rib.impl;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
-
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
@@ -84,18 +82,23 @@ public class BGPSynchronization {
      * @param msg received Update message
      */
     public void updReceived(final Update msg) {
-        TablesKey type = null;
-        if (msg.getNlri() != null || msg.getWithdrawnRoutes() != null) {
-            type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
-        } else if (msg.getPathAttributes().getAugmentation(PathAttributes1.class) != null) {
-            final PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
-            if (pa.getMpReachNlri() != null) {
-                type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
-            }
-        } else if (msg.getPathAttributes().getAugmentation(PathAttributes2.class) != null) {
-            final PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
-            if (pa.getMpUnreachNlri() != null) {
-                type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
+        TablesKey type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+        boolean isEOR = false;
+        if (msg.getNlri() == null && msg.getWithdrawnRoutes() == null) {
+            if (msg.getPathAttributes() != null) {
+                if (msg.getPathAttributes().getAugmentation(PathAttributes1.class) != null) {
+                    final PathAttributes1 pa = msg.getPathAttributes().getAugmentation(PathAttributes1.class);
+                    if (pa.getMpReachNlri() != null) {
+                        type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
+                    }
+                } else if (msg.getPathAttributes().getAugmentation(PathAttributes2.class) != null) {
+                    final PathAttributes2 pa = msg.getPathAttributes().getAugmentation(PathAttributes2.class);
+                    if (pa.getMpUnreachNlri() != null) {
+                        type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
+                    }
+                }
+            } else {
+                isEOR = true;
             }
         }
         final SyncVariables s = this.syncStorage.get(type);
@@ -104,6 +107,9 @@ public class BGPSynchronization {
             return;
         }
         s.setUpd(true);
+        if (isEOR) {
+            s.setEorTrue();
+        }
     }
 
     /**
index e83319e097bc42ae2b0d661f65c8703b96829606..d9fe1cddf50521e39e7885dd0df6bb01791ba75e 100644 (file)
@@ -11,9 +11,7 @@ import static org.junit.Assert.assertEquals;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
-
 import java.util.Set;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.protocol.bgp.parser.BGPSession;
@@ -51,6 +49,8 @@ public class SynchronizationTest {
 
     private Update lsm;
 
+    private Update eorm;
+
     @Before
     public void setUp() {
         this.listener = new SimpleSessionListener();
@@ -74,6 +74,8 @@ public class SynchronizationTest {
 
         this.lsm = new UpdateBuilder().setPathAttributes(paBuilder.build()).build();
 
+        this.eorm = new UpdateBuilder().build();
+
         final Set<TablesKey> types = Sets.newHashSet();
         types.add(new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
         types.add(new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
@@ -119,4 +121,20 @@ public class SynchronizationTest {
         this.bs.kaReceived(); // ipv4 sync
         assertEquals(2, this.listener.getListMsg().size());
     }
+
+    @Test
+    public void testSynchronizeWithEOR() {
+        this.bs.updReceived(this.ipv4m);
+        this.bs.updReceived(this.lsm);
+        // Ipv4 Unicast synchronized by EOR message
+        this.bs.updReceived(this.eorm);
+        // Linkstate not synchronized yet
+        this.bs.kaReceived();
+        // no message sent by BGPSychchronization
+        assertEquals(0, this.listener.getListMsg().size());
+        this.bs.kaReceived();
+        assertEquals(1, this.listener.getListMsg().size());
+        assertEquals(LinkstateAddressFamily.class, ((Update) this.listener.getListMsg().get(0)).getPathAttributes().getAugmentation(
+                PathAttributes1.class).getMpReachNlri().getAfi());
+    }
 }