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 org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
12 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
13 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
14 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
17 import org.opendaylight.yangtools.yang.binding.Notification;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Testing BGP Listener.
24 final class TestingListener implements BGPSessionListener {
25 private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
26 private final int nPrefixes;
27 private final List<String> extCom;
28 private final boolean multiPathSupport;
29 private int messageCounter = 0;
31 TestingListener(final int nPrefixes, final List<String> extCom, final boolean multiPathSupport) {
32 this.nPrefixes = nPrefixes;
34 this.multiPathSupport = multiPathSupport;
38 public void markUptodate(final TablesKey tablesKey) {
39 LOG.debug("Table marked as up-to-date {}", tablesKey);
43 public void onSessionUp(final BGPSession session) {
44 LOG.info("Client Listener: Session Up.");
45 if (this.nPrefixes > 0) {
46 PrefixesBuilder.AdvertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nPrefixes, this.extCom, this.multiPathSupport);
51 public void onSessionDown(final BGPSession session, final Exception e) {
52 LOG.info("Client Listener: Connection lost.");
55 } catch (Exception ie) {
56 LOG.warn("Error closing session", ie);
61 public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
62 LOG.info("Client Listener: Connection lost: {}.", cause);
66 public void onMessage(final BGPSession session, final Notification message) {
67 if (message instanceof Update) {
70 LOG.debug("Message received: {}", message.toString());
74 public void releaseConnection() {
75 LOG.info("Client Listener: Connection released.");
78 void printCount(final String localAddress) {
79 LOG.info("Peer {} received {} update messages.", localAddress, messageCounter);