BUG-47 : unfinished PCEP migration to generated DTOs.
[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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class MockPCE implements PCEPSessionListener {
23
24         private final List<Message> listMsg = new ArrayList<Message>();
25
26         private PCEPSessionImpl session = null;
27
28         public boolean up = false;
29
30         private static final Logger logger = LoggerFactory.getLogger(MockPCE.class);
31
32         public boolean down = false;
33
34         public MockPCE() {
35         }
36
37         public void sendMessage(final Message msg) {
38                 this.session.handleMessage(msg);
39         }
40
41         public void sendErrorMessage(final PCEPErrors value, final OpenObject open) {
42                 this.sendMessage(Util.createErrorMessage(value, open));
43         }
44
45         public List<Message> getListMsg() {
46                 return this.listMsg;
47         }
48
49         public void addSession(final PCEPSessionImpl l) {
50                 this.session = l;
51         }
52
53         @Override
54         public void onMessage(final PCEPSession session, final Message message) {
55                 this.listMsg.add(message);
56                 logger.debug("Message received: {}", message);
57         }
58
59         @Override
60         public void onSessionUp(final PCEPSession session) {
61                 logger.debug("Session Up");
62                 this.up = true;
63                 this.notifyAll();
64         }
65
66         @Override
67         public void onSessionDown(final PCEPSession session, final Exception e) {
68                 logger.debug("Session Down.", e);
69                 this.down = true;
70                 // this.notifyAll();
71         }
72
73         @Override
74         public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
75                 logger.debug("Session terminated. Cause : {}", cause);
76         }
77 }