来到最后的功能实现的步骤,功能实现其实很简单,添加一个yang文件,编译,添加接口实现代码,编译,ok,搞定收工。
yang文件编写
yang文件简单理解为是定义接口和传入参数的文件,在hello world项目中定了一个接口叫hello-world,需要传入的参数是:input标签中的name变量,类型为string,输出的信息为outpu标签中定义的greeting变量,类型也是string。
module example { yang–version 1; namespace "urn:opendaylight:params:xml:ns:yang:example"; prefix "example"; revision "2015-01-05" { description "Initial revision of example model"; } rpc hello–world { input { leaf name { type string; } } output { leaf greeting { type string; } } } }
定义好yang文件之后编译,odl的框架会自动生成很多代码,包括rpc中函数的定义,文件的引用等。
mvn clean install –DskipTests –Dmaven.javadoc.skip=true –Dcheckstyle.skip=true
[INFO] [INFO] — maven–site–plugin:3.6:attach–descriptor (generate–site) @ example–aggregator — [INFO] Attaching 'src/site/site.xml' site descriptor with classifier 'site'. [INFO] ———————————————————————— [INFO] Reactor Summary: [INFO] [INFO] ODL :: org.opendaylight.example :: example–api ….. SUCCESS [ 30.916 s] [INFO] ODL :: org.opendaylight.example :: example–impl …. SUCCESS [ 4.513 s] [INFO] ODL :: org.opendaylight.example :: example–cli ….. SUCCESS [ 4.574 s] [INFO] ODL :: org.opendaylight.example :: example–features SUCCESS [ 20.799 s] [INFO] ODL :: org.opendaylight.example :: example–karaf … SUCCESS [01:16 min] [INFO] ODL :: org.opendaylight.example :: example–artifacts SUCCESS [ 5.072 s] [INFO] ODL :: org.opendaylight.example :: example–it …… SUCCESS [ 7.690 s] [INFO] example …………………………………….. SUCCESS [ 14.771 s] [INFO] ———————————————————————— [INFO] BUILD SUCCESS [INFO] ———————————————————————— [INFO] Total time