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 java.util.List;
13 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
14 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
15 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
16 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
19 import org.opendaylight.yangtools.yang.binding.Notification;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Testing BGP Listener.
26 final class TestingListener implements BGPSessionListener {
27 private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
28 private final int nPrefixes;
29 private final List<String> extCom;
30 private final boolean multiPathSupport;
31 private int messageCounter = 0;
33 TestingListener(final int nPrefixes, final List<String> extCom, final boolean multiPathSupport) {
34 this.nPrefixes = nPrefixes;
36 this.multiPathSupport = multiPathSupport;
40 public void markUptodate(final TablesKey tablesKey) {
41 LOG.debug("Table marked as up-to-date {}", tablesKey);
45 public void onSessionUp(final BGPSession session) {
46 LOG.info("Client Listener: Session Up.");
47 if (this.nPrefixes > 0) {
48 PrefixesBuilder.advertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nPrefixes, this.extCom, this.multiPathSupport);
53 public void onSessionDown(final BGPSession session, final Exception e) {
54 LOG.info("Client Listener: Connection lost.");
57 } catch (Exception ie) {
58 LOG.warn("Error closing session", ie);
63 public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
64 LOG.info("Client Listener: Connection lost: {}.", cause);
68 public void onMessage(final BGPSession session, final Notification message) {
69 if (message instanceof Update) {
72 LOG.debug("Message received: {}", message.toString());
76 public ListenableFuture<?> releaseConnection() {
77 LOG.info("Client Listener: Connection released.");
78 return Futures.immediateFuture(null);
81 void printCount(final String localAddress) {
82 LOG.info("Peer {} received {} update messages.", localAddress, messageCounter);