2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.testtool;
10 import com.google.common.util.concurrent.FluentFuture;
11 import com.google.common.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.List;
14 import java.util.concurrent.atomic.LongAdder;
15 import org.opendaylight.mdsal.common.api.CommitInfo;
16 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
17 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
18 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
19 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
22 import org.opendaylight.yangtools.yang.binding.Notification;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Testing BGP Listener.
29 final class TestingListener implements BGPSessionListener {
30 private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
31 private final int nprefixes;
32 private final List<String> extCom;
33 private final boolean multiPathSupport;
34 private final LongAdder messageCounter = new LongAdder();
36 TestingListener(final int nprefixes, final List<String> extCom, final boolean multiPathSupport) {
37 this.nprefixes = nprefixes;
39 this.multiPathSupport = multiPathSupport;
43 public void markUptodate(final TablesKey tablesKey) {
44 LOG.debug("Table marked as up-to-date {}", tablesKey);
48 public void onSessionUp(final BGPSession session) {
49 LOG.info("Client Listener: Session Up.");
50 if (this.nprefixes > 0) {
51 PrefixesBuilder.advertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nprefixes, this.extCom,
52 this.multiPathSupport);
57 @SuppressWarnings("checkstyle:IllegalCatch")
58 public void onSessionDown(final BGPSession session, final Exception exc) {
59 LOG.info("Client Listener: Connection lost.");
62 } catch (Exception ie) {
63 LOG.warn("Error closing session", ie);
68 public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
69 LOG.info("Client Listener: Connection lost: {}.", cause);
73 public void onMessage(final BGPSession session, final Notification message) {
74 if (message instanceof Update) {
75 this.messageCounter.increment();
77 LOG.debug("Message received: {}", message.toString());
81 public FluentFuture<? extends CommitInfo> releaseConnection() {
82 LOG.info("Client Listener: Connection released.");
83 return CommitInfo.emptyFluentFuture();
87 public ListenableFuture<?> restartGracefully(final long selectionDeferralTimerSeconds) {
88 return Futures.immediateFailedFuture(
89 new UnsupportedOperationException("Testtool doesn't support graceful restart"));
92 void printCount(final String localAddress) {
93 LOG.info("Peer {} received {} update messages.", localAddress, this.messageCounter.longValue());