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.testtool;
10 import java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.protocol.concepts.IPv4Address;
14 import org.opendaylight.protocol.concepts.IPv4Prefix;
15 import org.opendaylight.protocol.concepts.Prefix;
16 import org.opendaylight.protocol.pcep.PCEPMessage;
17 import org.opendaylight.protocol.pcep.PCEPSession;
18 import org.opendaylight.protocol.pcep.PCEPSessionListener;
19 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
20 import org.opendaylight.protocol.pcep.message.PCEPXRAddTunnelMessage;
21 import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject;
22 import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
23 import org.opendaylight.protocol.pcep.object.PCEPLspObject;
24 import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
25 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class TestingSessionListener implements PCEPSessionListener {
31 public List<PCEPMessage> messages = new ArrayList<PCEPMessage>();
33 private static final Logger logger = LoggerFactory.getLogger(TestingSessionListener.class);
35 public TestingSessionListener() {
39 public void onMessage(final PCEPSession session, final PCEPMessage message) {
40 logger.debug("Received message: {}", message);
41 this.messages.add(message);
45 public void onSessionUp(final PCEPSession session) {
46 logger.debug("Session up.");
47 final List<ExplicitRouteSubobject> subs = new ArrayList<ExplicitRouteSubobject>();
48 subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 10, 1, 1, 2 }), 32), false));
49 subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 2, 2, 2, 2 }), 32), false));
50 session.sendMessage(new PCEPXRAddTunnelMessage(new PCEPLspObject(23, false, false, false, false), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(new byte[] {
51 1, 1, 1, 1 }), new IPv4Address(new byte[] { 2, 2, 2, 2 })), new PCEPExplicitRouteObject(subs, false)));
55 public void onSessionDown(final PCEPSession session, final Exception e) {
56 logger.debug("Session down with cause : {} or exception: {}", e);
61 public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
62 logger.debug("Session terminated. Cause : {}", cause.toString());