OpenDaylight开发hello-world项目之开发环境搭建

OpenDaylight开发hello-world项目之开发工具安装

OpenDaylight开发hello-world项目之代码框架搭建

OpenDaylight开发hello-world项目之功能实现

来到最后的功能实现的步骤,功能实现其实很简单,添加一个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: 02:53 min
[INFO] Finished at: 2019-09-12T17:02:48+08:00
[INFO] Final Memory: 209M/483M
[INFO] ------------------------------------------------------------------------

hello world 函数

编译顺利完成之后,首先将该RPC注册到系统当中去。编写impl-blueprint.xml文件,注册ExampleProvider。

<?xml version="1.0" encoding="UTF-8"?>
<!-- vi: set et smarttab sw=4 tabstop=4: -->
<!--
Copyright © 2017 worker 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
--> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
odl:use-default-for-reference-types="true"> <bean id="provider"
class="org.opendaylight.example.impl.ExampleProvider">
</bean> <odl:rpc-implementation ref="provider"/> </blueprint>

注册好函数之后,最后实现RPC的处理函数。获取input输入的内容,然后返回 ‘hello’ + input的内容。

package org.opendaylight.example.impl;

import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.example.rev150105.ExampleService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.example.rev150105.HelloWorldInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.example.rev150105.HelloWorldOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.example.rev150105.HelloWorldOutputBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import java.util.concurrent.Future; public class ExampleProvider implements ExampleService { @Override
public Future<RpcResult<HelloWorldOutput>> helloWorld(HelloWorldInput input) {
HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
helloBuilder.setGreeting("Hello " + input.getName());
return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
} }

编译文件

mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
[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 [ 35.665 s]
[INFO] ODL :: org.opendaylight.example :: example-impl .... SUCCESS [ 5.435 s]
[INFO] ODL :: org.opendaylight.example :: example-cli ..... SUCCESS [ 4.453 s]
[INFO] ODL :: org.opendaylight.example :: example-features SUCCESS [ 26.418 s]
[INFO] ODL :: org.opendaylight.example :: example-karaf ... SUCCESS [: min]
[INFO] ODL :: org.opendaylight.example :: example-artifacts SUCCESS [ 5.602 s]
[INFO] ODL :: org.opendaylight.example :: example-it ...... SUCCESS [ 18.424 s]
[INFO] example ............................................ SUCCESS [ 22.318 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: : min
[INFO] Finished at: --04T17::+:
[INFO] Final Memory: 207M/483M
[INFO] ------------------------------------------------------------------------

启动ODL

编译通过之后,在karaf文件夹下启动ODL,hello-world模块生效。

 查看ODL的api文档

当启动ODL之后,可以查看该ODL所有的api文档,在浏览器中输入 地址:http://localhost:8181/apidoc/explorer/index.html,从中能够找新鲜出炉的example模块。

测试接口

在这个api文档中,可以直接测试接口的可用性,按照输入的格式将内容输入,然后try it out!

使用Postman测试接口

postman是最常见的测试工具,输入restful api的地址,请求方法,body体,认证方式,然后send。

ODL hello-world模块的学习重点不是功能实现,而是ODL开发模块的过程和套路,其中很多深入的内容并没有介绍全面,主要的注意力还是放在流程上,如何安装环境,构建框架代码,编译,实现功能代码等。

OpenDaylight开发hello-world项目之功能实现的更多相关文章

  1. OpenDaylight开发hello-world项目之代码框架搭建

    OpenDaylight开发hello-world项目之开发环境搭建 OpenDaylight开发hello-world项目之开发工具安装 OpenDaylight开发hello-world项目之代码 ...

  2. OpenDaylight开发hello-world项目之开发环境搭建

    OpenDaylight开发hello-world项目之开发环境搭建 OpenDaylight开发hello-world项目之开发工具安装 OpenDaylight开发hello-world项目之代码 ...

  3. OpenDaylight开发hello-world项目之开发工具安装

    OpenDaylight开发hello-world项目之开发环境搭建 OpenDaylight开发hello-world项目之开发工具安装 OpenDaylight开发hello-world项目之代码 ...

  4. 基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  5. 基于.NetCore开发博客项目 StarBlog - (14) 实现主题切换功能

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  6. 基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)

    系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...

  7. MVC5 网站开发之三 数据存储层功能实现

    数据存储层在项目Ninesky.DataLibrary中实现,整个项目只有一个类Repository.   目录 奔跑吧,代码小哥! MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 ...

  8. ASP.NET MVC5 网站开发实践(一) - 项目框架

    前几天算是开题了,关于怎么做自己想了很多,但毕竟没做过项目既不知道这些想法有无必要,也不知道能不能实现,不过邓爷爷说过"摸着石头过河"吧.这段时间看了一些博主的文章收获很大,特别是 ...

  9. [ASP.NET MVC] 使用CLK.AspNet.Identity提供依权限显示选单项目的功能

    [ASP.NET MVC] 使用CLK.AspNet.Identity提供依权限显示选单项目的功能 CLK.AspNet.Identity CLK.AspNet.Identity是一个基于ASP.NE ...

随机推荐

  1. Redis 到底是怎么实现“附近的人”这个功能的呢?

    作者简介 万汨,饿了么资深开发工程师.iOS,Go,Java均有涉猎.目前主攻大数据开发.喜欢骑行.爬山. 前言:针对“附近的人”这一位置服务领域的应用场景,常见的可使用PG.MySQL和MongoD ...

  2. vmware vsphere client 虚拟机动态添加磁盘

    0x00 事件 为了在虚拟机添加了磁盘之后,不重启机器加载新磁盘. 如上图,添加了一块 10G 的磁盘之后. 在虚拟机中是看不到新添加的磁盘: 0x01 解决 运行如下命令,通过重新扫描 SCSI ( ...

  3. idea中git分支、合并与使用

    1.分支的新建与合并使用场景介绍 让我们来看一个简单的分支新建与分支合并的例子,实际工作中你可能会用到类似的工作流. 你将经历如下步骤: 开发某个网站. 为实现某个新的需求.问题(#53问题),创建一 ...

  4. 集合 set方法

    集合 number = {1, 2, 4} # 添加元素到集合 number.add(100) print(number) # 从集合中删除 number.remove(2) print(number ...

  5. django 做 migrate 时 表已存在的处理

    在开发web的时候,如果是以前已存在的项目,项目下载下来后,为了使用测试库的数据,会直接将整个测试库(如sqlite3)拿到本机来.这种情况下,如果执行的顺序不对,很容易在执行migrate的时候出现 ...

  6. asp.net实现SQL2005的通知数据缓存

    首先第一步是确保您的 Service Broker 已经激活,激活 Service Broker (Transact-SQL)如下: USE master ; GO ALTER DATABASE Yo ...

  7. 表单生成器(Form Builder)之伪造表单数据番外篇——随机车辆牌照

    前几天记录了一下表单生成器(Form Builder)之表单数据存储结构mongodb篇,之后便想着伪造一些数据.为什么要伪造数据呢?说来惭愧,因为拖拉拽设计表单以及表单对应的列表的PC端和移动端该显 ...

  8. September 08th, 2019. Sunday, Week 37th.

    A heavy drew refreshed the earth at night. 夜晚厚重的露水滋养着大地. From Leo Tolstoy. Today is the White Drew D ...

  9. 清除Windows系统图标缓存

    如果改变程序图标重新编译之后看到的图标并未改变,这可能不windows缓存了之前的图标导致的,需要清除Window的图标缓存来显示正确的图标. 下面是清除Windows系统图标缓存的批处理代码: re ...

  10. [洛谷P1122][题解]最大子树和

    这是一道还算简单的树型dp. 转移方程:f[i]=max(f[j],0) 其中i为任意非叶节点,j为i的一棵子树,而每棵子树都有选或不选两种选择 具体看代码: #include<bits/std ...