c259eee9cf19e066c0dbe56ef1485a39782e67b9
[bgpcep.git] / pcep / testtool / src / main / java / org / opendaylight / protocol / pcep / testtool / TestingSessionListener.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.testtool;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
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.framework.TerminationReason;
17 import org.opendaylight.protocol.pcep.PCEPMessage;
18 import org.opendaylight.protocol.pcep.PCEPSession;
19 import org.opendaylight.protocol.pcep.PCEPSessionListener;
20 import org.opendaylight.protocol.pcep.message.PCEPXRAddTunnelMessage;
21 import org.opendaylight.protocol.pcep.object.PCEPCloseObject;
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;
30
31 public class TestingSessionListener extends PCEPSessionListener {
32
33         public List<PCEPMessage> messages = new ArrayList<PCEPMessage>();
34
35         private static final Logger logger = LoggerFactory.getLogger(TestingSessionListener.class);
36
37         public TestingSessionListener() {
38         }
39
40         @Override
41         public void onMessage(final PCEPSession session, final PCEPMessage message) {
42                 logger.debug("Received message: {}", message);
43                 this.messages.add(message);
44         }
45
46         @Override
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)));
54         }
55
56         @Override
57         public void onSessionDown(final PCEPSession session, final PCEPCloseObject reason, final Exception e) {
58                 logger.debug("Session down because: {}", reason);
59         }
60
61         @Override
62         public void onSessionTerminated(final PCEPSession session, final TerminationReason cause) {
63                 logger.debug("Session terminated. Cause : {}", cause.toString());
64         }
65 }