/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.netconf.impl; import static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting; import com.google.common.collect.ImmutableSet; import java.util.Set; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences; import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider; import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.protocol.framework.SessionListenerFactory; import org.opendaylight.protocol.framework.SessionNegotiator; import org.opendaylight.protocol.framework.SessionNegotiatorFactory; import com.google.common.collect.Sets; import io.netty.channel.Channel; import io.netty.util.Timer; import io.netty.util.concurrent.Promise; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory { private static final Set DEFAULT_BASE_CAPABILITIES = ImmutableSet.of( XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0 // FIXME, Chunk framing causes ConcurrentClientsTest to fail, investigate // XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1, // FIXME, EXI causing issues with sal-netconf-connector, investigate // XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0 ); private final Timer timer; private final SessionIdProvider idProvider; private final NetconfOperationProvider netconfOperationProvider; private final long connectionTimeoutMillis; private final DefaultCommitNotificationProducer commitNotificationProducer; private final SessionMonitoringService monitoringService; private static final Logger logger = LoggerFactory.getLogger(NetconfServerSessionNegotiatorFactory.class); // TODO too many params, refactor public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationProvider netconfOperationProvider, SessionIdProvider idProvider, long connectionTimeoutMillis, DefaultCommitNotificationProducer commitNot, SessionMonitoringService monitoringService) { this.timer = timer; this.netconfOperationProvider = netconfOperationProvider; this.idProvider = idProvider; this.connectionTimeoutMillis = connectionTimeoutMillis; this.commitNotificationProducer = commitNot; this.monitoringService = monitoringService; } /** * * @param defunctSessionListenerFactory will not be taken into account as session listener factory can * only be created after snapshot is opened, thus this method constructs * proper session listener factory. * @param channel Underlying channel * @param promise Promise to be notified * @return session negotiator */ @Override public SessionNegotiator getSessionNegotiator(SessionListenerFactory defunctSessionListenerFactory, Channel channel, Promise promise) { long sessionId = idProvider.getNextSessionId(); NetconfOperationServiceSnapshot netconfOperationServiceSnapshot = netconfOperationProvider.openSnapshot( getNetconfSessionIdForReporting(sessionId)); CapabilityProvider capabilityProvider = new CapabilityProviderImpl(netconfOperationServiceSnapshot); NetconfServerSessionPreferences proposal = null; try { proposal = new NetconfServerSessionPreferences( createHelloMessage(sessionId, capabilityProvider), sessionId); } catch (NetconfDocumentedException e) { logger.error("Unable to create hello mesage for session {} with capability provider {}", sessionId,capabilityProvider); throw new IllegalStateException(e); } NetconfServerSessionListenerFactory sessionListenerFactory = new NetconfServerSessionListenerFactory( commitNotificationProducer, monitoringService, netconfOperationServiceSnapshot, capabilityProvider); return new NetconfServerSessionNegotiator(proposal, promise, channel, timer, sessionListenerFactory.getSessionListener(), connectionTimeoutMillis); } private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) throws NetconfDocumentedException { return NetconfHelloMessage.createServerHello(Sets.union(capabilityProvider.getCapabilities(), DEFAULT_BASE_CAPABILITIES), sessionId); } }