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 io.netty.util.concurrent.GlobalEventExecutor;
12 import java.io.IOException;
13 import java.net.InetSocketAddress;
14 import java.util.List;
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;
31 import com.google.common.collect.Lists;
33 public class PCCMock {
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() {
43 public PCEPSessionProposal getSessionProposal(final InetSocketAddress address, final int sessionId) {
44 return new PCEPSessionProposal() {
47 public PCEPSessionPreferences getProposal() {
56 final PCEPSessionProposalChecker check = new PCEPSessionProposalChecker() {
58 public Boolean checkSessionCharacteristics(final SessionPreferences openObj) {
63 public PCEPSessionPreferences getNewProposal(final SessionPreferences open) {
64 return new PCEPSessionPreferences(new PCEPOpenObject(30, 120, 0, null));
68 d.createClient(new PCEPConnection() {
70 public InetSocketAddress getPeerAddress() {
71 return new InetSocketAddress("127.0.0.3", 12345);
75 public PCEPSessionProposalChecker getProposalChecker() {
80 public PCEPSessionPreferences getProposal() {
85 public PCEPSessionListener getListener() {
86 return new SimpleSessionListener();
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));
99 // Thread.sleep(5000);
100 // Thread.sleep(1000);