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.FutureCallback;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import java.util.Arrays;
17 import javax.annotation.Nonnull;
18 import javax.annotation.Nullable;
19 import javax.annotation.concurrent.GuardedBy;
20 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
21 import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
22 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
23 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
24 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
25 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
26 import org.opendaylight.protocol.bgp.rib.impl.state.BGPPeerStateImpl;
27 import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
28 import org.opendaylight.protocol.bgp.rib.spi.Peer;
29 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryImportParameters;
30 import org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState;
31 import org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
38 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 abstract class AbstractPeer extends BGPPeerStateImpl implements BGPRouteEntryImportParameters, TransactionChainListener,
44 private static final Logger LOG = LoggerFactory.getLogger(AbstractPeer.class);
45 protected final RIB rib;
47 final PeerRole peerRole;
48 private final ClusterIdentifier clusterId;
49 private final AsNumber localAs;
56 final String peerName,
59 @Nullable final ClusterIdentifier clusterId,
60 @Nullable final AsNumber localAs,
61 final IpAddress neighborAddress,
62 final Set<TablesKey> afiSafisAdvertized,
63 final Set<TablesKey> afiSafisGracefulAdvertized) {
64 super(rib.getInstanceIdentifier(), groupId, neighborAddress, afiSafisAdvertized, afiSafisGracefulAdvertized);
67 this.clusterId = clusterId;
68 this.localAs = localAs;
74 final String peerName,
77 final IpAddress neighborAddress,
78 final Set<TablesKey> afiSafisGracefulAdvertized) {
79 this(rib, peerName, groupId, role, null, null, neighborAddress,
80 rib.getLocalTablesKeys(), afiSafisGracefulAdvertized);
83 @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Unrecognised NullableDecl")
84 final synchronized ListenableFuture<Void> removePeer(
85 @Nonnull final DOMTransactionChain chain,
86 @Nullable final YangInstanceIdentifier peerPath) {
87 if (peerPath != null) {
88 LOG.info("AdjRibInWriter closed per Peer {} removed", peerPath);
89 final DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
90 tx.delete(LogicalDatastoreType.OPERATIONAL, peerPath);
91 final ListenableFuture<Void> future = tx.submit();
92 Futures.addCallback(future, new FutureCallback<Void>() {
94 public void onSuccess(final Void result) {
95 LOG.debug("Peer {} removed", peerPath);
99 public void onFailure(final Throwable t) {
100 LOG.error("Failed to remove Peer {}", peerPath, t);
102 }, MoreExecutors.directExecutor());
105 return Futures.immediateFuture(null);
108 synchronized YangInstanceIdentifier createPeerPath() {
109 return this.rib.getYangRibId().node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib
110 .rev180329.bgp.rib.rib.Peer.QNAME).node(IdentifierUtils.domPeerId(this.peerId));
114 public synchronized final PeerId getPeerId() {
119 public final PeerRole getRole() {
120 return this.peerRole;
124 public final synchronized byte[] getRawIdentifier() {
125 return Arrays.copyOf(this.rawIdentifier, this.rawIdentifier.length);
129 public final PeerRole getFromPeerRole() {
134 public final PeerId getFromPeerId() {
139 public final ClusterIdentifier getFromClusterId() {
140 return getClusterId();
144 public final void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
145 LOG.debug("Transaction chain {} successful.", chain);
149 public final BGPErrorHandlingState getBGPErrorHandlingState() {
154 public final BGPAfiSafiState getBGPAfiSafiState() {
159 public final AsNumber getFromPeerLocalAs() {
164 public final String getName() {
169 public final ClusterIdentifier getClusterId() {
170 return this.clusterId;
174 public final AsNumber getLocalAs() {