2 * Copyright (c) 2015 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.bootstrap.Bootstrap;
12 import io.netty.channel.nio.NioEventLoopGroup;
13 import io.netty.channel.socket.SocketChannel;
14 import io.netty.util.concurrent.Future;
15 import io.netty.util.concurrent.Promise;
16 import java.net.InetSocketAddress;
17 import org.opendaylight.protocol.framework.ReconnectStrategy;
18 import org.opendaylight.protocol.framework.SessionListenerFactory;
19 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
20 import org.opendaylight.protocol.pcep.PCEPSessionListener;
21 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
22 import org.opendaylight.protocol.pcep.impl.PCEPHandlerFactory;
23 import org.opendaylight.protocol.pcep.impl.PCEPSessionImpl;
24 import org.opendaylight.protocol.pcep.spi.MessageRegistry;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
27 public final class PCCDispatcher extends PCEPDispatcherImpl {
29 private InetSocketAddress localAddress;
30 private final PCEPHandlerFactory factory;
32 public PCCDispatcher(final MessageRegistry registry,
33 final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
34 super(registry, negotiatorFactory, new NioEventLoopGroup(), new NioEventLoopGroup(), null, null);
35 this.factory = new PCEPHandlerFactory(registry);
39 protected void customizeBootstrap(final Bootstrap b) {
40 super.customizeBootstrap(b);
41 if (this.localAddress != null) {
42 b.localAddress(this.localAddress);
46 public synchronized Future<PCEPSessionImpl> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
47 final ReconnectStrategy strategy, final SessionListenerFactory<PCEPSessionListener> listenerFactory,
48 final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
49 this.localAddress = localAddress;
50 final Future<PCEPSessionImpl> futureClient = super.createClient(remoteAddress, strategy, new PipelineInitializer<PCEPSessionImpl>() {
52 public void initializeChannel(final SocketChannel ch, final Promise<PCEPSessionImpl> promise) {
53 ch.pipeline().addLast(PCCDispatcher.this.factory.getDecoders());
54 ch.pipeline().addLast("negotiator",
55 negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
56 ch.pipeline().addLast(PCCDispatcher.this.factory.getEncoders());
59 this.localAddress = null;