sh.k7p.work/index.php,Laowang's Blogs

OpenDayLight(硼Boron版本)實戰開發入門

OpenDayLight[1](簡寫為ODL)的硼Boron(0.5.0)版本于2016-09-16 這幾天剛剛發布。作為一款開源SDN網絡控制器,依托于強大的社區支持以及豐富的功能特性,ODL成為了目前主流的SDN網絡控制器開發平臺。不僅為開發者提供了大量的網絡管理功能,而且藉由AD-SAL(API驅動的服務層)和MD-SAL(模型驅動的服務層), 給獨立的網絡應用提供了完善的二次開發接口。由于OpenDaylight架構的復雜性和多樣性,以及ODL上官方wiki文檔更新的比較緩慢,往往給開發者帶來很多的困難。

下面我們以最新的版本硼Boron為例,講解ODL的入門應用開發技術。

1. 介紹

1.1 ODL應用開發

ODL做為網絡控制器, 將網絡設備和應用程序連接起來。通過南向接口(例如OpenFlow協議等)管理和控制實際的網絡物理設備, 通過北向接口(例如RESTConf形式的接口)向外部應用程序提供信息獲取和操作下發的功能。如下圖所示:

16402a894532c20659664bd1a0680a86.png

圖1-1 ODL和APP

對于南向接口, 設備廠商會比較關注; 應用開發主要集中于北向接口。本文我們只關注于北向接口的APP的開發。

開發ODL的應用有兩種模式:如下圖所示

模式一 外部應用,應用通過ODL提供的RESTful接口使用ODL提供的全部功能

模式二 內部應用, 應用內嵌于ODL中, 同時向外部暴露RESTful接口以供外部程序調用

cd6e020a4d196da881613ce8995dfa10.png

圖1-2 應用開發模式

采用RESTful接口的應用開發和傳統的開發模式類似,不再詳細說明。完全使用RESTful的方式,當業務邏輯復雜時,可能會導致調用RESTful接口過多影響性能而且開發復雜。另一方面, ODL提供的RESTful接口不一定能滿足業務邏輯要求, 此時,就需要模式二的ODL內部應用開發, 然后通過自定義的RESTful接口向外暴露功能。

1.2 OSGi簡介

OSGi[2]是采用Java語言的一種面向服務的組件模型, 它提供了模塊化為基礎開發應用的基本架構。模塊可以動態加載/卸載,向外暴露功能和隱藏內部實現細節等, 模塊在稱為容器的環境中運行。OSGi的實現有Apache Felix, Equinox , Spring DM 等.

OpenDaylight基于OSGi的實現Apache Karaf(Apache Felix的一個子項目)來構造系統。 模塊也稱為bundle, ODL的內部應用就是一個個的bundle, 它們放置在ODL目錄的system子目錄下, 以maven的存儲庫形式組織。借助于OSGi的架構, ODL中的內部應用可以動態加載和卸載, 系統具有很好的靈活性和可擴展性, 這對于大型系統而言是非常重要的。

模塊不僅向外提供接口, 而且需要使用其它模塊提供的功能, 也即模塊之間具有依賴性。因此ODL內部應用的開發除了專注于功能, 而且對不同的ODL生產版本,需要配置不同的依賴。

2. ODL之硼Boron版本應用開發

此部分內容主要來自于ODL的DOC。

2.1 開發環境搭建

開發環境配置如下:

1) 64位Linux系統,4G以上內存, 16G以上硬盤剩余空間(如果編譯ODL發行版的話)

2) JDK8, maven-3.3.x

3) 環境變量設置(設置JAVA_HOME, M2_HOME, PATH變量設置, MAVEN_OPTS選項設置等, 略)

export JAVA_HOME=…

export MAVEN_OPTS=”-Xmx1024m”

2.2 開發示例項目

0) 獲取ODL的maven配置文件(用于maven編譯時下載ODL的相應jar文件)

# cp ~/.m2/settings.xml ~/.m2/settings.xml.old

1) 用maven生成項目框架(設項目為hello)

# mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller \

-DarchetypeArtifactId=opendaylight-startup-archetype \

-DarchetypeRepository=https://nexus.opendaylight.org/content/repositories/public/ \

-DarchetypeCatalog=https://nexus.opendaylight.org/content/repositories/public/archetype-catalog.xml

(輸入如下內容)

