import org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPGracelfulRestartState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerMessagesState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
@Nonnull final BGPTableTypeRegistryConsumer bgpTableTypeRegistry) {
return new NeighborBuilder()
.setNeighborAddress(neighbor.getNeighborAddress())
- .setState(buildNeighborState(neighbor.getBGPSessionState()))
+ .setState(buildNeighborState(neighbor.getBGPSessionState(), neighbor.getBGPPeerMessagesState()))
.setTimers(buildTimer(neighbor.getBGPTimersState()))
.setTransport(buildTransport(neighbor.getBGPTransportState()))
.setErrorHandling(buildErrorHandling(neighbor.getBGPErrorHandlingState()))
/**
* Builds Neighbor State from BGPPeerState counters
*
- * @param neighbor BGPPeerState containing Operational state counters
+ * @param sessionState BGPPeerState containing Operational state counters
+ * @param bgpPeerMessagesState
* @return Neighbor State
*/
@Nullable
- public static State buildNeighborState(@Nullable final BGPSessionState neighbor) {
- if (neighbor == null) {
+ public static State buildNeighborState(@Nullable final BGPSessionState sessionState,
+ final BGPPeerMessagesState bgpPeerMessagesState) {
+ if (sessionState == null && bgpPeerMessagesState == null) {
return null;
}
- return new StateBuilder()
- .addAugmentation(NeighborStateAugmentation.class, buildCapabilityState(neighbor))
- .addAugmentation(BgpNeighborStateAugmentation.class,
- buildMessageState(neighbor)).build();
+ final StateBuilder builder = new StateBuilder();
+ if (sessionState != null) {
+ builder.addAugmentation(NeighborStateAugmentation.class, buildCapabilityState(sessionState));
+ }
+ if (bgpPeerMessagesState != null) {
+ builder.addAugmentation(BgpNeighborStateAugmentation.class, buildMessageState(bgpPeerMessagesState));
+ }
+ return builder.build();
}
/**
* @return BgpNeighborState containing Message State
*/
@Nonnull
- public static BgpNeighborStateAugmentation buildMessageState(@Nonnull final BGPSessionState neighbor) {
+ public static BgpNeighborStateAugmentation buildMessageState(@Nonnull final BGPPeerMessagesState neighbor) {
return new BgpNeighborStateAugmentationBuilder()
.setMessages(new MessagesBuilder()
.setReceived(buildMessagesReceived(neighbor))
.setSent(buildMessagesSent(neighbor)).build()).build();
}
- private static Received buildMessagesReceived(@Nonnull final BGPSessionState neighbor) {
+ private static Received buildMessagesReceived(@Nonnull final BGPPeerMessagesState neighbor) {
return new ReceivedBuilder()
.setUPDATE(toBigInteger(neighbor.getUpdateMessagesReceivedCount()))
.setNOTIFICATION(toBigInteger(neighbor.getNotificationMessagesReceivedCount()))
return UnsignedLong.valueOf(updateReceivedCounter).bigIntegerValue();
}
- private static Sent buildMessagesSent(@Nonnull final BGPSessionState neighbor) {
+ private static Sent buildMessagesSent(@Nonnull final BGPPeerMessagesState neighbor) {
return new SentBuilder()
.setUPDATE(toBigInteger(neighbor.getUpdateMessagesSentCount()))
.setNOTIFICATION(toBigInteger(neighbor.getNotificationMessagesSentCount()))
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.protocol.bgp.rib.impl.spi.Codecs;
import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesSentCounters;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
* performs transcoding to BA form (message) and sends it down the channel.
*/
@NotThreadSafe
-final class AdjRibOutListener implements ClusteredDOMDataTreeChangeListener {
+final class AdjRibOutListener implements ClusteredDOMDataTreeChangeListener, PrefixesSentCounters {
private static final Logger LOG = LoggerFactory.getLogger(AdjRibOutListener.class);
private final boolean mpSupport;
private final ListenerRegistration<AdjRibOutListener> registerDataTreeChangeListener;
private final LongAdder routeCounter;
+ private final LongAdder prefixesSentCounter = new LongAdder();
private AdjRibOutListener(final PeerId peerId, final TablesKey tablesKey, final YangInstanceIdentifier ribId,
final CodecsRegistry registry, final RIBSupport support, final DOMDataTreeChangeService service,
private Update advertise(final MapEntryNode route) {
this.routeCounter.increment();
+ this.prefixesSentCounter.increment();
if (!this.mpSupport) {
return buildUpdate(Collections.singleton(route), Collections.<MapEntryNode>emptyList(), routeAttributes(route));
}
boolean isMpSupported() {
return this.mpSupport;
}
+
+ @Override
+ public long getPrefixesSentCount() {
+ return this.prefixesSentCounter.longValue();
+ }
}
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPPeerStateImpl;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateImpl;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPPeerStats;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPPeerStatsImpl;
import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
* For purposed of import policies such as Best Path Selection, application
* peer needs to have a BGP-ID that is configurable.
*/
-public class ApplicationPeer implements AutoCloseable, org.opendaylight.protocol.bgp.rib.spi.Peer, ClusteredDOMDataTreeChangeListener, TransactionChainListener {
+public class ApplicationPeer extends BGPPeerStateImpl implements AutoCloseable,
+ org.opendaylight.protocol.bgp.rib.spi.Peer, ClusteredDOMDataTreeChangeListener, TransactionChainListener {
private static final Logger LOG = LoggerFactory.getLogger(ApplicationPeer.class);
private DOMTransactionChain writerChain;
private EffectiveRibInWriter effectiveRibInWriter;
private AdjRibInWriter adjRibInWriter;
- private BGPPeerStats peerStats;
private ListenerRegistration<ApplicationPeer> registration;
private final Set<NodeIdentifierWithPredicates> supportedTables = new HashSet<>();
-
+ private final BGPSessionStateImpl bgpSessionState = new BGPSessionStateImpl();
@FunctionalInterface
interface RegisterAppPeerListener {
}
public ApplicationPeer(final ApplicationRibId applicationRibId, final Ipv4Address ipAddress, final RIB rib) {
+ super(rib.getInstanceIdentifier(), "application-peers", new IpAddress(ipAddress), rib.getLocalTablesKeys(),
+ Collections.emptySet());
this.name = applicationRibId.getValue();
final RIB targetRib = Preconditions.checkNotNull(rib);
this.rawIdentifier = InetAddresses.forString(ipAddress.getValue()).getAddress();
}
this.supportedTables.add(RibSupportUtils.toYangTablesKey(tablesKey));
});
+ setAdvertizedGracefulRestartTableTypes(Collections.emptyList());
this.adjRibInWriter = AdjRibInWriter.create(this.rib.getYangRibId(), PeerRole.Internal, simpleRoutingPolicy, this.writerChain);
final RIBSupportContextRegistry context = this.rib.getRibSupportContext();
};
this.adjRibInWriter = this.adjRibInWriter.transform(peerId, context, localTables, Collections.emptyMap(),
registerAppPeerListener);
- this.peerStats = new BGPPeerStatsImpl(localTables);
+ final BGPPeerStats peerStats = new BGPPeerStatsImpl(this.name, localTables, this);
this.effectiveRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this), this.peerIId,
- this.rib.getImportPolicyPeerTracker(), context, PeerRole.Internal, this.peerStats.getEffectiveRibInRouteCounters(),
- this.peerStats.getAdjRibInRouteCounters());
+ this.rib.getImportPolicyPeerTracker(), context, PeerRole.Internal,
+ peerStats.getAdjRibInRouteCounters(), localTables);
+ this.bgpSessionState.registerMessagesCounter(this);
}
/**
public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
LOG.debug("Transaction chain {} successful.", chain);
}
+
+ @Override
+ public BGPErrorHandlingState getBGPErrorHandlingState() {
+ return this;
+ }
+
+ @Override
+ public BGPAfiSafiState getBGPAfiSafiState() {
+ return this;
+ }
+
+ @Override
+ public BGPSessionState getBGPSessionState() {
+ return this.bgpSessionState;
+ }
+
+ @Override
+ public BGPTimersState getBGPTimersState() {
+ return this.bgpSessionState;
+ }
+
+ @Override
+ public BGPTransportState getBGPTransportState() {
+ return this.bgpSessionState;
+ }
}
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeRegistration;
import org.opendaylight.protocol.bgp.parser.spi.MessageUtil;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPPeerStateImpl;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateProvider;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPPeerStats;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPPeerStatsImpl;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPSessionStats;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.Peer;
import org.opendaylight.protocol.bgp.rib.spi.RouterIds;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
import org.opendaylight.protocol.concepts.AbstractRegistration;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.DestinationIpv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4Prefixes;
* Class representing a peer. We have a single instance for each peer, which provides translation from BGP events into
* RIB actions.
*/
-public class BGPPeer implements BGPSessionListener, Peer, AutoCloseable, BGPPeerRuntimeMXBean, TransactionChainListener {
-
+public class BGPPeer extends BGPPeerStateImpl implements BGPSessionListener, Peer, AutoCloseable,
+ BGPPeerRuntimeMXBean, TransactionChainListener {
private static final Logger LOG = LoggerFactory.getLogger(BGPPeer.class);
@GuardedBy("this")
private YangInstanceIdentifier peerIId;
private final Set<AbstractRegistration> tableRegistration = new HashSet<>();
- public BGPPeer(final String name, final RIB rib, final PeerRole role, final SimpleRoutingPolicy peerStatus, final RpcProviderRegistry rpcRegistry) {
+ public BGPPeer(final String name, final RIB rib, final PeerRole role, final SimpleRoutingPolicy peerStatus,
+ final RpcProviderRegistry rpcRegistry,
+ @Nonnull final Set<TablesKey> afiSafisAdvertized,
+ @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized) {
+ //FIXME BUG-6971 Once Peer Group is implemented, pass it
+ super(rib.getInstanceIdentifier(), null, new IpAddress(new Ipv4Address(name)), afiSafisAdvertized,
+ afiSafisGracefulAdvertized);
this.peerRole = role;
this.simpleRoutingPolicy = Optional.ofNullable(peerStatus);
this.rib = Preconditions.checkNotNull(rib);
this.name = name;
this.rpcRegistry = rpcRegistry;
- this.peerStats = new BGPPeerStatsImpl(this.tables);
-
+ this.peerStats = new BGPPeerStatsImpl(this.name, this.tables, this);
this.chain = rib.createPeerChain(this);
}
- public BGPPeer(final String name, final RIB rib, final PeerRole role, final RpcProviderRegistry rpcRegistry) {
- this(name, rib, role, null, rpcRegistry);
+ public BGPPeer(final String name, final RIB rib, final PeerRole role,
+ final RpcProviderRegistry rpcRegistry, @Nonnull final Set<TablesKey> afiSafisAdvertized,
+ @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized) {
+ this(name, rib, role, null, rpcRegistry, afiSafisAdvertized, afiSafisGracefulAdvertized);
}
public void instantiateServiceInstance() {
// add current peer to "configured BGP peer" stats
this.rib.getRenderStats().getConfiguredPeerCounter().increment();
- this.ribWriter = AdjRibInWriter.create(rib.getYangRibId(), this.peerRole, this.simpleRoutingPolicy, this.chain);
+ this.ribWriter = AdjRibInWriter.create(this.rib.getYangRibId(), this.peerRole, this.simpleRoutingPolicy, this.chain);
}
@Override
@Override
public synchronized void onSessionUp(final BGPSession session) {
+ this.session = session;
+ if (this.session instanceof BGPSessionStateProvider) {
+ ((BGPSessionStateProvider) this.session).registerMessagesCounter(this);
+ }
+
final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes();
final Set<BgpTableType> advertizedTableTypes = session.getAdvertisedTableTypes();
+ final List<BgpTableType> advertizedGracefulRestartTableTypes = session.getAdvertisedGracefulRestartTableTypes();
LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", this.name, advertizedTableTypes, addPathTablesType);
- this.session = session;
-
this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress();
final PeerId peerId = RouterIds.createPeerId(session.getBgpId());
this.tables.addAll(advertizedTableTypes.stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
+
+ setAdvertizedGracefulRestartTableTypes(advertizedGracefulRestartTableTypes.stream()
+ .map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
final boolean announceNone = isAnnounceNone(this.simpleRoutingPolicy);
final Map<TablesKey, SendReceive> addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
this.peerIId = this.rib.getYangRibId().node(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer.QNAME)
addBgp4Support(peerId, announceNone);
if(!isLearnNone(this.simpleRoutingPolicy)) {
- this.effRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this), this.peerIId,
- this.rib.getImportPolicyPeerTracker(), this.rib.getRibSupportContext(), this.peerRole,
- this.peerStats.getEffectiveRibInRouteCounters(), this.peerStats.getAdjRibInRouteCounters());
+ this.effRibInWriter = EffectiveRibInWriter.create(this.rib.getService(), this.rib.createPeerChain(this),
+ this.peerIId, this.rib.getImportPolicyPeerTracker(), this.rib.getRibSupportContext(), this.peerRole,
+ this.peerStats.getAdjRibInRouteCounters(), this.tables);
+ registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
}
this.ribWriter = this.ribWriter.transform(peerId, this.rib.getRibSupportContext(), this.tables, addPathTableMaps);
// not particularly nice
if (context != null && this.session instanceof BGPSessionImpl) {
- this.adjRibOutListenerSet.put(key, AdjRibOutListener.create(peerId, key, this.rib.getYangRibId(), this.rib.getCodecsRegistry(),
- context.getRibSupport(), this.rib.getService(), ((BGPSessionImpl) this.session).getLimiter(), mpSupport,
- this.peerStats.getAdjRibOutRouteCounters().init(key)));
+ final ChannelOutputLimiter limiter = ((BGPSessionImpl) this.session).getLimiter();
+ final AdjRibOutListener adjRibOut = AdjRibOutListener.create(peerId, key,
+ this.rib.getYangRibId(), this.rib.getCodecsRegistry(), context.getRibSupport(),
+ this.rib.getService(), limiter, mpSupport, this.peerStats.getAdjRibOutRouteCounters().init(key));
+ this.adjRibOutListenerSet.put(key, adjRibOut);
+ registerPrefixesSentCounter(key, adjRibOut);
}
}
closeRegistration();
cleanup();
dropConnection();
+ resetState();
}
private void closeRegistration() {
return ImmutableMap.copyOf(addPathTablesType.stream().collect(Collectors.toMap(af -> new TablesKey(af.getAfi(), af.getSafi()),
BgpAddPathTableType::getSendReceive)));
}
+
+ @Override
+ public BGPErrorHandlingState getBGPErrorHandlingState() {
+ return this;
+ }
+
+ @Override
+ public BGPAfiSafiState getBGPAfiSafiState() {
+ return this;
+ }
+
+ @Override
+ public BGPSessionState getBGPSessionState() {
+ if (this.session instanceof BGPSessionStateProvider) {
+ return ((BGPSessionStateProvider) this.session).getBGPSessionState();
+ }
+ return null;
+ }
+
+ @Override
+ public BGPTimersState getBGPTimersState() {
+ if (this.session instanceof BGPSessionStateProvider) {
+ return ((BGPSessionStateProvider) this.session).getBGPTimersState();
+ }
+ return null;
+ }
+
+ @Override
+ public BGPTransportState getBGPTransportState() {
+ if (this.session instanceof BGPSessionStateProvider) {
+ return ((BGPSessionStateProvider) this.session).getBGPTransportState();
+ }
+ return null;
+ }
}
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
import org.opendaylight.protocol.bgp.parser.spi.pojo.MultiPathSupportImpl;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPMessagesListener;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateImpl;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateProvider;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPSessionStats;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPSessionStatsImpl;
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
import org.opendaylight.protocol.bgp.rib.spi.State;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
import org.slf4j.LoggerFactory;
@VisibleForTesting
-public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> implements BGPSession, BGPSessionStats, AutoCloseable {
+public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> implements BGPSession, BGPSessionStats,
+ BGPSessionStateProvider, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(BGPSessionImpl.class);
private final Ipv4Address bgpId;
private final BGPPeerRegistry peerRegistry;
private final ChannelOutputLimiter limiter;
+ private final BGPSessionStateImpl sessionState;
private BGPSessionStatsImpl sessionStats;
- public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen, final BGPSessionPreferences localPreferences,
- final BGPPeerRegistry peerRegistry) {
+ public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen,
+ final BGPSessionPreferences localPreferences, final BGPPeerRegistry peerRegistry) {
this(listener, channel, remoteOpen, localPreferences.getHoldTime(), peerRegistry);
- this.sessionStats = new BGPSessionStatsImpl(this, remoteOpen, this.holdTimerValue, this.keepAlive, channel, Optional.of(localPreferences), this.tableTypes, this.addPathTypes);
+ this.sessionStats = new BGPSessionStatsImpl(this, remoteOpen, this.holdTimerValue, this.keepAlive, channel,
+ Optional.of(localPreferences), this.tableTypes, this.addPathTypes);
}
- public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen, final int localHoldTimer,
- final BGPPeerRegistry peerRegistry) {
+ public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen,
+ final int localHoldTimer, final BGPPeerRegistry peerRegistry) {
this.listener = Preconditions.checkNotNull(listener);
this.channel = Preconditions.checkNotNull(channel);
this.limiter = new ChannelOutputLimiter(this);
this.keepAlive = this.holdTimerValue / KA_TO_DEADTIMER_RATIO;
this.asNumber = AsNumberUtil.advertizedAsNumber(remoteOpen);
this.peerRegistry = peerRegistry;
+ this.sessionState = new BGPSessionStateImpl();
final Set<TablesKey> tts = Sets.newHashSet();
final Set<BgpTableType> tats = Sets.newHashSet();
this.bgpId = remoteOpen.getBgpIdentifier();
this.sessionStats = new BGPSessionStatsImpl(this, remoteOpen, this.holdTimerValue, this.keepAlive, channel, Optional.<BGPSessionPreferences>absent(),
this.tableTypes, this.addPathTypes);
+
+ this.sessionState.advertizeCapabilities(this.holdTimerValue, channel.remoteAddress(), channel.localAddress(),
+ this.tableTypes, remoteOpen.getBgpParameters());
}
/**
}
this.sessionStats.updateReceivedMsg(msg);
-
+ this.sessionState.messageReceived(msg);
} catch (final BGPDocumentedException e) {
this.terminate(e);
}
});
this.lastMessageSentAt = System.nanoTime();
this.sessionStats.updateSentMsg(msg);
+ this.sessionState.messageSent(msg);
return future;
}
});
this.state = State.IDLE;
removePeerSession();
+ this.sessionState.setSessionState(this.state);
}
/**
protected synchronized void sessionUp() {
this.sessionStats.startSessionStopwatch();
this.state = State.UP;
+ this.sessionState.setSessionState(this.state);
this.listener.onSessionUp(this);
}
this.close();
}
}
+
+ @Override
+ public BGPSessionState getBGPSessionState() {
+ return this.sessionState;
+ }
+
+ @Override
+ public BGPTimersState getBGPTimersState() {
+ return this.sessionState;
+ }
+
+ @Override
+ public BGPTransportState getBGPTransportState() {
+ return this.sessionState;
+ }
+
+ @Override
+ public void registerMessagesCounter(final BGPMessagesListener bgpMessagesListener) {
+ this.sessionState.registerMessagesCounter(bgpMessagesListener);
+ }
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesInstalledCounters;
+import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesReceivedCounters;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
*
*/
@NotThreadSafe
-final class EffectiveRibInWriter implements AutoCloseable {
+final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesInstalledCounters, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(EffectiveRibInWriter.class);
- protected static final NodeIdentifier TABLE_ROUTES = new NodeIdentifier(Routes.QNAME);
- private final class AdjInTracker implements AutoCloseable, ClusteredDOMDataTreeChangeListener {
+ private static final Set<YangInstanceIdentifier> EMPTY_SET = Collections.emptySet();
+ static final NodeIdentifier TABLE_ROUTES = new NodeIdentifier(Routes.QNAME);
+
+ private final class AdjInTracker implements PrefixesReceivedCounters, PrefixesInstalledCounters, AutoCloseable,
+ ClusteredDOMDataTreeChangeListener {
private final RIBSupportContextRegistry registry;
private final YangInstanceIdentifier peerIId;
private final YangInstanceIdentifier effRibTables;
private final ListenerRegistration<?> reg;
private final DOMTransactionChain chain;
- private final PerTableTypeRouteCounter effectiveRibInRouteCounters;
private final PerTableTypeRouteCounter adjRibInRouteCounters;
- private final Map<TablesKey, Set<YangInstanceIdentifier>> effectiveRibInRouteMap = new ConcurrentHashMap<>();
private final Map<TablesKey, Set<YangInstanceIdentifier>> adjRibInRouteMap = new ConcurrentHashMap<>();
+ private final Map<TablesKey, LongAdder> prefixesReceived;
+ private final Map<TablesKey, LongAdder> prefixesInstalled;
- AdjInTracker(final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId,
- @Nonnull final PerTableTypeRouteCounter effectiveRibInRouteCounters, @Nonnull final PerTableTypeRouteCounter adjRibInRouteCounters) {
+ AdjInTracker(final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry,
+ final DOMTransactionChain chain, final YangInstanceIdentifier peerIId,
+ @Nonnull final PerTableTypeRouteCounter adjRibInRouteCounters, @Nonnull Set<TablesKey> tables) {
this.registry = Preconditions.checkNotNull(registry);
this.chain = Preconditions.checkNotNull(chain);
this.peerIId = Preconditions.checkNotNull(peerIId);
this.effRibTables = this.peerIId.node(EffectiveRibIn.QNAME).node(Tables.QNAME);
- this.effectiveRibInRouteCounters = Preconditions.checkNotNull(effectiveRibInRouteCounters);
this.adjRibInRouteCounters = Preconditions.checkNotNull(adjRibInRouteCounters);
+ this.prefixesInstalled = buildPrefixesTables(tables);
+ this.prefixesReceived = buildPrefixesTables(tables);
- final DOMDataTreeIdentifier treeId = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME));
+ final DOMDataTreeIdentifier treeId = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
+ this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME));
LOG.debug("Registered Effective RIB on {}", this.peerIId);
this.reg = service.registerDataTreeChangeListener(treeId, this);
}
- /**
- * @deprecated Should always pass in route counter
- * @param service
- * @param registry
- * @param chain
- * @param peerIId
- */
- @Deprecated
- AdjInTracker(final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId) {
- this(service, registry, chain, peerIId, new PerTableTypeRouteCounter(), new PerTableTypeRouteCounter());
+ private Map<TablesKey, LongAdder> buildPrefixesTables(final Set<TablesKey> tables) {
+ final ImmutableMap.Builder<TablesKey, LongAdder> b = ImmutableMap.builder();
+ tables.forEach(table -> b.put(table, new LongAdder()));
+ return b.build();
}
+
private void updateRoute(@Nonnull final PerTableTypeRouteCounter counter, @Nonnull final Map<TablesKey, Set<YangInstanceIdentifier>> routeMap,
@Nonnull final TablesKey tablesKey, @Nonnull final YangInstanceIdentifier routeId) {
routeMap.putIfAbsent(tablesKey, new HashSet<>());
routeMap.get(tablesKey).add(routeId);
-
updateRouteCounter(counter, routeMap,tablesKey);
}
updateRouteCounter(counter, routeMap,tablesKey);
}
- private void updateRouteCounter(@Nonnull final PerTableTypeRouteCounter counter, @Nonnull final Map<TablesKey, Set<YangInstanceIdentifier>> routeMap,
- @Nonnull final TablesKey tablesKey) {
- final LongAdder tableCounter = counter.getCounterOrSetDefault(tablesKey);
- tableCounter.reset();
- tableCounter.add(routeMap.getOrDefault(tablesKey, new HashSet<>()).size());
+ private void updateRouteCounter(@Nonnull final PerTableTypeRouteCounter counter, @Nonnull final Map<TablesKey,
+ Set<YangInstanceIdentifier>> routeMap, @Nonnull final TablesKey tablesKey) {
+ final int size = routeMap.getOrDefault(tablesKey, EMPTY_SET).size();
+ counter.setValueToCounterOrSetDefault(tablesKey, size);
}
- private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy, final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route) {
+ private void processRoute(final DOMDataWriteTransaction tx, final RIBSupport ribSupport, final AbstractImportPolicy policy,
+ final YangInstanceIdentifier routesPath, final DataTreeCandidateNode route) {
LOG.debug("Process route {}", route.getIdentifier());
final YangInstanceIdentifier routeId = ribSupport.routePath(routesPath, route.getIdentifier());
final TablesKey tablesKey = new TablesKey(ribSupport.getAfi(), ribSupport.getSafi());
LOG.debug("Route deleted. routeId={}", routeId);
deleteRoute(this.adjRibInRouteCounters, this.adjRibInRouteMap, tablesKey, routeId);
- deleteRoute(this.effectiveRibInRouteCounters, this.effectiveRibInRouteMap, tablesKey, routeId);
+ CountersUtil.decrement(this.prefixesInstalled.get(tablesKey), tablesKey);
break;
case UNMODIFIED:
// No-op
case SUBTREE_MODIFIED:
case WRITE:
tx.put(LogicalDatastoreType.OPERATIONAL, routeId, route.getDataAfter().get());
+ CountersUtil.increment(this.prefixesReceived.get(tablesKey), tablesKey);
// count adj-rib-in route first
updateRoute(this.adjRibInRouteCounters, this.adjRibInRouteMap, tablesKey, routeId);
- updateRoute(this.effectiveRibInRouteCounters, this.effectiveRibInRouteMap, tablesKey, routeId);
// Lookup per-table attributes from RIBSupport
final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(route.getDataAfter(), ribSupport.routeAttributesIdentifier()).orNull();
final ContainerNode effectiveAttrs;
if (effectiveAttrs != null) {
tx.put(LogicalDatastoreType.OPERATIONAL, routeId.node(ribSupport.routeAttributesIdentifier()), effectiveAttrs);
-
- updateRoute(this.effectiveRibInRouteCounters, this.effectiveRibInRouteMap, tablesKey, routeId);
+ if(route.getModificationType() == ModificationType.WRITE) {
+ CountersUtil.increment(this.prefixesInstalled.get(tablesKey), tablesKey);
+ }
} else {
LOG.warn("Route {} advertised empty attributes", routeId);
tx.delete(LogicalDatastoreType.OPERATIONAL, routeId);
-
- deleteRoute(this.effectiveRibInRouteCounters, this.effectiveRibInRouteMap, tablesKey, routeId);
}
break;
default:
LOG.debug("Route deleted. routeId={}", childPath);
deleteRoute(this.adjRibInRouteCounters, this.adjRibInRouteMap, tablesKey, childPath);
- deleteRoute(this.effectiveRibInRouteCounters, this.effectiveRibInRouteMap, tablesKey, childPath);
+ CountersUtil.decrement(this.prefixesInstalled.get(tablesKey), tablesKey);
break;
case UNMODIFIED:
// No-op
// delete the corresponding effective table
tx.delete(LogicalDatastoreType.OPERATIONAL, effectiveTablePath);
-
- deleteRoute(this.adjRibInRouteCounters, this.adjRibInRouteMap, new TablesKey(ribSupport.getAfi(), ribSupport.getSafi()));
- deleteRoute(this.effectiveRibInRouteCounters, this.effectiveRibInRouteMap, new TablesKey(ribSupport.getAfi(), ribSupport.getSafi()));
+ final TablesKey tk = new TablesKey(ribSupport.getAfi(), ribSupport.getSafi());
+ deleteRoute(this.adjRibInRouteCounters, this.adjRibInRouteMap, tk);
+ CountersUtil.decrement(this.prefixesInstalled.get(tk), tk);
break;
case SUBTREE_MODIFIED:
modifyTable(tx, tableKey, table);
@Override
public void close() {
this.reg.close();
+ this.prefixesReceived.values().forEach(LongAdder::reset);
+ this.prefixesInstalled.values().forEach(LongAdder::reset);
+ }
+
+ @Override
+ public long getPrefixedReceivedCount(final TablesKey tablesKey) {
+ final LongAdder counter = this.prefixesReceived.get(tablesKey);
+ if (counter == null) {
+ return 0;
+ }
+ return counter.longValue();
+ }
+
+ @Override
+ public Set<TablesKey> getTableKeys() {
+ return ImmutableSet.copyOf(this.prefixesReceived.keySet());
+ }
+
+ @Override
+ public boolean isSupported(final TablesKey tablesKey) {
+ return this.prefixesReceived.containsKey(tablesKey);
+ }
+
+ @Override
+ public long getPrefixedInstalledCount(final TablesKey tablesKey) {
+ final LongAdder counter = this.prefixesInstalled.get(tablesKey);
+ if (counter == null) {
+ return 0;
+ }
+ return counter.longValue();
+ }
+
+ @Override
+ public long getTotalPrefixesInstalled() {
+ return this.prefixesInstalled.values().stream().mapToLong(LongAdder::longValue).sum();
}
}
private final AdjInTracker adjInTracker;
private final AbstractImportPolicy importPolicy;
- @Deprecated
- static EffectiveRibInWriter create(@Nonnull final DOMDataTreeChangeService service, @Nonnull final DOMTransactionChain chain,
- @Nonnull final YangInstanceIdentifier peerIId, @Nonnull final ImportPolicyPeerTracker importPolicyPeerTracker, @Nonnull final RIBSupportContextRegistry registry, final PeerRole peerRole) {
- return new EffectiveRibInWriter(service, chain, peerIId, importPolicyPeerTracker, registry, peerRole);
- }
-
static EffectiveRibInWriter create(@Nonnull final DOMDataTreeChangeService service, @Nonnull final DOMTransactionChain chain,
- @Nonnull final YangInstanceIdentifier peerIId, @Nonnull final ImportPolicyPeerTracker importPolicyPeerTracker, @Nonnull final RIBSupportContextRegistry registry, final PeerRole peerRole,
- @Nonnull final PerTableTypeRouteCounter effectiveRouteCounters, @Nonnull final PerTableTypeRouteCounter adjRibInRouteCounters) {
- return new EffectiveRibInWriter(service, chain, peerIId, importPolicyPeerTracker, registry, peerRole, effectiveRouteCounters, adjRibInRouteCounters);
- }
-
- @Deprecated
- private EffectiveRibInWriter(final DOMDataTreeChangeService service, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId,
- final ImportPolicyPeerTracker importPolicyPeerTracker, final RIBSupportContextRegistry registry, final PeerRole peerRole) {
- importPolicyPeerTracker.peerRoleChanged(peerIId, peerRole);
- this.importPolicy = importPolicyPeerTracker.policyFor(IdentifierUtils.peerId((NodeIdentifierWithPredicates) peerIId.getLastPathArgument()));
- this.adjInTracker = new AdjInTracker(service, registry, chain, peerIId);
+ @Nonnull final YangInstanceIdentifier peerIId, @Nonnull final ImportPolicyPeerTracker importPolicyPeerTracker,
+ @Nonnull final RIBSupportContextRegistry registry, final PeerRole peerRole,
+ @Nonnull final PerTableTypeRouteCounter adjRibInRouteCounters, @Nonnull Set<TablesKey> tables) {
+ return new EffectiveRibInWriter(service, chain, peerIId, importPolicyPeerTracker, registry, peerRole,
+ adjRibInRouteCounters, tables);
}
private EffectiveRibInWriter(final DOMDataTreeChangeService service, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId,
- final ImportPolicyPeerTracker importPolicyPeerTracker, final RIBSupportContextRegistry registry, final PeerRole peerRole,
- @Nonnull final PerTableTypeRouteCounter effectiveRouteCounters, @Nonnull final PerTableTypeRouteCounter adjRibInRouteCounters) {
+ final ImportPolicyPeerTracker importPolicyPeerTracker, final RIBSupportContextRegistry registry, final PeerRole peerRole,
+ @Nonnull final PerTableTypeRouteCounter adjRibInRouteCounters, @Nonnull Set<TablesKey> tables) {
importPolicyPeerTracker.peerRoleChanged(peerIId, peerRole);
this.importPolicy = importPolicyPeerTracker.policyFor(IdentifierUtils.peerId((NodeIdentifierWithPredicates) peerIId.getLastPathArgument()));
- this.adjInTracker = new AdjInTracker(service, registry, chain, peerIId, effectiveRouteCounters, adjRibInRouteCounters);
+ this.adjInTracker = new AdjInTracker(service, registry, chain, peerIId, adjRibInRouteCounters, tables);
}
@Override
public void close() {
this.adjInTracker.close();
}
+
+ @Override
+ public long getPrefixedReceivedCount(final TablesKey tablesKey) {
+ return this.adjInTracker.getPrefixedReceivedCount(tablesKey);
+ }
+
+ @Override
+ public Set<TablesKey> getTableKeys() {
+ return this.adjInTracker.getTableKeys();
+ }
+
+ @Override
+ public boolean isSupported(final TablesKey tablesKey) {
+ return this.adjInTracker.isSupported(tablesKey);
+ }
+
+ @Override
+ public long getPrefixedInstalledCount(@Nonnull final TablesKey tablesKey) {
+ return this.adjInTracker.getPrefixedInstalledCount(tablesKey);
+ }
+
+ @Override
+ public long getTotalPrefixesInstalled() {
+ return this.adjInTracker.getTotalPrefixesInstalled();
+ }
}
import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
import org.opendaylight.protocol.bgp.mode.api.RouteEntry;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.state.rib.TotalPathsCounter;
+import org.opendaylight.protocol.bgp.rib.impl.state.rib.TotalPrefixesCounter;
import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.spi.IdentifierUtils;
import org.opendaylight.protocol.bgp.rib.spi.PeerExportGroup;
import org.slf4j.LoggerFactory;
@NotThreadSafe
-final class LocRibWriter implements AutoCloseable, ClusteredDOMDataTreeChangeListener {
+final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPathsCounter,
+ ClusteredDOMDataTreeChangeListener {
private static final Logger LOG = LoggerFactory.getLogger(LocRibWriter.class);
private final TablesKey localTablesKey;
private final ListenerRegistration<LocRibWriter> reg;
private final PathSelectionMode pathSelectionMode;
- private final LongAdder routeCounter;
+ private final LongAdder totalPathsCounter = new LongAdder();
+ private final LongAdder totalPrefixesCounter = new LongAdder();
- private LocRibWriter(final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier target,
- final Long ourAs, final DOMDataTreeChangeService service, final ExportPolicyPeerTracker exportPolicyPeerTracker, final TablesKey tablesKey,
- @Nonnull final PathSelectionMode pathSelectionMode, final LongAdder routeCounter) {
+ private LocRibWriter(final RIBSupportContextRegistry registry, final DOMTransactionChain chain,
+ final YangInstanceIdentifier target, final Long ourAs, final DOMDataTreeChangeService service,
+ final ExportPolicyPeerTracker exportPolicyPeerTracker, final TablesKey tablesKey,
+ final PathSelectionMode pathSelectionMode) {
this.chain = Preconditions.checkNotNull(chain);
final NodeIdentifierWithPredicates tableKey = RibSupportUtils.toYangTablesKey(tablesKey);
this.localTablesKey = tablesKey;
this.attributesIdentifier = this.ribSupport.routeAttributesIdentifier();
this.exportPolicyPeerTracker = exportPolicyPeerTracker;
this.pathSelectionMode = pathSelectionMode;
- this.routeCounter = routeCounter;
final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
tx.merge(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(Routes.QNAME), this.ribSupport.emptyRoutes());
this.reg = service.registerDataTreeChangeListener(wildcard, this);
}
- public static LocRibWriter create(@Nonnull final RIBSupportContextRegistry registry, @Nonnull final TablesKey tablesKey, @Nonnull final DOMTransactionChain chain,
- @Nonnull final YangInstanceIdentifier target, @Nonnull final AsNumber ourAs, @Nonnull final DOMDataTreeChangeService service, @Nonnull final ExportPolicyPeerTracker ep,
- @Nonnull final PathSelectionMode pathSelectionStrategy, @Nonnull final LongAdder routeCounter) {
- return new LocRibWriter(registry, chain, target, ourAs.getValue(), service, ep, tablesKey, pathSelectionStrategy, routeCounter);
+ public static LocRibWriter create(@Nonnull final RIBSupportContextRegistry registry, @Nonnull final TablesKey tablesKey,
+ @Nonnull final DOMTransactionChain chain,
+ @Nonnull final YangInstanceIdentifier target, @Nonnull final AsNumber ourAs, @Nonnull final DOMDataTreeChangeService service,
+ @Nonnull final ExportPolicyPeerTracker ep, @Nonnull final PathSelectionMode pathSelectionStrategy) {
+ return new LocRibWriter(registry, chain, target, ourAs.getValue(), service, ep, tablesKey,
+ pathSelectionStrategy);
}
@Override
@Nonnull
private RouteEntry createEntry(final PathArgument routeId) {
- final RouteEntry ret = this.pathSelectionMode.createRouteEntry(ribSupport.isComplexRoute());
+ final RouteEntry ret = this.pathSelectionMode.createRouteEntry(this.ribSupport.isComplexRoute());
this.routeEntries.put(routeId, ret);
+ this.totalPrefixesCounter.increment();
LOG.trace("Created new entry for {}", routeId);
return ret;
}
entry = createEntry(routeId);
}
entry.addRoute(routerId, this.ribSupport.extractPathId(maybeData.get()), this.attributesIdentifier, maybeData.get());
- } else if (entry != null && entry.removeRoute(routerId, this.ribSupport.extractPathId(maybeDataBefore.get()))) {
- this.routeEntries.remove(routeId);
- LOG.trace("Removed route from {}", routerId);
+ this.totalPathsCounter.increment();
+ } else if (entry != null) {
+ this.totalPathsCounter.decrement();
+ if(entry.removeRoute(routerId, this.ribSupport.extractPathId(maybeDataBefore.get()))) {
+ this.routeEntries.remove(routeId);
+ this.totalPrefixesCounter.decrement();
+ LOG.trace("Removed route from {}", routerId);
+ }
}
final RouteUpdateKey routeUpdateKey = new RouteUpdateKey(peerId, routeId);
LOG.debug("Updated route {} entry {}", routeId, entry);
routes.put(routeUpdateKey, entry);
}
- updateRouteCounter();
- }
-
- /**
- * Update the statistic of loc-rib route
- */
- private void updateRouteCounter() {
- this.routeCounter.reset();
- this.routeCounter.add(this.routeEntries.size());
}
private void walkThrough(final DOMDataWriteTransaction tx, final Set<Map.Entry<RouteUpdateKey, RouteEntry>> toUpdate) {
entry.updateRoute(this.localTablesKey, this.exportPolicyPeerTracker, this.locRibTarget, this.ribSupport, tx, e.getKey().getRouteId());
}
}
+
+ @Override
+ public long getPrefixesCount() {
+ return this.totalPrefixesCounter.longValue();
+ }
+
+ @Override
+ public long getPathsCount() {
+ return this.totalPathsCounter.longValue();
+ }
}
import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
-import org.opendaylight.protocol.bgp.rib.DefaultRibReference;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer;
import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPRIBStateImpl;
import org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl.BGPRenderStats;
import org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl.RIBImplRuntimeMXBeanImpl;
import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
import org.slf4j.LoggerFactory;
@ThreadSafe
-public final class RIBImpl extends DefaultRibReference implements ClusterSingletonService, AutoCloseable, RIB, TransactionChainListener, SchemaContextListener {
+public final class RIBImpl extends BGPRIBStateImpl implements ClusterSingletonService, RIB, TransactionChainListener,
+ SchemaContextListener, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(RIBImpl.class);
private static final QName RIB_ID_QNAME = QName.create(Rib.QNAME, "id").intern();
private static final ContainerNode EMPTY_TABLE_ATTRIBUTES = ImmutableNodes.containerNode(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME);
final BindingCodecTreeFactory codecFactory, final DOMDataBroker domDataBroker, final List<BgpTableType> localTables,
@Nonnull final Map<TablesKey, PathSelectionMode> bestPathSelectionStrategies, final GeneratedClassLoadingStrategy classStrategy,
final BgpDeployer.WriteConfiguration configurationWriter) {
-
- super(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))));
+ super(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))),
+ localBgpId, localAs);
this.localAs = Preconditions.checkNotNull(localAs);
this.bgpIdentifier = Preconditions.checkNotNull(localBgpId);
this.dispatcher = Preconditions.checkNotNull(dispatcher);
this.yangRibId = yangRibIdBuilder.nodeWithKey(Rib.QNAME, RIB_ID_QNAME, ribId.getValue()).build();
this.bestPathSelectionStrategies = Preconditions.checkNotNull(bestPathSelectionStrategies);
final ClusterIdentifier cId = (clusterId == null) ? new ClusterIdentifier(localBgpId) : clusterId;
- this.renderStats = new RIBImplRuntimeMXBeanImpl(localBgpId, ribId, localAs, cId);
this.ribId = ribId;
final PolicyDatabase policyDatabase = new PolicyDatabase(this.localAs.getValue(), localBgpId, cId);
this.importPolicyPeerTracker = new ImportPolicyPeerTrackerImpl(policyDatabase);
}
this.exportPolicyPeerTrackerMap = exportPolicies.build();
+ this.renderStats = new RIBImplRuntimeMXBeanImpl(localBgpId, ribId, localAs, cId, this, this.localTablesKeys);
LOG.info("RIB Singleton Service {} registered", getIdentifier());
//this need to be always the last step
this.registration = registerClusterSingletonService(this);
pathSelectionStrategy = BasePathSelectionModeFactory.createBestPathSelectionStrategy();
}
- this.locRibs.add(LocRibWriter.create(this.ribContextRegistry, key, createPeerChain(this), getYangRibId(), this.localAs, getService(),
- this.exportPolicyPeerTrackerMap.get(key), pathSelectionStrategy, this.renderStats.getLocRibRouteCounter().init(key)));
+ final LocRibWriter locRibWriter = LocRibWriter.create(this.ribContextRegistry, key, createPeerChain(this),
+ getYangRibId(), this.localAs, getService(), this.exportPolicyPeerTrackerMap.get(key), pathSelectionStrategy);
+ registerTotalPathCounter(key, locRibWriter);
+ registerTotalPrefixesCounter(key, locRibWriter);
+ this.locRibs.add(locRibWriter);
}
@Override
this.locRibs.forEach(LocRibWriter::close);
this.locRibs.clear();
- this.renderStats.getLocRibRouteCounter().resetAll();
-
-
final DOMDataWriteTransaction t = this.domChain.newWriteOnlyTransaction();
t.delete(LogicalDatastoreType.OPERATIONAL, getYangRibId());
final CheckedFuture<Void, TransactionCommitFailedException> cleanFuture = t.submit();
this.domChain.close();
-
return cleanFuture;
}
import org.opendaylight.protocol.bgp.rib.impl.ApplicationPeer;
import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer.WriteConfiguration;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Config;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class AppPeer implements PeerBean {
+public final class AppPeer implements PeerBean, BGPPeerStateConsumer {
private static final Logger LOG = LoggerFactory.getLogger(AppPeer.class);
private static final QName APP_ID_QNAME = QName.create(ApplicationRib.QNAME, "id").intern();
private Neighbor currentConfiguration;
private BgpAppPeerSingletonService bgpAppPeerSingletonService;
+ private ServiceRegistration<?> serviceRegistration;
@Override
public void start(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
} catch (final Exception e) {
LOG.warn("Failed to close application peer instance", e);
}
+ if (this.serviceRegistration != null) {
+ this.serviceRegistration.unregister();
+ this.serviceRegistration = null;
+ }
}
@Override
return new ApplicationRibId(neighbor.getNeighborAddress().getIpv4Address().getValue());
}
- private final class BgpAppPeerSingletonService implements ClusterSingletonService, AutoCloseable {
+ @Override
+ public BGPPeerState getPeerState() {
+ return this.bgpAppPeerSingletonService.getPeerState();
+ }
+
+ void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
+ this.serviceRegistration = serviceRegistration;
+ }
+
+ private final class BgpAppPeerSingletonService implements ClusterSingletonService, BGPPeerStateConsumer,
+ AutoCloseable {
private final ApplicationPeer applicationPeer;
private final DOMDataTreeChangeService dataTreeChangeService;
private final ApplicationRibId appRibId;
public ServiceGroupIdentifier getIdentifier() {
return this.serviceGroupIdentifier;
}
+
+ @Override
+ public BGPPeerState getPeerState() {
+ return this.applicationPeer.getPeerState();
+ }
}
}
\ No newline at end of file
bgpPeer.setServiceRegistration(serviceRegistration);
}
+ private void registerAppPeerInstance(final AppPeer appPeer, final String peerInstanceName) {
+ final Dictionary<String, String> properties = new Hashtable<>();
+ properties.put(InstanceType.PEER.getBeanName(), peerInstanceName);
+ final ServiceRegistration<?> serviceRegistration = this.bundleContext
+ .registerService(InstanceType.APP_PEER.getServices(), appPeer, properties);
+ appPeer.setServiceRegistration(serviceRegistration);
+ }
+
private void initiatePeerInstance(final InstanceIdentifier<Bgp> rootIdentifier, final InstanceIdentifier<Neighbor> neighborIdentifier, final Neighbor neighbor,
final PeerBean bgpPeer, final WriteConfiguration configurationWriter) {
final String peerInstanceName = getNeighborInstanceName(neighborIdentifier);
bgpPeer.start(rib, neighbor, this.tableTypeRegistry, configurationWriter);
if (bgpPeer instanceof BgpPeer) {
registerPeerInstance((BgpPeer) bgpPeer, peerInstanceName);
+ } else if(bgpPeer instanceof AppPeer) {
+ registerAppPeerInstance((AppPeer) bgpPeer, peerInstanceName);
}
}
}
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import java.util.Set;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpPeerState;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpSessionState;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.protocol.bgp.rib.impl.spi.BgpDeployer.WriteConfiguration;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.protocol.util.Ipv4Util;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.AddPathCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.MultiprotocolCapabilityBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class BgpPeer implements PeerBean, BGPPeerRuntimeMXBean {
+public final class BgpPeer implements PeerBean, BGPPeerStateConsumer, BGPPeerRuntimeMXBean {
private static final Logger LOG = LoggerFactory.getLogger(BgpPeer.class);
this.bgpPeerSingletonService.getPeer().resetStats();
}
+ @Override
+ public BGPPeerState getPeerState() {
+ if (this.bgpPeerSingletonService == null) {
+ return null;
+ }
+ return this.bgpPeerSingletonService.getPeerState();
+ }
+
void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
this.serviceRegistration = serviceRegistration;
}
- private final class BgpPeerSingletonService implements ClusterSingletonService, AutoCloseable {
+ private final class BgpPeerSingletonService implements BGPPeerStateConsumer, ClusterSingletonService,
+ AutoCloseable {
private final ServiceGroupIdentifier serviceGroupIdentifier;
private final boolean activeConnection;
private final BGPDispatcher dispatcher;
private final BGPSessionPreferences prefs;
private Future<Void> connection;
- private BgpPeerSingletonService(final RIB rib, final Neighbor neighbor, final BGPTableTypeRegistryConsumer tableTypeRegistry,
- final WriteConfiguration configurationWriter) {
+ private BgpPeerSingletonService(final RIB rib, final Neighbor neighbor,
+ final BGPTableTypeRegistryConsumer tableTypeRegistry, final WriteConfiguration configurationWriter) {
this.neighborAddress = neighbor.getNeighborAddress();
+ final AfiSafis afisSAfis = Preconditions.checkNotNull(neighbor.getAfiSafis());
+ final Set<TablesKey> afiSafisAdvertized = OpenConfigMappingUtil
+ .toTableKey(afisSAfis.getAfiSafi(), tableTypeRegistry);
this.bgpPeer = new BGPPeer(Ipv4Util.toStringIP(this.neighborAddress), rib,
- OpenConfigMappingUtil.toPeerRole(neighbor), getSimpleRoutingPolicy(neighbor), BgpPeer.this.rpcRegistry);
+ OpenConfigMappingUtil.toPeerRole(neighbor), getSimpleRoutingPolicy(neighbor), BgpPeer.this.rpcRegistry,
+ afiSafisAdvertized, Collections.emptySet());
final List<BgpParameters> bgpParameters = getBgpParameters(neighbor, rib, tableTypeRegistry);
final KeyMapping keyMapping = OpenConfigMappingUtil.getNeighborKey(neighbor);
- this.prefs = new BGPSessionPreferences(rib.getLocalAs(), getHoldTimer(neighbor), rib.getBgpIdentifier(), getPeerAs(neighbor, rib),
- bgpParameters, getPassword(keyMapping));
+ this.prefs = new BGPSessionPreferences(rib.getLocalAs(), getHoldTimer(neighbor), rib.getBgpIdentifier(),
+ getPeerAs(neighbor, rib), bgpParameters, getPassword(keyMapping));
this.activeConnection = OpenConfigMappingUtil.isActive(neighbor);
this.dispatcher = rib.getDispatcher();
this.inetAddress = Ipv4Util.toInetSocketAddress(this.neighborAddress, OpenConfigMappingUtil.getPort(neighbor));
this.key = Optional.fromNullable(keyMapping);
this.configurationWriter = configurationWriter;
this.serviceGroupIdentifier = rib.getRibIServiceGroupIdentifier();
- LOG.info("Peer Singleton Service {} registered", this.serviceGroupIdentifier);
+ LOG.info("Peer Singleton Service {} registered", this.serviceGroupIdentifier.getValue());
//this need to be always the last step
this.registration = rib.registerClusterSingletonService(this);
}
if(this.configurationWriter != null) {
this.configurationWriter.apply();
}
- LOG.info("Peer Singleton Service {} instantiated", getIdentifier());
+ LOG.info("Peer Singleton Service {} instantiated", getIdentifier().getValue());
this.bgpPeer.instantiateServiceInstance();
BgpPeer.this.peerRegistry.addPeer(this.neighborAddress, this.bgpPeer, this.prefs);
if (this.activeConnection) {
- this.connection = this.dispatcher.createReconnectingClient(this.inetAddress, BgpPeer.this.peerRegistry, this.retryTimer, this.key);
+ this.connection = this.dispatcher.createReconnectingClient(this.inetAddress, BgpPeer.this.peerRegistry,
+ this.retryTimer, this.key);
}
}
@Override
public ListenableFuture<Void> closeServiceInstance() {
- LOG.info("Close Peer Singleton Service {}", getIdentifier());
+ LOG.info("Close Peer Singleton Service {}", getIdentifier().getValue());
if (this.connection != null) {
this.connection.cancel(true);
this.connection = null;
BGPPeerRuntimeMXBean getPeer() {
return this.bgpPeer;
}
+
+ @Override
+ public BGPPeerState getPeerState() {
+ return this.bgpPeer.getPeerState();
+ }
}
}
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
public final class OpenConfigMappingUtil {
+ static final String APPLICATION_PEER_GROUP_NAME = "application-peers";
private static final AfiSafi IPV4_AFISAFI = new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class).build();
private static final List<AfiSafi> DEFAULT_AFISAFI = ImmutableList.of(IPV4_AFISAFI);
private static final int HOLDTIMER = 90;
private static final int CONNECT_RETRY = 30;
private static final PortNumber PORT = new PortNumber(179);
- static final String APPLICATION_PEER_GROUP_NAME = "application-peers";
private static final BigDecimal DEFAULT_KEEP_ALIVE = BigDecimal.valueOf(30);
private static final BigDecimal DEFAULT_MINIMUM_ADV_INTERVAL = BigDecimal.valueOf(30);
public static int getHoldTimer(final Neighbor neighbor) {
final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers.Config config =
- getTimersConfig(neighbor);
+ getTimersConfig(neighbor);
if (config != null && config.getHoldTime() != null) {
return config.getHoldTime().intValue();
}
public static int getRetryTimer(final Neighbor neighbor) {
final org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers.Config config =
- getTimersConfig(neighbor);
+ getTimersConfig(neighbor);
if (config != null && config.getConnectRetry() != null) {
return config.getConnectRetry().intValue();
}
}
public static InstanceIdentifier<Neighbor> getNeighborInstanceIdentifier(final InstanceIdentifier<Bgp> rootIdentifier,
- final NeighborKey neighborKey) {
+ final NeighborKey neighborKey) {
return rootIdentifier.child(Neighbors.class).child(Neighbor.class, neighborKey);
}
}
public static Global fromRib(final BgpId bgpId, final ClusterIdentifier clusterIdentifier, final RibId ribId,
- final AsNumber localAs, final List<BgpTableType> localTables,
- final Map<TablesKey, PathSelectionMode> pathSelectionStrategies, final BGPTableTypeRegistryConsumer bgpTableTypeRegistryConsumer) {
+ final AsNumber localAs, final List<BgpTableType> localTables,
+ final Map<TablesKey, PathSelectionMode> pathSelectionStrategies, final BGPTableTypeRegistryConsumer bgpTableTypeRegistryConsumer) {
return toGlobalConfiguration(bgpId, clusterIdentifier, localAs, localTables, pathSelectionStrategies, bgpTableTypeRegistryConsumer);
}
private static Global toGlobalConfiguration(final BgpId bgpId, final ClusterIdentifier clusterIdentifier,
- final AsNumber localAs, final List<BgpTableType> localTables,
- final Map<TablesKey, PathSelectionMode> pathSelectionStrategies, final BGPTableTypeRegistryConsumer bgpTableTypeRegistryConsumer) {
+ final AsNumber localAs, final List<BgpTableType> localTables,
+ final Map<TablesKey, PathSelectionMode> pathSelectionStrategies, final BGPTableTypeRegistryConsumer bgpTableTypeRegistryConsumer) {
final ConfigBuilder configBuilder = new ConfigBuilder();
configBuilder.setAs(localAs);
configBuilder.setRouterId(bgpId);
if (clusterIdentifier != null) {
configBuilder.addAugmentation(GlobalConfigAugmentation.class,
- new GlobalConfigAugmentationBuilder().setRouteReflectorClusterId(new RrClusterIdType(clusterIdentifier)).build());
+ new GlobalConfigAugmentationBuilder().setRouteReflectorClusterId(new RrClusterIdType(clusterIdentifier)).build());
}
return new GlobalBuilder().setAfiSafis(new AfiSafisBuilder().setAfiSafi(toAfiSafis(localTables,
- (afiSafi, tableType) -> toGlobalAfiSafiAddPath(afiSafi, tableType, pathSelectionStrategies), bgpTableTypeRegistryConsumer)).build())
- .setConfig(configBuilder.build()).build();
+ (afiSafi, tableType) -> toGlobalAfiSafiAddPath(afiSafi, tableType, pathSelectionStrategies), bgpTableTypeRegistryConsumer)).build())
+ .setConfig(configBuilder.build()).build();
}
public static Neighbor fromBgpPeer(final List<AddressFamilies> addPathCapabilities,
- final List<BgpTableType> advertisedTables, final Integer holdTimer, final IpAddress ipAddress,
- final Boolean isActive, final Rfc2385Key password, final PortNumber portNumber, final Integer retryTimer,
- final AsNumber remoteAs, final PeerRole peerRole, final SimpleRoutingPolicy simpleRoutingPolicy, final BGPTableTypeRegistryConsumer bgpTableTypeRegistryConsumer) {
+ final List<BgpTableType> advertisedTables, final Integer holdTimer, final IpAddress ipAddress,
+ final Boolean isActive, final Rfc2385Key password, final PortNumber portNumber, final Integer retryTimer,
+ final AsNumber remoteAs, final PeerRole peerRole, final SimpleRoutingPolicy simpleRoutingPolicy, final BGPTableTypeRegistryConsumer bgpTableTypeRegistryConsumer) {
final NeighborBuilder neighborBuilder = new NeighborBuilder();
neighborBuilder.setNeighborAddress(ipAddress);
neighborBuilder.setKey(new NeighborKey(ipAddress));
neighborBuilder.setAfiSafis(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder().setAfiSafi(toAfiSafis(advertisedTables,
- (afiSafi, tableType) -> toNeighborAfiSafiAddPath(afiSafi, tableType, addPathCapabilities), bgpTableTypeRegistryConsumer)).build());
+ (afiSafi, tableType) -> toNeighborAfiSafiAddPath(afiSafi, tableType, addPathCapabilities), bgpTableTypeRegistryConsumer)).build());
neighborBuilder.setTransport(new TransportBuilder().setConfig(
- new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.transport.ConfigBuilder()
+ new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.transport.ConfigBuilder()
.setPassiveMode(!isActive)
.setMtuDiscovery(Boolean.FALSE)
.addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config1.class,
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config1Builder()
- .setRemotePort(portNumber).build())
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev160614.Config1Builder()
+ .setRemotePort(portNumber).build())
.build()).build());
neighborBuilder.setConfig(
- new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder()
+ new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder()
.setAuthPassword(password != null ? password.getValue() : null)
.setPeerAs(remoteAs)
.setPeerType(toPeerType(peerRole))
.addAugmentation(NeighborConfigAugmentation.class, setNeighborAugmentation(simpleRoutingPolicy))
.build());
neighborBuilder.setTimers(new TimersBuilder().setConfig(
- new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers.ConfigBuilder()
+ new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers.ConfigBuilder()
.setHoldTime(BigDecimal.valueOf(holdTimer))
.setConnectRetry(BigDecimal.valueOf(retryTimer))
.setKeepaliveInterval(DEFAULT_KEEP_ALIVE)
.setMinimumAdvertisementInterval(DEFAULT_MINIMUM_ADV_INTERVAL)
.build()).build());
neighborBuilder.setRouteReflector(new RouteReflectorBuilder().setConfig(
- new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.route.reflector.ConfigBuilder()
+ new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.route.reflector.ConfigBuilder()
.setRouteReflectorClient(peerRole == PeerRole.RrClient).build()).build());
return neighborBuilder.build();
}
neighborBuilder.setNeighborAddress(new IpAddress(new Ipv4Address(bgpId.getValue())));
neighborBuilder.setKey(new NeighborKey(neighborBuilder.getNeighborAddress()));
neighborBuilder.setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder()
- .setDescription(applicationRibId.getValue())
- .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build())
- .build());
+ .setDescription(applicationRibId.getValue())
+ .addAugmentation(Config2.class, new Config2Builder().setPeerGroup(APPLICATION_PEER_GROUP_NAME).build())
+ .build());
return neighborBuilder.build();
}
- private static final NeighborConfigAugmentation setNeighborAugmentation(final SimpleRoutingPolicy simpleRoutingPolicy) {
+ private static NeighborConfigAugmentation setNeighborAugmentation(final SimpleRoutingPolicy simpleRoutingPolicy) {
if (simpleRoutingPolicy != null) {
return new NeighborConfigAugmentationBuilder().setSimpleRoutingPolicy(simpleRoutingPolicy).build();
}
}
static List<AfiSafi> toAfiSafis(final List<BgpTableType> advertizedTables, final BiFunction<AfiSafi, BgpTableType, AfiSafi> function,
- final BGPTableTypeRegistryConsumer bgpTableTypeRegistryConsumer) {
+ final BGPTableTypeRegistryConsumer bgpTableTypeRegistryConsumer) {
final List<AfiSafi> afiSafis = new ArrayList<>(advertizedTables.size());
for (final BgpTableType tableType : advertizedTables) {
final Optional<AfiSafi> afiSafiMaybe = toAfiSafi(new BgpTableTypeImpl(tableType.getAfi(), tableType.getSafi()), bgpTableTypeRegistryConsumer);
static AfiSafi toNeighborAfiSafiAddPath(final AfiSafi afiSafi, final BgpTableType tableType, final List<AddressFamilies> capabilities) {
final Optional<AddressFamilies> capability = capabilities.stream()
- .filter(af -> af.getAfi().equals(tableType.getAfi()) && af.getSafi().equals(tableType.getSafi()))
- .findFirst();
+ .filter(af -> af.getAfi().equals(tableType.getAfi()) && af.getSafi().equals(tableType.getSafi()))
+ .findFirst();
if (!capability.isPresent()) {
return afiSafi;
}
public static List<BgpTableType> toTableTypes(final List<AfiSafi> afiSafis, final BGPTableTypeRegistryConsumer tableTypeRegistry) {
return afiSafis.stream()
- .map(afiSafi -> tableTypeRegistry.getTableType(afiSafi.getAfiSafiName()))
- .filter(Optional::isPresent)
- .map(Optional::get)
- .collect(Collectors.toList());
+ .map(afiSafi -> tableTypeRegistry.getTableType(afiSafi.getAfiSafiName()))
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .collect(Collectors.toList());
}
+ public static Set<TablesKey> toTableKey(final List<AfiSafi> afiSafis, final BGPTableTypeRegistryConsumer
+ tableTypeRegistry) {
+ return afiSafis.stream()
+ .map(afiSafi -> tableTypeRegistry.getTableKey(afiSafi.getAfiSafiName()))
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .collect(Collectors.toSet());
+ }
}
package org.opendaylight.protocol.bgp.rib.impl.config;
import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getAfiSafiWithDefault;
+import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.getClusterIdentifier;
+import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.toTableTypes;
import com.google.common.base.Preconditions;
import java.util.List;
import org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl.BGPRenderStats;
import org.opendaylight.protocol.bgp.rib.spi.ExportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBStateConsumer;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.global.base.Config;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Global;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class RibImpl implements RIB, AutoCloseable {
+public final class RibImpl implements RIB, BGPRIBStateConsumer, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(RibImpl.class);
private ClusterIdentifier clusterId;
- public RibImpl(final ClusterSingletonServiceProvider provider, final RIBExtensionConsumerContext contextProvider, final BGPDispatcher dispatcher,
- final BindingCodecTreeFactory codecTreeFactory, final DOMDataBroker domBroker, final SchemaService schemaService) {
+ public RibImpl(final ClusterSingletonServiceProvider provider, final RIBExtensionConsumerContext contextProvider,
+ final BGPDispatcher dispatcher, final BindingCodecTreeFactory codecTreeFactory, final DOMDataBroker domBroker,
+ final SchemaService schemaService) {
this.provider = Preconditions.checkNotNull(provider);
this.extensions = contextProvider;
this.dispatcher = dispatcher;
void start(final Global global, final String instanceName, final BGPTableTypeRegistryConsumer tableTypeRegistry,
final BgpDeployer.WriteConfiguration configurationWriter) {
Preconditions.checkState(this.ribImpl == null, "Previous instance %s was not closed.", this);
- this.ribImpl = createRib(this.provider, global, instanceName, tableTypeRegistry, configurationWriter);
+ this.ribImpl = createRib(global, instanceName, tableTypeRegistry, configurationWriter);
this.schemaContextRegistration = this.schemaService.registerSchemaContextListener(this.ribImpl);
}
final Config globalConfig = global.getConfig();
final AsNumber globalAs = globalConfig.getAs();
final Ipv4Address globalRouterId = global.getConfig().getRouterId();
- final ClusterIdentifier globalClusterId = OpenConfigMappingUtil.getClusterIdentifier(globalConfig);
+ final ClusterIdentifier globalClusterId = getClusterIdentifier(globalConfig);
return this.afiSafi.containsAll(globalAfiSafi) && globalAfiSafi.containsAll(this.afiSafi)
&& globalAs.equals(this.asNumber)
&& globalRouterId.getValue().equals(this.routerId.getValue())
return this.ribImpl != null ? this.ribImpl.toString() : null;
}
- private RIBImpl createRib(final ClusterSingletonServiceProvider provider, final Global global, final String bgpInstanceName,
+ private RIBImpl createRib(final Global global, final String bgpInstanceName,
final BGPTableTypeRegistryConsumer tableTypeRegistry, final BgpDeployer.WriteConfiguration configurationWriter) {
this.afiSafi = getAfiSafiWithDefault(global.getAfiSafis(), true);
final Config globalConfig = global.getConfig();
this.asNumber = globalConfig.getAs();
this.routerId = globalConfig.getRouterId();
- this.clusterId = OpenConfigMappingUtil.getClusterIdentifier(globalConfig);
+ this.clusterId = getClusterIdentifier(globalConfig);
final Map<TablesKey, PathSelectionMode> pathSelectionModes = OpenConfigMappingUtil.toPathSelectionMode(this.afiSafi, tableTypeRegistry).entrySet()
.stream().collect(Collectors.toMap(entry -> new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
- return new RIBImpl(provider, new RibId(bgpInstanceName), this.asNumber, new BgpId(this.routerId), this.clusterId,
- this.extensions, this.dispatcher, this.codecTreeFactory, this.domBroker, OpenConfigMappingUtil.toTableTypes(this.afiSafi, tableTypeRegistry), pathSelectionModes,
+ return new RIBImpl(this.provider, new RibId(bgpInstanceName), this.asNumber, new BgpId(this.routerId), this.clusterId,
+ this.extensions, this.dispatcher, this.codecTreeFactory, this.domBroker, toTableTypes(this.afiSafi, tableTypeRegistry), pathSelectionModes,
this.extensions.getClassLoadingStrategy(), configurationWriter);
}
public ClusterSingletonServiceRegistration registerClusterSingletonService(final ClusterSingletonService clusterSingletonService) {
return this.ribImpl.registerClusterSingletonService(clusterSingletonService);
}
+
+ @Override
+ public BGPRIBState getRIBState() {
+ return this.ribImpl.getRIBState();
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.spi;
+
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
+/**
+ * BGP Operational Messages Listener State
+ */
+public interface BGPMessagesListener {
+ /**
+ * Fired when message is sent.
+ *
+ * @param msg message
+ */
+ void messageSent(@Nonnull Notification msg);
+
+ /**
+ * Fired when message is received.
+ *
+ * @param msg message
+ */
+ void messageReceived(@Nonnull Notification msg);
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.spi;
+
+import java.net.SocketAddress;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.Nonnull;
+import org.opendaylight.protocol.bgp.rib.spi.State;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+
+
+/**
+ * BGP Operational Session State Listener
+ */
+public interface BGPSessionStateListener extends BGPMessagesListener{
+ /**
+ * Advertize Session capabilities
+ *
+ * @param holdTimerValue hold Timer
+ * @param remoteAddress remote Address
+ * @param localAddress local Address
+ * @param tableTypes supported families
+ * @param bgpParameters bgp capabilities
+ */
+ void advertizeCapabilities(final int holdTimerValue, @Nonnull final SocketAddress remoteAddress,
+ @Nonnull final SocketAddress localAddress, @Nonnull final Set<BgpTableType> tableTypes,
+ @Nonnull List<BgpParameters> bgpParameters);
+
+ /**
+ * Fired when session state changes
+ *
+ * @param state session state
+ */
+ void setSessionState(@Nonnull State state);
+}
package org.opendaylight.protocol.bgp.rib.impl.spi;
-import com.google.common.collect.Lists;
+import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerRuntimeMXBean;
import org.opendaylight.protocol.bgp.rib.RibReference;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBStateConsumer;
public enum InstanceType {
- RIB("ribImpl", Lists.newArrayList(RIB.class, RibReference.class)),
+ RIB("ribImpl", ImmutableList.of(RIB.class, RibReference.class, BGPRIBStateConsumer.class)),
- PEER("bgpPeer", Collections.singletonList(BGPPeerRuntimeMXBean.class)),
+ PEER("bgpPeer", ImmutableList.of(BGPPeerRuntimeMXBean.class, BGPPeerStateConsumer.class)),
- APP_PEER("appPeer", Collections.emptyList());
+ APP_PEER("appPeer", Collections.singletonList(BGPPeerStateConsumer.class));
private final String beanName;
- private final String[] services;
+ private final List<String> services;
InstanceType(final String beanName, final List<Class<?>> services) {
this.beanName = beanName;
- this.services = new String[services.size()];
- services.stream().map(clazz -> clazz.getName()).collect(Collectors.toList()).toArray(this.services);
+ this.services = ImmutableList.copyOf(services.stream().map(Class::getName).collect(Collectors.toList()));
}
public String getBeanName() {
}
public String[] getServices() {
- return this.services;
+ return this.services.toArray(new String[0]);
}
-
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.LongAdder;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.protocol.bgp.rib.DefaultRibReference;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPMessagesListener;
+import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesInstalledCounters;
+import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesReceivedCounters;
+import org.opendaylight.protocol.bgp.rib.impl.state.peer.PrefixesSentCounters;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPAfiSafiState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPErrorHandlingState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPGracelfulRestartState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerMessagesState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
+public abstract class BGPPeerStateImpl extends DefaultRibReference implements BGPPeerState, BGPAfiSafiState,
+ BGPGracelfulRestartState, BGPErrorHandlingState, BGPPeerMessagesState, BGPPeerStateConsumer, BGPMessagesListener {
+ private static final long NONE = 0L;
+ private final IpAddress neighborAddress;
+ private final Set<TablesKey> afiSafisAdvertized;
+ private final Set<TablesKey> afiSafisGracefulAdvertized;
+ private final Set<TablesKey> afiSafisGracefulReceived = new HashSet<>();
+ private final LongAdder updateSentCounter = new LongAdder();
+ private final LongAdder notificationSentCounter = new LongAdder();
+ private final LongAdder updateReceivedCounter = new LongAdder();
+ private final LongAdder notificationReceivedCounter = new LongAdder();
+ private final LongAdder erroneousUpdate = new LongAdder();
+ private final String groupId;
+
+ @GuardedBy("this")
+ private final Map<TablesKey, PrefixesSentCounters> prefixesSent = new HashMap<>();
+ @GuardedBy("this")
+ private PrefixesReceivedCounters prefixesReceived;
+ @GuardedBy("this")
+ private PrefixesInstalledCounters prefixesInstalled;
+ @GuardedBy("this")
+ private boolean localRestarting;
+ @GuardedBy("this")
+ private int peerRestartTime;
+ @GuardedBy("this")
+ private boolean peerRestarting;
+
+ public BGPPeerStateImpl(@Nonnull final KeyedInstanceIdentifier<Rib, RibKey> instanceIdentifier,
+ @Nullable final String groupId, @Nonnull final IpAddress neighborAddress,
+ @Nonnull final Set<TablesKey> afiSafisAdvertized,
+ @Nonnull final Set<TablesKey> afiSafisGracefulAdvertized) {
+ super(instanceIdentifier);
+ this.neighborAddress = Preconditions.checkNotNull(neighborAddress);
+ this.groupId = groupId;
+ this.afiSafisAdvertized = Preconditions.checkNotNull(afiSafisAdvertized);
+ this.afiSafisGracefulAdvertized = Preconditions.checkNotNull(afiSafisGracefulAdvertized);
+ }
+
+ @Override
+ public final String getGroupId() {
+ return this.groupId;
+ }
+
+ @Override
+ public final IpAddress getNeighborAddress() {
+ return this.neighborAddress;
+ }
+
+ @Override
+ public final synchronized long getTotalPrefixes() {
+ if (this.prefixesInstalled == null) {
+ return NONE;
+ }
+ return this.prefixesInstalled.getTotalPrefixesInstalled();
+ }
+
+ @Override
+ public final BGPPeerMessagesState getBGPPeerMessagesState() {
+ return this;
+ }
+
+ @Override
+ public final BGPGracelfulRestartState getBGPGracelfulRestart() {
+ return this;
+ }
+
+ @Override
+ public final synchronized boolean isAfiSafiSupported(final TablesKey tablesKey) {
+ return this.prefixesReceived != null && this.prefixesReceived.isSupported(tablesKey) &&
+ this.afiSafisAdvertized.contains(tablesKey);
+ }
+
+ @Override
+ public final synchronized long getPrefixesInstalledCount(final TablesKey tablesKey) {
+ if (this.prefixesInstalled == null) {
+ return NONE;
+ }
+ return this.prefixesInstalled.getPrefixedInstalledCount(tablesKey);
+ }
+
+ @Override
+ public final synchronized long getPrefixesSentCount(@Nonnull final TablesKey tablesKey) {
+ if (this.prefixesSent == null) {
+ return 0;
+ }
+ final PrefixesSentCounters counter = this.prefixesSent.get(tablesKey);
+ if (counter == null) {
+ return NONE;
+ }
+ return counter.getPrefixesSentCount();
+ }
+
+ @Override
+ public final synchronized long getPrefixesReceivedCount(final TablesKey tablesKey) {
+ if (this.prefixesReceived == null) {
+ return NONE;
+ }
+ return this.prefixesReceived.getPrefixedReceivedCount(tablesKey);
+ }
+
+ @Override
+ public final Set<TablesKey> getAfiSafisAdvertized() {
+ return ImmutableSet.copyOf(this.afiSafisAdvertized);
+ }
+
+ @Override
+ public final synchronized Set<TablesKey> getAfiSafisReceived() {
+ if (this.prefixesReceived == null) {
+ return Collections.emptySet();
+ }
+ return this.prefixesReceived.getTableKeys();
+ }
+
+ @Override
+ public final boolean isGracefulRestartAdvertized(final TablesKey tablesKey) {
+ return this.afiSafisGracefulAdvertized.contains(tablesKey);
+ }
+
+ @Override
+ public final boolean isGracefulRestartReceived(final TablesKey tablesKey) {
+ return this.afiSafisGracefulReceived.contains(tablesKey);
+ }
+
+ @Override
+ public final synchronized boolean isLocalRestarting() {
+ return this.localRestarting;
+ }
+
+ @Override
+ public final synchronized int getPeerRestartTime() {
+ return this.peerRestartTime;
+ }
+
+ @Override
+ public final synchronized boolean isPeerRestarting() {
+ return this.peerRestarting;
+ }
+
+ //FIXME BUG-196
+ public final void setAfiSafiGracefulRestartState(final int peerRestartTime, final boolean peerRestarting,
+ final boolean localRestarting) {
+ this.peerRestartTime = peerRestartTime;
+ this.peerRestarting = peerRestarting;
+ this.localRestarting = localRestarting;
+ }
+
+ protected final synchronized void setAdvertizedGracefulRestartTableTypes(final List<TablesKey> receivedGraceful) {
+ this.afiSafisGracefulReceived.addAll(receivedGraceful);
+ }
+
+ protected final synchronized void registerPrefixesSentCounter(final TablesKey tablesKey,
+ final PrefixesSentCounters prefixesSentCounter) {
+ this.prefixesSent.put(tablesKey, prefixesSentCounter);
+ }
+
+ protected final synchronized void registerPrefixesCounters(@Nonnull final PrefixesReceivedCounters prefixesReceived,
+ @Nonnull final PrefixesInstalledCounters prefixesInstalled) {
+ this.prefixesReceived = prefixesReceived;
+ this.prefixesInstalled = prefixesInstalled;
+ }
+
+ protected final synchronized void resetState() {
+ this.localRestarting = false;
+ this.peerRestartTime = 0;
+ this.peerRestarting = false;
+ }
+
+ @Override
+ public final BGPPeerState getPeerState() {
+ return this;
+ }
+
+ @Override
+ public final long getErroneousUpdateReceivedCount() {
+ //FIXME BUG-4979
+ return this.erroneousUpdate.longValue();
+ }
+
+ @Override
+ public final long getUpdateMessagesSentCount() {
+ return this.updateSentCounter.longValue();
+ }
+
+ @Override
+ public final long getNotificationMessagesSentCount() {
+ return this.notificationSentCounter.longValue();
+ }
+
+ @Override
+ public final long getUpdateMessagesReceivedCount() {
+ return this.updateReceivedCounter.longValue();
+ }
+
+ @Override
+ public final long getNotificationMessagesReceivedCount() {
+ return this.notificationReceivedCounter.longValue();
+ }
+
+ @Override
+ public final void messageSent(final Notification msg) {
+ if (msg instanceof Notify) {
+ this.notificationSentCounter.increment();
+ } else if (msg instanceof Update) {
+ this.updateSentCounter.increment();
+ }
+ }
+
+ @Override
+ public final void messageReceived(final Notification msg) {
+ if (msg instanceof Notify) {
+ this.notificationReceivedCounter.increment();
+ } else if (msg instanceof Update) {
+ this.updateReceivedCounter.increment();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state;
+
+
+import com.google.common.base.Preconditions;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.protocol.bgp.rib.DefaultRibReference;
+import org.opendaylight.protocol.bgp.rib.impl.state.rib.TotalPathsCounter;
+import org.opendaylight.protocol.bgp.rib.impl.state.rib.TotalPrefixesCounter;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBStateConsumer;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+public class BGPRIBStateImpl extends DefaultRibReference implements BGPRIBState, BGPRIBStateConsumer {
+ private final BgpId routeId;
+ private final AsNumber localAs;
+ @GuardedBy("this")
+ private final Map<TablesKey, TotalPathsCounter> totalPaths = new HashMap<>();
+ @GuardedBy("this")
+ private final Map<TablesKey, TotalPrefixesCounter> totalPrefixes = new HashMap<>();
+
+ protected BGPRIBStateImpl(final KeyedInstanceIdentifier<Rib, RibKey> instanceIdentifier,
+ @Nonnull final BgpId routeId, @Nonnull final AsNumber localAs) {
+ super(instanceIdentifier);
+ this.routeId = Preconditions.checkNotNull(routeId);
+ this.localAs = Preconditions.checkNotNull(localAs);
+ }
+
+ @Override
+ public final synchronized Map<TablesKey, Long> getPrefixesCount() {
+ return this.totalPrefixes.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
+ (entry) -> entry.getValue().getPrefixesCount()));
+ }
+
+ @Override
+ public final synchronized Map<TablesKey, Long> getPathsCount() {
+ return this.totalPaths.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
+ (entry) -> entry.getValue().getPathsCount()));
+ }
+
+ @Override
+ public final synchronized long getTotalPathsCount() {
+ return this.totalPaths.values().stream().mapToLong(TotalPathsCounter::getPathsCount).sum();
+ }
+
+ @Override
+ public final synchronized long getTotalPrefixesCount() {
+ return this.totalPrefixes.values().stream().mapToLong(TotalPrefixesCounter::getPrefixesCount).sum();
+ }
+
+ @Override
+ public final synchronized long getPathCount(TablesKey tablesKey) {
+ return this.totalPaths.get(tablesKey).getPathsCount();
+ }
+
+ @Override
+ public final synchronized long getPrefixesCount(TablesKey tablesKey) {
+ return this.totalPrefixes.get(tablesKey).getPrefixesCount();
+ }
+
+ @Override
+ public final AsNumber getAs() {
+ return this.localAs;
+ }
+
+ @Override
+ public final BgpId getRouteId() {
+ return this.routeId;
+ }
+
+ protected final synchronized void registerTotalPathCounter(@Nonnull final TablesKey key,
+ @Nonnull final TotalPathsCounter totalPathsCounter) {
+ this.totalPaths.put(key, totalPathsCounter);
+ }
+
+ protected final synchronized void registerTotalPrefixesCounter(@Nonnull final TablesKey key,
+ @Nonnull final TotalPrefixesCounter totalPrefixesCounter) {
+ this.totalPrefixes.put(key, totalPrefixesCounter);
+ }
+
+ @Override
+ public final BGPRIBState getRIBState() {
+ return this;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state;
+
+import com.google.common.base.Stopwatch;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.GuardedBy;
+import javax.annotation.concurrent.ThreadSafe;
+import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPMessagesListener;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionStateListener;
+import org.opendaylight.protocol.bgp.rib.spi.State;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.MultiprotocolCapability;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
+@ThreadSafe
+public final class BGPSessionStateImpl implements BGPSessionState, BGPTimersState, BGPTransportState,
+ BGPSessionStateListener {
+ private static final PortNumber NON_DEFINED_PORT = new PortNumber(0);
+ private final Stopwatch sessionStopwatch;
+ private int holdTimerValue;
+ private IpAddress remoteAddress;
+ private PortNumber remotePort = NON_DEFINED_PORT;
+ private PortNumber localPort = NON_DEFINED_PORT;
+ @GuardedBy("this")
+ private boolean addPathCapability;
+ @GuardedBy("this")
+ private boolean asn32Capability;
+ @GuardedBy("this")
+ private boolean gracefulRestartCapability;
+ @GuardedBy("this")
+ private boolean multiProtocolCapability;
+ @GuardedBy("this")
+ private boolean routerRefreshCapability;
+ @GuardedBy("this")
+ private State sessionState;
+ @GuardedBy("this")
+ private BGPMessagesListener messagesListenerCounter;
+
+ public BGPSessionStateImpl() {
+ this.sessionState = State.OPEN_CONFIRM;
+ this.sessionStopwatch = Stopwatch.createUnstarted();
+ }
+
+ @Override
+ public synchronized void messageSent(final Notification msg) {
+ if (this.messagesListenerCounter != null) {
+ this.messagesListenerCounter.messageSent(msg);
+ }
+ }
+
+ @Override
+ public synchronized void messageReceived(final Notification msg) {
+ if (this.messagesListenerCounter != null) {
+ this.messagesListenerCounter.messageReceived(msg);
+ }
+ }
+
+ @Override
+ public synchronized void advertizeCapabilities(final int holdTimerValue, final SocketAddress remoteAddress,
+ final SocketAddress localAddress, final Set<BgpTableType> tableTypes, final List<BgpParameters> bgpParameters) {
+ if (bgpParameters != null && !bgpParameters.isEmpty()) {
+ for (final BgpParameters parameters : bgpParameters) {
+ for (final OptionalCapabilities optionalCapabilities : parameters.getOptionalCapabilities()) {
+ final CParameters cParam = optionalCapabilities.getCParameters();
+ final CParameters1 capabilities = cParam.getAugmentation(CParameters1.class);
+ if (capabilities != null) {
+ final MultiprotocolCapability mc = capabilities.getMultiprotocolCapability();
+ if (mc != null) {
+ this.multiProtocolCapability = true;
+ }
+ if (capabilities.getGracefulRestartCapability() != null) {
+ this.gracefulRestartCapability = true;
+ }
+ if (capabilities.getAddPathCapability() != null) {
+ this.addPathCapability = true;
+ }
+ if (capabilities.getRouteRefreshCapability() != null) {
+ this.routerRefreshCapability = true;
+ }
+ }
+ if (cParam.getAs4BytesCapability() != null) {
+ this.asn32Capability = true;
+ }
+ }
+ }
+ }
+
+ this.holdTimerValue = holdTimerValue;
+ this.remoteAddress = StrictBGPPeerRegistry.getIpAddress(remoteAddress);
+ this.remotePort = new PortNumber(((InetSocketAddress) remoteAddress).getPort());
+ this.localPort = new PortNumber(((InetSocketAddress) localAddress).getPort());
+ }
+
+ @Override
+ public synchronized State getSessionState() {
+ return this.sessionState;
+ }
+
+ @Override
+ public synchronized void setSessionState(@Nonnull State state) {
+ if (state == State.IDLE) {
+ this.sessionStopwatch.reset();
+ } else if (state == State.UP) {
+ this.sessionStopwatch.start();
+ }
+ this.sessionState = state;
+ }
+
+ @Override
+ public synchronized boolean isAddPathCapabilitySupported() {
+ return this.addPathCapability;
+ }
+
+ @Override
+ public synchronized boolean isAsn32CapabilitySupported() {
+ return this.asn32Capability;
+ }
+
+ @Override
+ public synchronized boolean isGracefulRestartCapabilitySupported() {
+ return this.gracefulRestartCapability;
+ }
+
+ @Override
+ public synchronized boolean isMultiProtocolCapabilitySupported() {
+ return this.multiProtocolCapability;
+ }
+
+ @Override
+ public synchronized boolean isRouterRefreshCapabilitySupported() {
+ return this.routerRefreshCapability;
+ }
+
+ @Override
+ public synchronized PortNumber getLocalPort() {
+ return this.localPort;
+ }
+
+ @Override
+ public synchronized IpAddress getRemoteAddress() {
+ return this.remoteAddress;
+ }
+
+ @Nonnull
+ @Override
+ public synchronized PortNumber getRemotePort() {
+ return this.remotePort;
+ }
+
+ @Override
+ public synchronized long getNegotiatedHoldTime() {
+ return this.holdTimerValue;
+ }
+
+ @Override
+ public synchronized long getUpTime() {
+ return this.sessionStopwatch.elapsed(TimeUnit.MILLISECONDS);
+ }
+
+ public synchronized void registerMessagesCounter(final BGPMessagesListener bgpMessagesListener) {
+ this.messagesListenerCounter= bgpMessagesListener;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state;
+
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPMessagesListener;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
+
+/**
+ * Serves to expose BGP Session, Timers, Transport, BGPErrorHandlingState Operational State
+ */
+public interface BGPSessionStateProvider {
+ /**
+ * BGP Operational Session State
+ * @return BGPSessionState
+ */
+ BGPSessionState getBGPSessionState();
+
+ /**
+ * BGP Operational Timers State
+ * @return BGPTimersState
+ */
+ BGPTimersState getBGPTimersState();
+
+ /**
+ * BGP Operational Transport State
+ * @return BGPTransportState
+ */
+ BGPTransportState getBGPTransportState();
+
+ /**
+ * Register BGP Operational Messages State Listener
+ * @param bgpMessagesListener BGPMessagesListener
+ */
+ void registerMessagesCounter(BGPMessagesListener bgpMessagesListener);
+}
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
@ThreadSafe
public class BGPStateCollectorImpl implements BGPStateProvider, BGPStateConsumer {
@GuardedBy("this")
- private final List<BGPRIBState> bgpRibStates = new ArrayList<>();
+ private final List<BGPRIBStateConsumer> bgpRibStates = new ArrayList<>();
@GuardedBy("this")
- private final List<BGPPeerState> bgpPeerStates = new ArrayList<>();
+ private final List<BGPPeerStateConsumer> bgpPeerStates = new ArrayList<>();
@Override
public List<BGPRIBState> getRibStats() {
synchronized (this.bgpRibStates) {
- return ImmutableList.copyOf(this.bgpRibStates);
+ return ImmutableList.copyOf(this.bgpRibStates.stream().map(BGPRIBStateConsumer::getRIBState)
+ .collect(Collectors.toList()));
}
}
@Override
public List<BGPPeerState> getPeerStats() {
synchronized (this.bgpPeerStates) {
- return ImmutableList.copyOf(this.bgpPeerStates);
+ return ImmutableList.copyOf(this.bgpPeerStates.stream().map(BGPPeerStateConsumer::getPeerState)
+ .collect(Collectors.toList()));
}
}
return;
}
synchronized (this.bgpRibStates) {
- this.bgpRibStates.add(bgpState.getRIBState());
+ this.bgpRibStates.add(bgpState);
}
}
return;
}
synchronized (this.bgpRibStates) {
- this.bgpRibStates.remove(bgpState.getRIBState());
+ this.bgpRibStates.remove(bgpState);
}
}
return;
}
synchronized (this.bgpPeerStates) {
- this.bgpPeerStates.add(bgpState.getPeerState());
+ this.bgpPeerStates.add(bgpState);
}
}
return;
}
synchronized (this.bgpPeerStates) {
- this.bgpPeerStates.remove(bgpState.getPeerState());
+ this.bgpPeerStates.remove(bgpState);
}
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state.peer;
+
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+
+/**
+ * Expose Prefixes Installed Count
+ */
+public interface PrefixesInstalledCounters {
+ /**
+ * Prefixes received and installed from Peer count (EffRibIn Count) pet Table
+ * @param tablesKey table
+ * @return count
+ */
+ long getPrefixedInstalledCount(@Nonnull final TablesKey tablesKey);
+
+ /**
+ * total Prefixes received and installed from Peer count (EffRibIn Count)
+ * @return count
+ */
+ long getTotalPrefixesInstalled();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state.peer;
+
+import java.util.Set;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+
+/**
+ * Expose Prefixes Received Count
+ */
+public interface PrefixesReceivedCounters {
+ /**
+ * Prefixes received from Peer count (AdjRinIn Count) pet Table
+ * @param tablesKey table
+ * @return count
+ */
+ long getPrefixedReceivedCount(@Nonnull final TablesKey tablesKey);
+
+ /**
+ * list of supported tables per Peer
+ * @return tables list
+ */
+ Set<TablesKey> getTableKeys();
+
+ /**
+ * table supported per Peer
+ * @param tablesKey table type
+ * @return true if supported
+ */
+ boolean isSupported(TablesKey tablesKey);
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state.peer;
+
+/**
+ * Expose Prefixes Sent Count
+ */
+public interface PrefixesSentCounters {
+ /**
+ * Prefixes sent to peer
+ * @return count
+ */
+ long getPrefixesSentCount();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state.rib;
+
+/**
+ * Expose Total Paths Count per RIB
+ */
+public interface TotalPathsCounter {
+ /**
+ * Total Paths installed on RIB
+ * @return count
+ */
+ long getPathsCount();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.state.rib;
+
+/**
+ * Expose Total Prefixes Count per RIB
+ */
+public interface TotalPrefixesCounter {
+ /**
+ * Total Prefixes installed on RIB
+ * @return count
+ */
+ long getPrefixesCount();
+}
PerTableTypeRouteCounter getAdjRibOutRouteCounters();
- PerTableTypeRouteCounter getEffectiveRibInRouteCounters();
-
LongAdder getSessionEstablishedCounter();
}
import org.opendaylight.controller.config.api.IdentityAttributeRef;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpPeerState;
import org.opendaylight.controller.config.yang.bgp.rib.impl.RouteTable;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPPeerStateImpl;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.common.QName;
private final Set<TablesKey> tablesKeySet;
private final PerTableTypeRouteCounter adjRibInRouteCounters;
private final PerTableTypeRouteCounter adjRibOutRouteCounters;
- private final PerTableTypeRouteCounter effectiveRibInRouteCounters;
private final LongAdder sessionEstablishedCounter = new LongAdder();
+ private final BGPPeerStateImpl neighborState;
- public BGPPeerStatsImpl(@Nonnull final Set<TablesKey> tablesKeySet) {
+ public BGPPeerStatsImpl(@Nonnull final String peerName, @Nonnull final Set<TablesKey> tablesKeySet,
+ @Nonnull final BGPPeerStateImpl neighborState) {
+ Preconditions.checkNotNull(peerName);
this.tablesKeySet = Preconditions.checkNotNull(tablesKeySet);
this.adjRibInRouteCounters = new PerTableTypeRouteCounter(tablesKeySet);
this.adjRibOutRouteCounters = new PerTableTypeRouteCounter(tablesKeySet);
- this.effectiveRibInRouteCounters = new PerTableTypeRouteCounter(tablesKeySet);
+ this.neighborState = Preconditions.checkNotNull(neighborState);
}
public PerTableTypeRouteCounter getAdjRibInRouteCounters() {
- return adjRibInRouteCounters;
+ return this.adjRibInRouteCounters;
}
public PerTableTypeRouteCounter getAdjRibOutRouteCounters() {
- return adjRibOutRouteCounters;
- }
-
- public PerTableTypeRouteCounter getEffectiveRibInRouteCounters() {
- return effectiveRibInRouteCounters;
+ return this.adjRibOutRouteCounters;
}
private RouteTable createRouteTable(@Nonnull final TablesKey tablesKey) {
// we want to get default counter in case particular route table is not initialized (e.g. adj-rib-out is not initialized in some cases)
routeTable.setAdjRibInRoutesCount(toZeroBasedCounter32(this.adjRibInRouteCounters.getCounterOrDefault(tablesKey)));
routeTable.setAdjRibOutRoutesCount(toZeroBasedCounter32(this.adjRibOutRouteCounters.getCounterOrDefault(tablesKey)));
- routeTable.setEffectiveRibInRoutesCount(toZeroBasedCounter32(this.effectiveRibInRouteCounters.getCounterOrDefault(tablesKey)));
+ routeTable.setEffectiveRibInRoutesCount(new ZeroBasedCounter32(this.neighborState
+ .getPrefixesInstalledCount(tablesKey)));
return routeTable;
}
private final ErrorMsgs errMsgs = new ErrorMsgs();
private final ErrorSentTotal errMsgsSentTotal = new ErrorSentTotal();
private final ErrorReceivedTotal errMsgsRecvTotal = new ErrorReceivedTotal();
+ private static final ZeroBasedCounter32 INITIAL_COUNTER = new ZeroBasedCounter32(0L);
public BGPSessionStatsImpl(@Nonnull final BGPSessionImpl session, @Nonnull final Open remoteOpen, final int holdTimerValue, final int keepAlive, @Nonnull final Channel channel,
@Nonnull final Optional<BGPSessionPreferences> localPreferences, @Nonnull final Collection<BgpTableType> tableTypes, @Nonnull final List<AddressFamilies> addPathTypes) {
this.stats.setKeepaliveCurrent(keepAlive);
this.stats.setLocalPeerPreferences(setLocalPeerPref(remoteOpen, channel, tableTypes, addPathTypes));
this.stats.setRemotePeerPreferences(setRemotePeerPref(channel, localPreferences));
- this.errMsgs.setErrorReceivedTotal(errMsgsRecvTotal);
- this.errMsgs.setErrorSentTotal(errMsgsSentTotal);
+ this.errMsgs.setErrorReceivedTotal(this.errMsgsRecvTotal);
+ this.errMsgs.setErrorSentTotal(this.errMsgsSentTotal);
this.errMsgs.setErrorReceived(new ArrayList<>());
this.errMsgs.setErrorSent(new ArrayList<>());
initMsgs();
private static Received newReceivedInstance() {
final Received recv = new Received();
- recv.setCount(new ZeroBasedCounter32(0L));
+ recv.setCount(INITIAL_COUNTER);
return recv;
}
private static Sent newSentInstance() {
final Sent sent = new Sent();
- sent.setCount(new ZeroBasedCounter32(0L));
+ sent.setCount(INITIAL_COUNTER);
return sent;
}
this.updMsgs.setSent(newSentInstance());
this.rrMsgs.setReceived(newReceivedInstance());
this.rrMsgs.setSent(newSentInstance());
- this.errMsgsSentTotal.setCount(new ZeroBasedCounter32(0L));
- this.errMsgsRecvTotal.setCount(new ZeroBasedCounter32(0L));
+ this.errMsgsSentTotal.setCount(INITIAL_COUNTER);
+ this.errMsgsRecvTotal.setCount(INITIAL_COUNTER);
this.errMsgs.getErrorSent().clear();
this.errMsgs.getErrorReceived().clear();
}
received = new ErrorReceived();
received.setErrorCode(error.getErrorCode());
received.setErrorSubcode(error.getErrorSubcode());
- received.setCount(new ZeroBasedCounter32(0L));
+ received.setCount(INITIAL_COUNTER);
errList.add(received);
}
received.setCount(new ZeroBasedCounter32(received.getCount().getValue() + 1));
sent = new ErrorSent();
sent.setErrorCode(error.getErrorCode());
sent.setErrorSubcode(error.getErrorSubcode());
- sent.setCount(new ZeroBasedCounter32(0L));
+ sent.setCount(INITIAL_COUNTER);
errList.add(sent);
}
sent.setCount(new ZeroBasedCounter32(sent.getCount().getValue() + 1));
/**
* Get the counter for given tablesKey. Return an empty counter if it doesn't exist
* NOTE: the created empty counter won't be put into the original map
+ *
* @param tablesKey
* @return
*/
/**
* Get the counter with given tablesKey. Create an empty counter if it doesn't exist
* This method will put the created empty counter back to map
+ *
* @param tablesKey
* @return
*/
LOG.debug("Resetting all route counters..");
this.counters.values().forEach(LongAdder::reset);
}
+
+ public void setValueToCounterOrSetDefault(final TablesKey tablesKey, final int size) {
+ final LongAdder counter = getCounterOrSetDefault(tablesKey);
+ counter.reset();
+ counter.add(size);
+ }
}
import java.util.concurrent.atomic.LongAdder;
import org.opendaylight.controller.config.yang.bgp.rib.impl.RIBImplRuntimeMXBean;
-import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
public interface BGPRenderStats extends RIBImplRuntimeMXBean {
-
- PerTableTypeRouteCounter getLocRibRouteCounter();
-
LongAdder getConfiguredPeerCounter();
LongAdder getConnectedPeerCounter();
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
+import java.util.Set;
import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.controller.config.api.IdentityAttributeRef;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpRenderState;
import org.opendaylight.controller.config.yang.bgp.rib.impl.LocRibRouteTable;
-import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.common.QName;
-public class BGPRenderStatsImpl implements BGPRenderStats {
- private final PerTableTypeRouteCounter locRibRouteCounter = new PerTableTypeRouteCounter();
+public final class BGPRenderStatsImpl implements BGPRenderStats {
private final BgpId bgpId;
private final RibId ribId;
private final ClusterIdentifier clusterId;
private final AsNumber localAs;
- private final LongAdder configuredPeerCounter;
- private final LongAdder connectedPeerCounter;
+ private final LongAdder configuredPeerCounter = new LongAdder();
+ private final LongAdder connectedPeerCounter = new LongAdder();
+ private final BGPRIBState globalState;
+ private final Set<TablesKey> tablesKeys;
- public BGPRenderStatsImpl(@Nonnull final BgpId bgpId, @Nonnull final RibId ribId, @Nonnull final AsNumber localAs, @Nullable final ClusterIdentifier clusterId) {
+ public BGPRenderStatsImpl(@Nonnull final BgpId bgpId, @Nonnull final RibId ribId, @Nonnull final AsNumber localAs,
+ @Nullable final ClusterIdentifier clusterId, @Nonnull final BGPRIBState globalState,
+ @Nonnull final Set<TablesKey> tablesKeys) {
this.bgpId = Preconditions.checkNotNull(bgpId);
this.ribId = Preconditions.checkNotNull(ribId);
+ this.globalState = Preconditions.checkNotNull(globalState);
+ this.tablesKeys = Preconditions.checkNotNull(tablesKeys);
this.localAs = localAs;
this.clusterId = clusterId;
- this.configuredPeerCounter = new LongAdder();
- this.connectedPeerCounter = new LongAdder();
}
@Override
// fill in the the statistic part
final LongAdder totalRouteCount = new LongAdder();
final List<LocRibRouteTable> locRibRouteTableList = new ArrayList<>();
- this.locRibRouteCounter.getCounters().entrySet().forEach(e -> generateCounters(e, locRibRouteTableList, totalRouteCount));
+ this.tablesKeys.forEach(e -> generateCounters(e, locRibRouteTableList, totalRouteCount));
renderState.setLocRibRouteTable(locRibRouteTableList);
renderState.setLocRibRoutesCount(toZeroBasedCounter32(totalRouteCount));
return renderState;
}
- private void generateCounters(final Map.Entry<TablesKey, LongAdder> e, final List<LocRibRouteTable> locRibRouteTableList,
+ private void generateCounters(final TablesKey tablesKey, final List<LocRibRouteTable> locRibRouteTableList,
final LongAdder totalRouteCount) {
final LocRibRouteTable table = new LocRibRouteTable();
- final QName afi = BindingReflections.getQName(e.getKey().getAfi()).intern();
- final QName safi = BindingReflections.getQName(e.getKey().getSafi()).intern();
+ final QName afi = BindingReflections.getQName(tablesKey.getAfi()).intern();
+ final QName safi = BindingReflections.getQName(tablesKey.getSafi()).intern();
table.setAfi(new IdentityAttributeRef(afi.toString()));
table.setSafi(new IdentityAttributeRef(safi.toString()));
- table.setRoutesCount(toZeroBasedCounter32(e.getValue()));
+ final long count = this.globalState.getPathCount(tablesKey);
+ table.setRoutesCount(new ZeroBasedCounter32(count));
locRibRouteTableList.add(table);
- totalRouteCount.add(e.getValue().longValue());
+ totalRouteCount.add(count);
}
- @Override
- public PerTableTypeRouteCounter getLocRibRouteCounter() {
- return this.locRibRouteCounter;
- }
-
@Override
public LongAdder getConfiguredPeerCounter() {
return this.configuredPeerCounter;
*/
package org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl;
+import java.util.Set;
import java.util.concurrent.atomic.LongAdder;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpRenderState;
-import org.opendaylight.protocol.bgp.rib.impl.stats.peer.route.PerTableTypeRouteCounter;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
public class RIBImplRuntimeMXBeanImpl implements BGPRenderStats {
private final BGPRenderStats renderStats;
- public RIBImplRuntimeMXBeanImpl(@Nonnull final BgpId bgpId, @Nonnull final RibId ribId, @Nonnull final AsNumber localAs, @Nullable final ClusterIdentifier clusterId) {
- this.renderStats = new BGPRenderStatsImpl(bgpId, ribId, localAs, clusterId);
+ public RIBImplRuntimeMXBeanImpl(@Nonnull final BgpId bgpId, @Nonnull final RibId ribId,
+ @Nonnull final AsNumber localAs, @Nullable final ClusterIdentifier clusterId,
+ @Nonnull final BGPRIBState globalState,
+ @Nonnull final Set<TablesKey> tablesKeys) {
+ this.renderStats = new BGPRenderStatsImpl(bgpId, ribId, localAs, clusterId, globalState, tablesKeys);
}
@Override
return this.renderStats.getBgpRenderState();
}
- @Override
- public PerTableTypeRouteCounter getLocRibRouteCounter() {
- return this.renderStats.getLocRibRouteCounter();
- }
-
@Override
public LongAdder getConfiguredPeerCounter() {
return this.renderStats.getConfiguredPeerCounter();
import io.netty.channel.epoll.Epoll;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.Future;
-import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import javassist.ClassPool;
import org.junit.After;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
class AbstractAddPathTest extends AbstractDataBrokerTest {
- static final int RETRY_TIMER = 10;
+ private static final int RETRY_TIMER = 10;
static final String RIB_ID = "127.0.0.1";
static final Ipv4Address PEER1 = new Ipv4Address("127.0.0.2");
static final Ipv4Address PEER2 = new Ipv4Address("127.0.0.3");
static final Update UPD_NA_100_EBGP = createSimpleUpdateEbgp(PREFIX1, null);
static final Update UPD_NA_200 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 200);
static final Update UPD_NA_200_EBGP = createSimpleUpdateEbgp(PREFIX1, null);
+ static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ static final Set<TablesKey> AFI_SAFIS_ADVERTIZED = Collections.singleton(TABLES_KEY);
protected BGPExtensionProviderContext context;
private static final InstanceIdentifier<BgpRib> BGP_IID = InstanceIdentifier.create(BgpRib.class);
protected SchemaContext schemaContext;
}
private static void configurePeer(final Ipv4Address localAddress, final RIBImpl ribImpl, final BgpParameters bgpParameters, final PeerRole peerRole) {
- final InetAddress inetAddress = InetAddresses.forString(localAddress.getValue());
+ final IpAddress ipAddress = new IpAddress(new Ipv4Address(InetAddresses.forString(localAddress.getValue())
+ .getHostAddress()));
- final BGPPeer bgpPeer = new BGPPeer(inetAddress.getHostAddress(), ribImpl, peerRole, null);
+
+ final BGPPeer bgpPeer = new BGPPeer(localAddress.getValue(), ribImpl, peerRole, null, AFI_SAFIS_ADVERTIZED,
+ Collections.emptySet());
final List<BgpParameters> tlvs = Lists.newArrayList(bgpParameters);
- StrictBGPPeerRegistry.GLOBAL.addPeer(new IpAddress(new Ipv4Address(inetAddress.getHostAddress())), bgpPeer,
+ StrictBGPPeerRegistry.GLOBAL.addPeer(ipAddress, bgpPeer,
new BGPSessionPreferences(AS_NUMBER, HOLDTIMER, new BgpId(RIB_ID), AS_NUMBER, tlvs, Optional.absent()));
bgpPeer.instantiateServiceInstance();
}
public void testUseCase1() throws Exception {
final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
- final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, new AllPathSelection());
+ final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, new AllPathSelection());
final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"), AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension,
import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.util.HexDumpBGPFileParser;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6Route;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
private AbstractRIBExtensionProviderActivator baseact, lsact;
private RIBExtensionProviderContext ext1, ext2;
private static final TablesKey TABLE_KEY = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
+ private String localAddress = "127.0.0.1";
+ private final IpAddress neighborAddress = new IpAddress(new Ipv4Address(localAddress));
@Mock
BGPDispatcher dispatcher;
@Mock
rib.instantiateServiceInstance();
assertTablesExists(tables, true);
rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
- final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib, PeerRole.Ibgp, null);
+ final BGPPeer peer = new BGPPeer(this.localAddress, rib, PeerRole.Ibgp, null, Collections.emptySet(),
+ Collections.emptySet());
peer.instantiateServiceInstance();
final ListenerRegistration<?> reg = this.mock.registerUpdateListener(peer);
reg.close();
rib.instantiateServiceInstance();
rib.onGlobalContextUpdated(this.schemaService.getGlobalContext());
assertTablesExists(tables, true);
- final BGPPeer peer = new BGPPeer("peer-" + this.mock.toString(), rib, PeerRole.Ibgp, null);
+ final BGPPeer peer = new BGPPeer(this.localAddress, rib, PeerRole.Ibgp, null, Collections.emptySet(),
+ Collections.emptySet());
peer.instantiateServiceInstance();
final ListenerRegistration<?> reg = this.mock.registerUpdateListener(peer);
reg.close();
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import org.opendaylight.controller.config.yang.bgp.rib.impl.RouteTable;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
private Map<YangInstanceIdentifier, NormalizedNode<?, ?>> routes;
private BGPPeer classic;
+ private final Ipv4Address neighborAddress = new Ipv4Address("127.0.0.1");
@Override
@Before
}
private void overrideMockedBehaviour() {
- Mockito.doAnswer(new Answer<Object>() {
- @Override
- public Object answer(final InvocationOnMock invocation) throws Throwable {
- final Object[] args = invocation.getArguments();
- final NormalizedNode<?, ?> node = (NormalizedNode<?, ?>) args[2];
- if (node.getIdentifier().getNodeType().equals(Ipv4Route.QNAME) || node.getNodeType().equals(PREFIX_QNAME)) {
- PeerTest.this.routes.put((YangInstanceIdentifier) args[1], node);
- }
- return args[1];
+ Mockito.doAnswer(invocation -> {
+ final Object[] args = invocation.getArguments();
+ final NormalizedNode<?, ?> node = (NormalizedNode<?, ?>) args[2];
+ if (node.getIdentifier().getNodeType().equals(Ipv4Route.QNAME) || node.getNodeType().equals(PREFIX_QNAME)) {
+ this.routes.put((YangInstanceIdentifier) args[1], node);
}
+ return args[1];
}).when(getTransaction()).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(YangInstanceIdentifier.class), Mockito.any(NormalizedNode.class));
- Mockito.doAnswer(new Answer<Object>() {
- @Override
- public Object answer(final InvocationOnMock invocation) throws Throwable {
- final Object[] args = invocation.getArguments();
- PeerTest.this.routes.remove(args[1]);
- return args[1];
- }
+ Mockito.doAnswer(invocation -> {
+ final Object[] args = invocation.getArguments();
+ this.routes.remove(args[1]);
+ return args[1];
}).when(getTransaction()).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), Mockito.any(YangInstanceIdentifier.class));
}
final Ipv4Prefix first = new Ipv4Prefix("127.0.0.2/32");
final Ipv4Prefix second = new Ipv4Prefix("127.0.0.1/32");
final Ipv4Prefix third = new Ipv4Prefix("127.0.0.3/32");
- this.peer = new ApplicationPeer(new ApplicationRibId("t"), new Ipv4Address("127.0.0.1"), getRib());
+ this.peer = new ApplicationPeer(new ApplicationRibId(this.neighborAddress.getValue()), this.neighborAddress, getRib());
this.peer.instantiateServiceInstance(null, null);
final YangInstanceIdentifier base = getRib().getYangRibId().node(LocRib.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(KEY));
this.peer.onDataTreeChanged(ipv4Input(base, ModificationType.WRITE, first, second, third));
@Test
public void testClassicPeer() throws Exception {
- this.classic = new BGPPeer("testPeer", getRib(), PeerRole.Ibgp, null);
+ this.classic = new BGPPeer(this.neighborAddress.getValue(), getRib(), PeerRole.Ibgp, null, Collections.emptySet(),
+ Collections.emptySet());
this.classic.instantiateServiceInstance();
this.mockSession();
- assertEquals("testPeer", this.classic.getName());
+ assertEquals(this.neighborAddress.getValue(), this.classic.getName());
this.classic.onSessionUp(this.session);
assertEquals(1, this.classic.getBgpPeerState().getSessionEstablishedCount().getValue().intValue());
Assert.assertArrayEquals(new byte[]{1, 1, 1, 1}, this.classic.getRawIdentifier());
- assertEquals("BGPPeer{name=testPeer, tables=[TablesKey [_afi=class org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily, _safi=class org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily]]}", this.classic.toString());
+ assertEquals("BGPPeer{name=127.0.0.1, tables=[TablesKey [_afi=class org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily, _safi=class org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily]]}", this.classic.toString());
final List<Ipv4Prefix> prefs = Lists.newArrayList(new Ipv4Prefix("8.0.1.0/28"), new Ipv4Prefix("127.0.0.1/32"), new Ipv4Prefix("2.2.2.2/24"));
final UpdateBuilder ub = new UpdateBuilder();
assertEquals(3, this.routes.size());
//create new peer so that it gets advertized routes from RIB
- try (final BGPPeer testingPeer = new BGPPeer("testingPeer", getRib(), PeerRole.Ibgp, null)) {
+ try (final BGPPeer testingPeer = new BGPPeer(this.neighborAddress.getValue(), getRib(), PeerRole.Ibgp, null,
+ Collections.emptySet(), Collections.emptySet())) {
testingPeer.instantiateServiceInstance();
testingPeer.onSessionUp(this.session);
assertEquals(3, this.routes.size());
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.rib.spi.RibSupportUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Notify;
private static final AsNumber AS_NUMBER = new AsNumber(30L);
private static final Ipv4Address BGP_ID = new Ipv4Address("1.1.1.2");
private static final String LOCAL_IP = "1.1.1.4";
+ private final IpAddress neighbor = new IpAddress(new Ipv4Address(LOCAL_IP));
private static final int LOCAL_PORT = 12345;
private final BgpTableType ipv4tt = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
private Open classicOpen;
@Test
public void testHandleMessageAfterException() throws InterruptedException {
- final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(new TablesKey(ipv4tt.getAfi(), ipv4tt.getSafi()),
+ final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
BasePathSelectionModeFactory.createBestPathSelectionStrategy());
- final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(RIB_ID), AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension,
- this.dispatcher, this.mappingService.getCodecFactory(), this.domBroker, ImmutableList.of(ipv4tt), pathTables, this.ribExtension
- .getClassLoadingStrategy(), null);
+ final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(RIB_ID), AS_NUMBER,
+ new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher, this.mappingService.getCodecFactory(),
+ this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy(),
+ null);
ribImpl.instantiateServiceInstance();
ribImpl.onGlobalContextUpdated(this.schemaContext);
- final BGPPeer bgpPeer = new BGPPeer("peer-test", ribImpl, PeerRole.Ibgp, null);
+ final BGPPeer bgpPeer = new BGPPeer(LOCAL_IP, ribImpl, PeerRole.Ibgp, null, AFI_SAFIS_ADVERTIZED,
+ Collections.emptySet());
bgpPeer.instantiateServiceInstance();
final BGPSessionImpl bgpSession = new BGPSessionImpl(bgpPeer, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer(), null);
bgpSession.setChannelExtMsgCoder(this.classicOpen);
@Test
public void testUseCase1() throws InterruptedException {
- final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(new TablesKey(ipv4tt.getAfi(), ipv4tt.getSafi()),
+ final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY,
BasePathSelectionModeFactory.createBestPathSelectionStrategy());
- final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(RIB_ID), AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension,
- this.dispatcher, this.mappingService.getCodecFactory(), this.domBroker, ImmutableList.of(ipv4tt), pathTables, this.ribExtension
- .getClassLoadingStrategy(), null);
+ final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId(RIB_ID), AS_NUMBER,
+ new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher, this.mappingService.getCodecFactory(),
+ this.domBroker, ImmutableList.of(this.ipv4tt), pathTables, this.ribExtension.getClassLoadingStrategy(),
+ null);
ribImpl.instantiateServiceInstance();
ribImpl.onGlobalContextUpdated(this.schemaContext);
- final BGPPeer bgpPeer = new BGPPeer("peer-test", ribImpl, PeerRole.Ibgp, null);
+ final BGPPeer bgpPeer = new BGPPeer(LOCAL_IP, ribImpl, PeerRole.Ibgp, null, AFI_SAFIS_ADVERTIZED,
+ Collections.emptySet());
bgpPeer.instantiateServiceInstance();
final BGPSessionImpl bgpSession = new BGPSessionImpl(bgpPeer, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer(), null);
bgpSession.setChannelExtMsgCoder(this.classicOpen);
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Rib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.osgi.framework.ServiceRegistration;
class AbstractConfig {
+ static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
protected static final AsNumber AS = new AsNumber(72L);
+ protected ClusterSingletonService singletonService;
@Mock
protected RIB rib;
@Mock
protected ListenerRegistration listener;
@Mock
protected Future future;
- protected ClusterSingletonService singletonService;
@Mock
protected DOMDataWriteTransaction domDW;
@Mock
private ImportPolicyPeerTracker importPolicyPeerTracker;
@Mock
private DOMDataTreeChangeService dataTreeChangeService;
+ protected static final RibId RIB_ID = new RibId("test");
@Before
public void setUp() throws Exception {
}).when(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
Mockito.doReturn(new LongAdder()).when(this.render).getConfiguredPeerCounter();
Mockito.doReturn(this.render).when(this.rib).getRenderStats();
+ Mockito.doReturn(InstanceIdentifier.create(BgpRib.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight
+ .params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib.class, new RibKey(RIB_ID))).when(this.rib)
+ .getInstanceIdentifier();
Mockito.doReturn(this.domTx).when(this.rib).createPeerChain(any(TransactionChainListener.class));
Mockito.doReturn(AS).when(this.rib).getLocalAs();
Mockito.doReturn(this.importPolicyPeerTracker).when(this.rib).getImportPolicyPeerTracker();
Mockito.doReturn(null).when(checkedFuture).checkedGet();
Mockito.doReturn(null).when(checkedFuture).get();
Mockito.doReturn("checkedFuture").when(checkedFuture).toString();
-
- Mockito.doNothing().when(this.singletonServiceRegistration).close();
+ Mockito.doAnswer(invocationOnMock->{
+ this.singletonService.closeServiceInstance();
+ return null;
+ }).when(this.singletonServiceRegistration).close();
Mockito.doReturn(YangInstanceIdentifier.of(Rib.QNAME)).when(this.rib).getYangRibId();
Mockito.doReturn(this.dataTreeChangeService).when(this.rib).getService();
Mockito.doReturn(this.listener).when(this.dataTreeChangeService).registerDataTreeChangeListener(any(), any());
Mockito.doReturn(java.util.Optional.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)))
.when(this.tableTypeRegistry).getTableType(any());
+ Mockito.doReturn(java.util.Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
Mockito.doReturn(Collections.singleton(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class)))
.when(this.rib).getLocalTables();
Mockito.doNothing().when(this.configurationWriter).apply();
Mockito.verify(this.rib).getService();
Mockito.verify(this.rib).getRibIServiceGroupIdentifier();
Mockito.verify(this.rib).registerClusterSingletonService(any(ClusterSingletonService.class));
+ Mockito.verify(this.rib, times(1)).getLocalTablesKeys();
this.singletonService.instantiateServiceInstance();
Mockito.verify(this.rib, times(2)).getYangRibId();
Mockito.verify(this.configurationWriter).apply();
Mockito.verify(this.rib).getRibSupportContext();
- Mockito.verify(this.rib).getLocalTablesKeys();
+ Mockito.verify(this.rib, times(2)).getLocalTablesKeys();
Mockito.verify(this.domTx).newWriteOnlyTransaction();
APP_PEER.close();
Mockito.verify(this.rib, times(4)).getService();
Mockito.verify(this.rib, times(2)).getRibIServiceGroupIdentifier();
Mockito.verify(this.rib, times(2)).registerClusterSingletonService(any(ClusterSingletonService.class));
-
- this.singletonService.closeServiceInstance();
Mockito.verify(this.listener, times(2)).close();
assertTrue(APP_PEER.containsEqualConfiguration(this.neighbor));
import static org.mockito.Mockito.verify;
import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.DELETE;
import static org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType.WRITE;
+import static org.opendaylight.protocol.bgp.rib.impl.config.AbstractConfig.TABLES_KEY;
import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createAddPath;
import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createConfig;
import static org.opendaylight.protocol.bgp.rib.impl.config.BgpPeerTest.createRR;
private static final AsNumber AS = new AsNumber(72L);
private static final IpAddress IPADDRESS = new IpAddress(new Ipv4Address("127.0.0.1"));
private static final BgpId BGP_ID = new BgpId(IPADDRESS.getIpv4Address());
- private static final BgpTableType TABLE_TYPE = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ private static final BgpTableType TABLE_TYPE = new BgpTableTypeImpl(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class);
+
private static final short SHORT = 0;
@Mock
.when(domDataBroker).getSupportedExtensions();
Mockito.doReturn(Optional.of(TABLE_TYPE)).when(this.tableTypeRegistry).getTableType(any());
+ Mockito.doReturn(Optional.of(TABLES_KEY)).when(this.tableTypeRegistry).getTableKey(any());
Mockito.doNothing().when(this.registration).unregister();
Mockito.doReturn(this.registration).when(this.bundleContext).registerService(eq(InstanceType.RIB.getServices()), any()
, any(Dictionary.class));
verify(this.blueprintContainer).getComponentInstance(eq("bgpPeer"));
verifyPrivate(spyDeployer).invoke("initiatePeerInstance", any(InstanceIdentifier.class), any(InstanceIdentifier.class), any(Neighbor.class),
any(PeerBean.class), any(BgpDeployer.WriteConfiguration.class));
- verifyPrivate(spyDeployer).invoke("registerPeerInstance", any(Neighbor.class), anyString());
+ verifyPrivate(spyDeployer).invoke("registerPeerInstance", any(BgpPeer.class), anyString());
verify(this.bundleContext).registerService(eq(InstanceType.PEER.getServices()), any(BgpPeer.class), any(Dictionary.class));
//change with same peer already existing
}
this.bgpPeer.setServiceRegistration(this.serviceRegistration);
this.bgpPeer.close();
+ Mockito.verify(this.singletonServiceRegistration).close();
+ Mockito.verify(this.future).cancel(true);
+
this.bgpPeer.restart(this.rib, this.tableTypeRegistry);
Mockito.verify(this.rib, times(2)).createPeerChain(any());
Mockito.verify(this.rib, times(4)).getLocalAs();
final Neighbor neighborExpected = createNeighborExpected(NEIGHBOR_ADDRESS);
assertTrue(this.bgpPeer.containsEqualConfiguration(neighborExpected));
assertFalse(this.bgpPeer.containsEqualConfiguration(createNeighborExpected(new IpAddress(new Ipv4Address("127.0.0.2")))));
-
- this.singletonService.closeServiceInstance();
Mockito.verify(this.bgpPeerRegistry).removePeer(any(IpAddress.class));
this.bgpPeer.close();
Mockito.verify(this.singletonServiceRegistration, times(2)).close();
Mockito.verify(this.serviceRegistration).unregister();
- Mockito.verify(this.future).cancel(true);
+ Mockito.verify(this.future, times(2)).cancel(true);
- final Neighbor emptyNeighbor = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS).build();
- this.bgpPeer.start(this.rib, emptyNeighbor, this.tableTypeRegistry, this.configurationWriter);
- assertTrue(this.bgpPeer.containsEqualConfiguration(emptyNeighbor));
+ final Neighbor neighborDiffConfig = new NeighborBuilder().setNeighborAddress(NEIGHBOR_ADDRESS)
+ .setAfiSafis(createAfiSafi()).build();
+ this.bgpPeer.start(this.rib, neighborDiffConfig, this.tableTypeRegistry, this.configurationWriter);
+ assertTrue(this.bgpPeer.containsEqualConfiguration(neighborDiffConfig));
this.bgpPeer.close();
}
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.ProtocolKey;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.policy.types.rev151009.BGP;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
private static final ClusterIdentifier CLUSTER_IDENTIFIER = new ClusterIdentifier("192.168.1.2");
private static final AsNumber AS = new AsNumber(72L);
- private static final IpAddress IPADDRESS = new IpAddress(new Ipv4Address("127.0.0.1"));
- private static final BgpId BGP_ID = new BgpId(IPADDRESS.getIpv4Address());
+ private static final BgpId BGP_ID = new BgpId(NEIGHBOR_ADDRESS.getIpv4Address());
private static final RibId RIB_ID = new RibId("bgp");
private static final List<AddressFamilies> FAMILIES;
private static final List<BgpTableType> TABLE_TYPES;
@Test
public void fromBgpPeer() {
- final Neighbor result = OpenConfigMappingUtil.fromBgpPeer(FAMILIES, TABLE_TYPES, 30, IPADDRESS, true, null, PORT_NUMBER, 30, AS, PeerRole.Ibgp, null, this.tableTypeRegistry);
+ final Neighbor result = OpenConfigMappingUtil.fromBgpPeer(FAMILIES, TABLE_TYPES, 30, NEIGHBOR_ADDRESS, true, null, PORT_NUMBER, 30, AS, PeerRole.Ibgp, null, this.tableTypeRegistry);
final List<AfiSafi> afisafis = new ArrayList<>();
afisafis.add(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
.addAugmentation(AfiSafi1.class, new AfiSafi1Builder().setReceive(true).setSendMax(Shorts.checkedCast(ALL_PATHS)).build()).build());
final Neighbor expected = new NeighborBuilder()
.setAfiSafis(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder().setAfiSafi(afisafis).build())
.setConfig(new ConfigBuilder().setPeerAs(AS).setPeerType(PeerType.INTERNAL).setRouteFlapDamping(false).setSendCommunity(CommunityType.NONE).build())
- .setNeighborAddress(IPADDRESS)
+ .setNeighborAddress(NEIGHBOR_ADDRESS)
.setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp
.neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(false).build()).build())
.setTimers(new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group
final Neighbor result = OpenConfigMappingUtil.fromApplicationPeer(app, BGP_ID);
final Neighbor expected = new NeighborBuilder().setConfig(new ConfigBuilder().setDescription(app.getValue())
.addAugmentation(Config2.class, new Config2Builder().setPeerGroup(OpenConfigMappingUtil.APPLICATION_PEER_GROUP_NAME).build()).build())
- .setNeighborAddress(IPADDRESS).build();
+ .setNeighborAddress(NEIGHBOR_ADDRESS).build();
assertEquals(expected, result);
}
}
\ No newline at end of file
package org.opendaylight.protocol.bgp.rib.impl.stats.rib.impl;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import java.util.concurrent.atomic.LongAdder;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.config.api.IdentityAttributeRef;
import org.opendaylight.controller.config.yang.bgp.rib.impl.BgpRenderState;
import org.opendaylight.controller.config.yang.bgp.rib.impl.LocRibRouteTable;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPRIBState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
private static final ClusterIdentifier CLUSTER_ID = new ClusterIdentifier("192.168.1.2");
private static final AsNumber AS = new AsNumber(0x10L);
private static final ZeroBasedCounter32 COUTER = new ZeroBasedCounter32(0L);
+ private static final ZeroBasedCounter32 COUTER_ONE_ROUTE = new ZeroBasedCounter32(1L);
+ private final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ @Mock
+ private BGPRIBState bgpGlobalState;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
@Test
public void getBgpRenderState() throws Exception {
- final BGPRenderStatsImpl render = new BGPRenderStatsImpl(BGP_ID, RIB_ID, AS, CLUSTER_ID);
+ final BGPRenderStatsImpl render = new BGPRenderStatsImpl(BGP_ID, RIB_ID, AS, CLUSTER_ID, this.bgpGlobalState,
+ Collections.singleton(this.tk));
final BgpRenderState renderStateExpected = new BgpRenderState();
renderStateExpected.setRibId(RIB_ID);
renderStateExpected.setLocalAs(AS);
renderStateExpected.setConfiguredPeerCount(COUTER);
renderStateExpected.setConnectedPeerCount(COUTER);
- final List<LocRibRouteTable> locRibRouteTableList = new ArrayList<>();
+ final LocRibRouteTable locRibTable = new LocRibRouteTable();
+ locRibTable.setAfi(new IdentityAttributeRef(Ipv4AddressFamily.QNAME.toString()));
+ locRibTable.setSafi(new IdentityAttributeRef(UnicastSubsequentAddressFamily.QNAME.toString()));
+ locRibTable.setRoutesCount(COUTER);
+ final List<LocRibRouteTable> locRibRouteTableList = Collections.singletonList(locRibTable);
renderStateExpected.setLocRibRouteTable(locRibRouteTableList);
renderStateExpected.setLocRibRoutesCount(COUTER);
+ doReturn(0L).when(this.bgpGlobalState).getPathCount(eq(this.tk));
assertEquals(renderStateExpected, render.getBgpRenderState());
- LongAdder counter = render.getLocRibRouteCounter().init(new TablesKey(Ipv4AddressFamily.class,
- UnicastSubsequentAddressFamily.class));
- counter.increment();
- assertEquals(1L, counter.longValue());
- counter = render.getConfiguredPeerCounter();
- counter.increment();
- assertEquals(1L, counter.longValue());
- counter = render.getConnectedPeerCounter();
- counter.increment();
- assertEquals(1L, counter.longValue());
+ doReturn(1L).when(this.bgpGlobalState).getPathCount(eq(this.tk));
+ locRibTable.setRoutesCount(COUTER_ONE_ROUTE);
+ renderStateExpected.setLocRibRoutesCount(COUTER_ONE_ROUTE);
+ assertEquals(renderStateExpected, render.getBgpRenderState());
+ render.getConfiguredPeerCounter().increment();
+ assertEquals(1L, render.getConfiguredPeerCounter().longValue());
+ render.getConnectedPeerCounter().increment();
+ assertEquals(1L, render.getConnectedPeerCounter().longValue());
}
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.spi.state;
+
+/**
+ * BGP Peer Messages Operational State
+ */
+public interface BGPPeerMessagesState {
+ /**
+ * Update Messages Sent count
+ *
+ * @return count
+ */
+ long getUpdateMessagesSentCount();
+
+ /**
+ * Notification Messages Sent count
+ *
+ * @return count
+ */
+ long getNotificationMessagesSentCount();
+
+ /**
+ * Update Messages Received count
+ *
+ * @return count
+ */
+ long getUpdateMessagesReceivedCount();
+
+ /**
+ * Notification Update Messages Received count
+ *
+ * @return count
+ */
+ long getNotificationMessagesReceivedCount();
+}
*/
@Nullable BGPSessionState getBGPSessionState();
+ /**
+ * BGP Message Operational State
+ * @return BGPPeerMessagesState
+ */
+ @Nullable BGPPeerMessagesState getBGPPeerMessagesState();
+
/**
* BGP Operation Timers State
* @return BGPTimersState
* @return true if supported
*/
boolean isRouterRefreshCapabilitySupported();
-
- /**
- * Update Messages Sent count
- *
- * @return count
- */
- long getUpdateMessagesSentCount();
-
- /**
- * Notification Messages Sent count
- *
- * @return count
- */
- long getNotificationMessagesSentCount();
-
- /**
- * Update Messages Received count
- *
- * @return count
- */
- long getUpdateMessagesReceivedCount();
-
- /**
- * Notification Update Messages Received count
- *
- * @return count
- */
- long getNotificationMessagesReceivedCount();
}
package org.opendaylight.protocol.bgp.testtool;
import java.util.List;
+import java.util.concurrent.atomic.LongAdder;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
private final int nPrefixes;
private final List<String> extCom;
private final boolean multiPathSupport;
- private int messageCounter = 0;
+ private LongAdder messageCounter = new LongAdder();
TestingListener(final int nPrefixes, final List<String> extCom, final boolean multiPathSupport) {
this.nPrefixes = nPrefixes;
@Override
public void onMessage(final BGPSession session, final Notification message) {
if (message instanceof Update) {
- messageCounter++;
+ this.messageCounter.increment();
}
LOG.debug("Message received: {}", message.toString());
}
}
void printCount(final String localAddress) {
- LOG.info("Peer {} received {} update messages.", localAddress, messageCounter);
+ LOG.info("Peer {} received {} update messages.", localAddress, this.messageCounter.longValue());
}
}