BUG-58: refactor to take advantage of netty
[bgpcep.git] / pcep / testtool / src / test / java / org / opendaylight / protocol / pcep / testtool / PCCMock.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 io.netty.util.HashedWheelTimer;
11 import io.netty.util.concurrent.GlobalEventExecutor;
12
13 import java.net.InetSocketAddress;
14 import java.util.List;
15
16 import org.opendaylight.protocol.framework.DispatcherImpl;
17 import org.opendaylight.protocol.framework.NeverReconnectStrategy;
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.PCEPTerminationReason;
22 import org.opendaylight.protocol.pcep.PCEPTlv;
23 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
24 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
25 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
26 import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv;
27
28 import com.google.common.collect.Lists;
29
30 public class PCCMock {
31
32         public static void main(final String[] args) throws Exception {
33                 final List<PCEPTlv> tlvs = Lists.newArrayList();
34                 tlvs.add(new NodeIdentifierTlv(new byte[] { (byte) 127, (byte) 2, (byte) 3, (byte) 7 }));
35
36                 final DispatcherImpl di = new DispatcherImpl();
37                 final PCEPDispatcherImpl d = new PCEPDispatcherImpl(di,
38                                 new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), new PCEPOpenObject(30, 120, 0, tlvs), 0));
39
40                 try {
41                         d.createClient(new InetSocketAddress("127.0.0.3", 12345),
42                                         new PCEPSessionListener() {
43
44                                 @Override
45                                 public void onMessage(final PCEPSession session, final PCEPMessage message) {
46                                         // TODO Auto-generated method stub
47
48                                 }
49
50                                 @Override
51                                 public void onSessionUp(final PCEPSession session) {
52                                         // TODO Auto-generated method stub
53
54                                 }
55
56                                 @Override
57                                 public void onSessionDown(final PCEPSession session, final Exception e) {
58                                         // TODO Auto-generated method stub
59
60                                 }
61
62                                 @Override
63                                 public void onSessionTerminated(final PCEPSession session,
64                                                 final PCEPTerminationReason cause) {
65                                         // TODO Auto-generated method stub
66
67                                 }
68                         }, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 2000)).get();
69
70                         // Thread.sleep(5000);
71                         // final List<CompositeRequestObject> cro = new ArrayList<CompositeRequestObject>();
72                         // cro.add(new CompositeRequestObject(new PCEPRequestParameterObject(false, true, true, true, true, (short)
73                         // 4, 123, false, false),
74                         // new PCEPEndPointsObject<IPv4Address>(new IPv4Address(InetAddress.getByName("10.0.0.3")), new
75                         // IPv4Address(InetAddress.getByName("10.0.0.5")))));
76                         // for (int i = 0; i < 3; i++) {
77                         // Thread.sleep(1000);
78                         // session.sendMessage(new PCEPRequestMessage(cro));
79                         // }
80                         // Thread.sleep(5000);
81                         // Thread.sleep(1000);
82                 } finally {
83                         // di.stop();
84                 }
85         }
86 }