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 static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting;
15 import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences;
16 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
17 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
18 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
19 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
20 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage;
21 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
22 import org.opendaylight.protocol.framework.SessionListenerFactory;
23 import org.opendaylight.protocol.framework.SessionNegotiator;
24 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
26 import com.google.common.collect.Sets;
28 import io.netty.channel.Channel;
29 import io.netty.util.Timer;
30 import io.netty.util.concurrent.Promise;
32 public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfHelloMessage, NetconfServerSession, NetconfServerSessionListener> {
34 private static final Set<String> DEFAULT_CAPABILITIES = Sets.newHashSet(
35 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0,
36 XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0);
38 private final Timer timer;
40 private final SessionIdProvider idProvider;
41 private final NetconfOperationProvider netconfOperationProvider;
42 private final long connectionTimeoutMillis;
43 private final DefaultCommitNotificationProducer commitNotificationProducer;
44 private final SessionMonitoringService monitoringService;
46 public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationProvider netconfOperationProvider,
47 SessionIdProvider idProvider, long connectionTimeoutMillis,
48 DefaultCommitNotificationProducer commitNot, SessionMonitoringService monitoringService) {
50 this.netconfOperationProvider = netconfOperationProvider;
51 this.idProvider = idProvider;
52 this.connectionTimeoutMillis = connectionTimeoutMillis;
53 this.commitNotificationProducer = commitNot;
54 this.monitoringService = monitoringService;
59 * @param defunctSessionListenerFactory will not be taken into account as session listener factory can
60 * only be created after snapshot is opened, thus this method constructs
61 * proper session listener factory.
62 * @param channel Underlying channel
63 * @param promise Promise to be notified
64 * @return session negotiator
67 public SessionNegotiator<NetconfServerSession> getSessionNegotiator(SessionListenerFactory<NetconfServerSessionListener> defunctSessionListenerFactory,
68 Channel channel, Promise<NetconfServerSession> promise) {
69 long sessionId = idProvider.getNextSessionId();
70 NetconfOperationServiceSnapshot netconfOperationServiceSnapshot = netconfOperationProvider.openSnapshot(
71 getNetconfSessionIdForReporting(sessionId));
72 CapabilityProvider capabilityProvider = new CapabilityProviderImpl(netconfOperationServiceSnapshot);
74 NetconfServerSessionPreferences proposal = new NetconfServerSessionPreferences(
75 createHelloMessage(sessionId, capabilityProvider), sessionId);
77 NetconfServerSessionListenerFactory sessionListenerFactory = new NetconfServerSessionListenerFactory(
78 commitNotificationProducer, monitoringService,
79 netconfOperationServiceSnapshot, capabilityProvider);
81 return new NetconfServerSessionNegotiator(proposal, promise, channel, timer,
82 sessionListenerFactory.getSessionListener(), connectionTimeoutMillis);
85 private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) {
86 return NetconfHelloMessage.createServerHello(Sets.union(capabilityProvider.getCapabilities(), DEFAULT_CAPABILITIES), sessionId);