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 java.util.List;
11 import java.util.concurrent.atomic.LongAdder;
12 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
13 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
14 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
15 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
18 import org.opendaylight.yangtools.yang.binding.Notification;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Testing BGP Listener.
25 final class TestingListener implements BGPSessionListener {
26 private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
27 private final int nPrefixes;
28 private final List<String> extCom;
29 private final boolean multiPathSupport;
30 private LongAdder messageCounter = new LongAdder();
32 TestingListener(final int nPrefixes, final List<String> extCom, final boolean multiPathSupport) {
33 this.nPrefixes = nPrefixes;
35 this.multiPathSupport = multiPathSupport;
39 public void markUptodate(final TablesKey tablesKey) {
40 LOG.debug("Table marked as up-to-date {}", tablesKey);
44 public void onSessionUp(final BGPSession session) {
45 LOG.info("Client Listener: Session Up.");
46 if (this.nPrefixes > 0) {
47 PrefixesBuilder.advertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nPrefixes, this.extCom, this.multiPathSupport);
52 public void onSessionDown(final BGPSession session, final Exception e) {
53 LOG.info("Client Listener: Connection lost.");
56 } catch (Exception ie) {
57 LOG.warn("Error closing session", ie);
62 public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
63 LOG.info("Client Listener: Connection lost: {}.", cause);
67 public void onMessage(final BGPSession session, final Notification message) {
68 if (message instanceof Update) {
69 this.messageCounter.increment();
71 LOG.debug("Message received: {}", message.toString());
75 public void releaseConnection() {
76 LOG.info("Client Listener: Connection released.");
79 void printCount(final String localAddress) {
80 LOG.info("Peer {} received {} update messages.", localAddress, this.messageCounter.longValue());