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