BUG-47 : removed PCEPMessage interface, switched to generated Message.
[bgpcep.git] / pcep / impl / src / test / java / org / opendaylight / protocol / pcep / impl / MockPCE.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.pcep.impl;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.opendaylight.protocol.pcep.PCEPErrors;
14 import org.opendaylight.protocol.pcep.PCEPSession;
15 import org.opendaylight.protocol.pcep.PCEPSessionListener;
16 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
17 import org.opendaylight.protocol.pcep.message.PCEPErrorMessage;
18 import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
19 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class MockPCE implements PCEPSessionListener {
25
26         private final List<Message> listMsg = new ArrayList<Message>();
27
28         private PCEPSessionImpl session = null;
29
30         public boolean up = false;
31
32         private static final Logger logger = LoggerFactory.getLogger(MockPCE.class);
33
34         public boolean down = false;
35
36         public MockPCE() {
37         }
38
39         public void sendMessage(final Message msg) {
40                 this.session.handleMessage(msg);
41         }
42
43         public void sendErrorMessage(final PCEPErrors value, final PCEPOpenObject open) {
44                 final PCEPErrorObject error = new PCEPErrorObject(value);
45                 final List<PCEPErrorObject> errors = new ArrayList<PCEPErrorObject>();
46                 errors.add(error);
47                 this.sendMessage(new PCEPErrorMessage(open, errors, null));
48         }
49
50         public List<Message> getListMsg() {
51                 return this.listMsg;
52         }
53
54         public void addSession(final PCEPSessionImpl l) {
55                 this.session = l;
56         }
57
58         @Override
59         public void onMessage(final PCEPSession session, final Message message) {
60                 this.listMsg.add(message);
61                 logger.debug("Message received: {}", message);
62         }
63
64         @Override
65         public void onSessionUp(final PCEPSession session) {
66                 logger.debug("Session Up");
67                 this.up = true;
68                 this.notifyAll();
69         }
70
71         @Override
72         public void onSessionDown(final PCEPSession session, final Exception e) {
73                 logger.debug("Session Down.", e);
74                 this.down = true;
75                 // this.notifyAll();
76         }
77
78         @Override
79         public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
80                 logger.debug("Session terminated. Cause : {}", cause);
81         }
82 }