private static final ContainerNode EMPTY_ADJRIBOUT = Builders.containerBuilder().withNodeIdentifier(ADJRIBOUT).addChild(ImmutableNodes.mapNodeBuilder(Tables.QNAME).build()).build();
private final Map<TablesKey, TableContext> tables;
- private final YangInstanceIdentifier tablesRoot;
+ private final YangInstanceIdentifier peerPath;
private final YangInstanceIdentifier ribPath;
private final DOMTransactionChain chain;
private final PeerId peerId;
private final String role;
- private AdjRibInWriter(final YangInstanceIdentifier ribPath, final DOMTransactionChain chain, final PeerId peerId, final String role, final YangInstanceIdentifier tablesRoot, final Map<TablesKey, TableContext> tables) {
+ private AdjRibInWriter(final YangInstanceIdentifier ribPath, final DOMTransactionChain chain, final PeerId peerId, final String role, final YangInstanceIdentifier peerPath, final Map<TablesKey, TableContext> tables) {
this.ribPath = Preconditions.checkNotNull(ribPath);
this.chain = Preconditions.checkNotNull(chain);
this.tables = Preconditions.checkNotNull(tables);
this.role = Preconditions.checkNotNull(role);
- this.tablesRoot = tablesRoot;
+ this.peerPath = peerPath;
this.peerId = peerId;
}
AdjRibInWriter transform(final PeerId newPeerId, final RIBSupportContextRegistry registry, final Set<TablesKey> tableTypes, final boolean isAppPeer) {
final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
- final YangInstanceIdentifier newTablesRoot;
+ final YangInstanceIdentifier newPeerPath;
if (!newPeerId.equals(this.peerId)) {
- if (this.peerId != null) {
- // Wipe old peer data completely
- tx.delete(LogicalDatastoreType.OPERATIONAL, this.ribPath.node(Peer.QNAME).node(new NodeIdentifierWithPredicates(Peer.QNAME, PEER_ID_QNAME, this.peerId.getValue())));
- }
-
- // Install new empty peer structure
- final NodeIdentifierWithPredicates peerKey = IdentifierUtils.domPeerId(newPeerId);
- final YangInstanceIdentifier newPeerPath = this.ribPath.node(Peer.QNAME).node(peerKey);
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> pb = Builders.mapEntryBuilder();
- pb.withNodeIdentifier(peerKey);
- pb.withChild(ImmutableNodes.leafNode(PEER_ID, newPeerId.getValue()));
- pb.withChild(ImmutableNodes.leafNode(PEER_ROLE, this.role));
- pb.withChild(EMPTY_ADJRIBIN);
- pb.withChild(EMPTY_EFFRIBIN);
- if (!isAppPeer) {
- pb.withChild(EMPTY_ADJRIBOUT);
- }
-
- tx.put(LogicalDatastoreType.OPERATIONAL, newPeerPath, pb.build());
- LOG.debug("New peer {} structure installed.", newPeerPath);
-
- newTablesRoot = newPeerPath.node(EMPTY_ADJRIBIN.getIdentifier()).node(TABLES);
+ newPeerPath = this.createEmptyPeerStructure(newPeerId, isAppPeer, tx);
} else {
- newTablesRoot = this.tablesRoot;
+ newPeerPath = this.peerPath;
// Wipe tables which are not present in the new types
for (final Entry<TablesKey, TableContext> e : this.tables.entrySet()) {
TableContext ctx = this.tables.get(k);
if (ctx == null) {
final RIBSupportContext rs = registry.getRIBSupportContext(k);
+ // TODO: Use returned value once Instance Identifier builder allows for it.
+ final NodeIdentifierWithPredicates key = RibSupportUtils.toYangTablesKey(k);
if (rs == null) {
LOG.warn("No support for table type {}, skipping it", k);
continue;
}
+ // install tables for adj-ribs-out (we do not need TableContext for that
+ if (!isAppPeer) {
+ rs.clearTable(tx, newPeerPath.node(EMPTY_ADJRIBOUT.getIdentifier()).node(TABLES).node(key));
+ }
// We will use table keys very often, make sure they are optimized
- final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(newTablesRoot);
-
- // TODO: Use returned value once Instance Identifier builder allows for it.
- final NodeIdentifierWithPredicates key = RibSupportUtils.toYangTablesKey(k);
+ final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(newPeerPath.node(EMPTY_ADJRIBIN.getIdentifier()).node(TABLES));
idb.nodeWithKey(key.getNodeType(), key.getKeyValues());
+
+ // install tables for adj-ribs-in
ctx = new TableContext(rs, idb.build());
ctx.clearTable(tx);
}
tx.submit();
- return new AdjRibInWriter(this.ribPath, this.chain, newPeerId, this.role, newTablesRoot, tb.build());
+ return new AdjRibInWriter(this.ribPath, this.chain, newPeerId, this.role, newPeerPath, tb.build());
+ }
+
+ private YangInstanceIdentifier createEmptyPeerStructure(final PeerId newPeerId, final boolean isAppPeer, final DOMDataWriteTransaction tx) {
+ if (this.peerId != null) {
+ // Wipe old peer data completely
+ tx.delete(LogicalDatastoreType.OPERATIONAL, this.ribPath.node(Peer.QNAME).node(new NodeIdentifierWithPredicates(Peer.QNAME, PEER_ID_QNAME, this.peerId.getValue())));
+ }
+ // Install new empty peer structure
+ final NodeIdentifierWithPredicates peerKey = IdentifierUtils.domPeerId(newPeerId);
+ final YangInstanceIdentifier newPeerPath = this.ribPath.node(Peer.QNAME).node(peerKey);
+
+ final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> pb = Builders.mapEntryBuilder();
+ pb.withNodeIdentifier(peerKey);
+ pb.withChild(ImmutableNodes.leafNode(PEER_ID, newPeerId.getValue()));
+ pb.withChild(ImmutableNodes.leafNode(PEER_ROLE, this.role));
+ pb.withChild(EMPTY_ADJRIBIN);
+ pb.withChild(EMPTY_EFFRIBIN);
+ if (!isAppPeer) {
+ pb.withChild(EMPTY_ADJRIBOUT);
+ }
+ tx.put(LogicalDatastoreType.OPERATIONAL, newPeerPath, pb.build());
+ LOG.debug("New peer {} structure installed.", newPeerPath);
+ return newPeerPath;
}
/**
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
final PeerId peerId = key.getPeerId();
final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(peerId, attributes);
for (final Entry<PeerId, YangInstanceIdentifier> pid : peerGroup.getPeers()) {
- // This points to adj-rib-out for a particular peer/table combination
- final RIBSupportContext ribCtx = this.registry.getRIBSupportContext(this.tableKey);
- // FIXME: the table should be created for a peer only once
- ribCtx.clearTable(tx, pid.getValue().node(AdjRibOut.QNAME).node(Tables.QNAME).node(this.tableKey));
final YangInstanceIdentifier routeTarget = this.ribSupport.routePath(pid.getValue().node(AdjRibOut.QNAME).node(Tables.QNAME).node(this.tableKey).node(Routes.QNAME), key.getRouteId());
if (effectiveAttributes != null && value != null && !peerId.equals(pid.getKey())) {
LOG.debug("Write route to AdjRibsOut {}", value);