+ def start() {
+ checkState(dispatcher != null, "Dispatcher must be set.");
+ checkState(schemaSourceProvider != null, "Schema Source Provider must be set.")
+ checkState(eventExecutor != null, "Event executor must be set.");
+
+ val listener = new NetconfDeviceListener(this, eventExecutor);
+ val task = startClientTask(dispatcher, listener)
+ if (mountInstance != null) {
+ commitHandlerReg = mountInstance.registerCommitHandler(ROOT_PATH, this)
+ }
+ return processingExecutor.submit(task) as Future<Void>;
+
+ //commitHandlerReg = mountInstance.registerCommitHandler(path,this);
+ }
+
+ def Optional<SchemaContext> getSchemaContext() {
+ if (deviceContextProvider == null) {
+ return Optional.absent();
+ }
+ return deviceContextProvider.currentContext;
+ }
+
+ private def Runnable startClientTask(NetconfClientDispatcher dispatcher, NetconfDeviceListener listener) {
+ return [ |
+ try {
+ logger.info("Starting Netconf Client on: {}", socketAddress);
+ client = NetconfClient.clientFor(name, socketAddress, reconnectStrategy, dispatcher, listener);
+ logger.debug("Initial capabilities {}", initialCapabilities);
+ var SchemaSourceProvider<String> delegate;
+ if (NetconfRemoteSchemaSourceProvider.isSupportedFor(initialCapabilities)) {
+ delegate = new NetconfRemoteSchemaSourceProvider(this);
+ } else if(client.capabilities.contains(NetconfRemoteSchemaSourceProvider.IETF_NETCONF_MONITORING.namespace.toString)) {
+ delegate = new NetconfRemoteSchemaSourceProvider(this);
+ } else {
+ logger.info("Netconf server {} does not support IETF Netconf Monitoring", socketAddress);
+ delegate = SchemaSourceProviders.<String>noopProvider();
+ }
+ remoteSourceProvider = schemaSourceProvider.createInstanceFor(delegate);
+ deviceContextProvider = new NetconfDeviceSchemaContextProvider(this, remoteSourceProvider);
+ deviceContextProvider.createContextFromCapabilities(initialCapabilities);
+ if (mountInstance != null && schemaContext.isPresent) {
+ mountInstance.schemaContext = schemaContext.get();
+ }
+ updateDeviceState()
+ if (mountInstance != null && confReaderReg == null && operReaderReg == null) {
+ confReaderReg = mountInstance.registerConfigurationReader(ROOT_PATH, this);
+ operReaderReg = mountInstance.registerOperationalReader(ROOT_PATH, this);
+ }
+ } catch (Exception e) {
+ logger.error("Netconf client NOT started. ", e)
+ }
+ ]
+ }
+
+ private def updateDeviceState() {
+ val transaction = dataBroker.beginTransaction
+
+ val it = ImmutableCompositeNode.builder
+ setQName(INVENTORY_NODE)
+ addLeaf(INVENTORY_ID, name)
+ addLeaf(INVENTORY_CONNECTED, client.clientSession.up)
+
+ logger.debug("Client capabilities {}", client.capabilities)
+ for (capability : client.capabilities) {
+ addLeaf(NETCONF_INVENTORY_INITIAL_CAPABILITY, capability)
+ }
+
+ logger.debug("Update device state transaction " + transaction.identifier + " putting operational data started.")
+ transaction.putOperationalData(path, it.toInstance)
+ logger.debug("Update device state transaction " + transaction.identifier + " putting operational data ended.")
+ val transactionStatus = transaction.commit.get;
+
+ if (transactionStatus.successful) {
+ logger.debug("Update device state transaction " + transaction.identifier + " SUCCESSFUL.")
+ } else {
+ logger.debug("Update device state transaction " + transaction.identifier + " FAILED!")
+ logger.debug("Update device state transaction status " + transaction.status)
+ }