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.util.Collections;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.protocol.pcep.PCEPCapability;
19 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
20 import org.opendaylight.protocol.util.InetSocketAddressUtil;
22 public final class PCCMockTest extends PCCMockCommon {
23 private final String[] mainInput = new String[] {"--local-address", this.localAddress.getHostString(), "--remote-address",
24 InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1", "--lsp", "3", "--log-level", "DEBUG", "-ka", "10", "-d", "40", "--reconnect", "-1",
25 "--redelegation-timeout", "0", "--state-timeout", "-1"};
28 public void testSessionEstablishment() throws Exception {
29 final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
30 final Channel channel = createServer(factory, this.remoteAddress);
33 //3 reported LSPs + syc
34 final int numMessages = 4;
35 final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
36 checkSession(sessionListener.getSession(), 40, 10);
41 public void testMockPCCToManyPCE() throws Exception {
42 final String localAddress2 = "127.0.0.2";
43 final InetSocketAddress serverAddress2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
44 final InetSocketAddress serverAddress3 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
45 final InetSocketAddress serverAddress4 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
47 final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
48 final TestingSessionListenerFactory factory2 = new TestingSessionListenerFactory();
49 final TestingSessionListenerFactory factory3 = new TestingSessionListenerFactory();
50 final Channel channel = createServer(factory, serverAddress2);
51 final Channel channel2 = createServer(factory2, serverAddress3);
52 final Channel channel3 = createServer(factory3, serverAddress4);
54 Main.main(new String[] {"--local-address", this.localAddress.getHostString(), "--remote-address",
55 InetSocketAddressUtil.toHostAndPort(serverAddress2).toString() + "," +
56 InetSocketAddressUtil.toHostAndPort(serverAddress3).toString() + "," +
57 InetSocketAddressUtil.toHostAndPort(serverAddress4).toString(),
62 checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
63 checkSessionListener(numMessages, channel, factory, localAddress2);
65 checkSessionListener(numMessages, channel2, factory2, this.localAddress.getHostString());
66 checkSessionListener(numMessages, channel2, factory2, localAddress2);
68 checkSessionListener(numMessages, channel3, factory3, this.localAddress.getHostString());
69 checkSessionListener(numMessages, channel3, factory3, localAddress2);
72 @Test(expected = UnsupportedOperationException.class)
73 public void testPrivateConstructor() throws Throwable {
74 final Constructor<MsgBuilderUtil> c = MsgBuilderUtil.class.getDeclaredConstructor();
75 c.setAccessible(true);
78 } catch (final InvocationTargetException e) {
84 protected List<PCEPCapability> getCapabilities() {
85 return Collections.emptyList();