92f3d6138ee4f155460a1b45c0c37932e10fad06
[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 java.util.List;
11 import java.util.Set;
12
13 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
14 import org.opendaylight.protocol.bgp.parser.BGPSession;
15 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
16 import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
17 import org.opendaylight.yangtools.yang.binding.Notification;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import com.google.common.collect.Lists;
22
23 /**
24  * Listener for the BGP Speaker.
25  */
26 public class SpeakerSessionListener implements BGPSessionListener {
27
28         public List<Notification> messages = Lists.newArrayList();
29
30         public boolean up = false;
31
32         public Set<BGPTableType> types;
33
34         private static final Logger logger = LoggerFactory.getLogger(SpeakerSessionListener.class);
35
36         public SpeakerSessionListener() {
37         }
38
39         @Override
40         public void onMessage(final BGPSession session, final Notification message) {
41                 logger.debug("Received message: " + message.getClass() + " " + message);
42                 this.messages.add(message);
43         }
44
45         @Override
46         public synchronized void onSessionUp(final BGPSession session) {
47                 logger.debug("Session up.");
48                 this.up = true;
49                 this.types = session.getAdvertisedTableTypes();
50                 this.notifyAll();
51         }
52
53         @Override
54         public void onSessionDown(final BGPSession session, final Exception e) {
55                 logger.debug("Session down.");
56                 this.up = false;
57         }
58
59         @Override
60         public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
61                 logger.debug("Session terminated. Cause : " + cause.toString());
62                 this.up = false;
63         }
64 }