Update user-guide.rst
[netconf.git] / docs / user-guide.rst
1 .. _netconf-user-guide:
2
3 NETCONF User Guide
4 ==================
5
6 Overview
7 --------
8
9 NETCONF is an XML-based protocol used for configuration and monitoring
10 devices in the network. The base NETCONF protocol is described in
11 `RFC-6241 <http://tools.ietf.org/html/rfc6241>`__.
12
13 **NETCONF in OpenDaylight:.**
14
15 OpenDaylight supports the NETCONF protocol as a northbound server as
16 well as a southbound plugin. It also includes a set of test tools for
17 simulating NETCONF devices and clients.
18
19 Southbound (netconf-connector)
20 ------------------------------
21
22 The NETCONF southbound plugin is capable of connecting to remote NETCONF
23 devices and exposing their configuration/operational datastores, RPCs
24 and notifications as MD-SAL mount points. These mount points allow
25 applications and remote users (over RESTCONF) to interact with the
26 mounted devices.
27
28 In terms of RFCs, the connector supports:
29
30 -  `RFC-6241 <http://tools.ietf.org/html/rfc6241>`__
31
32 -  `RFC-5277 <https://tools.ietf.org/html/rfc5277>`__
33
34 -  `RFC-6022 <https://tools.ietf.org/html/rfc6022>`__
35
36 -  `draft-ietf-netconf-yang-library-06 <https://tools.ietf.org/html/draft-ietf-netconf-yang-library-06>`__
37
38 **Netconf-connector is fully model-driven (utilizing the YANG modeling
39 language) so in addition to the above RFCs, it supports any
40 data/RPC/notifications described by a YANG model that is implemented by
41 the device.**
42
43 .. tip::
44
45     NETCONF southbound can be activated by installing
46     ``odl-netconf-connector-all`` Karaf feature.
47
48 Netconf-connector configuration
49 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
51 There are 2 ways for configuring netconf-connector: NETCONF or RESTCONF.
52 This guide focuses on using RESTCONF.
53
54 .. important::
55
56     There are 2 different endpoints related to RESTCONF protocols:
57
58     - | ``http://localhost:8181/restconf`` is related to `draft-bierman-netconf-restconf-02 <https://tools.ietf.org/html/draft-bierman-netconf-restconf-02>`__,
59       | can be activated by installing ``odl-restconf-nb-bierman02``
60        Karaf feature.
61       | This user guide uses this approach.
62
63     - | ``http://localhost:8181/rests`` is related to `RFC-8040 <https://tools.ietf.org/html/rfc8040>`__,
64       | can be activated by installing ``odl-restconf-nb-rfc8040``
65        Karaf feature.
66
67     | In case of `RFC-8040 <https://tools.ietf.org/html/rfc8040>`__
68      resources for configuration and operational datastores start
69      ``/rests/data/``,
70     | e. g. GET
71      http://localhost:8181/rests/data/network-topology:network-topology
72      with response of both datastores. It's allowed to use query
73      parameters to distinguish between them.
74     | e. g. GET
75      http://localhost:8181/rests/data/network-topology:network-topology?content=config
76      for configuration datastore
77     | and GET
78      http://localhost:8181/rests/data/network-topology:network-topology?content=nonconfig
79      for operational datastore.
80
81
82
83
84
85 Default configuration
86 ^^^^^^^^^^^^^^^^^^^^^
87
88 The default configuration contains all the necessary dependencies (file:
89 01-netconf.xml) and a single instance of netconf-connector (file:
90 99-netconf-connector.xml) called **controller-config** which connects
91 itself to the NETCONF northbound in OpenDaylight in a loopback fashion.
92 The connector mounts the NETCONF server for config-subsystem in order to
93 enable RESTCONF protocol for config-subsystem. This RESTCONF still goes
94 via NETCONF, but using RESTCONF is much more user friendly than using
95 NETCONF.
96
97 Spawning additional netconf-connectors while the controller is running
98 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99
100 Preconditions:
101
102 1. OpenDaylight is running
103
104 2. In Karaf, you must have the netconf-connector installed (at the Karaf
105    prompt, type: ``feature:install odl-netconf-connector-all``); the
106    loopback NETCONF mountpoint will be automatically configured and
107    activated
108
109 3. Wait until log displays following entry:
110    RemoteDevice{controller-config}: NETCONF connector initialized
111    successfully
112
113 To configure a new netconf-connector you need to send following request
114 to RESTCONF:
115
116 POST
117 http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/controller-config/yang-ext:mount/config:modules
118
119 Headers:
120
121 -  Accept application/xml
122
123 -  Content-Type application/xml
124
125 ::
126
127     <module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
128       <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">prefix:sal-netconf-connector</type>
129       <name>new-netconf-device</name>
130       <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">127.0.0.1</address>
131       <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">830</port>
132       <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</username>
133       <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</password>
134       <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
135       <event-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
136         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netty">prefix:netty-event-executor</type>
137         <name>global-event-executor</name>
138       </event-executor>
139       <binding-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
140         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">prefix:binding-broker-osgi-registry</type>
141         <name>binding-osgi-broker</name>
142       </binding-registry>
143       <dom-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
144         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type>
145         <name>dom-broker</name>
146       </dom-registry>
147       <client-dispatcher xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
148         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:netconf">prefix:netconf-client-dispatcher</type>
149         <name>global-netconf-dispatcher</name>
150       </client-dispatcher>
151       <processing-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
152         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:threadpool">prefix:threadpool</type>
153         <name>global-netconf-processing-executor</name>
154       </processing-executor>
155       <keepalive-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
156         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:threadpool">prefix:scheduled-threadpool</type>
157         <name>global-netconf-ssh-scheduled-executor</name>
158       </keepalive-executor>
159     </module>
160
161 This spawns a new netconf-connector which tries to connect to (or mount)
162 a NETCONF device at 127.0.0.1 and port 830. You can check the
163 configuration of config-subsystem’s configuration datastore. The new
164 netconf-connector will now be present there. Just invoke:
165
166 GET
167 http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/controller-config/yang-ext:mount/config:modules
168
169 The response will contain the module for new-netconf-device.
170
171 Right after the new netconf-connector is created, it writes some useful
172 metadata into the datastore of MD-SAL under the network-topology
173 subtree. This metadata can be found at:
174
175 GET
176 http://localhost:8181/restconf/operational/network-topology:network-topology/
177
178 Information about connection status, device capabilities, etc. can be
179 found there.
180
181 Connecting to a device not supporting NETCONF monitoring
182 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
183
184 The netconf-connector in OpenDaylight relies on ietf-netconf-monitoring
185 support when connecting to remote NETCONF device. The
186 ietf-netconf-monitoring support allows netconf-connector to list and
187 download all YANG schemas that are used by the device. NETCONF connector
188 can only communicate with a device if it knows the set of used schemas
189 (or at least a subset). However, some devices use YANG models internally
190 but do not support NETCONF monitoring. Netconf-connector can also
191 communicate with these devices, but you have to side load the necessary
192 yang models into OpenDaylight’s YANG model cache for netconf-connector.
193 In general there are 2 situations you might encounter:
194
195 **1. NETCONF device does not support ietf-netconf-monitoring but it does
196 list all its YANG models as capabilities in HELLO message**
197
198 This could be a device that internally uses only ietf-inet-types YANG
199 model with revision 2010-09-24. In the HELLO message that is sent from
200 this device there is this capability reported:
201
202 ::
203
204     urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&revision=2010-09-24
205
206 **For such devices you only need to put the schema into folder
207 cache/schema inside your Karaf distribution.**
208
209 .. important::
210
211     The file with YANG schema for ietf-inet-types has to be called
212     ietf-inet-types@2010-09-24.yang. It is the required naming format of
213     the cache.
214
215 **2. NETCONF device does not support ietf-netconf-monitoring and it does
216 NOT list its YANG models as capabilities in HELLO message**
217
218 Compared to device that lists its YANG models in HELLO message, in this
219 case there would be no capability with ietf-inet-types in the HELLO
220 message. This type of device basically provides no information about the
221 YANG schemas it uses so its up to the user of OpenDaylight to properly
222 configure netconf-connector for this device.
223
224 Netconf-connector has an optional configuration attribute called
225 yang-module-capabilities and this attribute can contain a list of "YANG
226 module based" capabilities. So by setting this configuration attribute,
227 it is possible to override the "yang-module-based" capabilities reported
228 in HELLO message of the device. To do this, we need to modify the
229 configuration of netconf-connector by adding this XML (It needs to be
230 added next to the address, port, username etc. configuration elements):
231
232 ::
233
234     <yang-module-capabilities xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
235       <capability xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
236         urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&amp;revision=2010-09-24
237       </capability>
238     </yang-module-capabilities>
239
240 **Remember to also put the YANG schemas into the cache folder.**
241
242 .. note::
243
244     For putting multiple capabilities, you just need to replicate the
245     capability xml element inside yang-module-capability element.
246     Capability element is modeled as a leaf-list. With this
247     configuration, we would make the remote device report usage of
248     ietf-inet-types in the eyes of netconf-connector.
249
250 Reconfiguring Netconf-Connector While the Controller is Running
251 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
252
253 It is possible to change the configuration of a running module while the
254 whole controller is running. This example will continue where the last
255 left off and will change the configuration for the brand new
256 netconf-connector after it was spawned. Using one RESTCONF request, we
257 will change both username and password for the netconf-connector.
258
259 To update an existing netconf-connector you need to send following
260 request to RESTCONF:
261
262 PUT
263 http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/controller-config/yang-ext:mount/config:modules/module/odl-sal-netconf-connector-cfg:sal-netconf-connector/new-netconf-device
264
265 ::
266
267     <module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
268       <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">prefix:sal-netconf-connector</type>
269       <name>new-netconf-device</name>
270       <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">bob</username>
271       <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">passwd</password>
272       <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
273       <event-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
274         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:netty">prefix:netty-event-executor</type>
275         <name>global-event-executor</name>
276       </event-executor>
277       <binding-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
278         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">prefix:binding-broker-osgi-registry</type>
279         <name>binding-osgi-broker</name>
280       </binding-registry>
281       <dom-registry xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
282         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type>
283         <name>dom-broker</name>
284       </dom-registry>
285       <client-dispatcher xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
286         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:config:netconf">prefix:netconf-client-dispatcher</type>
287         <name>global-netconf-dispatcher</name>
288       </client-dispatcher>
289       <processing-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
290         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:threadpool">prefix:threadpool</type>
291         <name>global-netconf-processing-executor</name>
292       </processing-executor>
293       <keepalive-executor xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">
294         <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:threadpool">prefix:scheduled-threadpool</type>
295         <name>global-netconf-ssh-scheduled-executor</name>
296       </keepalive-executor>
297     </module>
298
299 Since a PUT is a replace operation, the whole configuration must be
300 specified along with the new values for username and password. This
301 should result in a 2xx response and the instance of netconf-connector
302 called new-netconf-device will be reconfigured to use username bob and
303 password passwd. New configuration can be verified by executing:
304
305 GET
306 http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/controller-config/yang-ext:mount/config:modules/module/odl-sal-netconf-connector-cfg:sal-netconf-connector/new-netconf-device
307
308 With new configuration, the old connection will be closed and a new one
309 established.
310
311 Destroying Netconf-Connector While the Controller is Running
312 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313
314 Using RESTCONF one can also destroy an instance of a module. In case of
315 netconf-connector, the module will be destroyed, NETCONF connection
316 dropped and all resources will be cleaned. To do this, simply issue a
317 request to following URL:
318
319 DELETE
320 http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/controller-config/yang-ext:mount/config:modules/module/odl-sal-netconf-connector-cfg:sal-netconf-connector/new-netconf-device
321
322 The last element of the URL is the name of the instance and its
323 predecessor is the type of that module (In our case the type is
324 **sal-netconf-connector** and name **new-netconf-device**). The type and
325 name are actually the keys of the module list.
326
327 Netconf-connector configuration with MD-SAL
328 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
329
330 It is also possible to configure new NETCONF connectors directly through
331 MD-SAL with the usage of the network-topology model. You can configure
332 new NETCONF connectors both through the NETCONF server for MD-SAL (port
333 2830) or RESTCONF. This guide focuses on RESTCONF.
334
335 .. tip::
336
337     To enable NETCONF connector configuration through MD-SAL install
338     either the ``odl-netconf-topology`` or
339     ``odl-netconf-clustered-topology`` feature. We will explain the
340     difference between these features later.
341
342 Preconditions
343 ^^^^^^^^^^^^^
344
345 1. OpenDaylight is running
346
347 2. In Karaf, you must have the ``odl-netconf-topology`` or
348    ``odl-netconf-clustered-topology`` feature installed.
349
350 3. Feature ``odl-restconf`` must be installed
351
352 4. Wait until log displays following entry:
353
354    ::
355
356        Successfully pushed configuration snapshot 02-netconf-topology.xml(odl-netconf-topology,odl-netconf-topology)
357
358    or until
359
360    ::
361
362        GET http://localhost:8181/restconf/operational/network-topology:network-topology/topology/topology-netconf/
363
364    returns a non-empty response, for example:
365
366    ::
367
368        <topology xmlns="urn:TBD:params:xml:ns:yang:network-topology">
369          <topology-id>topology-netconf</topology-id>
370        </topology>
371
372 Spawning new NETCONF connectors
373 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
374
375 To create a new NETCONF connector you need to send the following request
376 to RESTCONF:
377
378 ::
379
380     PUT http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device
381
382 Headers:
383
384 -  Accept: application/xml
385
386 -  Content-Type: application/xml
387
388 Payload:
389
390 ::
391
392     <node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
393       <node-id>new-netconf-device</node-id>
394       <host xmlns="urn:opendaylight:netconf-node-topology">127.0.0.1</host>
395       <port xmlns="urn:opendaylight:netconf-node-topology">17830</port>
396       <username xmlns="urn:opendaylight:netconf-node-topology">admin</username>
397       <password xmlns="urn:opendaylight:netconf-node-topology">admin</password>
398       <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
399       <!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->
400       <reconnect-on-changed-schema xmlns="urn:opendaylight:netconf-node-topology">false</reconnect-on-changed-schema>
401       <connection-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">20000</connection-timeout-millis>
402       <max-connection-attempts xmlns="urn:opendaylight:netconf-node-topology">0</max-connection-attempts>
403       <between-attempts-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">2000</between-attempts-timeout-millis>
404       <sleep-factor xmlns="urn:opendaylight:netconf-node-topology">1.5</sleep-factor>
405       <!-- keepalive-delay set to 0 turns off keepalives-->
406       <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">120</keepalive-delay>
407     </node>
408
409 Note that the device name in <node-id> element must match the last
410 element of the restconf URL.
411
412 Reconfiguring an existing connector
413 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
414
415 The steps to reconfigure an existing connector are exactly the same as
416 when spawning a new connector. The old connection will be disconnected
417 and a new connector with the new configuration will be created.
418
419 Deleting an existing connector
420 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
421
422 To remove an already configured NETCONF connector you need to send the
423 following:
424
425 ::
426
427     DELETE http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device
428
429 Connecting to a device supporting only NETCONF 1.0
430 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
431
432 OpenDaylight is schema-based distribution and heavily depends on YANG
433 models. However some legacy NETCONF devices are not schema-based and
434 implement just RFC 4741. This type of device does not utilize YANG
435 models internally and OpenDaylight does not know how to communicate
436 with such devices, how to validate data, or what the semantics of data
437 are.
438
439 NETCONF connector can communicate also with these devices, but the
440 trade-offs are worsened possibilities in utilization of NETCONF
441 mountpoints. Using RESTCONF with such devices is not suported. Also
442 communicating with schemaless devices from application code is slightly
443 different.
444
445 To connect to schemaless device, there is a optional configuration option
446 in netconf-node-topology model called schemaless. You have to set this
447 option to true.
448
449 Clustered NETCONF connector
450 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
451
452 To spawn NETCONF connectors that are cluster-aware you need to install
453 the ``odl-netconf-clustered-topology`` karaf feature.
454
455 .. warning::
456
457     The ``odl-netconf-topology`` and ``odl-netconf-clustered-topology``
458     features are considered **INCOMPATIBLE**. They both manage the same
459     space in the datastore and would issue conflicting writes if
460     installed together.
461
462 Configuration of clustered NETCONF connectors works the same as the
463 configuration through the topology model in the previous section.
464
465 When a new clustered connector is configured the configuration gets
466 distributed among the member nodes and a NETCONF connector is spawned on
467 each node. From these nodes a master is chosen which handles the schema
468 download from the device and all the communication with the device. You
469 will be able to read/write to/from the device from all slave nodes due
470 to the proxy data brokers implemented.
471
472 You can use the ``odl-netconf-clustered-topology`` feature in a single
473 node scenario as well but the code that uses akka will be used, so for a
474 scenario where only a single node is used, ``odl-netconf-topology``
475 might be preferred.
476
477 Netconf-connector utilization
478 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
479
480 Once the connector is up and running, users can utilize the new mount
481 point instance. By using RESTCONF or from their application code. This
482 chapter deals with using RESTCONF and more information for app
483 developers can be found in the developers guide or in the official
484 tutorial application **ncmount** that can be found in the coretutorials
485 project:
486
487 -  https://github.com/opendaylight/coretutorials/tree/stable/beryllum/ncmount
488
489 Reading data from the device
490 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
491
492 Just invoke (no body needed):
493
494 GET
495 http://localhost:8080/restconf/operational/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device/yang-ext:mount/
496
497 This will return the entire content of operation datastore from the
498 device. To view just the configuration datastore, change **operational**
499 in this URL to **config**.
500
501 Writing configuration data to the device
502 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
503
504 In general, you cannot simply write any data you want to the device. The
505 data have to conform to the YANG models implemented by the device. In
506 this example we are adding a new interface-configuration to the mounted
507 device (assuming the device supports Cisco-IOS-XR-ifmgr-cfg YANG model).
508 In fact this request comes from the tutorial dedicated to the
509 **ncmount** tutorial app.
510
511 POST
512 http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device/yang-ext:mount/Cisco-IOS-XR-ifmgr-cfg:interface-configurations
513
514 ::
515
516     <interface-configuration xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
517         <active>act</active>
518         <interface-name>mpls</interface-name>
519         <description>Interface description</description>
520         <bandwidth>32</bandwidth>
521         <link-status></link-status>
522     </interface-configuration>
523
524 Should return 200 response code with no body.
525
526 .. tip::
527
528     This call is transformed into a couple of NETCONF RPCs. Resulting
529     NETCONF RPCs that go directly to the device can be found in the
530     OpenDaylight logs after invoking ``log:set TRACE
531     org.opendaylight.controller.sal.connect.netconf`` in the Karaf
532     shell. Seeing the NETCONF RPCs might help with debugging.
533
534 This request is very similar to the one where we spawned a new netconf
535 device. That’s because we used the loopback netconf-connector to write
536 configuration data into config-subsystem datastore and config-subsystem
537 picked it up from there.
538
539 Invoking custom RPC
540 ^^^^^^^^^^^^^^^^^^^
541
542 Devices can implement any additional RPC and as long as it provides YANG
543 models for it, it can be invoked from OpenDaylight. Following example
544 shows how to invoke the get-schema RPC (get-schema is quite common among
545 netconf devices). Invoke:
546
547 POST
548 http://localhost:8181/restconf/operations/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device/yang-ext:mount/ietf-netconf-monitoring:get-schema
549
550 ::
551
552     <input xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
553       <identifier>ietf-yang-types</identifier>
554       <version>2013-07-15</version>
555     </input>
556
557 This call should fetch the source for ietf-yang-types YANG model from
558 the mounted device.
559
560 Netconf-connector + Netopeer
561 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
562
563 `Netopeer <https://github.com/cesnet/netopeer>`__ (an open-source
564 NETCONF server) can be used for testing/exploring NETCONF southbound in
565 OpenDaylight.
566
567 Netopeer installation
568 ^^^^^^^^^^^^^^^^^^^^^
569
570 A `Docker <https://www.docker.com/>`__ container with netopeer will be
571 used in this guide. To install Docker and start the `netopeer
572 image <https://index.docker.io/u/dockeruser/netopeer/>`__ perform
573 following steps:
574
575 1. Install docker http://docs.docker.com/linux/step_one/
576
577 2. Start the netopeer image:
578
579    ::
580
581        docker run -rm -t -p 1831:830 dockeruser/netopeer
582
583 3. Verify netopeer is running by invoking (netopeer should send its
584    HELLO message right away:
585
586    ::
587
588        ssh root@localhost -p 1831 -s netconf
589        (password root)
590
591 Mounting netopeer NETCONF server
592 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
593
594 Preconditions:
595
596 -  OpenDaylight is started with features ``odl-restconf-all`` and
597    ``odl-netconf-connector-all``.
598
599 -  Netopeer is up and running in docker
600
601 Now just follow the chapter: `Spawning
602 netconf-connector <#_spawning_additional_netconf_connectors_while_the_controller_is_running>`__.
603 In the payload change the:
604
605 -  name, e.g., to netopeer
606
607 -  username/password to your system credentials
608
609 -  ip to localhost
610
611 -  port to 1831.
612
613 After netopeer is mounted successfully, its configuration can be read
614 using RESTCONF by invoking:
615
616 GET
617 http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/netopeer/yang-ext:mount/
618
619 Northbound (NETCONF servers)
620 ----------------------------
621
622 OpenDaylight provides 2 types of NETCONF servers:
623
624 -  **NETCONF server for config-subsystem (listening by default on port
625    1830)**
626
627    -  Serves as a default interface for config-subsystem and allows
628       users to spawn/reconfigure/destroy modules (or applications) in
629       OpenDaylight
630
631 -  **NETCONF server for MD-SAL (listening by default on port 2830)**
632
633    -  Serves as an alternative interface for MD-SAL (besides RESTCONF)
634       and allows users to read/write data from MD-SAL’s datastore and to
635       invoke its rpcs (NETCONF notifications are not available in the
636       Boron release of OpenDaylight)
637
638 .. note::
639
640     The reason for having 2 NETCONF servers is that config-subsystem and
641     MD-SAL are 2 different components of OpenDaylight and require
642     different approach for NETCONF message handling and data
643     translation. These 2 components will probably merge in the future.
644
645 .. note::
646
647     Since Nitrogen release, there is performance regression in NETCONF
648     servers accepting SSH connections. While opening a connection takes
649     less than 10 seconds on Carbon, on Nitrogen time can increase up to
650     60 seconds. Please see https://bugs.opendaylight.org/show_bug.cgi?id=9020
651
652 NETCONF server for config-subsystem
653 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
654
655 This NETCONF server is the primary interface for config-subsystem. It
656 allows the users to interact with config-subsystem in a standardized
657 NETCONF manner.
658
659 In terms of RFCs, these are supported:
660
661 -  `RFC-6241 <http://tools.ietf.org/html/rfc6241>`__
662
663 -  `RFC-5277 <https://tools.ietf.org/html/rfc5277>`__
664
665 -  `RFC-6470 <https://tools.ietf.org/html/rfc6470>`__
666
667    -  (partially, only the schema-change notification is available in
668       Boron release)
669
670 -  `RFC-6022 <https://tools.ietf.org/html/rfc6022>`__
671
672 For regular users it is recommended to use RESTCONF + the
673 controller-config loopback mountpoint instead of using pure NETCONF. How
674 to do that is spesific for each component/module/application in
675 OpenDaylight and can be found in their dedicated user guides.
676
677 NETCONF server for MD-SAL
678 ~~~~~~~~~~~~~~~~~~~~~~~~~
679
680 This NETCONF server is just a generic interface to MD-SAL in
681 OpenDaylight. It uses the stadard MD-SAL APIs and serves as an
682 alternative to RESTCONF. It is fully model driven and supports any data
683 and rpcs that are supported by MD-SAL.
684
685 In terms of RFCs, these are supported:
686
687 -  `RFC-6241 <http://tools.ietf.org/html/rfc6241>`__
688
689 -  `RFC-6022 <https://tools.ietf.org/html/rfc6022>`__
690
691 -  `draft-ietf-netconf-yang-library-06 <https://tools.ietf.org/html/draft-ietf-netconf-yang-library-06>`__
692
693 Notifications over NETCONF are not supported in the Boron release.
694
695 .. tip::
696
697     Install NETCONF northbound for MD-SAL by installing feature:
698     ``odl-netconf-mdsal`` in karaf. Default binding port is **2830**.
699
700 Configuration
701 ^^^^^^^^^^^^^
702
703 The default configuration can be found in file: *08-netconf-mdsal.xml*.
704 The file contains the configuration for all necessary dependencies and a
705 single SSH endpoint starting on port 2830. There is also a (by default
706 disabled) TCP endpoint. It is possible to start multiple endpoints at
707 the same time either in the initial configuration file or while
708 OpenDaylight is running.
709
710 The credentials for SSH endpoint can also be configured here, the
711 defaults are admin/admin. Credentials in the SSH endpoint are not yet
712 managed by the centralized AAA component and have to be configured
713 separately.
714
715 Verifying MD-SAL’s NETCONF server
716 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
717
718 After the NETCONF server is available it can be examined by a command
719 line ssh tool:
720
721 ::
722
723     ssh admin@localhost -p 2830 -s netconf
724
725 The server will respond by sending its HELLO message and can be used as
726 a regular NETCONF server from then on.
727
728 Mounting the MD-SAL’s NETCONF server
729 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
730
731 To perform this operation, just spawn a new netconf-connector as
732 described in `Spawning
733 netconf-connector <#_spawning_additional_netconf_connectors_while_the_controller_is_running>`__.
734 Just change the ip to "127.0.0.1" port to "2830" and its name to
735 "controller-mdsal".
736
737 Now the MD-SAL’s datastore can be read over RESTCONF via NETCONF by
738 invoking:
739
740 GET
741 http://localhost:8181/restconf/operational/network-topology:network-topology/topology/topology-netconf/node/controller-mdsal/yang-ext:mount
742
743 .. note::
744
745     This might not seem very useful, since MD-SAL can be accessed
746     directly from RESTCONF or from Application code, but the same method
747     can be used to mount and control other OpenDaylight instances by the
748     "master OpenDaylight".
749
750 NETCONF testtool
751 ----------------
752
753 **NETCONF testtool is a set of standalone runnable jars that can:**
754
755 -  Simulate NETCONF devices (suitable for scale testing)
756
757 -  Stress/Performance test NETCONF devices
758
759 -  Stress/Performance test RESTCONF devices
760
761 These jars are part of OpenDaylight’s controller project and are built
762 from the NETCONF codebase in OpenDaylight.
763
764 .. tip::
765
766     Download testtool from OpenDaylight Nexus at:
767     https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/netconf/netconf-testtool/1.1.0-Boron/
768
769 **Nexus contains 3 executable tools:**
770
771 -  executable.jar - device simulator
772
773 -  stress.client.tar.gz - NETCONF stress/performance measuring tool
774
775 -  perf-client.jar - RESTCONF stress/performance measuring tool
776
777 .. tip::
778
779     Each executable tool provides help. Just invoke ``java -jar
780     <name-of-the-tool.jar> --help``
781
782 NETCONF device simulator
783 ~~~~~~~~~~~~~~~~~~~~~~~~
784
785 NETCONF testtool (or NETCONF device simulator) is a tool that
786
787 -  Simulates 1 or more NETCONF devices
788
789 -  Is suitable for scale, performance or crud testing
790
791 -  Uses core implementation of NETCONF server from OpenDaylight
792
793 -  Generates configuration files for controller so that the OpenDaylight
794    distribution (Karaf) can easily connect to all simulated devices
795
796 -  Provides broad configuration options
797
798 -  Can start a fully fledged MD-SAL datastore
799
800 -  Supports notifications
801
802 Building testtool
803 ^^^^^^^^^^^^^^^^^
804
805 1. Check out latest NETCONF repository from
806    `git <https://git.opendaylight.org/gerrit/#/admin/projects/netconf>`__
807
808 2. Move into the ``opendaylight/netconf/tools/netconf-testtool/`` folder
809
810 3. Build testtool using the ``mvn clean install`` command
811
812 Downloading testtool
813 ^^^^^^^^^^^^^^^^^^^^
814
815 Netconf-testtool is now part of default maven build profile for
816 controller and can be also downloaded from nexus. The executable jar for
817 testtool can be found at:
818 `nexus-artifacts <https://nexus.opendaylight.org/content/repositories/public/org/opendaylight/netconf/netconf-testtool/1.1.0-Boron/>`__
819
820 Running testtool
821 ^^^^^^^^^^^^^^^^
822
823 1. After successfully building or downloading, move into the
824    ``opendaylight/netconf/tools/netconf-testtool/target/`` folder and
825    there is file ``netconf-testtool-1.1.0-SNAPSHOT-executable.jar`` (or
826    if downloaded from nexus just take that jar file)
827
828 2. Execute this file using, e.g.:
829
830    ::
831
832        java -jar netconf-testtool-1.1.0-SNAPSHOT-executable.jar
833
834    This execution runs the testtool with default for all parameters and
835    you should see this log output from the testtool :
836
837    ::
838
839        10:31:08.206 [main] INFO  o.o.c.n.t.t.NetconfDeviceSimulator - Starting 1, SSH simulated devices starting on port 17830
840        10:31:08.675 [main] INFO  o.o.c.n.t.t.NetconfDeviceSimulator - All simulated devices started successfully from port 17830 to 17830
841
842 Default Parameters
843 ''''''''''''''''''
844
845 The default parameters for testtool are:
846
847 -  Use SSH
848
849 -  Run 1 simulated device
850
851 -  Device port is 17830
852
853 -  YANG modules used by device are only: ietf-netconf-monitoring,
854    ietf-yang-types, ietf-inet-types (these modules are required for
855    device in order to support NETCONF monitoring and are included in the
856    netconf-testtool)
857
858 -  Connection timeout is set to 30 minutes (quite high, but when testing
859    with 10000 devices it might take some time for all of them to fully
860    establish a connection)
861
862 -  Debug level is set to false
863
864 -  No distribution is modified to connect automatically to the NETCONF
865    testtool
866
867 Verifying testtool
868 ^^^^^^^^^^^^^^^^^^
869
870 To verify that the simulated device is up and running, we can try to
871 connect to it using command line ssh tool. Execute this command to
872 connect to the device:
873
874 ::
875
876     ssh admin@localhost -p 17830 -s netconf
877
878 Just accept the server with yes (if required) and provide any password
879 (testtool accepts all users with all passwords). You should see the
880 hello message sent by simulated device.
881
882 Testtool help
883 ^^^^^^^^^^^^^
884
885 ::
886
887     usage: netconf testtool [-h] [--edit-content EDIT-CONTENT] [--async-requests {true,false}] [--thread-amount THREAD-AMOUNT] [--throttle THROTTLE]
888                             [--auth AUTH AUTH] [--controller-destination CONTROLLER-DESTINATION] [--device-count DEVICES-COUNT]
889                             [--devices-per-port DEVICES-PER-PORT] [--schemas-dir SCHEMAS-DIR] [--notification-file NOTIFICATION-FILE]
890                             [--initial-config-xml-file INITIAL-CONFIG-XML-FILE] [--starting-port STARTING-PORT]
891                             [--generate-config-connection-timeout GENERATE-CONFIG-CONNECTION-TIMEOUT]
892                             [--generate-config-address GENERATE-CONFIG-ADDRESS] [--generate-configs-batch-size GENERATE-CONFIGS-BATCH-SIZE]
893                             [--distribution-folder DISTRO-FOLDER] [--ssh {true,false}] [--exi {true,false}] [--debug {true,false}]
894                             [--md-sal {true,false}] [--time-out TIME-OUT] [-ip IP] [--thread-pool-size THREAD-POOL-SIZE] [--rpc-config RPC-CONFIG]
895
896     netconf testtool
897
898     named arguments:
899       -h, --help             show this help message and exit
900       --edit-content EDIT-CONTENT
901       --async-requests {true,false}
902       --thread-amount THREAD-AMOUNT
903                              The number of threads to use for configuring devices.
904       --throttle THROTTLE    Maximum amount of async requests that can be open at a time, with mutltiple threads this gets divided among all threads
905       --auth AUTH AUTH       Username and password for HTTP basic authentication in order username password.
906       --controller-destination CONTROLLER-DESTINATION
907                              Ip address and port of controller. Must  be  in  following  format  <ip>:<port>  if  available it will be used for spawning
908                              netconf   connectors    via    topology    configuration    as    a    part    of    URI.    Example    (http://<controller
909                              destination>/restconf/config/network-topology:network-topology/topology/topology-netconf/node/<node-id>)otherwise  it  will
910                              just start simulated devices and skip the execution of PUT requests
911       --device-count DEVICES-COUNT
912                              Number of simulated netconf devices to spin. This is the number of actual ports open for the devices.
913       --devices-per-port DEVICES-PER-PORT
914                              Amount of config files generated per port to spoof more devices than are actually running
915       --schemas-dir SCHEMAS-DIR
916                              Directory containing yang schemas to describe simulated devices.  Some  schemas  e.g. netconf monitoring and inet types are
917                              included by default
918       --notification-file NOTIFICATION-FILE
919                              Xml file containing notifications that should be sent to clients after create subscription is called
920       --initial-config-xml-file INITIAL-CONFIG-XML-FILE
921                              Xml file containing initial simulatted configuration to be returned via get-config rpc
922       --starting-port STARTING-PORT
923                              First port for simulated device. Each other device will have previous+1 port number
924       --generate-config-connection-timeout GENERATE-CONFIG-CONNECTION-TIMEOUT
925                              Timeout to be generated in initial config files
926       --generate-config-address GENERATE-CONFIG-ADDRESS
927                              Address to be placed in generated configs
928       --generate-configs-batch-size GENERATE-CONFIGS-BATCH-SIZE
929                              Number of connector configs per generated file
930       --distribution-folder DISTRO-FOLDER
931                              Directory where the karaf distribution for controller is located
932       --ssh {true,false}     Whether to use ssh for transport or just pure tcp
933       --exi {true,false}     Whether to use exi to transport xml content
934       --debug {true,false}   Whether to use debug log level instead of INFO
935       --md-sal {true,false}  Whether to use md-sal datastore instead of default simulated datastore.
936       --time-out TIME-OUT    the maximum time in seconds for executing each PUT request
937       -ip IP                 Ip address which will be used for creating a socket  address.It  can  either  be a machine name, such as java.sun.com, or a
938                              textual representation of its IP address.
939       --thread-pool-size THREAD-POOL-SIZE
940                              The number of threads to keep in the pool, when creating a device simulator. Even if they are idle.
941       --rpc-config RPC-CONFIG
942                              Rpc config file. It can be used to define custom rpc  behavior, or override the default one.Usable for testing buggy device
943                              behavior.
944
945
946 Supported operations
947 ^^^^^^^^^^^^^^^^^^^^
948
949 Testtool default simple datastore supported operations:
950
951 get-schema
952     returns YANG schemas loaded from user specified directory,
953
954 edit-config
955     always returns OK and stores the XML from the input in a local
956     variable available for get-config and get RPC. Every edit-config
957     replaces the previous data,
958
959 commit
960     always returns OK, but does not actually commit the data,
961
962 get-config
963     returns local XML stored by edit-config,
964
965 get
966     returns local XML stored by edit-config with netconf-state subtree,
967     but also supports filtering.
968
969 (un)lock
970     returns always OK with no lock guarantee
971
972 create-subscription
973     returns always OK and after the operation is triggered, provided
974     NETCONF notifications (if any) are fed to the client. No filtering
975     or stream recognition is supported.
976
977 Note: when operation="delete" is present in the payload for edit-config,
978 it will wipe its local store to simulate the removal of data.
979
980 When using the MD-SAL datastore testtool behaves more like normal
981 NETCONF server and is suitable for crud testing. create-subscription is
982 not supported when testtool is running with the MD-SAL datastore.
983
984 Notification support
985 ^^^^^^^^^^^^^^^^^^^^
986
987 Testtool supports notifications via the --notification-file switch. To
988 trigger the notification feed, create-subscription operation has to be
989 invoked. The XML file provided should look like this example file:
990
991 ::
992
993     <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
994     <notifications>
995
996     <!-- Notifications are processed in the order they are defined in XML -->
997
998     <!-- Notification that is sent only once right after create-subscription is called -->
999     <notification>
1000         <!-- Content of each notification entry must contain the entire notification with event time. Event time can be hardcoded, or generated by testtool if XXXX is set as eventtime in this XML -->
1001         <content><![CDATA[
1002             <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
1003                 <eventTime>2011-01-04T12:30:46</eventTime>
1004                 <random-notification xmlns="http://www.opendaylight.org/netconf/event:1.0">
1005                     <random-content>single no delay</random-content>
1006                 </random-notification>
1007             </notification>
1008         ]]></content>
1009     </notification>
1010
1011     <!-- Repeated Notification that is sent 5 times with 2 second delay inbetween -->
1012     <notification>
1013         <!-- Delay in seconds from previous notification -->
1014         <delay>2</delay>
1015         <!-- Number of times this notification should be repeated -->
1016         <times>5</times>
1017         <content><![CDATA[
1018             <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
1019                 <eventTime>XXXX</eventTime>
1020                 <random-notification xmlns="http://www.opendaylight.org/netconf/event:1.0">
1021                     <random-content>scheduled 5 times 10 seconds each</random-content>
1022                 </random-notification>
1023             </notification>
1024         ]]></content>
1025     </notification>
1026
1027     <!-- Single notification that is sent only once right after the previous notification -->
1028     <notification>
1029         <delay>2</delay>
1030         <content><![CDATA[
1031             <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
1032                 <eventTime>XXXX</eventTime>
1033                 <random-notification xmlns="http://www.opendaylight.org/netconf/event:1.0">
1034                     <random-content>single with delay</random-content>
1035                 </random-notification>
1036             </notification>
1037         ]]></content>
1038     </notification>
1039
1040     </notifications>
1041
1042 Connecting testtool with controller Karaf distribution
1043 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1044
1045 Auto connect to OpenDaylight
1046 ''''''''''''''''''''''''''''
1047
1048 It is possible to make OpenDaylight auto connect to the simulated
1049 devices spawned by testtool (so user does not have to post a
1050 configuration for every NETCONF connector via RESTCONF). The testtool is
1051 able to modify the OpenDaylight distribution to auto connect to the
1052 simulated devices after feature ``odl-netconf-connector-all`` is
1053 installed. When running testtool, issue this command (just point the
1054 testool to the distribution:
1055
1056 ::
1057
1058     java -jar netconf-testtool-1.1.0-SNAPSHOT-executable.jar --device-count 10 --distribution-folder ~/distribution-karaf-0.4.0-SNAPSHOT/ --debug true
1059
1060 With the distribution-folder parameter, the testtool will modify the
1061 distribution to include configuration for netconf-connector to connect
1062 to all simulated devices. So there is no need to spawn
1063 netconf-connectors via RESTCONF.
1064
1065 Running testtool and OpenDaylight on different machines
1066 '''''''''''''''''''''''''''''''''''''''''''''''''''''''
1067
1068 The testtool binds by default to 0.0.0.0 so it should be accessible from
1069 remote machines. However you need to set the parameter
1070 "generate-config-address" (when using autoconnect) to the address of
1071 machine where testtool will be run so OpenDaylight can connect. The
1072 default value is localhost.
1073
1074 Executing operations via RESTCONF on a mounted simulated device
1075 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1076
1077 Simulated devices support basic RPCs for editing their config. This part
1078 shows how to edit data for simulated device via RESTCONF.
1079
1080 Test YANG schema
1081 ''''''''''''''''
1082
1083 The controller and RESTCONF assume that the data that can be manipulated
1084 for mounted device is described by a YANG schema. For demonstration, we
1085 will define a simple YANG model:
1086
1087 ::
1088
1089     module test {
1090         yang-version 1;
1091         namespace "urn:opendaylight:test";
1092         prefix "tt";
1093
1094         revision "2014-10-17";
1095
1096
1097        container cont {
1098
1099             leaf l {
1100                 type string;
1101             }
1102        }
1103     }
1104
1105 Save this schema in file called test@2014-10-17.yang and store it a
1106 directory called test-schemas/, e.g., your home folder.
1107
1108 Editing data for simulated device
1109 '''''''''''''''''''''''''''''''''
1110
1111 -  Start the device with following command:
1112
1113    ::
1114
1115        java -jar netconf-testtool-1.1.0-SNAPSHOT-executable.jar --device-count 10 --distribution-folder ~/distribution-karaf-0.4.0-SNAPSHOT/ --debug true --schemas-dir ~/test-schemas/
1116
1117 -  Start OpenDaylight
1118
1119 -  Install odl-netconf-connector-all feature
1120
1121 -  Install odl-restconf feature
1122
1123 -  Check that you can see config data for simulated device by executing
1124    GET request to
1125
1126    ::
1127
1128        http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/17830-sim-device/yang-ext:mount/
1129
1130 -  The data should be just and empty data container
1131
1132 -  Now execute edit-config request by executing a POST request to:
1133
1134    ::
1135
1136        http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/17830-sim-device/yang-ext:mount
1137
1138    with headers:
1139
1140    ::
1141
1142        Accept application/xml
1143        Content-Type application/xml
1144
1145    and payload:
1146
1147    ::
1148
1149        <cont xmlns="urn:opendaylight:test">
1150          <l>Content</l>
1151        </cont>
1152
1153 -  Check that you can see modified config data for simulated device by
1154    executing GET request to
1155
1156    ::
1157
1158        http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/17830-sim-device/yang-ext:mount/
1159
1160 -  Check that you can see the same modified data in operational for
1161    simulated device by executing GET request to
1162
1163    ::
1164
1165        http://localhost:8181/restconf/operational/network-topology:network-topology/topology/topology-netconf/node/17830-sim-device/yang-ext:mount/
1166
1167 .. warning::
1168
1169     Data will be mirrored in operational datastore only when using the
1170     default simple datastore.
1171
1172
1173 Testing User defined RPC
1174 ^^^^^^^^^^^^^^^^^^^^^^^^
1175
1176 The NETCONF test-tool allows using custom RPC. Custom RPC needs to be defined in yang model provide to test-tool along
1177 with parameter ``--schemas-dir``.
1178
1179 The input and output of the custom RPC should be provided with ``--rpc-config`` parameter as a path to the file containing
1180 definition of input and output. The format of the custom RPC file is xml as shown below.
1181
1182 Start the device with following command:
1183
1184 ::
1185
1186     java -jar netconf/tools/netconf-testtool/target/netconf-testtool-1.7.0-SNAPSHOT-executable.jar --schemas-dir ~/test-schemas/ --rpc-config ~/tmp/customrpc.xml --debug=true
1187
1188 Example YANG model file:
1189
1190 ::
1191
1192     module example-ops {
1193          namespace "urn:example-ops:reboot";
1194          prefix "ops";
1195
1196         import ietf-yang-types {
1197         prefix "yang";
1198          }
1199
1200
1201          revision "2016-07-07" {
1202            description "Initial version.";
1203            reference "example document.";
1204          }
1205
1206
1207          rpc reboot {
1208            description "Reboot operation.";
1209            input {
1210              leaf delay {
1211                type uint32;
1212                units "seconds";
1213                default 0;
1214                description
1215                  "Delay in seconds.";
1216              }
1217              leaf message {
1218                type string;
1219                description
1220                  "Log message.";
1221              }
1222            }
1223          }
1224        }
1225
1226
1227 Example payload (RPC config file customrpc.xml):
1228
1229 ::
1230
1231     <rpcs>
1232       <rpc>
1233         <input>
1234           <reboot xmlns="urn:example-ops:reboot">
1235             <delay>300</delay>
1236             <message>message</message>
1237           </reboot>
1238         </input>
1239         <output>
1240           <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
1241             <ok/>
1242           </rpc-reply>
1243         </output>
1244       </rpc>
1245     </rpcs>
1246
1247
1248
1249 Example of use:
1250
1251 ::
1252
1253     POST http://localhost:8181/restconf/operations/network-topology:network-topology/topology/topology-netconf/node/new-netconf-device/yang-ext:mount/example-ops:get-reboot-info
1254
1255 If successful the command will return code 200.
1256
1257
1258
1259 .. note::
1260
1261     A working example of user defined RPC can be found in TestToolTest.java class of the tools[netconf-testtool] project.
1262
1263
1264 Known problems
1265 ^^^^^^^^^^^^^^
1266
1267 Slow creation of devices on virtual machines
1268 ''''''''''''''''''''''''''''''''''''''''''''
1269
1270 When testtool seems to take unusually long time to create the devices
1271 use this flag when running it:
1272
1273 ::
1274
1275     -Dorg.apache.sshd.registerBouncyCastle=false
1276
1277 Too many files open
1278 '''''''''''''''''''
1279
1280 When testtool or OpenDaylight starts to fail with TooManyFilesOpen
1281 exception, you need to increase the limit of open files in your OS. To
1282 find out the limit in linux execute:
1283
1284 ::
1285
1286     ulimit -a
1287
1288 Example sufficient configuration in linux:
1289
1290 ::
1291
1292     core file size          (blocks, -c) 0
1293     data seg size           (kbytes, -d) unlimited
1294     scheduling priority             (-e) 0
1295     file size               (blocks, -f) unlimited
1296     pending signals                 (-i) 63338
1297     max locked memory       (kbytes, -l) 64
1298     max memory size         (kbytes, -m) unlimited
1299     open files                      (-n) 500000
1300     pipe size            (512 bytes, -p) 8
1301     POSIX message queues     (bytes, -q) 819200
1302     real-time priority              (-r) 0
1303     stack size              (kbytes, -s) 8192
1304     cpu time               (seconds, -t) unlimited
1305     max user processes              (-u) 63338
1306     virtual memory          (kbytes, -v) unlimited
1307     file locks                      (-x) unlimited
1308
1309 To set these limits edit file: /etc/security/limits.conf, for example:
1310
1311 ::
1312
1313     *         hard    nofile      500000
1314     *         soft    nofile      500000
1315     root      hard    nofile      500000
1316     root      soft    nofile      500000
1317
1318 "Killed"
1319 ''''''''
1320
1321 The testtool might end unexpectedly with a simple message: "Killed".
1322 This means that the OS killed the tool due to too much memory consumed
1323 or too many threads spawned. To find out the reason on linux you can use
1324 following command:
1325
1326 ::
1327
1328     dmesg | egrep -i -B100 'killed process'
1329
1330 Also take a look at this file: /proc/sys/kernel/threads-max. It limits
1331 the number of threads spawned by a process. Sufficient (but probably
1332 much more than enough) value is, e.g., 126676
1333
1334 NETCONF stress/performance measuring tool
1335 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1336
1337 This is basically a NETCONF client that puts NETCONF servers under heavy
1338 load of NETCONF RPCs and measures the time until a configurable amount
1339 of them is processed.
1340
1341 RESTCONF stress-performance measuring tool
1342 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1343
1344 Very similar to NETCONF stress tool with the difference of using
1345 RESTCONF protocol instead of NETCONF.
1346
1347 YANGLIB remote repository
1348 -------------------------
1349
1350 There are scenarios in NETCONF deployment, that require for a centralized
1351 YANG models repository. YANGLIB plugin provides such remote repository.
1352
1353 To start this plugin, you have to install odl-yanglib feature. Then you
1354 have to configure YANGLIB either through RESTCONF or NETCONF. We will
1355 show how to configure YANGLIB through RESTCONF.
1356
1357 YANGLIB configuration through RESTCONF
1358 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1359
1360 You have to specify what local YANG modules directory you want to provide.
1361 Then you have to specify address and port whre you want to provide YANG
1362 sources. For example, we want to serve yang sources from folder /sources
1363 on localhost:5000 adress. The configuration for this scenario will be
1364 as follows:
1365
1366 ::
1367
1368     PUT  http://localhost:8181/restconf/config/network-topology:network-topology/topology/topology-netconf/node/controller-config/yang-ext:mount/config:modules/module/yanglib:yanglib/example
1369
1370 Headers:
1371
1372 -  Accept: application/xml
1373
1374 -  Content-Type: application/xml
1375
1376 Payload:
1377
1378 ::
1379
1380    <module xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
1381      <name>example</name>
1382      <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl">prefix:yanglib</type>
1383      <broker xmlns="urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl">
1384        <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">prefix:binding-broker-osgi-registry</type>
1385        <name>binding-osgi-broker</name>
1386      </broker>
1387      <cache-folder xmlns="urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl">/sources</cache-folder>
1388      <binding-addr xmlns="urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl">localhost</binding-addr>
1389      <binding-port xmlns="urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl">5000</binding-port>
1390    </module>
1391
1392 This should result in a 2xx response and new YANGLIB instance should be
1393 created. This YANGLIB takes all YANG sources from /sources folder and
1394 for each generates URL in form:
1395
1396 ::
1397
1398     http://localhost:5000/schemas/{modelName}/{revision}
1399
1400 On this URL will be hosted YANG source for particular module.
1401
1402 YANGLIB instance also write this URL along with source identifier to
1403 ietf-netconf-yang-library/modules-state/module list.
1404
1405 Netconf-connector with YANG library as fallback
1406 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1407
1408 There is an optional configuration in netconf-connector called
1409 yang-library. You can specify YANG library to be plugged as additional
1410 source provider into the mount's schema repository. Since YANGLIB
1411 plugin is advertising provided modules through yang-library model, we
1412 can use it in mount point's configuration as YANG library.  To do this,
1413 we need to modify the configuration of netconf-connector by adding this
1414 XML
1415
1416 ::
1417
1418     <yang-library xmlns="urn:opendaylight:netconf-node-topology">
1419       <yang-library-url xmlns="urn:opendaylight:netconf-node-topology">http://localhost:8181/restconf/operational/ietf-yang-library:modules-state</yang-library-url>
1420       <username xmlns="urn:opendaylight:netconf-node-topology">admin</username>
1421       <password xmlns="urn:opendaylight:netconf-node-topology">admin</password>
1422     </yang-library>
1423
1424 This will register YANGLIB provided sources as a fallback schemas for
1425 particular mount point.
1426
1427 NETCONF Call Home
1428 -----------------
1429
1430 .. important::
1431
1432     The call home feature is experimental and will change in a future
1433     release. In particular, the Yang models will change to those specified
1434     in the `RFC 8071 <https://tools.ietf.org/html/rfc8071>`__
1435
1436 Call Home Installation
1437 ~~~~~~~~~~~~~~~~~~~~~~
1438
1439 ODL Call-Home server is installed in Karaf by installing karaf feature
1440 ``odl-netconf-callhome-ssh``. RESTCONF feature is recommended for
1441 configuring Call Home & testing its functionality.
1442
1443 ::
1444
1445   feature:install odl-netconf-callhome-ssh
1446
1447
1448 .. note::
1449
1450     In order to test Call Home functionality we recommend Netopeer.
1451     See `Netopeer Call Home <https://github.com/CESNET/netopeer/wiki/CallHome>`__ to learn how to enable call-home on Netopeer.
1452
1453 Northbound Call-Home API
1454 ~~~~~~~~~~~~~~~~~~~~~~~~
1455
1456 The northbound Call Home API is used for administering the Call-Home Server. The
1457 following describes this configuration.
1458
1459 Global Configuration
1460 ^^^^^^^^^^^^^^^^^^^^
1461
1462 Configuring global credentials
1463 ''''''''''''''''''''''''''''''
1464
1465 ODL Call-Home server allows user to configure global credentials, which
1466 will be used for devices which does not have device-specific credentials
1467 configured.
1468
1469 This is done by creating
1470 ``/odl-netconf-callhome-server:netconf-callhome-server/global/credentials``
1471 with username and passwords specified.
1472
1473 *Configuring global username & passwords to try*
1474
1475 .. code-block:: none
1476
1477     PUT
1478     /restconf/config/odl-netconf-callhome-server:netconf-callhome-server/global/credentials HTTP/1.1
1479     Content-Type: application/json
1480     Accept: application/json
1481
1482 .. code-block:: json
1483
1484     {
1485       "credentials":
1486       {
1487         "username": "example",
1488         "passwords": [ "first-password-to-try", "second-password-to-try" ]
1489       }
1490     }
1491
1492 Configuring to accept any ssh server key using global credentials
1493 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1494
1495 By default Netconf Call-Home Server accepts only incoming connections
1496 from allowed devices
1497 ``/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices``,
1498 if user desire to allow all incoming connections, it is possible to set
1499 ``accept-all-ssh-keys`` to ``true`` in
1500 ``/odl-netconf-callhome-server:netconf-callhome-server/global``.
1501
1502 The name of this devices in ``netconf-topology`` will be in format
1503 ``ip-address:port``. For naming devices see Device-Specific
1504 Configuration.
1505
1506 *Allowing unknown devices to connect*
1507
1508 This is a debug feature and should not be used in production. Besides being an obvious
1509 security issue, this also causes the Call-Home Server to drastically increase its output
1510 to the log.
1511
1512 .. code-block:: none
1513
1514     POST
1515     /restconf/config/odl-netconf-callhome-server:netconf-callhome-server/global HTTP/1.1
1516     Content-Type: application/json
1517     Accept: application/json
1518
1519 .. code-block:: json
1520
1521     {
1522       "global": {
1523         "accept-all-ssh-keys": "true"
1524       }
1525     }
1526
1527 Device-Specific Configuration
1528 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1529
1530 Allowing Device & Configuring Name
1531 ''''''''''''''''''''''''''''''''''
1532
1533 Netconf Call Home Server uses device provided SSH server key (host key)
1534 to identify device. The pairing of name and server key is configured in
1535 ``/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices``.
1536 This list is colloquially called a whitelist.
1537
1538 If the Call-Home Server finds the SSH host key in the whitelist, it continues
1539 to negotiate a NETCONF connection over an SSH session. If the SSH host key is
1540 not found, the connection between the Call Home server and the device is dropped
1541 immediately. In either case, the device that connects to the Call home server
1542 leaves a record of its presence in the operational store.
1543
1544 *Example of configuring device*
1545
1546 .. code-block:: none
1547
1548     PUT
1549     /restconf/config/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device/example HTTP/1.1
1550     Content-Type: application/json
1551     Accept: application/json
1552
1553 .. code-block:: json
1554
1555     {
1556       "device": {
1557         "unique-id": "example",
1558         "ssh-host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1559       }
1560     }
1561
1562 Configuring Device with Device-specific Credentials
1563 '''''''''''''''''''''''''''''''''''''''''''''''''''
1564
1565 Call Home Server also allows to configure credentials per device basis,
1566 this is done by introducing ``credentials`` container into
1567 device-specific configuration. Format is same as in global credentials.
1568
1569 *Configuring Device with Credentials*
1570
1571 .. code-block:: none
1572
1573     PUT
1574     /restconf/config/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device/example HTTP/1.1
1575     Content-Type: application/json
1576     Accept: application/json
1577
1578 .. code-block:: json
1579
1580     {
1581       "device": {
1582         "unique-id": "example",
1583         "credentials": {
1584           "username": "example",
1585           "passwords": [ "password" ]
1586         },
1587         "ssh-host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1588       }
1589     }
1590
1591 Operational Status
1592 ^^^^^^^^^^^^^^^^^^
1593
1594 Once an entry is made into the config side of "allowed-devices", the Call-Home Server will
1595 populate an corresponding operational device that is the same as the config device but
1596 has an additional status. By default, this status is *DISCONNECTED*. Once a device calls
1597 home, this status will change to one of:
1598
1599 *CONNECTED* — The device is currently connected and the NETCONF mount is available for network
1600 management.
1601
1602 *FAILED_AUTH_FAILURE* — The last attempted connection was unsuccessful because the Call-Home
1603 Server was unable to provide the acceptable credentials of the device. The device is also
1604 disconnected and not available for network management.
1605
1606 *FAILED_NOT_ALLOWED* — The last attempted connection was unsuccessful because the device was
1607 not recognized as an acceptable device. The device is also disconnected and not available for
1608 network management.
1609
1610 *FAILED* — The last attempted connection was unsuccessful for a reason other than not
1611 allowed to connect or incorrect client credentials. The device is also disconnected and not
1612 available for network management.
1613
1614 *DISCONNECTED* — The device is currently disconnected.
1615
1616 Rogue Devices
1617 '''''''''''''
1618
1619 Devices which are not on the whitelist might try to connect to the Call-Home Server. In
1620 these cases, the server will keep a record by instantiating an operational device. There
1621 will be no corresponding config device for these rogues. They can be identified readily
1622 because their device id, rather than being user-supplied, will be of the form
1623 "address:port". Note that if a device calls back multiple times, there will only be
1624 a single operatinal entry (even if the port changes); these devices are recognized by
1625 their unique host key.
1626
1627 Southbound Call-Home API
1628 ~~~~~~~~~~~~~~~~~~~~~~~~
1629
1630 The Call-Home Server listens for incoming TCP connections and assumes that the other side of
1631 the connection is a device calling home via a NETCONF connection with SSH for
1632 management. The server uses port 6666 by default and this can be configured via a
1633 blueprint configuration file.
1634
1635 The device **must** initiate the connection and the server will not try to re-establish the
1636 connection in case of a drop. By requirement, the server cannot assume it has connectivity
1637 to the device due to NAT or firewalls among others.