09866808263d4411f752d4b9eaa0ee56b16e3d9b
[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.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;
21
22 /**
23  * Listener for the BGP Speaker.
24  */
25 public class SpeakerSessionListener implements BGPSessionListener {
26
27     public List<Notification> messages = Lists.newArrayList();
28
29     public boolean up = false;
30
31     public Set<BgpTableType> types;
32
33     private static final Logger LOG = LoggerFactory.getLogger(SpeakerSessionListener.class);
34
35     public SpeakerSessionListener() {
36     }
37
38     @Override
39     public void onMessage(final BGPSession session, final Notification message) {
40         LOG.debug("Received message: {} {}", message.getClass(), message);
41         this.messages.add(message);
42     }
43
44     @Override
45     public synchronized void onSessionUp(final BGPSession session) {
46         LOG.debug("Session up.");
47         this.up = true;
48         this.types = session.getAdvertisedTableTypes();
49         this.notifyAll();
50     }
51
52     @Override
53     public void onSessionDown(final BGPSession session, final Exception e) {
54         LOG.debug("Session down.");
55         this.up = false;
56     }
57
58     @Override
59     public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
60         LOG.debug("Session terminated. Cause : {}", cause.toString());
61         this.up = false;
62     }
63
64     @Override
65     public boolean isSessionActive() {
66         return true;
67     }
68
69     @Override
70     public void markUptodate(final TablesKey tablesKey) {
71         LOG.debug("Table marked as up-to-date {}", tablesKey);
72     }
73 }