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.io.IOException;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.protocol.concepts.IPv4Address;
15 import org.opendaylight.protocol.concepts.IPv4Prefix;
16 import org.opendaylight.protocol.concepts.Prefix;
17 import org.opendaylight.protocol.framework.TerminationReason;
18 import org.opendaylight.protocol.pcep.PCEPMessage;
19 import org.opendaylight.protocol.pcep.PCEPSession;
20 import org.opendaylight.protocol.pcep.PCEPSessionListener;
21 import org.opendaylight.protocol.pcep.message.PCEPXRAddTunnelMessage;
22 import org.opendaylight.protocol.pcep.object.PCEPEndPointsObject;
23 import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
24 import org.opendaylight.protocol.pcep.object.PCEPLspObject;
25 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
26 import org.opendaylight.protocol.pcep.subobject.EROIPPrefixSubobject;
27 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class TestingSessionListener extends PCEPSessionListener {
33 public List<PCEPMessage> messages = new ArrayList<PCEPMessage>();
35 private static final Logger logger = LoggerFactory.getLogger(TestingSessionListener.class);
37 public TestingSessionListener() {
41 public void onMessage(final PCEPSession session, final PCEPMessage message) {
42 logger.debug("Received message: {}", message);
43 this.messages.add(message);
47 public void onSessionUp(final PCEPSession session, final PCEPOpenObject local, final PCEPOpenObject remote) {
48 logger.debug("Session up.");
49 final List<ExplicitRouteSubobject> subs = new ArrayList<ExplicitRouteSubobject>();
50 subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 10, 1, 1, 2 }), 32), false));
51 subs.add(new EROIPPrefixSubobject<Prefix<?>>(new IPv4Prefix(new IPv4Address(new byte[] { 2, 2, 2, 2 }), 32), false));
52 session.sendMessage(new PCEPXRAddTunnelMessage(new PCEPLspObject(23, false, false, false, false), new PCEPEndPointsObject<IPv4Address>(new IPv4Address(new byte[] {
53 1, 1, 1, 1 }), new IPv4Address(new byte[] { 2, 2, 2, 2 })), new PCEPExplicitRouteObject(subs, false)));
57 public void onSessionDown(final PCEPSession session, final TerminationReason cause, final Exception e) {
58 logger.debug("Session down with cause : {} or exception: {}", cause, e);
61 } catch (final IOException e1) {
62 logger.debug("Could not close session, because {}", e1.getMessage(), e1);
67 public void onSessionTerminated(final PCEPSession session, final TerminationReason cause) {
68 logger.debug("Session terminated. Cause : {}", cause.toString());