7f5f7f2e60bd72c3464533fc63ced76845900e25
[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.concurrent.GlobalEventExecutor;
11
12 import java.io.IOException;
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.framework.SessionPreferences;
19 import org.opendaylight.protocol.pcep.PCEPConnection;
20 import org.opendaylight.protocol.pcep.PCEPSessionListener;
21 import org.opendaylight.protocol.pcep.PCEPSessionPreferences;
22 import org.opendaylight.protocol.pcep.PCEPSessionProposal;
23 import org.opendaylight.protocol.pcep.PCEPSessionProposalChecker;
24 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
25 import org.opendaylight.protocol.pcep.PCEPTlv;
26 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
27 import org.opendaylight.protocol.pcep.impl.PCEPMessageFactory;
28 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
29 import org.opendaylight.protocol.pcep.tlv.NodeIdentifierTlv;
30
31 import com.google.common.collect.Lists;
32
33 public class PCCMock {
34
35         public static void main(final String[] args) throws IOException, InterruptedException {
36                 final List<PCEPTlv> tlvs = Lists.newArrayList();
37                 tlvs.add(new NodeIdentifierTlv(new byte[] { (byte) 127, (byte) 2, (byte) 3, (byte) 7 }));
38                 final PCEPSessionPreferences prop = new PCEPSessionPreferences(new PCEPOpenObject(30, 120, 0, tlvs));
39                 final DispatcherImpl di = new DispatcherImpl(new PCEPMessageFactory());
40                 final PCEPDispatcherImpl d = new PCEPDispatcherImpl(di, new PCEPSessionProposalFactory() {
41
42                         @Override
43                         public PCEPSessionProposal getSessionProposal(final InetSocketAddress address, final int sessionId) {
44                                 return new PCEPSessionProposal() {
45
46                                         @Override
47                                         public PCEPSessionPreferences getProposal() {
48                                                 return prop;
49                                         }
50                                 };
51                         }
52                 });
53
54                 try {
55
56                         final PCEPSessionProposalChecker check = new PCEPSessionProposalChecker() {
57                                 @Override
58                                 public Boolean checkSessionCharacteristics(final SessionPreferences openObj) {
59                                         return true;
60                                 }
61
62                                 @Override
63                                 public PCEPSessionPreferences getNewProposal(final SessionPreferences open) {
64                                         return new PCEPSessionPreferences(new PCEPOpenObject(30, 120, 0, null));
65                                 }
66                         };
67
68                         d.createClient(new PCEPConnection() {
69                                 @Override
70                                 public InetSocketAddress getPeerAddress() {
71                                         return new InetSocketAddress("127.0.0.3", 12345);
72                                 }
73
74                                 @Override
75                                 public PCEPSessionProposalChecker getProposalChecker() {
76                                         return check;
77                                 }
78
79                                 @Override
80                                 public PCEPSessionPreferences getProposal() {
81                                         return prop;
82                                 }
83
84                                 @Override
85                                 public PCEPSessionListener getListener() {
86                                         return new SimpleSessionListener();
87                                 }
88                         }, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 2000));
89                         // Thread.sleep(5000);
90                         // final List<CompositeRequestObject> cro = new ArrayList<CompositeRequestObject>();
91                         // cro.add(new CompositeRequestObject(new PCEPRequestParameterObject(false, true, true, true, true, (short)
92                         // 4, 123, false, false),
93                         // new PCEPEndPointsObject<IPv4Address>(new IPv4Address(InetAddress.getByName("10.0.0.3")), new
94                         // IPv4Address(InetAddress.getByName("10.0.0.5")))));
95                         // for (int i = 0; i < 3; i++) {
96                         // Thread.sleep(1000);
97                         // session.sendMessage(new PCEPRequestMessage(cro));
98                         // }
99                         // Thread.sleep(5000);
100                         // Thread.sleep(1000);
101
102                 } finally {
103                         // di.stop();
104                 }
105         }
106 }