在OpenDaylight controller上开发App
安装环境:Ubuntu18.04
一、安装依赖
1. 安装JDK:
sudo apt update
sudo apt install openjdk-8-jdk-headless
选择默认的 JDK:
~$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode Press <enter> to keep the current choice[*], or type selection number: 2
~$ java -version
设置 JAVA_HOME:
echo JAVA_HOME=export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 >> ~/.bashrc
source ~/.bashrc
2. 安装 maven:
sudo apt install maven
mvn -v
3. 安装 Sublime-Text3:(可选)
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
sudo apt-get update
sudo apt-get install sublime-text
二、搭建 ODL 代码框架
1. 获取配置 mvn 的 setting.xml:
~$ mkdir .m2
~$ wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
如果无法下载,则可以拷贝以下内容:


<?xml version="1.0" encoding="UTF-8"?>
<!-- vi: set et smarttab sw=2 tabstop=2: -->
<!--
Copyright (c) 2014, 2015 Cisco Systems, 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
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <profiles>
<profile>
<id>opendaylight-release</id>
<repositories>
<repository>
<id>opendaylight-mirror</id>
<name>opendaylight-mirror</name>
<url>https://nexus.opendaylight.org/content/repositories/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>opendaylight-mirror</id>
<name>opendaylight-mirror</name>
<url>https://nexus.opendaylight.org/content/repositories/public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile> <profile>
<id>opendaylight-snapshots</id>
<repositories>
<repository>
<id>opendaylight-snapshot</id>
<name>opendaylight-snapshot</name>
<url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>opendaylight-snapshot</id>
<name>opendaylight-snapshot</name>
<url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles> <activeProfiles>
<activeProfile>opendaylight-release</activeProfile>
<activeProfile>opendaylight-snapshots</activeProfile>
</activeProfiles>
</settings>
2. 生成 odl 代码框架:
~$ mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeVersion=1.3.0-Carbon
Define value for property 'groupId': org.opendaylight.hello
Define value for property 'artifactId': hello
[INFO] Using property: version = 0.1.0-SNAPSHOT
Define value for property 'package' org.opendaylight.hello: :
Define value for property 'classPrefix' Hello: :
Define value for property 'copyright': ming
[INFO] Using property: copyrightYear = 2017
Confirm properties configuration:
groupId: org.opendaylight.hello
artifactId: hello
version: 0.1.0-SNAPSHOT
package: org.opendaylight.hello
classPrefix: Hello
copyright: ming
copyrightYear: 2017
Y: : y
3. 编译:
~$ cd hello/
~/hello$ mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
4. 启动 odl 控制器:
~/hello$ export TERM=xterm-color
~/hello$ cd karaf/target/assembly/bin
~/hello/karaf/target/assembly/bin$ ./karaf
opendaylight-user@root> feature:list | grep hello
5. Web 界面登录:
访问:http://127.0.0.1:8181/index.html 用户名密码都是 admin
。
三、RPC 实现
1. 编写、编译 yang 文件:
文件:~/hello/api/src/main/yang/hello.yang
module hello {
yang-version 1;
namespace "urn:opendaylight:params:xml:ns:yang:hello";
prefix "hello";
revision "2015-01-05" {
description "Initial revision of hello model";
}
rpc hello-world {
input {
leaf name {
type string;
}
}
output {
leaf greeting {
type string;
}
}
}
}
编译:(生成 RPC 定义等内容)
~/hello/api$ mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
2. 编写 impl-blueprint.xml文件:
注册 RPC。
文件:~/hello/impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- vi: set et smarttab sw=4 tabstop=4: -->
<!--
Copyright 2017 ming 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"> <reference id="dataBroker"
interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
odl:type="default" /> <bean id="provider"
class="org.opendaylight.hello.impl.HelloProvider"
init-method="init" destroy-method="close">
<argument ref="dataBroker" />
</bean> <odl:rpc-implementation ref="provider"/> </blueprint>
3. 实现 RPC 处理函数:
文件:~/hello/impl/src/main/java/org/opendaylight/hello/impl/HelloProvider.java
package org.opendaylight.hello.impl; import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloWorldInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloWorldOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.hello.rev150105.HelloWorldOutputBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import java.util.concurrent.Future; public class HelloProvider implements HelloService { private static final Logger LOG = LoggerFactory.getLogger(HelloProvider.class); private final DataBroker dataBroker; public HelloProvider(final DataBroker dataBroker) {
this.dataBroker = dataBroker;
} @Override
public Future<RpcResult<HelloWorldOutput>> helloWorld(HelloWorldInput input) {
HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
helloBuilder.setGreeting("Hello " + input.getName());
return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
} /**
* Method called when the blueprint container is created.
*/
public void init() {
LOG.info("HelloProvider Session Initiated");
} /**
* Method called when the blueprint container is destroyed.
*/
public void close() {
LOG.info("HelloProvider Closed");
}
}
~/hello$ mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
4. 启动 odl:
~/hello/karaf/target/assembly/bin$ ./karaf
5. 查看、测试 API:
打开:http://localhost:8181/apidoc/explorer/index.html
点击:hello(2015-01-05) -> post /operations/hello:hello-world
在参数部分输入:
{
"input": {
"name": "SDN"
}
}
点击:Try it out!
参考资料:
https://www.cnblogs.com/goldsunshine/p/11175698.html
https://www.cnblogs.com/leoych/p/13570303.html
https://docs.opendaylight.org/en/stable-aluminium/developer-guide/developing-apps-on-the-opendaylight-controller.html
https://www.cnblogs.com/goldsunshine/p/11176164.html
https://www.cnblogs.com/goldsunshine/p/11298951.html
在OpenDaylight controller上开发App的更多相关文章
- Smobiler 4.4 更新预告 Part 2(Smobiler能让你在Visual Studio上开发APP)
Hello Everybody,在Smobiler 4.4中,也为大家带来了新增功能和插件(重点,敲黑板). 新增功能: 1, 企业认证用户可设置路由(即客户端可根据不同的IP地址访问不同的服务器组) ...
- Smobiler 4.4 更新预告 Part 1(Smobiler能让你在Visual Studio上开发APP)
在4.4版本中,大家对产品优化的一些建议和意见进行了相应的优化和修复,同时,还新增了一些令人激动的功能和插件. 下面先为大家介绍4.4版本中Smobiler的优化和修复: 优化 1, PageView ...
- Smobiler 4.4已正式发布!(Smobiler能让你在Visual Studio上开发APP)
Smobiler 4.4已经正式发布,还不快来看看?原文地址:https://www.smobiler.com/portal.php?mod=view&aid=53这次更新要感谢我们的用户,在 ...
- mui开发app之cropper裁剪后上传头像的实现
在大多数app项目中,都需要对用户头像的上传,之前做web开发的时候,我主要是通过input type=file的标签实现的,上传后,使用php对图片进行裁剪,这种方式比较传统简单. 此次app开发中 ...
- HTML5 开发APP(打开相册以及图片上传)
我们开发app,常常会遇到让用户上传文件的功能.比如让用户上传头像.我公司的业务要求是让用户上传支付宝收款二维码,来实现用户提现的功能.想要调用相册要靠HTML Plus来实现.先上效果图 基本功能是 ...
- Hbuilder开发app实战-识岁03-文件上传
前言 做app不得不谈的问题就是文件上传.用hbuilder开发app让上传变的非常easy. Uploader Uploader模块管理网络上传任务,用于从本地上传各种文件到server,并支持跨域 ...
- IOS开发 APP提交程序上传流程
由于苹果的机制,在非越狱机器上安装应用必须通过官方的App Store,开发者开发好应用后上传App Store,也需要通过审核等环节.AppCan作为一个跨主流平台的一个开发平台,也对ipa包上传A ...
- qt-qml移动开发之在ios上开发和部署app流程简单介绍
qt5.3已经全面支持移动开发,除了mac,windows,linux.还支持ios,android,wp,meego等移动平台,本教程是作者依据自己的经验,从头讲怎么样在ios上公布自己的app.因 ...
- APP开发中,如何从UI设计上提升APP用户体验
设计中有很多细微的东西要注意,就如UI设计中,元素的统一性,图标风格.段落的排版等等,只有能注意这些细节,你的 APP UI 才算合格. 干货君总结了17个提升用户体验的 UI 设计小技巧,也是我们日 ...
随机推荐
- sqoop用法之mysql与hive数据导入导出
目录 一. Sqoop介绍 二. Mysql 数据导入到 Hive 三. Hive数据导入到Mysql 四. mysql数据增量导入hive 1. 基于递增列Append导入 1). 创建hive表 ...
- PSO 粒子群算法
注:本人参考http://www.cnblogs.com/tiandsp/category/348031.html来实现的 算法步骤: 1.首先确定粒子个数与迭代次数. 2.对每个粒子随机初始化位置与 ...
- Android 开源框架 -Toasty
GitHub地址 用法: 第一步:根目录的 build.gradle: allprojects { repositories { ... maven { url "https://jitpa ...
- Unity UI适配 之 GridLayoutGroup组件下的内容适配(进度条适配)
好久没有更新博客了,蓝廋啊. 今天写一写关于GripLayoutGroup组件的屏幕适配问题,以在ARPG游戏中常用的经验条适配来举例子,以此来加深自己的记忆,以便在下次需要制作该功能时能够快速完成. ...
- 使用IDE练习插件【廖雪峰】
使用廖雪峰大神的插件,安装过程中,一直出现问题,然后在他的Java教程下面看大家的评论也有点晕了(很多人说的是jar包,结果其实是下的依旧是zip包) 最终解决方法: 将zip包解压到同名文件夹中,再 ...
- (十五)、linux软件的安装与查询-rpm与yum命令
一.RPM软件管理程序:rpm 1.RPM安装软件(install) rpm命令的选项超级多,安装话直接使用-ivh即可,其余做了解即可 命令格式:rpm -ivh package_name.rp ...
- idea 【Maven Projects # Profiles】问题记录
今天启动接一个新项目,然后项目启动后发现启动的环境和预想的不一致,查看 pom 文件确认自己是 dev 无误之后,但是启动的就是 test 环境. 问题 发现了启动环境不对不对之后,自己试了一种解决办 ...
- Sublime Text 2 强大的编辑功能
多行编辑功能:1) 同时编辑多行 (Ctrl+Shift+L (Win) 或 Command+Shift+L (Mac))如要在选中的多行文本的最后面同时添加一个字符"a",先选 ...
- jQuery 库中的 $() 是什么?
概述: $() 函数是 jQuery() 函数的别称. $() 函数用于将任何对象包裹成 jQuery 对象,接着就被允许调用定义在 jQuery 对象上的多个不同方法. 可以将一个选择器字符串传入 ...
- 相对于Statement,PreparedStatement的优点是什么?
优点: 1.PreparedStatement有助于防止SQL注入,因为它会自动对特殊字符转义. 2.PreparedStatement可以用来进行动态查询. 3.PreparedStatement执 ...