Tail-f ConfD框架 - 图1

Reference

  • confd user guide-4.3.4.pdf

    What is ConfD

    ConfD是一个开发好的工具包,是cisco tail-f公司开发的,不是node产品代码里的。ConfD在目标设备上作为一个普通的Unix守护进程,主要有如下功能:

  • 作为NETCONF协议的NETCONF代理

  • 作为Web UI的Web服务器
  • 作为命令行访问的CLI引擎
  • 作为SNMP代理
  • 包含一个内置的XML配置数据库

    ConfD Architecture

    Tail-f ConfD框架 - 图2

    YANG in ConfD

    在confD中,YANG模型是作为所有接口的数据模型,不只是应用于NetConf。YANG模型会被转换成.fxs文件(不是xml)加载到confD中。fxs文件编译命令为:
    # 生成fxs文件
    confdc -c example.yang
    # 根据fxs文件生成头文件, 用于编写callback
    confdc —emit-h example.h example.fxs
    confd提供了两大类型,包含一些有用的数据类型,可以import到自己的YANG文件中使用

  • ietf-yang-types: defining some basic data types such as counters, dates and times.

  • ietf-inet-types :defining several useful types related to IP addresses.


    Example:
    module test {
    namespace “http://tail-f.com/test“;
    prefix “t”;
    import ietf-inet-types {//引用confd类型
    prefix inet;
    }

    container top {
    leaf a {
    type int32;
    }
    leaf b {
    type string;
    }
    leaf ip {
    type inet:ipv4-address;
    }
    }
    }

    callpoint with callback

    add callpoint

    在confd的YANGM模型定义文件中, 可以通过tailf-common:callpoint语句定义一个callpoint,然后注册相应的回调函数实现。这样就可以在confd外部实现参数的配置和value获取等操作
    import ietf-inet-types {
    prefix inet;
    }
    import tailf-common {
    prefix tailf;
    }
    container arpentries {
    config false;
    tailf:callpoint arpe; //定义callpoint
    list arpe {
    key “ip ifname”;
    max-elements 1024;
    leaf ip {
    type inet:ip-address;
    }
    }
    }

    register callback

    每一个callpoint都需要实现下面的函数用于操作数据配置和读取,然后注册到confd中:

  • confd_data_cbs: 数据操作的回调函数集合

    • get_next()
    • get_elem()
    • exists_optional()
    • get_object()
    • num_instances()
    • get_next_object()
    • find_next()
    • find_next_object()
  • confd_trans_cbs:事务唤醒和结束的回调函数
    • init()
    • finish()

回调函数使用如下方式注册到confd:
struct confd_trans_cbs trans;
memset(&trans, 0, sizeof (struct confd_trans_cbs));
trans.init = s_init;
trans.finish = s_finish;

struct confd_data_cbs data;
memset(&data, 0, sizeof (struct confd_data_cbs));
data.get_elem = get_elem;
data.get_next = get_next;
strcpy(data.callpoint, arpe__callpointid_arpe);//指定callpoint名

//省略连接yang模型进程的步骤,进程context为下面的dctx

if (confd_register_trans_cb(dctx, &trans) == CONFD_ERR)
confd_fatal(“Failed to register trans cb \n”);
if (confd_register_data_cb(dctx, &data) == CONFD_ERR)
confd_fatal(“Failed to register data cb \n”);
if (confd_register_done(dctx) != CONFD_OK)
confd_fatal(“Failed to complete registration \n”);

call callpoint function diagram

Tail-f ConfD框架 - 图3

action with callback

当不需要对配置数据进行配置和读取,只需要进行对YANG模型进行操作时,可以定义tailf:action并注册回调函数实现操作.

add action

list server {
key name;
max-elements 64;
leaf name {
type string;
}
//定义一个action
tailf:action reset {
tailf:actionpoint reboot-point;//action name,注册时需要用到
input { //输入参数
leaf when {
type string;
mandatory true;
}
}
output { //输出参数
leaf time {
type string;
mandatory true;
}
}
}
}

register callback

memset(&acb, 0, sizeof(acb));
strcpy(acb.actionpoint, “reboot-point”);
acb.init = init_action;
acb.action = do_action;
acb.abort = abort_action;

if (confd_register_action_cbs(dctx, &acb) != CONFD_OK)
fail(“Couldn’t register action callbacks”);