目录
开发环境
- VM14.0
- Ubuntu 18.04
- JDK1.8
- Maven 3.6.3
- postman
所用资料
Opendaylight-Controller(Solium版)
下载压缩包,用clone的话下载的应该是最新版
maven 设置
cp -n ~/.m2/settings.xml{,.orig} ; wget -q -O - https://raw.githubusercontent.com/opendaylight/odlparent/master/settings.xml > ~/.m2/settings.xml
实验步骤
构建项目
进入controller-stable-sodium/opendaylight/md-sal/samples
在该目录下执行以下命令
mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
耗时2-3分钟...
编写toaster
添加一个名为features的module
打开项目,在samples目录下的pom.xml中添加名为features的module,如下图
在features目录下添加pom.xml,内容如下
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.odlparent</groupId>
<artifactId>odlparent-lite</artifactId>
<version>5.0.5</version>
<relativePath/>
</parent>
<groupId>org.opendaylight.controller.samples</groupId>
<artifactId>mytoaster-features-aggregator</artifactId>
<version>1.10.3-SNAPSHOT</version>
<packaging>pom</packaging>
<name>org.opendaylight.controller.samples :: ${project.artifactId}</name>
<modules>
<module>odl-mytoaster</module>
<module>odl-mytoaster-provider</module>
<module>features-mytoaster</module>
</modules>
</project>
在features中添加三个目录,odl-mytoaster,odl-mytoster-provider,features-mytoaster。
mkdir odl-mytoaster odl-mytoster-provider features-mytoaster
之后,在三个目录下分别添加pom.xml文件,内容如下
odl-mytoaster下的pom.xml文件内容
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.odlparent</groupId>
<artifactId>feature-repo-parent</artifactId>
<version>5.0.5</version>
<relativePath/>
</parent>
<groupId>org.opendaylight.controller.samples</groupId>
<artifactId>features-mytoaster</artifactId>
<version>1.10.3-SNAPSHOT</version>
<packaging>feature</packaging>
<name>ODL::org.opendaylight.mytoaster::${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>odl-mytoaster-provider</artifactId>
<version>${project.version}</version>
<type>xml</type>
<classifier>features</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>odl-mytoaster</artifactId>
<version>${project.version}</version>
<type>xml</type>
<classifier>features</classifier>
</dependency>
</dependencies>
</project>
odl-mytoaster下的pom.xml内容
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.odlparent</groupId>
<artifactId>single-feature-parent</artifactId>
<version>5.0.5</version>
<relativePath/>
</parent>
<groupId>org.opendaylight.controller.samples</groupId>
<artifactId>odl-mytoaster</artifactId>
<version>1.10.3-SNAPSHOT</version>
<packaging>feature</packaging>
<name>OpenDaylight::mytoaster::Impl[Karaf Feature]</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>mdsal-artifacts</artifactId>
<version>1.10.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>odl-mdsal-broker</artifactId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sample-toaster</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
features-mytoaster的内容
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.odlparent</groupId>
<artifactId>single-feature-parent</artifactId>
<version>5.0.5</version>
<relativePath/>
</parent>
<groupId>org.opendaylight.controller.samples</groupId>
<artifactId>odl-mytoaster-provider</artifactId>
<version>1.10.3-SNAPSHOT</version>
<packaging>feature</packaging>
<name>OpenDaylight::mytoaster::Impl[Karaf Feature]</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>mdsal-artifacts</artifactId>
<version>1.10.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>odl-mdsal-broker</artifactId>
<type>xml</type>
<classifier>features</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sample-toaster</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sample-toaster-provider</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
再次编译
进入controller-stable-sodium/opendaylight/md-sal/samples
在该目录下再次执行以下命令
mvn clean install -DskipTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true
耗时5分半...
添加toaster到opendaylight中
我选择了上篇文章SDN-OpenDaylight(Solium版本)应用开发入门HelloWorld中创建的helloworld项目。
在helloworld/karaf/target/assembly/system/org/opendaylight/controller下创建一个名为 samples的目录在改目录中创建如下几个文件夹 features-mytoaster odl-mytoaster-consumer sample-toaster-consumer features_mytoaster odl-mytoaster-provider sample-toaster-provider odl-mytoaster sample-toaster
mkdir samples
cd samples
mkdir features-mytoaster odl-mytoaster-consumer sample-toaster-consumer features_mytoaster odl-mytoaster-provider sample-toaster-provider odl-mytoaster sample-toaster
在每个目录中创建和 toaster 项目中对应 module version 相同名称的目录,即创建1.10.3-SNAPSHOT目录
mkdir 1.10.3-SNAPSHOT
在 odl 开头的目录中(odl-mytoaster、odl-mytoaster-provider),将前面 toaster 构建的 target目录 中找到 feature目录并将其每一个目录中的feature.xml放入创建的和版本名相同的目录(1.10.3-SNAPSHOT)中
在以 sample 开头的目录(三个)中放入对应模块构建的 jar 包,不要结尾有sources的,另外两个同理。
feature:repo-add mvn:org.opendaylight.controller.samples/features-mytoaster/1.10.3-SNAPSHOT/xml/features
Postman测试
更多SDN相关内容,请查看:SDN-自学笔记
有问题请下方评论,转载请注明出处,并附有原文链接,谢谢!如有侵权,请及时联系。