2 * Copyright (c) 2014 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
9 package org.opendaylight.protocol.pcep.pcc.mock;
11 import io.netty.channel.Channel;
12 import java.lang.reflect.Constructor;
13 import java.lang.reflect.InvocationTargetException;
14 import java.net.InetSocketAddress;
15 import java.net.UnknownHostException;
16 import java.util.Collections;
17 import java.util.List;
18 import java.util.concurrent.ExecutionException;
19 import org.junit.Test;
20 import org.opendaylight.protocol.pcep.PCEPCapability;
21 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
23 public class PCCMockTest extends PCCMockCommon {
24 private static final String REMOTE_ADDRESS2 = "127.0.2.0";
25 private static final String REMOTE_ADDRESS3 = "127.0.3.0";
26 private static final String REMOTE_ADDRESS4 = "127.0.4.0";
27 private static final String LOCAL_ADDRESS2 = "127.0.0.2";
28 private static final InetSocketAddress SERVER_ADDRESS2 = new InetSocketAddress(REMOTE_ADDRESS2, 4189);
29 private static final InetSocketAddress SERVER_ADDRESS3 = new InetSocketAddress(REMOTE_ADDRESS3, 4189);
30 private static final InetSocketAddress SERVER_ADDRESS4 = new InetSocketAddress(REMOTE_ADDRESS4, 4189);
31 private final String[] mainInput = new String[]{"--local-address", PCCMockCommon.LOCAL_ADDRESS, "--remote-address",
32 PCCMockCommon.REMOTE_ADDRESS + ":4560", "--pcc", "1", "--lsp", "3", "--log-level", "DEBUG", "-ka", "10", "-d", "40", "--reconnect", "-1",
33 "--redelegation-timeout", "0", "--state-timeout", "-1"};
36 public void testSessionEstablishment() throws Exception {
37 final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
38 final Channel channel = createServer(factory, this.socket);
41 //3 reported LSPs + syc
42 final int numMessages = 4;
43 final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory, PCCMockCommon.LOCAL_ADDRESS);
44 checkSession(sessionListener.getSession(), 40, 10);
49 public void testMockPCCToManyPCE() throws Exception {
50 final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
51 final TestingSessionListenerFactory factory2 = new TestingSessionListenerFactory();
52 final TestingSessionListenerFactory factory3 = new TestingSessionListenerFactory();
53 final Channel channel = createServer(factory, SERVER_ADDRESS2);
54 final Channel channel2 = createServer(factory2, SERVER_ADDRESS3);
55 final Channel channel3 = createServer(factory3, SERVER_ADDRESS4);
57 Main.main(new String[]{"--local-address", PCCMockCommon.LOCAL_ADDRESS, "--remote-address", REMOTE_ADDRESS2 + "," + REMOTE_ADDRESS3 + "," + REMOTE_ADDRESS4, "--pcc", "2"});
61 checkSessionListener(numMessages, channel, factory, PCCMockCommon.LOCAL_ADDRESS);
62 checkSessionListener(numMessages, channel, factory, LOCAL_ADDRESS2);
64 checkSessionListener(numMessages, channel2, factory2, LOCAL_ADDRESS);
65 checkSessionListener(numMessages, channel2, factory2, LOCAL_ADDRESS2);
67 checkSessionListener(numMessages, channel3, factory3, PCCMockCommon.LOCAL_ADDRESS);
68 checkSessionListener(numMessages, channel3, factory3, LOCAL_ADDRESS2);
71 @Test(expected = UnsupportedOperationException.class)
72 public void testPrivateConstructor() throws Throwable {
73 final Constructor<MsgBuilderUtil> c = MsgBuilderUtil.class.getDeclaredConstructor();
74 c.setAccessible(true);
77 } catch (final InvocationTargetException e) {
83 protected List<PCEPCapability> getCapabilities() {
84 return Collections.emptyList();
88 protected int getPort() {