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 java.util.List;
12 import java.util.concurrent.atomic.LongAdder;
13 import org.opendaylight.mdsal.common.api.CommitInfo;
14 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
15 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
16 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
17 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.Update;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
20 import org.opendaylight.yangtools.yang.binding.Notification;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Testing BGP Listener.
27 final class TestingListener implements BGPSessionListener {
28 private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
29 private final int nprefixes;
30 private final List<String> extCom;
31 private final boolean multiPathSupport;
32 private final LongAdder messageCounter = new LongAdder();
34 TestingListener(final int nprefixes, final List<String> extCom, final boolean multiPathSupport) {
35 this.nprefixes = nprefixes;
37 this.multiPathSupport = multiPathSupport;
41 public void markUptodate(final TablesKey tablesKey) {
42 LOG.debug("Table marked as up-to-date {}", tablesKey);
46 public void onSessionUp(final BGPSession session) {
47 LOG.info("Client Listener: Session Up.");
48 if (this.nprefixes > 0) {
49 PrefixesBuilder.advertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nprefixes, this.extCom,
50 this.multiPathSupport);
55 @SuppressWarnings("checkstyle:IllegalCatch")
56 public void onSessionDown(final BGPSession session, final Exception exc) {
57 LOG.info("Client Listener: Connection lost.");
60 } catch (Exception ie) {
61 LOG.warn("Error closing session", ie);
66 public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
67 LOG.info("Client Listener: Connection lost: {}.", cause);
71 public void onMessage(final BGPSession session, final Notification message) {
72 if (message instanceof Update) {
73 this.messageCounter.increment();
75 LOG.debug("Message received: {}", message.toString());
79 public FluentFuture<? extends CommitInfo> releaseConnection() {
80 LOG.info("Client Listener: Connection released.");
81 return CommitInfo.emptyFluentFuture();
84 void printCount(final String localAddress) {
85 LOG.info("Peer {} received {} update messages.", localAddress, this.messageCounter.longValue());