Do not use BindingReflections in bmp-impl 30/106630/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 22 Jun 2023 15:28:06 +0000 (17:28 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 22 Jun 2023 15:30:09 +0000 (17:30 +0200)
There is just no point in needing to translate binding to dom -- we have
the QName readily available or we can get it from codecs we have near
by.

JIRA: BGPCEP-1016
Change-Id: I1a89e4aea49d99f8c255a77227941e1fabea7246
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bmp/bmp-impl/pom.xml
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRibInWriter.java
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/BmpRouterPeerImpl.java
bmp/bmp-impl/src/main/java/org/opendaylight/protocol/bmp/impl/app/TablesUtil.java

index 5bf843e34e2b6781bc67f7459e53ef7a11b0dd78..8279928e0ab59b02518cbb0645e5271716ce1ee3 100644 (file)
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>yang-binding</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.mdsal</groupId>
-            <artifactId>mdsal-binding-spec-util</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>mdsal-common-api</artifactId>
index 61ce55bc50d6c2bed632f237622bfcb566807be2..33ca3a930d2a6baa978dd1ec159a25085fbd4c3c 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.type
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.UnicastSubsequentAddressFamily;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.slf4j.Logger;
@@ -65,7 +66,7 @@ final class BmpRibInWriter {
             final Set<TablesKey> tableTypes,  final BindingCodecTree tree) {
         this.chain = chain;
         final DOMDataTreeWriteTransaction tx = this.chain.newWriteOnlyTransaction();
-        this.tables = createTableInstance(tableTypes, tablesRoot, tx, ribExtensions, tree).build();
+        tables = createTableInstance(tableTypes, tablesRoot, tx, ribExtensions, tree).build();
 
         LOG.debug("New RIB table {} structure installed.", tablesRoot.toString());
         tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@@ -125,22 +126,26 @@ final class BmpRibInWriter {
     private static ImmutableMap.Builder<TablesKey, TableContext> createTableInstance(final Set<TablesKey> tableTypes,
             final YangInstanceIdentifier yangTableRootIId, final DOMDataTreeWriteTransaction tx,
             final RIBExtensionConsumerContext ribExtensions, final BindingCodecTree tree) {
+        final var identityCodec = tree.getIdentityCodec();
 
         final ImmutableMap.Builder<TablesKey, TableContext> tb = ImmutableMap.builder();
-        for (final TablesKey k : tableTypes) {
-            final RIBSupport rs = ribExtensions.getRIBSupport(k);
+        for (final TablesKey tableType : tableTypes) {
+            final RIBSupport rs = ribExtensions.getRIBSupport(tableType);
             if (rs == null) {
-                LOG.warn("No support for table type {}, skipping it", k);
+                LOG.warn("No support for table type {}, skipping it", tableType);
                 continue;
             }
-            final TableContext ctx = new TableContext(rs,
-                yangTableRootIId.node(TablesUtil.toYangTablesKey(k)).toOptimized(), tree);
+
+            final var domTableKey = NodeIdentifierWithPredicates.of(TablesUtil.BMP_TABLES_QNAME, ImmutableMap.of(
+                TablesUtil.BMP_AFI_QNAME, identityCodec.fromBinding(tableType.getAfi()),
+                TablesUtil.BMP_SAFI_QNAME, identityCodec.fromBinding(tableType.getSafi())));
+            final TableContext ctx = new TableContext(rs, yangTableRootIId.node(domTableKey).toOptimized(), tree);
             ctx.createTable(tx);
 
             tx.put(LogicalDatastoreType.OPERATIONAL, ctx.getTableId().node(BMP_ATTRIBUTES_QNAME)
                     .node(ATTRIBUTES_UPTODATE_FALSE.getIdentifier()), ATTRIBUTES_UPTODATE_FALSE);
             LOG.debug("Created table instance {}", ctx.getTableId());
-            tb.put(k, ctx);
+            tb.put(tableType, ctx);
         }
         return tb;
     }
@@ -148,14 +153,14 @@ final class BmpRibInWriter {
     private synchronized void addRoutes(final MpReachNlri nlri, final org.opendaylight.yang.gen.v1.urn.opendaylight
             .params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes attributes) {
         final TablesKey key = new TablesKey(nlri.getAfi(), nlri.getSafi());
-        final TableContext ctx = this.tables.get(key);
+        final TableContext ctx = tables.get(key);
 
         if (ctx == null) {
             LOG.debug("No table for {}, not accepting NLRI {}", key, nlri);
             return;
         }
 
-        final DOMDataTreeWriteTransaction tx = this.chain.newWriteOnlyTransaction();
+        final DOMDataTreeWriteTransaction tx = chain.newWriteOnlyTransaction();
         ctx.writeRoutes(tx, nlri, attributes);
         LOG.trace("Write routes {}", nlri);
         tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@@ -194,14 +199,14 @@ final class BmpRibInWriter {
 
     private synchronized void removeRoutes(final MpUnreachNlri nlri) {
         final TablesKey key = new TablesKey(nlri.getAfi(), nlri.getSafi());
-        final TableContext ctx = this.tables.get(key);
+        final TableContext ctx = tables.get(key);
 
         if (ctx == null) {
             LOG.debug("No table for {}, not accepting NLRI {}", key, nlri);
             return;
         }
         LOG.trace("Removing routes {}", nlri);
-        final DOMDataTreeWriteTransaction tx = this.chain.newWriteOnlyTransaction();
+        final DOMDataTreeWriteTransaction tx = chain.newWriteOnlyTransaction();
         ctx.removeRoutes(tx, nlri);
         tx.commit().addCallback(new FutureCallback<CommitInfo>() {
             @Override
@@ -277,8 +282,8 @@ final class BmpRibInWriter {
     }
 
     private synchronized void markTableUptodated(final TablesKey tableTypes) {
-        final DOMDataTreeWriteTransaction tx = this.chain.newWriteOnlyTransaction();
-        final TableContext ctxPre = this.tables.get(tableTypes);
+        final DOMDataTreeWriteTransaction tx = chain.newWriteOnlyTransaction();
+        final TableContext ctxPre = tables.get(tableTypes);
         tx.merge(LogicalDatastoreType.OPERATIONAL, ctxPre.getTableId().node(BMP_ATTRIBUTES_QNAME)
                 .node(ATTRIBUTES_UPTODATE_TRUE.getIdentifier()), ATTRIBUTES_UPTODATE_TRUE);
         tx.commit().addCallback(new FutureCallback<CommitInfo>() {
index 70de727a71e0e018620a7cb2b8bb57476ae2e22e..e9e78e46d82f6616dc5ced4d5ee700ad98635698 100644 (file)
@@ -12,6 +12,7 @@ import static org.opendaylight.protocol.bmp.impl.app.TablesUtil.BMP_TABLES_QNAME
 import static org.opendaylight.yangtools.yang.common.QName.create;
 
 import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
@@ -110,6 +111,11 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
     private static final QName STAT11_QNAME = create(Stats.QNAME, "updates-treated-as-withdraw").intern();
     private static final QName STAT13_QNAME = create(Stats.QNAME, "duplicate-updates").intern();
 
+    private static final NodeIdentifierWithPredicates AFI_ITEM = NodeIdentifierWithPredicates.of(AF_QNAME,
+        ImmutableMap.of(
+            TablesUtil.BMP_AFI_QNAME.bindTo(AF_QNAME.getModule()).intern(), Ipv4AddressFamily.QNAME,
+            TablesUtil.BMP_SAFI_QNAME.bindTo(AF_QNAME.getModule()).intern(), UnicastSubsequentAddressFamily.QNAME));
+
     private static final TablesKey DEFAULT_TABLE =
             new TablesKey(Ipv4AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE);
 
@@ -378,8 +384,7 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
                 .withChild(ImmutableNodes.mapNodeBuilder(AF_QNAME).withChild(Builders.mapEntryBuilder()
                     .withChild(ImmutableNodes.leafNode(COUNT_QNAME,
                             tlvs.getPerAfiSafiAdjRibInTlv().getCount().getValue()))
-                    .withNodeIdentifier(TablesUtil.toYangTablesKey(AF_QNAME,
-                            Ipv4AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE))
+                    .withNodeIdentifier(AFI_ITEM)
                     .build()).build()).build());
         }
         if (tlvs.getPerAfiSafiLocRibTlv() != null) {
@@ -388,8 +393,7 @@ public final class BmpRouterPeerImpl implements BmpRouterPeer {
                             .withChild(Builders.mapEntryBuilder()
                                     .withChild(ImmutableNodes.leafNode(COUNT_QNAME,
                                             tlvs.getPerAfiSafiLocRibTlv().getCount().getValue()))
-                                    .withNodeIdentifier(TablesUtil.toYangTablesKey(AF_QNAME,
-                                            Ipv4AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE))
+                                    .withNodeIdentifier(AFI_ITEM)
                                     .build()).build()).build());
         }
         if (tlvs.getUpdatesTreatedAsWithdrawTlv() != null) {
index 4f6dd759aa7282019262f16d2b9e6b798efbc298..39832581bbbf7ea501ee24a084ccdc7739893ceb 100644 (file)
@@ -7,14 +7,8 @@
  */
 package org.opendaylight.protocol.bmp.impl.app;
 
-import com.google.common.collect.ImmutableMap;
-import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.BmpMonitor;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 
 public final class TablesUtil {
     public static final QName BMP_TABLES_QNAME = QName.create(BmpMonitor.QNAME, "tables").intern();
@@ -27,44 +21,4 @@ public final class TablesUtil {
         // Hidden on purpose
     }
 
-    /**
-     * Creates Yang Instance Identifier path argument from supplied AFI and SAFI.
-     *
-     * @param afi Class representing AFI
-     * @param safi Class representing SAFI
-     * @return NodeIdentifierWithPredicates for specified AFI, SAFI combination.
-     */
-    public static NodeIdentifierWithPredicates toYangTablesKey(final AddressFamily afi,
-            final SubsequentAddressFamily safi) {
-        return NodeIdentifierWithPredicates.of(BMP_TABLES_QNAME,
-            ImmutableMap.of(
-                BMP_AFI_QNAME, BindingReflections.getQName(afi),
-                BMP_SAFI_QNAME, BindingReflections.getQName(safi)));
-    }
-
-    /**
-     * Creates Yang Instance Identifier path argument from supplied QNAMES and AFI and SAFI.
-     *
-     * @param nodeName QName reprenting node
-     * @param afi Class representing AFI
-     * @param safi Class representing SAFI
-     * @return NodeIdentifierWithPredicates for specified AFI, SAFI combination.
-     */
-    public static NodeIdentifierWithPredicates toYangTablesKey(final QName nodeName,
-            final AddressFamily afi, final SubsequentAddressFamily safi) {
-        return NodeIdentifierWithPredicates.of(nodeName,
-            ImmutableMap.of(
-                BMP_AFI_QNAME.bindTo(nodeName.getModule()).intern(), BindingReflections.getQName(afi),
-                BMP_SAFI_QNAME.bindTo(nodeName.getModule()).intern(), BindingReflections.getQName(safi)));
-    }
-
-    /**
-     * Creates Yang Instance Identifier path argument from supplied {@link TablesKey}.
-     *
-     * @param tablesKey Tables key representing table.
-     * @return NodeIdentifierWithPredicates of for specified AFI, SAFI combination.
-     */
-    public static NodeIdentifierWithPredicates toYangTablesKey(final TablesKey tablesKey) {
-        return toYangTablesKey(tablesKey.getAfi(), tablesKey.getSafi());
-    }
 }