X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNetconfDeviceListener.java;h=d6bf868b75dfaa55059e19f05bdb5bf924f08306;hb=refs%2Fchanges%2F05%2F6205%2F3;hp=d5e1d35d7d5721e06b9b515822813b54feac779f;hpb=1d159b16ac23b4935ed6a0df683558ab42cd6f2c;p=controller.git diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java index d5e1d35d7d..d6bf868b75 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.sal.connect.netconf; +import com.google.common.collect.Sets; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.FutureListener; @@ -39,6 +40,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; class NetconfDeviceListener implements NetconfClientSessionListener { + private static final class Request { final UncancellableFuture> future; final NetconfMessage request; @@ -63,6 +65,8 @@ class NetconfDeviceListener implements NetconfClientSessionListener { LOG.debug("Session with {} established as address {} session-id {}", device.getName(), device.getSocketAddress(), session.getSessionId()); + this.session = session; + final Set caps = device.getCapabilities(session.getServerCapabilities()); LOG.trace("Server {} advertized capabilities {}", device.getName(), caps); @@ -70,16 +74,22 @@ class NetconfDeviceListener implements NetconfClientSessionListener { final SchemaSourceProvider delegate; if (NetconfRemoteSchemaSourceProvider.isSupportedFor(caps)) { delegate = new NetconfRemoteSchemaSourceProvider(device); - } else if(caps.contains(NetconfRemoteSchemaSourceProvider.IETF_NETCONF_MONITORING.getNamespace().toString())) { + // FIXME caps do not contain urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring, since it is filtered out in getCapabilitites + } else if(session.getServerCapabilities().contains(NetconfRemoteSchemaSourceProvider.IETF_NETCONF_MONITORING.getNamespace().toString())) { delegate = new NetconfRemoteSchemaSourceProvider(device); } else { LOG.info("Netconf server {} does not support IETF Netconf Monitoring", device.getName()); - delegate = SchemaSourceProviders.noopProvider(); + delegate = SchemaSourceProviders.noopProvider(); } - device.bringUp(delegate, caps); + device.bringUp(delegate, caps, isRollbackSupported(session.getServerCapabilities())); - this.session = session; + } + + private static boolean isRollbackSupported(final Collection serverCapabilities) { + // TODO rollback capability cannot be searched for in Set caps + // since this set does not contain module-less capabilities + return Sets.newHashSet(serverCapabilities).contains(NetconfMapping.NETCONF_ROLLBACK_ON_ERROR_URI.toString()); } private synchronized void tearDown(final Exception e) { @@ -136,9 +146,22 @@ class NetconfDeviceListener implements NetconfClientSessionListener { requests.poll(); LOG.debug("Matched {} to {}", r.request, message); - // FIXME: this can throw exceptions, which should result - // in the future failing - NetconfMapping.checkValidReply(r.request, message); + try { + NetconfMapping.checkValidReply(r.request, message); + } catch (IllegalStateException e) { + LOG.warn("Invalid request-reply match, reply message contains different message-id", e); + r.future.setException(e); + return; + } + + try { + NetconfMapping.checkSuccessReply(message); + } catch (IllegalStateException e) { + LOG.warn("Error reply from remote device", e); + r.future.setException(e); + return; + } + r.future.set(Rpcs.getRpcResult(true, NetconfMapping.toNotificationNode(message, device.getSchemaContext()), Collections.emptyList())); } else {