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;
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.*;
String addressValue = getAddress();
+ int attemptMsTimeout = 60*1000;
+ int connectionAttempts = 5;
/*
* Uncomment after Switch to IP Address
if(getAddress().getIpv4Address() != null) {
}
*/
+ 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);
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;
@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,
}
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;
}
return current;
}
+ override requestCommit(DataModification<InstanceIdentifier, CompositeNode> modification) {
+ throw new UnsupportedOperationException("TODO: auto-generated method stub")
+ }
+
override close() {
confReaderReg?.close()
operReaderReg?.close()
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 {
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);
+
+
}
}
+ 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<?>
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());
}
} 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));
}
}
+ 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,
<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
<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>