Search in sources :

Example 31 with DOMDataWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project bgpcep by opendaylight.

the class BmpRibInWriter method removeRoutes.

private synchronized void removeRoutes(final MpUnreachNlri nlri) {
    final TablesKey key = new TablesKey(nlri.getAfi(), nlri.getSafi());
    final TableContext ctx = this.tables.get(key);
    if (ctx == null) {
        LOG.debug("No table for {}, not accepting NLRI {}", key, nlri);
        return;
    }
    LOG.trace("Removing routes {}", nlri);
    final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
    ctx.removeRoutes(tx, nlri);
    tx.submit();
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 32 with DOMDataWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project bgpcep by opendaylight.

the class BmpRouterImpl method onInitiate.

private synchronized void onInitiate(final InitiationMessage initiation) {
    Preconditions.checkState(isDatastoreWritable());
    final DOMDataWriteTransaction wTx = this.domTxChain.newWriteOnlyTransaction();
    wTx.merge(LogicalDatastoreType.OPERATIONAL, this.routerYangIId, Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(Router.QNAME, ROUTER_ID_QNAME, this.routerIp)).withChild(ImmutableNodes.leafNode(ROUTER_NAME_QNAME, initiation.getTlvs().getNameTlv().getName())).withChild(ImmutableNodes.leafNode(ROUTER_DESCRIPTION_QNAME, initiation.getTlvs().getDescriptionTlv().getDescription())).withChild(ImmutableNodes.leafNode(ROUTER_INFO_QNAME, getStringInfo(initiation.getTlvs().getStringInformation()))).withChild(ImmutableNodes.leafNode(ROUTER_STATUS_QNAME, UP)).build());
    wTx.submit();
}
Also used : NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 33 with DOMDataWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project bgpcep by opendaylight.

the class BmpRouterImpl method tearDown.

@GuardedBy("this")
@SuppressWarnings("checkstyle:IllegalCatch")
private synchronized void tearDown() {
    // the session has been teared down before
    if (this.session == null) {
        return;
    }
    // we want to display remote router's IP here, as sometimes this.session.close() is already
    // invoked before tearDown(), and session channel is null in this case, which leads to unuseful
    // log information
    LOG.info("BMP Session with remote router {} ({}) went down.", this.routerIp, this.session);
    this.session = null;
    final Iterator<BmpRouterPeer> it = this.peers.values().iterator();
    try {
        while (it.hasNext()) {
            it.next().close();
            it.remove();
        }
        this.domTxChain.close();
    } catch (final Exception e) {
        LOG.error("Failed to properly close BMP application.", e);
    } finally {
        // as the routerId is the same for both connection
        if (isDatastoreWritable()) {
            try {
                // it means the session was closed before it was written to datastore
                final DOMDataWriteTransaction wTx = this.domDataBroker.newWriteOnlyTransaction();
                wTx.delete(LogicalDatastoreType.OPERATIONAL, this.routerYangIId);
                wTx.submit().checkedGet();
            } catch (final TransactionCommitFailedException e) {
                LOG.error("Failed to remove BMP router data from DS.", e);
            }
            this.sessionManager.removeSessionListener(this);
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) BmpRouterPeer(org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) GuardedBy(javax.annotation.concurrent.GuardedBy)

Example 34 with DOMDataWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project bgpcep by opendaylight.

the class BmpRouterImpl method createRouterEntry.

private synchronized void createRouterEntry() {
    Preconditions.checkState(isDatastoreWritable());
    final DOMDataWriteTransaction wTx = this.domTxChain.newWriteOnlyTransaction();
    wTx.put(LogicalDatastoreType.OPERATIONAL, this.routerYangIId, Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(Router.QNAME, ROUTER_ID_QNAME, this.routerIp)).withChild(ImmutableNodes.leafNode(ROUTER_ID_QNAME, this.routerIp)).withChild(ImmutableNodes.leafNode(ROUTER_STATUS_QNAME, DOWN)).withChild(ImmutableNodes.mapNodeBuilder(Peer.QNAME).build()).build());
    wTx.submit();
}
Also used : NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 35 with DOMDataWriteTransaction

use of org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction in project bgpcep by opendaylight.

the class BmpRouterPeerImpl method onPeerDown.

private synchronized void onPeerDown() {
    final DOMDataWriteTransaction wTx = this.domTxChain.newWriteOnlyTransaction();
    wTx.delete(LogicalDatastoreType.OPERATIONAL, this.peerYangIId);
    wTx.submit();
    close();
}
Also used : DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Aggregations

DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)42 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)14 Test (org.junit.Test)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)9 CountDownLatch (java.util.concurrent.CountDownLatch)7 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)7 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)7 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)7 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)6 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)5 TablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey)5 DOMTransactionChain (org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain)4 QName (org.opendaylight.yangtools.yang.common.QName)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 DOMDataReadOnlyTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction)3 DOMDataReadWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction)3 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 InetSocketAddress (java.net.InetSocketAddress)2