Update NETCONF user guide
[netconf.git] / docs / user-guide.rst
1 .. _netconf-user-guide:
2
3 .. |ss| raw:: html
4
5    <strike>
6
7 .. |se| raw:: html
8
9    </strike>
10
11 NETCONF User Guide
12 ==================
13
14 Overview
15 --------
16
17 NETCONF is an XML-based protocol used for configuration and monitoring
18 devices in the network. The base NETCONF protocol is described in
19 `RFC-6241 <http://tools.ietf.org/html/rfc6241>`__.
20
21 **NETCONF in OpenDaylight:.**
22
23 OpenDaylight supports the NETCONF protocol as a northbound server as
24 well as a southbound plugin. It also includes a set of test tools for
25 simulating NETCONF devices and clients.
26
27 Southbound (netconf-connector)
28 ------------------------------
29
30 The NETCONF southbound plugin is capable of connecting to remote NETCONF
31 devices and exposing their configuration/operational datastores, RPCs
32 and notifications as MD-SAL mount points. These mount points allow
33 applications and remote users (over RESTCONF) to interact with the
34 mounted devices.
35
36 In terms of RFCs, the connector supports:
37
38 -  `RFC-6241 <http://tools.ietf.org/html/rfc6241>`__
39
40 -  `RFC-5277 <https://tools.ietf.org/html/rfc5277>`__
41
42 -  `RFC-6022 <https://tools.ietf.org/html/rfc6022>`__
43
44 -  `RFC-7895 <https://tools.ietf.org/html/rfc7895>`__
45
46 **Netconf-connector is fully model-driven (utilizing the YANG modeling
47 language) so in addition to the above RFCs, it supports any
48 data/RPC/notifications described by a YANG model that is implemented by
49 the device.**
50
51 .. tip::
52
53     NETCONF southbound can be activated by installing
54     ``odl-netconf-connector-all`` Karaf feature.
55
56 Netconf-connector configuration
57 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58
59 NETCONF connectors are configured directly through the usage of the
60 network-topology model. You can configure new NETCONF connectors both
61 through the NETCONF server for MD-SAL (port 2830) or RESTCONF. This guide
62 focuses on RESTCONF.
63
64 .. important::
65
66     Since 2022.09 Chlorine there is only one RESTCONF endpoint:
67
68     - | ``http://localhost:8181/rests`` is related to `RFC-8040 <https://tools.ietf.org/html/rfc8040>`__,
69       | can be activated by installing ``odl-restconf-nb``
70        Karaf feature.
71
72     | Resources for configuration and operational datastores start
73      ``/rests/data/``,
74     | e. g. GET
75      http://localhost:8181/rests/data/network-topology:network-topology
76      with response of both datastores. It's allowed to use query
77      parameters to distinguish between them.
78     | e. g. GET
79      http://localhost:8181/rests/data/network-topology:network-topology?content=config
80      for configuration datastore
81     | and GET
82      http://localhost:8181/rests/data/network-topology:network-topology?content=nonconfig
83      for operational datastore.
84
85     | Also if a data node in the path expression is a YANG leaf-list or list
86      node, the path segment has to be constructed by having leaf-list or
87      list node name, followed by an "=" character, then followed by the
88      leaf-list or list value. Any reserved characters must be
89      percent-encoded.
90     | e. g. GET
91      http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf?content=config
92      for retrieving data from configuration datastore for
93      topology-netconf value of topology list.
94
95 Preconditions
96 ^^^^^^^^^^^^^
97
98 1. OpenDaylight is running
99
100 2. In Karaf, you must have the ``odl-netconf-topology`` or
101    ``odl-netconf-clustered-topology`` feature installed.
102
103 3. Feature ``odl-restconf-nb`` must be installed
104
105 Spawning new NETCONF connectors
106 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
107
108 To create a new NETCONF connector you need to send the following PUT request
109 to RESTCONF:
110
111 .. list-table::
112    :widths: 1 5
113
114    * - rfc8040
115      - http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device
116
117 You could use the same body to create the new  NETCONF connector with a POST
118 without specifying the node in the URL:
119
120 .. list-table::
121    :widths: 1 5
122
123    * - rfc8040
124      - http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf
125
126 Payload:
127
128 .. tabs::
129
130    .. tab:: XML
131
132       **Content-type:** ``application/xml``
133
134       **Accept:** ``application/xml``
135
136       **Authentication:** ``admin:admin``
137
138       .. code-block:: xml
139
140          <node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
141            <node-id>new-netconf-device</node-id>
142            <host xmlns="urn:opendaylight:netconf-node-topology">127.0.0.1</host>
143            <port xmlns="urn:opendaylight:netconf-node-topology">17830</port>
144            <username xmlns="urn:opendaylight:netconf-node-topology">admin</username>
145            <password xmlns="urn:opendaylight:netconf-node-topology">admin</password>
146            <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
147            <!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->
148            <reconnect-on-changed-schema xmlns="urn:opendaylight:netconf-node-topology">false</reconnect-on-changed-schema>
149            <connection-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">20000</connection-timeout-millis>
150            <max-connection-attempts xmlns="urn:opendaylight:netconf-node-topology">0</max-connection-attempts>
151            <between-attempts-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">2000</between-attempts-timeout-millis>
152            <sleep-factor xmlns="urn:opendaylight:netconf-node-topology">1.5</sleep-factor>
153            <!-- keepalive-delay set to 0 turns off keepalives-->
154            <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">120</keepalive-delay>
155          </node>
156
157    .. tab:: JSON
158
159       **Content-type:** ``application/json``
160
161       **Accept:** ``application/json``
162
163       **Authentication:** ``admin:admin``
164
165       .. code-block:: json
166
167          {
168              "node": [
169                  {
170                      "node-id": "new-netconf-device",
171                      "netconf-node-topology:port": 17830,
172                      "netconf-node-topology:reconnect-on-changed-schema": false,
173                      "netconf-node-topology:connection-timeout-millis": 20000,
174                      "netconf-node-topology:tcp-only": false,
175                      "netconf-node-topology:max-connection-attempts": 0,
176                      "netconf-node-topology:username": "admin",
177                      "netconf-node-topology:password": "admin",
178                      "netconf-node-topology:sleep-factor": 1.5,
179                      "netconf-node-topology:host": "127.0.0.1",
180                      "netconf-node-topology:between-attempts-timeout-millis": 2000,
181                      "netconf-node-topology:keepalive-delay": 120
182                  }
183              ]
184          }
185
186 Note that the device name in <node-id> element must match the last
187 element of the restconf URL.
188
189 Reconfiguring an existing connector
190 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
191
192 The steps to reconfigure an existing connector are exactly the same as
193 when spawning a new connector. The old connection will be disconnected
194 and a new connector with the new configuration will be created. This needs
195 to be done with a PUT request because the node already exists. A POST
196 request will fail for that reason.
197
198 Additionally, a PATCH request can be used to modify an existing
199 configuration. Currently, only yang-patch (`RFC-8072 <https://tools.ietf.org/html/rfc8072>`__)
200 is supported. The URL would be the same as the above PUT examples.
201 Using JSON for the body, the headers needed for the request would
202 be:
203
204 Headers:
205
206 -  Accept: application/yang-data+json
207
208 -  Content-Type: application/yang-patch+json
209
210 Example JSON payload to modify the password entry:
211
212 ::
213
214     {
215       "ietf-restconf:yang-patch" : {
216         "patch-id" : "0",
217         "edit" : [
218           {
219             "edit-id" : "edit1",
220             "operation" : "merge",
221             "target" : "",
222             "value" : {
223              "node": [
224                 {
225                  "node-id": "new-netconf-device",
226                  "netconf-node-topology:password" : "newpassword"
227                 }
228              ]
229             }
230          }
231         ]
232       }
233     }
234
235 Deleting an existing connector
236 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237
238 To remove an already configured NETCONF connector you need to send a
239 DELETE request to the same PUT request URL that was used to create the
240 device:
241
242 .. list-table::
243    :widths: 1 5
244
245    * - rfc8040
246      - http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device
247
248 .. note::
249
250     No body is needed to delete the node/device
251
252 Connecting to a device not supporting NETCONF monitoring
253 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
254
255 The netconf-connector in OpenDaylight relies on ietf-netconf-monitoring
256 support when connecting to remote NETCONF device. The
257 ietf-netconf-monitoring support allows netconf-connector to list and
258 download all YANG schemas that are used by the device. NETCONF connector
259 can only communicate with a device if it knows the set of used schemas
260 (or at least a subset). However, some devices use YANG models internally
261 but do not support NETCONF monitoring. Netconf-connector can also
262 communicate with these devices, but you have to side load the necessary
263 yang models into OpenDaylight’s YANG model cache for netconf-connector.
264 In general there are 2 situations you might encounter:
265
266 **1. NETCONF device does not support ietf-netconf-monitoring but it does
267 list all its YANG models as capabilities in HELLO message**
268
269 This could be a device that internally uses only ietf-inet-types YANG
270 model with revision 2010-09-24. In the HELLO message that is sent from
271 this device there is this capability reported:
272
273 ::
274
275     urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&revision=2010-09-24
276
277 **For such devices you only need to put the schema into folder
278 cache/schema inside your Karaf distribution.**
279
280 .. important::
281
282     The file with YANG schema for ietf-inet-types has to be called
283     ietf-inet-types@2010-09-24.yang. It is the required naming format of
284     the cache.
285
286 **2. NETCONF device does not support ietf-netconf-monitoring and it does
287 NOT list its YANG models as capabilities in HELLO message**
288
289 Compared to device that lists its YANG models in HELLO message, in this
290 case there would be no capability with ietf-inet-types in the HELLO
291 message. This type of device basically provides no information about the
292 YANG schemas it uses so its up to the user of OpenDaylight to properly
293 configure netconf-connector for this device.
294
295 Netconf-connector has an optional configuration attribute called
296 yang-module-capabilities and this attribute can contain a list of "YANG
297 module based" capabilities. So by setting this configuration attribute,
298 it is possible to override the "yang-module-based" capabilities reported
299 in HELLO message of the device. To do this, we need to modify the
300 configuration of netconf-connector like in the example below:
301
302 .. tabs::
303
304    .. tab:: XML
305
306       **Content-type:** ``application/xml``
307
308       **Accept:** ``application/xml``
309
310       **Authentication:** ``admin:admin``
311
312       .. code-block:: xml
313
314          <node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
315            <node-id>r5</node-id>
316            <host xmlns="urn:opendaylight:netconf-node-topology">127.0.0.1</host>
317            <port xmlns="urn:opendaylight:netconf-node-topology">8305</port>
318            <username xmlns="urn:opendaylight:netconf-node-topology">root</username>
319            <password xmlns="urn:opendaylight:netconf-node-topology">root</password>
320            <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
321            <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">30</keepalive-delay>
322            <yang-module-capabilities xmlns="urn:opendaylight:netconf-node-topology">
323              <override>true</override>
324              <capability xmlns="urn:opendaylight:netconf-node-topology">
325                urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&amp;revision=2013-07-15
326              </capability>
327            </yang-module-capabilities>
328          </node>
329
330    .. tab:: JSON
331
332       **Content-type:** ``application/json``
333
334       **Accept:** ``application/json``
335
336       **Authentication:** ``admin:admin``
337
338       .. code-block:: json
339
340          {
341              "node": [
342                  {
343                      "node-id": "device",
344                      "netconf-node-topology:host": "127.0.0.1",
345                      "netconf-node-topology:password": "root",
346                      "netconf-node-topology:username": "root",
347                      "netconf-node-topology:yang-module-capabilities": {
348                          "override": true,
349                          "capability": [
350                              "urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&revision=2013-07-15"
351                          ]
352                      },
353                      "netconf-node-topology:port": 8305,
354                      "netconf-node-topology:tcp-only": false,
355                      "netconf-node-topology:keepalive-delay": 30
356                  }
357              ]
358          }
359
360 **Remember to also put the YANG schemas into the cache folder.**
361
362 .. note::
363
364     For putting multiple capabilities, you just need to replicate the
365     capability element inside yang-module-capability element.
366     Capability element is modeled as a leaf-list. With this
367     configuration, we would make the remote device report usage of
368     ietf-inet-types in the eyes of netconf-connector.
369
370 Connecting to a device supporting only NETCONF 1.0
371 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
372
373 OpenDaylight is schema-based distribution and heavily depends on YANG
374 models. However some legacy NETCONF devices are not schema-based and
375 implement just RFC 4741. This type of device does not utilize YANG
376 models internally and OpenDaylight does not know how to communicate
377 with such devices, how to validate data, or what the semantics of data
378 are.
379
380 NETCONF connector can communicate also with these devices, but the
381 trade-offs are worsened possibilities in utilization of NETCONF
382 mountpoints. Using RESTCONF with such devices is not suported. Also
383 communicating with schemaless devices from application code is slightly
384 different.
385
386 To connect to schemaless device, there is a optional configuration option
387 in netconf-node-topology model called schemaless. You have to set this
388 option to true.
389
390 Clustered NETCONF connector
391 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
392
393 To spawn NETCONF connectors that are cluster-aware you need to install
394 the ``odl-netconf-clustered-topology`` karaf feature.
395
396 .. warning::
397
398     The ``odl-netconf-topology`` and ``odl-netconf-clustered-topology``
399     features are considered **INCOMPATIBLE**. They both manage the same
400     space in the datastore and would issue conflicting writes if
401     installed together.
402
403 Configuration of clustered NETCONF connectors works the same as the
404 configuration through the topology model in the previous section.
405
406 When a new clustered connector is configured the configuration gets
407 distributed among the member nodes and a NETCONF connector is spawned on
408 each node. From these nodes a master is chosen which handles the schema
409 download from the device and all the communication with the device. You
410 will be able to read/write to/from the device from all slave nodes due
411 to the proxy data brokers implemented.
412
413 You can use the ``odl-netconf-clustered-topology`` feature in a single
414 node scenario as well but the code that uses akka will be used, so for a
415 scenario where only a single node is used, ``odl-netconf-topology``
416 might be preferred.
417
418 Netconf-connector utilization
419 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
420
421 Once the connector is up and running, users can utilize the new mount
422 point instance. By using RESTCONF or from their application code. This
423 chapter deals with using RESTCONF and more information for app
424 developers can be found in the developers guide or in the official
425 tutorial application **ncmount** that can be found in the coretutorials
426 project:
427
428 -  https://github.com/opendaylight/coretutorials/tree/master/ncmount
429
430 Reading data from the device
431 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
432
433 Just invoke (no body needed):
434
435 GET
436 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device/yang-ext:mount?content=nonconfig
437
438 This will return the entire content of operation datastore from the
439 device. To view just the configuration datastore, change **nonconfig**
440 in this URL to **config**.
441
442 Writing configuration data to the device
443 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
444
445 In general, you cannot simply write any data you want to the device. The
446 data have to conform to the YANG models implemented by the device. In
447 this example we are adding a new interface-configuration to the mounted
448 device (assuming the device supports Cisco-IOS-XR-ifmgr-cfg YANG model).
449 In fact this request comes from the tutorial dedicated to the
450 **ncmount** tutorial app.
451
452 POST
453 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device/yang-ext:mount/Cisco-IOS-XR-ifmgr-cfg:interface-configurations
454
455 ::
456
457     <interface-configuration xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
458         <active>act</active>
459         <interface-name>mpls</interface-name>
460         <description>Interface description</description>
461         <bandwidth>32</bandwidth>
462         <link-status></link-status>
463     </interface-configuration>
464
465 Should return 200 response code with no body.
466
467 .. tip::
468
469     This call is transformed into a couple of NETCONF RPCs. Resulting
470     NETCONF RPCs that go directly to the device can be found in the
471     OpenDaylight logs after invoking ``log:set TRACE
472     org.opendaylight.controller.sal.connect.netconf`` in the Karaf
473     shell. Seeing the NETCONF RPCs might help with debugging.
474
475 This request is very similar to the one where we spawned a new netconf
476 device. That’s because we used the loopback netconf-connector to write
477 configuration data into config-subsystem datastore and config-subsystem
478 picked it up from there.
479
480 Invoking custom RPC
481 ^^^^^^^^^^^^^^^^^^^
482
483 Devices can implement any additional RPC and as long as it provides YANG
484 models for it, it can be invoked from OpenDaylight. Following example
485 shows how to invoke the get-schema RPC (get-schema is quite common among
486 netconf devices). Invoke:
487
488 POST
489 http://localhost:8181/rests/operations/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device/yang-ext:mount/ietf-netconf-monitoring:get-schema
490
491 ::
492
493     <input xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
494       <identifier>ietf-yang-types</identifier>
495       <version>2013-07-15</version>
496     </input>
497
498 This call should fetch the source for ietf-yang-types YANG model from
499 the mounted device.
500
501 Receiving Netconf Device Notifications on a http client
502 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
503
504 Devices emit netconf alarms and notifictions on certain situtations, which can demand
505 attention from Device Administration. The notifications are received as Netconf messages on an
506 active Netconf session.
507
508 Opendaylight provides the way to stream the device notifications over a http session.
509
510 - Step 1: Mount the device (assume node name is test_device)
511
512 - Step 2: Wait for the device to be connected.
513
514 - Step 3: Create the Subscription for notification on the active session.
515
516  .. code-block::
517
518     POST
519     http://localhost:8181/rests/operations/network-topology:network-topology/topology=topology-netconf/node=test_device/yang-ext:mount/notifications:create-subscription
520     Content-Type: application/json
521     Accept: application/json
522
523  .. code-block:: json
524
525     {
526       "input": {
527         "stream": "NETCONF"
528        }
529     }
530
531 - Step 4: Create the http Stream for the events.
532
533 .. code-block::
534
535     POST
536     http://localhost:8181/rests/operations/odl-device-notification:subscribe-device-notification
537     Content-Type: application/json
538     Accept: application/json
539
540 .. code-block:: json
541
542     {
543       "input": {
544          "path":"/network-topology:network-topology/topology[topology-id='topology-netconf']/node[node-id='test_device']"
545       }
546     }
547
548 The response suggests the http url for reading the notifications.
549
550 .. code-block:: json
551
552     {
553        "odl-device-notification:output": {
554             "stream-path": "http://localhost:8181/rests/notif/test_device?notificationType=test_device"
555         }
556     }
557
558 - Step 5: User can access the url in the response and the notifications will be as follows.
559
560 .. code-block::
561
562     GET
563     http://localhost:8181/rests/notif/test_device?notificationType=test_device
564     Content-Type: application/xml
565     Accept: application/xml
566
567
568 .. code-block:: xml
569
570     : ping
571
572     : ping
573
574     : ping
575
576     : ping
577
578     : ping
579
580     data: <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><eventTime>2022-06-17T07:01:08.60228Z</eventTime><netconf-session-start xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"><username>root</username><source-host>127.0.0.1</source-host><session-id>2</session-id></netconf-session-start></notification>
581
582     data: <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0"><eventTime>2022-06-17T07:01:12.458258Z</eventTime><netconf-session-end xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications"><username>root</username><source-host>127.0.0.1</source-host><termination-reason>closed</termination-reason><session-id>2</session-id></netconf-session-end></notification>
583
584
585 Netconf-connector + Netopeer
586 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
587
588 `Netopeer <https://github.com/cesnet/netopeer>`__ (an open-source
589 NETCONF server) can be used for testing/exploring NETCONF southbound in
590 OpenDaylight.
591
592 Netopeer installation
593 ^^^^^^^^^^^^^^^^^^^^^
594
595 A `Docker <https://www.docker.com/>`__ container with netopeer will be
596 used in this guide. To install Docker and start the `netopeer
597 image <https://hub.docker.com/r/sysrepo/sysrepo-netopeer2>`__ perform
598 following steps:
599
600 1. Install docker http://docs.docker.com/linux/step_one/
601
602 2. Start the netopeer image:
603
604    ::
605
606        docker run -it --name sysrepo -p 830:830 --rm sysrepo/sysrepo-netopeer2:latest
607
608 3. Verify netopeer is running by invoking (netopeer should send its
609    HELLO message right away:
610
611    ::
612
613        ssh root@localhost -p 830 -s netconf
614        (password root)
615
616 Mounting netopeer NETCONF server
617 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
618
619 Preconditions:
620
621 -  OpenDaylight is started with features ``odl-restconf-all`` and
622    ``odl-netconf-connector-all``.
623
624 -  Netopeer is up and running in docker
625
626 Now just follow the section: `Spawning new NETCONF connectors`_.
627 In the payload change the:
628
629 -  name, e.g., to netopeer
630
631 -  username/password to your system credentials
632
633 -  ip to localhost
634
635 -  port to 1831.
636
637 After netopeer is mounted successfully, its configuration can be read
638 using RESTCONF by invoking:
639
640 GET
641 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=netopeer/yang-ext:mount?content:config
642
643 Northbound (NETCONF servers)
644 ----------------------------
645
646 OpenDaylight provides 2 types of NETCONF servers:
647
648 -  **NETCONF server for config-subsystem (listening by default on port
649    1830)**
650
651    -  Serves as a default interface for config-subsystem and allows
652       users to spawn/reconfigure/destroy modules (or applications) in
653       OpenDaylight
654
655 -  **NETCONF server for MD-SAL (listening by default on port 2830)**
656
657    -  Serves as an alternative interface for MD-SAL (besides RESTCONF)
658       and allows users to read/write data from MD-SAL’s datastore and to
659       invoke its rpcs (NETCONF notifications are not available in the
660       Boron release of OpenDaylight)
661
662 .. note::
663
664     The reason for having 2 NETCONF servers is that config-subsystem and
665     MD-SAL are 2 different components of OpenDaylight and require
666     different approach for NETCONF message handling and data
667     translation. These 2 components will probably merge in the future.
668
669 .. note::
670
671     Since Nitrogen release, there is performance regression in NETCONF
672     servers accepting SSH connections. While opening a connection takes
673     less than 10 seconds on Carbon, on Nitrogen time can increase up to
674     60 seconds. Please see https://bugs.opendaylight.org/show_bug.cgi?id=9020
675
676 NETCONF server for config-subsystem
677 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
678
679 This NETCONF server is the primary interface for config-subsystem. It
680 allows the users to interact with config-subsystem in a standardized
681 NETCONF manner.
682
683 In terms of RFCs, these are supported:
684
685 -  `RFC-6241 <http://tools.ietf.org/html/rfc6241>`__
686
687 -  `RFC-5277 <https://tools.ietf.org/html/rfc5277>`__
688
689 -  `RFC-6470 <https://tools.ietf.org/html/rfc6470>`__
690
691    -  (partially, only the schema-change notification is available in
692       Boron release)
693
694 -  `RFC-6022 <https://tools.ietf.org/html/rfc6022>`__
695
696 For regular users it is recommended to use RESTCONF + the
697 controller-config loopback mountpoint instead of using pure NETCONF. How
698 to do that is spesific for each component/module/application in
699 OpenDaylight and can be found in their dedicated user guides.
700
701 NETCONF server for MD-SAL
702 ~~~~~~~~~~~~~~~~~~~~~~~~~
703
704 This NETCONF server is just a generic interface to MD-SAL in
705 OpenDaylight. It uses the stadard MD-SAL APIs and serves as an
706 alternative to RESTCONF. It is fully model driven and supports any data
707 and rpcs that are supported by MD-SAL.
708
709 In terms of RFCs, these are supported:
710
711 -  `RFC-6241 <http://tools.ietf.org/html/rfc6241>`__
712
713 -  `RFC-6022 <https://tools.ietf.org/html/rfc6022>`__
714
715 -  `RFC-7895 <https://tools.ietf.org/html/rfc7895>`__
716
717 Notifications over NETCONF are not supported in the Boron release.
718
719 .. tip::
720
721     Install NETCONF northbound for MD-SAL by installing feature:
722     ``odl-netconf-mdsal`` in karaf. Default binding port is **2830**.
723
724 Configuration
725 ^^^^^^^^^^^^^
726
727 The default configuration can be found in file: *08-netconf-mdsal.xml*.
728 The file contains the configuration for all necessary dependencies and a
729 single SSH endpoint starting on port 2830. There is also a (by default
730 disabled) TCP endpoint. It is possible to start multiple endpoints at
731 the same time either in the initial configuration file or while
732 OpenDaylight is running.
733
734 The credentials for SSH endpoint can also be configured here, the
735 defaults are admin/admin. Credentials in the SSH endpoint are not yet
736 managed by the centralized AAA component and have to be configured
737 separately.
738
739 Verifying MD-SAL’s NETCONF server
740 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
741
742 After the NETCONF server is available it can be examined by a command
743 line ssh tool:
744
745 ::
746
747     ssh admin@localhost -p 2830 -s netconf
748
749 The server will respond by sending its HELLO message and can be used as
750 a regular NETCONF server from then on.
751
752 Mounting the MD-SAL’s NETCONF server
753 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
754
755 To perform this operation, just spawn a new netconf-connector as
756 described in `Spawning new NETCONF connectors`_. Just change the ip to
757 "127.0.0.1" port to "2830" and its name to "controller-mdsal".
758
759 Now the MD-SAL’s datastore can be read over RESTCONF via NETCONF by
760 invoking:
761
762 GET
763 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=controller-mdsal/yang-ext:mount?content:nonconfig
764
765 .. note::
766
767     This might not seem very useful, since MD-SAL can be accessed
768     directly from RESTCONF or from Application code, but the same method
769     can be used to mount and control other OpenDaylight instances by the
770     "master OpenDaylight".
771
772 NETCONF stress/performance measuring tool
773 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
774
775 This is basically a NETCONF client that puts NETCONF servers under heavy
776 load of NETCONF RPCs and measures the time until a configurable amount
777 of them is processed.
778
779 RESTCONF stress-performance measuring tool
780 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
781
782 Very similar to NETCONF stress tool with the difference of using
783 RESTCONF protocol instead of NETCONF.
784
785 YANGLIB remote repository
786 -------------------------
787
788 There are scenarios in NETCONF deployment, that require for a centralized
789 YANG models repository. YANGLIB plugin provides such remote repository.
790
791 To start this plugin, you have to install odl-yanglib feature. Then you
792 have to configure YANGLIB either through RESTCONF or NETCONF. We will
793 show how to configure YANGLIB through RESTCONF.
794
795 YANGLIB configuration through RESTCONF
796 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
797
798 You have to specify what local YANG modules directory you want to provide.
799 Then you have to specify address and port whre you want to provide YANG
800 sources. For example, we want to serve yang sources from folder /sources
801 on localhost:8181 adress. The configuration for this scenario will be
802 as follows:
803
804 ::
805
806     PUT  http://localhost:8181/rests/data/yanglib:yanglib-config
807
808 Headers:
809
810 -  Accept: application/xml
811
812 -  Content-Type: application/xml
813
814 Payload:
815
816 ::
817
818     <yanglib-config xmlns="urn:opendaylight:params:xml:ns:yang:controller:yanglib:impl">
819         <cache-folder>cache/newSchema</cache-folder>
820         <binding-addr>localhost</binding-addr>
821         <binding-port>8181</binding-port>
822     </yanglib-config>
823
824 This should result in a 2xx response and new YANGLIB instance should be
825 created. This YANGLIB takes all YANG sources from /sources folder and
826 for each generates URL in form:
827
828 ::
829
830     http://localhost:8181/yanglib/schemas/{modelName}/{revision}
831
832 On this URL will be hosted YANG source for particular module.
833
834 YANGLIB instance also write this URL along with source identifier to
835 ietf-netconf-yang-library/modules-state/module list.
836
837 Netconf-connector with YANG library as fallback
838 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
839
840 There is an optional configuration in netconf-connector called
841 yang-library. You can specify YANG library to be plugged as additional
842 source provider into the mount's schema repository. Since YANGLIB
843 plugin is advertising provided modules through yang-library model, we
844 can use it in mount point's configuration as YANG library.  To do this,
845 we need to modify the configuration of netconf-connector by adding this
846 XML
847
848 ::
849
850     <yang-library xmlns="urn:opendaylight:netconf-node-topology">
851       <yang-library-url xmlns="urn:opendaylight:netconf-node-topology">http://localhost:8181/rests/data/ietf-yang-library:modules-state</yang-library-url>
852       <username xmlns="urn:opendaylight:netconf-node-topology">admin</username>
853       <password xmlns="urn:opendaylight:netconf-node-topology">admin</password>
854     </yang-library>
855
856 This will register YANGLIB provided sources as a fallback schemas for
857 particular mount point.
858
859 NETCONF Call Home
860 -----------------
861
862 Call Home Installation
863 ~~~~~~~~~~~~~~~~~~~~~~
864
865 ODL Call-Home server is installed in Karaf by installing karaf feature
866 ``odl-netconf-callhome-ssh``. RESTCONF feature is recommended for
867 configuring Call Home & testing its functionality.
868
869 ::
870
871   feature:install odl-netconf-callhome-ssh
872
873
874 .. note::
875
876     In order to test Call Home functionality we recommend Netopeer or
877     Netopeer2. See `Netopeer Call Home <https://github.com/CESNET/netopeer/wiki/CallHome>`__
878     or `Netopeer2 <https://github.com/CESNET/netopeer2>`__ to learn how to
879     enable call-home on Netopeer.
880
881 Northbound Call-Home API
882 ~~~~~~~~~~~~~~~~~~~~~~~~
883
884 The northbound Call Home API is used for administering the Call-Home Server. The
885 following describes this configuration.
886
887 Global Configuration
888 ^^^^^^^^^^^^^^^^^^^^
889
890 .. important::
891   The global configuration is not a part of the `RFC 8071
892   <https://tools.ietf.org/html/rfc8071>`__ and, therefore, subject to change.
893
894 Configuring global credentials
895 ''''''''''''''''''''''''''''''
896
897 ODL Call-Home server allows user to configure global credentials, which will be
898 used for connected over SSH transport protocol devices which does not have
899 device-specific credentials configured.
900
901 This is done by creating
902 ``/odl-netconf-callhome-server:netconf-callhome-server/global/credentials``
903 with username and passwords specified.
904
905 *Configuring global username & passwords to try*
906
907 .. code-block::
908
909     PUT HTTP/1.1
910     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/global/credentials
911     Content-Type: application/json
912     Accept: application/json
913
914 .. code-block:: json
915
916     {
917       "credentials":
918       {
919         "username": "example",
920         "passwords": [ "first-password-to-try", "second-password-to-try" ]
921       }
922     }
923
924 Configuring to accept any ssh server key using global credentials
925 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
926
927 By default Netconf Call-Home Server accepts only incoming connections
928 from allowed devices
929 ``/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices``,
930 if user desire to allow all incoming connections, it is possible to set
931 ``accept-all-ssh-keys`` to ``true`` in
932 ``/odl-netconf-callhome-server:netconf-callhome-server/global``.
933
934 The name of this devices in ``netconf-topology`` will be in format
935 ``ip-address:port``. For naming devices see Device-Specific
936 Configuration.
937
938 *Allowing unknown devices to connect*
939
940 This is a debug feature and should not be used in production. Besides being an obvious
941 security issue, this also causes the Call-Home Server to drastically increase its output
942 to the log.
943
944 .. code-block::
945
946     PUT HTTP/1.1
947     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/global/accept-all-ssh-keys
948     Content-Type: application/json
949     Accept: application/json
950
951 .. code-block:: json
952
953     {
954         "accept-all-ssh-keys": "true"
955     }
956
957 Device-Specific Configuration
958 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
959
960 Netconf Call Home server supports both of the secure transports used
961 by the Network Configuration Protocol (NETCONF) - Secure Shell (SSH),
962 and Transport Layer Security (TLS).
963
964 Configure device to connect over SSH protocol
965 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
966
967 Netconf Call Home Server uses device provided SSH server key (host key)
968 to identify device. The pairing of name and server key is configured in
969 ``/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices``.
970 This list is colloquially called a whitelist.
971
972 If the Call-Home Server finds the SSH host key in the whitelist, it continues
973 to negotiate a NETCONF connection over an SSH session. If the SSH host key is
974 not found, the connection between the Call Home server and the device is dropped
975 immediately. In either case, the device that connects to the Call home server
976 leaves a record of its presence in the operational store.
977
978 Configuring Device with Device-specific Credentials
979 '''''''''''''''''''''''''''''''''''''''''''''''''''
980
981 Adding specific device to the allowed list is done by creating
982 ``/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device={device}``
983 with device-id and connection parameters inside the ssh-client-params container.
984
985 *Configuring Device with Credentials*
986
987 .. code-block::
988
989     PUT HTTP/1.1
990     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example
991     Content-Type: application/json
992     Accept: application/json
993
994 .. code-block:: json
995
996     {
997       "device": {
998         "unique-id": "example",
999         "ssh-client-params": {
1000           "credentials": {
1001             "username": "example",
1002             "passwords": [ "password" ]
1003           },
1004           "host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1005         }
1006       }
1007     }
1008
1009 Configuring Device with Global Credentials
1010 '''''''''''''''''''''''''''''''''''''''''''''''''''
1011
1012 It is possible to omit ``username`` and ``password`` for ssh-client-params,
1013 in such case values from global credentials will be used.
1014
1015 *Example of configuring device*
1016
1017 .. code-block::
1018
1019     PUT HTTP/1.1
1020     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example
1021     Content-Type: application/json
1022     Accept: application/json
1023
1024 .. code-block:: json
1025
1026     {
1027       "device": {
1028         "unique-id": "example",
1029         "ssh-client-params": {
1030           "host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1031         }
1032       }
1033     }
1034
1035 Deprecated configuration models for devices accessed with SSH protocol
1036 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1037
1038 With `RFC 8071 <https://tools.ietf.org/html/rfc8071>`__ alignment and adding
1039 support for TLS transport following configuration models has been marked
1040 deprecated.
1041
1042 Configuring Device with Global Credentials
1043 '''''''''''''''''''''''''''''''''''''''''''''''''''
1044
1045 *Example of configuring device*
1046
1047 .. code-block::
1048
1049     PUT HTTP/1.1
1050     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example
1051     Content-Type: application/json
1052     Accept: application/json
1053
1054 .. code-block:: json
1055
1056     {
1057       "device": {
1058         "unique-id": "example",
1059         "ssh-host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1060       }
1061     }
1062
1063 Configuring Device with Device-specific Credentials
1064 '''''''''''''''''''''''''''''''''''''''''''''''''''
1065
1066 Call Home Server also allows to configure credentials per device basis,
1067 this is done by introducing ``credentials`` container into
1068 device-specific configuration. Format is same as in global credentials.
1069
1070 *Configuring Device with Credentials*
1071
1072 .. code-block::
1073
1074     PUT HTTP/1.1
1075     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example
1076     Content-Type: application/json
1077     Accept: application/json
1078
1079 .. code-block:: json
1080
1081     {
1082       "device": {
1083         "unique-id": "example",
1084         "credentials": {
1085           "username": "example",
1086           "passwords": [ "password" ]
1087         },
1088         "ssh-host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1089       }
1090     }
1091
1092 Configure device to connect over TLS protocol
1093 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1094
1095 Netconf Call Home Server allows devices to use TLS transport protocol to
1096 establish a connection towards the NETCONF device. This communication
1097 requires proper setup to make two-way TLS authentication possible for client
1098 and server.
1099
1100 The initial step is to configure certificates and keys for two-way TLS by
1101 storing them within the netconf-keystore.
1102
1103 *Adding a client private key credential to the netconf-keystore*
1104
1105 .. code-block::
1106
1107     POST HTTP/1.1
1108     /rests/operations/netconf-keystore:add-keystore-entry
1109     Content-Type: application/json
1110     Accept: application/json
1111
1112 .. code-block:: json
1113
1114   {
1115     "input": {
1116       "key-credential": [
1117         {
1118           "key-id": "example-client-key-id",
1119           "private-key": "base64encoded-private-key",
1120           "passphrase": "passphrase"
1121         }
1122       ]
1123     }
1124   }
1125
1126 *Associate a private key with a client and CA certificates chain*
1127
1128 .. code-block::
1129
1130     POST HTTP/1.1
1131     /rests/operations/netconf-keystore:add-private-key
1132     Content-Type: application/json
1133     Accept: application/json
1134
1135 .. code-block:: json
1136
1137   {
1138     "input": {
1139       "private-key": [
1140         {
1141           "name": "example-client-key-id",
1142           "data": "key-data",
1143           "certificate-chain": [
1144             "certificate-data"
1145           ]
1146         }
1147       ]
1148     }
1149   }
1150
1151 *Add a list of trusted CA and server certificates*
1152
1153 .. code-block::
1154
1155     POST HTTP/1.1
1156     /rests/operations/netconf-keystore:add-trusted-certificate
1157     Content-Type: application/json
1158     Accept: application/json
1159
1160 .. code-block:: json
1161
1162   {
1163     "input": {
1164       "trusted-certificate": [
1165         {
1166           "name": "example-ca-certificate",
1167           "certificate": "ca-certificate-data"
1168         },
1169         {
1170           "name": "example-server-certificate",
1171           "certificate": "server-certificate-data"
1172         }
1173       ]
1174     }
1175   }
1176
1177 In a second step, it is required to create an allowed device associated with
1178 a server certificate and client key. The server certificate will be used to
1179 identify and pin the NETCONF device during SSL handshake and should be unique
1180 among the allowed devices.
1181
1182 *Add device configuration for TLS protocol to allowed devices list*
1183
1184 .. code-block::
1185
1186     PUT HTTP/1.1
1187     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example-device
1188     Content-Type: application/json
1189     Accept: application/json
1190
1191 .. code-block:: json
1192
1193   {
1194     "device": {
1195       "unique-id": "example-device",
1196       "tls-client-params": {
1197         "key-id": "example-client-key-id",
1198         "certificate-id": "example-server-certificate"
1199       }
1200     }
1201   }
1202
1203 Operational Status
1204 ^^^^^^^^^^^^^^^^^^
1205
1206 Once an entry is made into the config side of "allowed-devices", the Call-Home Server will
1207 populate an corresponding operational device that is the same as the config device but
1208 has an additional status. By default, this status is *DISCONNECTED*. Once a device calls
1209 home, this status will change to one of:
1210
1211 *CONNECTED* â€” The device is currently connected and the NETCONF mount is available for network
1212 management.
1213
1214 *FAILED_AUTH_FAILURE* â€” The last attempted connection was unsuccessful because the Call-Home
1215 Server was unable to provide the acceptable credentials of the device. The device is also
1216 disconnected and not available for network management.
1217
1218 *FAILED_NOT_ALLOWED* â€” The last attempted connection was unsuccessful because the device was
1219 not recognized as an acceptable device. The device is also disconnected and not available for
1220 network management.
1221
1222 *FAILED* â€” The last attempted connection was unsuccessful for a reason other than not
1223 allowed to connect or incorrect client credentials. The device is also disconnected and not
1224 available for network management.
1225
1226 *DISCONNECTED* â€” The device is currently disconnected.
1227
1228 Rogue Devices
1229 '''''''''''''
1230
1231 Devices which are not on the whitelist might try to connect to the Call-Home Server. In
1232 these cases, the server will keep a record by instantiating an operational device. There
1233 will be no corresponding config device for these rogues. They can be identified readily
1234 because their device id, rather than being user-supplied, will be of the form
1235 "address:port". Note that if a device calls back multiple times, there will only be
1236 a single operatinal entry (even if the port changes); these devices are recognized by
1237 their unique host key.
1238
1239 Southbound Call-Home API
1240 ~~~~~~~~~~~~~~~~~~~~~~~~
1241
1242 The Call-Home Server listens for incoming TCP connections and assumes that the other side of
1243 the connection is a device calling home via a NETCONF connection with SSH for
1244 management. The server uses port 6666 by default and this can be configured via a
1245 blueprint configuration file.
1246
1247 The device **must** initiate the connection and the server will not try to re-establish the
1248 connection in case of a drop. By requirement, the server cannot assume it has connectivity
1249 to the device due to NAT or firewalls among others.
1250
1251 Reading data with selected fields
1252 ---------------------------------
1253
1254 Overview
1255 ~~~~~~~~
1256
1257 If user would like to read only selected fields from NETCONF device, it is possible to use
1258 fields query parameter that is described by RFC-8040. RESTCONF parses content of query
1259 parameter into format that is accepted by NETCONF subtree filtering - filtering of data is done
1260 on NETCONF server, not on NETCONF client side. This approach optimizes network traffic load,
1261 because data in which user doesn't have interest, is not transferred over network.
1262
1263 Next advantages:
1264
1265 * using single RESTCONF request and single NETCONF RPC for reading multiple subtrees
1266 * possibility to read only selected fields under list node across multiple hierarchies
1267   (it cannot be done without proper selection API)
1268
1269 .. note::
1270
1271   More information about fields query parameter: `RFC 8071 <https://tools.ietf.org/html/rfc8040#section-4.8.3>`__
1272
1273 Preparation of data
1274 ~~~~~~~~~~~~~~~~~~~
1275
1276 For demonstration, we will define next YANG model:
1277
1278 ::
1279
1280     module test-module {
1281         yang-version 1.1;
1282         namespace "urn:opendaylight:test-module";
1283         prefix "tm";
1284         revision "2023-02-16";
1285
1286         container root {
1287             container simple-root {
1288                 leaf leaf-a {
1289                     type string;
1290                 }
1291                 leaf leaf-b {
1292                     type string;
1293                 }
1294                 leaf-list ll {
1295                     type string;
1296                 }
1297                 container nested {
1298                     leaf sample-x {
1299                         type boolean;
1300                     }
1301                     leaf sample-y {
1302                         type boolean;
1303                     }
1304                 }
1305             }
1306
1307             container list-root {
1308                 leaf branch-ab {
1309                     type int32;
1310                 }
1311                 list top-list {
1312                     key "key-1 key-2";
1313                     ordered-by user;
1314                     leaf key-1 {
1315                         type string;
1316                     }
1317                     leaf key-2 {
1318                         type string;
1319                     }
1320                     container next-data {
1321                         leaf switch-1 {
1322                             type empty;
1323                         }
1324                         leaf switch-2 {
1325                             type empty;
1326                         }
1327                     }
1328                     list nested-list {
1329                         key "identifier";
1330                         leaf identifier {
1331                             type string;
1332                         }
1333                         leaf foo {
1334                             type int32;
1335                         }
1336                     }
1337                 }
1338             }
1339         }
1340     }
1341
1342 Follow the :doc:`testtool` instructions to save this schema and run it with testtool.
1343
1344 Mounting NETCONF device that runs on NETCONF testtool:
1345
1346 .. code-block:: bash
1347
1348   curl --location --request PUT 'http://127.0.0.1:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=testtool' \
1349   --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
1350   --header 'Content-Type: application/json' \
1351   --data-raw '{
1352       "node": [
1353           {
1354               "node-id": "testtool",
1355               "netconf-node-topology:host": "127.0.0.1",
1356               "netconf-node-topology:port": 17830,
1357               "netconf-node-topology:keepalive-delay": 100,
1358               "netconf-node-topology:tcp-only": false,
1359               "netconf-node-topology:username": "admin",
1360               "netconf-node-topology:password": "admin"
1361           }
1362       ]
1363   }'
1364
1365 Setting initial configuration on NETCONF device:
1366
1367 .. code-block:: bash
1368
1369   curl --location --request PUT 'http://127.0.0.1:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=testtool/yang-ext:mount/test-module:root' \
1370   --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
1371   --header 'Content-Type: application/json' \
1372   --data-raw '{
1373       "root": {
1374           "simple-root": {
1375               "leaf-a": "asddhg",
1376               "leaf-b": "ffffff",
1377               "ll": [
1378                   "str1",
1379                   "str2",
1380                   "str3"
1381               ],
1382               "nested": {
1383                   "sample-x": true,
1384                   "sample-y": false
1385               }
1386           },
1387           "list-root": {
1388               "branch-ab": 5,
1389               "top-list": [
1390                   {
1391                       "key-1": "ka",
1392                       "key-2": "kb",
1393                       "next-data": {
1394                           "switch-1": [
1395                               null
1396                           ],
1397                           "switch-2": [
1398                               null
1399                           ]
1400                       },
1401                       "nested-list": [
1402                           {
1403                               "identifier": "f1",
1404                               "foo": 1
1405                           },
1406                           {
1407                               "identifier": "f2",
1408                               "foo": 10
1409                           },
1410                           {
1411                               "identifier": "f3",
1412                               "foo": 20
1413                           }
1414                       ]
1415                   },
1416                   {
1417                       "key-1": "kb",
1418                       "key-2": "ka",
1419                       "next-data": {
1420                           "switch-1": [
1421                               null
1422                           ]
1423                       },
1424                       "nested-list": [
1425                           {
1426                               "identifier": "e1",
1427                               "foo": 1
1428                           },
1429                           {
1430                               "identifier": "e2",
1431                               "foo": 2
1432                           },
1433                           {
1434                               "identifier": "e3",
1435                               "foo": 3
1436                           }
1437                       ]
1438                   },
1439                   {
1440                       "key-1": "kc",
1441                       "key-2": "ke",
1442                       "next-data": {
1443                           "switch-2": [
1444                               null
1445                           ]
1446                       },
1447                       "nested-list": [
1448                           {
1449                               "identifier": "q1",
1450                               "foo": 13
1451                           },
1452                           {
1453                               "identifier": "q2",
1454                               "foo": 14
1455                           },
1456                           {
1457                               "identifier": "q3",
1458                               "foo": 15
1459                           }
1460                       ]
1461                   }
1462               ]
1463           }
1464       }
1465   }'
1466
1467 Examples
1468 --------
1469
1470 1. Reading whole leaf-list 'll' and leaf 'nested/sample-x' under 'simple-root' container.
1471
1472 RESTCONF request:
1473
1474 .. code-block:: bash
1475
1476     curl --location --request GET 'http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=testtool/yang-ext:mount/test-module:root/simple-root?content=config&fields=ll;nested/sample-x' \
1477     --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
1478     --header 'Cookie: JSESSIONID=node01h4w82eorc1k61866b71qjgj503.node0'
1479
1480 Generated NETCONF RPC request:
1481
1482 .. code-block:: xml
1483
1484     <rpc message-id="m-18" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
1485         <get-config>
1486             <source>
1487                 <running/>
1488             </source>
1489             <filter xmlns:ns0="urn:ietf:params:xml:ns:netconf:base:1.0" ns0:type="subtree">
1490                 <root xmlns="urn:ietf:params:xml:ns:yang:test-model">
1491                     <simple-root>
1492                         <ll/>
1493                         <nested>
1494                             <sample-x/>
1495                         </nested>
1496                     </simple-root>
1497                 </root>
1498             </filter>
1499         </get-config>
1500     </rpc>
1501
1502 .. note::
1503
1504     Using fields query parameter it is also possible to read whole leaf-list or list without
1505     necessity to specify value / key predicate (without reading parent entity). Such scenario
1506     is not permitted in RFC-8040 paths alone - fields query parameter can be used as
1507     workaround for this case.
1508
1509 RESTCONF response:
1510
1511 .. code-block:: json
1512
1513     {
1514         "test-module:simple-root": {
1515             "ll": [
1516                 "str3",
1517                 "str1",
1518                 "str2"
1519             ],
1520             "nested": {
1521                 "sample-x": true
1522             }
1523         }
1524     }
1525
1526 2. Reading all identifiers of 'nested-list' under all elements of 'top-list'.
1527
1528 RESTCONF request:
1529
1530 .. code-block:: bash
1531
1532     curl --location --request GET 'http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=testtool/yang-ext:mount/test-module:root/list-root?content=config&fields=top-list(nested-list/identifier)' \
1533     --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
1534     --header 'Cookie: JSESSIONID=node01h4w82eorc1k61866b71qjgj503.node0'
1535
1536 Generated NETCONF RPC request:
1537
1538 .. code-block:: xml
1539
1540     <rpc message-id="m-27" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
1541         <get-config>
1542             <source>
1543                 <running/>
1544             </source>
1545             <filter xmlns:ns0="urn:ietf:params:xml:ns:netconf:base:1.0" ns0:type="subtree">
1546                 <root xmlns="urn:ietf:params:xml:ns:yang:test-model">
1547                     <list-root>
1548                         <top-list>
1549                             <nested-list>
1550                                 <identifier/>
1551                             </nested-list>
1552                             <key-1/>
1553                             <key-2/>
1554                         </top-list>
1555                     </list-root>
1556                 </root>
1557             </filter>
1558         </get-config>
1559     </rpc>
1560
1561 .. note::
1562
1563     NETCONF client automatically fetches values of list keys since they are required for correct
1564     deserialization of NETCONF response and at the end serialization of response to RESTCONF
1565     response (JSON/XML).
1566
1567 RESTCONF response:
1568
1569 .. code-block:: json
1570
1571     {
1572         "test-module:list-root": {
1573             "top-list": [
1574                 {
1575                     "key-1": "ka",
1576                     "key-2": "kb",
1577                     "nested-list": [
1578                         {
1579                             "identifier": "f3"
1580                         },
1581                         {
1582                             "identifier": "f2"
1583                         },
1584                         {
1585                             "identifier": "f1"
1586                         }
1587                     ]
1588                 },
1589                 {
1590                     "key-1": "kb",
1591                     "key-2": "ka",
1592                     "nested-list": [
1593                         {
1594                             "identifier": "e3"
1595                         },
1596                         {
1597                             "identifier": "e2"
1598                         },
1599                         {
1600                             "identifier": "e1"
1601                         }
1602                     ]
1603                 },
1604                 {
1605                     "key-1": "kc",
1606                     "key-2": "ke",
1607                     "nested-list": [
1608                         {
1609                             "identifier": "q3"
1610                         },
1611                         {
1612                             "identifier": "q2"
1613                         },
1614                         {
1615                             "identifier": "q1"
1616                         }
1617                     ]
1618                 }
1619             ]
1620         }
1621     }
1622
1623 3. Reading value of leaf 'branch-ab' and all values of leaves 'switch-1' that are placed
1624    under 'top-list' list elements.
1625
1626 RESTCONF request:
1627
1628 .. code-block:: bash
1629
1630     curl --location --request GET 'http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=testtool/yang-ext:mount/test-module:root/list-root?content=config&fields=branch-ab;top-list/next-data/switch-1' \
1631     --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
1632     --header 'Cookie: JSESSIONID=node01jx6o5thwae9t1ft7c2zau5zbz4.node0'
1633
1634 Generated NETCONF RPC request:
1635
1636 .. code-block:: xml
1637
1638     <rpc message-id="m-42" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
1639         <get-config>
1640             <source>
1641                 <running/>
1642             </source>
1643             <filter xmlns:ns0="urn:ietf:params:xml:ns:netconf:base:1.0" ns0:type="subtree">
1644                 <root xmlns="urn:ietf:params:xml:ns:yang:test-model">
1645                     <list-root>
1646                         <branch-ab/>
1647                         <top-list>
1648                             <next-data>
1649                                 <switch-1/>
1650                             </next-data>
1651                             <key-1/>
1652                             <key-2/>
1653                         </top-list>
1654                     </list-root>
1655                 </root>
1656             </filter>
1657         </get-config>
1658     </rpc>
1659
1660 RESTCONF response:
1661
1662 .. code-block:: json
1663
1664     {
1665         "test-module:list-root": {
1666             "branch-ab": 5,
1667             "top-list": [
1668                 {
1669                     "key-1": "ka",
1670                     "key-2": "kb",
1671                     "next-data": {
1672                         "switch-1": [
1673                             null
1674                         ]
1675                     }
1676                 },
1677                 {
1678                     "key-1": "kb",
1679                     "key-2": "ka",
1680                     "next-data": {
1681                         "switch-1": [
1682                             null
1683                         ]
1684                     }
1685                 },
1686                 {
1687                     "key-1": "kc",
1688                     "key-2": "ke"
1689                 }
1690             ]
1691         }
1692     }