Define value for property ‘groupId’: : org.bupt.siwind.hello

Define value for property ‘artifactId’: : hello

Define value for property ‘package’: org.bupt.siwind.hello: :

Define value for property ‘classPrefix’: Hello: :

Define value for property ‘copyright’: : BNRC, Inc.

或者輸入如下:

mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller \

-DarchetypeArtifactId=opendaylight-startup-archetype \

-DarchetypeVersion=1.2.0-Boron \

-DarchetypeRepository=https://nexus.opendaylight.org/content/repositories/public/ \

-DarchetypeCatalog=https://nexus.opendaylight.org/content/repositories/public/archetype-catalog.xml

上述步驟完成后, 在當前目錄下面會生成hello目錄, 即為我們的APP目錄.

2) 修改依賴項(針對硼Boron版本)

# cd hello (進入hello項目目錄)

# 依次打開文件: pom.xml, api/pom.xml, artifacts/pom.xml, features/pom.xml, impl/pom.xml, it/pom.xml, karaf/pom.xml, 修改內容(其中features/pom.xml修改多處)

按照下面列出的各自修改對應的依賴的版本號:

odlparent(odlparent-lite): 1.7.0-Boron

binding-parent: 0.9.0-Boron

mdsal.model: 0.9.0-Boron

mdsal: 1.4.0-Boron

restconf: 1.4.0-Boron

yangtools: 1.0.0-Boron

dlux: 0.4.0-Boron

config-parent: 0.5.0-Boron

mdsal-it-parent: 1.4.0-Boron

karaf-parent: 1.7.0-Boron

例如文件features/pom.xml, 修改后如下(藍色部分):

org.opendaylight.odlparent

features-parent

1.7.0-Boron

……

0.9.0-Boron

1.4.0-Boron

1.4.0-Boron

1.0.0-Boron

0.4.0-Boron

etc/opendaylight/karaf

3) 編譯和運行

#mvn clean install

#./karaf/target/assembly/bin/karaf

進入ODL控制臺,輸入如下命令可以看到結果:

opendaylight-user@root>feature:list -i | grep hello

opendaylight-user@root>log:display | grep Hello

4) 添加基于yang模型的RPC接口, 并編譯運行

添加接口并編譯的內容看ODL的文檔, 略.

可以看到hello-world RPC接口, 輸入{“input”: { “name”:”Good day”}} , 可以看到結果。

c8745da0139ed1e0c80c76d3f746aa73.png

圖21 hello RPC example

Curl訪問RPC驗證:

#curl –user “admin”:”admin” \

-H “Accept: application/json” \

-H “Content-type: application/json” \

-X POST –data “{‘hello:input’: { ‘name’:’Good day ODL’}}” \

2.3 安裝到ODL生產版本

有三種方法: 方法一為將當前生成hello項目的bundle拷貝到已經正常部署運行的ODL的硼版本上; 方法二為重新編譯一個包含hello項目的ODL發行版。

方法三(推薦)為拷貝項目的maven結構到生產環境ODL的system目錄下,然后在生產環境ODL的features-integration-index處添加自己項目的repository倉庫即可進行feature的安裝。

1) 方法一: 手動拷貝bundle

由于ODL以OSGi的方式組織, 因此項目hello也是一個OSGi的bundle. 在ODL中, bundle位于ODL發行版的目錄的system/子目錄下,????并且各個bundle以maven的包形式組織。我們hello項目正常編譯運行后, hello的bundle存在于當前hello目錄下面的karaf/target/assembly/system下面(其它很多bundle不要拷貝), 我們從此目錄拷貝hello自己的bundle到ODL的發行版即可。

i) 拷貝: 假設當前正常部署運行的ODL發行版位于: /home/guest/distribution-karaf-0.5.0-Boron

當前的hello項目位于/home/guest/bin/hello

那么拷貝命令如下:

#cp -Ru /home/guest/bin/hello/karaf/target/assembly/system/org/bupt /home/guest/distribution-karaf-0.5.0-Boron/system/org

ii) 查看hello的maven路徑:

#cd hello (進入hello項目目錄)

#cat ./karaf/target/assembly/etc/org.apache.karaf.features.cfg

查看這一行:featuresRepositories

在最后有hello的mvn路徑: “mvn:org.bupt.siwind.odl/hello-features/1.0.0-SNAPSHOT/xml/features”

