Merge "Fixed sal-netconf-connector readConfiguration"
authorEd Warnicke <eaw@cisco.com>
Sun, 8 Dec 2013 16:22:08 +0000 (16:22 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sun, 8 Dec 2013 16:22:08 +0000 (16:22 +0000)
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.xtend
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfMapping.xtend
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlMapper.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java
opendaylight/netconf/netconf-client/src/main/resources/client_hello.xml
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/client_hello.xml

index 4d0a1ac6b663e3ecf7aee035ab5b47157de1aed8..55a1fbfe486a03f033ba961586675cb21beea2d6 100644 (file)
@@ -10,6 +10,7 @@
 package org.opendaylight.controller.config.yang.md.sal.connector.netconf;
 
 import io.netty.channel.EventLoopGroup;
+import io.netty.util.concurrent.GlobalEventExecutor;
 
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
@@ -21,6 +22,8 @@ import org.opendaylight.controller.netconf.client.NetconfSshClientDispatcher;
 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.AuthenticationHandler;
 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
 import org.opendaylight.controller.sal.connect.netconf.NetconfDevice;
+import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.TimedReconnectStrategy;
 import org.osgi.framework.BundleContext;
 
 import static com.google.common.base.Preconditions.*;
@@ -62,6 +65,8 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         String addressValue = getAddress();
         
         
+        int attemptMsTimeout = 60*1000;
+        int connectionAttempts = 5;
         /*
          * Uncomment after Switch to IP Address
         if(getAddress().getIpv4Address() != null) {
@@ -71,6 +76,12 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         }
         
         */
+        ReconnectStrategy strategy = new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, attemptMsTimeout, 1000, 1.0, null,
+                Long.valueOf(connectionAttempts), null);
+        
+        
+        device.setStrategy(strategy);
+        
         InetAddress addr = InetAddresses.forString(addressValue);
         InetSocketAddress socketAddress = new InetSocketAddress(addr , getPort().intValue());
         device.setSocketAddress(socketAddress);
index 49d9757f421058cb05ffed90f81922f6509ff688..7c4bf5facad6a3dd94b0f1bd6a73e301a7820143 100644 (file)
@@ -22,8 +22,16 @@ import org.opendaylight.controller.sal.core.api.data.DataBrokerService
 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction
 import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl
 import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl
+import org.opendaylight.protocol.framework.ReconnectStrategy
+import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler
+import org.opendaylight.controller.md.sal.common.api.data.DataModification
 
