记录一下如何创建一个NSO service,只是用来测试使用,无参考意义。
Step 1: Generate a service packet in runtime package directory. #
#cd ncs-run/packages
#ncs-make-package --service-skeleton template <l3vpn>
Step 2: Modify the template file: #
使用NSO dry-run 一个配置,并format xml格式.修改template 文件如下:
[root@localhost templates]# pwd
/root/ncs-run/packages/l3vpn/templates
[root@localhost templates]# ls
l3vpn-template.xml
[root@localhost templates]# cat l3vpn-template.xml
<config-template xmlns="http://tail-f.com/ns/config/1.0"
servicepoint="l3vpn">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>{/device}</name>
<config>
<bgp xmlns="http://tail-f.com/ned/huawei-vrp">
<name>{/bgpas}</name>
<ipv4-family>
<vpn-instance>
<name>{/vpnname}</name>
<maximum>
<load-balancing>{/load}</load-balancing>
</maximum>
<peer>
<ip>{/peerip}</ip>
<as-number>{/asnum}</as-number>
<timer>
<keepalive-hold>
<keepalive>{/keeptime}</keepalive>
<hold>{/holdtime}</hold>
</keepalive-hold>
</timer>
<route-limit>
<route-limit>{/limit}</route-limit>
<percentage>{/percent}</percentage>
<idle-timeout>{/idletime}</idle-timeout>
</route-limit>
<advertise-community/>
</peer>
</vpn-instance>
</ipv4-family>
</bgp>
</config>
</device>
</devices>
</config-template>
[root@localhost templates]#
Step 3: Edit YANG service model in PACKAGE-NAME/src/yang #
简单做测试使用,所以把变量的类型都定义为string了。
[root@localhost yang]# cat l3vpn.yang
module l3vpn {
namespace "http://com/example/l3vpn";
prefix l3vpn;
import ietf-inet-types {
prefix inet;
}
import tailf-ncs {
prefix ncs;
}
import tailf-common {
prefix tailf;
}
list l3vpn {
key name;
uses ncs:service-data;
ncs:servicepoint "l3vpn";
leaf name {
type string;
}
// may replace this with other ways of refering to the devices.
// replace with your own stuff here
leaf device {
mandatory true;
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
}
leaf bgpas {
type string;
}
leaf vpnname {
type string;
}
leaf load {
type string;
}
leaf peerip {
type string;
}
leaf asnum {
type string;
}
leaf keeptime {
type string;
}
leaf holdtime {
type string;
}
leaf limit {
type string;
}
leaf percent {
type string;
}
leaf idletime {
type string;
}
}
}
[root@localhost yang]#
Step 4:Build the service mode/Reload #
$ cd PACKAGE-NAME/src
$ make
//reload
admin@ncs# packages reload