BUG-2873 : Remove dependency protocol-framework on BGP
[bgpcep.git] / bgp / testtool / src / main / java / org / opendaylight / protocol / bgp / testtool / TestingListener.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.testtool;
9
10 import org.opendaylight.protocol.bgp.rib.impl.spi.ReusableBGPPeer;
11 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
12 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
14 import org.opendaylight.yangtools.yang.binding.Notification;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Testing BGP Listener.
20  */
21 public class TestingListener implements ReusableBGPPeer {
22     private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
23
24     @Override
25     public void onMessage(final BGPSession session, final Notification message) {
26         LOG.info("Client Listener: message received: {}", message.toString());
27     }
28
29     @Override
30     public void onSessionUp(final BGPSession session) {
31         LOG.info("Client Listener: Session Up.");
32     }
33
34     @Override
35     public void onSessionDown(final BGPSession session, final Exception e) {
36         LOG.info("Client Listener: Connection lost.");
37         try {
38             session.close();
39         } catch (Exception ie) {
40             LOG.warn("Error closing session", ie);
41         }
42     }
43
44     @Override
45     public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
46         LOG.info("Client Listener: Connection lost: {}.", cause);
47     }
48
49     @Override
50     public void releaseConnection() {
51         LOG.info("Client Listener: Connection released.");
52     }
53
54     @Override
55     public boolean isSessionActive() {
56         return true;
57     }
58
59     @Override
60     public void markUptodate(final TablesKey tablesKey) {
61         LOG.debug("Table marked as up-to-date {}", tablesKey);
62     }
63 }