import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
-import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.DestinationIpv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4Prefixes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.UpdateMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.UpdateMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesReach;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.AttributesUnreach;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.reach.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.MpUnreachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.attributes.unreach.mp.unreach.nlri.WithdrawnRoutesBuilder;
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.rev180329.Ipv4AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
+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.InstanceIdentifierBuilder;
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.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class BmpRibInWriter {
-
private static final Logger LOG = LoggerFactory.getLogger(BmpRibInWriter.class);
private static final LeafNode<Boolean> ATTRIBUTES_UPTODATE_FALSE =
- ImmutableNodes.leafNode(QName.create(BMP_ATTRIBUTES_QNAME, "uptodate"), Boolean.FALSE);
+ ImmutableNodes.leafNode(QName.create(BMP_ATTRIBUTES_QNAME, "uptodate").intern(), Boolean.FALSE);
private static final LeafNode<Boolean> ATTRIBUTES_UPTODATE_TRUE =
- ImmutableNodes.leafNode(ATTRIBUTES_UPTODATE_FALSE.getNodeType(), Boolean.TRUE);
+ ImmutableNodes.leafNode(ATTRIBUTES_UPTODATE_FALSE.name(), Boolean.TRUE);
private final DOMTransactionChain chain;
private final Map<TablesKey, TableContext> tables;
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>() {
public void onMessage(final UpdateMessage message) {
if (!checkEndOfRib(message)) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path
.attributes.Attributes attrs = message.getAttributes();
MpReachNlri mpReach = null;
if (message.getNlri() != null) {
mpReach = prefixesToMpReach(message);
- } else if (attrs != null && attrs.augmentation(Attributes1.class) != null) {
- mpReach = attrs.augmentation(Attributes1.class).getMpReachNlri();
+ } else if (attrs != null && attrs.augmentation(AttributesReach.class) != null) {
+ mpReach = attrs.augmentation(AttributesReach.class).getMpReachNlri();
}
if (mpReach != null) {
addRoutes(mpReach, attrs);
MpUnreachNlri mpUnreach = null;
if (message.getWithdrawnRoutes() != null) {
mpUnreach = prefixesToMpUnreach(message);
- } else if (attrs != null && attrs.augmentation(Attributes2.class) != null) {
- mpUnreach = attrs.augmentation(Attributes2.class).getMpUnreachNlri();
+ } else if (attrs != null && attrs.augmentation(AttributesUnreach.class) != null) {
+ mpUnreach = attrs.augmentation(AttributesUnreach.class).getMpUnreachNlri();
}
if (mpUnreach != null) {
removeRoutes(mpUnreach);
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 var 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 InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(yangTableRootIId);
- final NodeIdentifierWithPredicates key = TablesUtil.toYangTablesKey(k);
- idb.nodeWithKey(key.getNodeType(), key.getKeyValues());
- final TableContext ctx = new TableContext(rs, idb.build(), 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.getNodeType()), ATTRIBUTES_UPTODATE_FALSE);
+ .node(ATTRIBUTES_UPTODATE_FALSE.name()), ATTRIBUTES_UPTODATE_FALSE);
LOG.debug("Created table instance {}", ctx.getTableId());
- tb.put(k, ctx);
+ tb.put(tableType, ctx);
}
return tb;
}
private synchronized void addRoutes(final MpReachNlri nlri, final org.opendaylight.yang.gen.v1.urn.opendaylight
- .params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes attributes) {
+ .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>() {
final List<Ipv4Prefixes> prefixes = message.getNlri().stream()
.map(n -> new Ipv4PrefixesBuilder().setPrefix(n.getPrefix()).setPathId(n.getPathId()).build())
.collect(Collectors.toList());
- final MpReachNlriBuilder b = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(
- UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(
- new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv4CaseBuilder().setDestinationIpv4(
- new DestinationIpv4Builder().setIpv4Prefixes(prefixes).build()).build()).build());
+ final MpReachNlriBuilder b = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.VALUE).setSafi(
+ UnicastSubsequentAddressFamily.VALUE).setAdvertizedRoutes(
+ new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(
+ new DestinationIpv4Builder().setIpv4Prefixes(prefixes).build()).build()).build());
if (message.getAttributes() != null) {
b.setCNextHop(message.getAttributes().getCNextHop());
}
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
final List<Ipv4Prefixes> prefixes = new ArrayList<>();
message.getWithdrawnRoutes().forEach(
w -> prefixes.add(new Ipv4PrefixesBuilder().setPrefix(w.getPrefix()).setPathId(w.getPathId()).build()));
- return new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+ return new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.VALUE).setSafi(UnicastSubsequentAddressFamily.VALUE)
.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.update
.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
* @param msg received Update message
*/
private boolean checkEndOfRib(final UpdateMessage msg) {
- TablesKey type = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ TablesKey type = new TablesKey(Ipv4AddressFamily.VALUE, UnicastSubsequentAddressFamily.VALUE);
boolean isEOR = false;
if (msg.getNlri() == null && msg.getWithdrawnRoutes() == null) {
if (msg.getAttributes() != null) {
- if (msg.getAttributes().augmentation(Attributes1.class) != null) {
- final Attributes1 pa = msg.getAttributes().augmentation(Attributes1.class);
+ if (msg.getAttributes().augmentation(AttributesReach.class) != null) {
+ final AttributesReach pa = msg.getAttributes().augmentation(AttributesReach.class);
if (pa.getMpReachNlri() != null) {
type = new TablesKey(pa.getMpReachNlri().getAfi(), pa.getMpReachNlri().getSafi());
}
- } else if (msg.getAttributes().augmentation(Attributes2.class) != null) {
- final Attributes2 pa = msg.getAttributes().augmentation(Attributes2.class);
+ } else if (msg.getAttributes().augmentation(AttributesUnreach.class) != null) {
+ final AttributesUnreach pa = msg.getAttributes().augmentation(AttributesUnreach.class);
if (pa.getMpUnreachNlri() != null) {
type = new TablesKey(pa.getMpUnreachNlri().getAfi(), pa.getMpUnreachNlri().getSafi());
}
}
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.getNodeType()), ATTRIBUTES_UPTODATE_TRUE);
+ .node(ATTRIBUTES_UPTODATE_TRUE.name()), ATTRIBUTES_UPTODATE_TRUE);
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {