X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fimpl%2FNetconfServerSessionNegotiatorFactory.java;h=38df10178b641fb0991ed93833fbdedf728f9263;hb=7a5d09a57cedf0ad1259b72dc918f5925e248683;hp=bd26baa6190e8d3080072df10e66e6c339dbd367;hpb=ec860b9f946515a6a16659b23eb7dec1a8d89624;p=netconf.git diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.java index bd26baa619..38df10178b 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactory.java @@ -5,10 +5,8 @@ * 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.netconf.impl; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableSet; @@ -18,8 +16,7 @@ import io.netty.util.Timer; import io.netty.util.concurrent.Promise; import java.net.SocketAddress; import java.util.Set; -import org.opendaylight.netconf.api.NetconfDocumentedException; -import org.opendaylight.netconf.api.NetconfServerSessionPreferences; +import org.opendaylight.netconf.api.NetconfSessionListenerFactory; import org.opendaylight.netconf.api.messages.NetconfHelloMessage; import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.netconf.api.xml.XmlNetconfConstants; @@ -27,20 +24,18 @@ import org.opendaylight.netconf.impl.osgi.NetconfOperationRouter; import org.opendaylight.netconf.impl.osgi.NetconfOperationRouterImpl; import org.opendaylight.netconf.mapping.api.NetconfOperationService; import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.protocol.framework.SessionListenerFactory; -import org.opendaylight.protocol.framework.SessionNegotiator; -import org.opendaylight.protocol.framework.SessionNegotiatorFactory; +import org.opendaylight.netconf.nettyutil.NetconfSessionNegotiatorFactory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory { +public class NetconfServerSessionNegotiatorFactory + implements NetconfSessionNegotiatorFactory { public static final Set DEFAULT_BASE_CAPABILITIES = ImmutableSet.of( XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_0, XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1, - XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0 + XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_EXI_1_0, + XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0 ); private final Timer timer; @@ -49,26 +44,35 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF private final NetconfOperationServiceFactory aggregatedOpService; private final long connectionTimeoutMillis; private final NetconfMonitoringService monitoringService; - private static final Logger LOG = LoggerFactory.getLogger(NetconfServerSessionNegotiatorFactory.class); private final Set baseCapabilities; - protected NetconfServerSessionNegotiatorFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider, + public NetconfServerSessionNegotiatorFactory(final Timer timer, + final NetconfOperationServiceFactory netconfOperationProvider, + final SessionIdProvider idProvider, final long connectionTimeoutMillis, + final NetconfMonitoringService monitoringService) { + this(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService, null); + } + + public NetconfServerSessionNegotiatorFactory(final Timer timer, + final NetconfOperationServiceFactory netconfOperationProvider, final SessionIdProvider idProvider, final long connectionTimeoutMillis, - final NetconfMonitoringService monitoringService, final Set baseCapabilities) { + final NetconfMonitoringService monitoringService, + final Set baseCapabilities) { this.timer = timer; - this.aggregatedOpService = netconfOperationProvider; + aggregatedOpService = netconfOperationProvider; this.idProvider = idProvider; this.connectionTimeoutMillis = connectionTimeoutMillis; this.monitoringService = monitoringService; - this.baseCapabilities = validateBaseCapabilities(baseCapabilities == null ? DEFAULT_BASE_CAPABILITIES : baseCapabilities); + this.baseCapabilities = validateBaseCapabilities(baseCapabilities == null ? DEFAULT_BASE_CAPABILITIES : + baseCapabilities); } - private static ImmutableSet validateBaseCapabilities(final Set baseCapabilities) { // Check base capabilities to be supported by the server final Sets.SetView unknownBaseCaps = Sets.difference(baseCapabilities, DEFAULT_BASE_CAPABILITIES); Preconditions.checkArgument(unknownBaseCaps.isEmpty(), - "Base capabilities that will be supported by netconf server have to be subset of %s, unknown base capabilities: %s", + "Base capabilities that will be supported by netconf server have to be subset of %s, " + + "unknown base capabilities: %s", DEFAULT_BASE_CAPABILITIES, unknownBaseCaps); final ImmutableSet.Builder b = ImmutableSet.builder(); @@ -79,57 +83,51 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF } /** + * Get session negotiator. + * * @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 + * @param channel Underlying channel + * @param promise Promise to be notified * @return session negotiator */ @Override - public SessionNegotiator getSessionNegotiator(final SessionListenerFactory defunctSessionListenerFactory, - final Channel channel, final Promise promise) { + public NetconfServerSessionNegotiator getSessionNegotiator( + final NetconfSessionListenerFactory defunctSessionListenerFactory, + final Channel channel, final Promise promise) { final long sessionId = idProvider.getNextSessionId(); - NetconfServerSessionPreferences proposal; - try { - proposal = new NetconfServerSessionPreferences(createHelloMessage(sessionId, monitoringService), sessionId); - } catch (final NetconfDocumentedException e) { - LOG.error("Unable to create hello message for session {} with {}", sessionId, monitoringService); - throw new IllegalStateException(e); - } - - return new NetconfServerSessionNegotiator(proposal, promise, channel, timer, - getListener(Long.toString(sessionId), channel.localAddress()), connectionTimeoutMillis); + return new NetconfServerSessionNegotiator(createHelloMessage(sessionId, monitoringService), sessionId, promise, + channel, timer, getListener(Long.toString(sessionId), channel.parent().localAddress()), + connectionTimeoutMillis); } - private NetconfServerSessionListener getListener(final String netconfSessionIdForReporting, final SocketAddress socketAddress) { - final NetconfOperationService service = getOperationServiceForAddress(netconfSessionIdForReporting, socketAddress); + private NetconfServerSessionListener getListener(final String netconfSessionIdForReporting, + final SocketAddress socketAddress) { + final NetconfOperationService service = getOperationServiceForAddress(netconfSessionIdForReporting, + socketAddress); final NetconfOperationRouter operationRouter = new NetconfOperationRouterImpl(service, monitoringService, netconfSessionIdForReporting); return new NetconfServerSessionListener(operationRouter, monitoringService, service); - } - protected NetconfOperationService getOperationServiceForAddress(final String netconfSessionIdForReporting, final SocketAddress socketAddress) { - return this.aggregatedOpService.createService(netconfSessionIdForReporting); + protected NetconfOperationService getOperationServiceForAddress(final String netconfSessionIdForReporting, + final SocketAddress socketAddress) { + return aggregatedOpService.createService(netconfSessionIdForReporting); } protected final NetconfOperationServiceFactory getOperationServiceFactory() { return aggregatedOpService; } - private NetconfHelloMessage createHelloMessage(final long sessionId, final NetconfMonitoringService capabilityProvider) throws NetconfDocumentedException { - return NetconfHelloMessage.createServerHello(Sets.union(transformCapabilities(capabilityProvider.getCapabilities()), baseCapabilities), sessionId); + private NetconfHelloMessage createHelloMessage( + final long sessionId, final NetconfMonitoringService capabilityProvider) { + return NetconfHelloMessage.createServerHello(Sets.union(transformCapabilities(capabilityProvider + .getCapabilities()), baseCapabilities), sessionId); } public static Set transformCapabilities(final Capabilities capabilities) { - return Sets.newHashSet(Collections2.transform(capabilities.getCapability(), new Function() { - @Override - public String apply(final Uri uri) { - return uri.getValue(); - } - })); + return Sets.newHashSet(Collections2.transform(capabilities.getCapability(), Uri::getValue)); } - }