Migrate netconf-server/mapping tests to JUnit5
[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 <https://www.rfc-editor.org/rfc/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 <https://www.rfc-editor.org/rfc/rfc6241>`__
39
40 -  `RFC-5277 <https://www.rfc-editor.org/rfc/rfc5277>`__
41
42 -  `RFC-6022 <https://www.rfc-editor.org/rfc/rfc6022>`__
43
44 -  `RFC-7895 <https://www.rfc-editor.org/rfc/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:
57
58 Netconf-connector configuration
59 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60
61 NETCONF connectors are configured directly through the usage of the
62 network-topology model. You can configure new NETCONF connectors both
63 through the NETCONF server for MD-SAL (port 2830) or RESTCONF. This guide
64 focuses on RESTCONF.
65
66 .. important::
67
68     Since 2022.09 Chlorine there is only one RESTCONF endpoint:
69
70     - | ``http://localhost:8181/rests`` is related to `RFC-8040 <https://www.rfc-editor.org/rfc/rfc8040>`__,
71       | can be activated by installing ``odl-restconf-nb``
72        Karaf feature.
73
74     | Resources for configuration and operational datastores start
75      ``/rests/data/``,
76     | e. g. GET
77      http://localhost:8181/rests/data/network-topology:network-topology
78      with response of both datastores. It's allowed to use query
79      parameters to distinguish between them.
80     | e. g. GET
81      http://localhost:8181/rests/data/network-topology:network-topology?content=config
82      for configuration datastore
83     | and GET
84      http://localhost:8181/rests/data/network-topology:network-topology?content=nonconfig
85      for operational datastore.
86
87     | Also if a data node in the path expression is a YANG leaf-list or list
88      node, the path segment has to be constructed by having leaf-list or
89      list node name, followed by an "=" character, then followed by the
90      leaf-list or list value. Any reserved characters must be
91      percent-encoded.
92     | e. g. GET
93      http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf?content=config
94      for retrieving data from configuration datastore for
95      topology-netconf value of topology list.
96
97 Preconditions
98 ^^^^^^^^^^^^^
99
100 1. OpenDaylight is running
101
102 2. In Karaf, you must have the ``odl-netconf-topology`` or
103    ``odl-netconf-clustered-topology`` feature installed.
104
105 3. Feature ``odl-restconf-nb`` must be installed
106
107 Spawning new NETCONF connectors
108 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109
110 To create a new NETCONF connector you need to send the following PUT request
111 to RESTCONF:
112
113 .. list-table::
114    :widths: 1 5
115
116    * - rfc8040
117      - http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device
118
119 You could use the same body to create the new  NETCONF connector with a POST
120 without specifying the node in the URL:
121
122 .. list-table::
123    :widths: 1 5
124
125    * - rfc8040
126      - http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf
127
128 Payload for password authentication:
129
130 .. tabs::
131
132    .. tab:: XML
133
134       **Content-type:** ``application/xml``
135
136       **Accept:** ``application/xml``
137
138       **Authentication:** ``admin:admin``
139
140       .. code-block:: xml
141
142          <node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
143            <node-id>new-netconf-device</node-id>
144            <host xmlns="urn:opendaylight:netconf-node-topology">127.0.0.1</host>
145            <port xmlns="urn:opendaylight:netconf-node-topology">17830</port>
146            <login-password-unencrypted xmlns="urn:opendaylight:netconf-node-topology">
147              <username xmlns="urn:opendaylight:netconf-node-topology">admin</username>
148              <password xmlns="urn:opendaylight:netconf-node-topology">admin</password>
149            </login-password-unencrypted>
150            <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
151            <!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->
152            <reconnect-on-changed-schema xmlns="urn:opendaylight:netconf-node-topology">false</reconnect-on-changed-schema>
153            <connection-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">20000</connection-timeout-millis>
154            <max-connection-attempts xmlns="urn:opendaylight:netconf-node-topology">0</max-connection-attempts>
155            <min-backoff-millis xmlns="urn:opendaylight:netconf-node-topology">2000</min-backoff-millis>
156            <max-backoff-millis xmlns="urn:opendaylight:netconf-node-topology">1800000</max-backoff-millis>
157            <backoff-multiplier xmlns="urn:opendaylight:netconf-node-topology">1.5</backoff-multiplier>
158            <!-- keepalive-delay set to 0 turns off keepalives-->
159            <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">120</keepalive-delay>
160          </node>
161
162    .. tab:: JSON
163
164       **Content-type:** ``application/json``
165
166       **Accept:** ``application/json``
167
168       **Authentication:** ``admin:admin``
169
170       .. code-block:: json
171
172          {
173              "node": [
174                  {
175                      "node-id": "new-netconf-device",
176                      "netconf-node-topology:port": 17830,
177                      "netconf-node-topology:reconnect-on-changed-schema": false,
178                      "netconf-node-topology:connection-timeout-millis": 20000,
179                      "netconf-node-topology:tcp-only": false,
180                      "netconf-node-topology:max-connection-attempts": 0,
181                      "netconf-node-topology:login-password-unencrypted": {
182                         "netconf-node-topology:username": "admin",
183                         "netconf-node-topology:password": "admin"
184                      },
185                      "netconf-node-topology:host": "127.0.0.1",
186                      "netconf-node-topology:min-backoff-millis": 2000,
187                      "netconf-node-topology:max-backoff-millis": 1800000,
188                      "netconf-node-topology:backoff-multiplier": 1.5,
189                      "netconf-node-topology:keepalive-delay": 120
190                  }
191              ]
192          }
193
194 .. note::
195
196     You have the option to use the 'login-password' configuration for authentication as shown below:
197
198     .. code-block:: json
199
200         "login-password": {
201             "netconf-node-topology:username": "netconf",
202             "netconf-node-topology:password": "c5R3aLBss7J8T2VC3pEeAQ=="
203         }
204
205     In OpenDaylight's configuration, the AAAEncryptionServiceImpl generates a new encryption key with
206     each application build. You can use this method if you have access to the current encryption key.
207     Additionally, it is important to ensure that the entire password is encoded in base64 format and
208     that its length is a multiple of 16 bytes for successful authentication.
209
210 There is also option of using key-based authentication instead
211 of password. First we need to create key in datastore.
212
213 *Adding a client private key credential to the netconf-keystore*
214
215 .. code-block::
216
217     POST HTTP/1.1
218     /rests/operations/netconf-keystore:add-keystore-entry
219     Content-Type: application/json
220     Accept: application/json
221
222 .. code-block:: json
223
224   {
225     "input": {
226       "key-credential": [
227         {
228           "key-id": "example-client-key-id",
229           "private-key": "PEM-format-private-key",
230           "passphrase": "passphrase"
231         }
232       ]
233     }
234   }
235
236 After we can use this key to create connector using this key.
237
238 Payload for key-based authentication via SSH:
239
240 .. tabs::
241
242    .. tab:: XML
243
244       **Content-type:** ``application/xml``
245
246       **Accept:** ``application/xml``
247
248       **Authentication:** ``admin:admin``
249
250       .. code-block:: xml
251
252          <node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
253            <node-id>new-netconf-device</node-id>
254            <host xmlns="urn:opendaylight:netconf-node-topology">127.0.0.1</host>
255            <port xmlns="urn:opendaylight:netconf-node-topology">17830</port>
256            <key-based xmlns="urn:opendaylight:netconf-node-topology">
257              <username xmlns="urn:opendaylight:netconf-node-topology">admin</username>
258              <key-id xmlns="urn:opendaylight:netconf-node-topology">key-id</password>
259            </key-based>
260            <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
261            <!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->
262            <reconnect-on-changed-schema xmlns="urn:opendaylight:netconf-node-topology">false</reconnect-on-changed-schema>
263            <connection-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">20000</connection-timeout-millis>
264            <max-connection-attempts xmlns="urn:opendaylight:netconf-node-topology">0</max-connection-attempts>
265            <min-backoff-millis xmlns="urn:opendaylight:netconf-node-topology">2000</min-backoff-millis>
266            <max-backoff-millis xmlns="urn:opendaylight:netconf-node-topology">1800000</max-backoff-millis>
267            <backoff-multiplier xmlns="urn:opendaylight:netconf-node-topology">1.5</backoff-multiplier>
268            <!-- keepalive-delay set to 0 turns off keepalives-->
269            <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">120</keepalive-delay>
270          </node>
271
272    .. tab:: JSON
273
274       **Content-type:** ``application/json``
275
276       **Accept:** ``application/json``
277
278       **Authentication:** ``admin:admin``
279
280       .. code-block:: json
281
282          {
283              "node": [
284                  {
285                      "node-id": "new-netconf-device",
286                      "netconf-node-topology:port": 17830,
287                      "netconf-node-topology:reconnect-on-changed-schema": false,
288                      "netconf-node-topology:connection-timeout-millis": 20000,
289                      "netconf-node-topology:tcp-only": false,
290                      "netconf-node-topology:max-connection-attempts": 0,
291                      "netconf-node-topology:key-based": {
292                         "netconf-node-topology:username": "admin",
293                         "netconf-node-topology:key-id": "key-id"
294                      },
295                      "netconf-node-topology:host": "127.0.0.1",
296                      "netconf-node-topology:min-backoff-millis": 2000,
297                      "netconf-node-topology:max-backoff-millis": 1800000,
298                      "netconf-node-topology:backoff-multiplier": 1.5,
299                      "netconf-node-topology:keepalive-delay": 120
300                  }
301              ]
302          }
303
304 Connecting via TLS protocol is similar to SSH. First setup keystore
305 by using three RPCs from `Configure device to connect over TLS protocol`_
306 to add a client private key, associate a private key with a client and CA
307 certificates chain and add a list of trusted CA and server certificates.
308 Only after that we can process and create a new NETCONF connector you need
309 to send the following PUT request.
310
311 Payload for key-based authentication via TLS:
312
313 .. tabs::
314
315    .. tab:: XML
316
317       **Content-type:** ``application/xml``
318
319       **Accept:** ``application/xml``
320
321       **Authentication:** ``admin:admin``
322
323       .. code-block:: xml
324
325          <node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
326            <node-id>new-netconf-device</node-id>
327            <host xmlns="urn:opendaylight:netconf-node-topology">127.0.0.1</host>
328            <port xmlns="urn:opendaylight:netconf-node-topology">17830</port>
329            <key-based xmlns="urn:opendaylight:netconf-node-topology">
330              <username xmlns="urn:opendaylight:netconf-node-topology">admin</username>
331              <key-id xmlns="urn:opendaylight:netconf-node-topology">key-id</password>
332            </key-based>
333            <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
334            <!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->
335            <reconnect-on-changed-schema xmlns="urn:opendaylight:netconf-node-topology">false</reconnect-on-changed-schema>
336            <connection-timeout-millis xmlns="urn:opendaylight:netconf-node-topology">20000</connection-timeout-millis>
337            <max-connection-attempts xmlns="urn:opendaylight:netconf-node-topology">0</max-connection-attempts>
338            <min-backoff-millis xmlns="urn:opendaylight:netconf-node-topology">2000</min-backoff-millis>
339            <max-backoff-millis xmlns="urn:opendaylight:netconf-node-topology">1800000</max-backoff-millis>
340            <backoff-multiplier xmlns="urn:opendaylight:netconf-node-topology">1.5</backoff-multiplier>
341            <!-- keepalive-delay set to 0 turns off keepalives-->
342            <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">120</keepalive-delay>
343            <protocol xmlns="urn:opendaylight:netconf-node-topology">
344              <name xmlns="urn:opendaylight:netconf-node-topology">TLS</name>
345            </protocol>
346          </node>
347
348    .. tab:: JSON
349
350       **Content-type:** ``application/json``
351
352       **Accept:** ``application/json``
353
354       **Authentication:** ``admin:admin``
355
356       .. code-block:: json
357
358          {
359              "node": [
360                  {
361                      "node-id": "new-netconf-device",
362                      "netconf-node-topology:port": 17830,
363                      "netconf-node-topology:reconnect-on-changed-schema": false,
364                      "netconf-node-topology:connection-timeout-millis": 20000,
365                      "netconf-node-topology:tcp-only": false,
366                      "netconf-node-topology:max-connection-attempts": 0,
367                      "netconf-node-topology:key-based": {
368                         "netconf-node-topology:username": "admin",
369                         "netconf-node-topology:key-id": "key-id"
370                      },
371                      "netconf-node-topology:host": "127.0.0.1",
372                      "netconf-node-topology:min-backoff-millis": 2000,
373                      "netconf-node-topology:max-backoff-millis": 1800000,
374                      "netconf-node-topology:backoff-multiplier": 1.5,
375                      "netconf-node-topology:keepalive-delay": 120,
376                      "protocol": {
377                         "name": "TLS"
378                      }
379                  }
380              ]
381          }
382
383
384 Note that the device name in <node-id> element must match the last
385 element of the restconf URL.
386
387 Reconfiguring an existing connector
388 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
389
390 The steps to reconfigure an existing connector are exactly the same as
391 when spawning a new connector. The old connection will be disconnected
392 and a new connector with the new configuration will be created. This needs
393 to be done with a PUT request because the node already exists. A POST
394 request will fail for that reason.
395
396 Additionally, a PATCH request can be used to modify an existing
397 configuration. Currently, only yang-patch (`RFC-8072 <https://www.rfc-editor.org/rfc/rfc8072>`__)
398 is supported. The URL would be the same as the above PUT examples.
399 Using JSON for the body, the headers needed for the request would
400 be:
401
402 Headers:
403
404 -  Accept: application/yang-data+json
405
406 -  Content-Type: application/yang-patch+json
407
408 Example JSON payload to modify the password entry:
409
410 ::
411
412     {
413       "ietf-restconf:yang-patch" : {
414         "patch-id" : "0",
415         "edit" : [
416           {
417             "edit-id" : "edit1",
418             "operation" : "merge",
419             "target" : "",
420             "value" : {
421              "node": [
422                 {
423                  "node-id": "new-netconf-device",
424                  "netconf-node-topology:password" : "newpassword"
425                 }
426              ]
427             }
428          }
429         ]
430       }
431     }
432
433 Deleting an existing connector
434 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
435
436 To remove an already configured NETCONF connector you need to send a
437 DELETE request to the same PUT request URL that was used to create the
438 device:
439
440 .. list-table::
441    :widths: 1 5
442
443    * - rfc8040
444      - http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device
445
446 .. note::
447
448     No body is needed to delete the node/device
449
450 Connecting to a device not supporting NETCONF monitoring
451 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
452
453 The netconf-connector in OpenDaylight relies on ietf-netconf-monitoring
454 support when connecting to remote NETCONF device. The
455 ietf-netconf-monitoring support allows netconf-connector to list and
456 download all YANG schemas that are used by the device. NETCONF connector
457 can only communicate with a device if it knows the set of used schemas
458 (or at least a subset). However, some devices use YANG models internally
459 but do not support NETCONF monitoring. Netconf-connector can also
460 communicate with these devices, but you have to side load the necessary
461 yang models into OpenDaylight’s YANG model cache for netconf-connector.
462 In general there are 2 situations you might encounter:
463
464 **1. NETCONF device does not support ietf-netconf-monitoring but it does
465 list all its YANG models as capabilities in HELLO message**
466
467 This could be a device that internally uses only ietf-inet-types YANG
468 model with revision 2010-09-24. In the HELLO message that is sent from
469 this device there is this capability reported:
470
471 ::
472
473     urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&revision=2010-09-24
474
475 **For such devices you only need to put the schema into folder
476 cache/schema inside your Karaf distribution.**
477
478 .. important::
479
480     The file with YANG schema for ietf-inet-types has to be called
481     ietf-inet-types@2010-09-24.yang. It is the required naming format of
482     the cache.
483
484 **2. NETCONF device does not support ietf-netconf-monitoring and it does
485 NOT list its YANG models as capabilities in HELLO message**
486
487 Compared to device that lists its YANG models in HELLO message, in this
488 case there would be no capability with ietf-inet-types in the HELLO
489 message. This type of device basically provides no information about the
490 YANG schemas it uses so its up to the user of OpenDaylight to properly
491 configure netconf-connector for this device.
492
493 Netconf-connector has an optional configuration attribute called
494 yang-module-capabilities and this attribute can contain a list of "YANG
495 module based" capabilities. So by setting this configuration attribute,
496 it is possible to override the "yang-module-based" capabilities reported
497 in HELLO message of the device. To do this, we need to modify the
498 configuration of netconf-connector like in the example below:
499
500 .. tabs::
501
502    .. tab:: XML
503
504       **Content-type:** ``application/xml``
505
506       **Accept:** ``application/xml``
507
508       **Authentication:** ``admin:admin``
509
510       .. code-block:: xml
511
512          <node xmlns="urn:TBD:params:xml:ns:yang:network-topology">
513            <node-id>r5</node-id>
514            <host xmlns="urn:opendaylight:netconf-node-topology">127.0.0.1</host>
515            <port xmlns="urn:opendaylight:netconf-node-topology">8305</port>
516            <login-password-unencrypted xmlns="urn:opendaylight:netconf-node-topology">
517              <username xmlns="urn:opendaylight:netconf-node-topology">root</username>
518              <password xmlns="urn:opendaylight:netconf-node-topology">root</password>
519            </login-password-unencrypted>
520            <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>
521            <keepalive-delay xmlns="urn:opendaylight:netconf-node-topology">30</keepalive-delay>
522            <yang-module-capabilities xmlns="urn:opendaylight:netconf-node-topology">
523              <override>true</override>
524              <capability xmlns="urn:opendaylight:netconf-node-topology">
525                urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&amp;revision=2013-07-15
526              </capability>
527            </yang-module-capabilities>
528          </node>
529
530    .. tab:: JSON
531
532       **Content-type:** ``application/json``
533
534       **Accept:** ``application/json``
535
536       **Authentication:** ``admin:admin``
537
538       .. code-block:: json
539
540          {
541              "node": [
542                  {
543                      "node-id": "device",
544                      "netconf-node-topology:host": "127.0.0.1",
545                      "netconf-node-topology:login-password-unencrypted": {
546                         "netconf-node-topology:password": "root",
547                         "netconf-node-topology:username": "root"
548                      },
549                      "netconf-node-topology:yang-module-capabilities": {
550                          "override": true,
551                          "capability": [
552                              "urn:ietf:params:xml:ns:yang:ietf-inet-types?module=ietf-inet-types&revision=2013-07-15"
553                          ]
554                      },
555                      "netconf-node-topology:port": 8305,
556                      "netconf-node-topology:tcp-only": false,
557                      "netconf-node-topology:keepalive-delay": 30
558                  }
559              ]
560          }
561
562 **Remember to also put the YANG schemas into the cache folder.**
563
564 .. note::
565
566     For putting multiple capabilities, you just need to replicate the
567     capability element inside yang-module-capability element.
568     Capability element is modeled as a leaf-list. With this
569     configuration, we would make the remote device report usage of
570     ietf-inet-types in the eyes of netconf-connector.
571
572 Connecting to a device supporting only NETCONF 1.0
573 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
574
575 OpenDaylight is schema-based distribution and heavily depends on YANG
576 models. However some legacy NETCONF devices are not schema-based and
577 implement just RFC 4741. This type of device does not utilize YANG
578 models internally and OpenDaylight does not know how to communicate
579 with such devices, how to validate data, or what the semantics of data
580 are.
581
582 NETCONF connector can communicate also with these devices, but the
583 trade-offs are worsened possibilities in utilization of NETCONF
584 mountpoints. Using RESTCONF with such devices is not supported. Also
585 communicating with schemaless devices from application code is slightly
586 different.
587
588 To connect to schemaless device, there is a optional configuration option
589 in netconf-node-topology model called schemaless. You have to set this
590 option to true.
591
592 Clustered NETCONF connector
593 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
594
595 To spawn NETCONF connectors that are cluster-aware you need to install
596 the ``odl-netconf-clustered-topology`` karaf feature.
597
598 .. warning::
599
600     The ``odl-netconf-topology`` and ``odl-netconf-clustered-topology``
601     features are considered **INCOMPATIBLE**. They both manage the same
602     space in the datastore and would issue conflicting writes if
603     installed together.
604
605 Configuration of clustered NETCONF connectors works the same as the
606 configuration through the topology model in the previous section.
607
608 When a new clustered connector is configured the configuration gets
609 distributed among the member nodes and a NETCONF connector is spawned on
610 each node. From these nodes a master is chosen which handles the schema
611 download from the device and all the communication with the device. You
612 will be able to read/write to/from the device from all slave nodes due
613 to the proxy data brokers implemented.
614
615 You can use the ``odl-netconf-clustered-topology`` feature in a single
616 node scenario as well but the code that uses akka will be used, so for a
617 scenario where only a single node is used, ``odl-netconf-topology``
618 might be preferred.
619
620 Netconf-connector utilization
621 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
622
623 Once the connector is up and running, users can utilize the new mount
624 point instance. By using RESTCONF or from their application code. This
625 chapter deals with using RESTCONF and more information for app
626 developers can be found in the developers guide or in the official
627 tutorial application **ncmount** that can be found in the coretutorials
628 project:
629
630 -  https://github.com/opendaylight/coretutorials/tree/master/ncmount
631
632 Reading data from the device
633 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
634
635 Just invoke (no body needed):
636
637 GET
638 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device/yang-ext:mount?content=nonconfig
639
640 This will return the entire content of operation datastore from the
641 device. To view just the configuration datastore, change **nonconfig**
642 in this URL to **config**.
643
644 Writing configuration data to the device
645 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
646
647 In general, you cannot simply write any data you want to the device. The
648 data have to conform to the YANG models implemented by the device. In
649 this example we are adding a new interface-configuration to the mounted
650 device (assuming the device supports Cisco-IOS-XR-ifmgr-cfg YANG model).
651 In fact this request comes from the tutorial dedicated to the
652 **ncmount** tutorial app.
653
654 POST
655 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
656
657 ::
658
659     <interface-configuration xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
660         <active>act</active>
661         <interface-name>mpls</interface-name>
662         <description>Interface description</description>
663         <bandwidth>32</bandwidth>
664         <link-status></link-status>
665     </interface-configuration>
666
667 Should return 200 response code with no body.
668
669 .. tip::
670
671     This call is transformed into a couple of NETCONF RPCs. Resulting
672     NETCONF RPCs that go directly to the device can be found in the
673     OpenDaylight logs after invoking ``log:set TRACE
674     org.opendaylight.controller.sal.connect.netconf`` in the Karaf
675     shell. Seeing the NETCONF RPCs might help with debugging.
676
677 This request is very similar to the one where we spawned a new netconf
678 device. That’s because we used the loopback netconf-connector to write
679 configuration data into config-subsystem datastore and config-subsystem
680 picked it up from there.
681
682 Invoking custom RPC
683 ^^^^^^^^^^^^^^^^^^^
684
685 Devices can implement any additional RPC and as long as it provides YANG
686 models for it, it can be invoked from OpenDaylight. Following example
687 shows how to invoke the get-schema RPC (get-schema is quite common among
688 netconf devices). Invoke:
689
690 POST
691 http://localhost:8181/rests/operations/network-topology:network-topology/topology=topology-netconf/node=new-netconf-device/yang-ext:mount/ietf-netconf-monitoring:get-schema
692
693 ::
694
695     <input xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">
696       <identifier>ietf-yang-types</identifier>
697       <version>2013-07-15</version>
698     </input>
699
700 This call should fetch the source for ietf-yang-types YANG model from
701 the mounted device.
702
703 Receiving Netconf Device Notifications on a http client
704 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
705
706 Devices emit netconf alarms and notifications in certain situations, which can demand
707 attention from Device Administration. The notifications are received as Netconf messages on an
708 active Netconf session.
709
710 Opendaylight provides the way to stream the device notifications over a http session.
711
712 - Step 1: Mount the device (assume node name is test_device)
713
714 - Step 2: Wait for the device to be connected.
715
716 - Step 3: Create the Subscription for notification on the active session.
717
718  .. code-block::
719
720     POST
721     http://localhost:8181/rests/operations/network-topology:network-topology/topology=topology-netconf/node=test_device/yang-ext:mount/notifications:create-subscription
722     Content-Type: application/json
723     Accept: application/json
724
725  .. code-block:: json
726
727     {
728       "input": {
729         "stream": "NETCONF"
730        }
731     }
732
733 - Step 4: Create the http Stream for the events.
734
735 .. code-block::
736
737     POST
738     http://localhost:8181/rests/operations/odl-device-notification:subscribe-device-notification
739     Content-Type: application/json
740     Accept: application/json
741
742 .. code-block:: json
743
744     {
745       "input": {
746          "path":"/network-topology:network-topology/topology[topology-id='topology-netconf']/node[node-id='test_device']"
747       }
748     }
749
750 The response contains the stream name for reading the notifications.
751
752 .. code-block:: json
753
754     {
755        "odl-device-notification:output": {
756             "stream-name": "urn:uuid:91e630ec-1324-4f57-bae3-0925b6d11ffd"
757         }
758     }
759
760 - Step 5: To receive notifications send GET request to url as follows:
761
762 .. code-block::
763
764     http://localhost:8181/rests/streams/{encoding}/{stream-name}
765
766 {stream-name} - being **stream-name** received in previous step
767
768 {encoding} - being desired encoding to be received, either "xml" or "json"
769
770 The request for xml encoding and **stream-name** from previous example would look like this:
771
772 .. code-block::
773
774     GET
775     http://localhost:8181/rests/streams/xml/urn:uuid:91e630ec-1324-4f57-bae3-0925b6d11ffd
776     Content-Type: application/xml
777     Accept: application/xml
778
779
780 .. code-block:: xml
781
782     : ping
783
784     : ping
785
786     : ping
787
788     : ping
789
790     : ping
791
792     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>
793
794     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>
795
796 Change event notification subscription tutorial
797 -----------------------------------------------
798
799 Subscribing to data change notifications makes it possible to obtain
800 notifications about data manipulation (insert, change, delete) which are
801 done on any specified **path** of any specified **datastore** with
802 specific **scope**. In following examples *{odlAddress}* is address of
803 server where ODL is running and *{odlPort}* is port on which
804 OpenDaylight is running. OpenDaylight offers two methods for receiving notifications:
805 Server-Sent Events (SSE) and WebSocket. SSE is the default notification mechanism used in OpenDaylight.
806
807 SSE notifications subscription process
808 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
809
810 In this section we will learn what steps need to be taken in order to
811 successfully subscribe to data change event notifications.
812
813 Create stream
814 ^^^^^^^^^^^^^
815
816 In order to use event notifications you first need to call RPC that
817 creates notification stream that you can later listen to. You need to
818 provide three parameters to this RPC:
819
820 -  **path**: data store path that you plan to listen to. You can
821    register listener on containers, lists and leaves.
822
823 -  **datastore**: data store type. *OPERATIONAL* or *CONFIGURATION*.
824
825 -  **scope**: Represents scope of data change. Possible options are:
826
827    -  BASE: only changes directly to the data tree node specified in the
828       path will be reported
829
830    -  ONE: changes to the node and to direct child nodes will be
831       reported
832
833    -  SUBTREE: changes anywhere in the subtree starting at the node will
834       be reported
835
836 The RPC to create the stream can be invoked via RESTCONF like this:
837
838 ::
839
840     OPERATION: POST
841     URI:  http://{odlAddress}:{odlPort}/rests/operations/sal-remote:create-data-change-event-subscription
842     HEADER: Content-Type=application/json
843             Accept=application/json
844
845 .. code-block:: json
846
847        {
848            "input": {
849                "path": "/toaster:toaster/toaster:toasterStatus",
850                "sal-remote-augment:datastore": "OPERATIONAL",
851                "sal-remote-augment:scope": "ONE"
852            }
853        }
854
855 The response should look something like this:
856
857 .. code-block:: json
858
859     {
860         "sal-remote:output": {
861             "stream-name": "data-change-event-subscription/toaster:toaster/toaster:toasterStatus/datastore=CONFIGURATION/scope=SUBTREE"
862         }
863     }
864
865 **stream-name** is important because you will need to use it when you
866 subscribe to the stream in the next step.
867
868 .. note::
869
870     Internally, this will create a new listener for *stream-name* if it
871     did not already exist.
872
873 Subscribe to stream
874 ^^^^^^^^^^^^^^^^^^^
875
876 In order to subscribe to stream and obtain SSE location you need
877 to call *GET* on your stream path. The URI should generally be
878 `http://{odlAddress}:{odlPort}/rests/data/ietf-restconf-monitoring:restconf-state/streams/stream/{streamName}`,
879 where *{streamName}* is the *stream-name* parameter contained in
880 response from *create-data-change-event-subscription* RPC from the
881 previous step.
882
883 ::
884
885    OPERATION: GET
886    URI: http://{odlAddress}:{odlPort}/rests/data/ietf-restconf-monitoring:restconf-state/streams/stream/data-change-event-subscription/toaster:toaster/datastore=CONFIGURATION/scope=SUBTREE
887
888 The subscription call may be modified with the following query parameters defined in the RESTCONF RFC:
889
890 -  `filter <https://www.rfc-editor.org/rfc/rfc8040#section-4.8.4>`__
891
892 -  `start-time <https://www.rfc-editor.org/rfc/rfc8040#section-4.8.7>`__
893
894 -  `end-time <https://www.rfc-editor.org/rfc/rfc8040#section-4.8.8>`__
895
896 In addition, the following ODL extension query parameter is supported:
897
898 :odl-leaf-nodes-only:
899   If this parameter is set to "true", create and update notifications will only
900   contain the leaf nodes modified instead of the entire subscription subtree.
901   This can help in reducing the size of the notifications.
902
903 :odl-skip-notification-data:
904   If this parameter is set to "true", create and update notifications will only
905   contain modified leaf nodes without data.
906   This can help in reducing the size of the notifications.
907
908 The response should look something like this:
909
910 .. code-block:: json
911
912     {
913         "subscribe-to-notification:location": "http://localhost:8181/rests/notif/data-change-event-subscription/network-topology:network-topology/datastore=CONFIGURATION/scope=SUBTREE"
914     }
915
916 .. note::
917
918     During this phase there is an internal check for to see if a
919     listener for the *stream-name* from the URI exists. If not, new a
920     new listener is registered with the DOM data broker.
921
922 Receive notifications
923 ^^^^^^^^^^^^^^^^^^^^^
924
925 Once you got SSE location you can now connect to it and
926 start receiving data change events. The request should look something like this:
927
928 ::
929
930     curl -v -X GET  http://localhost:8181/rests/notif/data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE  -H "Content-Type: text/event-stream" -H "Authorization: Basic YWRtaW46YWRtaW4="
931
932
933 WebSocket notifications subscription process
934 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
935
936 Enabling WebSocket notifications in OpenDaylight requires a manual setup before starting the application.
937 The following steps can be followed to enable WebSocket notifications in OpenDaylight:
938
939 1. Open the file `org.opendaylight.restconf.nb.rfc8040.cfg`, at `etc/` folder inside your Karaf distribution. Or create in case it does not exist.
940 2. Locate the `use-sse` configuration parameter and change its value from `true` to `false`. Or add ``use-sse=false`` as new line in case this parameter is not present.
941 3. Save the changes made to the `org.opendaylight.restconf.nb.rfc8040.cfg` file.
942 4. Restart OpenDaylight if it is already running.
943
944 Once these steps are completed, WebSocket notifications will be enabled in OpenDaylight,
945 and they can be used for receiving notifications instead of SSE.
946
947 WebSocket Notifications subscription process is the same as SSE until you receive a location of WebSocket.
948 You can follow steps given above and after subscribing to a notification stream over WebSocket,
949 you will receive a response indicating that the subscription was successful:
950
951 .. code-block:: json
952
953     {
954         "subscribe-to-notification:location": "ws://localhost:8181/rests/notif/data-change-event-subscription/network-topology:network-topology/datastore=CONFIGURATION/scope=SUBTREE"
955     }
956
957 You can use this WebSocket to listen to data
958 change notifications. To listen to notifications you can use a
959 JavaScript client or if you are using chrome browser you can use the
960 `Simple WebSocket
961 Client <https://chrome.google.com/webstore/detail/simple-websocket-client/pfdhoblngboilpfeibdedpjgfnlcodoo>`__.
962
963 Also, for testing purposes, there is simple Java application named
964 WebSocketClient. The application is placed in the
965 */restconf/websocket-client* project. It accepts a WebSocket URI
966 as an input parameter. After starting the utility (WebSocketClient
967 class directly in Eclipse/InteliJ Idea) received notifications should be
968 displayed in console.
969
970 Notifications are always in XML format and look like this:
971
972 .. code-block:: xml
973
974     <notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
975         <eventTime>2014-09-11T09:58:23+02:00</eventTime>
976         <data-changed-notification xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote">
977             <data-change-event>
978                 <path xmlns:meae="http://netconfcentral.org/ns/toaster">/meae:toaster</path>
979                 <operation>updated</operation>
980                 <data>
981                    <!-- updated data -->
982                 </data>
983             </data-change-event>
984         </data-changed-notification>
985     </notification>
986
987 Example use case
988 ~~~~~~~~~~~~~~~~
989
990 The typical use case is listening to data change events to update web
991 page data in real time. In this tutorial we will be using toaster as the
992 base.
993
994 When you call *make-toast* RPC, it sets *toasterStatus* to "down" to
995 reflect that the toaster is busy making toast. When it finishes,
996 *toasterStatus* is set to "up" again. We will listen to these toaster
997 status changes in data store and will reflect it on our web page in
998 real-time thanks to WebSocket data change notification.
999
1000 Simple javascript client implementation
1001 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1002
1003 We will create a simple JavaScript web application that will listen for
1004 updates on *toasterStatus* leaf and update some elements of our web page
1005 according to the new toaster status state.
1006
1007 Create stream
1008 ^^^^^^^^^^^^^
1009
1010 First you need to create stream that you are planning to subscribe to.
1011 This can be achieved by invoking "create-data-change-event-subscription"
1012 RPC on RESTCONF via AJAX request. You need to provide data store
1013 **path** that you plan to listen on, **data store type** and **scope**.
1014 If the request is successful you can extract the **stream-name** from
1015 the response and use that to subscribe to the newly created stream. The
1016 *{username}* and *{password}* fields represent the credentials that you
1017 use to connect to OpenDaylight via RESTCONF:
1018
1019 .. note::
1020
1021     The default user name and password are "admin".
1022
1023 .. code-block:: javascript
1024
1025     function createStream() {
1026         $.ajax(
1027             {
1028                 url: 'http://{odlAddress}:{odlPort}/rests/operations/sal-remote:create-data-change-event-subscription',
1029                 type: 'POST',
1030                 headers: {
1031                   'Authorization': 'Basic ' + btoa('{username}:{password}'),
1032                   'Content-Type': 'application/json'
1033                 },
1034                 data: JSON.stringify(
1035                     {
1036                         'input': {
1037                             'path': '/toaster:toaster/toaster:toasterStatus',
1038                             'sal-remote-augment:datastore': 'OPERATIONAL',
1039                             'sal-remote-augment:scope': 'ONE'
1040                         }
1041                     }
1042                 )
1043             }).done(function (data) {
1044                 // this function will be called when ajax call is executed successfully
1045                 subscribeToStream(data.output['stream-name']);
1046             }).fail(function (data) {
1047                 // this function will be called when ajax call fails
1048                 console.log("Create stream call unsuccessful");
1049             })
1050     }
1051
1052 Subscribe to stream
1053 ^^^^^^^^^^^^^^^^^^^
1054
1055 The Next step is to subscribe to the stream. To subscribe to the stream
1056 you need to call *GET* on
1057 *http://{odlAddress}:{odlPort}/rests/data/ietf-restconf-monitoring:restconf-state/streams/stream/{stream-name}*.
1058 If the call is successful, you get WebSocket address for this stream in
1059 **Location** parameter inside response header. You can get response
1060 header by calling *getResponseHeader(\ *Location*)* on HttpRequest
1061 object inside *done()* function call:
1062
1063 .. code-block:: javascript
1064
1065     function subscribeToStream(streamName) {
1066         $.ajax(
1067             {
1068                 url: 'http://{odlAddress}:{odlPort}/rests/data/ietf-restconf-monitoring:restconf-state/streams/stream/' + streamName;
1069                 type: 'GET',
1070                 headers: {
1071                   'Authorization': 'Basic ' + btoa('{username}:{password}'),
1072                 }
1073             }
1074         ).done(function (data, textStatus, httpReq) {
1075             // we need function that has http request object parameter in order to access response headers.
1076             listenToNotifications(httpReq.getResponseHeader('Location'));
1077         }).fail(function (data) {
1078             console.log("Subscribe to stream call unsuccessful");
1079         });
1080     }
1081
1082 Receive notifications
1083 ^^^^^^^^^^^^^^^^^^^^^
1084
1085 Once you have WebSocket server location you can now connect to it and
1086 start receiving data change events. You need to define functions that
1087 will handle events on WebSocket. In order to process incoming events
1088 from OpenDaylight you need to provide a function that will handle
1089 *onmessage* events. The function must have one parameter that represents
1090 the received event object. The event data will be stored in
1091 *event.data*. The data will be in an XML format that you can then easily
1092 parse using jQuery.
1093
1094 .. code-block:: javascript
1095
1096     function listenToNotifications(socketLocation) {
1097         try {
1098             var notificatinSocket = new WebSocket(socketLocation);
1099
1100             notificatinSocket.onmessage = function (event) {
1101                 // we process our received event here
1102                 console.log('Received toaster data change event.');
1103                 $($.parseXML(event.data)).find('data-change-event').each(
1104                     function (index) {
1105                         var operation = $(this).find('operation').text();
1106                         if (operation == 'updated') {
1107                             // toaster status was updated so we call function that gets the value of toasterStatus leaf
1108                             updateToasterStatus();
1109                             return false;
1110                         }
1111                     }
1112                 );
1113             }
1114             notificatinSocket.onerror = function (error) {
1115                 console.log("Socket error: " + error);
1116             }
1117             notificatinSocket.onopen = function (event) {
1118                 console.log("Socket connection opened.");
1119             }
1120             notificatinSocket.onclose = function (event) {
1121                 console.log("Socket connection closed.");
1122             }
1123             // if there is a problem on socket creation we get exception (i.e. when socket address is incorrect)
1124         } catch(e) {
1125             alert("Error when creating WebSocket" + e );
1126         }
1127     }
1128
1129 The *updateToasterStatus()* function represents function that calls
1130 *GET* on the path that was modified and sets toaster status in some web
1131 page element according to received data. After the WebSocket connection
1132 has been established you can test events by calling make-toast RPC via
1133 RESTCONF.
1134
1135 .. note::
1136
1137     for more information about WebSockets in JavaScript visit `Writing
1138     WebSocket client
1139     applications <https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications>`__
1140
1141 Netconf-connector + Netopeer
1142 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1143
1144 `Netopeer <https://github.com/cesnet/netopeer>`__ (an open-source
1145 NETCONF server) can be used for testing/exploring NETCONF southbound in
1146 OpenDaylight.
1147
1148 Netopeer installation
1149 ^^^^^^^^^^^^^^^^^^^^^
1150
1151 A `Docker <https://www.docker.com/>`__ container with netopeer will be
1152 used in this guide. To install Docker and start the `netopeer
1153 image <https://hub.docker.com/r/sysrepo/sysrepo-netopeer2>`__ perform
1154 following steps:
1155
1156 1. Install docker https://docs.docker.com/get-started/
1157
1158 2. Start the netopeer image:
1159
1160    ::
1161
1162        docker run -it --name sysrepo -p 830:830 --rm sysrepo/sysrepo-netopeer2:latest
1163
1164 3. Verify netopeer is running by invoking (netopeer should send its
1165    HELLO message right away:
1166
1167    ::
1168
1169        ssh root@localhost -p 830 -s netconf
1170        (password root)
1171
1172 Mounting netopeer NETCONF server
1173 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1174
1175 Preconditions:
1176
1177 -  OpenDaylight is started with features ``odl-restconf-all`` and
1178    ``odl-netconf-connector-all``.
1179
1180 -  Netopeer is up and running in docker
1181
1182 Now just follow the section: `Spawning new NETCONF connectors`_ for
1183 password authentication.
1184 In the payload change the:
1185
1186 -  name, e.g., to netopeer
1187
1188 -  username/password to your system credentials
1189
1190 -  ip to localhost
1191
1192 -  port to 830.
1193
1194 After netopeer is mounted successfully, its configuration can be read
1195 using RESTCONF by invoking:
1196
1197 GET
1198 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=netopeer/yang-ext:mount?content:config
1199
1200 Mounting netopeer NETCONF server using key-based authentication SSH
1201 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1202
1203 1. Install docker https://docs.docker.com/get-started/
1204
1205 2. Create RSA key pair - it will be user for connection.
1206
1207 3. Start the netopeer image(this command will also copy you pub key
1208    into docker container):
1209
1210    ::
1211
1212        docker run -dt -p 830:830 -v {path-to-pub-key}:/home/{netopeer-username}/.ssh/authorized_keys sysrepo/sysrepo-netopeer2:latest netopeer2-server -d -v 2
1213
1214 4. Verify netopeer is running by invoking (netopeer should send its
1215    HELLO message right away:
1216
1217    ::
1218
1219        ssh root@localhost -p 830 -s netconf
1220        (password root)
1221
1222 Now just follow the section: `Spawning new NETCONF connectors`_ for
1223 key-based authentication(SSH) to create device.
1224 In the payload change the:
1225
1226 -  name, e.g., to netopeer
1227
1228 -  username/password to your system credentials
1229
1230 -  ip to localhost
1231
1232 -  port to 830.
1233
1234 After netopeer is mounted successfully, its configuration can be read
1235 using RESTCONF by invoking:
1236
1237 GET
1238 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=netopeer/yang-ext:mount?content:config
1239
1240 Mounting netopeer NETCONF server using key-based authentication TLS
1241 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1242
1243 1. Install docker https://docs.docker.com/get-started/
1244
1245 2. Run netopeer2
1246
1247    ::
1248
1249        docker pull sysrepo/sysrepo-netopeer2
1250        docker run -it --name sysrepo -p 830:830 --rm sysrepo/sysrepo-netopeer2:latest
1251
1252 3. Enable TLS communication on server netopeer2
1253
1254    ::
1255
1256        ssh root@localhost -p 830 -s netconf
1257        (type password root)
1258
1259    After successful connecting to netopeer2 setup your
1260    TLS configuration xml
1261    (See: https://github.com/CESNET/netopeer2/tree/master/example_configuration).
1262
1263 4. Run ODL:
1264
1265 -  :~/netconf/karaf/target/assembly/bin$ ./karaf
1266
1267 -  feature:install odl-netconf-topology odl-restconf-nb-bierman02 odl-mdsal-apidocs
1268
1269 5. Set up ODL netconf keystore
1270
1271    To setup keystore is needed to send three RPCs from
1272    `Configure device to connect over TLS protocol`_
1273    to add a client private key, associate a private key with a client and CA
1274    certificates chain and add a list of trusted CA and server certificates.
1275
1276 Now just follow the section: `Spawning new NETCONF connectors`_ for
1277 key-based authentication(TLS) to create device.
1278 In the payload change the:
1279
1280 -  name, e.g., to netopeer
1281
1282 -  username/password to your system credentials
1283
1284 -  ip to localhost
1285
1286 -  port to 830.
1287
1288 After netopeer is mounted successfully, its configuration can be read
1289 using RESTCONF by invoking:
1290
1291 GET
1292 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=netopeer/yang-ext:mount?content:config
1293
1294 Northbound (NETCONF servers)
1295 ----------------------------
1296
1297 OpenDaylight provides 2 types of NETCONF servers:
1298
1299 -  **NETCONF server for config-subsystem (listening by default on port
1300    1830)**
1301
1302    -  Serves as a default interface for config-subsystem and allows
1303       users to spawn/reconfigure/destroy modules (or applications) in
1304       OpenDaylight
1305
1306 -  **NETCONF server for MD-SAL (listening by default on port 2830)**
1307
1308    -  Serves as an alternative interface for MD-SAL (besides RESTCONF)
1309       and allows users to read/write data from MD-SAL’s datastore and to
1310       invoke its rpcs (NETCONF notifications are not available in the
1311       Boron release of OpenDaylight)
1312
1313 .. note::
1314
1315     The reason for having 2 NETCONF servers is that config-subsystem and
1316     MD-SAL are 2 different components of OpenDaylight and require
1317     different approaches for NETCONF message handling and data
1318     translation. These 2 components will probably merge in the future.
1319
1320 .. note::
1321
1322     Since Nitrogen release, there has been performance regression in NETCONF
1323     servers accepting SSH connections. While opening a connection takes
1324     less than 10 seconds on Carbon, on Nitrogen time can increase up to
1325     60 seconds. Please see https://jira.opendaylight.org/browse/ODLPARENT-112
1326
1327 NETCONF server for config-subsystem
1328 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1329
1330 This NETCONF server is the primary interface for config-subsystem. It
1331 allows the users to interact with config-subsystem in a standardized
1332 NETCONF manner.
1333
1334 In terms of RFCs, these are supported:
1335
1336 -  `RFC-6241 <https://www.rfc-editor.org/rfc/rfc6241>`__
1337
1338 -  `RFC-5277 <https://www.rfc-editor.org/rfc/rfc5277>`__
1339
1340 -  `RFC-6470 <https://www.rfc-editor.org/rfc/rfc6470>`__
1341
1342    -  (partially, only the schema-change notification is available in
1343       Boron release)
1344
1345 -  `RFC-6022 <https://www.rfc-editor.org/rfc/rfc6022>`__
1346
1347 For regular users it is recommended to use RESTCONF + the
1348 controller-config loopback mountpoint instead of using pure NETCONF. How
1349 to do that is specific for each component/module/application in
1350 OpenDaylight and can be found in their dedicated user guides.
1351
1352 NETCONF server for MD-SAL
1353 ~~~~~~~~~~~~~~~~~~~~~~~~~
1354
1355 This NETCONF server is just a generic interface to MD-SAL in
1356 OpenDaylight. It uses the standard MD-SAL APIs and serves as an
1357 alternative to RESTCONF. It is fully model-driven and supports any data
1358 and rpcs that are supported by MD-SAL.
1359
1360 In terms of RFCs, these are supported:
1361
1362 -  `RFC-6241 <https://www.rfc-editor.org/rfc/rfc6241>`__
1363
1364 -  `RFC-6022 <https://www.rfc-editor.org/rfc/rfc6022>`__
1365
1366 -  `RFC-7895 <https://www.rfc-editor.org/rfc/rfc7895>`__
1367
1368 Notifications over NETCONF are not supported in the Boron release.
1369
1370 .. tip::
1371
1372     Install NETCONF northbound for MD-SAL by installing feature:
1373     ``odl-netconf-mdsal`` in karaf. Default binding port is **2830**.
1374
1375 Configuration
1376 ^^^^^^^^^^^^^
1377
1378 The default configuration can be found in file: *08-netconf-mdsal.xml*.
1379 The file contains the configuration for all necessary dependencies and a
1380 single SSH endpoint starting on port 2830. There is also a (by default
1381 disabled) TCP endpoint. It is possible to start multiple endpoints at
1382 the same time either in the initial configuration file or while
1383 OpenDaylight is running.
1384
1385 The credentials for SSH endpoint can also be configured here, the
1386 defaults are admin/admin. Credentials in the SSH endpoint are not yet
1387 managed by the centralized AAA component and have to be configured
1388 separately.
1389
1390 Verifying MD-SAL’s NETCONF server
1391 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1392
1393 After the NETCONF server is available it can be examined by a command
1394 line ssh tool:
1395
1396 ::
1397
1398     ssh admin@localhost -p 2830 -s netconf
1399
1400 The server will respond by sending its HELLO message and can be used as
1401 a regular NETCONF server from then on.
1402
1403 Mounting the MD-SAL’s NETCONF server
1404 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1405
1406 To perform this operation, just spawn a new netconf-connector as
1407 described in `Spawning new NETCONF connectors`_. Just change the ip to
1408 "127.0.0.1" port to "2830" and its name to "controller-mdsal".
1409
1410 Now the MD-SAL’s datastore can be read over RESTCONF via NETCONF by
1411 invoking:
1412
1413 GET
1414 http://localhost:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=controller-mdsal/yang-ext:mount?content:nonconfig
1415
1416 .. note::
1417
1418     This might not seem very useful, since MD-SAL can be accessed
1419     directly from RESTCONF or from Application code, but the same method
1420     can be used to mount and control other OpenDaylight instances by the
1421     "master OpenDaylight".
1422
1423 NETCONF stress/performance measuring tool
1424 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1425
1426 This is basically a NETCONF client that puts NETCONF servers under heavy
1427 load of NETCONF RPCs and measures the time until a configurable amount
1428 of them is processed.
1429
1430 RESTCONF stress-performance measuring tool
1431 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1432
1433 Very similar to NETCONF stress tool with the difference of using
1434 RESTCONF protocol instead of NETCONF.
1435
1436 YANGLIB remote repository
1437 -------------------------
1438
1439 There are scenarios in NETCONF deployment, that require for a centralized
1440 YANG models repository. YANGLIB plugin provides such remote repository.
1441
1442 To start this plugin, you have to install odl-yanglib feature. Then you
1443 have to configure YANGLIB either through RESTCONF or NETCONF. We will
1444 show how to configure YANGLIB through RESTCONF.
1445
1446 YANGLIB configuration
1447 ~~~~~~~~~~~~~~~~~~~~~
1448 YANGLIB configuration works through OSGi Configuration Admin interface, in the
1449 ``org.opendaylight.netconf.yanglib`` configuration PID. There are three tuneables you can
1450 set:
1451
1452 * ``cache-folder``, which defaults to ``cache/schema``
1453 * ``binding-address``, which defaults to ``localhost``
1454 * ``binding-port``, which defaults to ``8181``
1455
1456 In order to change these settings, you can either modify the corresponding configuration
1457 file, ``etc/org.opendaylight.netconf.yanglib.cfg``, for example:
1458
1459 ::
1460     cache-folder = cache/newSchema
1461     binding-address = localhost
1462     binding-port = 8181
1463
1464 Or use Karaf CLI:
1465
1466 ::
1467     opendaylight-user@root>config:edit org.opendaylight.netconf.yanglib
1468     opendaylight-user@root>config:property-set cache-folder cache/newSchema
1469     opendaylight-user@root>config:property-set binding-address localhost
1470     opendaylight-user@root>config:property-set binding-port 8181
1471     opendaylight-user@root>config:update
1472
1473 This YANGLIB takes all YANG sources from the configured sources folder and
1474 for each generates URL in form:
1475
1476 ::
1477
1478     http://localhost:8181/yanglib/schemas/{modelName}/{revision}
1479
1480 On this URL will be hosted YANG source for particular module.
1481
1482 YANGLIB instance also writes this URL along with source identifier to
1483 ietf-netconf-yang-library/modules-state/module list.
1484
1485 Netconf-connector with YANG library as fallback
1486 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1487
1488 There is an optional configuration in netconf-connector called
1489 yang-library. You can specify YANG library to be plugged as additional
1490 source provider into the mount's schema repository. Since YANGLIB
1491 plugin is advertising provided modules through yang-library model, we
1492 can use it in mount point's configuration as YANG library.  To do this,
1493 we need to modify the configuration of netconf-connector by adding this
1494 XML
1495
1496 ::
1497
1498     <yang-library xmlns="urn:opendaylight:netconf-node-topology">
1499       <yang-library-url xmlns="urn:opendaylight:netconf-node-topology">http://localhost:8181/rests/data/ietf-yang-library:modules-state</yang-library-url>
1500       <username xmlns="urn:opendaylight:netconf-node-topology">admin</username>
1501       <password xmlns="urn:opendaylight:netconf-node-topology">admin</password>
1502     </yang-library>
1503
1504 This will register YANGLIB provided sources as a fallback schemas for
1505 particular mount point.
1506
1507 Restconf northbound configuration
1508 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1509 Restconf-nb configuration works through OSGi Configuration Admin interface, in the
1510 ``org.opendaylight.restconf.nb.rfc8040`` configuration PID. There are six tuneables you can
1511 set:
1512
1513 * ``maximum-fragment-length``, which defaults to ``0``
1514 * ``heartbeat-interval``, which defaults to ``10000``
1515 * ``idle-timeout``, which defaults to ``30000``
1516 * ``ping-executor-name-prefix``, which defaults to ``ping-executor``
1517 * ``max-thread-count``, which defaults to ``1``
1518 * ``use-sse``, which defaults to ``true``
1519 * ``restconf``, which defaults to ``rests``
1520
1521 *maximum-fragment-length* â€” Maximum web-socket fragment length in number of Unicode code units (characters)
1522 (exceeded message length leads to fragmentation of messages)
1523
1524 *heartbeat-interval* â€” Interval in milliseconds between sending of ping control frames.
1525
1526 *idle-timeout* â€” Maximum idle time of web-socket session before the session is closed (milliseconds).
1527
1528 *ping-executor-name-prefix* â€” Name of thread group Ping Executor will be run with.
1529
1530 *max-thread-count* â€” Number of threads Ping Executor will be run with.
1531
1532 *use-sse* â€” In case of ``true`` access to notification streams will be via Server-Sent Events.
1533 Otherwise web-socket servlet will be initialized.
1534
1535 *restconf* â€” The value of RFC8040 restconf URI template, pointing to the root resource. Must not end with '/'.
1536
1537 In order to change these settings, you can either modify the corresponding configuration
1538 file, ``org.opendaylight.restconf.nb.rfc8040.cfg``, for example:
1539
1540 ::
1541
1542     maximum-fragment-length=0
1543     heartbeat-interval=10000
1544     idle-timeout=30000
1545     ping-executor-name-prefix=ping-executor
1546     max-thread-count=1
1547     use-sse=true
1548     restconf=rests
1549
1550 Or use Karaf CLI:
1551
1552 ::
1553
1554     opendaylight-user@root>config:edit org.opendaylight.restconf.nb.rfc8040
1555     opendaylight-user@root>config:property-set maximum-fragment_length 0
1556     opendaylight-user@root>config:property-set heartbeat-interval 10000
1557     opendaylight-user@root>config:property-set idle-timeout 30000
1558     opendaylight-user@root>config:property-set ping-executor-name-prefix "ping-executor"
1559     opendaylight-user@root>config:property-set max-thread-count 1
1560     opendaylight-user@root>config:property-set use-sse true
1561     opendaylight-user@root>config:property-set restconf "rests"
1562     opendaylight-user@root>config:update
1563
1564 NETCONF Call Home
1565 -----------------
1566
1567 Call Home Installation
1568 ~~~~~~~~~~~~~~~~~~~~~~
1569
1570 ODL Call-Home server is installed in Karaf by installing karaf feature
1571 ``odl-netconf-callhome-ssh``. RESTCONF feature is recommended for
1572 configuring Call Home & testing its functionality.
1573
1574 ::
1575
1576   feature:install odl-netconf-callhome-ssh
1577
1578
1579 .. note::
1580
1581     In order to test Call Home functionality we recommend Netopeer or
1582     Netopeer2. See `Netopeer Call Home <https://github.com/CESNET/netopeer/wiki/CallHome>`__
1583     or `Netopeer2 <https://github.com/CESNET/netopeer2>`__ to learn how to
1584     enable call-home on Netopeer.
1585
1586 Northbound Call-Home API
1587 ~~~~~~~~~~~~~~~~~~~~~~~~
1588
1589 The northbound Call Home API is used for administering the Call-Home Server. The
1590 following describes this configuration.
1591
1592 Global Configuration
1593 ^^^^^^^^^^^^^^^^^^^^
1594
1595 .. important::
1596   The global configuration is not a part of the `RFC 8071
1597   <https://www.rfc-editor.org/rfc/rfc8071>`__ and, therefore, subject to change.
1598
1599 Configuring global credentials
1600 ''''''''''''''''''''''''''''''
1601
1602 The ODL Call-Home server allows user to configure global credentials, which will be
1603 used for devices connecting over SSH transport protocol that do not have
1604 device-specific credentials configured.
1605
1606 This is done by creating
1607 ``/odl-netconf-callhome-server:netconf-callhome-server/global/credentials``
1608 with username and passwords specified.
1609
1610 *Configuring global username & passwords to try*
1611
1612 .. code-block::
1613
1614     PUT HTTP/1.1
1615     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/global/credentials
1616     Content-Type: application/json
1617     Accept: application/json
1618
1619 .. code-block:: json
1620
1621     {
1622       "credentials":
1623       {
1624         "username": "example",
1625         "passwords": [ "first-password-to-try", "second-password-to-try" ]
1626       }
1627     }
1628
1629 Configuring to accept any ssh server key using global credentials
1630 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1631
1632 By default Netconf Call-Home Server accepts only incoming connections
1633 from allowed devices
1634 ``/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices``,
1635 if user desires to allow all incoming connections, it is possible to set
1636 ``accept-all-ssh-keys`` to ``true`` in
1637 ``/odl-netconf-callhome-server:netconf-callhome-server/global``.
1638
1639 The name of these devices in ``netconf-topology`` will be in format
1640 ``ip-address:port``. For naming devices see Device-Specific
1641 Configuration.
1642
1643 *Allowing unknown devices to connect*
1644
1645 This is a debug feature and should not be used in production. Besides being an obvious
1646 security issue, this also causes the Call-Home Server to drastically increase its output
1647 to the log.
1648
1649 .. code-block::
1650
1651     PUT HTTP/1.1
1652     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/global/accept-all-ssh-keys
1653     Content-Type: application/json
1654     Accept: application/json
1655
1656 .. code-block:: json
1657
1658     {
1659         "accept-all-ssh-keys": "true"
1660     }
1661
1662 Device-Specific Configuration
1663 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1664
1665 Netconf Call Home server supports both of the secure transports used
1666 by the Network Configuration Protocol (NETCONF) - Secure Shell (SSH),
1667 and Transport Layer Security (TLS).
1668
1669 Configure device to connect over SSH protocol
1670 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1671
1672 Netconf Call Home Server uses device provided SSH server key (host key)
1673 to identify device. The pairing of name and server key is configured in
1674 ``/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices``.
1675 This list is colloquially called a allowlist.
1676
1677 If the Call-Home Server finds the SSH host key in the allowlist, it continues
1678 to negotiate a NETCONF connection over an SSH session. If the SSH host key is
1679 not found, the connection between the Call Home server and the device is dropped
1680 immediately. In either case, the device that connects to the Call home server
1681 leaves a record of its presence in the operational store.
1682
1683 Configuring Device with Device-specific Credentials
1684 '''''''''''''''''''''''''''''''''''''''''''''''''''
1685
1686 Adding specific device to the allowed list is done by creating
1687 ``/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device={device}``
1688 with device-id and connection parameters inside the ssh-client-params container.
1689
1690 *Configuring Device with Credentials*
1691
1692 .. code-block::
1693
1694     PUT HTTP/1.1
1695     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example
1696     Content-Type: application/json
1697     Accept: application/json
1698
1699 .. code-block:: json
1700
1701     {
1702       "device": {
1703         "unique-id": "example",
1704         "ssh-client-params": {
1705           "credentials": {
1706             "username": "example",
1707             "passwords": [ "password" ]
1708           },
1709           "host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1710         }
1711       }
1712     }
1713
1714 Configuring Device with Global Credentials
1715 '''''''''''''''''''''''''''''''''''''''''''''''''''
1716
1717 It is possible to omit ``username`` and ``password`` for ssh-client-params,
1718 in such case values from global credentials will be used.
1719
1720 *Example of configuring device*
1721
1722 .. code-block::
1723
1724     PUT HTTP/1.1
1725     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example
1726     Content-Type: application/json
1727     Accept: application/json
1728
1729 .. code-block:: json
1730
1731     {
1732       "device": {
1733         "unique-id": "example",
1734         "ssh-client-params": {
1735           "host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1736         }
1737       }
1738     }
1739
1740 Deprecated configuration models for devices accessed with SSH protocol
1741 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
1742
1743 With `RFC 8071 <https://www.rfc-editor.org/rfc/rfc8071>`__ alignment and adding
1744 support for TLS transport following configuration models have been marked
1745 deprecated.
1746
1747 Configuring Device with Global Credentials
1748 '''''''''''''''''''''''''''''''''''''''''''''''''''
1749
1750 *Example of configuring device*
1751
1752 .. code-block::
1753
1754     PUT HTTP/1.1
1755     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example
1756     Content-Type: application/json
1757     Accept: application/json
1758
1759 .. code-block:: json
1760
1761     {
1762       "device": {
1763         "unique-id": "example",
1764         "ssh-host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1765       }
1766     }
1767
1768 Configuring Device with Device-specific Credentials
1769 '''''''''''''''''''''''''''''''''''''''''''''''''''
1770
1771 Call Home Server also allows the configuration of credentials per device basis.
1772 This is done by introducing ``credentials`` container into the
1773 device-specific configuration. Format is same as in global credentials.
1774
1775 *Configuring Device with Credentials*
1776
1777 .. code-block::
1778
1779     PUT HTTP/1.1
1780     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example
1781     Content-Type: application/json
1782     Accept: application/json
1783
1784 .. code-block:: json
1785
1786     {
1787       "device": {
1788         "unique-id": "example",
1789         "credentials": {
1790           "username": "example",
1791           "passwords": [ "password" ]
1792         },
1793         "ssh-host-key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDHoH1jMjltOJnCt999uaSfc48ySutaD3ISJ9fSECe1Spdq9o9mxj0kBTTTq+2V8hPspuW75DNgN+V/rgJeoUewWwCAasRx9X4eTcRrJrwOQKzb5Fk+UKgQmenZ5uhLAefi2qXX/agFCtZi99vw+jHXZStfHm9TZCAf2zi+HIBzoVksSNJD0VvPo66EAvLn5qKWQD4AdpQQbKqXRf5/W8diPySbYdvOP2/7HFhDukW8yV/7ZtcywFUIu3gdXsrzwMnTqnATSLPPuckoi0V2jd8dQvEcu1DY+rRqmqu0tEkFBurlRZDf1yhNzq5xWY3OXcjgDGN+RxwuWQK3cRimcosH"
1794       }
1795     }
1796
1797 Configure device to connect over TLS protocol
1798 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1799
1800 Netconf Call Home Server allows devices to use TLS transport protocol to
1801 establish a connection towards the NETCONF device. This communication
1802 requires proper setup to make two-way TLS authentication possible for client
1803 and server.
1804
1805 The initial step is to configure certificates and keys for two-way TLS by
1806 storing them within the netconf-keystore.
1807
1808 *Adding a client private key credential to the netconf-keystore*
1809
1810 .. code-block::
1811
1812     POST HTTP/1.1
1813     /rests/operations/netconf-keystore:add-keystore-entry
1814     Content-Type: application/json
1815     Accept: application/json
1816
1817 .. code-block:: json
1818
1819   {
1820     "input": {
1821       "key-credential": [
1822         {
1823           "key-id": "example-client-key-id",
1824           "private-key": "PEM-format-private-key",
1825           "passphrase": "passphrase"
1826         }
1827       ]
1828     }
1829   }
1830
1831 *Associate a private key with a client and CA certificates chain*
1832
1833 .. code-block::
1834
1835     POST HTTP/1.1
1836     /rests/operations/netconf-keystore:add-private-key
1837     Content-Type: application/json
1838     Accept: application/json
1839
1840 .. code-block:: json
1841
1842   {
1843     "input": {
1844       "private-key": [
1845         {
1846           "name": "example-client-key-id",
1847           "data": "key-data",
1848           "certificate-chain": [
1849             "certificate-data"
1850           ]
1851         }
1852       ]
1853     }
1854   }
1855
1856 *Add a list of trusted CA and server certificates*
1857
1858 .. code-block::
1859
1860     POST HTTP/1.1
1861     /rests/operations/netconf-keystore:add-trusted-certificate
1862     Content-Type: application/json
1863     Accept: application/json
1864
1865 .. code-block:: json
1866
1867   {
1868     "input": {
1869       "trusted-certificate": [
1870         {
1871           "name": "example-ca-certificate",
1872           "certificate": "ca-certificate-data"
1873         },
1874         {
1875           "name": "example-server-certificate",
1876           "certificate": "server-certificate-data"
1877         }
1878       ]
1879     }
1880   }
1881
1882 In a second step, it is required to create an allowed device associated with
1883 a server certificate and client key. The server certificate will be used to
1884 identify and pin the NETCONF device during SSL handshake and should be unique
1885 among the allowed devices.
1886
1887 *Add device configuration for TLS protocol to allowed devices list*
1888
1889 .. code-block::
1890
1891     PUT HTTP/1.1
1892     /rests/data/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices/device=example-device
1893     Content-Type: application/json
1894     Accept: application/json
1895
1896 .. code-block:: json
1897
1898   {
1899     "device": {
1900       "unique-id": "example-device",
1901       "tls-client-params": {
1902         "key-id": "example-client-key-id",
1903         "certificate-id": "example-server-certificate"
1904       }
1905     }
1906   }
1907
1908 Operational Status
1909 ^^^^^^^^^^^^^^^^^^
1910
1911 Once an entry is made on the config side of "allowed-devices", the Call-Home Server will
1912 populate a corresponding operational device that is the same as the config device but
1913 has an additional status. By default, this status is *DISCONNECTED*. Once a device calls
1914 home, this status will change to one of:
1915
1916 *CONNECTED* â€” The device is currently connected and the NETCONF mount is available for network
1917 management.
1918
1919 *FAILED_AUTH_FAILURE* â€” The last attempted connection was unsuccessful because the Call-Home
1920 Server was unable to provide the acceptable credentials of the device. The device is also
1921 disconnected and not available for network management.
1922
1923 *FAILED_NOT_ALLOWED* â€” The last attempted connection was unsuccessful because the device was
1924 not recognized as an acceptable device. The device is also disconnected and not available for
1925 network management.
1926
1927 *FAILED* â€” The last attempted connection was unsuccessful for a reason other than not
1928 allowed to connect or incorrect client credentials. The device is also disconnected and not
1929 available for network management.
1930
1931 *DISCONNECTED* â€” The device is currently disconnected.
1932
1933 Rogue Devices
1934 '''''''''''''
1935
1936 Devices that are not on the allowlist might try to connect to the Call-Home Server. In
1937 these cases, the server will keep a record by instantiating an operational device. There
1938 will be no corresponding config device for these rogues. They can be identified readily
1939 because their device id, rather than being user-supplied, will be of the form
1940 "address:port". Note that if a device calls back multiple times, there will only be
1941 a single operatinal entry (even if the port changes); these devices are recognized by
1942 their unique host key.
1943
1944 Southbound Call-Home API
1945 ~~~~~~~~~~~~~~~~~~~~~~~~
1946
1947 The Call-Home Server listens for incoming TCP connections and assumes that the other side of
1948 the connection is a device calling home via a NETCONF connection with SSH for
1949 management. The server uses port 4334 by default and this can be configured via a
1950 blueprint configuration file.
1951
1952 The device **must** initiate the connection and the server will not try to re-establish the
1953 connection in case of a drop. By requirement, the server cannot assume it has connectivity
1954 to the device due to NAT or firewalls among others.
1955
1956 Reading data with selected fields
1957 ---------------------------------
1958
1959 Overview
1960 ~~~~~~~~
1961
1962 If user would like to read only selected fields from a NETCONF device, it is possible to use
1963 the fields query parameter that is described by RFC-8040. RESTCONF parses content of query
1964 parameter into format that is accepted by NETCONF subtree filtering - filtering of data is done
1965 on NETCONF server, not on NETCONF client side. This approach optimizes network traffic load,
1966 because data in which user doesn't have interest, is not transferred over network.
1967
1968 Next advantages:
1969
1970 * using single RESTCONF request and single NETCONF RPC for reading multiple subtrees
1971 * possibility to read only selected fields under list node across multiple hierarchies
1972   (it cannot be done without proper selection API)
1973
1974 .. note::
1975
1976   More information about fields query parameter: `RFC 8071 <https://www.rfc-editor.org/rfc/rfc8040#section-4.8.3>`__
1977
1978 Preparation of data
1979 ~~~~~~~~~~~~~~~~~~~
1980
1981 For demonstration, we will define next YANG model:
1982
1983 ::
1984
1985     module test-module {
1986         yang-version 1.1;
1987         namespace "urn:opendaylight:test-module";
1988         prefix "tm";
1989         revision "2023-02-16";
1990
1991         container root {
1992             container simple-root {
1993                 leaf leaf-a {
1994                     type string;
1995                 }
1996                 leaf leaf-b {
1997                     type string;
1998                 }
1999                 leaf-list ll {
2000                     type string;
2001                 }
2002                 container nested {
2003                     leaf sample-x {
2004                         type boolean;
2005                     }
2006                     leaf sample-y {
2007                         type boolean;
2008                     }
2009                 }
2010             }
2011
2012             container list-root {
2013                 leaf branch-ab {
2014                     type int32;
2015                 }
2016                 list top-list {
2017                     key "key-1 key-2";
2018                     ordered-by user;
2019                     leaf key-1 {
2020                         type string;
2021                     }
2022                     leaf key-2 {
2023                         type string;
2024                     }
2025                     container next-data {
2026                         leaf switch-1 {
2027                             type empty;
2028                         }
2029                         leaf switch-2 {
2030                             type empty;
2031                         }
2032                     }
2033                     list nested-list {
2034                         key "identifier";
2035                         leaf identifier {
2036                             type string;
2037                         }
2038                         leaf foo {
2039                             type int32;
2040                         }
2041                     }
2042                 }
2043             }
2044         }
2045     }
2046
2047 Follow the :doc:`testtool` instructions to save this schema and run it with testtool.
2048
2049 Mounting NETCONF device that runs on NETCONF testtool:
2050
2051 .. code-block:: bash
2052
2053   curl --location --request PUT 'http://127.0.0.1:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=testtool' \
2054   --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
2055   --header 'Content-Type: application/json' \
2056   --data-raw '{
2057       "node": [
2058           {
2059               "node-id": "testtool",
2060               "netconf-node-topology:host": "127.0.0.1",
2061               "netconf-node-topology:port": 17830,
2062               "netconf-node-topology:keepalive-delay": 100,
2063               "netconf-node-topology:tcp-only": false,
2064               "netconf-node-topology:login-password-unencrypted": {
2065                   "netconf-node-topology:username": "admin",
2066                   "netconf-node-topology:password": "admin"
2067               },
2068           }
2069       ]
2070   }'
2071
2072 Setting initial configuration on NETCONF device:
2073
2074 .. code-block:: bash
2075
2076   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' \
2077   --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
2078   --header 'Content-Type: application/json' \
2079   --data-raw '{
2080       "root": {
2081           "simple-root": {
2082               "leaf-a": "asddhg",
2083               "leaf-b": "ffffff",
2084               "ll": [
2085                   "str1",
2086                   "str2",
2087                   "str3"
2088               ],
2089               "nested": {
2090                   "sample-x": true,
2091                   "sample-y": false
2092               }
2093           },
2094           "list-root": {
2095               "branch-ab": 5,
2096               "top-list": [
2097                   {
2098                       "key-1": "ka",
2099                       "key-2": "kb",
2100                       "next-data": {
2101                           "switch-1": [
2102                               null
2103                           ],
2104                           "switch-2": [
2105                               null
2106                           ]
2107                       },
2108                       "nested-list": [
2109                           {
2110                               "identifier": "f1",
2111                               "foo": 1
2112                           },
2113                           {
2114                               "identifier": "f2",
2115                               "foo": 10
2116                           },
2117                           {
2118                               "identifier": "f3",
2119                               "foo": 20
2120                           }
2121                       ]
2122                   },
2123                   {
2124                       "key-1": "kb",
2125                       "key-2": "ka",
2126                       "next-data": {
2127                           "switch-1": [
2128                               null
2129                           ]
2130                       },
2131                       "nested-list": [
2132                           {
2133                               "identifier": "e1",
2134                               "foo": 1
2135                           },
2136                           {
2137                               "identifier": "e2",
2138                               "foo": 2
2139                           },
2140                           {
2141                               "identifier": "e3",
2142                               "foo": 3
2143                           }
2144                       ]
2145                   },
2146                   {
2147                       "key-1": "kc",
2148                       "key-2": "ke",
2149                       "next-data": {
2150                           "switch-2": [
2151                               null
2152                           ]
2153                       },
2154                       "nested-list": [
2155                           {
2156                               "identifier": "q1",
2157                               "foo": 13
2158                           },
2159                           {
2160                               "identifier": "q2",
2161                               "foo": 14
2162                           },
2163                           {
2164                               "identifier": "q3",
2165                               "foo": 15
2166                           }
2167                       ]
2168                   }
2169               ]
2170           }
2171       }
2172   }'
2173
2174 Examples
2175 --------
2176
2177 1. Reading whole leaf-list 'll' and leaf 'nested/sample-x' under 'simple-root' container.
2178
2179 RESTCONF request:
2180
2181 .. code-block:: bash
2182
2183     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' \
2184     --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
2185     --header 'Cookie: JSESSIONID=node01h4w82eorc1k61866b71qjgj503.node0'
2186
2187 Generated NETCONF RPC request:
2188
2189 .. code-block:: xml
2190
2191     <rpc message-id="m-18" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
2192         <get-config>
2193             <source>
2194                 <running/>
2195             </source>
2196             <filter xmlns:ns0="urn:ietf:params:xml:ns:netconf:base:1.0" ns0:type="subtree">
2197                 <root xmlns="urn:ietf:params:xml:ns:yang:test-model">
2198                     <simple-root>
2199                         <ll/>
2200                         <nested>
2201                             <sample-x/>
2202                         </nested>
2203                     </simple-root>
2204                 </root>
2205             </filter>
2206         </get-config>
2207     </rpc>
2208
2209 .. note::
2210
2211     Using fields query parameter it is also possible to read whole leaf-list or list without
2212     necessity to specify value / key predicate (without reading parent entity). Such scenario
2213     is not permitted in RFC-8040 paths alone - fields query parameter can be used as
2214     workaround for this case.
2215
2216 RESTCONF response:
2217
2218 .. code-block:: json
2219
2220     {
2221         "test-module:simple-root": {
2222             "ll": [
2223                 "str3",
2224                 "str1",
2225                 "str2"
2226             ],
2227             "nested": {
2228                 "sample-x": true
2229             }
2230         }
2231     }
2232
2233 2. Reading all identifiers of 'nested-list' under all elements of 'top-list'.
2234
2235 RESTCONF request:
2236
2237 .. code-block:: bash
2238
2239     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)' \
2240     --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
2241     --header 'Cookie: JSESSIONID=node01h4w82eorc1k61866b71qjgj503.node0'
2242
2243 Generated NETCONF RPC request:
2244
2245 .. code-block:: xml
2246
2247     <rpc message-id="m-27" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
2248         <get-config>
2249             <source>
2250                 <running/>
2251             </source>
2252             <filter xmlns:ns0="urn:ietf:params:xml:ns:netconf:base:1.0" ns0:type="subtree">
2253                 <root xmlns="urn:ietf:params:xml:ns:yang:test-model">
2254                     <list-root>
2255                         <top-list>
2256                             <nested-list>
2257                                 <identifier/>
2258                             </nested-list>
2259                             <key-1/>
2260                             <key-2/>
2261                         </top-list>
2262                     </list-root>
2263                 </root>
2264             </filter>
2265         </get-config>
2266     </rpc>
2267
2268 .. note::
2269
2270     NETCONF client automatically fetches values of list keys since they are required for correct
2271     deserialization of NETCONF response and at the end serialization of response to RESTCONF
2272     response (JSON/XML).
2273
2274 RESTCONF response:
2275
2276 .. code-block:: json
2277
2278     {
2279         "test-module:list-root": {
2280             "top-list": [
2281                 {
2282                     "key-1": "ka",
2283                     "key-2": "kb",
2284                     "nested-list": [
2285                         {
2286                             "identifier": "f3"
2287                         },
2288                         {
2289                             "identifier": "f2"
2290                         },
2291                         {
2292                             "identifier": "f1"
2293                         }
2294                     ]
2295                 },
2296                 {
2297                     "key-1": "kb",
2298                     "key-2": "ka",
2299                     "nested-list": [
2300                         {
2301                             "identifier": "e3"
2302                         },
2303                         {
2304                             "identifier": "e2"
2305                         },
2306                         {
2307                             "identifier": "e1"
2308                         }
2309                     ]
2310                 },
2311                 {
2312                     "key-1": "kc",
2313                     "key-2": "ke",
2314                     "nested-list": [
2315                         {
2316                             "identifier": "q3"
2317                         },
2318                         {
2319                             "identifier": "q2"
2320                         },
2321                         {
2322                             "identifier": "q1"
2323                         }
2324                     ]
2325                 }
2326             ]
2327         }
2328     }
2329
2330 3. Reading value of leaf 'branch-ab' and all values of leaves 'switch-1' that are placed
2331    under 'top-list' list elements.
2332
2333 RESTCONF request:
2334
2335 .. code-block:: bash
2336
2337     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' \
2338     --header 'Authorization: Basic YWRtaW46YWRtaW4=' \
2339     --header 'Cookie: JSESSIONID=node01jx6o5thwae9t1ft7c2zau5zbz4.node0'
2340
2341 Generated NETCONF RPC request:
2342
2343 .. code-block:: xml
2344
2345     <rpc message-id="m-42" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
2346         <get-config>
2347             <source>
2348                 <running/>
2349             </source>
2350             <filter xmlns:ns0="urn:ietf:params:xml:ns:netconf:base:1.0" ns0:type="subtree">
2351                 <root xmlns="urn:ietf:params:xml:ns:yang:test-model">
2352                     <list-root>
2353                         <branch-ab/>
2354                         <top-list>
2355                             <next-data>
2356                                 <switch-1/>
2357                             </next-data>
2358                             <key-1/>
2359                             <key-2/>
2360                         </top-list>
2361                     </list-root>
2362                 </root>
2363             </filter>
2364         </get-config>
2365     </rpc>
2366
2367 RESTCONF response:
2368
2369 .. code-block:: json
2370
2371     {
2372         "test-module:list-root": {
2373             "branch-ab": 5,
2374             "top-list": [
2375                 {
2376                     "key-1": "ka",
2377                     "key-2": "kb",
2378                     "next-data": {
2379                         "switch-1": [
2380                             null
2381                         ]
2382                     }
2383                 },
2384                 {
2385                     "key-1": "kb",
2386                     "key-2": "ka",
2387                     "next-data": {
2388                         "switch-1": [
2389                             null
2390                         ]
2391                     }
2392                 },
2393                 {
2394                     "key-1": "kc",
2395                     "key-2": "ke"
2396                 }
2397             ]
2398         }
2399     }
2400
2401 Reading module source
2402 ---------------------
2403
2404 Overview
2405 ~~~~~~~~
2406
2407 If user would like to read module source from a Controller or NETCONF device, it is possible to use
2408 the subpath "modules". Revision of the module is optional, so it is passed as a query parameter. There is
2409 also a possibility to read modules in yang format or in yin format.
2410
2411 *Read module source from controller*
2412
2413 .. code-block::
2414
2415     GET
2416     /rests/modules/{module-name}?revision={revision}
2417     Accept: application/yang or application/yin+xml
2418
2419 *Read mounted module source from device*
2420
2421 .. code-block::
2422
2423     GET
2424     /rests/modules/network-topology:network-topology/topology=topology-netconf/node={node-id}/yang-ext:mount/{module-name}?revision={revision}
2425     Accept: application/yang or application/yin+xml
2426
2427 RESTCONF OpenAPI
2428 ----------------
2429
2430 Overview
2431 ~~~~~~~~
2432
2433 The OpenAPI provides full API for configurational data which can be edited (by POST, PUT, PATCH and DELETE).
2434 For operational data we only provide GET API. For the majority of requests you can see only config data in examples.
2435 That’s because we can show only one example per request. The exception when you can see operational data in an
2436 example is when data are representing an operational (config false) container with no config data in it.
2437
2438
2439 Using the OpenAPI Explorer through HTTP
2440 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2441
2442 1. Install OpenApi into Karaf by installing karaf feature:
2443
2444 ::
2445
2446     $ feature:install odl-restconf-openapi
2447
2448 2.  Navigate to OpenAPI in your web browser which is available at URLs:
2449
2450 -  http://localhost:8181/openapi/explorer/index.html for general overview
2451
2452 -  http://localhost:8181/openapi/api/v3/single for JSON data
2453
2454 .. note::
2455
2456     In the URL links for OpenAPI, change *localhost* to the IP/Host name of your actual server.
2457
2458 3.  Enter the username and password.
2459     By default the credentials are  *admin/admin*.
2460
2461 4.  Select any model to try out.
2462
2463 5.  Select any available request to try out.
2464
2465 6.  Click on the **Try it out** button.
2466
2467 7.  Provide any required parameters or edit request body.
2468
2469 8.  Click the **Execute** button.
2470
2471 9.  You can see responses to the given request.
2472
2473
2474 OpenAPI Explorer can also be used for connected device. How to connect a device can be found :ref:`here <netconf-connector>`.
2475
2476 OpenAPI URLs in that case would look like this:
2477
2478 -  `http://localhost:8181/openapi/explorer/index.html?urls.primaryName=17830-sim-device resources - RestConf RFC 8040 <http://localhost:8181/openapi/explorer/index.html?urls.primaryName=17830-sim-device%20resources%20-%20RestConf%20RFC%208040>`_ for device overview
2479
2480 -  http://localhost:8181/openapi/api/v3/mounts/1 for JSON data
2481
2482 -  `http://localhost:8181/openapi/api/v3/mounts/1/toaster(2009-11-20) <http://localhost:8181/openapi/api/v3/mounts/1/toaster(2009-11-20)>`__ JSON data for given model
2483
2484 .. note::
2485
2486     The URL links for OpenAPI are made for device with name *17830-sim-device* and model toaster
2487     with *2009-11-20* revision and need to be changed accordingly to connected device.