-class NetconfDevice implements Provider, DataReader<InstanceIdentifier, CompositeNode>, RpcImplementation, AutoCloseable {
+class NetconfDevice implements 
+    Provider, // 
+    DataReader<InstanceIdentifier, CompositeNode>, //
+    DataCommitHandler<InstanceIdentifier, CompositeNode>, //
+    RpcImplementation, //
+    AutoCloseable {
 
     var NetconfClient client;
 
@@ -36,14 +44,17 @@ class NetconfDevice implements Provider, DataReader<InstanceIdentifier, Composit
     @Property
     var InstanceIdentifier path;
 
-    Registration<DataReader<InstanceIdentifier, CompositeNode>> operReaderReg
+    @Property
+    var ReconnectStrategy strategy;
 
+    Registration<DataReader<InstanceIdentifier, CompositeNode>> operReaderReg
     Registration<DataReader<InstanceIdentifier, CompositeNode>> confReaderReg
-
-    String name
-
+    Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> commitHandlerReg
+    
+    val String name
     MountProvisionService mountService
-
+    
+    
     public new(String name) {
         this.name = name;
         this.path = InstanceIdentifier.builder(INVENTORY_PATH).nodeWithKey(INVENTORY_NODE,
@@ -51,13 +62,14 @@ class NetconfDevice implements Provider, DataReader<InstanceIdentifier, Composit
     }
 
     def start(NetconfClientDispatcher dispatcher) {
-        client = new NetconfClient(name, socketAddress, dispatcher);
+        client = NetconfClient.clientFor(name, socketAddress, strategy, dispatcher);
         confReaderReg = mountInstance.registerConfigurationReader(path, this);
         operReaderReg = mountInstance.registerOperationalReader(path, this);
+        //commitHandlerReg = mountInstance.registerCommitHandler(path,this);
     }
 
     override readConfigurationData(InstanceIdentifier path) {
-        val result = invokeRpc(NETCONF_GET_CONFIG_QNAME, wrap(NETCONF_GET_CONFIG_QNAME, path.toFilterStructure()));
+        val result = invokeRpc(NETCONF_GET_CONFIG_QNAME, wrap(NETCONF_GET_CONFIG_QNAME, CONFIG_SOURCE_RUNNING, path.toFilterStructure()));
         val data = result.result.getFirstCompositeByName(NETCONF_DATA_QNAME);
         return data?.findNode(path) as CompositeNode;
     }
@@ -133,6 +145,10 @@ class NetconfDevice implements Provider, DataReader<InstanceIdentifier, Composit
         return current;
     }
 
+    override requestCommit(DataModification<InstanceIdentifier, CompositeNode> modification) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub")
+    }
+
     override close() {
         confReaderReg?.close()
         operReaderReg?.close()
index d23ec1cd61ae65ee507693638e03be9043b3e937..78f6d59f77ed2b2a7025b578d6090929ceead2dd 100644 (file)
@@ -18,6 +18,8 @@ import java.util.concurrent.atomic.AtomicInteger
 import org.w3c.dom.Document
 import org.w3c.dom.Element
 import org.opendaylight.controller.sal.common.util.Rpcs
+import java.util.List
+import com.google.common.collect.ImmutableList
 
 class NetconfMapping {
 
@@ -26,12 +28,18 @@ class NetconfMapping {
     public static val NETCONF_RPC_QNAME = new QName(NETCONF_QNAME,"rpc");
     public static val NETCONF_GET_QNAME = new QName(NETCONF_QNAME,"get");
     public static val NETCONF_GET_CONFIG_QNAME = new QName(NETCONF_QNAME,"get-config");
+    public static val NETCONF_SOURCE_QNAME = new QName(NETCONF_QNAME,"source");
+    public static val NETCONF_RUNNING_QNAME = new QName(NETCONF_QNAME,"running");
     public static val NETCONF_RPC_REPLY_QNAME = new QName(NETCONF_QNAME,"rpc-reply");
     public static val NETCONF_OK_QNAME = new QName(NETCONF_QNAME,"ok");
     public static val NETCONF_DATA_QNAME = new QName(NETCONF_QNAME,"data");
     
+     static List<Node<?>> RUNNING = Collections.<Node<?>>singletonList(new SimpleNodeTOImpl(NETCONF_RUNNING_QNAME,null,null));
+    public static val CONFIG_SOURCE_RUNNING = new CompositeNodeTOImpl(NETCONF_SOURCE_QNAME,null,RUNNING);
 
     static val messageId = new AtomicInteger(0);
+    
+   
 
 
 
@@ -88,6 +96,15 @@ class NetconfMapping {
         }
     }
     
+        static def wrap(QName name,Node<?> additional,Node<?> node) {
+        if(node != null) {
+            return new CompositeNodeTOImpl(name,null,ImmutableList.of(additional,node));
+        }
+        else {
+            return new CompositeNodeTOImpl(name,null,ImmutableList.of(additional));
+        }
+    }
+    
     
     public static def Node<?> toCompositeNode(Document document) {
         return XmlDocumentUtils.toCompositeNode(document) as Node<?>
index c0de0d80a8c0f04fbb5a322c822acf4ca5e91661..4a077e663f187f6d23e05a771d4ec988290c8c90 100644 (file)
@@ -59,7 +59,6 @@ public class XmlMapper {
             throws UnsupportedDataTypeException {
         QName dataType = data.getNodeType();
         Element itemEl = doc.createElementNS(dataType.getNamespace().toString(), dataType.getLocalName());
-
         if (data instanceof SimpleNode<?>) {
             if (schema instanceof LeafListSchemaNode) {
                 writeValueOfNodeByType(itemEl, (SimpleNode<?>) data, ((LeafListSchemaNode) schema).getType());
@@ -73,11 +72,14 @@ public class XmlMapper {
             }
         } else { // CompositeNode
             for (Node<?> child : ((CompositeNode) data).getChildren()) {
-                DataSchemaNode childSchema = findFirstSchemaForNode(child, ((DataNodeContainer) schema).getChildNodes());
-                if (logger.isDebugEnabled()) {
-                    if (childSchema == null) {
-                        logger.debug("Probably the data node \"" + ((child == null) ? "" : child.getNodeType().getLocalName())
-                                + "\" is not conform to schema");
+                DataSchemaNode childSchema = null;
+                if(schema != null){
+                    childSchema = findFirstSchemaForNode(child, ((DataNodeContainer) schema).getChildNodes());
+                    if (logger.isDebugEnabled()) {
+                        if (childSchema == null) {
+                            logger.debug("Probably the data node \"" + ((child == null) ? "" : child.getNodeType().getLocalName())
+                                    + "\" is not conform to schema");
+                        }
                     }
                 }
                 itemEl.appendChild(translateToXmlAndReturnRootElement(doc, child, childSchema));
index d644cddff4855afe0a6e87b399a81d9eb5f5b152..95f526b2ecb535787570fd60fe97e96094421420 100644 (file)
@@ -67,6 +67,10 @@ public class NetconfClient implements Closeable {
         }
     }
 
+    public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
+        return new NetconfClient(clientLabelForLogging,address,strat,netconfClientDispatcher);
+    }
+
     public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs,
             NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
         this(clientLabelForLogging, address,
index 221953e56e51053af95bc32bd866f2d51b99f05a..520627a09899c826f7a7254610cf8e9f7f776b65 100644 (file)
@@ -1,6 +1,7 @@
 <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
     <capabilities>
         <capability>urn:ietf:params:netconf:base:1.0</capability>
+        <capability>urn:ietf:params:netconf:base:1.1</capability>
         <capability>urn:ietf:params:netconf:capability:exi:1.0</capability>
     </capabilities>
 </hello>
\ No newline at end of file
index 4e34591284e78e23e4b84f0553aea90c53792295..46f6f76412e01b8b09c45f209021fff8ec0d270d 100644 (file)
@@ -1,5 +1,6 @@
 <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
     <capabilities>
         <capability>urn:ietf:params:netconf:base:1.0</capability>
+        <capability>urn:ietf:params:netconf:base:1.1</capability>
     </capabilities>
 </hello>