- final YangInstanceIdentifier newTablesRoot;
- 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())));
+ final YangInstanceIdentifier newPeerPath;
+ newPeerPath = createEmptyPeerStructure(newPeerId, tx);
+ final ImmutableMap<TablesKey, TableContext> tb = createNewTableInstances(newPeerPath, registry, tableTypes, addPathTablesType, tx);
+ tx.submit();
+
+ return new AdjRibInWriter(this.ribPath, this.chain, this.role, this.simpleRoutingPolicy, newPeerPath, tb);
+ }
+
+ /**
+ * Create new table instances, potentially creating their empty entries
+ * @param newPeerPath
+ * @param registry
+ * @param tableTypes
+ * @param addPathTablesType
+ * @param tx
+ * @return
+ */
+ private ImmutableMap<TablesKey, TableContext> createNewTableInstances(final YangInstanceIdentifier newPeerPath,
+ final RIBSupportContextRegistry registry, final Set<TablesKey> tableTypes, final List<AddressFamilies> addPathTablesType,
+ final DOMDataWriteTransaction tx) {
+
+ final Map<TablesKey, SendReceive> addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
+ 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;