BUG-3768 : fixed AdjRibsOutWriter 73/22773/1
authorDana Kutenicsova <dkutenic@cisco.com>
Wed, 17 Jun 2015 08:38:47 +0000 (10:38 +0200)
committerDana Kutenicsova <dkutenic@cisco.com>
Wed, 17 Jun 2015 09:59:01 +0000 (11:59 +0200)
Added peerId to list of arguments for this writer
and limited listening to AdjRibsOut only for that
particular peer.

Fixed switched arguments for creating Mp_Reach and Mp_Unreach.

Change-Id: If1f3c576395d68aa3c26d2e4fabd696a4bf14457
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
(cherry picked from commit 8bf877875bc2038063008ffd2d99e67591db73ba)

bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/AdjRibOutListener.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java

index a14fd54a29ea613b381a36248f67491d968963b8..3476914fc4a379ae6cdd7cf0dec22a5f1aba4925 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
 import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.peer.AdjRibOut;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
@@ -47,22 +48,23 @@ final class AdjRibOutListener implements DOMDataTreeChangeListener {
     private final RIBSupportContextImpl context;
     private final RIBSupport support;
 
-    private AdjRibOutListener(final TablesKey tablesKey, final YangInstanceIdentifier ribId, final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry, final ChannelOutputLimiter session) {
+    private AdjRibOutListener(final PeerId peerId, final TablesKey tablesKey, final YangInstanceIdentifier ribId, final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry, final ChannelOutputLimiter session) {
         this.session = Preconditions.checkNotNull(session);
         this.context = (RIBSupportContextImpl) registry.getRIBSupportContext(tablesKey);
         this.support = this.context.getRibSupport();
-        final YangInstanceIdentifier adjRibOutId =  ribId.node(Peer.QNAME).node(Peer.QNAME).node(AdjRibOut.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(tablesKey));
+        final YangInstanceIdentifier adjRibOutId =  ribId.node(Peer.QNAME).node(IdentifierUtils.domPeerId(peerId)).node(AdjRibOut.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(tablesKey));
         service.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, adjRibOutId), this);
     }
 
