2 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import com.google.common.util.concurrent.FluentFuture;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.util.Arrays;
15 import javax.annotation.Nonnull;
16 import javax.annotation.Nullable;
17 import javax.annotation.concurrent.GuardedBy;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
20 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
21 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
22 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
23 import org.opendaylight.mdsal.common.api.CommitInfo;
24 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
25 import org.opendaylight.protocol.bgp.rib.impl.state.BGPPeerStateImpl;
26 import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
27 import org.opendaylight.protocol.bgp.rib.spi.Peer;
28 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
29 import org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState;
30 import org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImportParameters, TransactionChainListener,
43 private static final Logger LOG = LoggerFactory.getLogger(AbstractPeer.class);
44 protected final RIB rib;
46 final PeerRole peerRole;
47 private final ClusterIdentifier clusterId;
48 private final AsNumber localAs;
55 final String peerName,
58 @Nullable final ClusterIdentifier clusterId,
59 @Nullable final AsNumber localAs,
60 final IpAddress neighborAddress,
61 final Set<TablesKey> afiSafisAdvertized,
62 final Set<TablesKey> afiSafisGracefulAdvertized) {
63 super(rib.getInstanceIdentifier(), groupId, neighborAddress, afiSafisAdvertized, afiSafisGracefulAdvertized);
66 this.clusterId = clusterId;
67 this.localAs = localAs;
73 final String peerName,
76 final IpAddress neighborAddress,
77 final Set<TablesKey> afiSafisGracefulAdvertized) {
78 this(rib, peerName, groupId, role, null, null, neighborAddress,
79 rib.getLocalTablesKeys(), afiSafisGracefulAdvertized);
82 final synchronized FluentFuture<? extends CommitInfo> removePeer(
83 @Nonnull final DOMTransactionChain chain,
84 @Nullable final YangInstanceIdentifier peerPath) {
85 if (peerPath != null) {
86 LOG.info("AdjRibInWriter closed per Peer {} removed", peerPath);
87 final DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
88 tx.delete(LogicalDatastoreType.OPERATIONAL, peerPath);
89 final FluentFuture<? extends CommitInfo> future = tx.commit();
90 future.addCallback(new FutureCallback<CommitInfo>() {
92 public void onSuccess(final CommitInfo result) {
93 LOG.debug("Peer {} removed", peerPath);
97 public void onFailure(final Throwable t) {
98 LOG.error("Failed to remove Peer {}", peerPath, t);
100 }, MoreExecutors.directExecutor());
103 return CommitInfo.emptyFluentFuture();
106 synchronized YangInstanceIdentifier createPeerPath() {
107 return this.rib.getYangRibId().node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib
108 .rev180329.bgp.rib.rib.Peer.QNAME).node(IdentifierUtils.domPeerId(this.peerId));
112 public synchronized final PeerId getPeerId() {
117 public final PeerRole getRole() {
118 return this.peerRole;
122 public final synchronized byte[] getRawIdentifier() {
123 return Arrays.copyOf(this.rawIdentifier, this.rawIdentifier.length);
127 public final PeerRole getFromPeerRole() {
132 public final PeerId getFromPeerId() {
137 public final ClusterIdentifier getFromClusterId() {
138 return getClusterId();
142 public final void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
143 LOG.debug("Transaction chain {} successful.", chain);
147 public final BGPErrorHandlingState getBGPErrorHandlingState() {
152 public final BGPAfiSafiState getBGPAfiSafiState() {
157 public final AsNumber getFromPeerLocalAs() {
162 public final String getName() {
167 public final ClusterIdentifier getClusterId() {
168 return this.clusterId;
172 public final AsNumber getLocalAs() {