已获取onos源码 master分支
已安装maven并配置/etc/profile环境变量
maven 版本3.6.3
https://wiki.onosproject.org/display/ONOS/Template+Application+Tutorial
执行onos-create-app脚本,就在~/onos/tools/dev/bin
目录下生成框架
root@vpp3:~/onos/tools/dev/bin# ./onos-create-app
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.2.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.2.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype [org.onosproject:onos-bundle-archetype:2.7.0] found in catalog remote
[INFO] Using property: onosVersion = 2.7.0
Define value for property 'groupId': org。^H^H^Croot@vpp3:~/onos/tools/dev/bin# ./onos-create-app
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.2.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.2.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype [org.onosproject:onos-bundle-archetype:2.7.0] found in catalog remote
[INFO] Using property: onosVersion = 2.7.0
Define value for property 'groupId': org.onos.test
Define value for property 'artifactId': Demo
Define value for property 'version' 1.0-SNAPSHOT: : 1.10
Define value for property 'package' org.onos.test: : test
Confirm properties configuration:
onosVersion: 2.7.0
groupId: org.onos.test
artifactId: Demo
version: 1.10
package: test
Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: onos-bundle-archetype:2.7.0
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: org.onos.test
[INFO] Parameter: artifactId, Value: Demo
[INFO] Parameter: version, Value: 1.10
[INFO] Parameter: package, Value: test
[INFO] Parameter: packageInPathFormat, Value: test
[INFO] Parameter: package, Value: test
[INFO] Parameter: version, Value: 1.10
[INFO] Parameter: groupId, Value: org.onos.test
[INFO] Parameter: onosVersion, Value: 2.7.0
[INFO] Parameter: artifactId, Value: Demo
[INFO] Project created from Archetype in dir: /root/onos/tools/dev/bin/Demo
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:00 min
[INFO] Finished at: 2022-03-16T10:12:32+08:00
[INFO] ------------------------------------------------------------------------
注意参考
# groupId 定义了项目属于哪个组,组织.公司.项目,eg:com.mycom.myapp
Define value for property 'groupId': org.onos.test
# artifactId定义了当前maven项目在组中唯一的ID,项目文件夹名
Define value for property 'artifactId': Demo
# 版本号,一般直接回车(使用 1.0-SNAPSHOT)
Define value for property 'version' 1.0-SNAPSHOT: : 1.10
# package,目录结构src.main.java下一级包名,AppComponent.java所在包名
Define value for property 'package' org.onos.test: : test
onos源码不要切分支!只需要生成之后修改pom.xml文件中的onos版本
切到1.10下生成会报错
root@vpp3:~/onos/tools/dev/bin# ./onos-create-app
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom >-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.2.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.2.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.2.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository not defined. Using the one from [org.onosproject:onos-bundle-archetype:2.7.0] found in catalog remote
[WARNING] The POM for org.onosproject:onos-bundle-archetype:jar:1.10.13-SNAPSHOT is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:58 min
[INFO] Finished at: 2022-03-16T09:34:58+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate (default-cli) on project standalone-pom: The desired archetype does not exist (org.onosproject:onos-bundle-archetype:1.10.13-SNAPSHOT) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
进行activate 开发,pom文件中添加jar的依赖关系
先配置好maven,JDK版本记得调到8(否则报程序包javax.xml.bind.annotation不存在)
修改onos版本(原来是2.7)
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-dependencies</artifactId>
<version>1.10.0</version>
</parent>
添加onos.version
参考
<properties>
<onos.version>1.10.0</onos.version>
<onos.app.name>org.onos.test</onos.app.name>
<onos.app.origin>ON.Lab</onos.app.origin>
<onos.app.title>One-Test App</onos.app.title>
<onos.app.category>Monitoring</onos.app.category>
<onos.app.url>http://onosproject.org</onos.app.url>
<onos.app.requires>org.onosproject.fwd</onos.app.requires>
</properties>
编译,在编译执行的路径下的/target生成oar包。
mvn compile
Unknown packaging: bundle
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
mvn install
会把oar包放到m2仓库(没必要)安装Applications右上角的 + ,注意远程传的话可能需要传两次(网络问题)
卸载:垃圾桶
oar文件可以放任意路径(本次直接放在/opt/onos/apps/),最后安装好的app都会在onos启动的apps路径下/opt/onos/apps/
。
(必须有onos源码)
/onos/tools/package/runtime/bin
路径下执行
root@vpp3:~/onos/tools/package/runtime/bin# ./onos-app localhost install /opt/onos/apps/onos-app-oneping-1.10.0-SNAPSHOT.oar
{"name":"org.onosproject.oneping","id":117,"version":"1.10.0.SNAPSHOT","category":"Monitoring","description":"One-Ping-Only sample application","readme":"One-Ping-Only sample application","origin":"ON.Lab","url":"http://onosproject.org","featuresRepo":"mvn:org.onosproject/onos-app-oneping/1.10.0-SNAPSHOT/xml/features","state":"INSTALLED","features":["onos-app-oneping"],"permissions":[],"requiredApps":["org.onosproject.fwd"]}
不知道这个feature install有啥用,没有激活app但是list有变化
onos> feature:install onos-app-oneping
# list可以看到app了
onos> list
onos> feature:uninstall onos-app-oneping
# unistall也只影响了list,UI中还有应用
卸载(用app name)
root@vpp3:~/onos/tools/package/runtime/bin# ./onos-app localhost uninstall org.onosproject.oneping
UI Applications右上角的启动
onos> app (de)activate org.onosproject.$YOUR_APP_NAME
使用onos-app-examples的oneping,onos-app-examples
启动onos
启动mininet拓扑(配好远程控制器地址)
onos-app-examples的oneping用mvn package
后,生成的oar文件放到onos机器上,安装app,激活app
2022-03-22 17:38:42,583 | INFO | -message-handler | FeaturesServiceImpl | 20 - org.apache.karaf.features.core - 3.0.8 | Installing feature onos-app-oneping 1.10.0-SNAPSHOT
2022-03-22 17:38:42,583 | INFO | -message-handler | FeaturesServiceImpl | 20 - org.apache.karaf.features.core - 3.0.8 | Found installed feature onos-api 1.10.0
2022-03-22 17:38:42,610 | INFO | -message-handler | FeaturesServiceImpl | 20 - org.apache.karaf.features.core - 3.0.8 | Found installed feature scr-condition-webconsole_0_0_0 3.0.8
2022-03-22 17:38:42,610 | INFO | -message-handler | FeaturesServiceImpl | 20 - org.apache.karaf.features.core - 3.0.8 | Found installed feature webconsole-condition-scr_0_0_0 3.0.8
2022-03-22 17:38:42,611 | INFO | -message-handler | FeaturesServiceImpl | 20 - org.apache.karaf.features.core - 3.0.8 | Found installed feature standard-condition-webconsole_0_0_0 3.0.8
2022-03-22 17:38:42,674 | INFO | -message-handler | OnePing | 182 - org.onosproject.onos-app-oneping - 1.10.0.SNAPSHOT | Started
2022-03-22 17:38:42,679 | INFO | -message-handler | ApplicationManager | 127 - org.onosproject.onos-core-net - 1.10.0 | Application org.onosproject.oneping has been activated
在mininet第一次 h1 ping h2
2022-03-22 17:39:43,205 | INFO | ew I/O worker #1 | OnePing | 182 - org.onosproject.onos-app-oneping - 1.10.0.SNAPSHOT | Thank you, Vasili. One ping from 00:00:00:00:00:01 to 00:00:00:00:00:02 received by of:0000000000000002
2022-03-22 17:39:43,216 | INFO | ew I/O worker #1 | OnePing | 182 - org.onosproject.onos-app-oneping - 1.10.0.SNAPSHOT | Thank you, Vasili. One ping from 00:00:00:00:00:02 to 00:00:00:00:00:01 received by of:0000000000000002
第二次(无论是h1pingh2还是反过来)
2022-03-22 17:41:10,455 | WARN | ew I/O worker #1 | OnePing | 182 - org.onosproject.onos-app-oneping - 1.10.0.SNAPSHOT | What are you doing, Vasili?! I said one ping only!!! Ping from 00:00:00:00:00:01 to 00:00:00:00:00:02 has already been received by of:0000000000000002; 60 second ban has been issued
60s限制自动取消
2022-03-22 17:42:11,826 | WARN | tch-programming0 | OnePing | 182 - org.onosproject.onos-app-oneping - 1.10.0.SNAPSHOT | Careful next time, Vasili! Re-enabled ping from 00:00:00:00:00:01 to 00:00:00:00:00:01 on of:0000000000000002