Search in sources :

Example 1 with BmpRouterPeer

use of org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer in project bgpcep by opendaylight.

the class BmpRouterImpl method onPeerUp.

private synchronized void onPeerUp(final PeerUpNotification peerUp) {
    final PeerId peerId = getPeerIdFromOpen(peerUp.getReceivedOpen());
    if (!getPeer(peerId).isPresent()) {
        final BmpRouterPeer peer = BmpRouterPeerImpl.createRouterPeer(this.domTxChain, this.peersYangIId, peerUp, this.extensions, this.tree, peerId);
        this.peers.put(peerId, peer);
        LOG.debug("Router {}: Peer {} goes up.", this.routerIp, peerId.getValue());
    } else {
        LOG.debug("Peer: {} for Router: {} already exists.", peerId.getValue(), this.routerIp);
    }
}
Also used : BmpRouterPeer(org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId)

Example 2 with BmpRouterPeer

use of org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer in project bgpcep by opendaylight.

the class BmpRouterImpl method delegateToPeer.

private synchronized void delegateToPeer(final Notification perPeerMessage) {
    final PeerId peerId = getPeerId((PeerHeader) perPeerMessage);
    final Optional<BmpRouterPeer> maybePeer = getPeer(peerId);
    if (maybePeer.isPresent()) {
        maybePeer.get().onPeerMessage(perPeerMessage);
        if (perPeerMessage instanceof PeerDownNotification) {
            this.peers.remove(peerId);
            LOG.debug("Router {}: Peer {} removed.", this.routerIp, peerId.getValue());
        }
    } else {
        LOG.debug("Peer: {} for Router: {} was not found.", peerId.getValue(), this.routerIp);
    }
}
Also used : PeerDownNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotification) BmpRouterPeer(org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer) PeerId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId)

Example 3 with BmpRouterPeer

use of org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer 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)

Aggregations

BmpRouterPeer (org.opendaylight.protocol.bmp.impl.spi.BmpRouterPeer)3 PeerId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId)2 GuardedBy (javax.annotation.concurrent.GuardedBy)1 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)1 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)1 PeerDownNotification (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerDownNotification)1