use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class ApplicationPeer method onDataTreeChanged.
/**
* Routes come from application RIB that is identified by (configurable) name.
* Each route is pushed into AdjRibsInWriter with it's whole context. In this
* method, it doesn't matter if the routes are removed or added, this will
* be determined in LocRib.
*/
@Override
public synchronized void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
final DOMTransactionChain chain = getDomChain();
if (chain == null) {
LOG.trace("Skipping data changed called to Application Peer. Change : {}", changes);
return;
}
final DOMDataTreeWriteTransaction tx = chain.newWriteOnlyTransaction();
LOG.debug("Received data change to ApplicationRib {}", changes);
for (final DataTreeCandidate tc : changes) {
LOG.debug("Modification Type {}", tc.getRootNode().getModificationType());
final YangInstanceIdentifier path = tc.getRootPath();
final PathArgument lastArg = path.getLastPathArgument();
verify(lastArg instanceof NodeIdentifierWithPredicates, "Unexpected type %s in path %s", lastArg.getClass(), path);
final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) lastArg;
if (!this.supportedTables.contains(tableKey)) {
LOG.trace("Skipping received data change for non supported family {}.", tableKey);
continue;
}
for (final DataTreeCandidateNode child : tc.getRootNode().getChildNodes()) {
final PathArgument childIdentifier = child.getIdentifier();
final YangInstanceIdentifier tableId = this.adjRibsInId.node(tableKey).node(childIdentifier);
switch(child.getModificationType()) {
case DELETE:
case DISAPPEARED:
LOG.trace("App peer -> AdjRibsIn path delete: {}", childIdentifier);
tx.delete(LogicalDatastoreType.OPERATIONAL, tableId);
break;
case UNMODIFIED:
// No-op
break;
case SUBTREE_MODIFIED:
if (ROUTES_NID.equals(childIdentifier)) {
processRoutesTable(child, tableId, tx, tableId);
} else {
processWrite(child, tableId, tx);
}
break;
case WRITE:
case APPEARED:
processWrite(child, tableId, tx);
break;
default:
break;
}
}
}
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Successful commit");
}
@Override
public void onFailure(final Throwable trw) {
LOG.error("Failed commit", trw);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AbstractPeer method initializeRibOut.
@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>> void initializeRibOut(final RouteEntryDependenciesContainer entryDep, final List<ActualBestPathRoutes<C, S>> routesToStore) {
if (ribOutChain == null) {
LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
return;
}
final RIBSupport<C, S> ribSupport = entryDep.getRIBSupport();
final YangInstanceIdentifier tableRibout = getRibOutIId(ribSupport.tablesKey());
final boolean addPathSupported = supportsAddPathSupported(ribSupport.getTablesKey());
final DOMDataTreeWriteTransaction tx = ribOutChain.newWriteOnlyTransaction();
for (final ActualBestPathRoutes<C, S> initRoute : routesToStore) {
if (!supportsLLGR() && initRoute.isDepreferenced()) {
// Stale Long-lived Graceful Restart routes should not be propagated
continue;
}
final PeerId fromPeerId = initRoute.getFromPeerId();
if (!filterRoutes(fromPeerId, ribSupport.getTablesKey())) {
continue;
}
final MapEntryNode route = initRoute.getRoute();
final Peer fromPeer = entryDep.getPeerTracker().getPeer(fromPeerId);
if (fromPeer == null) {
LOG.debug("Failed to acquire peer structure for {}, ignoring route {}", fromPeerId, initRoute);
continue;
}
final YangInstanceIdentifier routePath = createRoutePath(ribSupport, tableRibout, initRoute, addPathSupported);
applyExportPolicy(entryDep, fromPeerId, route, routePath, initRoute.getAttributes()).ifPresent(attributes -> storeRoute(ribSupport, initRoute, route, routePath, attributes, tx));
}
final FluentFuture<? extends CommitInfo> future = tx.commit();
submitted = future;
future.addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Successful update commit");
}
@Override
public void onFailure(final Throwable trw) {
LOG.error("Failed update commit", trw);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AbstractPeer method reEvaluateAdvertizement.
@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>> void reEvaluateAdvertizement(final RouteEntryDependenciesContainer entryDep, final List<ActualBestPathRoutes<C, S>> routesToStore) {
if (ribOutChain == null) {
LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
return;
}
final RIBSupport<C, S> ribSupport = entryDep.getRIBSupport();
final NodeIdentifierWithPredicates tk = ribSupport.tablesKey();
final boolean addPathSupported = supportsAddPathSupported(ribSupport.getTablesKey());
final DOMDataTreeWriteTransaction tx = ribOutChain.newWriteOnlyTransaction();
for (final ActualBestPathRoutes<C, S> actualBestRoute : routesToStore) {
final PeerId fromPeerId = actualBestRoute.getFromPeerId();
if (!filterRoutes(fromPeerId, ribSupport.getTablesKey())) {
continue;
}
final YangInstanceIdentifier tableRibout = getRibOutIId(tk);
// Stale Long-lived Graceful Restart routes should not be propagated
if (supportsLLGR() || !actualBestRoute.isDepreferenced()) {
final YangInstanceIdentifier routePath = createRoutePath(ribSupport, tableRibout, actualBestRoute, addPathSupported);
final MapEntryNode route = actualBestRoute.getRoute();
final Optional<ContainerNode> effAttr = applyExportPolicy(entryDep, fromPeerId, route, routePath, actualBestRoute.getAttributes());
if (effAttr.isPresent()) {
storeRoute(ribSupport, actualBestRoute, route, routePath, effAttr.get(), tx);
continue;
}
}
deleteRoute(ribSupport, addPathSupported, tableRibout, actualBestRoute, tx);
}
final FluentFuture<? extends CommitInfo> future = tx.commit();
submitted = future;
future.addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Successful update commit");
}
@Override
public void onFailure(final Throwable trw) {
LOG.error("Failed update commit", trw);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class RIBImpl method closeServiceInstance.
public synchronized FluentFuture<? extends CommitInfo> closeServiceInstance() {
if (!isServiceInstantiated) {
LOG.trace("RIB {} already closed", ribId.getValue());
return CommitInfo.emptyFluentFuture();
}
LOG.info("Close RIB {}", ribId.getValue());
isServiceInstantiated = false;
setActive(false);
txChainToLocRibWriter.values().forEach(LocRibWriter::close);
txChainToLocRibWriter.clear();
final DOMDataTreeWriteTransaction t = domChain.newWriteOnlyTransaction();
t.delete(LogicalDatastoreType.OPERATIONAL, getYangRibId());
final FluentFuture<? extends CommitInfo> cleanFuture = t.commit();
cleanFuture.addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.info("RIB cleaned {}", ribId.getValue());
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("Failed to clean RIB {}", ribId.getValue(), throwable);
}
}, MoreExecutors.directExecutor());
domChain.close();
return cleanFuture;
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project bgpcep by opendaylight.
the class AbstractPeer method refreshRibOut.
@Override
public final synchronized <C extends Routes & DataObject & ChoiceIn<Tables>, S extends ChildOf<? super C>> void refreshRibOut(final RouteEntryDependenciesContainer entryDep, final List<StaleBestPathRoute> staleRoutes, final List<AdvertizedRoute<C, S>> newRoutes) {
if (ribOutChain == null) {
LOG.debug("Session closed, skip changes to peer AdjRibsOut {}", getPeerId());
return;
}
final DOMDataTreeWriteTransaction tx = ribOutChain.newWriteOnlyTransaction();
final RIBSupport<C, S> ribSupport = entryDep.getRIBSupport();
deleteRouteRibOut(ribSupport, staleRoutes, tx);
installRouteRibOut(entryDep, newRoutes, tx);
final FluentFuture<? extends CommitInfo> future = tx.commit();
submitted = future;
future.addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.trace("Successful update commit");
}
@Override
public void onFailure(final Throwable trw) {
LOG.error("Failed update commit", trw);
}
}, MoreExecutors.directExecutor());
}
Aggregations