30b7cbd3dfd07152fce227adcdbe1b976dbe4173
[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 java.util.List;
11 import java.util.Set;
12
13 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
14 import org.opendaylight.protocol.bgp.parser.BGPError;
15 import org.opendaylight.protocol.bgp.parser.BGPMessage;
16 import org.opendaylight.protocol.bgp.parser.BGPSession;
17 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
18 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 import com.google.common.collect.Lists;
23
24 /**
25  * Listener for the client.
26  */
27 public class SimpleSessionListener extends BGPSessionListener {
28
29         private final List<BGPMessage> listMsg = Lists.newArrayList();
30
31         private BGPSessionImpl session = null;
32
33         public boolean up = false;
34
35         private static final Logger logger = LoggerFactory.getLogger(SimpleSessionListener.class);
36
37         public boolean down = false;
38
39         public SimpleSessionListener() {
40         }
41
42         public void sendMessage(final BGPMessage msg) {
43                 this.session.handleMessage(msg);
44         }
45
46         public List<BGPMessage> getListMsg() {
47                 return this.listMsg;
48         }
49
50         public void addSession(final BGPSessionImpl l) {
51                 this.session = l;
52         }
53
54         @Override
55         public void onMessage(final BGPMessage message) {
56                 this.listMsg.add(message);
57                 logger.debug("Message received:" + message);
58         }
59
60         @Override
61         public void onSessionUp(final Set<BGPTableType> remote) {
62                 logger.debug("Session Up");
63                 this.up = true;
64                 this.notifyAll();
65         }
66
67         @Override
68         public void onSessionDown(final BGPSession session, final Exception e) {
69                 logger.debug("Session Down", e);
70                 this.down = true;
71         }
72
73         @Override
74         public void onSessionTerminated(final BGPError cause) {
75                 logger.debug("Session terminated. Cause : " + cause.toString());
76         }
77 }