import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
final Builder<TablesKey, TableContext> tb = ImmutableMap.builder();
for (final TablesKey tableKey : tableTypes) {
final RIBSupportContext rs = registry.getRIBSupportContext(tableKey);
- // TODO: Use returned value once Instance Identifier builder allows for it.
- final NodeIdentifierWithPredicates instanceIdentifierKey = RibSupportUtils.toYangTablesKey(tableKey);
if (rs == null) {
LOG.warn("No support for table type {}, skipping it", tableKey);
continue;
}
- installAdjRibsOutTables(newPeerPath, rs, instanceIdentifierKey, tableKey,
- addPathTablesType.get(tableKey), tx);
- installAdjRibInTables(newPeerPath, tableKey, rs, instanceIdentifierKey, tx, tb);
+ installAdjRibsOutTables(newPeerPath, rs, addPathTablesType.get(tableKey), tx);
+ installAdjRibInTables(newPeerPath, tableKey, rs, tx, tb);
}
return tb.build();
}
private static void installAdjRibInTables(final YangInstanceIdentifier newPeerPath, final TablesKey tableKey,
- final RIBSupportContext rs, final NodeIdentifierWithPredicates instanceIdentifierKey,
- final DOMDataTreeWriteTransaction tx, final Builder<TablesKey, TableContext> tb) {
+ final RIBSupportContext rs, final DOMDataTreeWriteTransaction tx,
+ final Builder<TablesKey, TableContext> tb) {
// We will use table keys very often, make sure they are optimized
final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(newPeerPath
- .node(EMPTY_ADJRIBIN.getIdentifier()).node(TABLES_NID)).node(instanceIdentifierKey);
+ .node(EMPTY_ADJRIBIN.getIdentifier()).node(TABLES_NID)).node(rs.getRibSupport().tablesKey());
final TableContext ctx = new TableContext(rs, idb.build());
ctx.createEmptyTableStructure(tx);
}
private static void installAdjRibsOutTables(final YangInstanceIdentifier newPeerPath, final RIBSupportContext rs,
- final NodeIdentifierWithPredicates instanceIdentifierKey, final TablesKey tableKey,
final SendReceive sendReceive, final DOMDataTreeWriteTransaction tx) {
- final NodeIdentifierWithPredicates supTablesKey = RibSupportUtils.toYangKey(SupportedTables.QNAME, tableKey);
+ final var tableKey = rs.getRibSupport().tablesKey();
+ final var supTablesKey = NodeIdentifierWithPredicates.of(SupportedTables.QNAME, tableKey.asMap());
final var tt = Builders.mapEntryBuilder().withNodeIdentifier(supTablesKey);
- for (final Entry<QName, Object> e : supTablesKey.entrySet()) {
+ for (var e : supTablesKey.entrySet()) {
tt.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue()));
}
if (sendReceive != null) {
tt.withChild(ImmutableNodes.leafNode(SEND_RECEIVE, sendReceive.getName()));
}
tx.put(LogicalDatastoreType.OPERATIONAL, newPeerPath.node(PEER_TABLES).node(supTablesKey), tt.build());
- rs.createEmptyTableStructure(tx, newPeerPath.node(EMPTY_ADJRIBOUT.getIdentifier())
- .node(TABLES_NID).node(instanceIdentifierKey));
+ rs.createEmptyTableStructure(tx,
+ newPeerPath.node(EMPTY_ADJRIBOUT.getIdentifier()).node(TABLES_NID).node(tableKey));
}
private void createEmptyPeerStructure(final PeerId newPeerId,
import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
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.yangtools.util.ImmutableOffsetMapTemplate;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
* @return NodeIdentifierWithPredicates of {@link Tables} for specified AFI, SAFI combination.
*/
static NodeIdentifierWithPredicates toYangTablesKey(final TablesKey tablesKey) {
- return toYangKey(Tables.QNAME, tablesKey.getAfi(), tablesKey.getSafi());
- }
-
- /**
- * Creates Yang Instance Identifier path argument from supplied AFI and SAFI.
- *
- * @param id QNAME representing node
- * @param afi Class representing AFI
- * @param safi Class representing SAFI
- * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
- */
- static NodeIdentifierWithPredicates toYangKey(final QName id, final AddressFamily afi,
- final SubsequentAddressFamily safi) {
- return NodeIdentifierWithPredicates.of(id, AFI_SAFI_TEMPLATE.instantiateWithValues(
- BindingReflections.getQName(afi), BindingReflections.getQName(safi)));
- }
-
- /**
- * Creates Yang Instance Identifier path argument from supplied {@link TablesKey}.
- *
- * @param id QNAME representing node
- * @param tablesKey Tables key representing table.
- * @return NodeIdentifierWithPredicates of 'id' for specified AFI, SAFI combination.
- */
- static NodeIdentifierWithPredicates toYangKey(final QName id, final TablesKey tablesKey) {
- return toYangKey(id, tablesKey.getAfi(), tablesKey.getSafi());
+ return NodeIdentifierWithPredicates.of(Tables.QNAME, AFI_SAFI_TEMPLATE.instantiateWithValues(
+ BindingReflections.getQName(tablesKey.getAfi()), BindingReflections.getQName(tablesKey.getSafi())));
}
}
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.RIBNormalizedNodes;
import org.opendaylight.protocol.bgp.rib.spi.RIBQNames;
+import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.SendReceive;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.Rib;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.peer.SupportedTables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
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.Ipv4AddressFamily;
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.NormalizedNode;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class AdjRibsInWriterTest {
-
private static final TablesKey K4 = new TablesKey(Ipv4AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE);
+ private static final NodeIdentifierWithPredicates DOM_K4 = NodeIdentifierWithPredicates.of(Tables.QNAME,
+ Map.of(QName.create(Tables.QNAME, "afi"), Ipv4AddressFamily.QNAME,
+ QName.create(Tables.QNAME, "safi"), UnicastSubsequentAddressFamily.QNAME));
private static final Map<TablesKey, SendReceive> ADD_PATH_TABLE_MAPS = Map.of(K4, SendReceive.Both);
+
private final Set<TablesKey> tableTypes = Set.of(K4);
private final String peerIp = "12.34.56.78";
+
@Mock
private DOMTransactionChain chain;
@Mock
@Mock
private RIBSupportContext context;
@Mock
+ private RIBSupport<?, ?> support;
+ @Mock
private PeerTransactionChain ptc;
+
private AdjRibInWriter writer;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- doReturn("MockedTrans").when(tx).toString();
doReturn(tx).when(chain).newWriteOnlyTransaction();
doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit();
doNothing().when(tx).put(eq(LogicalDatastoreType.OPERATIONAL),
doReturn(context).when(registry).getRIBSupportContext(any(TablesKey.class));
doReturn(chain).when(ptc).getDomChain();
doNothing().when(context).createEmptyTableStructure(eq(tx), any(YangInstanceIdentifier.class));
+ doReturn(support).when(context).getRibSupport();
+ doReturn(DOM_K4).when(support).tablesKey();
}
@Test
verifyPeerSkeletonInsertedCorrectly(peerPath);
// verify supported tables were inserted for ipv4
verify(tx).put(eq(LogicalDatastoreType.OPERATIONAL), eq(peerPath.node(SupportedTables.QNAME)
- .node(RibSupportUtils.toYangKey(SupportedTables.QNAME, K4))), any(NormalizedNode.class));
+ .node(NodeIdentifierWithPredicates.of(SupportedTables.QNAME, DOM_K4.asMap()))), any(NormalizedNode.class));
verifyUptodateSetToFalse(peerPath);
}
private void verifyUptodateSetToFalse(final YangInstanceIdentifier peerPath) {
final YangInstanceIdentifier path = peerPath.node(ADJRIBIN_NID)
- .node(TABLES_NID).node(RibSupportUtils.toYangTablesKey(K4))
+ .node(TABLES_NID).node(DOM_K4)
.node(ATTRIBUTES_NID).node(UPTODATE_NID);
verify(tx).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(path),
eq(RIBNormalizedNodes.ATTRIBUTES_UPTODATE_FALSE));
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.peer.SupportedTables;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
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.Ipv4AddressFamily;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
public class RibSupportUtilsTest {
- private static final NodeIdentifierWithPredicates NII;
- private static final NodeIdentifierWithPredicates NII_PATH;
- private static final TablesKey TABLE_KEY = new TablesKey(Ipv4AddressFamily.VALUE,
- UnicastSubsequentAddressFamily.VALUE);
-
- static {
- final QName afi = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-rib?revision=2018-03-29", "afi");
- final QName safi = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-rib?revision=2018-03-29", "safi");
- NII = NodeIdentifierWithPredicates.of(SupportedTables.QNAME, ImmutableMap.of(afi, Ipv4AddressFamily.QNAME,
- safi, UnicastSubsequentAddressFamily.QNAME));
- NII_PATH = NodeIdentifierWithPredicates.of(SupportedTables.QNAME, ImmutableMap.of(
- QName.create("urn:opendaylight:params:xml:ns:yang:bgp-multiprotocol?revision=2018-03-29", "afi"),
- Ipv4AddressFamily.QNAME,
- QName.create("urn:opendaylight:params:xml:ns:yang:bgp-multiprotocol?revision=2018-03-29", "safi"),
- UnicastSubsequentAddressFamily.QNAME));
- }
-
@Test
public void testYangTablesKey() {
- final NodeIdentifierWithPredicates p = RibSupportUtils.toYangTablesKey(TABLE_KEY);
+ final NodeIdentifierWithPredicates p = RibSupportUtils.toYangTablesKey(new TablesKey(Ipv4AddressFamily.VALUE,
+ UnicastSubsequentAddressFamily.VALUE));
final Map<QName, Object> m = p.asMap();
assertFalse(m.isEmpty());
assertEquals(Tables.QNAME, p.getNodeType());
assertTrue(m.containsValue(Ipv4AddressFamily.QNAME));
assertTrue(m.containsValue(UnicastSubsequentAddressFamily.QNAME));
}
-
- @Test
- public void testYangKey() {
- final NodeIdentifierWithPredicates p = RibSupportUtils.toYangKey(SupportedTables.QNAME, TABLE_KEY);
- final Map<QName, Object> m = p.asMap();
- assertFalse(m.isEmpty());
- assertEquals(SupportedTables.QNAME, p.getNodeType());
- assertTrue(m.containsValue(Ipv4AddressFamily.QNAME));
- assertTrue(m.containsValue(UnicastSubsequentAddressFamily.QNAME));
- }
-
- @Test
- public void toYangKey() {
- final NodeIdentifierWithPredicates result = RibSupportUtils.toYangKey(SupportedTables.QNAME, TABLE_KEY);
- assertEquals(NII.toString(), result.toString());
- }
}