iii) 運行ODL并添加和安裝hello的bundle:

#cd /home/guest/distribution-karaf-0.5.0-Boron

#./bin/karaf (啟動ODL運行, 或者以干凈模式啟動: ./bin/karaf clean)

#opendaylight@root> feature:repo-add

mvn:org.bupt.siwind.odl/hello-features/1.0.0-SNAPSHOT/xml/features

# opendaylight@root> feature:install odl-hello-ui

# opendaylight@root> feature:list | grep hello

# opendaylight@root> log:display | grep Hello

可以看到運行結果正常。

(移除bundle)

# opendaylight@root> feature:repo-remove mvn:org.bupt.siwind.odl/hello-features/1.0.0-SNAPSHOT/xml/features

2) 方法二: 編譯hello項目到ODL發行版中

i) 編譯ODL發行版:

#git tag

#git checkout release/boron (切換需要的版本)

#mvn mvn clean install

編譯成功后在當前目錄下的distribution-karaf\target下面有壓縮包形式的發行版:

distribution-karaf-0.5.0-Boron.tar.gz, distribution-karaf-0.5.0-Boron.zip

當前目錄下的distribution-karaf\target\assembly為解壓縮后的karaf執行版本

ii) 記錄hello項目的信息

# cat /features/pom.xml

(記錄hello-feature的版本等信息)

# cat /karaf/target/assembly/etc/org.apache.karaf.features.cfg

(記錄hello的mvn路徑: “mvn:org.bupt.siwind.odl/hello-features/1.0.0-SNAPSHOT/xml/features”)

iii) 添加hello的bundle信息

此步驟之前,確保hello編譯運行和測試例運行通過, 并且用mvn clean install 安裝其bundle到了.m2/repository下面。

在當前的distribution目錄下面, 修改如下兩個pom.xml文件

# vim features-index/pom.xml , 添加如下內容:

org.bupt.siwind.odl

hello-features

1.0.0-SNAPSHOT

features

xml

# vim features-index/src/main/resources/features.xml, 添加如下內容:

mvn:org.bupt.siwind.odl/hello-features/1.0.0-SNAPSHOT/xml/features

iv) 重新編譯發行版

#mvn clean install

3) 方法三(推薦),結合前述兩種方法,操作如下:

i) 拷貝: 在當前編譯運行成功項目的目錄” karaf/target/assembly/system/”下面是maven格式的倉庫,拷貝我們項目的maven倉庫內容到生成環境ODL的system目錄下。

例如:

#cp –R ?/home/guest/bin/hello/karaf/target/assembly/system/org/bupt? /home/guest/distribution-karaf-0.5.0-Boron/system/org

ii) 添加我們項目倉庫信息到ODL生成環境的” features-integration-index”xml文件下面。此文件路徑為:

“\system\org\opendaylight\integration\features-integration-index\\features-integration-index--features.xml”

例如: Boson-SR1的路徑為:

“system\org\opendaylight\integration\features-integration-index\0.5.1-Boron-SR1\features-integration-index-0.5.1-Boron-SR1-features.xml”

打開此文件,在末尾的標簽之前添加一行內容:

mvn:org.bupt.siwind.odl/hello-features/1.0.0-SNAPSHOT/xml/features

iii) 啟動生產環境ODL,安裝feature即可。

# /bin/karaf

# opendaylight@root> feature:install? xxxx

8e8fe1d56a3ecdb69b0b9d91d62a5fa2.png

圖2-2 運行結果

3. 結論

本文介紹了目前2016最新的ODL硼Boron版本的應用開發基礎步驟, 其也適用于其它版本的開發, 以及介紹了一些OSGi相關的背景技術; 增加了將應用集成到發行版ODL的方法,和簡單的RPC接口示例。

4. FAQ

1) 不能在ODL發行版中正常加載hello項目

A:查看是否hello的各個pom.xml中定義的依賴版本符合當前運行的ODL發行版

2) 編譯ODL的integration/distribution發行版時, 某些依賴的bundle不能下載

A:查看報錯的是哪個bundle, 這里是ODL的倉儲, 用git自行下載此bundle源碼, 編譯到本機的.m2/repository中.

例如:

# cd {PROJECT}

# git checkout release/boron ? ?(切換指定版本)

# mvn clean install

References

[1] OpenDaylight:開源SDN平臺

