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.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.util.List;
14 import java.util.concurrent.atomic.LongAdder;
15 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
16 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
17 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
18 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Update;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
21 import org.opendaylight.yangtools.yang.binding.Notification;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Testing BGP Listener.
28 final class TestingListener implements BGPSessionListener {
29 private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
30 private final int nprefixes;
31 private final List<String> extCom;
32 private final boolean multiPathSupport;
33 private final LongAdder messageCounter = new LongAdder();
35 TestingListener(final int nprefixes, final List<String> extCom, final boolean multiPathSupport) {
36 this.nprefixes = nprefixes;
38 this.multiPathSupport = multiPathSupport;
42 public void markUptodate(final TablesKey tablesKey) {
43 LOG.debug("Table marked as up-to-date {}", tablesKey);
47 public void onSessionUp(final BGPSession session) {
48 LOG.info("Client Listener: Session Up.");
49 if (this.nprefixes > 0) {
50 PrefixesBuilder.advertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nprefixes, this.extCom,
51 this.multiPathSupport);
56 @SuppressWarnings("checkstyle:IllegalCatch")
57 public void onSessionDown(final BGPSession session, final Exception exc) {
58 LOG.info("Client Listener: Connection lost.");
61 } catch (Exception ie) {
62 LOG.warn("Error closing session", ie);
67 public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
68 LOG.info("Client Listener: Connection lost: {}.", cause);
72 public void onMessage(final BGPSession session, final Notification message) {
73 if (message instanceof Update) {
74 this.messageCounter.increment();
76 LOG.debug("Message received: {}", message.toString());
80 @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Unrecognised NullableDecl")
81 public ListenableFuture<?> releaseConnection() {
82 LOG.info("Client Listener: Connection released.");
83 return Futures.immediateFuture(null);
86 void printCount(final String localAddress) {
87 LOG.info("Peer {} received {} update messages.", localAddress, this.messageCounter.longValue());