+
+ @Override
+ public void instantiateServiceInstance() {
+ if(this.configurationWriter != null) {
+ this.configurationWriter.apply();
+ }
+ LOG.info("RIB Singleton Service {} instantiated", this.getIdentifier());
+ LOG.debug("Instantiating RIB table {} at {}", this.ribId , this.yangRibId);
+
+ final ContainerNode bgpRib = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(BgpRib.QNAME))
+ .addChild(ImmutableNodes.mapNodeBuilder(Rib.QNAME).build()).build();
+
+ final MapEntryNode ribInstance = Builders.mapEntryBuilder().withNodeIdentifier(
+ new NodeIdentifierWithPredicates(Rib.QNAME, RIB_ID_QNAME, this.ribId .getValue()))
+ .addChild(ImmutableNodes.leafNode(RIB_ID_QNAME, this.ribId .getValue()))
+ .addChild(ImmutableNodes.mapNodeBuilder(Peer.QNAME).build())
+ .addChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(LocRib.QNAME))
+ .addChild(ImmutableNodes.mapNodeBuilder(Tables.QNAME).build())
+ .build()).build();
+
+
+ final DOMDataWriteTransaction trans = this.domChain.newWriteOnlyTransaction();
+
+ // merge empty BgpRib + Rib, to make sure the top-level parent structure is present
+ trans.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BgpRib.QNAME).build(), bgpRib);
+ trans.put(LogicalDatastoreType.OPERATIONAL, this.yangRibId, ribInstance);
+
+ try {
+ trans.submit().checkedGet();
+ } catch (final TransactionCommitFailedException e) {
+ LOG.error("Failed to initiate RIB {}", this.yangRibId, e);
+ }
+
+ LOG.debug("Effective RIB created.");
+
+ for (final BgpTableType t : this.localTables) {
+ final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
+ this.localTablesKeys.add(key);
+ startLocRib(key, policyDatabase);
+ }
+
+ if (this.configModuleTracker != null) {
+ this.configModuleTracker.onInstanceCreate();
+ }
+ }
+
+ @Override
+ public ListenableFuture<Void> closeServiceInstance() {
+ LOG.info("Close RIB Singleton Service {}", this.getIdentifier());
+ for (final LocRibWriter locRib : this.locRibs) {
+ try {
+ locRib.close();
+ } catch (final Exception e) {
+ LOG.warn("Could not close LocalRib reference: {}", locRib, e);
+ }
+ }
+ try {
+ final DOMDataWriteTransaction t = this.domChain.newWriteOnlyTransaction();
+ t.delete(LogicalDatastoreType.OPERATIONAL, getYangRibId());
+ t.submit().checkedGet();
+ } catch (final TransactionCommitFailedException e) {
+ LOG.warn("Failed to remove RIB instance {} from DS.", getYangRibId(), e);
+ }
+ this.renderStats.getLocRibRouteCounter().resetAll();
+
+ if (this.configModuleTracker != null) {
+ this.configModuleTracker.onInstanceClose();
+ }
+ return Futures.immediateFuture(null);
+ }
+
+ @Override
+ public ServiceGroupIdentifier getIdentifier() {
+ return this.serviceGroupIdentifier;
+ }
+
+ @Override
+ public ClusterSingletonServiceRegistration registerClusterSingletonService(final ClusterSingletonService clusterSingletonService) {
+ return this.provider.registerClusterSingletonService(clusterSingletonService);
+ }
+
+ @Override
+ public ServiceGroupIdentifier getRibIServiceGroupIdentifier() {
+ return getIdentifier();
+ }