[2] OSGi: The Dynamic Module System for Java[EB/OL]. https://www.osgi.org/.

贊過:

贊 正在加載……

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/443544.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/443544.shtml
英文地址,請注明出處:http://en.pswp.cn/news/443544.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

php接收不到ios值,php設置標簽后,ios收不到,安卓可以收到

通過下面代碼設置的標簽:$client->device()->addTags($registration_id, test);通過下面代碼推送的消息$result self::getClient()->push()->setPlatform([ios, android])->addTag([test])->setNotificationAlert($content)->options([time_t…

0+到10+隨機數+java,java代碼--實現隨機輸出10個隨機數,并顯示最大值,最小值

總結;對于length()屬性&#xff0c;還不是很熟悉。不會用它。package com.s.x;//隨機產生10個隨機數&#xff0c;并且顯示出最大值&#xff0c;最小值public class Love {public static void main(String[] args) {int a[] new int[10];int max, min;for (int i 0; i < 10…

oracle推送短信,ORACLE 10G如何實現發短信的服務?

CREATE OR REPLACE PROCEDURE SEND_MAIL(SUBJECT IN VARCHAR2,CONTENTSED IN VARCHAR2) ISEMAIL_SERVER VARCHAR2(30) : 10.1.200.6;SENDER_ADDRESS VARCHAR2(50) : testcz.com.cn;--發件地址RECEIVER_ADDRESS VARCHAR2(30); …

Java和iText導出pdf文檔

一&#xff1a;工程截圖&#xff1a; 二&#xff1a;項目運行截圖&#xff1a; 三&#xff1a;源代碼&#xff1a; Book.java package com.iText.bean;public class Book {private int bookId;// 圖書編號private String name;// 圖書名稱private String author;// 圖書作者pr…

oracle 12 ORA-01262,oracle物理dg安裝:方法二

本文記錄了物理dg的第二種安裝方法&#xff0c;使用rman duplicate from active database&#xff0c;不需要做備份文件。準備工作&#xff1a;1.兩臺虛擬機&#xff0c;主機名&#xff1a;n1, n2&#xff0c;操作系統&#xff1a;centos6.7&#xff0c;建好信任關系2.oracle d…

linux多進程原理,Linux進程調度

極簡模式假設我的系統只有一種調度算法cfs那么有個調度的隊列 cfs_rq所有running的進程都會 進入這個隊列&#xff0c;不在running 或者其他情況會出隊列&#xff0c;ok。則假設隊列控制的算法有以下。cfs_rq_enqueuecfs_rq_dequeuecfs_rq_pick所操作的是進程描述符 task_struc…

openwrt使用linux內核版本,降低OpenWRT的Linux內核版本

不久前&#xff0c;為了移植某驅動程序&#xff0c;筆者可謂絞盡腦汁&#xff0c;在4.1內核版本上&#xff0c;嘗試了很多次都沒能成功&#xff0c;后來仔細分析&#xff0c;才知道是內核版本過高導致的&#xff0c;本文給出降低內核版本的方法&#xff0c;具體編譯環境的搭建&…

Hibernate3.x,hibernate3.x,Hibernate3.x整合Spring3.x不能實現自動創建表結構的解決辦法:...

一&#xff1a;今天遇到一個詭異的問題&#xff0c;就是關于hibernate3.x實現表結構自動創建&#xff0c;一般我們在用Struts2&#xff0c;Hibernate3.x&#xff0c;Spring3.x搭建框架&#xff0c;尤其在開發階段都希望在啟動Web容器時就可以根據Bean實體自動創建數據表結構&am…

linux s t i a權限,關于Linux下s、t、i、a權限

關于Linux下s、t、i、a權限文件權限除了r、w、x外還有s、t、i、a權限&#xff1a;s&#xff1a;文件屬主和組設置SUID和GUID&#xff0c;文件在被設置了s權限后將以root身份執行。在設置s權限時文件屬主、屬組必須先設置相應的x權限&#xff0c;否則s權限并不能正真生效(c h m …

linux ssh禁止用戶訪問任何目錄,怎么限制遠程ssh用戶訪問特定的文件

比如我要實現以下目標&#xff0c;通過配置linux限制SSH用戶指定目錄user 1 只可以訪問 /Media, /Documents以及它的家目錄User 2 只可以訪問/Folder21, 以及它的家目錄,User 3 只可以訪問 /Documents, /Folder21 以及他的家目錄,ssh如何限制指定目錄2. 通過配置Linux權限限制S…

linux配置定時刪除日志文件,Linux使用shell腳本定時刪除歷史日志文件

Linux使用shell腳本定時刪除歷史日志文件,文件,小時,時間,目錄,腳本Linux使用shell腳本定時刪除歷史日志文件易采站長站&#xff0c;站長之家為您整理了Linux使用shell腳本定時刪除歷史日志文件的相關內容。1、tools目錄文件結構[rootwww tools]# tree tools/tools/├── bin│…

linux awk執行shell命令,awk調用shell命令

在awk內部可利用管道和getline函數來調用shell命令&#xff0c;并可得到返回的具體結果&#xff0c;進行相應處理。例子如下&#xff1a;1) {while ( ("ls" | getline) >0 )print}輸出當前目錄下的所有文件&#xff0c;并打印到標準輸出上。| 是管道&#xff0c;g…

linux添加啟動腳本文件夾,linux – 將腳本中的符號鏈接添加到rc.d文件夾中以在系統啟動期間啟動進程...

我正在使用fedora 15.我試圖添加MYSql守護進程在系統strtup期間啟動.我已經明白我必須將它添加到rc5.d,因為它是默認目標&是graphical.target.來自inittab&#xff1a;systemd uses ‘targets’ instead of runlevels. By default, there are two main targets:multi-user.…

org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException:

一&#xff1a;今天在使用struts2做文件上傳時出現了該異常&#xff1a; 警告: Unable to parse request org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (5897994) exceeds the configured maximum (2…

linux天氣軟件,類似智能手機!Linux中安裝Conky天氣插件

如今&#xff0c;智能手機中很多都安裝相匹配外觀的天氣小插件&#xff0c;而對于喜歡操作系統平臺的用戶而言&#xff0c;可以在你的Linux桌面中擁有像智能手機一樣的天氣外觀。通過Flair Weather Conky可以將使用一個GUI工具Conky Manager在Linux中輕松地管理Conky。這里介紹…

linux go 安裝路徑,在Alpine Linux D的路徑中找不到已安裝的Go二進制文件

我有一個Go二進制文件&#xff0c;試圖在Alpine Docker映像上運行。這對于Docker Go二進制文件很好用。docker run -it alpine:3.3 shapk add --no-cache curlDOCKER_BUCKETget.docker.comDOCKER_VERSION1.9.1curl -fSL "https://${DOCKER_BUCKET}/builds/Linux/x86_64/do…

linux安裝下載中文包,linux下安裝中文包和字體

在虛擬機中使用中文輸入法和中文顯示使用的是rhel5的鏡像我把其鏡像掛載在/mnt/cdrom中&#xff0c;然后切換到/Server目錄下&#xff0c;安裝支持中文字體Mount /dev/cdrom /mnt/cdromCd /mnt/cdrom/serverrpm -ivh fonts-chinese-3.02-9.6.el5.noarch.rpmrpm -ivh fonts-ISO8…

Java-Jdbc,JDBC連接Oracle11g實例:

很長時間沒用Oracle數據庫了&#xff0c;今天在公司的電腦上裝了一個Oracle11g&#xff0c;安裝完成后&#xff0c;順便寫了個簡單的Jdbc連接Oracle的例子&#xff0c;現在記錄一下&#xff0c;方便以后查看&#xff1a; 例子很簡單&#xff0c;直接上代碼&#xff1a; (注意&…

linux無桌面重做系統,Linux不需要重做系統

感謝hsyyf的投遞但從系統構架上來講&#xff0c;總所周知&#xff0c;Linux的穩定性遠大于windows&#xff0c;單純的使用不會引起系統的損壞。當不進行危險操作時&#xff0c;例如執行sudo rm-rf/*之類的命令&#xff0c;或者混用分區工具&#xff0c;是不會引起各種徹底性損壞…

linux遠程連接工具putty使用方法,linux遠程登陸工具putty使用

#putty工具百度下載即可&#xff0c;最好從官網下。安裝時&#xff0c;除安裝位置外&#xff0c;其余默認即可。1、使用命令ifconfig命令&#xff0c;記下eth0的IP&#xff0c;我的是192.168.1.1692、打開putty&#xff0c;并將查到的ip寫在圖中位置&#xff0c;下側的Saved Se…