BUG-2109 : clear BGP session after it was already initialized
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / SimpleSessionListener.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.rib.impl;
9
10 import com.google.common.collect.Lists;
11 import java.util.List;
12 import org.opendaylight.protocol.bgp.rib.impl.spi.ReusableBGPPeer;
13 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
14 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
15 import org.opendaylight.yangtools.yang.binding.Notification;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Listener for the client.
21  */
22 public class SimpleSessionListener implements ReusableBGPPeer {
23
24     private final List<Notification> listMsg = Lists.newArrayList();
25
26     public boolean up = false;
27
28     private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
29
30     public boolean down = false;
31
32     public List<Notification> getListMsg() {
33         return this.listMsg;
34     }
35
36     @Override
37     public void onMessage(final BGPSession session, final Notification message) {
38         this.listMsg.add(message);
39         LOG.debug("Message received: {}", message);
40     }
41
42     @Override
43     public void onSessionUp(final BGPSession session) {
44         LOG.debug("Session Up");
45         this.up = true;
46     }
47
48     @Override
49     public void onSessionDown(final BGPSession session, final Exception e) {
50         LOG.debug("Session Down", e);
51         this.down = true;
52     }
53
54     @Override
55     public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
56         LOG.debug("Session terminated. Cause : {}", cause.toString());
57     }
58
59     @Override
60     public void releaseConnection() {
61         LOG.debug("Releasing connection");
62     }
63
64     @Override
65     public boolean isSessionActive() {
66         return true;
67     }
68 }