Module restriction using data provider API

Dear Team,

I would like to know that whether confd supports for module element level restrictions.I mean that i have 10 applications trying to access the same module which contains 10 leaf, one of my instant(application) wants to access only 5,6,7and 8 leaf and another application have access permission for 1,2 and 3 leaf like that.I need to implement instant basis access level restriction,Is it possible with confd? how to achieve this ?if you have any example please share that will help me to understand more.

Regard,
Aarur

Hi Aarur,

Which ConfD API will your applications use, e.g. CDB, DP, MAAPI, NETCONF?
Will they read only or write too?
Will they access configuration and/or operational data?

Hi Cohult,

      Small change in my previous post sorry for the confusion .I'm looking for key based filtering for application.For example take the arpe example 

container arpentries {
config false;
list arpe {
key “ip ifname”;
max-elements 1024;
leaf ip {
type inet:ip-address;
}
leaf ifname {
type string;
}
leaf hwaddr {
type string;
mandatory true;
}
leaf permanent {
type boolean;
mandatory true;
}
leaf published {
type boolean;
mandatory true;
}
I have two applications trying to get the value based on key .first application only get the rows matches with key “192.34.56.23,eth1” and second will get rows matches with key “198.32.45.67,eth2”.how i can achieve this?

Regards,
Aarur

Say we have an APR table like this one:

$ arp -a
apps-net0-13.test.com (172.16.171.13) at dd:aa:aa:aa:aa:bb [ether] PERM on eth1
apps-net0-9.test.com (172.16.171.10) at aa:aa:aa:aa:aa:aa [ether] PERM on eth1
apps-net0-1.test.com (172.16.171.2) at 00:50:56:f7:9d:e2 [ether] on eth1
apps-net15-14.test.com (172.16.171.254) at 00:50:56:fc:2e:c5 [ether] on eth0
apps-net0-11.test.com (172.16.171.11) at aa:aa:aa:aa:aa:bb [ether] PERM on eth2
apps-net0-12.test.com (172.16.171.12) at cc:aa:aa:aa:aa:bb [ether] PERM on eth2
apps-net0-1.test.com (172.16.171.2) at 00:50:56:f7:9d:e2 [ether] on eth0

Let’s look at a MAAPI example how we can get part of the list using the ip key, the ifname key, or both keys. We use the confd_load tool that comes with ConfD to run our MAAPI commands:

$ confd_load -d -d -F p -o -P '/arpentries/arpe[ip="172.16.171.2"]/hwaddr' 
TRACE Connected (maapi) to ConfD
starting user session ctxt=system user=system groups=[system]
TRACE MAAPI_START_USER_SESSION  --> CONFD_OK
TRACE MAAPI_START_TRANS  --> CONFD_OK
TRACE MAAPI_SAVE_CONFIG  --> CONFD_OK
TRACE Connected (stream) to ConfD
<config xmlns="http://tail-f.com/ns/config/1.0">
  <arpentries xmlns="http://tail-f.com/ns/example/arpe">
  <arpe>
    <ip>172.16.171.2</ip>
    <ifname>eth0</ifname>
      <hwaddr>00:50:56:f7:9d:e2</hwaddr>
  </arpe>
  <arpe>
    <ip>172.16.171.2</ip>
    <ifname>eth1</ifname>
      <hwaddr>00:50:56:f7:9d:e2</hwaddr>
  </arpe>
  </arpentries>
TRACE MAAPI_SAVE_CONFIG_RESULT  --> CONFD_OK
</config>
TRACE MAAPI_END_USER_SESSION  --> CONFD_OK

$ confd_load -d -d -F p -o -P '/arpentries/arpe[ifname="eth2"]/hwaddr'TRACE Connected (maapi) to ConfD
starting user session ctxt=system user=system groups=[system]
TRACE MAAPI_START_USER_SESSION  --> CONFD_OK
TRACE MAAPI_START_TRANS  --> CONFD_OK
TRACE MAAPI_SAVE_CONFIG  --> CONFD_OK
TRACE Connected (stream) to ConfD
<config xmlns="http://tail-f.com/ns/config/1.0">
  <arpentries xmlns="http://tail-f.com/ns/example/arpe">
  <arpe>
    <ip>172.16.171.11</ip>
    <ifname>eth2</ifname>
      <hwaddr>aa:aa:aa:aa:aa:bb</hwaddr>
  </arpe>
  <arpe>
    <ip>172.16.171.12</ip>
    <ifname>eth2</ifname>
      <hwaddr>cc:aa:aa:aa:aa:bb</hwaddr>
  </arpe>
  </arpentries>
TRACE MAAPI_SAVE_CONFIG_RESULT  --> CONFD_OK
</config>
TRACE MAAPI_END_USER_SESSION  --> CONFD_OK

$ confd_load -d -d -F p -o -P '/arpentries/arpe[ip="172.16.171.11"][ifname="eth2"]/hwaddr'
TRACE Connected (maapi) to ConfD
starting user session ctxt=system user=system groups=[system]
TRACE MAAPI_START_USER_SESSION  --> CONFD_OK
TRACE MAAPI_START_TRANS  --> CONFD_OK
TRACE MAAPI_SAVE_CONFIG  --> CONFD_OK
TRACE Connected (stream) to ConfD
<config xmlns="http://tail-f.com/ns/config/1.0">
  <arpentries xmlns="http://tail-f.com/ns/example/arpe">
  <arpe>
    <ip>172.16.171.11</ip>
    <ifname>eth2</ifname>
      <hwaddr>aa:aa:aa:aa:aa:bb</hwaddr>
  </arpe>
  </arpentries>
TRACE MAAPI_SAVE_CONFIG_RESULT  --> CONFD_OK
</config>
TRACE MAAPI_END_USER_SESSION  --> CONFD_OK

Here’s a NETCONF example were we get the same parts of the list over NETCONF this time again using the ip key, the ifname key, or both keys:

$ netconf-console -i

* Enter a NETCONF operation, end with an empty line
  <get>
    <filter xmlns="http://tail-f.com/ns/example/arpe">
      <arpentries>
	<arpe>
          <ip>172.16.171.2</ip>
        </arpe>
      </arpentries>
    </filter>
  </get>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
  <data>
    <arpentries xmlns="http://tail-f.com/ns/example/arpe">
      <arpe>
        <ip>172.16.171.2</ip>
        <ifname>eth0</ifname>
        <hwaddr>00:50:56:f7:9d:e2</hwaddr>
        <permanent>false</permanent>
        <published>false</published>
      </arpe>
      <arpe>
        <ip>172.16.171.2</ip>
        <ifname>eth1</ifname>
        <hwaddr>00:50:56:f7:9d:e2</hwaddr>
        <permanent>false</permanent>
        <published>false</published>
      </arpe>
    </arpentries>
  </data>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line
  <get>
    <filter xmlns="http://tail-f.com/ns/example/arpe">
      <arpentries>
	<arpe>
          <ifname>eth2</ifname>
        </arpe>
      </arpentries>
    </filter>
  </get>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
  <data>
    <arpentries xmlns="http://tail-f.com/ns/example/arpe">
      <arpe>
        <ip>172.16.171.11</ip>
        <ifname>eth2</ifname>
        <hwaddr>aa:aa:aa:aa:aa:bb</hwaddr>
        <permanent>true</permanent>
        <published>false</published>
      </arpe>
      <arpe>
        <ip>172.16.171.12</ip>
        <ifname>eth2</ifname>
        <hwaddr>cc:aa:aa:aa:aa:bb</hwaddr>
        <permanent>true</permanent>
        <published>false</published>
      </arpe>
    </arpentries>
  </data>
</rpc-reply>

* Enter a NETCONF operation, end with an empty line
  <get>
    <filter xmlns="http://tail-f.com/ns/example/arpe">
      <arpentries>
	<arpe>
          <ip>172.16.171.11</ip>
          <ifname>eth2</ifname>
        </arpe>
      </arpentries>
    </filter>
  </get>

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">
  <data>
    <arpentries xmlns="http://tail-f.com/ns/example/arpe">
      <arpe>
        <ip>172.16.171.11</ip>
        <ifname>eth2</ifname>
        <hwaddr>aa:aa:aa:aa:aa:bb</hwaddr>
        <permanent>true</permanent>
        <published>false</published>
      </arpe>
    </arpentries>
  </data>
</rpc-reply>

Thank you so much cohult.

One more clarification regarding the previous post i want to achieve the same results through DP API instead of using confd_load tool.For that what i need to do ? i mean any changes required on the callbacks?

Regards,
Aarur

The source code for the confd_load and confd_cmd tools come with the ConfD release in $CONFD_DIR/src/confd/tools

From the confd_lib_maapi man pages:

int maapi_get_elem(int sock, int thandle, confd_value_t *v, const char *fmt, …);
This reads a value from the path in fmt and writes the result into the result parameter confd_value_t.

If you for example call maapi_get_elem(), here we use the maapi_cmd tool, and set the path to “/arpentries/arpe{172.16.171.2 eth0}/hwaddr” :

$ confd_cmd -d -d -c 'mget "/arpentries/arpe{172.16.171.2 eth0}/hwaddr"'
mget "/arpentries/arpe{172.16.171.2 eth0}/hwaddr"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_LOAD_ALL_NS
TRACE MAAPI_LOAD_HASH_DB
CMD_MAAPI is true [mtid = 0]
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION  --> CONFD_OK
TRACE MAAPI_START_TRANS  --> CONFD_OK
TRACE MAAPI_GET_ELEM /arpentries/arpe{172.16.171.2 eth0}/hwaddr --> CONFD_OK
00:50:56:f7:9d:e2
TRACE MAAPI_APPLY_TRANS  --> CONFD_OK
TRACE MAAPI_STOP_TRANS  --> CONFD_OK
TRACE MAAPI_END_USER_SESSION  --> CONFD_OK

Since your operational data in the 5-c_stats example is not located in the CDB operational datastore, i.e. it is fetched through a callback from the arpstat.c example application (see tailf:callpoint the YANG module), you cannot use the CDB/DP API to get the data which is not in CDB. You need to use MAAPI to trigger the application callback/callpoint.

For an example where the data is stored in the CDB operational datastore, see $CONFD_DIR/examples.confd/cdb_oper/ifstatus.
Here you can use the CDB/DP API to get the operational data from the CDB operational datastore. E.g.

$ pwd
/home/tailf/tailf/confd-6.0/examples.confd/cdb_oper/ifstatus
$ make start
...
$ confd_cmd -d -d -o -c 'get "/interfaces/interface{lo}/status/receive/bytes"'
get "/interfaces/interface{lo}/status/receive/bytes"
TRACE Connected (maapi) to ConfD
TRACE MAAPI_LOAD_ALL_NS
TRACE MAAPI_LOAD_HASH_DB
TRACE Connected (cdb) to ConfD
TRACE CDB_NEW_SESSION  --> CONFD_OK
TRACE Established new CDB session to ConfD
TRACE CDB_GET /interfaces/interface{lo}/status/receive/bytes --> CONFD_OK
103958329