BUG-2109 : clear BGP session after it was already initialized
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / SpeakerSessionListener.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 java.util.Set;
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.multiprotocol.rev130919.BgpTableType;
17 import org.opendaylight.yangtools.yang.binding.Notification;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * Listener for the BGP Speaker.
23  */
24 public class SpeakerSessionListener implements BGPSessionListener {
25
26     public List<Notification> messages = Lists.newArrayList();
27
28     public boolean up = false;
29
30     public Set<BgpTableType> types;
31
32     private static final Logger LOG = LoggerFactory.getLogger(SpeakerSessionListener.class);
33
34     public SpeakerSessionListener() {
35     }
36
37     @Override
38     public void onMessage(final BGPSession session, final Notification message) {
39         LOG.debug("Received message: {} {}", message.getClass(), message);
40         this.messages.add(message);
41     }
42
43     @Override
44     public synchronized void onSessionUp(final BGPSession session) {
45         LOG.debug("Session up.");
46         this.up = true;
47         this.types = session.getAdvertisedTableTypes();
48         this.notifyAll();
49     }
50
51     @Override
52     public void onSessionDown(final BGPSession session, final Exception e) {
53         LOG.debug("Session down.");
54         this.up = false;
55     }
56
57     @Override
58     public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
59         LOG.debug("Session terminated. Cause : {}", cause.toString());
60         this.up = false;
61     }
62
63     @Override
64     public boolean isSessionActive() {
65         return true;
66     }
67 }