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