2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.impl;
10 import java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.protocol.pcep.PCEPErrors;
14 import org.opendaylight.protocol.pcep.PCEPMessage;
15 import org.opendaylight.protocol.pcep.PCEPSession;
16 import org.opendaylight.protocol.pcep.PCEPSessionListener;
17 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
18 import org.opendaylight.protocol.pcep.message.PCEPErrorMessage;
19 import org.opendaylight.protocol.pcep.object.PCEPErrorObject;
20 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class MockPCE implements PCEPSessionListener {
26 private final List<PCEPMessage> listMsg = new ArrayList<PCEPMessage>();
28 private PCEPSessionImpl session = null;
30 public boolean up = false;
32 private static final Logger logger = LoggerFactory.getLogger(MockPCE.class);
34 public boolean down = false;
39 public void sendMessage(final PCEPMessage msg) {
40 this.session.handleMessage(msg);
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>();
47 this.sendMessage(new PCEPErrorMessage(open, errors, null));
50 public List<PCEPMessage> getListMsg() {
54 public void addSession(final PCEPSessionImpl l) {
59 public void onMessage(final PCEPSession session, final PCEPMessage message) {
60 this.listMsg.add(message);
61 logger.debug("Message received: {}", message);
65 public void onSessionUp(final PCEPSession session) {
66 logger.debug("Session Up");
72 public void onSessionDown(final PCEPSession session, final Exception e) {
73 logger.debug("Session Down.", e);
79 public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
80 logger.debug("Session terminated. Cause : {}", cause);