# How to receive subscription notifications towards the operational data in CDB?

**URL:** <https://dmap-community.ductus.global/t/how-to-receive-subscription-notifications-towards-the-operational-data-in-cdb/110>\
**Category:** CDB and CDB API\
**Created:** [June 8, 2015, 11:06pm UTC](https://dmap-community.ductus.global/t/how-to-receive-subscription-notifications-towards-the-operational-data-in-cdb/110 "2015-06-08T23:06:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![waitai](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/waitai/32/436_2.png) [@waitai](https://dmap-community.ductus.global/u/waitai)\
**Post date:** [June 8, 2015, 11:06pm UTC](https://dmap-community.ductus.global/t/how-to-receive-subscription-notifications-towards-the-operational-data-in-cdb/110/1 "2015-06-08T23:06:09Z")

</div>

It is often times useful for your application to be notified upon changes in the operational data that are being stored in CDB.

Given the following simple YANG model:

```
module server {

  namespace "http://tail-f.com/ns/example/server";
  prefix sv;

  container server {
    leaf oper-status {
      type enumeration {
        enum up;
        enum down;
      }
      config false;
    }
  }
}

```

In order for subscription notifications to be generated, a “subscription lock” has to be obtained during the CDB write call as follows:

```
    if ((subsock = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
        confd_fatal("Failed to open socket\n");

    if (cdb_connect(subsock, CDB_DATA_SOCKET, (struct sockaddr*)&addr,
                      sizeof (struct sockaddr_in)) < 0)
        return CONFD_ERR;
    if (cdb_start_session2(subsock, CDB_OPERATIONAL, CDB_LOCK_REQUEST | CDB_LOCK_WAIT) != CONFD_OK)
        return CONFD_ERR;
    cdb_set_namespace(subsock, sv__ns);

    confd_value_t status_value;
    CONFD_SET_ENUM_VALUE(&status_value, sv_up);

    if (cdb_set_elem(subsock, &status_value, "/server/oper-status") != CONFD_OK)
        return CONFD_ERR;

    cdb_close(subsock);

```

Following is what needs to be done in order to subscribe to the CDB operational data subscription:

```
if ((subsock = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
    confd_fatal("Failed to open socket\n");

if (cdb_connect(subsock, CDB_SUBSCRIPTION_SOCKET, (struct sockaddr*)&addr,
                  sizeof (struct sockaddr_in)) < 0)
    confd_fatal("Failed to cdb_connect() to confd \n");

int spoint;

if ((status = cdb_oper_subscribe(subsock, sv__ns, &spoint, "/server/oper-status"))
    != CONFD_OK) {
    fprintf(stderr, "Terminate: subscribe %d\n", status);
    exit(0);
}

if (cdb_subscribe_done(subsock) != CONFD_OK)
    confd_fatal("cdb_subscribe_done() failed");

```

In order to manually trigger the subscription without actually changing the state of the operational data, you can do the following:

```
if ((rsock = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
    confd_fatal("Failed to open socket\n");

if (cdb_connect(rsock, CDB_DATA_SOCKET, (struct sockaddr*)&addr,
                  sizeof (struct sockaddr_in)) < 0)
    return CONFD_ERR;

int sub_points[0];

if ((cdb_trigger_oper_subscriptions(rsock, sub_points, 0, 0) != CONFD_OK)) {
    return CONFD_ERR;
}
cdb_close(rsock);

```

It is important to note that the cdb\_trigger\_oper\_subscriptions() call is blocking and doesn’t return until all subscribers have acknowledged the notification. This means that it is not possible to issue the cdb\_trigger\_oper\_subscriptions() call in a cdb subscriber process (without forking a process or spawning a thread) since it would cause a deadlock.

---

<div class="post-metadata">

**Author:** ![gpaliwal](https://avatars.discourse-cdn.com/v4/letter/g/9dc877/32.png) [@gpaliwal](https://dmap-community.ductus.global/u/gpaliwal)\
**Post date:** [June 18, 2016, 12:23am UTC](https://dmap-community.ductus.global/t/how-to-receive-subscription-notifications-towards-the-operational-data-in-cdb/110/2 "2016-06-18T00:23:49Z")

</div>

> [@waitai](#):
>
> cdb\_trigger\_oper\_subscriptions

Hello, I have a below sceneriao.

1. I have address entry in the schema where fqdn gets resolved at the run-time (which means ip-address is writable operational-data.

2. I wish to have a subscriber get a subscribe notification so that I can process it as a config-diff rather than as operational diff.

3. By iterating this diff, i will create a netconf-patch (edit-config) and will apply this patch to the basic-confd running remotely.

So basically, i want to receive all writable-operational updates as config-updates for that address object.

Is it possible to get config-updates for writable operational data and then apply this as patch to the remote basic-confd client ? Or the remote will reject it since it won’t allow edit-config operational on that writable operational data.
