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
9 package org.opendaylight.controller.netconf.util;
11 import io.netty.channel.socket.SocketChannel;
12 import io.netty.util.concurrent.Promise;
14 import org.opendaylight.controller.netconf.api.NetconfSession;
15 import org.opendaylight.controller.netconf.util.handler.FramingMechanismHandlerFactory;
16 import org.opendaylight.controller.netconf.util.handler.NetconfEOMAggregator;
17 import org.opendaylight.controller.netconf.util.handler.NetconfHelloMessageToXMLEncoder;
18 import org.opendaylight.controller.netconf.util.handler.NetconfXMLToHelloMessageDecoder;
19 import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
21 public abstract class AbstractChannelInitializer<S extends NetconfSession> {
23 public static final String NETCONF_MESSAGE_DECODER = "netconfMessageDecoder";
24 public static final String NETCONF_MESSAGE_AGGREGATOR = "aggregator";
25 public static final String NETCONF_MESSAGE_ENCODER = "netconfMessageEncoder";
26 public static final String NETCONF_MESSAGE_FRAME_ENCODER = "frameEncoder";
27 public static final String NETCONF_SESSION_NEGOTIATOR = "negotiator";
29 public void initialize(SocketChannel ch, Promise<S> promise) {
30 ch.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator());
31 initializeMessageDecoder(ch);
32 ch.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
33 initializeMessageEncoder(ch);
35 initializeSessionNegotiator(ch, promise);
38 protected void initializeMessageEncoder(SocketChannel ch) {
39 // Special encoding handler for hello message to include additional header if available,
40 // it is thrown away after successful negotiation
41 ch.pipeline().addLast(NETCONF_MESSAGE_ENCODER, new NetconfHelloMessageToXMLEncoder());
44 protected void initializeMessageDecoder(SocketChannel ch) {
45 // Special decoding handler for hello message to parse additional header if available,
46 // it is thrown away after successful negotiation
47 ch.pipeline().addLast(NETCONF_MESSAGE_DECODER, new NetconfXMLToHelloMessageDecoder());
51 * Insert session negotiator into the pipeline. It must be inserted after message decoder
52 * identified by {@link AbstractChannelInitializer#NETCONF_MESSAGE_DECODER}, (or any other custom decoder processor)
54 protected abstract void initializeSessionNegotiator(SocketChannel ch, Promise<S> promise);