From 8f8dbea2be7d3a8385cfb8263443ff5c242dfb33 Mon Sep 17 00:00:00 2001 From: Milos Fabian Date: Fri, 25 Jul 2014 13:07:36 +0200 Subject: [PATCH] Bug-1409: Fix empty Update message (EOR) handling. -Processing of EOR in BGPSynchronization#updReceived ends up with NPE -fixed behaviour - synchronize Ipv4 Unicast Change-Id: I6b85cbcfd8ff9ec00c99b9f11b4bb2dce75ef334 Signed-off-by: Milos Fabian --- .../bgp/rib/impl/BGPSynchronization.java | 34 +++++++++++-------- .../bgp/rib/impl/SynchronizationTest.java | 22 ++++++++++-- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSynchronization.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSynchronization.java index 9745b1c839..e335d413f8 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSynchronization.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPSynchronization.java @@ -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(); + } } /** diff --git a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java index e83319e097..d9fe1cddf5 100644 --- a/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java +++ b/bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/SynchronizationTest.java @@ -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 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()); + } } -- 2.36.6