-    static AdjRibOutListener create(@Nonnull final TablesKey tablesKey, @Nonnull final YangInstanceIdentifier ribId, @Nonnull final DOMDataTreeChangeService service, @Nonnull final RIBSupportContextRegistry registry, @Nonnull final ChannelOutputLimiter session) {
-        return new AdjRibOutListener(tablesKey, ribId, service, registry, session);
+    static AdjRibOutListener create(@Nonnull final PeerId peerId, @Nonnull final TablesKey tablesKey, @Nonnull final YangInstanceIdentifier ribId, @Nonnull final DOMDataTreeChangeService service, @Nonnull final RIBSupportContextRegistry registry, @Nonnull final ChannelOutputLimiter session) {
+        return new AdjRibOutListener(peerId, tablesKey, ribId, service, registry, session);
     }
 
     @Override
     public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
         LOG.debug("Data change received for AdjRibOut {}", changes);
         for (final DataTreeCandidate tc : changes) {
+            LOG.trace("Change {} type {}", tc.getRootNode(), tc.getRootNode().getModificationType());
             for (final DataTreeCandidateNode child : tc.getRootNode().getChildNodes()) {
                 for (final DataTreeCandidateNode route : this.context.getRibSupport().changedRoutes(child)) {
                     final Update update;
@@ -102,10 +104,10 @@ final class AdjRibOutListener implements DOMDataTreeChangeListener {
     }
 
     private Update withdraw(final MapEntryNode route) {
-        return this.support.buildUpdate(Collections.singleton(route), Collections.<MapEntryNode>emptyList(), routeAttributes(route));
+        return this.support.buildUpdate(Collections.<MapEntryNode>emptyList(), Collections.singleton(route), routeAttributes(route));
     }
 
     private Update advertise(final MapEntryNode route) {
-        return this.support.buildUpdate(Collections.<MapEntryNode>emptyList(), Collections.singleton(route), routeAttributes(route));
+        return this.support.buildUpdate(Collections.singleton(route), Collections.<MapEntryNode>emptyList(), routeAttributes(route));
     }
 }
index eef785ba1d880144c8e34cc193384f74a393b72b..85518cf955a0b3ef43c17ab14660530d4a5b77b7 100644 (file)
@@ -50,6 +50,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.mult
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
@@ -176,6 +177,7 @@ public class BGPPeer implements ReusableBGPPeer, Peer, AutoCloseable, BGPPeerRun
         LOG.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
         this.session = session;
         this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress();
+        final PeerId peerId = RouterIds.createPeerId(session.getBgpId());
 
         for (final BgpTableType t : session.getAdvertisedTableTypes()) {
             final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
@@ -183,10 +185,10 @@ public class BGPPeer implements ReusableBGPPeer, Peer, AutoCloseable, BGPPeerRun
 
             // not particularly nice
             if (session instanceof BGPSessionImpl) {
-                AdjRibOutListener.create(key, this.rib.getYangRibId(), ((RIBImpl)this.rib).getService(), this.rib.getRibSupportContext(), ((BGPSessionImpl) session).getLimiter());
+                AdjRibOutListener.create(peerId, key, this.rib.getYangRibId(), ((RIBImpl)this.rib).getService(), this.rib.getRibSupportContext(), ((BGPSessionImpl) session).getLimiter());
             }
         }
-        this.ribWriter = this.ribWriter.transform(RouterIds.createPeerId(session.getBgpId()), this.rib.getRibSupportContext(), this.tables, false);
+        this.ribWriter = this.ribWriter.transform(peerId, this.rib.getRibSupportContext(), this.tables, false);
         this.sessionEstablishedCounter++;
         if (this.registrator != null) {
             this.runtimeReg = this.registrator.register(this);
index 0c6481d3fb644b155aeee44bfafcfa2daa05d627..499248a0d75a612fd43cc9e1939c8ccdc308492d 100644 (file)
@@ -128,7 +128,7 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
 
             // Now walk all updated entries
             walkThrough(tx, toUpdate);
-        } catch (Exception e) {
+        } catch (final Exception e) {
             LOG.error("Failed to completely propagate updates {}, state is undefined", changes, e);
         } finally {
             tx.submit();
@@ -140,7 +140,6 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
         final Map<RouteUpdateKey, AbstractRouteEntry> ret = new HashMap<>();
 
         for (final DataTreeCandidate tc : changes) {
-            // call out peer-role has changed
             final YangInstanceIdentifier rootPath = tc.getRootPath();
             final DataTreeCandidateNode rootNode = tc.getRootNode();
             final DataTreeCandidateNode roleChange =  rootNode.getModifiedChild(AbstractPeerRoleTracker.PEER_ROLE_NID);
@@ -162,6 +161,7 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
             final PeerId peerId = IdentifierUtils.peerId(peerKey);
             final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId);
             for (final DataTreeCandidateNode child : table.getChildNodes()) {
+                LOG.debug("Modification type {}", child.getModificationType());
                 if ((Attributes.QNAME).equals(child.getIdentifier().getNodeType())) {
                     if (child.getDataAfter().isPresent()) {
                         // putting uptodate attribute in
@@ -245,11 +245,11 @@ final class LocRibWriter implements AutoCloseable, DOMDataTreeChangeListener {
                 for (final Entry<PeerId, YangInstanceIdentifier> pid : peerGroup.getPeers()) {
                     final YangInstanceIdentifier routeTarget = this.ribSupport.routePath(pid.getValue().node(AdjRibOut.QNAME).node(Tables.QNAME).node(this.tableKey).node(ROUTES_IDENTIFIER), key.getRouteId());
                     if (effectiveAttributes != null && value != null && !peerId.equals(pid.getKey())) {
-                        LOG.debug("Write route to AdjRibsOut {}", value);
+                        LOG.debug("Write route {} to peers AdjRibsOut {}", value, pid.getKey());
                         tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget, value);
                         tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget.node(this.attributesIdentifier), effectiveAttributes);
                     } else {
-                        LOG.trace("Removing {} from transaction", routeTarget);
+                        LOG.trace("Removing {} from transaction for peer {}", routeTarget, pid.getKey());
                         tx.delete(LogicalDatastoreType.OPERATIONAL, routeTarget);
                     }
                 }