OpenDaylight开发实例toaster实验过程记录(2)
2016-04-13 16:58
666 查看
【OpenDaylight开发实例toaster实验过程记录】这一部分博客主要记录我做官网wiki(https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Toaster_Step-By-Step)开发实例toaster的实验过程。
(并不是完全按照官网内容)
Part 1: Defining an Operational Toaster
定义烤面包机数据模型
toaster.yang文件位于toaster/api/src/main/yang/目录下。该文件定义了toaster的北向抽象数据模型,提别是toaster的属性,RPCs和通知,可以通过北向客户端来访问(如restconf api)。toaster.yang内容及注释如下:
给toaster容器设置了3个叶子(leaf)属性,并且用变量config=false/true将其表示为可操作(operational)属性, 而不是配置数据(configuration data)。
修改pom.xml,目录为(toaster/api/)
返回目录toaster/
编译:
( 补充:在toaster/api目录下也是可以编译成功的 mvn clean install )。
官网上说会在目录src/main/yang-gen-sal/中生成类,但是本实验中是在下面目录中生成:
这些文件是通过yangtools将toaster.yang中的model生成对应的代码:
重要的类:
1. Toaster : 一个接口,表示toaster容器获得叶子节点数据的方法
2. ToasterData:一个接口表示顶层的toaster模块,包含一个方法getToaster() 返回单个 toaster实例。
3. WheatBread,WhiteBread: 代表不同toast类型的抽象类。
4. YangModelBindingProvider,YangModelBindingProvider,YangModuleInfolmpl: 被MD-SAL在内部使用来写toaster模块,more on this later。
补充:如果想在toaster/src/main/yang-gen-sal中生成上述类文件,可以修改两个部分
(1)toaster/pom.xml
增加:
(2)toaster/api/pom.xml
增加:
(并不是完全按照官网内容)
Part 1: Defining an Operational Toaster
定义烤面包机数据模型
toaster.yang文件位于toaster/api/src/main/yang/目录下。该文件定义了toaster的北向抽象数据模型,提别是toaster的属性,RPCs和通知,可以通过北向客户端来访问(如restconf api)。toaster.yang内容及注释如下:
//This file contains a YANG data definition. This data model defines //a toaster, which is based on the SNMP MIB Toaster example module toaster { //The yang version - today only 1 version exists. If omitted defaults to 1. //版本 yang-version 1; //a unique namespace for this toaster module, to uniquely identify it from other modules that may have the same name. //名字空间 namespace "http://netconfcentral.org/ns/toaster"; //a shorter prefix that represents the namespace for references used below //前缀 prefix toast; //Defines the organization which defined / owns this .yang file. //定义该.yang文件的组织 organization "Netconf Central"; //defines the primary contact of this yang file. //联系方式 contact "Andy Bierman <andy@netconfcentral.org>"; //provides a description of this .yang file. //对该yang文件的描述 description "YANG version of the TOASTER-MIB."; //defines the dates of revisions for this yang file //修订本 revision "2009-11-20" { description "Toaster module in progress."; } //declares a base identity, in this case a base type for different types of toast. //类型 toast-type, 所有面包的基本类型 //个人认为可以把identity理解为java中的class identity toast-type { description "Base for all bread types supported by the toaster. New bread types not listed here nay be added in the future."; } //the below identity section is used to define globally unique identities //Note - removed a number of different types of bread to shorten the text length. //类型 white-bread 白面包, 继承toast-type identity white-bread { base toast:toast-type; //logically extending the declared toast-type above. description "White bread."; //free text description of this type. } //类型 wheat-bread identity wheat-bread { base toast-type; description "Wheat bread."; } //defines a new "Type" string type which limits the length typedef DisplayString { type string { length "0 .. 255"; } description "YANG version of the SMIv2 DisplayString TEXTUAL-CONVENTION."; reference "RFC 2579, section 2."; } // This definition is the top-level configuration "item" that defines a toaster. The "presence" flag connotes there // can only be one instance of a toaster which, if present, indicates the service is available. //容器 toaster container toaster { presence "Indicates the toaster service is available"; description "Top-level container for all toaster database objects."; //Note in these three attributes that config = false. This indicates that they are operational //attributes. 将config=false,表示可操作属性 //leaf 用来描述属性(attributes) //leaf 面包机制造商 leaf toasterManufacturer { type DisplayString; config false; mandatory true; description "The name of the toaster's manufacturer. For instance, Microsoft Toaster."; } //leaf 面包机型号 leaf toasterModelNumber { type DisplayString; config false; mandatory true; description "The name of the toaster's model. For instance, Radiant Automatic."; } //leaf 面包机状态,up表示没有在工作,down表示正在烤面包 leaf toasterStatus { type enumeration { enum "up" { value 1; description "The toaster knob position is up. No toast is being made now."; } enum "down" { value 2; description "The toaster knob position is down. Toast is being made now."; } } config false; mandatory true; description "This variable indicates the current state of the toaster."; } } // container toaster } // module toaster
给toaster容器设置了3个叶子(leaf)属性,并且用变量config=false/true将其表示为可操作(operational)属性, 而不是配置数据(configuration data)。
修改pom.xml,目录为(toaster/api/)
<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright © 2015 Copyright(c) Yoyodyne, Inc. and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.opendaylight.mdsal</groupId> <artifactId>binding-parent</artifactId> <version>0.8.2-SNAPSHOT</version> <relativePath/> </parent> <modelVersion>4.0.0</modelVersion> <groupId>org.opendaylight.toaster</groupId> <artifactId>toaster-api</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>bundle</packaging> <build> <plugins> <plugin> <groupId>org.opendaylight.yangtools</groupId> <artifactId>yang-maven-plugin</artifactId> <version>0.7.5-SNAPSHOT</version> <executions> <execution> <goals> <goal>generate-sources</goal> </goals> <configuration> <yangFilesRootDir>src/main/yang</yangFilesRootDir> <codeGenerators> <generator> <codeGeneratorClass>org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl</codeGeneratorClass> <outputBaseDir>${salGeneratorPath}</outputBaseDir> </generator> </codeGenerators> <inspectDependencies>true</inspectDependencies> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.opendaylight.yangtools</groupId> <artifactId>maven-sal-api-gen-plugin</artifactId> <version>0.7.5-SNAPSHOT</version> <type>jar</type> </dependency> </dependencies> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.opendaylight.yangtools</groupId> <artifactId>yang-binding</artifactId> <version>0.7.5-SNAPSHOT</version> </dependency> <dependency> <groupId>org.opendaylight.yangtools</groupId> <artifactId>yang-common</artifactId> <version>0.7.5-SNAPSHOT</version> </dependency> </dependencies> <scm> <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection> <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection> <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url> <tag>HEAD</tag> </scm> </project>
返回目录toaster/
编译:
mvn clean install
( 补充:在toaster/api目录下也是可以编译成功的 mvn clean install )。
官网上说会在目录src/main/yang-gen-sal/中生成类,但是本实验中是在下面目录中生成:
这些文件是通过yangtools将toaster.yang中的model生成对应的代码:
重要的类:
1. Toaster : 一个接口,表示toaster容器获得叶子节点数据的方法
2. ToasterData:一个接口表示顶层的toaster模块,包含一个方法getToaster() 返回单个 toaster实例。
3. WheatBread,WhiteBread: 代表不同toast类型的抽象类。
4. YangModelBindingProvider,YangModelBindingProvider,YangModuleInfolmpl: 被MD-SAL在内部使用来写toaster模块,more on this later。
补充:如果想在toaster/src/main/yang-gen-sal中生成上述类文件,可以修改两个部分
(1)toaster/pom.xml
增加:
<properties> <mdsal.model.version>0.8.1-SNAPSHOT</mdsal.model.version> <mdsal.version>1.3.1-SNAPSHOT</mdsal.version> <restconf.version>1.3.1-SNAPSHOT</restconf.version> <yangtools.version>0.7.5-SNAPSHOT</yangtools.version> <dlux.version>0.3.1-SNAPSHOT</dlux.version> <configfile.directory>etc/opendaylight/karaf</configfile.directory> <salGeneratorPath>./src/main/yang-gen-sal</salGeneratorPath> </properties>
(2)toaster/api/pom.xml
增加:
<properties> <salGeneratorPath>../src/main/yang-gen-sal</salGeneratorPath> </properties>
相关文章推荐
- commons-cli使用介绍
- 关于tomcat优化记录与思路
- linux hadoop安装
- LINUX命令汇总,太常用了
- maven project 部署到tomcat时项目部署不上去
- shell各类脚本
- 集群监控
- 学习OpenGL(五)绘制多边形
- Servlet和Tomcat部署
- 开机小脚本自动打开sublime text 和git-bash
- CentOS 7 的 firewalld防火墙(转载)
- linux 基础
- openwrt14.07 howto generate /etc/config/network
- 【浅层优化实战】ssh远程登录Linux卡慢的全过程排查及解决方案
- Linux基础3(用户/组管理,rpm,yum,源码安装软件)
- 在CentOS7.2安装Jdk1.8和resin4.0.45的步骤及shell脚本
- 《Linux内核设计与实现》读书笔记六
- 御载 centos 7 openJDK
- Android架构文章合集(a collection of android Architecture)
- 初探hadoop+hbase+sqoop+hive