import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
+import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import com.google.common.net.InetAddresses;
import io.netty.util.concurrent.GlobalEventExecutor;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.List;
import java.util.concurrent.ExecutionException;
import org.opendaylight.protocol.framework.NeverReconnectStrategy;
import org.opendaylight.protocol.framework.SessionListenerFactory;
public static void main(final String[] args) throws InterruptedException, ExecutionException, UnknownHostException {
InetAddress localAddress = InetAddress.getByName("127.0.0.1");
- InetAddress remoteAddress = InetAddress.getByName("127.0.0.1");
+ List<InetAddress> remoteAddress = Lists.newArrayList(InetAddress.getByName("127.0.0.1"));
int pccCount = 1;
int lsps = 1;
boolean pcError = false;
if (args[argIdx].equals("--local-address")) {
localAddress = InetAddress.getByName(args[++argIdx]);
} else if (args[argIdx].equals("--remote-address")) {
- remoteAddress = InetAddress.getByName(args[++argIdx]);
+ remoteAddress = parseAddresses(args[++argIdx]);
} else if (args[argIdx].equals("--pcc")) {
pccCount = Integer.valueOf(args[++argIdx]);
} else if (args[argIdx].equals("--lsp")) {
}
public static void createPCCs(final int lspsPerPcc, final boolean pcerr, final int pccCount,
- final InetAddress localAddress, final InetAddress remoteAddress) throws InterruptedException, ExecutionException {
+ final InetAddress localAddress, final List<InetAddress> remoteAddress) throws InterruptedException, ExecutionException {
final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf = new DefaultPCEPSessionNegotiatorFactory(
new OpenBuilder().setKeepalive(DEFAULT_KEEP_ALIVE).setDeadTimer(DEFAULT_DEAD_TIMER).setSessionId((short) 0).build(), 0);
final StatefulActivator activator07 = new StatefulActivator();
- final PCCActivator activator = new PCCActivator();
activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
- activator.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
final PCCMock<Message, PCEPSessionImpl, PCEPSessionListener> pcc = new PCCMock<>(snf, new PCEPHandlerFactory(
ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry()));
- final InetAddress pceAddress = remoteAddress;
- InetAddress currentAddress = localAddress;
- int i = 0;
- while (i < pccCount) {
- final InetAddress pccAddress = currentAddress;
- pcc.createClient(new InetSocketAddress(pccAddress, 0), new InetSocketAddress(pceAddress, DEFAULT_PORT),
- new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_STRATEGY_TIMEOUT),
- new SessionListenerFactory<PCEPSessionListener>() {
+ for (final InetAddress pceAddress : remoteAddress) {
+ InetAddress currentAddress = localAddress;
+ int i = 0;
+ while (i < pccCount) {
+ final InetAddress pccAddress = currentAddress;
+ pcc.createClient(new InetSocketAddress(pccAddress, 0), new InetSocketAddress(pceAddress, DEFAULT_PORT),
+ new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_STRATEGY_TIMEOUT),
+ new SessionListenerFactory<PCEPSessionListener>() {
- @Override
- public PCEPSessionListener getSessionListener() {
- return new SimpleSessionListener(lspsPerPcc, pcerr, pccAddress);
- }
- }).get();
- i++;
- currentAddress = InetAddresses.increment(currentAddress);
+ @Override
+ public PCEPSessionListener getSessionListener() {
+ return new SimpleSessionListener(lspsPerPcc, pcerr, pccAddress);
+ }
+ }).get();
+ i++;
+ currentAddress = InetAddresses.increment(currentAddress);
+ }
}
}
});
}
+ private static List<InetAddress> parseAddresses(final String address) {
+ return Lists.transform(Arrays.asList(address.split(",")), new Function<String, InetAddress>() {
+ @Override
+ public InetAddress apply(String input) {
+ try {
+ return InetAddress.getByName(input);
+ } catch (UnknownHostException e) {
+ throw new RuntimeException("Not an IP address: " + input, e);
+ }
+ }
+ });
+ }
+
}
}
}
+ @Test
+ public void testMockPCCToManyPCE() {
+ try {
+ org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.4.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
+ org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.2.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
+ org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.3.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
+ Main.main(new String[] {"--local-address", "127.0.0.1", "--remote-address", "127.0.4.0,127.0.2.0,127.0.3.0"});
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
@Test
public void testSrpObjectParser() throws PCEPDeserializerException {
final byte[] bytes = {