How to modify the 1-2-3-start-query-model example to receive CDB subscription notifications in CLI format

As was described in Integrating ConfD with an existing CLI management infrastructure, you can use the cdb_get_modifications_cli( ) API in order to receive CDB configuration changes as a sequence of Cisco style CLI commands.

To illustrate how that works, the socket poll( ) loop inside the main( ) of dhcpd_conf.c has been modified as follows:

while (1) {
    static int poll_fail_counter=0;
    struct pollfd set[1];

    set[0].fd = subsock;
    set[0].events = POLLIN;
    set[0].revents = 0;

    if (poll(&set[0], 1, -1) < 0) {
        perror("Poll failed:");
        if(++poll_fail_counter < 10)
            continue;
        fprintf(stderr, "Too many poll failures, terminating\n");
        exit(1);
    }

    poll_fail_counter = 0;
    if (set[0].revents & POLLIN) {
        int sub_points[1];
        int reslen;

        if ((status = cdb_read_subscription_socket(subsock,
                                                   &sub_points[0],
                                                   &reslen)) != CONFD_OK) {
            fprintf(stderr, "terminate sub_read: %d\n", status);
            exit(1);
        }
        if (reslen > 0) {
            if ((status = cdb_get_modifications_cli(subsock, sub_points[0], 0, &str)) != CONFD_OK) {
                fprintf(stderr, "Terminate: cdb_get_modifications_cli %d\n", status);
                exit(1);
            }
            else {
                printf("CLI command of CDB changes:\n%s", str);
                free(str);
            }
        }

        if ((status = cdb_sync_subscription_socket(subsock,
                                                   CDB_DONE_PRIORITY))
            != CONFD_OK) {
            fprintf(stderr, "failed to sync subscription: %d\n", status);
            exit(1);
        }
    }
}

Instead of reading all of the configuration changes from CDB using the various cdb_get_xxx( ) API calls over a CDB session according to the schema of the data model as was done in the original example, you will now receive the sequence of CLI commands as a string.

When you send the following NETCONF edit-config request to ConfD (after it has been started with “make all start”) using netconf-console in the interactive mode:

$ netconf-console -i

* Enter a NETCONF operation, end with an empty line
  <edit-config>
    <target>
      <running/>
    </target>
    <config>
      <dhcp xmlns="http://tail-f.com/ns/example/dhcpd">
        <defaultLeaseTime>PT30M</defaultLeaseTime>
        <maxLeaseTime>PT6400S</maxLeaseTime>
        <logFacility>mail</logFacility>
      </dhcp>
    </config>
  </edit-config>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
  <ok/>
</rpc-reply>

You will then see the trace output from ./dhcpd_conf as follows:

./dhcpd_conf 
TRACE Connected (cdb) to ConfD
TRACE CDB_SUBSCRIBE /dhcp --> CONFD_OK
TRACE CDB_SUBSCRIBE_DONE  --> CONFD_OK
Subscription point = 6
TRACE CDB_SUBSCRIPTION_EVENT --> 6
TRACE CDB_GET_CLI  --> CONFD_OK
CLI command of CDB changes:
dhcp defaultLeaseTime 30m
dhcp maxLeaseTime 6400s
dhcp logFacility mail
TRACE CDB_SYNC_SUB CDB_DONE_PRIORITY --> CONFD_OK

The output of the CLI commands as shown above can then be fed to the CLI session of the legacy CLI-based application. There is now NETCONF support added to the legacy application.

I tried the API, for creating operation, CONFD provide the full command list from parent node to children nodes. while for deleting parent node, there is no children nodes provided. is it possible to have a fully list of children nodes when deleting a parent node?

If everything under a node is deleted, there will be only one “no path to my node” CLI command generated by cdb_get_modifications_cli() for that node and all children nodes.