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.impl;
11 import java.net.InetSocketAddress;
13 import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences;
14 import org.opendaylight.controller.netconf.util.AbstractNetconfSessionNegotiator;
15 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage;
16 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import com.google.common.base.Optional;
22 import io.netty.channel.Channel;
23 import io.netty.util.Timer;
24 import io.netty.util.concurrent.Promise;
26 public class NetconfServerSessionNegotiator extends
27 AbstractNetconfSessionNegotiator<NetconfServerSessionPreferences, NetconfServerSession, NetconfServerSessionListener> {
29 static final Logger logger = LoggerFactory.getLogger(NetconfServerSessionNegotiator.class);
31 protected NetconfServerSessionNegotiator(NetconfServerSessionPreferences sessionPreferences,
32 Promise<NetconfServerSession> promise, Channel channel, Timer timer, NetconfServerSessionListener sessionListener,
33 long connectionTimeoutMillis) {
34 super(sessionPreferences, promise, channel, timer, sessionListener, connectionTimeoutMillis);
38 protected NetconfServerSession getSession(NetconfServerSessionListener sessionListener, Channel channel, NetconfHelloMessage message) {
39 Optional<NetconfHelloMessageAdditionalHeader> additionalHeader = message.getAdditionalHeader();
41 NetconfHelloMessageAdditionalHeader parsedHeader;
42 if (additionalHeader.isPresent()) {
43 parsedHeader = additionalHeader.get();
45 InetSocketAddress inetSocketAddress = (InetSocketAddress) channel.localAddress();
46 parsedHeader = new NetconfHelloMessageAdditionalHeader("unknown", inetSocketAddress.getHostString(), Integer.toString(inetSocketAddress.getPort()),
50 logger.debug("Additional header from hello parsed as {} from {}", parsedHeader, additionalHeader);
52 return new NetconfServerSession(sessionListener, channel, getSessionPreferences().getSessionId(), parsedHeader);