.externalToolBuilders\r
maven-eclipse.xml\r
.metadata/
+.checkstyle
<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.openflowplugin</groupId>
- <artifactId>openflowplugin-parent</artifactId>
- <version>0.2.0-SNAPSHOT</version>
- <relativePath>../../</relativePath>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>features-parent</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ <relativePath/>
</parent>
- <artifactId>features-flow</artifactId>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <version>0.2.0-SNAPSHOT</version>
+ <artifactId>features-flow</artifactId>
<packaging>jar</packaging>
<properties>
- <features.file>features.xml</features.file>
+ <yangtools.version>0.8.0-SNAPSHOT</yangtools.version>
+ <config.version>0.4.0-SNAPSHOT</config.version>
+ <mdsal.version>1.3.0-SNAPSHOT</mdsal.version>
+ <openflowjava.version>0.7.0-SNAPSHOT</openflowjava.version>
+ <lldp.version>0.10.0-SNAPSHOT</lldp.version>
+
+ <config.configfile.directory>etc/opendaylight/karaf</config.configfile.directory>
+ <config.statistics.manager.configfile>30-statistics-manager.xml</config.statistics.manager.configfile>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <!-- This project -->
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-artifacts</artifactId>
+ <version>${project.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- YANG tools -->
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-artifacts</artifactId>
+ <version>${yangtools.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- Controller infrastructure -->
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-artifacts</artifactId>
+ <version>${config.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>mdsal-artifacts</artifactId>
+ <version>${mdsal.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- OpenFlowJava -->
+ <dependency>
+ <groupId>org.opendaylight.openflowjava</groupId>
+ <artifactId>openflowjava-artifacts</artifactId>
+ <version>${openflowjava.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>features-mdsal</artifactId>
- <version>${mdsal.version}</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>org.opendaylight.controller.model</groupId>
<artifactId>model-inventory</artifactId>
- <version>${mdsal.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.controller.model</groupId>
<artifactId>model-topology</artifactId>
- <version>${mdsal.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowplugin.applications</groupId>
<groupId>org.opendaylight.openflowplugin</groupId>
<artifactId>openflowplugin-common</artifactId>
</dependency>
- <!-- test to validate features.xml -->
<dependency>
- <groupId>org.opendaylight.odlparent</groupId>
- <artifactId>features-test</artifactId>
- <version>1.6.0-SNAPSHOT</version>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>liblldp</artifactId>
+ <version>${lldp.version}</version>
</dependency>
</dependencies>
- <build>
- <resources>
- <resource>
- <filtering>true</filtering>
- <directory>src/main/resources</directory>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>filter</id>
- <goals>
- <goal>resources</goal>
- </goals>
- <phase>generate-resources</phase>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.directory}/classes/${features.file}</file>
- <type>xml</type>
- <classifier>features</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <systemPropertyVariables>
- <karaf.distro.groupId>org.opendaylight.controller</karaf.distro.groupId>
- <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId>
- <karaf.distro.version>${commons.opendaylight.version}</karaf.distro.version>
- </systemPropertyVariables>
- <dependenciesToScan>
- <dependency>org.opendaylight.odlparent:features-test</dependency>
- </dependenciesToScan>
- </configuration>
- </plugin>
- </plugins>
- </build>
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
<repository>mvn:org.opendaylight.controller/features-mdsal/${mdsal.version}/xml/features</repository>
<feature name='odl-flow-model' version='${project.version}' description="OpenDaylight :: Flow :: Model">
- <feature version='${yangtools.version}'>odl-yangtools-models</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-base/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-service/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-statistics/${project.version}</bundle>
+ <feature version='${yangtools.version}'>odl-mdsal-models</feature>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-base/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-service/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-statistics/{{VERSION}}</bundle>
<bundle>mvn:org.opendaylight.controller.model/model-inventory/${mdsal.version}</bundle>
<bundle>mvn:org.opendaylight.controller.model/model-topology/${mdsal.version}</bundle>
</feature>
<feature name='odl-flow-services' version='${project.version}' description="OpenDaylight :: Flow :: Services">
<feature version='${project.version}'>odl-mdsal-broker</feature>
<feature version='${project.version}'>odl-flow-model</feature>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/statistics-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/inventory-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.controller/liblldp/${mdsal.version}</bundle>
- <configfile finalname="${config.configfile.directory}/${config.statistics.manager.configfile}">mvn:org.opendaylight.controller.md/statistics-manager-config/${mdsal.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/statistics-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/inventory-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.controller/liblldp/{{VERSION}}</bundle>
+ <configfile finalname="${config.configfile.directory}/${config.statistics.manager.configfile}">mvn:org.opendaylight.openflowplugin.applications/statistics-manager-config/{{VERSION}}/xml/config</configfile>
</feature>
</features>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
<module>forwardingrules-manager</module>
<module>forwardingrules-manager-config</module>
<module>topology-lldp-discovery</module>
+ <!--<module>features</module>-->
<!-- experimental apps -->
<module>bulk-o-matic</module>
</modules>
private static final int MAX_BATCH = 100;
private final BlockingQueue<StatDataStoreOperation> dataStoreOperQueue = new LinkedBlockingDeque<>(QUEUE_DEPTH);
- private final Map<InstanceIdentifier<Node>, Pair<StatPermCollector, UUID>> nodeCollectorMap = new ConcurrentHashMap<>();
- private AtomicInteger numNodesBeingCollected = new AtomicInteger(0);
+ private final Map<InstanceIdentifier<Node>, Pair<StatPermCollector, UUID>> nodeCollectorMap = new ConcurrentHashMap<>();
+ private AtomicInteger numNodesBeingCollected = new AtomicInteger(0);
- private final DataBroker dataBroker;
+ private final DataBroker dataBroker;
private final ExecutorService statRpcMsgManagerExecutor;
private final ExecutorService statDataStoreOperationServ;
private StatRpcMsgManager rpcMsgManager;
<classifier>features</classifier>
<type>xml</type>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>features-openflowplugin-extension-li</artifactId>
+ <version>${project.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ </dependency>
<dependency>
<groupId>${project.groupId}.applications</groupId>
<artifactId>bulk-o-matic</artifactId>
<type>xml</type>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>features-openflowplugin-extension-li</artifactId>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
<build>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
--- /dev/null
+<?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>features-parent</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <version>0.2.0-SNAPSHOT</version>
+ <artifactId>features-openflowplugin-extension-li</artifactId>
+
+ <packaging>jar</packaging>
+
+ <properties>
+ <openflowplugin.version>0.2.0-SNAPSHOT</openflowplugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- This project -->
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-artifacts</artifactId>
+ <version>${project.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <!-- feature dependencies -->
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>features-openflowplugin-li</artifactId>
+ <classifier>features</classifier>
+ <type>xml</type>
+ </dependency>
+
+ <!-- bundle dependencies -->
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-extension-api</artifactId>
+ </dependency>
+
+ <!-- Nicira extensions -->
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-extension-nicira-config</artifactId>
+ <type>xml</type>
+ <classifier>config</classifier>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-extension-nicira</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowjava-extension-nicira-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowjava-extension-nicira</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+
+<features name="openflowplugin-extension-li-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
+ <repository>mvn:org.opendaylight.openflowplugin/features-openflowplugin-li/${project.version}/xml/features</repository>
+
+ <feature name="odl-openflowplugin-nxm-extensions-li" description="OpenDaylight :: Openflow Plugin :: Nicira Extensions" version='${project.version}'>
+ <feature version="${project.version}">odl-openflowplugin-southbound-li</feature>
+ <configfile finalname="etc/opendaylight/karaf/43-openflowjava-nx-config.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-extension-nicira-config/{{VERSION}}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowjava-extension-nicira-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowjava-extension-nicira/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-extension-nicira/{{VERSION}}</bundle>
+ </feature>
+
+</features>
<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.openflowplugin</groupId>
- <artifactId>openflowplugin-extension-parent</artifactId>
- <version>0.2.0-SNAPSHOT</version>
- <relativePath>../</relativePath>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>features-parent</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ <relativePath/>
</parent>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <version>0.2.0-SNAPSHOT</version>
<artifactId>features-openflowplugin-extension</artifactId>
<packaging>jar</packaging>
<properties>
- <features.file>features.xml</features.file>
- <karaf.empty.distro.version>1.6.0-SNAPSHOT</karaf.empty.distro.version>
+ <openflowplugin.version>0.2.0-SNAPSHOT</openflowplugin.version>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <!-- This project -->
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-artifacts</artifactId>
+ <version>${project.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<!-- feature dependencies -->
<dependency>
<groupId>org.opendaylight.openflowplugin</groupId>
<artifactId>openflowjava-extension-nicira</artifactId>
</dependency>
-
- <!-- test the features.xml -->
- <dependency>
- <groupId>org.opendaylight.odlparent</groupId>
- <artifactId>features-test</artifactId>
- </dependency>
- <!-- dependency for opendaylight-karaf-empty for use by testing -->
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>opendaylight-karaf-empty</artifactId>
- <version>${karaf.distro.empty.version}</version>
- <type>zip</type>
- </dependency>
</dependencies>
- <build>
- <resources>
- <resource>
- <filtering>true</filtering>
- <directory>src/main/resources</directory>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>filter</id>
- <goals>
- <goal>resources</goal>
- </goals>
- <phase>generate-resources</phase>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.directory}/classes/${features.file}</file>
- <type>xml</type>
- <classifier>features</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.16</version>
- <configuration>
- <systemPropertyVariables>
- <karaf.distro.groupId>org.opendaylight.controller</karaf.distro.groupId>
- <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId>
- <karaf.distro.version>${karaf.empty.distro.version}</karaf.distro.version>
- </systemPropertyVariables>
- <dependenciesToScan>
- <dependency>org.opendaylight.odlparent:features-test</dependency>
- </dependenciesToScan>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
</project>
<feature name="odl-openflowplugin-nxm-extensions" description="OpenDaylight :: Openflow Plugin :: Nicira Extensions" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound</feature>
- <configfile finalname="etc/opendaylight/karaf/43-openflowjava-nx-config.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-extension-nicira-config/${project.version}/xml/config</configfile>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowjava-extension-nicira-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowjava-extension-nicira/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-extension-nicira/${project.version}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/43-openflowjava-nx-config.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-extension-nicira-config/{{VERSION}}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowjava-extension-nicira-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowjava-extension-nicira/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-extension-nicira/{{VERSION}}</bundle>
</feature>
</features>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
<artifactId>openflowjava-extension-nicira-api</artifactId>
</dependency>
<!-- <dependency> -->
-<!-- <groupId>org.opendaylight.yangtools.model</groupId> -->
+<!-- <groupId>org.opendaylight.mdsal.model</groupId> -->
<!-- <artifactId>yang-ext</artifactId> -->
<!-- </dependency> -->
<dependency>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
<module>openflowplugin-extension-nicira</module>
<module>openflowplugin-extension-nicira-config</module>
<module>features</module>
+ <module>features-li</module>
<module>test-extension</module>
</modules>
</project>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
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.openflowplugin</groupId>
- <artifactId>openflowplugin-parent</artifactId>
- <version>0.2.0-SNAPSHOT</version>
- <relativePath>../parent</relativePath>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>features-parent</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ <relativePath/>
</parent>
- <artifactId>features-openflowplugin-li</artifactId>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>features-openflowplugin-li</artifactId>
<packaging>jar</packaging>
+ <version>0.2.0-SNAPSHOT</version>
<properties>
- <karaf.empty.distro.version>1.6.0-SNAPSHOT</karaf.empty.distro.version>
+ <yangtools.version>0.8.0-SNAPSHOT</yangtools.version>
+ <config.version>0.4.0-SNAPSHOT</config.version>
+ <mdsal.version>1.3.0-SNAPSHOT</mdsal.version>
+ <openflowjava.version>0.7.0-SNAPSHOT</openflowjava.version>
+ <openflowplugin.version>0.2.0-SNAPSHOT</openflowplugin.version>
+ <dlux.version>0.3.0-SNAPSHOT</dlux.version>
+ <lldp.version>0.10.0-SNAPSHOT</lldp.version>
+
<config.configfile.directory>etc/opendaylight/karaf</config.configfile.directory>
<config.statistics.manager.configfile>30-statistics-manager.xml</config.statistics.manager.configfile>
- <controller.model.version>1.3.0-SNAPSHOT</controller.model.version>
+ <restconf.version>1.3.0-SNAPSHOT</restconf.version>
+ <mdsal.model.version>0.8.0-SNAPSHOT</mdsal.model.version>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <!-- This project -->
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-artifacts</artifactId>
+ <version>${project.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- YANG tools -->
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-artifacts</artifactId>
+ <version>${yangtools.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- Controller infrastructure -->
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-artifacts</artifactId>
+ <version>${config.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>mdsal-artifacts</artifactId>
+ <version>${mdsal.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- restconf -->
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
+ <artifactId>restconf-artifacts</artifactId>
+ <version>${restconf.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+
+ <!-- OpenFlowJava -->
+ <dependency>
+ <groupId>org.opendaylight.openflowjava</groupId>
+ <artifactId>openflowjava-artifacts</artifactId>
+ <version>${openflowjava.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<!-- feature dependencies -->
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>features-mdsal-model</artifactId>
+ <version>${mdsal.model.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>features-mdsal</artifactId>
- <version>${mdsal.version}</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>features-yangtools</artifactId>
<classifier>features</classifier>
- <version>${yangtools.version}</version>
<type>xml</type>
</dependency>
<dependency>
- <groupId>org.opendaylight.controller</groupId>
+ <groupId>org.opendaylight.netconf</groupId>
<artifactId>features-restconf</artifactId>
- <version>${mdsal.version}</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowjava</groupId>
<artifactId>features-openflowjava</artifactId>
- <version>${openflowjava.version}</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>liblldp</artifactId>
- <version>${sal.api.version}</version>
+ <version>${lldp.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowplugin</groupId>
<type>xml</type>
<classifier>config</classifier>
</dependency>
-
-
- <!-- test the features.xml -->
- <dependency>
- <groupId>org.opendaylight.odlparent</groupId>
- <artifactId>features-test</artifactId>
- </dependency>
- <!-- dependency for opendaylight-karaf-empty for use by testing -->
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>opendaylight-karaf-empty</artifactId>
- <version>${karaf.distro.empty.version}</version>
- <type>zip</type>
- </dependency>
</dependencies>
-
- <build>
- <resources>
- <resource>
- <filtering>true</filtering>
- <directory>src/main/resources</directory>
- </resource>
- </resources>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>filter</id>
- <goals>
- <goal>resources</goal>
- </goals>
- <phase>generate-resources</phase>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.outputDirectory}/features.xml</file>
- <type>xml</type>
- <classifier>features</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.16</version>
- <configuration>
- <systemPropertyVariables>
- <karaf.distro.groupId>org.opendaylight.controller</karaf.distro.groupId>
- <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId>
- <karaf.distro.version>${karaf.empty.distro.version}</karaf.distro.version>
- </systemPropertyVariables>
- <dependenciesToScan>
- <dependency>org.opendaylight.odlparent:features-test</dependency>
- </dependenciesToScan>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <scm>
- <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
- <tag>HEAD</tag>
- <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url>
- </scm>
</project>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
<repository>mvn:org.opendaylight.controller/features-mdsal/${mdsal.version}/xml/features</repository>
- <repository>mvn:org.opendaylight.controller/features-restconf/${mdsal.version}/xml/features</repository>
+ <repository>mvn:org.opendaylight.netconf/features-restconf/${restconf.version}/xml/features</repository>
<repository>mvn:org.opendaylight.openflowjava/features-openflowjava/${openflowjava.version}/xml/features</repository>
<repository>mvn:org.opendaylight.dlux/features-dlux/${dlux.version}/xml/features</repository>
<repository>mvn:org.opendaylight.yangtools/features-yangtools/${yangtools.version}/xml/features</repository>
+ <repository>mvn:org.opendaylight.mdsal.model/features-mdsal-model/${mdsal.model.version}/xml/features</repository>
+
<feature name='odl-openflowplugin-all-li' description="OpenDaylight :: Openflow Plugin :: All" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound-li</feature>
<feature version="${mdsal.version}">odl-mdsal-broker</feature>
<feature version="${project.version}">odl-openflowplugin-nsf-services-li</feature>
<feature version="${openflowjava.version}">odl-openflowjava-protocol</feature>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/{{VERSION}}</bundle>
<!-- TODO : remove dependency on openflowplugin in the future -->
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-impl/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-extension-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.controller/liblldp/${sal.api.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/42-openflowplugin-Li.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-controller-config/${project.version}/xml/config-Li</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-impl/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-extension-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.controller/liblldp/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/42-openflowplugin-Li.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-controller-config/{{VERSION}}/xml/config-Li</configfile>
</feature>
<feature name='odl-openflowplugin-flow-services-li' description="OpenDaylight :: Openflow Plugin :: Flow Services" version='${project.version}'>
description="OpenDaylight :: OpenflowPlugin :: NSF :: Services">
<feature version='${mdsal.version}'>odl-mdsal-broker</feature>
<feature version='${project.version}'>odl-openflowplugin-nsf-model-li</feature>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.controller/liblldp/${sal.api.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/30-forwardingrules-manager.xml">mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager-config/${project.version}/xml/config</configfile>
- <configfile finalname="etc/opendaylight/karaf/72-topology-lldp-discovery.xml">mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/${project.version}/xml/config</configfile>
- <configfile finalname="etc/opendaylight/karaf/73-topology-manager.xml">mvn:org.opendaylight.openflowplugin.applications/topology-manager/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.controller/liblldp/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/30-forwardingrules-manager.xml">mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager-config/{{VERSION}}/xml/config</configfile>
+ <configfile finalname="etc/opendaylight/karaf/72-topology-lldp-discovery.xml">mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/{{VERSION}}/xml/config</configfile>
+ <configfile finalname="etc/opendaylight/karaf/73-topology-manager.xml">mvn:org.opendaylight.openflowplugin.applications/topology-manager/{{VERSION}}/xml/config</configfile>
</feature>
<feature name='odl-openflowplugin-nsf-model-li' version='${project.version}'
description="OpenDaylight :: OpenflowPlugin :: NSF :: Model">
<!-- general models -->
- <feature version='${yangtools.version}'>odl-yangtools-models</feature>
- <bundle>mvn:org.opendaylight.controller.model/model-inventory/${controller.model.version}</bundle>
- <bundle>mvn:org.opendaylight.controller.model/model-topology/${controller.model.version}</bundle>
+ <feature version='${yangtools.version}'>odl-mdsal-models</feature>
+ <bundle>mvn:org.opendaylight.controller.model/model-inventory/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.controller.model/model-topology/{{VERSION}}</bundle>
<!-- openflow specific models -->
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-base/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-statistics/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-service/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-base/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-statistics/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-service/{{VERSION}}</bundle>
</feature>
<feature name='odl-openflowplugin-flow-services-rest-li' description="OpenDaylight :: Openflow Plugin :: Flow Services :: REST" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-flow-services-li</feature>
- <feature version="${mdsal.version}">odl-restconf</feature>
+ <feature version="${restconf.version}">odl-restconf</feature>
</feature>
<feature name='odl-openflowplugin-flow-services-ui-li' description="OpenDaylight :: Openflow Plugin :: Flow Services :: UI" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-flow-services-rest-li</feature>
<feature version="${dlux.version}">odl-dlux-core</feature>
- <feature version="${mdsal.version}">odl-mdsal-apidocs</feature>
+ <feature version="${restconf.version}">odl-mdsal-apidocs</feature>
<feature version="${mdsal.version}">odl-mdsal-xsql</feature>
</feature>
<!-- CBENCH TESTING -->
<feature name='odl-openflowplugin-drop-test-li' description="OpenDaylight :: Openflow Plugin :: Drop Test" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-flow-services-li</feature>
- <bundle>mvn:org.opendaylight.openflowplugin/test-common/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/drop-test-karaf/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/69-drop-test.xml">mvn:org.opendaylight.openflowplugin/drop-test-karaf/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/test-common/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/drop-test-karaf/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/69-drop-test.xml">mvn:org.opendaylight.openflowplugin/drop-test-karaf/{{VERSION}}/xml/config</configfile>
</feature>
<!-- APPLICATIONS -->
<feature name='odl-openflowplugin-app-table-miss-enforcer-li' description="OpenDaylight :: Openflow Plugin :: Application - table-miss-enforcer" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound-li</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/table-miss-enforcer/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/69-table-miss-enforcer.xml">mvn:org.opendaylight.openflowplugin.applications/table-miss-enforcer/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/table-miss-enforcer/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/69-table-miss-enforcer.xml">mvn:org.opendaylight.openflowplugin.applications/table-miss-enforcer/{{VERSION}}/xml/config</configfile>
</feature>
<feature name='odl-openflowplugin-app-config-pusher-li' description="OpenDaylight :: Openflow Plugin :: app - default config-pusher" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound-li</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/of-switch-config-pusher/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/70-of-switch-config-pusher.xml">mvn:org.opendaylight.openflowplugin.applications/of-switch-config-pusher/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/of-switch-config-pusher/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/70-of-switch-config-pusher.xml">mvn:org.opendaylight.openflowplugin.applications/of-switch-config-pusher/{{VERSION}}/xml/config</configfile>
</feature>
<feature name='odl-openflowplugin-app-lldp-speaker-li' description="OpenDaylight :: Openflow Plugin :: app lldp-speaker" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound-li</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/lldp-speaker/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/71-lldp-speaker.xml">mvn:org.opendaylight.openflowplugin.applications/lldp-speaker/${project.version}/xml/config</configfile>
- <configfile finalname="etc/opendaylight/karaf/72-topology-lldp-discovery.xml">mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/lldp-speaker/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/71-lldp-speaker.xml">mvn:org.opendaylight.openflowplugin.applications/lldp-speaker/{{VERSION}}/xml/config</configfile>
+ <configfile finalname="etc/opendaylight/karaf/72-topology-lldp-discovery.xml">mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/{{VERSION}}/xml/config</configfile>
</feature>
<feature name='odl-openflowplugin-app-bulk-o-matic-li' description="OpenDaylight :: Openflow Plugin :: app bulk flow operations support" version='${project.version}'>
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.openflowplugin</groupId>
- <artifactId>openflowplugin-parent</artifactId>
- <version>0.2.0-SNAPSHOT</version>
- <relativePath>../parent</relativePath>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>features-parent</artifactId>
+ <version>1.6.0-SNAPSHOT</version>
+ <relativePath/>
</parent>
- <artifactId>features-openflowplugin</artifactId>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>features-openflowplugin</artifactId>
<packaging>jar</packaging>
+ <version>0.2.0-SNAPSHOT</version>
<properties>
- <karaf.empty.distro.version>1.6.0-SNAPSHOT</karaf.empty.distro.version>
+ <yangtools.version>0.8.0-SNAPSHOT</yangtools.version>
+ <config.version>0.4.0-SNAPSHOT</config.version>
+ <mdsal.version>1.3.0-SNAPSHOT</mdsal.version>
+ <openflowjava.version>0.7.0-SNAPSHOT</openflowjava.version>
+ <openflowplugin.version>0.2.0-SNAPSHOT</openflowplugin.version>
+ <dlux.version>0.3.0-SNAPSHOT</dlux.version>
+ <lldp.version>0.10.0-SNAPSHOT</lldp.version>
+
<config.configfile.directory>etc/opendaylight/karaf</config.configfile.directory>
<config.statistics.manager.configfile>30-statistics-manager.xml</config.statistics.manager.configfile>
<config.inventory.manager.configfile>40-inventory-manager.xml</config.inventory.manager.configfile>
- <controller.model.version>1.3.0-SNAPSHOT</controller.model.version>
+ <restconf.version>1.3.0-SNAPSHOT</restconf.version>
+ <mdsal.model.version>0.8.0-SNAPSHOT</mdsal.model.version>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <!-- This project -->
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <artifactId>openflowplugin-artifacts</artifactId>
+ <version>${project.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- YANG tools -->
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-artifacts</artifactId>
+ <version>${yangtools.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- Controller infrastructure -->
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-artifacts</artifactId>
+ <version>${config.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>mdsal-artifacts</artifactId>
+ <version>${mdsal.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <!-- restconf -->
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
+ <artifactId>restconf-artifacts</artifactId>
+ <version>${restconf.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+
+ <!-- OpenFlowJava -->
+ <dependency>
+ <groupId>org.opendaylight.openflowjava</groupId>
+ <artifactId>openflowjava-artifacts</artifactId>
+ <version>${openflowjava.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<!-- feature dependencies -->
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>features-mdsal-model</artifactId>
+ <version>${mdsal.model.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>features-mdsal</artifactId>
- <version>${mdsal.version}</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>features-yangtools</artifactId>
<classifier>features</classifier>
- <version>${yangtools.version}</version>
<type>xml</type>
</dependency>
<dependency>
- <groupId>org.opendaylight.controller</groupId>
+ <groupId>org.opendaylight.netconf</groupId>
<artifactId>features-restconf</artifactId>
- <version>${mdsal.version}</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowjava</groupId>
<artifactId>features-openflowjava</artifactId>
- <version>${openflowjava.version}</version>
<classifier>features</classifier>
<type>xml</type>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>liblldp</artifactId>
- <version>${sal.api.version}</version>
+ <version>${lldp.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.openflowplugin</groupId>
<type>xml</type>
<classifier>config</classifier>
</dependency>
-
- <!-- test the features.xml -->
- <dependency>
- <groupId>org.opendaylight.odlparent</groupId>
- <artifactId>features-test</artifactId>
- </dependency>
- <!-- dependency for opendaylight-karaf-empty for use by testing -->
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>opendaylight-karaf-empty</artifactId>
- <version>${karaf.distro.empty.version}</version>
- <type>zip</type>
- </dependency>
</dependencies>
- <build>
- <resources>
- <resource>
- <filtering>true</filtering>
- <directory>src/main/resources</directory>
- </resource>
- </resources>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>filter</id>
- <goals>
- <goal>resources</goal>
- </goals>
- <phase>generate-resources</phase>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.outputDirectory}/features.xml</file>
- <type>xml</type>
- <classifier>features</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.16</version>
- <configuration>
- <systemPropertyVariables>
- <karaf.distro.groupId>org.opendaylight.controller</karaf.distro.groupId>
- <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId>
- <karaf.distro.version>${karaf.empty.distro.version}</karaf.distro.version>
- </systemPropertyVariables>
- <dependenciesToScan>
- <dependency>org.opendaylight.odlparent:features-test</dependency>
- </dependenciesToScan>
- </configuration>
- </plugin>
- </plugins>
- </build>
<scm>
<connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
<developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
<repository>mvn:org.opendaylight.controller/features-mdsal/${mdsal.version}/xml/features</repository>
- <repository>mvn:org.opendaylight.controller/features-restconf/${mdsal.version}/xml/features</repository>
+ <repository>mvn:org.opendaylight.netconf/features-restconf/${restconf.version}/xml/features</repository>
<repository>mvn:org.opendaylight.openflowjava/features-openflowjava/${openflowjava.version}/xml/features</repository>
<repository>mvn:org.opendaylight.dlux/features-dlux/${dlux.version}/xml/features</repository>
<repository>mvn:org.opendaylight.yangtools/features-yangtools/${yangtools.version}/xml/features</repository>
+ <repository>mvn:org.opendaylight.mdsal.model/features-mdsal-model/${mdsal.model.version}/xml/features</repository>
<feature name='odl-openflowplugin-all' description="OpenDaylight :: Openflow Plugin :: All" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound</feature>
<feature version="${mdsal.version}">odl-mdsal-broker</feature>
<feature version="${project.version}">odl-openflowplugin-nsf-model</feature>
<feature version="${openflowjava.version}">odl-openflowjava-protocol</feature>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-extension-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.controller/liblldp/${sal.api.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/inventory-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/statistics-manager/${project.version}</bundle>
- <configfile finalname="${config.configfile.directory}/${config.statistics.manager.configfile}">mvn:org.opendaylight.openflowplugin.applications/statistics-manager-config/${project.version}/xml/config</configfile>
- <configfile finalname="${config.configfile.directory}/${config.inventory.manager.configfile}">mvn:org.opendaylight.openflowplugin.applications/inventory-manager/${project.version}/xml/config</configfile>
- <configfile finalname="etc/opendaylight/karaf/42-openflowplugin-He.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-controller-config/${project.version}/xml/config-He</configfile>
- <configfile finalname="etc/opendaylight/karaf/43-msg-spy.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-controller-config/${project.version}/xml/configmsgspy</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-extension-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.controller/liblldp/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/inventory-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/statistics-manager/{{VERSION}}</bundle>
+ <configfile finalname="${config.configfile.directory}/${config.statistics.manager.configfile}">mvn:org.opendaylight.openflowplugin.applications/statistics-manager-config/{{VERSION}}/xml/config</configfile>
+ <configfile finalname="${config.configfile.directory}/${config.inventory.manager.configfile}">mvn:org.opendaylight.openflowplugin.applications/inventory-manager/{{VERSION}}/xml/config</configfile>
+ <configfile finalname="etc/opendaylight/karaf/42-openflowplugin-He.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-controller-config/{{VERSION}}/xml/config-He</configfile>
+ <configfile finalname="etc/opendaylight/karaf/43-msg-spy.xml">mvn:org.opendaylight.openflowplugin/openflowplugin-controller-config/{{VERSION}}/xml/configmsgspy</configfile>
</feature>
<feature name='odl-openflowplugin-flow-services' description="OpenDaylight :: Openflow Plugin :: Flow Services" version='${project.version}'>
description="OpenDaylight :: OpenflowPlugin :: NSF :: Services">
<feature version='${mdsal.version}'>odl-mdsal-broker</feature>
<feature version='${project.version}'>odl-openflowplugin-nsf-model</feature>
- <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.controller/liblldp/${sal.api.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/30-forwardingrules-manager.xml">mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager-config/${project.version}/xml/config</configfile>
- <configfile finalname="etc/opendaylight/karaf/72-topology-lldp-discovery.xml">mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/${project.version}/xml/config</configfile>
- <configfile finalname="etc/opendaylight/karaf/73-topology-manager.xml">mvn:org.opendaylight.openflowplugin.applications/topology-manager/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/openflowplugin-common/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.controller/liblldp/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/30-forwardingrules-manager.xml">mvn:org.opendaylight.openflowplugin.applications/forwardingrules-manager-config/{{VERSION}}/xml/config</configfile>
+ <configfile finalname="etc/opendaylight/karaf/72-topology-lldp-discovery.xml">mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/{{VERSION}}/xml/config</configfile>
+ <configfile finalname="etc/opendaylight/karaf/73-topology-manager.xml">mvn:org.opendaylight.openflowplugin.applications/topology-manager/{{VERSION}}/xml/config</configfile>
</feature>
<feature name='odl-openflowplugin-nsf-model' version='${project.version}'
description="OpenDaylight :: OpenflowPlugin :: NSF :: Model">
<!-- general models -->
- <feature version='${yangtools.version}'>odl-yangtools-models</feature>
- <bundle>mvn:org.opendaylight.controller.model/model-inventory/${controller.model.version}</bundle>
- <bundle>mvn:org.opendaylight.controller.model/model-topology/${controller.model.version}</bundle>
+ <feature version='${yangtools.version}'>odl-mdsal-models</feature>
+ <bundle>mvn:org.opendaylight.controller.model/model-inventory/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.controller.model/model-topology/{{VERSION}}</bundle>
<!-- openflow specific models -->
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-base/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-statistics/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-service/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-base/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-statistics/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.model/model-flow-service/{{VERSION}}</bundle>
</feature>
<feature name='odl-openflowplugin-flow-services-rest' description="OpenDaylight :: Openflow Plugin :: Flow Services :: REST" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-flow-services</feature>
- <feature version="${mdsal.version}">odl-restconf</feature>
+ <feature version="${restconf.version}">odl-restconf</feature>
</feature>
<feature name='odl-openflowplugin-flow-services-ui' description="OpenDaylight :: Openflow Plugin :: Flow Services :: UI" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-flow-services-rest</feature>
<feature version="${dlux.version}">odl-dlux-core</feature>
- <feature version="${mdsal.version}">odl-mdsal-apidocs</feature>
+ <feature version="${restconf.version}">odl-mdsal-apidocs</feature>
<feature version="${mdsal.version}">odl-mdsal-xsql</feature>
</feature>
<!-- CBENCH TESTING -->
<feature name='odl-openflowplugin-drop-test' description="OpenDaylight :: Openflow Plugin :: Drop Test" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-flow-services</feature>
- <bundle>mvn:org.opendaylight.openflowplugin/test-common/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin/drop-test-karaf/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/69-drop-test.xml">mvn:org.opendaylight.openflowplugin/drop-test-karaf/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin/test-common/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin/drop-test-karaf/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/69-drop-test.xml">mvn:org.opendaylight.openflowplugin/drop-test-karaf/{{VERSION}}/xml/config</configfile>
</feature>
<!-- APPLICATIONS -->
<feature name='odl-openflowplugin-app-table-miss-enforcer' description="OpenDaylight :: Openflow Plugin :: Application - table-miss-enforcer" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/table-miss-enforcer/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/69-table-miss-enforcer.xml">mvn:org.opendaylight.openflowplugin.applications/table-miss-enforcer/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/table-miss-enforcer/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/69-table-miss-enforcer.xml">mvn:org.opendaylight.openflowplugin.applications/table-miss-enforcer/{{VERSION}}/xml/config</configfile>
</feature>
<feature name='odl-openflowplugin-app-config-pusher' description="OpenDaylight :: Openflow Plugin :: app - default config-pusher" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/of-switch-config-pusher/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/70-of-switch-config-pusher.xml">mvn:org.opendaylight.openflowplugin.applications/of-switch-config-pusher/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/of-switch-config-pusher/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/70-of-switch-config-pusher.xml">mvn:org.opendaylight.openflowplugin.applications/of-switch-config-pusher/{{VERSION}}/xml/config</configfile>
</feature>
<feature name='odl-openflowplugin-app-lldp-speaker' description="OpenDaylight :: Openflow Plugin :: app lldp-speaker" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/lldp-speaker/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/71-lldp-speaker.xml">mvn:org.opendaylight.openflowplugin.applications/lldp-speaker/${project.version}/xml/config</configfile>
- <configfile finalname="etc/opendaylight/karaf/72-topology-lldp-discovery.xml">mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/lldp-speaker/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/71-lldp-speaker.xml">mvn:org.opendaylight.openflowplugin.applications/lldp-speaker/{{VERSION}}/xml/config</configfile>
+ <configfile finalname="etc/opendaylight/karaf/72-topology-lldp-discovery.xml">mvn:org.opendaylight.openflowplugin.applications/topology-lldp-discovery/{{VERSION}}/xml/config</configfile>
</feature>
<feature name='odl-openflowplugin-app-bulk-o-matic' description="OpenDaylight :: Openflow Plugin :: app bulk flow operations support" version='${project.version}'>
<feature version="${project.version}">odl-openflowplugin-southbound</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.applications/bulk-o-matic/${project.version}</bundle>
- <configfile finalname="etc/opendaylight/karaf/71-bulk-o-matic.xml">mvn:org.opendaylight.openflowplugin.applications/bulk-o-matic/${project.version}/xml/config</configfile>
+ <bundle>mvn:org.opendaylight.openflowplugin.applications/bulk-o-matic/{{VERSION}}</bundle>
+ <configfile finalname="etc/opendaylight/karaf/71-bulk-o-matic.xml">mvn:org.opendaylight.openflowplugin.applications/bulk-o-matic/{{VERSION}}/xml/config</configfile>
</feature>
</features>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>\r
-<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">\r
- <modelVersion>4.0.0</modelVersion>\r
- <parent>\r
- <groupId>org.opendaylight.openflowplugin.legacy</groupId>\r
- <artifactId>legacy-parent</artifactId>\r
- <version>0.2.0-SNAPSHOT</version>\r
- <relativePath>../</relativePath>\r
- </parent>\r
-\r
- <artifactId>features-legacy</artifactId>\r
- <packaging>jar</packaging>\r
- <properties>\r
- <features.file>features.xml</features.file>\r
- <feature.test.version>0.8.0-SNAPSHOT</feature.test.version>\r
- <sal.version>0.10.0-SNAPSHOT</sal.version>\r
- </properties>\r
- <dependencies>\r
- <!--\r
- Necessary TODO: Put dependencies on any feature repos\r
- you use in your features.xml file.\r
-\r
- Note: they will need to be <type>xml</xml>\r
- and <classifier>features</classifier>.\r
- One other thing to watch for is to make sure they are\r
- <scope>compile</compile>, which they should be by default,\r
- but be cautious lest they be at a different scope in a parent pom.\r
-\r
- Examples:\r
- <dependency>\r
- <groupId>org.opendaylight.yangtools</groupId>\r
- <artifactId>features-yangtools</artifactId>\r
- <version>0.8.0-SNAPSHOT</version>\r
- <classifier>features</classifier>\r
- <type>xml</type>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.opendaylight.controller</groupId>\r
- <artifactId>features-mdsal</artifactId>\r
- <version>1.3.0-SNAPSHOT</version>\r
- <classifier>features</classifier>\r
- <type>xml</type>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.opendaylight.openflowplugin</groupId>\r
- <artifactId>features-openflowplugin</artifactId>\r
- <version>0.2.0-SNAPSHOT</version>\r
- <classifier>features</classifier>\r
- <type>xml</type>\r
- </dependency>\r
- -->\r
- <dependency>\r
- <groupId>org.opendaylight.controller</groupId>\r
- <artifactId>features-mdsal</artifactId>\r
- <version>${mdsal.version}</version>\r
- <classifier>features</classifier>\r
- <type>xml</type>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.opendaylight.controller</groupId>\r
- <artifactId>features-adsal</artifactId>\r
- <version>${sal.version}</version>\r
- <classifier>features</classifier>\r
- <type>xml</type>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.opendaylight.openflowplugin</groupId>\r
- <artifactId>features-openflowplugin</artifactId>\r
- <classifier>features</classifier>\r
- <type>xml</type>\r
- </dependency>\r
-\r
- <!--\r
- Necessary TODO: Put dependencies for bundles directly referenced\r
- in your features.xml file. For every <bundle> reference in your\r
- features.xml file, you need a corresponding dependency here.\r
-\r
- Examples:\r
- <dependency>\r
- <groupId>org.opendaylight.controller</groupId>\r
- <artifactId>controller-provider</artifactId>\r
- <version>${project.version}</version>\r
- </dependency>\r
- <dependency>\r
- <groupId>org.opendaylight.controller</groupId>\r
- <artifactId>controller-model</artifactId>\r
- <version>${project.version}</version>\r
- </dependency>\r
- -->\r
- <dependency>\r
- <groupId>org.opendaylight.openflowplugin.legacy</groupId>\r
- <artifactId>sal-compatibility</artifactId>\r
- </dependency>\r
-\r
- <!--\r
- Necessary TODO: Put dependencies for configfiles directly referenced\r
- in your features.xml file. For every <configfile> reference in your\r
- features.xml file, you need a corresponding dependency here.\r
-\r
- Example (presuming here version is coming from the parent pom):\r
- <dependency>\r
- <groupId>org.opendaylight.controller</groupId>\r
- <artifactId>controller-config</artifactId>\r
- <version>${project.version}</version>\r
- <type>xml</type>\r
- <classifier>config</classifier>\r
- </dependency>\r
- -->\r
-\r
- <!--\r
- Optional TODO: Remove TODO comments.\r
- -->\r
- <!-- test to validate features.xml -->\r
- <dependency>\r
- <groupId>org.opendaylight.odlparent</groupId>\r
- <artifactId>features-test</artifactId>\r
- <scope>test</scope>\r
- </dependency>\r
- <!-- dependency for opendaylight-karaf-empty for use by testing -->\r
- <dependency>\r
- <groupId>org.opendaylight.controller</groupId>\r
- <artifactId>opendaylight-karaf-empty</artifactId>\r
- <version>${karaf.distro.empty.version}</version>\r
- <type>zip</type>\r
- </dependency>\r
- <!-- Uncomment this if you get an error : java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;\r
- <dependency>\r
- <groupId>org.slf4j</groupId>\r
- <artifactId>slf4j-simple</artifactId>\r
- <version>1.7.2</version>\r
- </dependency>\r
- -->\r
-\r
- </dependencies>\r
- <build>\r
- <resources>\r
- <resource>\r
- <directory>src/main/resources</directory>\r
- <filtering>true</filtering>\r
- </resource>\r
- </resources>\r
- <plugins>\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-resources-plugin</artifactId>\r
- <executions>\r
- <execution>\r
- <id>filter</id>\r
- <phase>generate-resources</phase>\r
- <goals>\r
- <goal>resources</goal>\r
- </goals>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- <plugin>\r
- <groupId>org.codehaus.mojo</groupId>\r
- <artifactId>build-helper-maven-plugin</artifactId>\r
- <executions>\r
- <execution>\r
- <id>attach-artifacts</id>\r
- <phase>package</phase>\r
- <goals>\r
- <goal>attach-artifact</goal>\r
- </goals>\r
- <configuration>\r
- <artifacts>\r
- <artifact>\r
- <file>${project.build.directory}/classes/${features.file}</file>\r
- <type>xml</type>\r
- <classifier>features</classifier>\r
- </artifact>\r
- </artifacts>\r
- </configuration>\r
- </execution>\r
- </executions>\r
- </plugin>\r
- <plugin>\r
- <groupId>org.apache.maven.plugins</groupId>\r
- <artifactId>maven-surefire-plugin</artifactId>\r
- <configuration>\r
- <systemPropertyVariables>\r
- <karaf.distro.groupId>org.opendaylight.controller</karaf.distro.groupId>\r
- <karaf.distro.artifactId>opendaylight-karaf-empty</karaf.distro.artifactId>\r
- <karaf.distro.version>${karaf.distro.empty.version}</karaf.distro.version>\r
- </systemPropertyVariables>\r
- <dependenciesToScan>\r
- <dependency>org.opendaylight.odlparent:features-test</dependency>\r
- </dependenciesToScan>\r
- </configuration>\r
- </plugin>\r
- </plugins>\r
- </build>\r
-\r
- <scm>\r
- <connection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</connection>\r
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</developerConnection>\r
- <url>https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin:Main</url>\r
- <tag>HEAD</tag>\r
- </scm>\r
-\r
-</project>\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
- Necessary TODO: Put your copyright statement here
-
- 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
--->
-<features name="openflowplugin-legacy-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
- <repository>mvn:org.opendaylight.controller/features-mdsal/${mdsal.version}/xml/features</repository>
- <repository>mvn:org.opendaylight.controller/features-adsal/${sal.version}/xml/features</repository>
- <repository>mvn:org.opendaylight.openflowplugin/features-openflowplugin/${project.version}/xml/features</repository>
-
- <feature name='odl-openflowplugin-adsal-compatibility-all' version='${project.version}' description='OpenDaylight :: openflowplugin :: All'>
- <feature version='${project.version}'>odl-openflowplugin-adsal-compatibility</feature>
- </feature>
-
- <feature name='odl-openflowplugin-adsal-compatibility' description="OpenDaylight :: openflowplugin :: AD-SAL Compatibility" version="${project.version}">
- <feature version="${mdsal.version}">odl-mdsal-broker</feature>
- <feature version="${project.version}">odl-openflowplugin-nsf-model</feature>
- <feature version="${sal.version}">odl-adsal-all</feature>
- <bundle>mvn:org.opendaylight.openflowplugin.legacy/sal-compatibility/${project.version}</bundle>
- </feature>
-</features>
+++ /dev/null
-<?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.openflowplugin</groupId>
- <artifactId>openflowplugin-parent</artifactId>
- <version>0.2.0-SNAPSHOT</version>
- <relativePath>../parent</relativePath>
- </parent>
- <groupId>org.opendaylight.openflowplugin.legacy</groupId>
- <artifactId>legacy-parent</artifactId>
- <packaging>pom</packaging>
- <name>MD-SAL to AD-SAL Adaptation Parent</name>
-
- <modules>
- <module>sal-compatibility</module>
- <module>features-legacy</module>
- </modules>
-
- <dependencies>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal</artifactId>
- <version>0.10.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-binding-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-common-util</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Bundle-Name>${project.name}</Bundle-Name>
- <Bundle-Activator>org.opendaylight.controller.sal.compability.ComponentActivator</Bundle-Activator>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <scm>
- <connection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</connection>
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</developerConnection>
- <url>https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin:Main</url>
- <tag>HEAD</tag>
- </scm>
-
-</project>
+++ /dev/null
-<?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.openflowplugin.legacy</groupId>
- <artifactId>legacy-parent</artifactId>
- <version>0.2.0-SNAPSHOT</version>
- <relativePath>../</relativePath>
- </parent>
- <artifactId>sal-compatibility</artifactId>
- <packaging>bundle</packaging>
- <name>MD-SAL to AD-SAL Adaptation</name>
-
- <dependencies>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>clustering.services</artifactId>
- <version>0.7.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-binding-util</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.openflowplugin.model</groupId>
- <artifactId>model-flow-statistics</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller.model</groupId>
- <artifactId>model-topology</artifactId>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <configuration>
- <instructions>
- <Bundle-Name>${project.name}</Bundle-Name>
- <Bundle-Activator>org.opendaylight.openflowplugin.legacy.sal.compatibility.ComponentActivator</Bundle-Activator>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <scm>
- <connection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</connection>
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/openflowplugin.git</developerConnection>
- <url>https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin:Main</url>
- <tag>HEAD</tag>
- </scm>
-
-</project>
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-
-public abstract class AbstractDataChangeListener <T extends DataObject> implements AutoCloseable,DataChangeListener{
-
- private static final Logger LOG = LoggerFactory.getLogger(AbstractDataChangeListener.class);
- protected InventoryAndReadAdapter adapter;
- protected final Class<T> clazz;
- protected ListenerRegistration<DataChangeListener> listenerRegistration;
-
- public AbstractDataChangeListener(final InventoryAndReadAdapter adapter, DataBroker db, final Class<T> clazz) {
- this.adapter = Preconditions.checkNotNull(adapter, "InventoryAndReadAdapter can not be null!");
- this.clazz = Preconditions.checkNotNull(clazz, "Class can not be null!");
- Preconditions.checkNotNull(db, "DataBroker can not be null!");
- registrationListener(db, 5);
- }
-
- @Override
- public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changeEvent) {
- Preconditions.checkNotNull(changeEvent,"Async ChangeEvent can not be null!");
- /* All DataObjects for create */
- final Map<InstanceIdentifier<?>, DataObject> createdData = changeEvent.getCreatedData() != null
- ? changeEvent.getCreatedData() : Collections.<InstanceIdentifier<?>, DataObject> emptyMap();
- /* All DataObjects for remove */
- final Set<InstanceIdentifier<?>> removeData = changeEvent.getRemovedPaths() != null
- ? changeEvent.getRemovedPaths() : Collections.<InstanceIdentifier<?>> emptySet();
- /* All DataObjects for updates */
- final Map<InstanceIdentifier<?>, DataObject> updateData = changeEvent.getUpdatedData() != null
- ? changeEvent.getUpdatedData() : Collections.<InstanceIdentifier<?>, DataObject> emptyMap();
- /* All Original DataObjects */
- final Map<InstanceIdentifier<?>, DataObject> originalData = changeEvent.getOriginalData() != null
- ? changeEvent.getOriginalData() : Collections.<InstanceIdentifier<?>, DataObject> emptyMap();
- this.createData(createdData);
- this.updateData(updateData, originalData);
- this.removeData(removeData, originalData);
- }
-
- @SuppressWarnings("unchecked")
- private void createData(final Map<InstanceIdentifier<?>, DataObject> createdData) {
- final Set<InstanceIdentifier<?>> keys = createdData.keySet() != null
- ? createdData.keySet() : Collections.<InstanceIdentifier<?>> emptySet();
- for (InstanceIdentifier<?> key : keys) {
- if (clazz.equals(key.getTargetType())) {
- InstanceIdentifier<T> createKeyIdent = key.firstIdentifierOf(clazz);
- final Optional<DataObject> value = Optional.of(createdData.get(key));
- if (value.isPresent()) {
- this.add(createKeyIdent, (T)value.get());
- }
- }
- }
- }
-
- abstract protected void add(InstanceIdentifier<T> createKeyIdent, T node);
-
- @SuppressWarnings("unchecked")
- private void updateData(final Map<InstanceIdentifier<?>, DataObject> updateData, final Map<InstanceIdentifier<?>, DataObject> originalData) {
-
- final Set<InstanceIdentifier<?>> keys = updateData.keySet() != null
- ? updateData.keySet() : Collections.<InstanceIdentifier<?>> emptySet();
- for (InstanceIdentifier<?> key : keys) {
- if (clazz.equals(key.getTargetType())) {
- InstanceIdentifier<T> updateKeyIdent = key.firstIdentifierOf(clazz);
- final Optional<DataObject> value = Optional.of(updateData.get(key));
- final Optional<DataObject> original = Optional.of(originalData.get(key));
- if (value.isPresent() && original.isPresent()) {
- this.update(updateKeyIdent, (T)original.get(), (T)value.get());
- }
- }
- }
- }
-
- abstract protected void update(InstanceIdentifier<T> updateKeyIdent, T node,
- T node2);
-
- @SuppressWarnings("unchecked")
- private void removeData(final Set<InstanceIdentifier<?>> removeData, final Map<InstanceIdentifier<?>, DataObject> originalData) {
-
- for (InstanceIdentifier<?> key : removeData) {
- if (clazz.equals(key.getTargetType())) {
- final InstanceIdentifier<T> ident = key.firstIdentifierOf(clazz);
- final DataObject removeValue = originalData.get(key);
- this.remove(ident, (T)removeValue);
- }
- }
- }
-
- abstract protected void remove(InstanceIdentifier<T> ident, T removeValue);
-
- protected void registrationListener(final DataBroker db, int i) {
- try {
- listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- getWildCardPath(), this, DataChangeScope.SUBTREE);
- } catch (final Exception e) {
- if (i >= 1) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e1) {
- LOG.error("Thread interrupted '{}'", e1);
- Thread.currentThread().interrupt();
- }
- registrationListener(db, --i);
- } else {
- LOG.error("AbstractDataChangeListener registration fail!", e);
- throw new IllegalStateException("AbstractDataChangeListener registration Listener fail! System needs restart.", e);
- }
- }
- }
-
- protected abstract InstanceIdentifier<?> getWildCardPath();
-
- @Override
- public void close() {
- if (listenerRegistration != null) {
- try {
- listenerRegistration.close();
- } catch (final Exception e) {
- LOG.error("Error by stop AbstractDataChangeListener.", e);
- }
- listenerRegistration = null;
- }
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import com.google.common.base.Preconditions;
-
-import org.apache.felix.dm.Component;
-import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
-import org.opendaylight.controller.sal.core.Node.NodeIDType;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
-import org.opendaylight.controller.sal.discovery.IDiscoveryService;
-import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
-import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
-import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
-import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
-import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
-import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
-import org.opendaylight.controller.sal.reader.IPluginInReadService;
-import org.opendaylight.controller.sal.reader.IPluginOutReadService;
-import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
-import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
-import org.opendaylight.controller.sal.utils.GlobalConstants;
-import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
-import org.opendaylight.controller.sal.utils.INodeFactory;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.adsal.DataPacketServiceAdapter;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyAdapter;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyProvider;
-import org.osgi.framework.BundleContext;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-public class ComponentActivator extends ComponentActivatorAbstractBase {
- private final INodeConnectorFactory nodeConnectorFactory = new MDSalNodeConnectorFactory();
- private final DataPacketServiceAdapter dataPacketService = new DataPacketServiceAdapter();
- private final InventoryAndReadAdapter inventory = new InventoryAndReadAdapter();
- private final FlowProgrammerAdapter flow = new FlowProgrammerAdapter();
- private final DataPacketAdapter dataPacket = new DataPacketAdapter();
- private final TopologyProvider tpProvider = new TopologyProvider();
- private final INodeFactory nodeFactory = new MDSalNodeFactory();
- private final TopologyAdapter topology = new TopologyAdapter();
- private BundleContext context;
-
- public INodeConnectorFactory getNodeConnectorFactory() {
- return nodeConnectorFactory;
- }
-
- public DataPacketServiceAdapter getDataPacketService() {
- return dataPacketService;
- }
-
- public InventoryAndReadAdapter getInventory() {
- return inventory;
- }
-
- public FlowProgrammerAdapter getFlow() {
- return flow;
- }
-
- public DataPacketAdapter getDataPacket() {
- return dataPacket;
- }
-
- public TopologyProvider getTpProvider() {
- return tpProvider;
- }
-
- public INodeFactory getNodeFactory() {
- return nodeFactory;
- }
-
- public TopologyAdapter getTopology() {
- return topology;
- }
-
- @Override
- protected void init() {
- // TODO: deprecated, should be removed soon
- NodeIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class);
- NodeConnectorIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class, NodeMapping.MD_SAL_TYPE);
- }
-
- @Override
- public void start(final BundleContext context) {
- this.context = Preconditions.checkNotNull(context);
- super.start(context);
- }
-
- public ProviderContext setBroker(final BindingAwareBroker broker) {
- return broker.registerProvider(new SalCompatibilityProvider(this), context);
- }
-
- @Override
- protected Object[] getGlobalImplementations() {
- return new Object[] {
- this, // Used for setBroker callback
- flow,
- inventory,
- dataPacket,
- nodeFactory,
- nodeConnectorFactory,
- topology,
- tpProvider
- };
- }
-
- @Override
- protected void configureGlobalInstance(final Component c, final Object imp) {
- if (imp instanceof DataPacketAdapter) {
- _configure((DataPacketAdapter)imp, c);
- } else if (imp instanceof FlowProgrammerAdapter) {
- _configure((FlowProgrammerAdapter)imp, c);
- } else if (imp instanceof InventoryAndReadAdapter) {
- _configure((InventoryAndReadAdapter)imp, c);
- } else if (imp instanceof ComponentActivator) {
- _configure((ComponentActivator)imp, c);
- } else if (imp instanceof MDSalNodeConnectorFactory) {
- _configure((MDSalNodeConnectorFactory)imp, c);
- } else if (imp instanceof MDSalNodeFactory) {
- _configure((MDSalNodeFactory)imp, c);
- } else if (imp instanceof TopologyAdapter) {
- _configure((TopologyAdapter)imp, c);
- } else if (imp instanceof TopologyProvider) {
- _configure((TopologyProvider)imp, c);
- } else {
- throw new IllegalArgumentException(String.format("Unhandled implementation class %s", imp.getClass()));
- }
- }
-
- @Override
- protected Object[] getImplementations() {
- return new Object[] {
- dataPacketService,
- inventory,
- };
- }
-
- @Override
- protected void configureInstance(final Component c, final Object imp, final String containerName) {
- if (imp instanceof ComponentActivator) {
- _instanceConfigure((ComponentActivator)imp, c, containerName);
- } else if (imp instanceof DataPacketServiceAdapter) {
- _instanceConfigure((DataPacketServiceAdapter)imp, c, containerName);
- } else if (imp instanceof InventoryAndReadAdapter) {
- _instanceConfigure((InventoryAndReadAdapter)imp, c, containerName);
- } else {
- throw new IllegalArgumentException(String.format("Unhandled implementation class %s", imp.getClass()));
- }
- }
-
- private void _configure(final MDSalNodeFactory imp, final Component it) {
- it.setInterface(INodeFactory.class.getName(), properties());
- }
-
- private void _configure(final MDSalNodeConnectorFactory imp, final Component it) {
- it.setInterface(INodeConnectorFactory.class.getName(), properties());
- }
-
- private void _configure(final ComponentActivator imp, final Component it) {
- it.add(createServiceDependency()
- .setService(BindingAwareBroker.class)
- .setCallbacks("setBroker", "setBroker")
- .setRequired(true));
- }
-
- private void _configure(final DataPacketAdapter imp, final Component it) {
- it.add(createServiceDependency()
- .setService(IPluginOutDataPacketService.class)
- .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher")
- .setRequired(false));
- }
-
- private void _configure(final FlowProgrammerAdapter imp, final Component it) {
- it.setInterface(IPluginInFlowProgrammerService.class.getName(), properties());
- it.add(createServiceDependency()
- .setService(IPluginOutFlowProgrammerService.class)
- .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher")
- .setRequired(false));
- it.add(createServiceDependency()
- .setService(IClusterGlobalServices.class)
- .setCallbacks("setClusterGlobalServices", "unsetClusterGlobalServices")
- .setRequired(false));
- }
-
- private void _instanceConfigure(final DataPacketServiceAdapter imp, final Component it, final String containerName) {
- it.setInterface(IPluginInDataPacketService.class.getName(), properties());
- }
-
- private void _instanceConfigure(final ComponentActivator imp, final Component it, final String containerName) {
- // No-op
- }
-
- private void _configure(final InventoryAndReadAdapter imp, final Component it) {
- it.setInterface(new String[] {
- IPluginInInventoryService.class.getName(),
- IPluginInReadService.class.getName(),
- }, properties());
-
- it.add(createServiceDependency()
- .setService(IPluginOutReadService.class)
- .setCallbacks("setReadPublisher", "unsetReadPublisher")
- .setRequired(false));
- it.add(createServiceDependency()
- .setService(IPluginOutInventoryService.class)
- .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher")
- .setRequired(false));
- it.add(createServiceDependency()
- .setService(IDiscoveryService.class)
- .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher")
- .setRequired(false));
- it.add(createServiceDependency()
- .setService(BindingAwareBroker.class)
- .setRequired(true));
- }
-
- private void _instanceConfigure(final InventoryAndReadAdapter imp, final Component it, String containerName) {
- it.setInterface(new String[] {
- IPluginInInventoryService.class.getName(),
- IPluginInReadService.class.getName(),
- }, properties());
-
- it.add(createServiceDependency()
- .setService(IPluginOutReadService.class)
- .setCallbacks("setReadPublisher", "unsetReadPublisher")
- .setRequired(false));
- it.add(createServiceDependency()
- .setService(IPluginOutInventoryService.class)
- .setCallbacks("setInventoryPublisher", "unsetInventoryPublisher")
- .setRequired(false));
- it.add(createServiceDependency()
- .setService(BindingAwareBroker.class)
- .setRequired(true));
- }
-
- private void _configure(final TopologyAdapter imp, final Component it) {
- it.setInterface(IPluginInTopologyService.class.getName(), properties());
-
- it.add(createServiceDependency()
- .setService(IPluginOutTopologyService.class)
- .setCallbacks("setTopologyPublisher", "setTopologyPublisher")
- .setRequired(false));
- }
-
- private void _configure(final TopologyProvider imp, final Component it) {
- it.add(createServiceDependency()
- .setService(IPluginOutTopologyService.class)
- .setCallbacks("setTopologyPublisher", "setTopologyPublisher")
- .setRequired(false));
- }
-
- private Dictionary<String,Object> properties() {
- final Hashtable<String,Object> props = new Hashtable<String, Object>();
- props.put(GlobalConstants.PROTOCOLPLUGINTYPE.toString(), NodeIDType.OPENFLOW);
- props.put("protocolName", NodeIDType.OPENFLOW);
- return props;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService;
-import org.opendaylight.controller.sal.packet.RawPacket;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-class DataPacketAdapter implements PacketProcessingListener {
- private static final Logger LOG = LoggerFactory.getLogger(DataPacketAdapter.class);
-
- // These are injected via Apache DM (see ComponentActivator)
- private IPluginOutDataPacketService dataPacketPublisher;
-
- @Override
- public void onPacketReceived(final PacketReceived packet) {
- try {
- RawPacket inPacket = toRawPacket(packet);
- if (dataPacketPublisher != null) {
- dataPacketPublisher.receiveDataPacket(inPacket);
- } else {
- LOG.warn("IPluginOutDataPacketService is not available. Not forwarding packet to AD-SAL.");
- }
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct raw packet from {}, dropping it", packet, e);
- }
- }
-
- public static RawPacket toRawPacket(final PacketReceived received) throws ConstructionException {
- final RawPacket ret = new RawPacket(received.getPayload());
- ret.setIncomingNodeConnector(NodeMapping.toADNodeConnector(received.getIngress()));
- return ret;
- }
-
- public IPluginOutDataPacketService getDataPacketPublisher() {
- return dataPacketPublisher;
- }
-
- // These are injected via Apache DM (see ComponentActivator)
- public void setDataPacketPublisher(final IPluginOutDataPacketService dataPacketPublisher) {
- this.dataPacketPublisher = dataPacketPublisher;
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import java.util.EnumSet;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import org.opendaylight.controller.clustering.services.CacheConfigException;
-import org.opendaylight.controller.clustering.services.CacheExistException;
-import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
-import org.opendaylight.controller.clustering.services.IClusterServices.cacheMode;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.flowprogrammer.Flow;
-import org.opendaylight.controller.sal.flowprogrammer.IPluginInFlowProgrammerService;
-import org.opendaylight.controller.sal.flowprogrammer.IPluginOutFlowProgrammerService;
-import org.opendaylight.controller.sal.utils.Status;
-import org.opendaylight.controller.sal.utils.StatusCode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeExperimenterErrorNotification;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FlowProgrammerAdapter implements IPluginInFlowProgrammerService, SalFlowListener {
- private final static Logger LOG = LoggerFactory.getLogger(FlowProgrammerAdapter.class);
-
- // Note: clustering services manipulate this
- private final Map<Flow, UUID> flowToFlowId = new ConcurrentHashMap<Flow, UUID>();
- private final static String CACHE_NAME = "flowprogrammeradapter.flowtoid";
-
- // These are injected via Apache DM (see ComponentActivator)
- private IPluginOutFlowProgrammerService flowProgrammerPublisher;
- private IClusterGlobalServices clusterGlobalServices;
- private DataBrokerService dataBrokerService;
- private SalFlowService delegate;
-
- public SalFlowService getDelegate() {
- return this.delegate;
- }
-
- public void setDelegate(final SalFlowService delegate) {
- this.delegate = delegate;
- }
-
- public DataBrokerService getDataBrokerService() {
- return this.dataBrokerService;
- }
-
- public void setDataBrokerService(final DataBrokerService dataBrokerService) {
- this.dataBrokerService = dataBrokerService;
- }
-
- public IPluginOutFlowProgrammerService getFlowProgrammerPublisher() {
- return this.flowProgrammerPublisher;
- }
-
- public void setFlowProgrammerPublisher(final IPluginOutFlowProgrammerService flowProgrammerPublisher) {
- this.flowProgrammerPublisher = flowProgrammerPublisher;
- }
-
- public IClusterGlobalServices getClusterGlobalServices() {
- return this.clusterGlobalServices;
- }
-
- public void setClusterGlobalServices(final IClusterGlobalServices clusterGlobalServices) {
- this.clusterGlobalServices = clusterGlobalServices;
- }
-
- @Override
- public Status addFlow(final Node node, final Flow flow) {
- return toFutureStatus(internalAddFlowAsync(node, flow, 0));
- }
-
- @Override
- public Status modifyFlow(final Node node, final Flow oldFlow, final Flow newFlow) {
- return toFutureStatus(internalModifyFlowAsync(node, oldFlow, newFlow, 0));
- }
-
- @Override
- public Status removeFlow(final Node node, final Flow flow) {
- return toFutureStatus(internalRemoveFlowAsync(node, flow, 0));
- }
-
- @Override
- public Status addFlowAsync(final Node node, final Flow flow, final long rid) {
- // FIXME is this correct? What if the future fails?
- this.internalAddFlowAsync(node, flow, rid);
- return FlowProgrammerAdapter.toStatus(true);
- }
-
- @Override
- public Status modifyFlowAsync(final Node node, final Flow oldFlow, final Flow newFlow, final long rid) {
- // FIXME is this correct? What if the future fails?
- this.internalModifyFlowAsync(node, oldFlow, newFlow, rid);
- return FlowProgrammerAdapter.toStatus(true);
- }
-
- @Override
- public Status removeFlowAsync(final Node node, final Flow flow, final long rid) {
- // FIXME is this correct? What if the future fails?
- this.internalRemoveFlowAsync(node, flow, rid);
- return FlowProgrammerAdapter.toStatus(true);
- }
-
- @Override
- public Status removeAllFlows(final Node node) {
- // FIXME: unfinished?
- return new Status(StatusCode.SUCCESS);
- }
-
- @Override
- public Status syncSendBarrierMessage(final Node node) {
- // FIXME: unfinished?
- return null;
- }
-
- @Override
- public Status asyncSendBarrierMessage(final Node node) {
- // FIXME: unfinished?
- return null;
- }
-
- private static Status toStatus(final boolean successful) {
- return new Status(successful ? StatusCode.SUCCESS : StatusCode.INTERNALERROR);
- }
-
- public static Status toStatus(final RpcResult<? extends Object> result) {
- return toStatus(result.isSuccessful());
- }
-
- @Override
- public void onFlowAdded(final FlowAdded notification) {
- // FIXME: unfinished?
- }
-
- @Override
- public void onFlowRemoved(final FlowRemoved notification) {
- // notified upon remove flow rpc successfully invoked
- if (notification == null) {
- return;
- }
-
- final NodeRef node = notification.getNode();
- if (node == null) {
- LOG.debug("Notification {} has not node, ignoring it", notification);
- return;
- }
-
- Node adNode;
- try {
- adNode = NodeMapping.toADNode(notification.getNode());
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct AD node for {}, ignoring notification", node, e);
- return;
- }
- flowProgrammerPublisher.flowRemoved(adNode, ToSalConversionsUtils.toFlow(notification, adNode));
- }
-
- @Override
- public void onFlowUpdated(final FlowUpdated notification) {
- // FIXME: unfinished?
- }
-
- @Override
- public void onSwitchFlowRemoved(final SwitchFlowRemoved notification) {
- // notified upon remove flow message from device arrives
- if (notification == null) {
- return;
- }
-
- final NodeRef node = notification.getNode();
- if (node == null) {
- LOG.debug("Notification {} has not node, ignoring it", notification);
- return;
- }
-
- Node adNode;
- try {
- adNode = NodeMapping.toADNode(notification.getNode());
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct AD node for {}, ignoring notification", node, e);
- return;
- }
- flowProgrammerPublisher.flowRemoved(adNode, ToSalConversionsUtils.toFlow(notification, adNode));
- }
-
- @Override
- public void onNodeErrorNotification(final NodeErrorNotification notification) {
- // FIXME: unfinished?
- }
-
- @Override
- public void onNodeExperimenterErrorNotification(final NodeExperimenterErrorNotification notification) {
- // FIXME: unfinished?
- }
-
- private static final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow> flowPath(
- final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow flow, final NodeKey nodeKey) {
- return InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, nodeKey)
- .augmentation(FlowCapableNode.class)
- .child(Table.class, new TableKey(flow.getTableId()))
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow.class, new FlowKey(flow.getId()))
- .toInstance();
- }
-
- private Future<RpcResult<TransactionStatus>> writeFlowAsync(final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow flow, final NodeKey nodeKey) {
- final DataModificationTransaction modification = this.dataBrokerService.beginTransaction();
- modification.putConfigurationData(flowPath(flow, nodeKey), flow);
- return modification.commit();
- }
-
- private Future<RpcResult<TransactionStatus>> internalAddFlowAsync(final Node node, final Flow flow, final long rid) {
- final Map<Flow,UUID> cache = this.getCache();
- UUID flowId = cache.get(flow);
- if (flowId != null) {
- this.removeFlow(node, flow);
- }
-
- flowId = UUID.randomUUID();
- cache.put(flow, flowId);
- return this.writeFlowAsync(MDFlowMapping.toMDFlow(flow, flowId.toString()), new NodeKey(
- new NodeId(NodeMapping.OPENFLOW_ID_PREFIX + node.getID())));
- }
-
- private Future<RpcResult<TransactionStatus>> internalModifyFlowAsync(final Node node, final Flow oldFlow, final Flow newFlow, final long rid) {
- final Map<Flow,UUID> cache = this.getCache();
-
- UUID flowId = cache.remove(oldFlow);
- if (flowId == null) {
- flowId = UUID.randomUUID();
- cache.put(oldFlow, flowId);
- LOG.warn("Could not find flow {} in cache, assigned new ID {}", oldFlow.hashCode(), flowId);
- }
-
- cache.put(newFlow, flowId);
- return this.writeFlowAsync(MDFlowMapping.toMDFlow(newFlow, flowId.toString()), new NodeKey(
- new NodeId(NodeMapping.OPENFLOW_ID_PREFIX + node.getID())));
- }
-
- private Future<RpcResult<TransactionStatus>> internalRemoveFlowAsync(final Node node, final Flow adflow, final long rid) {
- final Map<Flow,UUID> cache = this.getCache();
-
- final UUID flowId = cache.remove(adflow);
- if (flowId == null) {
- LOG.warn("Could not find flow {} in cache, nothing to do", adflow.hashCode());
- return null;
- }
-
- final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow flow = MDFlowMapping.toMDFlow(adflow, flowId.toString());
- final DataModificationTransaction modification = this.dataBrokerService.beginTransaction();
- modification.removeConfigurationData(flowPath(flow, new NodeKey(
- new NodeId(NodeMapping.OPENFLOW_ID_PREFIX + node.getID()))));
- return modification.commit();
- }
-
- private static Status toFutureStatus(final Future<RpcResult<TransactionStatus>> future) {
- if (future == null) {
- // FIXME: really?
- return FlowProgrammerAdapter.toStatus(true);
- }
-
- try {
- final RpcResult<TransactionStatus> result = future.get();
- return FlowProgrammerAdapter.toStatus(result);
- } catch (final InterruptedException e) {
- FlowProgrammerAdapter.LOG.error("Interrupted while processing flow", e);
- } catch (ExecutionException e) {
- FlowProgrammerAdapter.LOG.error("Failed to process flow", e);
- }
-
- return new Status(StatusCode.INTERNALERROR);
- }
-
- @SuppressWarnings("unchecked")
- private Map<Flow,UUID> getCache() {
- final IClusterGlobalServices cgs = getClusterGlobalServices();
- if (cgs == null) {
- return new ConcurrentHashMap<Flow, UUID>();
- }
-
- Map<Flow, UUID> cache = (Map<Flow, UUID>) cgs.getCache(FlowProgrammerAdapter.CACHE_NAME);
- if (cache != null) {
- return cache;
- }
-
- try {
- return (Map<Flow, UUID>) cgs.createCache(CACHE_NAME, EnumSet.of(cacheMode.TRANSACTIONAL));
- } catch (CacheExistException e) {
- return (Map<Flow, UUID>) cgs.getCache(CACHE_NAME);
- } catch (CacheConfigException e) {
- throw new IllegalStateException("Unexpected cache configuration problem", e);
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import static org.opendaylight.controller.sal.match.MatchType.DL_DST;
-import static org.opendaylight.controller.sal.match.MatchType.DL_SRC;
-import static org.opendaylight.controller.sal.match.MatchType.DL_TYPE;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.CRUDP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.ETHERNET_ARP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.TCP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.UDP;
-
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.match.Match;
-import org.opendaylight.controller.sal.match.MatchField;
-import org.opendaylight.controller.sal.match.MatchType;
-import org.opendaylight.controller.sal.utils.NetUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
-
-import com.google.common.net.InetAddresses;
-
-/**
- * MD-SAL to AD-SAL conversions collection
- */
-public final class FromSalConversionsUtils {
-
- /** http://en.wikipedia.org/wiki/IPv4#Packet_structure (end of octet number 1, bit 14.+15.) */
- public static final int ENC_FIELD_BIT_SIZE = 2;
-
- private FromSalConversionsUtils() {
- throw new IllegalAccessError("forcing no instance for factory");
- }
-
- @SuppressWarnings("unused")
- private static Address addressFromAction(InetAddress inetAddress) {
- String strInetAddresss = InetAddresses.toAddrString(inetAddress);
- if (inetAddress instanceof Inet4Address) {
- Ipv4Builder ipv4Builder = new Ipv4Builder();
- ipv4Builder.setIpv4Address(new Ipv4Prefix(strInetAddresss));
- return ipv4Builder.build();
- } else if (inetAddress instanceof Inet6Address) {
- Ipv6Builder ipv6Builder = new Ipv6Builder();
- ipv6Builder.setIpv6Address(new Ipv6Prefix(strInetAddresss));
- return ipv6Builder.build();
- }
- return null;
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match toMatch(
- Match sourceMatch) {
- if (sourceMatch != null) {
- MatchBuilder targetBuilder = new MatchBuilder();
-
- targetBuilder.setEthernetMatch(ethernetMatch(sourceMatch));
- targetBuilder.setIpMatch(ipMatch(sourceMatch));
- targetBuilder.setVlanMatch(vlanMatch(sourceMatch));
- targetBuilder.setLayer3Match(layer3Match(sourceMatch));
- targetBuilder.setLayer4Match(layer4Match(sourceMatch));
- targetBuilder.setInPort(inPortMatch(sourceMatch));
-
- return targetBuilder.build();
- }
- return null;
-
- }
-
- private static NodeConnectorId inPortMatch(Match sourceMatch) {
- MatchField inPort = sourceMatch.getField(MatchType.IN_PORT);
- if(inPort != null && inPort.getValue() != null && (inPort.getValue() instanceof NodeConnector)) {
- NodeConnector port = (NodeConnector)inPort.getValue();
- return (NodeConnectorId)MDFlowMapping.toUri(port);
- }
- return null;
- }
-
- private static Layer4Match layer4Match(final Match sourceMatch) {
- MatchField nwProto = sourceMatch.getField(MatchType.NW_PROTO);
- Short nwProtocolSource = null;
- if (nwProto != null && nwProto.getValue() != null) {
- nwProtocolSource = (short) ((byte) nwProto.getValue());
- switch (nwProtocolSource) {
- case TCP:
- return Layer4MatchAsTcp(sourceMatch);
- case UDP:
- return Layer4MatchAsUdp(sourceMatch);
- case CRUDP:
- return Layer4MatchAsSctp(sourceMatch);
- }
- }
- return null;
- }
-
- private static Layer4Match Layer4MatchAsSctp(final Match sourceMatch) {
- SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
-
- Integer sourcePort = transportPort(sourceMatch, MatchType.TP_SRC);
- Integer destinationPort = transportPort(sourceMatch,
- MatchType.TP_DST);
-
- if (sourcePort != null) {
- sctpMatchBuilder.setSctpSourcePort(new PortNumber(sourcePort));
- }
- if (destinationPort != null) {
- sctpMatchBuilder.setSctpDestinationPort(new PortNumber(
- destinationPort));
- }
- if(sourcePort != null || destinationPort != null) {
- return sctpMatchBuilder.build();
- }
- return null;
- }
-
- private static Layer4Match Layer4MatchAsUdp(final Match sourceMatch) {
- UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
-
- Integer sourcePort = transportPort(sourceMatch, MatchType.TP_SRC);
- Integer destinationPort = transportPort(sourceMatch,
- MatchType.TP_DST);
-
- if (sourcePort != null) {
- udpMatchBuilder.setUdpSourcePort(new PortNumber(sourcePort));
- }
-
- if (destinationPort != null) {
- udpMatchBuilder.setUdpDestinationPort(new PortNumber(
- destinationPort));
- }
- if(sourcePort != null || destinationPort != null) {
- return udpMatchBuilder.build();
- }
- return null;
- }
-
- private static Layer4Match Layer4MatchAsTcp(final Match sourceMatch) {
- TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
-
- Integer sourcePort = transportPort(sourceMatch, MatchType.TP_SRC);
- Integer destinationPort = transportPort(sourceMatch,
- MatchType.TP_DST);
-
- if (sourcePort != null) {
- tcpMatchBuilder.setTcpSourcePort(new PortNumber(sourcePort));
- }
- if (destinationPort != null) {
- tcpMatchBuilder.setTcpDestinationPort(new PortNumber(
- destinationPort));
- }
- if(sourcePort != null || destinationPort != null) {
- return tcpMatchBuilder.build();
- }
- return null;
- }
-
- private static Integer transportPort(final Match sourceMatch,
- final MatchType matchType) {
- MatchField transportPort = sourceMatch.getField(matchType);
- if (transportPort != null && transportPort.getValue() != null
- && transportPort.getValue().getClass().equals(Short.class)) {
- return NetUtils.getUnsignedShort((short) transportPort.getValue());
- }
- return null;
- }
-
- private static VlanMatch vlanMatch(final Match sourceMatch) {
- VlanMatchBuilder vlanMatchBuild = new VlanMatchBuilder();
-
- MatchField vlan = sourceMatch.getField(MatchType.DL_VLAN);
- if (vlan != null && vlan.getValue() != null) {
- VlanIdBuilder vlanIDBuilder = new VlanIdBuilder();
- short vid = (short)vlan.getValue();
- boolean present = (vid != MatchType.DL_VLAN_NONE);
- vlanIDBuilder.setVlanId(new VlanId((NetUtils
- .getUnsignedShort(vid))));
- vlanIDBuilder.setVlanIdPresent(present);
- vlanMatchBuild.setVlanId(vlanIDBuilder.build());
- }
-
- MatchField vlanPriority = sourceMatch.getField(MatchType.DL_VLAN_PR);
- if (vlanPriority != null && vlanPriority.getValue() != null) {
- vlanMatchBuild.setVlanPcp(new VlanPcp((short) ((byte) vlanPriority
- .getValue())));
- }
- if((vlan != null && vlan.getValue() != null) || (vlanPriority != null && vlanPriority.getValue() != null)) {
- return vlanMatchBuild.build();
- }
- return null;
- }
-
- private static IpMatch ipMatch(final Match sourceMatch) {
- IpMatchBuilder targetIpMatchBuild = new IpMatchBuilder();
- MatchField networkTos = sourceMatch.getField(MatchType.NW_TOS);
- if (networkTos != null && networkTos.getValue() != null) {
- Dscp dscp = new Dscp(
- (short) (NetUtils.getUnsignedByte((Byte) networkTos
- .getValue())));
- targetIpMatchBuild.setIpDscp(dscp);
- }
-
- MatchField protocol = sourceMatch.getField(MatchType.NW_PROTO);
- if (protocol != null && protocol.getValue() != null) {
- targetIpMatchBuild.setIpProtocol((short) ((byte) protocol
- .getValue()));
- }
- if((networkTos != null && networkTos.getValue() != null) || (protocol != null && protocol.getValue() != null)) {
- return targetIpMatchBuild.build();
- }
- return null;
- }
-
- private static EthernetMatch ethernetMatch(final Match sourceMatch) {
- final EthernetMatchBuilder targetEthMatchBuild = new EthernetMatchBuilder();
- if(sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) {
- EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder()
- .setAddress(ethernetSourceAddress(sourceMatch));
- targetEthMatchBuild.setEthernetSource(ethSourBuild.build());
- }
- if(sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null) {
- EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder()
- .setAddress(ethernetDestAddress(sourceMatch));
- targetEthMatchBuild.setEthernetDestination(ethDestBuild.build());
- }
-
- final MatchField dataLinkType = sourceMatch.getField(MatchType.DL_TYPE);
- if (dataLinkType != null && dataLinkType.getValue() != null) {
- EtherType etherType = new EtherType((long) NetUtils.getUnsignedShort((Short) dataLinkType.getValue()));
- EthernetTypeBuilder ethType = new EthernetTypeBuilder()
- .setType(etherType);
- targetEthMatchBuild.setEthernetType(ethType.build());
- }
- if((sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) ||
- (sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null)||
- dataLinkType != null ) {
- return targetEthMatchBuild.build();
- }
- return null;
- }
-
- private static MacAddress ethernetSourceAddress(final Match sourceMatch) {
- final MatchField dataLinkSource = sourceMatch.getField(DL_SRC);
- if (dataLinkSource != null && dataLinkSource.getValue() != null) {
- return MDFlowMapping.toMacAddress((byte[])dataLinkSource.getValue());
- }
- return null;
-
- }
-
- private static Layer3Match layer3Match(final Match sourceMatch) {
- InetAddress inetSourceAddress = null;
- MatchField netSource = sourceMatch.getField(MatchType.NW_SRC);
- if (netSource != null && netSource.getValue() != null) {
- inetSourceAddress = (InetAddress) (netSource.getValue());
- }
-
- InetAddress inetDestAddress = null;
- MatchField netDest = sourceMatch.getField(MatchType.NW_DST);
- if (netDest != null && netDest.getValue() != null) {
- inetDestAddress = (InetAddress) (netDest.getValue());
- }
-
- if ((inetSourceAddress instanceof Inet4Address)
- || (inetDestAddress instanceof Inet4Address)) {
- MatchField dataLinkType = sourceMatch.getField(DL_TYPE);
- Short dLType = null;
- if (dataLinkType != null && dataLinkType.getValue() != null) {
- dLType = (Short) (dataLinkType.getValue());
- }
- if (dLType != null && dLType.equals(ETHERNET_ARP)) {
- return setLayer3MatchAsArp(sourceMatch,
- (Inet4Address) inetSourceAddress,
- (Inet4Address) inetDestAddress);
- } else {
- return setLayer3MatchAsIpv4((Inet4Address) inetSourceAddress,
- (Inet4Address) inetDestAddress);
- }
- } else if ((inetSourceAddress instanceof Inet6Address)
- || (inetDestAddress instanceof Inet6Address)) {
- return setLayer3MatchAsIpv6((Inet6Address) inetSourceAddress,
- (Inet6Address) inetDestAddress);
- }
-
- return null;
-
- }
-
- private static Layer3Match setLayer3MatchAsArp(final Match sourceMatch,
- final Inet4Address inetSourceAddress,
- final Inet4Address inetDestAddress) {
- String inetSourceAddressStr = InetAddresses
- .toAddrString(inetSourceAddress);
- Ipv4Prefix ipv4SourcePrefix = new Ipv4Prefix(inetSourceAddressStr + "/32");
-
- String inetDestAddressValue = InetAddresses
- .toAddrString(inetDestAddress);
- Ipv4Prefix ipv4DestPrefix = new Ipv4Prefix(inetDestAddressValue + "/32");
-
- ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
-
- arpMatchBuilder.setArpSourceTransportAddress(ipv4SourcePrefix);
- arpMatchBuilder.setArpTargetTransportAddress(ipv4DestPrefix);
-
- ArpSourceHardwareAddressBuilder arpSourceHardwareAddressBuilder = new ArpSourceHardwareAddressBuilder();
- arpSourceHardwareAddressBuilder
- .setAddress(ethernetSourceAddress(sourceMatch));
- arpMatchBuilder
- .setArpSourceHardwareAddress(arpSourceHardwareAddressBuilder
- .build());
-
- ArpTargetHardwareAddressBuilder arpTargetHardwareAddressBuilder = new ArpTargetHardwareAddressBuilder();
- arpTargetHardwareAddressBuilder
- .setAddress(ethernetDestAddress(sourceMatch));
- arpMatchBuilder
- .setArpTargetHardwareAddress(arpTargetHardwareAddressBuilder
- .build());
-
- return arpMatchBuilder.build();
-
- }
-
- private static MacAddress ethernetDestAddress(final Match sourceMatch) {
- final MatchField dataLinkDest = sourceMatch.getField(DL_DST);
- if (dataLinkDest != null && dataLinkDest.getValue() != null) {
- return MDFlowMapping.toMacAddress((byte[]) dataLinkDest.getValue());
- }
- return null;
- }
-
- private static Layer3Match setLayer3MatchAsIpv4(
- final Inet4Address inetSourceAddress,
- final Inet4Address inetDestAddress) {
- Ipv4MatchBuilder layer4MatchBuild = new Ipv4MatchBuilder();
- if(inetSourceAddress != null) {
- String inetSrcAddressString = InetAddresses
- .toAddrString(inetSourceAddress);
- layer4MatchBuild.setIpv4Source(new Ipv4Prefix(inetSrcAddressString + "/32"));
- }
- if(inetDestAddress != null) {
- String inetDstAddressString = InetAddresses
- .toAddrString(inetDestAddress);
- layer4MatchBuild
- .setIpv4Destination(new Ipv4Prefix(inetDstAddressString + "/32"));
- }
- return layer4MatchBuild.build();
-
- }
-
- private static Layer3Match setLayer3MatchAsIpv6(
- final Inet6Address inetSourceAddress,
- final Inet6Address inetDestAddress) {
- Ipv6MatchBuilder layer6MatchBuild = new Ipv6MatchBuilder();
- if(inetSourceAddress != null) {
- String inetSrcAddressString = InetAddresses
- .toAddrString(inetSourceAddress);
- layer6MatchBuild.setIpv6Source(new Ipv6Prefix(inetSrcAddressString + "/128"));
- }
- if(inetDestAddress != null) {
- String inetDstAddressString = InetAddresses
- .toAddrString(inetDestAddress);
- layer6MatchBuild
- .setIpv6Destination(new Ipv6Prefix(inetDstAddressString + "/128"));
- }
- return layer6MatchBuild.build();
- }
-
- public static boolean flowEquals(Flow statsFlow, Flow storedFlow) {
- if (statsFlow.getClass() != storedFlow.getClass()) {
- return false;
- }
- if (statsFlow.getBufferId()== null) {
- if (storedFlow.getBufferId() != null) {
- return false;
- }
- } else if(!statsFlow.getBufferId().equals(storedFlow.getBufferId())) {
- return false;
- }
- if (statsFlow.getContainerName()== null) {
- if (storedFlow.getContainerName()!= null) {
- return false;
- }
- } else if(!statsFlow.getContainerName().equals(storedFlow.getContainerName())) {
- return false;
- }
- if (statsFlow.getCookie()== null) {
- if (storedFlow.getCookie()!= null) {
- return false;
- }
- } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
- return false;
- }
- if (statsFlow.getMatch()== null) {
- if (storedFlow.getMatch() != null) {
- return false;
- }
- } else if(!statsFlow.getMatch().equals(storedFlow.getMatch())) {
- return false;
- }
- if (statsFlow.getCookie()== null) {
- if (storedFlow.getCookie()!= null) {
- return false;
- }
- } else if(!statsFlow.getCookie().equals(storedFlow.getCookie())) {
- return false;
- }
- if (statsFlow.getHardTimeout() == null) {
- if (storedFlow.getHardTimeout() != null) {
- return false;
- }
- } else if(!statsFlow.getHardTimeout().equals(storedFlow.getHardTimeout() )) {
- return false;
- }
- if (statsFlow.getIdleTimeout()== null) {
- if (storedFlow.getIdleTimeout() != null) {
- return false;
- }
- } else if(!statsFlow.getIdleTimeout().equals(storedFlow.getIdleTimeout())) {
- return false;
- }
- if (statsFlow.getPriority() == null) {
- if (storedFlow.getPriority() != null) {
- return false;
- }
- } else if(!statsFlow.getPriority().equals(storedFlow.getPriority())) {
- return false;
- }
- if (statsFlow.getTableId() == null) {
- if (storedFlow.getTableId() != null) {
- return false;
- }
- } else if(!statsFlow.getTableId().equals(storedFlow.getTableId())) {
- return false;
- }
- return true;
- }
-
- /**
- * @param nwDscp NW-DSCP
- * @return shifted to NW-TOS (with empty ECN part)
- */
- public static int dscpToTos(int nwDscp) {
- return (short) (nwDscp << ENC_FIELD_BIT_SIZE);
- }
-
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
-import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
-import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Edge;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.NodeTable;
-import org.opendaylight.controller.sal.core.NodeTable.NodeTableIDType;
-import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.core.UpdateType;
-import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
-import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
-import org.opendaylight.controller.sal.reader.FlowOnNode;
-import org.opendaylight.controller.sal.reader.IPluginInReadService;
-import org.opendaylight.controller.sal.reader.IPluginOutReadService;
-import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
-import org.opendaylight.controller.sal.reader.NodeDescription;
-import org.opendaylight.controller.sal.reader.NodeTableStatistics;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.Link;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionAware;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericStatistics;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Bytes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Packets;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatistics;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Optional;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.collect.Iterables;
-
-public class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventoryService, OpendaylightFlowStatisticsListener, OpendaylightFlowTableStatisticsListener, OpendaylightPortStatisticsListener {
- private static final Logger LOG = LoggerFactory.getLogger(InventoryAndReadAdapter.class);
- private static final short OPENFLOWV10_TABLE_ID = 0;
- private static final int SLEEP_FOR_NOTIFICATIONS_MILLIS = 500;
-
- private final InventoryNotificationProvider inventoryNotificationProvider = new InventoryNotificationProvider();
- private final Map<PathArgument,List<PathArgument>> nodeToNodeConnectorsMap = new ConcurrentHashMap<>();
- private List<IPluginOutInventoryService> inventoryPublisher = new CopyOnWriteArrayList<>();
- private List<IPluginOutReadService> statisticsPublisher = new CopyOnWriteArrayList<>();
- private Cache<String, TransactionNotificationList<? extends TransactionAware>> txCache;
-
- private OpendaylightFlowTableStatisticsService flowTableStatisticsService;
- private OpendaylightPortStatisticsService nodeConnectorStatisticsService;
- private OpendaylightFlowStatisticsService flowStatisticsService;
- private FlowTopologyDiscoveryService topologyDiscovery;
- private DataProviderService dataProviderService;
- private DataBrokerService dataService;
-
- public DataBrokerService getDataService() {
- return dataService;
- }
-
- public void setDataService(final DataBrokerService dataService) {
- this.dataService = dataService;
- }
-
- public DataProviderService getDataProviderService() {
- return dataProviderService;
- }
-
- public void setDataProviderService(final DataProviderService dataProviderService) {
- this.dataProviderService = dataProviderService;
- }
-
- public OpendaylightFlowStatisticsService getFlowStatisticsService() {
- return flowStatisticsService;
- }
-
- public void setFlowStatisticsService(final OpendaylightFlowStatisticsService flowStatisticsService) {
- this.flowStatisticsService = flowStatisticsService;
- }
-
- public OpendaylightPortStatisticsService getNodeConnectorStatisticsService() {
- return nodeConnectorStatisticsService;
- }
-
- public void setNodeConnectorStatisticsService(final OpendaylightPortStatisticsService nodeConnectorStatisticsService) {
- this.nodeConnectorStatisticsService = nodeConnectorStatisticsService;
- }
-
- public OpendaylightFlowTableStatisticsService getFlowTableStatisticsService() {
- return flowTableStatisticsService;
- }
-
- public void setFlowTableStatisticsService(final OpendaylightFlowTableStatisticsService flowTableStatisticsService) {
- this.flowTableStatisticsService = flowTableStatisticsService;
- }
-
- public FlowTopologyDiscoveryService getTopologyDiscovery() {
- return topologyDiscovery;
- }
-
- public void setTopologyDiscovery(final FlowTopologyDiscoveryService topologyDiscovery) {
- this.topologyDiscovery = topologyDiscovery;
- }
-
- public List<IPluginOutReadService> getStatisticsPublisher() {
- return statisticsPublisher;
- }
-
- public void setStatisticsPublisher(final List<IPluginOutReadService> statisticsPublisher) {
- this.statisticsPublisher = statisticsPublisher;
- }
-
- public List<IPluginOutInventoryService> getInventoryPublisher() {
- return inventoryPublisher;
- }
-
- public void setInventoryPublisher(final List<IPluginOutInventoryService> inventoryPublisher) {
- this.inventoryPublisher = inventoryPublisher;
- }
-
- public void startAdapter() {
- inventoryNotificationProvider.setDataProviderService(getDataProviderService());
- inventoryNotificationProvider.setInventoryPublisher(getInventoryPublisher());
- txCache = CacheBuilder.newBuilder().expireAfterWrite(60L, TimeUnit.SECONDS).maximumSize(10000).build();
- // inventoryNotificationProvider.start();
- }
-
- public boolean setInventoryPublisher(final IPluginOutInventoryService listener) {
- return getInventoryPublisher().add(listener);
- }
-
- public boolean unsetInventoryPublisher(final IPluginOutInventoryService listener) {
- return getInventoryPublisher().remove(listener);
- }
-
- public boolean setReadPublisher(final IPluginOutReadService listener) {
- return getStatisticsPublisher().add(listener);
- }
-
- public Boolean unsetReadPublisher(final IPluginOutReadService listener) {
- if (listener != null) {
- return getStatisticsPublisher().remove(listener);
- }
- return false;
- }
-
- protected DataModificationTransaction startChange() {
- return getDataProviderService().beginTransaction();
- }
-
- @Override
- public long getTransmitRate(final NodeConnector connector) {
- final FlowCapableNodeConnector nodeConnector = this.readOperFlowCapableNodeConnector(NodeMapping.toNodeConnectorRef(connector));
- return nodeConnector.getCurrentSpeed().longValue();
- }
-
- private FlowCapableNode readOperFlowCapableNode(final NodeRef ref) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node =
- (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)getDataService().readOperationalData(ref.getValue());
- if (node == null) {
- return null;
- }
-
- return node.getAugmentation(FlowCapableNode.class);
- }
-
- private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node readConfigNode(final Node node) {
- final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
- InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, InventoryMapping.toNodeKey(node))
- .build();
-
- return (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) startChange().readConfigurationData(nodeRef);
- }
-
- private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector readConfigNodeConnector(final NodeConnector connector) {
- final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector> nodeConnectorRef =
- InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, InventoryMapping.toNodeKey(connector.getNode()))
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector.class, InventoryMapping.toNodeConnectorKey(connector))
- .toInstance();
-
- return((org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) startChange().readConfigurationData(nodeConnectorRef));
- }
-
- /**
- * Read a table of a node from configuration data store.
- *
- * @param node Node id
- * @param id Table id
- * @return Table contents, or null if not present
- */
- private Table readOperationalTable(final Node node, final short id) {
- final InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, NodeMapping.toNodeKey(node))
- .augmentation(FlowCapableNode.class)
- .child(Table.class, new TableKey(id))
- .build();
-
- return (Table) startChange().readOperationalData(tableRef);
- }
-
- @Override
- public List<FlowOnNode> readAllFlow(final Node node, final boolean cached) {
- final ArrayList<FlowOnNode> ret= new ArrayList<>();
- if (cached) {
- final Table table = readOperationalTable(node, OPENFLOWV10_TABLE_ID);
- if (table != null) {
- final List<Flow> flows = table.getFlow();
- LOG.trace("Number of flows installed in table 0 of node {} : {}", node, flows.size());
-
- for (final Flow flow : flows) {
- final FlowStatisticsData statsFromDataStore = flow.getAugmentation(FlowStatisticsData.class);
- if (statsFromDataStore != null) {
- final FlowOnNode it = new FlowOnNode(ToSalConversionsUtils.toFlow(flow, node));
- ret.add(addFlowStats(it, statsFromDataStore.getFlowStatistics()));
- }
- }
- }
- } else {
- LOG.debug("readAllFlow cached:{}", cached);
- GetAllFlowStatisticsFromFlowTableInput input =
- new GetAllFlowStatisticsFromFlowTableInputBuilder()
- .setNode(NodeMapping.toNodeRef(node))
- .setTableId(new TableId(OPENFLOWV10_TABLE_ID))
- .build();
-
- Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> future =
- getFlowStatisticsService().getAllFlowStatisticsFromFlowTable(input);
-
- RpcResult<GetAllFlowStatisticsFromFlowTableOutput> result = null;
- try {
- // having a blocking call is fine here, as we need to join
- // the notifications and return the result
- result = future.get();
- } catch (Exception e) {
- LOG.error("Exception in getAllFlowStatisticsFromFlowTable ", e);
- return ret;
- }
-
- GetAllFlowStatisticsFromFlowTableOutput output = result.getResult();
- if (output == null) {
- return ret;
- }
-
- TransactionId transactionId = output.getTransactionId();
- String cacheKey = buildCacheKey(transactionId, NodeMapping.toNodeId(node));
- LOG.info("readAllFlow transactionId:{} cacheKey:{}", transactionId, cacheKey);
-
- // insert an entry in tempcache, will get updated when notification is received
- txCache.put(cacheKey, new TransactionNotificationList<FlowsStatisticsUpdate>(
- transactionId, node.getNodeIDString()));
-
- TransactionNotificationList<FlowsStatisticsUpdate> txnList =
- (TransactionNotificationList<FlowsStatisticsUpdate>) txCache.getIfPresent(cacheKey);
-
- // this loop would not be infinite as the cache will remove an entry
- // after defined time if not written to
- while (txnList != null && !txnList.areAllNotificationsGathered()) {
- LOG.debug("readAllFlow waiting for notification...");
- waitForNotification();
- txnList = (TransactionNotificationList<FlowsStatisticsUpdate>) txCache.getIfPresent(cacheKey);
- }
-
- if (txnList == null) {
- return ret;
- }
-
- List<FlowsStatisticsUpdate> notifications = txnList.getNotifications();
- for (FlowsStatisticsUpdate flowsStatisticsUpdate : notifications) {
- List<FlowAndStatisticsMapList> flowAndStatisticsMapList = flowsStatisticsUpdate.getFlowAndStatisticsMapList();
- if (flowAndStatisticsMapList != null) {
- for (FlowAndStatisticsMapList flowAndStatistics : flowAndStatisticsMapList) {
- final FlowOnNode it = new FlowOnNode(ToSalConversionsUtils.toFlow(flowAndStatistics, node));
- ret.add(addFlowStats(it, flowAndStatistics));
- }
- }
- }
- }
- return ret;
- }
-
- private String buildCacheKey(final TransactionId id, final NodeId nodeId) {
- return String.valueOf(id.getValue()) + "-" + nodeId.getValue();
- }
-
- private void waitForNotification() {
- try {
- // going for a simple sleep approach,as wait-notify on a monitor would require
- // us to maintain monitors per txn-node combo
- Thread.sleep(SLEEP_FOR_NOTIFICATIONS_MILLIS);
- LOG.trace("statCollector is waking up from a wait stat Response sleep");
- } catch (final InterruptedException e) {
- LOG.warn("statCollector has been interrupted waiting stat Response sleep", e);
- }
- }
-
- @Override
- public List<NodeConnectorStatistics> readAllNodeConnector(final Node node, final boolean cached) {
- final ArrayList<NodeConnectorStatistics> ret = new ArrayList<>();
-
- final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node dsNode = readConfigNode(node);
- if (dsNode != null) {
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector dsNodeConnector : dsNode.getNodeConnector()) {
- final FlowCapableNodeConnectorStatistics stats = (dsNodeConnector.getAugmentation(FlowCapableNodeConnectorStatisticsData.class));
- if (stats != null) {
- try {
- ret.add(toNodeConnectorStatistics(stats.getFlowCapableNodeConnectorStatistics(), dsNode.getId(), dsNodeConnector.getId()));
- } catch (ConstructionException e) {
- LOG.warn("Failed to instantiate node connector statistics for node {} connector {}, ignoring it",
- dsNode.getId(), dsNodeConnector.getId(), e);
- }
- }
- }
- }
-
- //TODO: Refer TODO (main)
- getNodeConnectorStatisticsService().getAllNodeConnectorsStatistics(
- new GetAllNodeConnectorsStatisticsInputBuilder().setNode(NodeMapping.toNodeRef(node)).build());
- return ret;
- }
-
- @Override
- public List<NodeTableStatistics> readAllNodeTable(final Node node, final boolean cached) {
- final NodeRef nodeRef = NodeMapping.toNodeRef(node);
-
- final ArrayList<NodeTableStatistics> ret = new ArrayList<>();
- final FlowCapableNode dsFlowCapableNode = this.readOperFlowCapableNode(nodeRef);
- if (dsFlowCapableNode != null) {
- for (final Table table : dsFlowCapableNode.getTable()) {
- final FlowTableStatisticsData tableStats = table.getAugmentation(FlowTableStatisticsData.class);
- if (tableStats != null) {
- try {
- ret.add(toNodeTableStatistics(tableStats.getFlowTableStatistics(), table.getId(), node));
- } catch (ConstructionException e) {
- LOG.warn("Failed to instantiate table statistics for node {} table {}, ignoring it", node, table.getId(), e);
- }
- }
- }
- }
-
- //TODO: Refer TODO (main)
- getFlowTableStatisticsService().getFlowTablesStatistics(new GetFlowTablesStatisticsInputBuilder().setNode(nodeRef).build());
- return ret;
- }
-
- @Override
- public NodeDescription readDescription(final Node node, final boolean cached) {
- return this.toNodeDescription(NodeMapping.toNodeRef(node));
- }
-
- @Override
- public FlowOnNode readFlow(final Node node, final org.opendaylight.controller.sal.flowprogrammer.Flow targetFlow, final boolean cached) {
- FlowOnNode ret = null;
- final Table table = readOperationalTable(node, OPENFLOWV10_TABLE_ID);
- if (table != null) {
- final List<Flow> flows = table.getFlow();
- InventoryAndReadAdapter.LOG.trace("Number of flows installed in table 0 of node {} : {}", node, flows.size());
-
- for (final Flow mdsalFlow : flows) {
- if(FromSalConversionsUtils.flowEquals(mdsalFlow, MDFlowMapping.toMDSalflow(targetFlow))) {
- final FlowStatisticsData statsFromDataStore = mdsalFlow.getAugmentation(FlowStatisticsData.class);
- if (statsFromDataStore != null) {
- InventoryAndReadAdapter.LOG.debug("Found matching flow in the data store flow table ");
- ret = addFlowStats(new FlowOnNode(targetFlow), statsFromDataStore.getFlowStatistics());
-
- // FIXME: break; ?
- }
- }
- }
- }
-
- //TODO: Refer TODO (main)
- final GetFlowStatisticsFromFlowTableInputBuilder input = new GetFlowStatisticsFromFlowTableInputBuilder().setNode(NodeMapping.toNodeRef(node));
- input.fieldsFrom(MDFlowMapping.toMDSalflow(targetFlow));
- getFlowStatisticsService().getFlowStatisticsFromFlowTable(input.build());
- return ret;
- }
-
- @Override
- public NodeConnectorStatistics readNodeConnector(final NodeConnector connector, final boolean cached) {
- final NodeConnectorId ncId = InventoryMapping.toNodeConnectorKey(connector).getId();
-
- NodeConnectorStatistics ret = null;
- final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nodeConnectorFromDS = readConfigNodeConnector(connector);
- if (nodeConnectorFromDS != null) {
- final FlowCapableNodeConnectorStatistics stats = nodeConnectorFromDS.getAugmentation(FlowCapableNodeConnectorStatisticsData.class);
- if (stats != null) {
- try {
- ret = toNodeConnectorStatistics(stats.getFlowCapableNodeConnectorStatistics(),
- InventoryMapping.toNodeKey(connector.getNode()).getId(), ncId);
- } catch (ConstructionException e) {
- LOG.warn("Failed to instantiate node connector statistics for connector {}, ignoring it",
- connector, e);
- }
- }
- }
-
- getNodeConnectorStatisticsService().getNodeConnectorStatistics(
- new GetNodeConnectorStatisticsInputBuilder().setNode(NodeMapping.toNodeRef(connector.getNode())).setNodeConnectorId(ncId).build());
- return ret;
- }
-
- @Override
- public NodeTableStatistics readNodeTable(final NodeTable nodeTable, final boolean cached) {
- NodeTableStatistics nodeStats = null;
- final Table table = readOperationalTable(nodeTable.getNode(), (short) nodeTable.getID());
- if (table != null) {
- final FlowTableStatisticsData tableStats = table.getAugmentation(FlowTableStatisticsData.class);
- if (tableStats != null) {
- try {
- nodeStats = toNodeTableStatistics(tableStats.getFlowTableStatistics(), table.getId(), nodeTable.getNode());
- } catch (ConstructionException e) {
- LOG.warn("Failed to instantiate table statistics for node {} table {}, ignoring it",
- nodeTable.getNode(), table.getId(), e);
- }
- }
- }
-
- //TODO: Refer TODO (main)
- getFlowTableStatisticsService().getFlowTablesStatistics(
- new GetFlowTablesStatisticsInputBuilder().setNode(NodeMapping.toNodeRef(nodeTable.getNode())).build());
- return nodeStats;
- }
-
- public void onNodeConnectorRemovedInternal(final NodeConnectorRemoved update) {
- // Never received
- }
-
- public void onNodeRemovedInternal(final NodeRemoved notification) {
- this.removeNodeConnectors(notification.getNodeRef().getValue());
- try {
- final Node aDNode = NodeMapping.toADNode(notification.getNodeRef());
- this.publishNodeUpdate(aDNode, UpdateType.REMOVED, Collections.<Property>emptySet());
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct node for {}, not propagating update", notification.getNodeRef(), e);
- }
- }
-
- public void onNodeConnectorUpdatedInternal(final NodeConnectorUpdated update) {
- final NodeConnectorRef ref = update.getNodeConnectorRef();
- final UpdateType updateType;
- if (!this.isKnownNodeConnector(ref.getValue())) {
- this.recordNodeConnector(ref.getValue());
- updateType = UpdateType.ADDED;
- } else {
- updateType = UpdateType.CHANGED;
- }
-
- try {
- final NodeConnector nodeConnector;
- nodeConnector = NodeMapping.toADNodeConnector(ref);
- this.publishNodeConnectorUpdate(nodeConnector, updateType, NodeMapping.toADNodeConnectorProperties(update));
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct node connector for {}, not reporting the update", ref, e);
- }
- }
-
- public void onNodeUpdatedInternal(final NodeUpdated notification) {
- final NodeRef ref = notification.getNodeRef();
-
- final UpdateType updateType;
- if (dataService.readOperationalData(ref.getValue()) == null) {
- updateType = UpdateType.ADDED;
- } else {
- updateType = UpdateType.CHANGED;
- }
-
- final Node aDNode;
- try {
- aDNode = NodeMapping.toADNode(ref);
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct node for {}, not reporting the update", ref, e);
- return;
- }
-
- this.publishNodeUpdate(aDNode, updateType, NodeMapping.toADNodeProperties(notification));
- for (final IPluginOutReadService statsPublisher : getStatisticsPublisher()) {
- final NodeDescription description = this.toNodeDescription(ref);
- if (description != null) {
- final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
- InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(notification.getId()))
- .toInstance();
- try {
- statsPublisher.descriptionStatisticsUpdated(NodeMapping.toADNode(nodeRef), description);
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct node for {}, not reporting the update to publisher {}", nodeRef, statsPublisher, e);
- }
- }
- }
- }
-
- @Override
- public ConcurrentMap<Node,Map<String,Property>> getNodeProps() {
- final ConcurrentHashMap<Node,Map<String,Property>> props = new ConcurrentHashMap<>();
- final Nodes nodes = this.readOperAllMDNodes();
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node : nodes.getNode()) {
- final FlowCapableNode fcn = node.getAugmentation(FlowCapableNode.class);
- if (fcn != null) {
- final ConcurrentHashMap<String,Property> perNodePropMap = new ConcurrentHashMap<String, Property>();
- final HashSet<Property> perNodeProps = NodeMapping.toADNodeProperties(fcn, node.getId());
- if (perNodeProps != null) {
- for (final Property perNodeProp : perNodeProps) {
- perNodePropMap.put(perNodeProp.getName(), perNodeProp);
- }
- }
-
- try {
- final Node adNode = NodeMapping.toADNode(node.getId());
- props.put(adNode, perNodePropMap);
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct node for {}, skipping it", node, e);
- }
- }
- }
- return props;
- }
-
- private Nodes readOperAllMDNodes() {
- final TypeSafeDataReader reader = TypeSafeDataReader.forReader(getDataService());
- return reader.readOperationalData(InstanceIdentifier.builder(Nodes.class).build());
- }
-
- @Override
- public ConcurrentMap<NodeConnector,Map<String,Property>> getNodeConnectorProps(final Boolean refresh) {
- final ConcurrentHashMap<NodeConnector,Map<String,Property>> props = new ConcurrentHashMap<>();
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node : this.readOperAllMDNodes().getNode()) {
- for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc : node.getNodeConnector()) {
- final FlowCapableNodeConnector fcnc = nc.getAugmentation(FlowCapableNodeConnector.class);
- if (fcnc != null) {
- final ConcurrentHashMap<String,Property> ncpsm = new ConcurrentHashMap<>();
- final HashSet<Property> ncps = NodeMapping.toADNodeConnectorProperties(fcnc);
- if (ncps != null) {
- for (final Property p : ncps) {
- ncpsm.put(p.getName(), p);
- }
- }
-
- try {
- props.put(NodeMapping.toADNodeConnector(nc.getId(), node.getId()), ncpsm);
- } catch (ConstructionException e) {
- LOG.warn("Failed to instantiate node {} connector {}, not reporting it", node.getId(), nc.getId(), e);
- }
- }
- }
- }
- return props;
- }
-
- private FlowCapableNodeConnector readOperFlowCapableNodeConnector(final NodeConnectorRef ref) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc =
- (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector)
- getDataService().readOperationalData(ref.getValue());
- return nc.getAugmentation(FlowCapableNodeConnector.class);
- }
-
- private static NodeConnectorStatistics toNodeConnectorStatistics(final org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.NodeConnectorStatistics nodeConnectorStatistics, final NodeId nodeId, final NodeConnectorId nodeConnectorId) throws ConstructionException {
- final NodeConnectorStatistics it = new NodeConnectorStatistics();
-
- final Packets packets = nodeConnectorStatistics.getPackets();
- it.setReceivePacketCount(packets.getReceived().longValue());
- it.setTransmitPacketCount(packets.getTransmitted().longValue());
-
- final Bytes bytes = nodeConnectorStatistics.getBytes();
- it.setReceiveByteCount(bytes.getReceived().longValue());
- it.setTransmitByteCount(bytes.getTransmitted().longValue());
-
- it.setReceiveDropCount(nodeConnectorStatistics.getReceiveDrops().longValue());
- it.setTransmitDropCount(nodeConnectorStatistics.getTransmitDrops().longValue());
- it.setReceiveErrorCount(nodeConnectorStatistics.getReceiveErrors().longValue());
- it.setTransmitErrorCount(nodeConnectorStatistics.getTransmitErrors().longValue());
- it.setReceiveFrameErrorCount(nodeConnectorStatistics.getReceiveFrameError().longValue());
- it.setReceiveOverRunErrorCount(nodeConnectorStatistics.getReceiveOverRunError().longValue());
- it.setReceiveCRCErrorCount(nodeConnectorStatistics.getReceiveCrcError().longValue());
- it.setCollisionCount(nodeConnectorStatistics.getCollisionCount().longValue());
-
- final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector> nodeConnectorRef =
- InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(nodeId))
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector.class, new NodeConnectorKey(nodeConnectorId))
- .build();
- it.setNodeConnector(NodeMapping.toADNodeConnector(new NodeConnectorRef(nodeConnectorRef)));
- return it;
- }
-
- private static NodeTableStatistics toNodeTableStatistics(final FlowTableStatistics tableStats, final Short tableId, final Node node) throws ConstructionException {
- final NodeTableStatistics it = new NodeTableStatistics();
- it.setActiveCount(tableStats.getActiveFlows().getValue().intValue());
- it.setLookupCount(tableStats.getPacketsLookedUp().getValue().longValue());
- it.setMatchedCount(tableStats.getPacketsMatched().getValue().longValue());
- it.setName(tableId.toString());
- it.setNodeTable(new NodeTable(NodeTableIDType.OPENFLOW, tableId.byteValue(), node));
- return it;
- }
-
- private NodeDescription toNodeDescription(final NodeRef nodeRef) {
- final FlowCapableNode capableNode = this.readOperFlowCapableNode(nodeRef);
- if (capableNode == null) {
- return null;
- }
-
- final NodeDescription it = new NodeDescription();
- it.setManufacturer(capableNode.getManufacturer());
- it.setSerialNumber(capableNode.getSerialNumber());
- it.setSoftware(capableNode.getSoftware());
- it.setDescription(capableNode.getDescription());
- return it;
- }
-
- public Edge toADEdge(final Link link) throws ConstructionException {
- NodeConnectorRef _source = link.getSource();
- NodeConnector _aDNodeConnector = NodeMapping.toADNodeConnector(_source);
- NodeConnectorRef _destination = link.getDestination();
- NodeConnector _aDNodeConnector_1 = NodeMapping.toADNodeConnector(_destination);
- Edge _edge = new Edge(_aDNodeConnector, _aDNodeConnector_1);
- return _edge;
- }
-
- /**
- * OpendaylightFlowStatisticsListener interface implementation
- */
- @Override
- public void onAggregateFlowStatisticsUpdate(final AggregateFlowStatisticsUpdate notification) {
- // Ignoring this notification as there does not seem to be a way to bubble this up to AD-SAL
- }
-
- @Override
- public void onFlowsStatisticsUpdate(final FlowsStatisticsUpdate notification) {
- final ArrayList<FlowOnNode> adsalFlowsStatistics = new ArrayList<>();
- final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
- InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(notification.getId()))
- .build();
-
- final Node aDNode;
- try {
- aDNode = NodeMapping.toADNode(nodeRef);
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct node for {}, ignoring it", notification.getId(), e);
- return;
- }
-
- for (final FlowAndStatisticsMapList flowStats : notification.getFlowAndStatisticsMapList()) {
- if (flowStats.getTableId() == 0) {
- adsalFlowsStatistics.add(InventoryAndReadAdapter.toFlowOnNode(flowStats, aDNode));
- }
- }
- for (final IPluginOutReadService statsPublisher : getStatisticsPublisher()) {
- statsPublisher.nodeFlowStatisticsUpdated(aDNode, adsalFlowsStatistics);
- }
-
- updateTransactionCache(notification, notification.getId(), !notification.isMoreReplies());
- }
-
- /**
- * OpendaylightFlowTableStatisticsListener interface implementation
- */
- @Override
- public void onFlowTableStatisticsUpdate(final FlowTableStatisticsUpdate notification) {
- ArrayList<NodeTableStatistics> adsalFlowTableStatistics = new ArrayList<>();
- for (final FlowTableAndStatisticsMap stats : notification.getFlowTableAndStatisticsMap()) {
- if (stats.getTableId().getValue() == 0) {
- final NodeTableStatistics it = new NodeTableStatistics();
- it.setActiveCount(stats.getActiveFlows().getValue().intValue());
- it.setLookupCount(stats.getPacketsLookedUp().getValue().longValue());
- it.setMatchedCount(stats.getPacketsMatched().getValue().longValue());
- adsalFlowTableStatistics.add(it);
- }
- }
-
- final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
- InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(notification.getId()))
- .build();
-
- final Node aDNode;
- try {
- aDNode = NodeMapping.toADNode(nodeRef);
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct node for {}, ignoring it", notification.getId(), e);
- return;
- }
-
- for (final IPluginOutReadService statsPublisher : getStatisticsPublisher()) {
- statsPublisher.nodeTableStatisticsUpdated(aDNode, adsalFlowTableStatistics);
- }
- }
-
- /**
- * OpendaylightPortStatisticsUpdate interface implementation
- */
- @Override
- public void onNodeConnectorStatisticsUpdate(final NodeConnectorStatisticsUpdate notification) {
- final ArrayList<NodeConnectorStatistics> adsalPortStatistics = new ArrayList<NodeConnectorStatistics>();
- for (final NodeConnectorStatisticsAndPortNumberMap nodeConnectorStatistics : notification.getNodeConnectorStatisticsAndPortNumberMap()) {
- try {
- adsalPortStatistics.add(toNodeConnectorStatistics(
- nodeConnectorStatistics, notification.getId(), nodeConnectorStatistics.getNodeConnectorId()));
- } catch (ConstructionException e) {
- LOG.warn("Failed to create statistics for node {} connector {}, not updating them",
- notification.getId(), nodeConnectorStatistics.getNodeConnectorId(), e);
- }
- }
-
- final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
- InstanceIdentifier.builder(Nodes.class)
- .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(notification.getId()))
- .build();
-
- final Node aDNode;
- try {
- aDNode = NodeMapping.toADNode(nodeRef);
- } catch (ConstructionException e) {
- LOG.warn("Failed to construct node for {}, ignoring it", notification.getId(), e);
- return;
- }
-
- for (final IPluginOutReadService statsPublisher : getStatisticsPublisher()) {
- statsPublisher.nodeConnectorStatisticsUpdated(aDNode, adsalPortStatistics);
- }
- }
-
- private static FlowOnNode toFlowOnNode(final FlowAndStatisticsMapList flowAndStatsMap, final Node node) {
- final FlowOnNode it = new FlowOnNode(ToSalConversionsUtils.toFlow(flowAndStatsMap, node));
- return addFlowStats(it, flowAndStatsMap);
- }
-
- private static FlowOnNode addFlowStats(final FlowOnNode node, final GenericStatistics stats) {
- node.setByteCount(stats.getByteCount().getValue().longValue());
- node.setPacketCount(stats.getPacketCount().getValue().longValue());
- node.setDurationSeconds(stats.getDuration().getSecond().getValue().intValue());
- node.setDurationNanoseconds(stats.getDuration().getNanosecond().getValue().intValue());
- return node;
- }
-
- @Override
- public Set<Node> getConfiguredNotConnectedNodes() {
- return Collections.emptySet();
- }
-
- private void publishNodeUpdate(final Node node, final UpdateType updateType, final Set<Property> properties) {
- for (final IPluginOutInventoryService publisher : getInventoryPublisher()) {
- publisher.updateNode(node, updateType, properties);
- }
- }
-
- private void publishNodeConnectorUpdate(final NodeConnector nodeConnector, final UpdateType updateType, final Set<Property> properties) {
- for (final IPluginOutInventoryService publisher : getInventoryPublisher()) {
- publisher.updateNodeConnector(nodeConnector, updateType, properties);
- }
- }
-
- private boolean isKnownNodeConnector(final InstanceIdentifier<? extends Object> nodeConnectorIdentifier) {
- final Iterator<PathArgument> it = nodeConnectorIdentifier.getPathArguments().iterator();
-
- if (!it.hasNext()) {
- return false;
- }
- it.next();
-
- if (!it.hasNext()) {
- return false;
- }
- final PathArgument nodePath = it.next();
-
- if (!it.hasNext()) {
- return false;
- }
- final PathArgument nodeConnectorPath = it.next();
-
- final List<PathArgument> nodeConnectors = nodeToNodeConnectorsMap.get(nodePath);
- return nodeConnectors == null ? false :
- nodeConnectors.contains(nodeConnectorPath);
- }
-
- private boolean recordNodeConnector(final InstanceIdentifier<? extends Object> nodeConnectorIdentifier) {
- final Iterator<PathArgument> it = nodeConnectorIdentifier.getPathArguments().iterator();
-
- if (!it.hasNext()) {
- return false;
- }
- it.next();
-
- if (!it.hasNext()) {
- return false;
- }
- final PathArgument nodePath = it.next();
-
- if (!it.hasNext()) {
- return false;
- }
- final PathArgument nodeConnectorPath = it.next();
-
- synchronized (this) {
- List<PathArgument> nodeConnectors = this.nodeToNodeConnectorsMap.get(nodePath);
- if (nodeConnectors == null) {
- nodeConnectors = new ArrayList<>();
- this.nodeToNodeConnectorsMap.put(nodePath, nodeConnectors);
- }
-
- return nodeConnectors.add(nodeConnectorPath);
- }
- }
-
- private List<PathArgument> removeNodeConnectors(final InstanceIdentifier<? extends Object> nodeIdentifier) {
- return this.nodeToNodeConnectorsMap.remove(Iterables.get(nodeIdentifier.getPathArguments(), 1));
- }
-
- private <T extends TransactionAware> void updateTransactionCache(T notification, NodeId nodeId, boolean lastNotification) {
-
- String cacheKey = buildCacheKey(notification.getTransactionId(), nodeId);
- TransactionNotificationList<T> txnList = (TransactionNotificationList<T>) txCache.getIfPresent(cacheKey);
- final Optional<TransactionNotificationList<T>> optional = Optional.<TransactionNotificationList<T>>fromNullable(txnList);
- if (optional.isPresent()) {
- LOG.info("updateTransactionCache cacheKey:{}, lastNotification:{}, txnList-present:{}", cacheKey, lastNotification, optional.isPresent());
- TransactionNotificationList<T> txn = optional.get();
- txn.addNotification(notification);
- txn.setAllNotificationsGathered(lastNotification);
- }
- }
-
- private class TransactionNotificationList<T extends TransactionAware> {
- private TransactionId id;
- private String nId;
- private List<T> notifications;
- private boolean allNotificationsGathered;
-
- public TransactionNotificationList(TransactionId id, String nId) {
- this.nId = nId;
- this.id = id;
- notifications = new ArrayList<T>();
- }
-
- public void addNotification(T notification) {
- notifications.add(notification);
- }
-
- public void setAllNotificationsGathered(boolean allNotificationsGathered) {
- this.allNotificationsGathered = allNotificationsGathered;
- }
-
- public boolean areAllNotificationsGathered() {
- return allNotificationsGathered;
- }
-
- public List<T> getNotifications() {
- return notifications;
- }
-
- }
-
-}
+++ /dev/null
-/**
- * Copyright (c) 2013 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import java.util.Iterator;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-import com.google.common.base.Splitter;
-
-public final class InventoryMapping {
- private static final String NODE_TYPE_STRING = "::";
- private static final Splitter NODE_TYPE_SPLITTER = Splitter.on(NODE_TYPE_STRING);
-
- private InventoryMapping() {
- throw new UnsupportedOperationException("Utility class");
- }
-
- public static org.opendaylight.controller.sal.core.NodeConnector toAdNodeConnector(final InstanceIdentifier<NodeConnector> identifier) {
- @SuppressWarnings("unchecked")
- final NodeConnectorKey tpKey = ((KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey>) identifier).getKey();
- return InventoryMapping.nodeConnectorFromId(tpKey.getId().getValue());
- }
-
- public static org.opendaylight.controller.sal.core.Node toAdNode(final InstanceIdentifier<Node> identifier) {
- @SuppressWarnings("unchecked")
- final NodeKey tpKey = ((KeyedInstanceIdentifier<Node,NodeKey>)identifier).getKey();
- return InventoryMapping.nodeFromNodeId(tpKey.getId().getValue());
- }
-
- public static NodeRef toNodeRef(final org.opendaylight.controller.sal.core.Node node) {
- final NodeKey nodeKey = new NodeKey(new NodeId(InventoryMapping.toNodeId(node)));
- final InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class)
- .child(Node.class, nodeKey).toInstance();
- return new NodeRef(path);
- }
-
- public static NodeKey toNodeKey(final org.opendaylight.controller.sal.core.Node node) {
- final NodeId nodeId = new NodeId(InventoryMapping.toNodeId(node));
- return new NodeKey(nodeId);
- }
-
- public static NodeConnectorKey toNodeConnectorKey(final org.opendaylight.controller.sal.core.NodeConnector nc) {
- final NodeConnectorId nodeConnectorId = new NodeConnectorId(InventoryMapping.toNodeConnectorId(nc));
- return new NodeConnectorKey(nodeConnectorId);
- }
-
- private static StringBuilder nodeIdBulder(final org.opendaylight.controller.sal.core.Node node) {
- final StringBuilder sb = new StringBuilder();
- sb.append("ad-sal:");
- sb.append(node.getType());
- sb.append(NODE_TYPE_STRING);
- sb.append(node.getNodeIDString());
- return sb;
- }
-
- public static String toNodeId(final org.opendaylight.controller.sal.core.Node node) {
- return nodeIdBulder(node).toString();
- }
-
- public static String toNodeConnectorId(final org.opendaylight.controller.sal.core.NodeConnector nc) {
- final StringBuilder sb = nodeIdBulder(nc.getNode());
- sb.append(NODE_TYPE_STRING);
- sb.append(nc.getNodeConnectorIDString());
- return sb.toString();
- }
-
- public static org.opendaylight.controller.sal.core.Node nodeFromNodeId(final String nodeId) {
- return InventoryMapping.nodeFromStrings(NODE_TYPE_SPLITTER.split(nodeId).iterator());
- }
-
- public static org.opendaylight.controller.sal.core.NodeConnector nodeConnectorFromId(final String invId) {
- return InventoryMapping.nodeConnectorFromString(NODE_TYPE_SPLITTER.split(invId).iterator());
- }
-
- private static org.opendaylight.controller.sal.core.NodeConnector nodeConnectorFromString(final Iterator<String> it) {
- final org.opendaylight.controller.sal.core.Node node = InventoryMapping.nodeFromStrings(it);
- return org.opendaylight.controller.sal.core.NodeConnector.fromStringNoNode(it.next(), node);
- }
-
- private static org.opendaylight.controller.sal.core.Node nodeFromStrings(final Iterator<String> it) {
- final String type = it.next().substring(6);
- return org.opendaylight.controller.sal.core.Node.fromString(type, it.next());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 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
- */
-
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import java.util.List;
-
-import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
-import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class InventoryNotificationProvider implements AutoCloseable{
-
- private ListenerRegistration<DataChangeListener> nodeConnectorDataChangeListenerRegistration;
-
- private NodeConnectorDataChangeListener nodeConnectorDataChangeListener;
-
- private DataProviderService dataProviderService;
-
- private List<IPluginOutInventoryService> inventoryPublisher;
-
- private final static Logger LOG = LoggerFactory.getLogger(NodeConnectorDataChangeListener.class);
-
- public void start(){
-
- LOG.info("InventoryNotificationProvider started");
-
- if(dataProviderService != null
- && inventoryPublisher!= null){
-
- if(nodeConnectorDataChangeListener == null){
- InstanceIdentifier<NodeConnector> nodeConnectorPath = InstanceIdentifier.builder(Nodes.class).child(Node.class).child(NodeConnector.class).build();
- nodeConnectorDataChangeListener = new NodeConnectorDataChangeListener();
- nodeConnectorDataChangeListener.setInventoryPublisher(inventoryPublisher);
- nodeConnectorDataChangeListenerRegistration = dataProviderService.registerDataChangeListener(nodeConnectorPath, nodeConnectorDataChangeListener);
- }
-
- }
- }
-
- @Override
- public void close() throws Exception {
- if(nodeConnectorDataChangeListenerRegistration != null){
- nodeConnectorDataChangeListenerRegistration.close();
- }
- }
-
- public void setDataProviderService(DataProviderService dataProviderService) {
- this.dataProviderService = dataProviderService;
- }
-
- public void setInventoryPublisher(List<IPluginOutInventoryService> inventoryPublisher) {
- this.inventoryPublisher = inventoryPublisher;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import com.google.common.base.Preconditions;
-import com.google.common.net.InetAddresses;
-import org.opendaylight.controller.sal.action.Action;
-import org.opendaylight.controller.sal.action.Controller;
-import org.opendaylight.controller.sal.action.Drop;
-import org.opendaylight.controller.sal.action.Flood;
-import org.opendaylight.controller.sal.action.FloodAll;
-import org.opendaylight.controller.sal.action.HwPath;
-import org.opendaylight.controller.sal.action.Loopback;
-import org.opendaylight.controller.sal.action.Output;
-import org.opendaylight.controller.sal.action.PopVlan;
-import org.opendaylight.controller.sal.action.PushVlan;
-import org.opendaylight.controller.sal.action.SetDlDst;
-import org.opendaylight.controller.sal.action.SetDlSrc;
-import org.opendaylight.controller.sal.action.SetDlType;
-import org.opendaylight.controller.sal.action.SetNextHop;
-import org.opendaylight.controller.sal.action.SetNwDst;
-import org.opendaylight.controller.sal.action.SetNwSrc;
-import org.opendaylight.controller.sal.action.SetNwTos;
-import org.opendaylight.controller.sal.action.SetTpDst;
-import org.opendaylight.controller.sal.action.SetTpSrc;
-import org.opendaylight.controller.sal.action.SetVlanCfi;
-import org.opendaylight.controller.sal.action.SetVlanId;
-import org.opendaylight.controller.sal.action.SetVlanPcp;
-import org.opendaylight.controller.sal.action.SwPath;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.flowprogrammer.Flow;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.action._case.FloodActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.flood.all.action._case.FloodAllActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.hw.path.action._case.HwPathActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.loopback.action._case.LoopbackActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.type.action._case.SetDlTypeActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.next.hop.action._case.SetNextHopActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.cfi.action._case.SetVlanCfiActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.sw.path.action._case.SwPathActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAdded;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
-
-import java.math.BigInteger;
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public final class MDFlowMapping {
- private MDFlowMapping() {
- throw new UnsupportedOperationException("Utility class");
- }
-
- private static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> toMDActions(final List<Action> actions) {
- final ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> ret =
- new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>(actions.size());
- int action = 0;
- for (final Action sourceAction : actions) {
- ret.add(toAction(sourceAction, action));
- action++;
- }
-
- return ret;
- }
-
- public static FlowAdded flowAdded(final Flow sourceFlow) {
- Preconditions.checkArgument(sourceFlow != null);
-
- return new FlowAddedBuilder()
- .setHardTimeout(Integer.valueOf(sourceFlow.getHardTimeout()))
- .setIdleTimeout(Integer.valueOf(sourceFlow.getIdleTimeout()))
- .setCookie(new FlowCookie(BigInteger.valueOf(sourceFlow.getId())))
- .setPriority(Integer.valueOf(sourceFlow.getPriority()))
- .setInstructions(MDFlowMapping.toApplyInstruction(toMDActions(sourceFlow.getActions())))
- .setMatch(FromSalConversionsUtils.toMatch(sourceFlow.getMatch()))
- .setTableId((short)0)
- .build();
- }
-
- private static FlowBuilder internalToMDFlow(final Flow sourceFlow) {
- Preconditions.checkArgument(sourceFlow != null);
-
- return new FlowBuilder()
- .setHardTimeout(Integer.valueOf(sourceFlow.getHardTimeout()))
- .setIdleTimeout(Integer.valueOf(sourceFlow.getIdleTimeout()))
- .setCookie(new FlowCookie(BigInteger.valueOf(sourceFlow.getId())))
- .setPriority(Integer.valueOf((sourceFlow.getPriority())))
- .setInstructions(MDFlowMapping.toApplyInstruction(toMDActions(sourceFlow.getActions())))
- .setMatch(FromSalConversionsUtils.toMatch(sourceFlow.getMatch()));
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow toMDFlow(final Flow sourceFlow, final String flowId) {
- return internalToMDFlow(sourceFlow)
- .setTableId((short)0)
- .setId(new FlowId(flowId))
- .build();
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow toMDSalflow(final Flow sourceFlow) {
- return internalToMDFlow(sourceFlow).build();
- }
-
- public static Instructions toApplyInstruction(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions) {
- return new InstructionsBuilder()
- .setInstruction(
- Collections.singletonList(
- new InstructionBuilder()
- .setOrder(0)
- .setInstruction(
- new ApplyActionsCaseBuilder()
- .setApplyActions(new ApplyActionsBuilder().setAction(actions).build())
- .build()
- ).build())
- ).build();
- }
-
- public static RemoveFlowInput removeFlowInput(final Node sourceNode, final Flow sourceFlow) {
- final FlowAdded source = MDFlowMapping.flowAdded(sourceFlow);
- return new RemoveFlowInputBuilder((org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) source)
- .setNode(NodeMapping.toNodeRef(sourceNode))
- .build();
- }
-
- public static AddFlowInput addFlowInput(final Node sourceNode, final Flow sourceFlow) {
- final FlowAdded source = MDFlowMapping.flowAdded(sourceFlow);
- return new AddFlowInputBuilder(((org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) source))
- .setNode(NodeMapping.toNodeRef(sourceNode))
- .build();
- }
-
- public static UpdateFlowInput updateFlowInput(final Node sourceNode, final Flow oldFlow, final Flow newFlow) {
- return new UpdateFlowInputBuilder()
- .setOriginalFlow(new OriginalFlowBuilder(MDFlowMapping.flowAdded(newFlow)).build())
- .setUpdatedFlow(new UpdatedFlowBuilder(MDFlowMapping.flowAdded(newFlow)).build())
- .setNode(NodeMapping.toNodeRef(sourceNode))
- .build();
- }
-
- private static ControllerActionCase _toAction(final Controller sourceAction) {
- return new ControllerActionCaseBuilder().setControllerAction(new ControllerActionBuilder().build()).build();
- }
-
- private static DropActionCase _toAction(final Drop sourceAction) {
- return new DropActionCaseBuilder().setDropAction(new DropActionBuilder().build()).build();
- }
-
- private static FloodActionCase _toAction(final Flood sourceAction) {
- return new FloodActionCaseBuilder().setFloodAction(new FloodActionBuilder().build()).build();
- }
-
- private static FloodAllActionCase _toAction(final FloodAll sourceAction) {
- return new FloodAllActionCaseBuilder().setFloodAllAction(new FloodAllActionBuilder().build()).build();
- }
-
- private static HwPathActionCase _toAction(final HwPath sourceAction) {
- return new HwPathActionCaseBuilder().setHwPathAction(new HwPathActionBuilder().build()).build();
- }
-
- private static LoopbackActionCase _toAction(final Loopback sourceAction) {
- return new LoopbackActionCaseBuilder().setLoopbackAction( new LoopbackActionBuilder().build()).build();
- }
-
- private static OutputActionCase _toAction(final Output sourceAction) {
- return new OutputActionCaseBuilder()
- .setOutputAction(
- new OutputActionBuilder().setOutputNodeConnector(MDFlowMapping.toUri(sourceAction.getPort())).build()
- ).build();
- }
-
- private static PopVlanActionCase _toAction(final PopVlan sourceAction) {
- PopVlanActionBuilder popVlanActionBuilder = new PopVlanActionBuilder();
- return new PopVlanActionCaseBuilder().setPopVlanAction(popVlanActionBuilder.build()).build();
- }
-
- private static PushVlanActionCase _toAction(final PushVlan sourceAction) {
- return new PushVlanActionCaseBuilder()
- .setPushVlanAction(
- new PushVlanActionBuilder()
- .setEthernetType(Integer.valueOf(sourceAction.getTag()))
- .build()
- ).build();
- }
-
- private static SetDlDstActionCase _toAction(final SetDlDst sourceAction) {
- return new SetDlDstActionCaseBuilder()
- .setSetDlDstAction(new SetDlDstActionBuilder().setAddress(MDFlowMapping.toMacAddress(sourceAction.getDlAddress())).build())
- .build();
- }
-
- private static SetDlSrcActionCase _toAction(final SetDlSrc sourceAction) {
- return new SetDlSrcActionCaseBuilder()
- .setSetDlSrcAction(new SetDlSrcActionBuilder().setAddress(MDFlowMapping.toMacAddress(sourceAction.getDlAddress())).build())
- .build();
- }
-
- private static SetDlTypeActionCase _toAction(final SetDlType sourceAction) {
- return new SetDlTypeActionCaseBuilder()
- .setSetDlTypeAction(new SetDlTypeActionBuilder().setDlType(new EtherType(Long.valueOf(sourceAction.getDlType()))).build())
- .build();
- }
-
- private static SetNextHopActionCase _toAction(final SetNextHop sourceAction) {
- return new SetNextHopActionCaseBuilder()
- .setSetNextHopAction(new SetNextHopActionBuilder().setAddress(MDFlowMapping.toInetAddress(sourceAction.getAddress())).build())
- .build();
- }
-
- private static SetNwDstActionCase _toAction(final SetNwDst sourceAction) {
- return new SetNwDstActionCaseBuilder()
- .setSetNwDstAction(new SetNwDstActionBuilder().setAddress(MDFlowMapping.toInetAddress(sourceAction.getAddress())).build())
- .build();
- }
-
- private static SetNwSrcActionCase _toAction(final SetNwSrc sourceAction) {
- return new SetNwSrcActionCaseBuilder()
- .setSetNwSrcAction(new SetNwSrcActionBuilder().setAddress(MDFlowMapping.toInetAddress(sourceAction.getAddress())).build())
- .build();
- }
-
- private static SetNwTosActionCase _toAction(final SetNwTos sourceAction) {
- return new SetNwTosActionCaseBuilder()
- .setSetNwTosAction(new SetNwTosActionBuilder().setTos(FromSalConversionsUtils.dscpToTos(sourceAction.getNwTos())).build())
- .build();
- }
-
- private static SetTpDstActionCase _toAction(final SetTpDst sourceAction) {
- return new SetTpDstActionCaseBuilder()
- .setSetTpDstAction(new SetTpDstActionBuilder().setPort(new PortNumber(sourceAction.getPort())).build())
- .build();
- }
-
- private static SetTpSrcActionCase _toAction(final SetTpSrc sourceAction) {
- return new SetTpSrcActionCaseBuilder()
- .setSetTpSrcAction(new SetTpSrcActionBuilder().setPort(new PortNumber(sourceAction.getPort())).build())
- .build();
- }
-
- private static SetVlanCfiActionCase _toAction(final SetVlanCfi sourceAction) {
- return new SetVlanCfiActionCaseBuilder()
- .setSetVlanCfiAction(new SetVlanCfiActionBuilder().setVlanCfi(new VlanCfi(sourceAction.getCfi())).build())
- .build();
- }
-
- private static SetVlanIdActionCase _toAction(final SetVlanId sourceAction) {
- return new SetVlanIdActionCaseBuilder()
- .setSetVlanIdAction(new SetVlanIdActionBuilder().setVlanId(new VlanId(sourceAction.getVlanId())).build())
- .build();
- }
-
- private static SetVlanPcpActionCase _toAction(final SetVlanPcp sourceAction) {
- return new SetVlanPcpActionCaseBuilder()
- .setSetVlanPcpAction(new SetVlanPcpActionBuilder().setVlanPcp(new VlanPcp((short) sourceAction.getPcp())).build())
- .build();
- }
-
- private static SwPathActionCase _toAction(final SwPath sourceAction) {
- return new SwPathActionCaseBuilder().setSwPathAction(new SwPathActionBuilder().build()).build();
- }
-
- public static Uri toUri(final NodeConnector connector) {
- return new NodeConnectorId(NodeMapping.OPENFLOW_ID_PREFIX + connector.getNode().getID() + ":" + (connector.getID()));
- }
-
- public static MacAddress toMacAddress(final byte[] bytes) {
- final StringBuilder sb = new StringBuilder(18);
- boolean first = true;
-
- for (final byte b : bytes) {
- if (first) {
- first = false;
- } else {
- sb.append(':');
- }
- sb.append(String.format("%02x", Byte.valueOf(b)));
- }
- return new MacAddress(sb.toString());
- }
-
- public static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action toAction(final Action sourceAction, final int order) {
- final ActionBuilder ret = new ActionBuilder().setOrder(order);
-
- if (sourceAction instanceof Controller) {
- ret.setAction(_toAction((Controller)sourceAction));
- } else if (sourceAction instanceof Drop) {
- ret.setAction(_toAction((Drop)sourceAction));
- } else if (sourceAction instanceof Flood) {
- ret.setAction(_toAction((Flood)sourceAction));
- } else if (sourceAction instanceof FloodAll) {
- ret.setAction(_toAction((FloodAll)sourceAction));
- } else if (sourceAction instanceof HwPath) {
- ret.setAction(_toAction((HwPath)sourceAction));
- } else if (sourceAction instanceof Loopback) {
- ret.setAction(_toAction((Loopback)sourceAction));
- } else if (sourceAction instanceof Output) {
- ret.setAction(_toAction((Output)sourceAction));
- } else if (sourceAction instanceof PopVlan) {
- ret.setAction(_toAction((PopVlan)sourceAction));
- } else if (sourceAction instanceof PushVlan) {
- ret.setAction(_toAction((PushVlan)sourceAction));
- } else if (sourceAction instanceof SetDlDst) {
- ret.setAction(_toAction((SetDlDst)sourceAction));
- } else if (sourceAction instanceof SetDlSrc) {
- ret.setAction(_toAction((SetDlSrc)sourceAction));
- } else if (sourceAction instanceof SetDlType) {
- ret.setAction(_toAction((SetDlType)sourceAction));
- } else if (sourceAction instanceof SetNextHop) {
- ret.setAction(_toAction((SetNextHop)sourceAction));
- } else if (sourceAction instanceof SetNwDst) {
- ret.setAction(_toAction((SetNwDst)sourceAction));
- } else if (sourceAction instanceof SetNwSrc) {
- ret.setAction(_toAction((SetNwSrc)sourceAction));
- } else if (sourceAction instanceof SetNwTos) {
- ret.setAction(_toAction((SetNwTos)sourceAction));
- } else if (sourceAction instanceof SetTpDst) {
- ret.setAction(_toAction((SetTpDst)sourceAction));
- } else if (sourceAction instanceof SetTpSrc) {
- ret.setAction(_toAction((SetTpSrc)sourceAction));
- } else if (sourceAction instanceof SetVlanCfi) {
- ret.setAction(_toAction((SetVlanCfi)sourceAction));
- } else if (sourceAction instanceof SetVlanId) {
- ret.setAction(_toAction((SetVlanId)sourceAction));
- } else if (sourceAction instanceof SetVlanPcp) {
- ret.setAction(_toAction((SetVlanPcp)sourceAction));
- } else if (sourceAction instanceof SwPath) {
- ret.setAction(_toAction((SwPath)sourceAction));
- } else {
- throw new IllegalArgumentException(String.format("Unhandled action class %s", sourceAction.getClass()));
- }
-
- return ret.build();
- }
-
- public static Address toInetAddress(final InetAddress address) {
- if (address instanceof Inet4Address) {
- return new Ipv4Builder()
- .setIpv4Address(new Ipv4Prefix(InetAddresses.toAddrString(address) + "/32"))
- .build();
- }
- if (address instanceof Inet6Address) {
- return new Ipv6Builder()
- .setIpv6Address(new Ipv6Prefix(InetAddresses.toAddrString(address) + "/128"))
- .build();
- }
-
- throw new IllegalArgumentException(String.format("Unhandled address class %s", address.getClass()));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.utils.INodeConnectorFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MDSalNodeConnectorFactory implements INodeConnectorFactory{
- private Logger logger = LoggerFactory.getLogger(MDSalNodeConnectorFactory.class);
-
- @Override
- public NodeConnector fromStringNoNode(String type, String id, Node node) {
- try {
- return new NodeConnector(type, id, node);
- } catch (ConstructionException e) {
- logger.error("Could not construct NodeConnector", e);
- }
- return null;
-
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.INodeFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class MDSalNodeFactory implements INodeFactory{
- private Logger logger = LoggerFactory.getLogger(MDSalNodeFactory.class);
-
- @Override
- public Node fromString(String type, String id) {
-
- try {
- return new Node(type, id);
- } catch (ConstructionException e) {
- logger.error("Could not construct Node", e);
- }
- return null;
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemovedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdatedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class NCDataChangeListener extends AbstractDataChangeListener<NodeConnector> {
- private static final Logger LOG = LoggerFactory.getLogger(NodeDataChangeListener.class);
- private ListenerRegistration<DataChangeListener> listenerRegistration;
- public NCDataChangeListener (final InventoryAndReadAdapter adapter, final DataBroker db) {
- super(adapter,db,NodeConnector.class);
- }
-
- @Override
- protected void add(InstanceIdentifier<NodeConnector> createKeyIdent, NodeConnector node) {
- FlowCapableNodeConnector fcnc = node.getAugmentation(FlowCapableNodeConnector.class);
- if(fcnc != null) {
- FlowCapableNodeConnectorUpdatedBuilder fcncub = new FlowCapableNodeConnectorUpdatedBuilder(fcnc);
- NodeConnectorUpdatedBuilder builder = new NodeConnectorUpdatedBuilder();
- builder.setId(node.getId());
- builder.setNodeConnectorRef(new NodeConnectorRef(createKeyIdent));
- builder.addAugmentation(FlowCapableNodeConnectorUpdated.class, fcncub.build());
- adapter.onNodeConnectorUpdatedInternal(builder.build());
- }
- }
-
- @Override
- protected void update(InstanceIdentifier<NodeConnector> updateKeyIdent, NodeConnector original,
- NodeConnector update) {
- add(updateKeyIdent,update);
- }
-
- @Override
- protected void remove(InstanceIdentifier<NodeConnector> ident, NodeConnector removeValue) {
- NodeConnectorRemovedBuilder builder = new NodeConnectorRemovedBuilder();
- builder.setNodeConnectorRef(new NodeConnectorRef(ident));
- adapter.onNodeConnectorRemovedInternal(builder.build());
- }
-
- protected InstanceIdentifier<NodeConnector> getWildCardPath() {
- return InstanceIdentifier.create(Nodes.class).child(Node.class).child(NodeConnector.class);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 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
- */
-
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
-import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.core.UpdateType;
-import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-// org.opendaylight.controller.sal.compatibility.NodeConnectorDataChangeListener
-public class NodeConnectorDataChangeListener implements DataChangeListener{
- private final static Logger LOG = LoggerFactory.getLogger(NodeConnectorDataChangeListener.class);
-
- private List<IPluginOutInventoryService> inventoryPublisher;
-
- public List<IPluginOutInventoryService> getInventoryPublisher() {
- return this.inventoryPublisher;
- }
-
- public void setInventoryPublisher(final List<IPluginOutInventoryService> inventoryPublisher) {
- this.inventoryPublisher = inventoryPublisher;
- }
-
- @Override
- public void onDataChanged(DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- final Map<InstanceIdentifier<?>,DataObject> createdOperationalData = change.getCreatedOperationalData();
- final Map<InstanceIdentifier<?>,DataObject> updatedOperationalData = change.getUpdatedOperationalData();
-
- final Set<Map.Entry<InstanceIdentifier<?>,DataObject>> createdEntries = createdOperationalData.entrySet();
- final Set<Map.Entry<InstanceIdentifier<?>,DataObject>> updatedEntries = new HashSet<>();
-
- updatedEntries.addAll(updatedOperationalData.entrySet());
- updatedEntries.removeAll(createdEntries);
-
- for(final Map.Entry<InstanceIdentifier<?>,DataObject> entry : createdEntries){
- publishNodeConnectorUpdate(entry, UpdateType.ADDED);
- }
-
- for(final Map.Entry<InstanceIdentifier<?>,DataObject> entry : updatedEntries){
- publishNodeConnectorUpdate(entry, UpdateType.CHANGED);
- }
- }
-
- private void publishNodeConnectorUpdate(final Map.Entry<InstanceIdentifier<?>,DataObject> entry, final UpdateType updateType) {
- if (entry.getKey().getTargetType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector.class)) {
- NodeConnectorRef nodeConnectorRef = new NodeConnectorRef(entry.getKey());
- NodeConnector nodeConnector = null;
- try {
- nodeConnector = NodeMapping.toADNodeConnector(nodeConnectorRef);
- } catch (ConstructionException e) {
- LOG.debug("Construction exception: %s",e.getMessage());
- }
- HashSet<Property> _aDNodeConnectorProperties = NodeMapping.toADNodeConnectorProperties((org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) entry.getValue());
- this.publishNodeConnectorUpdate(nodeConnector, updateType, _aDNodeConnectorProperties);
- }
- }
-
- private void publishNodeConnectorUpdate(final NodeConnector nodeConnector, final UpdateType updateType, final Set<Property> properties) {
- LOG.debug("Publishing NodeConnector " + updateType.toString() + " nodeConnector Id = " + nodeConnector.getNodeConnectorIdAsString());
-
- List<IPluginOutInventoryService> _inventoryPublisher = getInventoryPublisher();
- for (final IPluginOutInventoryService publisher : _inventoryPublisher) {
- publisher.updateNodeConnector(nodeConnector, updateType, properties);
- }
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdatedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemovedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdatedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class NodeDataChangeListener extends AbstractDataChangeListener<Node> {
- private static final Logger LOG = LoggerFactory.getLogger(NodeDataChangeListener.class);
-
-
- public NodeDataChangeListener (final InventoryAndReadAdapter adapter, final DataBroker db) {
- super(adapter,db,Node.class);
- }
-
- protected void add(InstanceIdentifier<Node> createKeyIdent, Node node) {
- FlowCapableNode fcn = node.getAugmentation(FlowCapableNode.class);
- if(fcn != null) {
- FlowCapableNodeUpdatedBuilder fcbnu = new FlowCapableNodeUpdatedBuilder(fcn);
- NodeUpdatedBuilder builder = new NodeUpdatedBuilder();
- builder.setId(node.getId());
- builder.setNodeRef(new NodeRef(createKeyIdent));
- builder.setNodeConnector(node.getNodeConnector());
- builder.addAugmentation(FlowCapableNodeUpdated.class, fcbnu.build());
- adapter.onNodeUpdatedInternal(builder.build());
- }
- }
-
- protected void update(InstanceIdentifier<Node> updateKeyIdent, Node original,
- Node update) {
- this.add(updateKeyIdent, update);
- }
-
- protected void remove(InstanceIdentifier<Node> ident, Node removeValue) {
- NodeRemovedBuilder builder = new NodeRemovedBuilder();
- builder.setNodeRef(new NodeRef(ident));
- adapter.onNodeRemovedInternal(builder.build());
- }
-
- protected InstanceIdentifier<Node> getWildCardPath() {
- return InstanceIdentifier.create(Nodes.class).child(Node.class);
- }
-
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-
-import org.opendaylight.controller.sal.common.util.Arguments;
-import org.opendaylight.controller.sal.core.AdvertisedBandwidth;
-import org.opendaylight.controller.sal.core.Bandwidth;
-import org.opendaylight.controller.sal.core.Buffers;
-import org.opendaylight.controller.sal.core.Capabilities;
-import org.opendaylight.controller.sal.core.Config;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Description;
-import org.opendaylight.controller.sal.core.MacAddress;
-import org.opendaylight.controller.sal.core.Name;
-import org.opendaylight.controller.sal.core.Node.NodeIDType;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
-import org.opendaylight.controller.sal.core.PeerBandwidth;
-import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.core.SupportedBandwidth;
-import org.opendaylight.controller.sal.core.Tables;
-import org.opendaylight.controller.sal.core.TimeStamp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FeatureCapability;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityArpMatchIp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityFlowStats;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityIpReasm;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityPortStats;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityQueueStats;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityStp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowFeatureCapabilityTableStats;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowNodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.State;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.math.BigInteger;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.regex.Pattern;
-
-public final class NodeMapping {
-
- private static final Logger LOG = LoggerFactory
- .getLogger(NodeMapping.class);
-
- /**
- * openflow id prefix
- */
- public static final String OPENFLOW_ID_PREFIX = "openflow:";
-
- public final static String MD_SAL_TYPE = "MD_SAL_DEPRECATED";
-
- private final static Class<Node> NODE_CLASS = Node.class;
-
- private final static Class<NodeConnector> NODECONNECTOR_CLASS = NodeConnector.class;
-
- private final static Pattern COLON_NUMBERS_EOL = Pattern.compile(":[0-9]+$");
-
- private final static Pattern NUMBERS_ONLY = Pattern.compile("[0-9]+");
-
- private final static Pattern ALL_CHARS_TO_COLON = Pattern.compile("^.*:");
-
- private NodeMapping() {
- throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
- }
-
- public static org.opendaylight.controller.sal.core.Node toADNode(final InstanceIdentifier<? extends Object> node) throws ConstructionException {
- NodeId nodeId = NodeMapping.toNodeId(node);
- return NodeMapping.toADNode(nodeId);
- }
-
- public static org.opendaylight.controller.sal.core.Node toADNode(final NodeId id) throws ConstructionException {
- String nodeId = NodeMapping.toADNodeId(id);
- String nodeIdasNumber = nodeId.replaceFirst("^.*:", "");
- if (isInteger(nodeIdasNumber)) {
- Long aDNodeId = openflowFullNodeIdToLong(nodeIdasNumber);
- return new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, aDNodeId);
- } else {
- return new org.opendaylight.controller.sal.core.Node(NodeIDType.PRODUCTION, nodeId);
- }
- }
-
- /**
- * @param adNodeId
- * @return nodeId as long
- */
- @VisibleForTesting
- public static Long openflowFullNodeIdToLong(String adNodeId) {
- if (adNodeId == null) {
- return null;
- }
- return new BigInteger(adNodeId).longValue();
- }
-
- public static NodeId toNodeId(final InstanceIdentifier<?> id) {
- final NodeKey key = id.firstKeyOf(Node.class, NodeKey.class);
- Preconditions.checkArgument(key != null, "No node identifier found in %s", id);
- return key.getId();
- }
-
- /**
- * @param nodeId containing "<NodeTypeString>:<plainIntegerId>"
- * @return adNodeId form
- */
- public static String toADNodeId(final NodeId nodeId) {
- if (nodeId == null) {
- return null;
- }
- return nodeId.getValue();
- }
-
- public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorRef source) throws ConstructionException {
- final InstanceIdentifier<?> id = Preconditions.checkNotNull(source.getValue());
- final NodeConnectorKey key = id.firstKeyOf(NodeConnector.class, NodeConnectorKey.class);
- return NodeMapping.toADNodeConnector(key.getId(), NodeMapping.toNodeId(id));
- }
-
- public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorId ncid, final NodeId nid) throws ConstructionException {
- String nodeConnectorType = NodeMapping.toNodeConnectorType(ncid, nid);
- Object aDNodeConnectorId = NodeMapping.toADNodeConnectorId(ncid, nid);
- org.opendaylight.controller.sal.core.Node aDNode = NodeMapping.toADNode(nid);
- return new org.opendaylight.controller.sal.core.NodeConnector(nodeConnectorType, aDNodeConnectorId, aDNode);
- }
-
- /**
- * @param ncid nodeConnector identifier, e.g.: OF:21 or CTRL
- * @param aDNode
- * @return nodeConnector attached to given node
- * @throws ConstructionException
- */
- public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(
- final NodeConnectorId ncid, final org.opendaylight.controller.sal.core.Node aDNode) throws ConstructionException {
- NodeId nid = NodeMapping.toNodeId(aDNode);
- String nodeConnectorType = NodeMapping.toNodeConnectorType(ncid, nid);
- Object aDNodeConnectorId = NodeMapping.toADNodeConnectorId(ncid, nid);
- return new org.opendaylight.controller.sal.core.NodeConnector(nodeConnectorType, aDNodeConnectorId, aDNode);
- }
-
- /**
- * @param aDNode
- * @return
- */
- public static NodeId toNodeId(org.opendaylight.controller.sal.core.Node aDNode) {
- String targetPrefix = null;
- if (NodeIDType.OPENFLOW.equals(aDNode.getType())) {
- targetPrefix = OPENFLOW_ID_PREFIX;
- } else {
- targetPrefix = aDNode.getType() + ":";
- }
-
- return new NodeId(targetPrefix + String.valueOf(aDNode.getID()));
- }
-
- /**
- * @param aDNode
- * @return md-sal {@link NodeKey}
- */
- public static NodeKey toNodeKey(org.opendaylight.controller.sal.core.Node aDNode) {
- return new NodeKey(toNodeId(aDNode));
- }
-
- public static String toNodeConnectorType(final NodeConnectorId ncId, final NodeId nodeId) {
- if (ncId.equals(toLocalNodeConnectorId(nodeId))) {
- return NodeConnectorIDType.SWSTACK;
- } else if (ncId.equals(toNormalNodeConnectorId(nodeId))) {
- return NodeConnectorIDType.HWPATH;
- } else if (ncId.equals(toControllerNodeConnectorId(nodeId))) {
- return NodeConnectorIDType.CONTROLLER;
- }
- return NodeConnectorIDType.OPENFLOW;
- }
-
- public static Object toADNodeConnectorId(final NodeConnectorId nodeConnectorId, final NodeId nodeId) {
- if (nodeConnectorId.equals(toLocalNodeConnectorId(nodeId)) ||
- nodeConnectorId.equals(toNormalNodeConnectorId(nodeId)) ||
- nodeConnectorId.equals(toControllerNodeConnectorId(nodeId))) {
- return org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID;
- }
-
- String nodeConnectorIdStripped = stripToColon(nodeConnectorId.getValue());
-
- if (NUMBERS_ONLY.matcher(nodeConnectorIdStripped).matches()) {
- Short nodeConnectorIdVal = null;
- try {
- nodeConnectorIdVal = Short.valueOf(nodeConnectorIdStripped);
- return nodeConnectorIdVal;
- } catch (NumberFormatException e) {
- LOG.warn("nodeConnectorId not supported (long): {}", nodeConnectorIdStripped, e);
- }
- }
- return nodeConnectorIdStripped;
- }
-
- public static String stripToColon(final String elementId) {
- return ALL_CHARS_TO_COLON.matcher(elementId).replaceFirst("");
- }
-
- public static NodeId toAdNodeId(final NodeConnectorId nodeConnectorId) {
- NodeId nodeId = null;
- if (nodeConnectorId != null) {
- nodeId = new NodeId(COLON_NUMBERS_EOL.matcher(nodeConnectorId.getValue()).replaceFirst(""));
- }
- return nodeId;
- }
-
- public static NodeConnectorId toControllerNodeConnectorId(final NodeId node) {
- return new NodeConnectorId(node.getValue() + ":" + OutputPortValues.CONTROLLER.toString());
- }
-
- public static NodeConnectorId toLocalNodeConnectorId(final NodeId node) {
- return new NodeConnectorId(node.getValue() + ":" + OutputPortValues.LOCAL.toString());
- }
-
- public static NodeConnectorId toNormalNodeConnectorId(final NodeId node) {
- return new NodeConnectorId(node.getValue() + ":" + OutputPortValues.NORMAL.toString());
- }
-
- public static NodeRef toNodeRef(final org.opendaylight.controller.sal.core.Node node) {
- Preconditions.checkArgument(NodeIDType.OPENFLOW.equals(node.getType()));
- final Long nodeId = Arguments.<Long>checkInstanceOf(node.getID(), Long.class);
- final NodeKey nodeKey = new NodeKey(new NodeId(OPENFLOW_ID_PREFIX + nodeId));
- final InstanceIdentifier<Node> nodePath = InstanceIdentifier.builder(Nodes.class).child(NODE_CLASS, nodeKey).toInstance();
- return new NodeRef(nodePath);
- }
-
- public static NodeConnectorRef toNodeConnectorRef(final org.opendaylight.controller.sal.core.NodeConnector nodeConnector) {
-
- final NodeRef node = NodeMapping.toNodeRef(nodeConnector.getNode());
- @SuppressWarnings("unchecked")
- final InstanceIdentifier<Node> nodePath = ((InstanceIdentifier<Node>) node.getValue());
- NodeConnectorId nodeConnectorId = null;
-
- if (nodeConnector.getID().equals(org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID)) {
- final NodeId nodeId = toNodeId(nodePath);
- final String nodeConnectorType = nodeConnector.getType();
- if (nodeConnectorType.equals(NodeConnectorIDType.SWSTACK)) {
- nodeConnectorId = toLocalNodeConnectorId(nodeId);
- } else if (nodeConnectorType.equals(NodeConnectorIDType.HWPATH)) {
- nodeConnectorId = toNormalNodeConnectorId(nodeId);
- } else if (nodeConnectorType.equals(NodeConnectorIDType.CONTROLLER)) {
- nodeConnectorId = toControllerNodeConnectorId(nodeId);
- }
- } else {
- nodeConnectorId = new NodeConnectorId(OPENFLOW_ID_PREFIX
- + Arguments.<Short>checkInstanceOf(nodeConnector.getID(), Short.class));
- }
- final NodeConnectorKey connectorKey = new NodeConnectorKey(nodeConnectorId);
- final InstanceIdentifier<NodeConnector> path = nodePath.child(NODECONNECTOR_CLASS, connectorKey);
- return new NodeConnectorRef(path);
- }
-
- public static org.opendaylight.controller.sal.core.Node toADNode(final NodeRef node) throws ConstructionException {
- return NodeMapping.toADNode(node.getValue());
- }
-
- public static HashSet<Property> toADNodeConnectorProperties(final NodeConnectorUpdated nc) {
- final FlowCapableNodeConnectorUpdated fcncu = nc.<FlowCapableNodeConnectorUpdated>getAugmentation(FlowCapableNodeConnectorUpdated.class);
- if (!Objects.equal(fcncu, null)) {
- HashSet<Property> adNodeConnectorProperties = NodeMapping.toADNodeConnectorProperties(fcncu);
- return adNodeConnectorProperties;
- }
- return new HashSet<Property>();
- }
-
- /**
- * @param nodeRef
- * @return node description in AD form, e.g.: OF|00:00:00:...:01
- */
- private static Description toADDescription(NodeRef nodeRef) {
- Description desc;
- try {
- desc = new Description(toADNode(nodeRef).toString());
- } catch (ConstructionException e) {
- desc = new Description("none");
- LOG.warn("node description extraction failed: {}", nodeRef);
- }
- return desc;
- }
-
- public static HashSet<Property> toADNodeConnectorProperties(final NodeConnector nc) {
- final FlowCapableNodeConnector fcnc = nc.<FlowCapableNodeConnector>getAugmentation(FlowCapableNodeConnector.class);
- if (!Objects.equal(fcnc, null)) {
- return NodeMapping.toADNodeConnectorProperties(fcnc);
- }
- return new HashSet<Property>();
- }
-
- public static HashSet<Property> toADNodeConnectorProperties(final FlowNodeConnector fcncu) {
-
- final HashSet<org.opendaylight.controller.sal.core.Property> props = new HashSet<>();
- if (fcncu != null) {
- if (fcncu.getCurrentFeature() != null && toAdBandwidth(fcncu.getCurrentFeature()) != null) {
- props.add(toAdBandwidth(fcncu.getCurrentFeature()));
- }
- if (fcncu.getAdvertisedFeatures() != null && toAdAdvertizedBandwidth(fcncu.getAdvertisedFeatures()) != null) {
- props.add(toAdAdvertizedBandwidth(fcncu.getAdvertisedFeatures()));
- }
- if (fcncu.getSupported() != null && toAdSupportedBandwidth(fcncu.getSupported()) != null) {
- props.add(toAdSupportedBandwidth(fcncu.getSupported()));
- }
- if (fcncu.getPeerFeatures() != null && toAdPeerBandwidth(fcncu.getPeerFeatures()) != null) {
- props.add(toAdPeerBandwidth(fcncu.getPeerFeatures()));
- }
- if (fcncu.getName() != null && toAdName(fcncu.getName()) != null) {
- props.add(toAdName(fcncu.getName()));
- }
- if (fcncu.getConfiguration() != null && toAdConfig(fcncu.getConfiguration()) != null) {
- props.add(toAdConfig(fcncu.getConfiguration()));
- }
- if (fcncu.getState() != null && toAdState(fcncu.getState()) != null) {
- props.add(toAdState(fcncu.getState()));
- }
- }
- return props;
- }
-
- public static Name toAdName(final String name) {
- return new Name(name);
- }
-
- public static Config toAdConfig(final PortConfig pc) {
- Config config = null;
- if (pc.isPORTDOWN()) {
- config = new Config(Config.ADMIN_DOWN);
- } else {
- config = new Config(Config.ADMIN_UP);
- }
- return config;
- }
-
- public static org.opendaylight.controller.sal.core.State toAdState(final State s) {
-
- org.opendaylight.controller.sal.core.State state = null;
- if (s.isLinkDown()) {
- state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_DOWN);
- } else {
- state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_UP);
- }
- return state;
- }
-
- public static Bandwidth toAdBandwidth(final PortFeatures pf) {
- Bandwidth bw = null;
- if (pf.isTenMbHd() || pf.isTenMbFd()) {
- bw = new Bandwidth(Bandwidth.BW10Mbps);
- } else if (pf.isHundredMbHd() || pf.isHundredMbFd()) {
- bw = new Bandwidth(Bandwidth.BW100Mbps);
- } else if (pf.isOneGbHd() || pf.isOneGbFd()) {
- bw = new Bandwidth(Bandwidth.BW1Gbps);
- } else if (pf.isOneGbFd()) {
- bw = new Bandwidth(Bandwidth.BW10Gbps);
- } else if (pf.isTenGbFd()) {
- bw = new Bandwidth(Bandwidth.BW10Gbps);
- } else if (pf.isFortyGbFd()) {
- bw = new Bandwidth(Bandwidth.BW40Gbps);
- } else if (pf.isHundredGbFd()) {
- bw = new Bandwidth(Bandwidth.BW100Gbps);
- } else if (pf.isOneTbFd()) {
- bw = new Bandwidth(Bandwidth.BW1Tbps);
- }
- return bw;
- }
-
- public static AdvertisedBandwidth toAdAdvertizedBandwidth(final PortFeatures pf) {
- AdvertisedBandwidth abw = null;
- final Bandwidth bw = toAdBandwidth(pf);
- if (bw != null) {
- abw = new AdvertisedBandwidth(bw.getValue());
- }
- return abw;
- }
-
- public static SupportedBandwidth toAdSupportedBandwidth(final PortFeatures pf) {
- SupportedBandwidth sbw = null;
- final Bandwidth bw = toAdBandwidth(pf);
- if (bw != null) {
- sbw = new SupportedBandwidth(bw.getValue());
- }
- return sbw;
- }
-
- public static PeerBandwidth toAdPeerBandwidth(final PortFeatures pf) {
- PeerBandwidth pbw = null;
- final Bandwidth bw = toAdBandwidth(pf);
- if (bw != null) {
- pbw = new PeerBandwidth(bw.getValue());
- }
- return pbw;
- }
-
- public static HashSet<Property> toADNodeProperties(final NodeUpdated nu) {
- final FlowCapableNodeUpdated fcnu = nu.getAugmentation(FlowCapableNodeUpdated.class);
- if (fcnu != null) {
- HashSet<Property> adNodeProperties = toADNodeProperties(fcnu, nu.getId());
- adNodeProperties.add(toADDescription(nu.getNodeRef()));
- return adNodeProperties;
- }
- return new HashSet<org.opendaylight.controller.sal.core.Property>();
- }
-
- public static HashSet<Property> toADNodeProperties(final FlowNode fcnu, final NodeId id) {
-
- final HashSet<org.opendaylight.controller.sal.core.Property> props = new HashSet<>();
-
- if (fcnu != null) {
- props.add(toADTimestamp());
-
- // props.add(fcnu.supportedActions.toADActions) - TODO
- if (id != null) {
- props.add(toADMacAddress(id));
- }
- SwitchFeatures switchFeatures = fcnu.getSwitchFeatures();
- if (switchFeatures != null) {
- if (switchFeatures.getMaxTables() != null) {
- props.add(toADTables(switchFeatures.getMaxTables()));
- }
- if (switchFeatures.getCapabilities() != null) {
- props.add(toADCapabiliities(switchFeatures.getCapabilities()));
- }
- if (switchFeatures.getMaxBuffers() != null) {
- props.add(toADBuffers(switchFeatures.getMaxBuffers()));
- }
- }
- }
- return props;
- }
-
- public static TimeStamp toADTimestamp() {
- final Date date = new Date();
- final TimeStamp timestamp = new TimeStamp(date.getTime(), "connectedSince");
- return timestamp;
- }
-
- public static MacAddress toADMacAddress(final NodeId id) {
- final String nodeId = id.getValue().replaceAll(OPENFLOW_ID_PREFIX, "");
- BigInteger nodeIdRaw = new BigInteger(nodeId);
- long lNodeId = nodeIdRaw.longValue();
- byte[] bytesFromDpid = ToSalConversionsUtils.bytesFromDpid(lNodeId);
- return new MacAddress(bytesFromDpid);
- }
-
- public static Tables toADTables(final Short tables) {
- return new Tables(tables.byteValue());
- }
-
- public static Capabilities toADCapabiliities(final List<Class<? extends FeatureCapability>> capabilities) {
-
- int b = 0;
- for (Class<? extends FeatureCapability> capability : capabilities) {
- if (capability.equals(FlowFeatureCapabilityFlowStats.class)) {
- b = Capabilities.CapabilitiesType.FLOW_STATS_CAPABILITY.getValue() | b;
- } else if (capability.equals(FlowFeatureCapabilityTableStats.class)) {
- b = Capabilities.CapabilitiesType.TABLE_STATS_CAPABILITY.getValue() | b;
- } else if (capability.equals(FlowFeatureCapabilityPortStats.class)) {
- b = Capabilities.CapabilitiesType.PORT_STATS_CAPABILITY.getValue() | b;
- } else if (capability.equals(FlowFeatureCapabilityStp.class)) {
- b = Capabilities.CapabilitiesType.STP_CAPABILITY.getValue() | b;
- } else if (capability.equals(FlowFeatureCapabilityIpReasm.class)) {
- b = Capabilities.CapabilitiesType.IP_REASSEM_CAPABILITY.getValue() | b;
- } else if (capability.equals(FlowFeatureCapabilityQueueStats.class)) {
- b = Capabilities.CapabilitiesType.QUEUE_STATS_CAPABILITY.getValue() | b;
- } else if (capability.equals(FlowFeatureCapabilityArpMatchIp.class)) {
- b = Capabilities.CapabilitiesType.ARP_MATCH_IP_CAPABILITY.getValue() | b;
- }
- }
- return new Capabilities(b);
- }
-
- public static Buffers toADBuffers(final Long buffers) {
- return new Buffers(buffers.intValue());
- }
-
-
- private static final boolean isInteger(String value) {
- if (value.isEmpty()) return false;
- for (int i = 0; i < value.length(); i++) {
- if (i == 0 && value.charAt(i) == '-') {
- if (value.length() == 1) return false;
- else continue;
- }
- if (Character.digit(value.charAt(i), 10) < 0) return false;
- }
- return true;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-public class ProtocolConstants {
- // source: http://en.wikipedia.org/wiki/Ethertype
- public static final short ETHERNET_ARP = (short) 0x0806;
-
- // source: http://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
- public static final byte TCP = (byte) 0x06;
- public static final byte UDP = (byte) 0x11;
- public static final byte CRUDP = (byte) 0x7F;
-
- private ProtocolConstants() {
-
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
-import org.opendaylight.controller.sal.binding.api.NotificationService;
-import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.adsal.DataPacketServiceAdapter;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyAdapter;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyProvider;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
-
-import com.google.common.base.Preconditions;
-
-class SalCompatibilityProvider implements BindingAwareProvider {
- private final ComponentActivator activator;
-
- public SalCompatibilityProvider(final ComponentActivator cmpAct) {
- this.activator = Preconditions.checkNotNull(cmpAct);
- }
-
- @Override
- public void onSessionInitiated(final ProviderContext session) {
- final NotificationService subscribe = session.getSALService(NotificationService.class);
-
- final FlowProgrammerAdapter flow = activator.getFlow();
- flow.setDelegate(session.getRpcService(SalFlowService.class));
- flow.setDataBrokerService(session.getSALService(DataBrokerService.class));
- // FIXME: remember registration for clean shutdown
- subscribe.registerNotificationListener(flow);
-
- final InventoryAndReadAdapter inv = activator.getInventory();
- inv.setDataService(session.getSALService(DataBrokerService.class));
- inv.setFlowStatisticsService(session.getRpcService(OpendaylightFlowStatisticsService.class));
- inv.setFlowTableStatisticsService(session.getRpcService(OpendaylightFlowTableStatisticsService.class));
- inv.setNodeConnectorStatisticsService(session.getRpcService(OpendaylightPortStatisticsService.class));
- inv.setTopologyDiscovery(session.getRpcService(FlowTopologyDiscoveryService.class));
- inv.setDataProviderService(session.getSALService(DataProviderService.class));
-
- final NodeDataChangeListener ndcl = new NodeDataChangeListener(inv,session.getSALService(DataBroker.class));
- final NCDataChangeListener ncdcl = new NCDataChangeListener(inv,session.getSALService(DataBroker.class));
-
- // FIXME: remember registration for clean shutdown
- subscribe.registerNotificationListener(inv);
-
- final DataPacketServiceAdapter dps = activator.getDataPacketService();
- dps.setDelegate(session.getRpcService(PacketProcessingService.class));
-
- final TopologyAdapter topo = activator.getTopology();
- topo.setDataService(session.getSALService(DataProviderService.class));
-
- final TopologyProvider tpp = activator.getTpProvider();
- tpp.setDataService(session.getSALService(DataProviderService.class));
-
- inv.startAdapter();
- tpp.startAdapter();
-
- subscribe.registerNotificationListener(activator.getDataPacket());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility;
-
-import static org.opendaylight.controller.sal.match.MatchType.DL_DST;
-import static org.opendaylight.controller.sal.match.MatchType.DL_SRC;
-import static org.opendaylight.controller.sal.match.MatchType.DL_TYPE;
-import static org.opendaylight.controller.sal.match.MatchType.DL_VLAN;
-import static org.opendaylight.controller.sal.match.MatchType.DL_VLAN_PR;
-import static org.opendaylight.controller.sal.match.MatchType.NW_DST;
-import static org.opendaylight.controller.sal.match.MatchType.NW_PROTO;
-import static org.opendaylight.controller.sal.match.MatchType.NW_SRC;
-import static org.opendaylight.controller.sal.match.MatchType.NW_TOS;
-import static org.opendaylight.controller.sal.match.MatchType.TP_DST;
-import static org.opendaylight.controller.sal.match.MatchType.TP_SRC;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.CRUDP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.ETHERNET_ARP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.TCP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.UDP;
-
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.opendaylight.controller.sal.action.Controller;
-import org.opendaylight.controller.sal.action.Drop;
-import org.opendaylight.controller.sal.action.Flood;
-import org.opendaylight.controller.sal.action.FloodAll;
-import org.opendaylight.controller.sal.action.HwPath;
-import org.opendaylight.controller.sal.action.Loopback;
-import org.opendaylight.controller.sal.action.Output;
-import org.opendaylight.controller.sal.action.PopVlan;
-import org.opendaylight.controller.sal.action.PushVlan;
-import org.opendaylight.controller.sal.action.SetDlDst;
-import org.opendaylight.controller.sal.action.SetDlSrc;
-import org.opendaylight.controller.sal.action.SetDlType;
-import org.opendaylight.controller.sal.action.SetNextHop;
-import org.opendaylight.controller.sal.action.SetNwDst;
-import org.opendaylight.controller.sal.action.SetNwSrc;
-import org.opendaylight.controller.sal.action.SetNwTos;
-import org.opendaylight.controller.sal.action.SetTpDst;
-import org.opendaylight.controller.sal.action.SetTpSrc;
-import org.opendaylight.controller.sal.action.SetVlanCfi;
-import org.opendaylight.controller.sal.action.SetVlanId;
-import org.opendaylight.controller.sal.action.SetVlanPcp;
-import org.opendaylight.controller.sal.action.SwPath;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.Node.NodeIDType;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.flowprogrammer.Flow;
-import org.opendaylight.controller.sal.match.Match;
-import org.opendaylight.controller.sal.match.MatchType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.GenericFlowAttributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.MacAddressFilter;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanId;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.net.InetAddresses;
-
-public class ToSalConversionsUtils {
-
- private static final Logger LOG = LoggerFactory.getLogger(ToSalConversionsUtils.class);
-
- private ToSalConversionsUtils() {
- throw new IllegalAccessError("forcing no instance for factory");
- }
-
- public static Flow toFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow source, Node node) {
- final Flow target = new Flow();
- genericFlowToAdFlow(source, target);
-
- target.setMatch(toMatch(source.getMatch()));
-
- List<Action> actions = getAction(source);
- if (actions != null) {
- target.setActions(actionFrom(actions, node));
- }
-
- return target;
- }
-
- /**
- * @param source notification, missing instructions
- * @param node corresponding node where the flow change occured
- * @return ad-sal node, build from given data
- */
- public static Flow toFlow(SwitchFlowRemoved source, Node node) {
- final Flow target = new Flow();
- genericFlowToAdFlow(source, target);
-
- target.setMatch(toMatch(source.getMatch()));
-
- return target;
- }
-
- /**
- * @param source
- * @param target
- */
- private static void genericFlowToAdFlow(GenericFlowAttributes source,
- final Flow target) {
- Integer hardTimeout = source.getHardTimeout();
- if (hardTimeout != null) {
- target.setHardTimeout(hardTimeout.shortValue());
- }
-
- Integer idleTimeout = source.getIdleTimeout();
- if (idleTimeout != null) {
- target.setIdleTimeout(idleTimeout.shortValue());
- }
-
- Integer priority = source.getPriority();
- if (priority != null) {
- target.setPriority(priority.shortValue());
- }
- target.setId(source.getCookie().getValue().longValue());
- }
-
- public static List<Action> getAction(
- org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow source) {
- if (source.getInstructions() != null) {
- for (Instruction instruction : source.getInstructions().getInstruction()) {
- if (instruction.getInstruction() instanceof ApplyActionsCase) {
- return (((ApplyActionsCase) instruction.getInstruction()).getApplyActions().getAction());
- }
- }
- }
- // TODO Auto-generated method stub
- return Collections.emptyList();
- }
-
- public static List<org.opendaylight.controller.sal.action.Action> actionFrom(List<Action> actions, Node node) {
- List<org.opendaylight.controller.sal.action.Action> targetAction = new ArrayList<>();
- for (Action action : actions) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action sourceAction = action
- .getAction();
-
- if (sourceAction instanceof ControllerActionCase) {
- targetAction.add(new Controller());
- } else if (sourceAction instanceof OutputActionCase) {
-
- Uri nodeConnector = ((OutputActionCase) sourceAction).getOutputAction().getOutputNodeConnector();
- if (nodeConnector != null) {
- // TODO: We should really have a bi-directional map from AD-SAL node types to
- // MD-SAL node types, but lets fix that later.
- String type = node.getType();
- if( type.equals(NodeIDType.OPENFLOW) ){
- type = NodeMapping.OPENFLOW_ID_PREFIX;
- }else{
- type = type + ":";
- }
- Uri fullNodeConnector = new Uri(type+node.getID()+":"
- +NodeMapping.stripToColon(nodeConnector.getValue()));
- targetAction.add(new Output(fromNodeConnectorRef(fullNodeConnector, node)));
- }
- } else if (sourceAction instanceof PopMplsActionCase) {
- // TODO: define maping
- } else if (sourceAction instanceof PushMplsActionCase) {
- // TODO: define maping
- } else if (sourceAction instanceof PushPbbActionCase) {
- // TODO: define maping
- } else if (sourceAction instanceof SetMplsTtlActionCase) {
- // TODO: define maping
- // targetAction = //no action to map
- } else if (sourceAction instanceof SetNwTtlActionCase) {
- // TODO: define maping
- } else if (sourceAction instanceof SetQueueActionCase) {
- // TODO: define maping
- // targetAction = //no action to map
- } else if (sourceAction instanceof DropActionCase) {
- targetAction.add(new Drop());
- } else if (sourceAction instanceof FloodActionCase) {
- targetAction.add(new Flood());
- } else if (sourceAction instanceof FloodAllActionCase) {
- targetAction.add(new FloodAll());
- } else if (sourceAction instanceof HwPathActionCase) {
- targetAction.add(new HwPath());
- } else if (sourceAction instanceof LoopbackActionCase) {
- targetAction.add(new Loopback());
- } else if (sourceAction instanceof PopVlanActionCase) {
- targetAction.add(new PopVlan());
- } else if (sourceAction instanceof PushVlanActionCase) {
- PushVlanActionCase pushVlanAction = (PushVlanActionCase) sourceAction;
- PushVlan pushVlan = pushVlanFrom(pushVlanAction.getPushVlanAction());
- if (pushVlan != null) {
- targetAction.add(pushVlan);
- }
- } else if (sourceAction instanceof SetDlDstActionCase) {
- MacAddress addressL2Dest = ((SetDlDstActionCase) sourceAction).getSetDlDstAction().getAddress();
- if (addressL2Dest != null) {
- targetAction.add(new SetDlDst(bytesFrom(addressL2Dest)));
- }
- } else if (sourceAction instanceof SetDlSrcActionCase) {
- MacAddress addressL2Src = ((SetDlSrcActionCase) sourceAction).getSetDlSrcAction().getAddress();
- if (addressL2Src != null) {
- targetAction.add(new SetDlSrc(bytesFrom(addressL2Src)));
-
- }
- } else if (sourceAction instanceof SetDlTypeActionCase) {
- EtherType dlType = ((SetDlTypeActionCase) sourceAction).getSetDlTypeAction().getDlType();
- if (dlType != null) {
- Long dlTypeValue = dlType.getValue();
- if (dlTypeValue != null) {
- targetAction.add(new SetDlType(dlTypeValue.intValue()));
- }
- }
- } else if (sourceAction instanceof SetNextHopActionCase) {
- Address addressL3 = ((SetNextHopActionCase) sourceAction).getSetNextHopAction().getAddress();
-
- InetAddress inetAddress = inetAddressFrom(addressL3);
- if (inetAddress != null) {
- targetAction.add(new SetNextHop(inetAddress));
- }
- } else if (sourceAction instanceof SetNwDstActionCase) {
- Address addressL3 = ((SetNwDstActionCase) sourceAction).getSetNwDstAction().getAddress();
-
- InetAddress inetAddress = inetAddressFrom(addressL3);
- if (inetAddress != null) {
- targetAction.add(new SetNwDst(inetAddress));
- }
- } else if (sourceAction instanceof SetNwSrcActionCase) {
- Address addressL3 = ((SetNwSrcActionCase) sourceAction).getSetNwSrcAction().getAddress();
-
- InetAddress inetAddress = inetAddressFrom(addressL3);
- if (inetAddress != null) {
- targetAction.add(new SetNwSrc(inetAddress));
- }
- } else if (sourceAction instanceof SetNwTosActionCase) {
- Integer tos = ((SetNwTosActionCase) sourceAction).getSetNwTosAction().getTos();
- if (tos != null) {
- targetAction.add(new SetNwTos(ToSalConversionsUtils.tosToNwDscp(tos)));
- }
- } else if (sourceAction instanceof SetTpDstActionCase) {
- PortNumber port = ((SetTpDstActionCase) sourceAction).getSetTpDstAction().getPort();
- if (port != null) {
- Integer portValue = port.getValue();
- if (port.getValue() != null) {
- targetAction.add(new SetTpDst(portValue));
- }
- }
- } else if (sourceAction instanceof SetTpSrcActionCase) {
- PortNumber port = ((SetTpSrcActionCase) sourceAction).getSetTpSrcAction().getPort();
- if (port != null) {
- Integer portValue = port.getValue();
- if (port.getValue() != null) {
- targetAction.add(new SetTpSrc(portValue));
- }
- }
- } else if (sourceAction instanceof SetVlanCfiActionCase) {
- VlanCfi vlanCfi = ((SetVlanCfiActionCase) sourceAction).getSetVlanCfiAction().getVlanCfi();
- if (vlanCfi != null) {
- Integer vlanCfiValue = vlanCfi.getValue();
- if (vlanCfiValue != null) {
- targetAction.add(new SetVlanCfi(vlanCfiValue));
- }
- }
- } else if (sourceAction instanceof SetVlanIdActionCase) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId vlanID = ((SetVlanIdActionCase) sourceAction).getSetVlanIdAction()
- .getVlanId();
- if (vlanID != null) {
- Integer vlanIdValue = vlanID.getValue();
- if (vlanIdValue != null) {
- targetAction.add(new SetVlanId(vlanIdValue));
- }
- }
- } else if (sourceAction instanceof SetVlanPcpActionCase) {
- VlanPcp vlanPcp = ((SetVlanPcpActionCase) sourceAction).getSetVlanPcpAction().getVlanPcp();
- if (vlanPcp != null) {
- Short vlanPcpValue = vlanPcp.getValue();
- if (vlanPcpValue != null) {
- targetAction.add(new SetVlanPcp(vlanPcpValue));
- }
- }
- } else if (sourceAction instanceof SwPathActionCase) {
- targetAction.add(new SwPath());
- }
- }
-
- return targetAction;
- }
-
- private static InetAddress inetAddressFrom(Address addressL3) {
- if (addressL3 != null) {
- if (addressL3 instanceof Ipv4) {
- Ipv4Prefix addressL3Ipv4 = ((Ipv4) addressL3).getIpv4Address();
- if (addressL3Ipv4 != null) {
- return inetAddressFrom(addressL3Ipv4);
- }
- } else if (addressL3 instanceof Ipv6) {
- Ipv6Prefix addressL3Ipv6 = ((Ipv6) addressL3).getIpv6Address();
- if (addressL3Ipv6 != null) {
- return inetAddressFrom(addressL3Ipv6);
- }
- }
- }
- return null;
- }
-
- private static PushVlan pushVlanFrom(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction pushVlanAction) {
- Integer tag = pushVlanAction.getTag();
- if (tag != null) {
- return new PushVlan(tag.intValue());
- }
- return null;
- }
-
- /**
- * @param uri openflow nodeConnector URI
- * @param node
- * @return assembled nodeConnector
- */
- public static NodeConnector fromNodeConnectorRef(Uri uri, Node node) {
- NodeConnector nodeConnector = null;
- try {
- NodeConnectorId nodeConnectorId = new NodeConnectorId(uri.getValue());
- nodeConnector = NodeMapping.toADNodeConnector(nodeConnectorId, node);
- } catch (ConstructionException e) {
- LOG.warn("nodeConnector creation failed at node: {} with nodeConnectorUri: {}",
- node, uri.getValue());
- }
- return nodeConnector;
- }
-
- public static Match toMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match source) {
- Match target = new Match();
- if (source != null) {
- fillFrom(target, source.getVlanMatch());
- fillFrom(target, source.getEthernetMatch());
- fillFrom(target, source.getLayer3Match());
- fillFrom(target, source.getLayer4Match());
- fillFrom(target, source.getIpMatch());
- fillFrom(target, source.getInPort());
- }
-
- return target;
- }
-
- /**
- * @param target
- * @param inPort
- */
- private static void fillFrom(Match target, NodeConnectorId inPort) {
- if (inPort != null) {
- String inPortValue = inPort.getValue();
- if (inPortValue != null) {
- try {
- target.setField(MatchType.IN_PORT, NodeMapping.toADNodeConnector(inPort,
- NodeMapping.toAdNodeId(inPort)));
- } catch (ConstructionException e) {
- LOG.warn("nodeConnector construction failed", e);
- }
- }
- }
- }
-
- private static void fillFrom(Match target, VlanMatch vlanMatch) {
- if (vlanMatch != null) {
- VlanId vlanId = vlanMatch.getVlanId();
- if (vlanId != null) {
- if (Boolean.TRUE.equals(vlanId.isVlanIdPresent())) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId vlanIdInner = vlanId
- .getVlanId();
- if (vlanIdInner != null) {
- Integer vlanValue = vlanIdInner.getValue();
- if (vlanValue != null) {
- target.setField(DL_VLAN, vlanValue.shortValue());
- }
- }
- } else {
- target.setField(DL_VLAN, MatchType.DL_VLAN_NONE);
- }
- }
- VlanPcp vlanPcp = vlanMatch.getVlanPcp();
- if (vlanPcp != null) {
- Short vlanPcpValue = vlanPcp.getValue();
- if (vlanPcpValue != null) {
- target.setField(DL_VLAN_PR, vlanPcpValue.byteValue());
- }
- }
- }
- }
-
- private static void fillFrom(Match target, IpMatch ipMatch) {
- if (ipMatch != null) {
- Short ipProtocol = ipMatch.getIpProtocol();
-
- if (ipProtocol != null && target.getField(NW_PROTO) == null) {
- target.setField(NW_PROTO, ipProtocol.byteValue());
- }
- Dscp dscp = ipMatch.getIpDscp();
- if (dscp != null) {
- Short dscpValue = dscp.getValue();
- if (dscpValue != null) {
- target.setField(NW_TOS, dscpValue.byteValue());
- }
- }
- }
- }
-
- private static void fillFrom(Match target, Layer4Match layer4Match) {
- if (layer4Match == null) {
- return;
- }
- if (layer4Match instanceof SctpMatch) {
- fillTransportLayer(target, (SctpMatch) layer4Match);
- } else if (layer4Match instanceof TcpMatch) {
- fillTransportLayer(target, (TcpMatch) layer4Match);
- } else if (layer4Match instanceof UdpMatch) {
- fillTransportLayer(target, (UdpMatch) layer4Match);
- }
- }
-
- private static void fillTransportLayer(Match target, UdpMatch source) {
- PortNumber udpSourcePort = source.getUdpSourcePort();
- if (udpSourcePort != null) {
- Integer udpSourcePortValue = udpSourcePort.getValue();
- if (udpSourcePortValue != null) {
- target.setField(TP_SRC, udpSourcePortValue.shortValue());
- }
- }
-
- PortNumber udpDestPort = source.getUdpDestinationPort();
- if (udpDestPort != null) {
- Integer udpDestPortValue = udpDestPort.getValue();
- if (udpDestPortValue != null) {
- target.setField(TP_DST, udpDestPortValue.shortValue());
- }
- }
-
- target.setField(NW_PROTO, UDP);
- }
-
- private static void fillTransportLayer(Match target, TcpMatch source) {
- PortNumber tcpSourcePort = source.getTcpSourcePort();
- if (tcpSourcePort != null) {
- Integer tcpSourcePortValue = tcpSourcePort.getValue();
- if (tcpSourcePortValue != null) {
- target.setField(TP_SRC, tcpSourcePortValue.shortValue());
- }
- }
-
- PortNumber tcpDestPort = source.getTcpDestinationPort();
- if (tcpDestPort != null) {
- Integer tcpDestPortValue = tcpDestPort.getValue();
- if (tcpDestPortValue != null) {
- target.setField(TP_DST, tcpDestPortValue.shortValue());
- }
- }
-
- target.setField(NW_PROTO, TCP);
- }
-
- private static void fillTransportLayer(Match target, SctpMatch source) {
- PortNumber sctpSourcePort = source.getSctpSourcePort();
- if (sctpSourcePort != null) {
- Integer sctpSourcePortValue = sctpSourcePort.getValue();
- if (sctpSourcePortValue != null) {
- target.setField(TP_SRC, sctpSourcePortValue.shortValue());
- }
- }
- PortNumber sctpDestPort = source.getSctpDestinationPort();
- if (sctpDestPort != null) {
- Integer sctpDestPortValue = sctpDestPort.getValue();
- if (sctpDestPortValue != null) {
- target.setField(TP_DST, sctpDestPortValue.shortValue());
- }
- }
-
- target.setField(NW_PROTO, CRUDP);
-
- }
-
- private static void fillFrom(Match target, Layer3Match source) {
- if (source == null)
- return;
- if (source instanceof Ipv4Match) {
- fillFromIpv4(target, (Ipv4Match) source);
- } else if (source instanceof Ipv6Match) {
- fillFromIpv6(target, (Ipv6Match) source);
- } else if (source instanceof ArpMatch) {
- fillFromArp(target, (ArpMatch) source);
- }
- }
-
- private static void fillFromArp(Match target, ArpMatch source) {
- Ipv4Prefix sourceAddress = source.getArpSourceTransportAddress();
- if (sourceAddress != null) {
- target.setField(NW_SRC, inetAddressFrom(sourceAddress), null);
- }
- Ipv4Prefix destAddress = source.getArpTargetTransportAddress();
- if (destAddress != null) {
- target.setField(NW_DST, inetAddressFrom(destAddress), null);
- }
- ArpSourceHardwareAddress sourceHwAddress = source.getArpSourceHardwareAddress();
- if (sourceHwAddress != null) {
- target.setField(DL_SRC, bytesFrom(sourceHwAddress.getAddress()));
- }
- ArpTargetHardwareAddress targetHwAddress = source.getArpTargetHardwareAddress();
- if (targetHwAddress != null) {
- target.setField(DL_DST, bytesFrom(targetHwAddress.getAddress()));
- }
-
- target.setField(DL_TYPE, ETHERNET_ARP);
-
- }
-
- private static void fillFromIpv6(Match target, Ipv6Match source) {
- Ipv6Prefix sourceAddress = source.getIpv6Source();
- if (sourceAddress != null) {
- target.setField(NW_SRC, inetAddressFrom(sourceAddress), null);
- }
- Ipv6Prefix destAddress = source.getIpv6Destination();
- if (destAddress != null) {
- target.setField(NW_DST, inetAddressFrom(destAddress), null);
- }
- }
-
- private static void fillFromIpv4(Match target, Ipv4Match source) {
- Ipv4Prefix sourceAddress = source.getIpv4Source();
- if (sourceAddress != null) {
- target.setField(NW_SRC, inetAddressFrom(sourceAddress), null);
- }
- Ipv4Prefix destAddress = source.getIpv4Destination();
- if (destAddress != null) {
- target.setField(NW_DST, inetAddressFrom(destAddress), null);
- }
- }
-
- private static InetAddress inetAddressFrom(Ipv4Prefix source) {
- if (source != null) {
- String[] parts = source.getValue().split("/");
- return InetAddresses.forString(parts[0]);
- }
- return null;
- }
-
- private static InetAddress inetAddressFrom(Ipv6Prefix source) {
- if (source != null) {
- String[] parts = source.getValue().split("/");
- return InetAddresses.forString(parts[0]);
- }
- return null;
- }
-
- private static void fillFrom(Match target, EthernetMatch source) {
- if (source == null)
- return;
- EthernetType ethType = source.getEthernetType();
- if (ethType != null) {
- EtherType ethInnerType = ethType.getType();
- if (ethInnerType != null && target.getField(DL_TYPE) == null) {
- Long value = ethInnerType.getValue();
- target.setField(DL_TYPE, value.shortValue());
- }
- }
-
- MacAddressFilter ethSource = source.getEthernetSource();
- if (ethSource != null) {
- target.setField(DL_SRC, bytesFrom(ethSource.getAddress()));
- }
-
- MacAddressFilter ethDest = source.getEthernetDestination();
- if (ethDest != null) {
- target.setField(DL_DST, bytesFrom(ethDest.getAddress()));
- }
- }
-
- public static byte[] bytesFrom(MacAddress address) {
- String[] mac = address.getValue().split(":");
- byte[] macAddress = new byte[6]; // mac.length == 6 bytes
- for (int i = 0; i < mac.length; i++) {
- macAddress[i] = Integer.decode("0x" + mac[i]).byteValue();
- }
- return macAddress;
- }
-
- public static byte[] bytesFromDpid(long dpid) {
- byte[] mac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- for (short i = 0; i < 6; i++) {
- mac[5 - i] = (byte) dpid;
- dpid >>= 8;
- }
-
- return mac;
- }
-
- /**
- * @param nwTos NW-TOS
- * @return shifted to NW-DSCP
- */
- public static int tosToNwDscp(int nwTos) {
- return (short) (nwTos >>> FromSalConversionsUtils.ENC_FIELD_BIT_SIZE);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.adsal;
-
-import org.opendaylight.controller.sal.packet.IPluginInDataPacketService;
-import org.opendaylight.controller.sal.packet.RawPacket;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder;
-
-public class DataPacketServiceAdapter implements IPluginInDataPacketService {
-
- PacketProcessingService delegate;
-
- @Override
- public void transmitDataPacket(RawPacket outPkt) {
- TransmitPacketInput packet = toTransmitPacketInput(outPkt);
- delegate.transmitPacket(packet);
- }
-
- private TransmitPacketInput toTransmitPacketInput(RawPacket rawPacket) {
- TransmitPacketInputBuilder builderTPIB = new TransmitPacketInputBuilder();
-
- builderTPIB.setNode(NodeMapping.toNodeRef(rawPacket.getOutgoingNodeConnector().getNode()));
-
- NodeConnectorRef egress = rawPacket.getOutgoingNodeConnector() == null ? null :
- NodeMapping.toNodeConnectorRef(rawPacket.getOutgoingNodeConnector());
- NodeConnectorRef ingress = rawPacket.getIncomingNodeConnector() == null ? null :
- NodeMapping.toNodeConnectorRef(rawPacket.getIncomingNodeConnector());
- byte[] payload = rawPacket.getPacketData();
-
- builderTPIB.setEgress(egress);
- builderTPIB.setIngress(ingress);
- builderTPIB.setPayload(payload);
-
- return builderTPIB.build();
- }
-
- public PacketProcessingService getDelegate() {
- return delegate;
- }
-
- public void setDelegate(PacketProcessingService delegate) {
- this.delegate = delegate;
- }
-
-
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.adsal;
-
-import java.math.BigInteger;
-
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.controller.sal.flowprogrammer.Flow;
-import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
-import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
-import org.opendaylight.controller.sal.utils.Status;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.InventoryMapping;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.ToSalConversionsUtils;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-
-public class FlowServiceAdapter implements SalFlowService, IFlowProgrammerListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(FlowServiceAdapter.class);
-
- private IFlowProgrammerService delegate;
-
- private NotificationProviderService publish;
-
- @Override
- public void flowRemoved(org.opendaylight.controller.sal.core.Node node, Flow flow) {
- FlowRemovedBuilder flowRemovedBuilder = new FlowRemovedBuilder();
- flowRemovedBuilder.setNode(InventoryMapping.toNodeRef(node));
- publish.publish(flowRemovedBuilder.build());
- }
-
- @Override
- public void flowErrorReported(org.opendaylight.controller.sal.core.Node node, long rid, Object err) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public ListenableFuture<RpcResult<AddFlowOutput>> addFlow(AddFlowInput input) {
-
- Flow flow = ToSalConversionsUtils.toFlow(input, null);
- @SuppressWarnings("unchecked")
- org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
- .getNode().getValue());
- Status status = delegate.addFlowAsync(node, flow);
- AddFlowOutputBuilder builder = new AddFlowOutputBuilder();
- builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
- AddFlowOutput rpcResultType = builder.build();
- return Futures.immediateFuture(RpcResultBuilder.<AddFlowOutput>status(status.isSuccess())
- .withResult(rpcResultType).build());
- }
-
- @Override
- public ListenableFuture<RpcResult<RemoveFlowOutput>> removeFlow(RemoveFlowInput input) {
-
- Flow flow = ToSalConversionsUtils.toFlow(input, null);
- @SuppressWarnings("unchecked")
- org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
- .getNode().getValue());
- Status status = delegate.removeFlowAsync(node, flow);
- RemoveFlowOutputBuilder builder = new RemoveFlowOutputBuilder();
- builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
- RemoveFlowOutput rpcResultType = builder.build();
- return Futures.immediateFuture(RpcResultBuilder.<RemoveFlowOutput>status(status.isSuccess())
- .withResult(rpcResultType).build());
-
- }
-
- @Override
- public ListenableFuture<RpcResult<UpdateFlowOutput>> updateFlow(UpdateFlowInput input) {
- @SuppressWarnings("unchecked")
- org.opendaylight.controller.sal.core.Node node = InventoryMapping.toAdNode((InstanceIdentifier<Node>) input
- .getNode().getValue());
- Flow originalFlow = ToSalConversionsUtils.toFlow(input.getOriginalFlow(), null);
- Flow updatedFlow = ToSalConversionsUtils.toFlow(input.getUpdatedFlow(), null);
- Status status = delegate.modifyFlowAsync(node, originalFlow, updatedFlow);
- UpdateFlowOutputBuilder builder = new UpdateFlowOutputBuilder();
- builder.setTransactionId(new TransactionId(BigInteger.valueOf(status.getRequestId())));
- UpdateFlowOutput rpcResultType = builder.build();
- throw new UnsupportedOperationException("Need to translate AD-SAL status to MD-SAL UpdateFlowOuptut - eaw@cisco.com");
- // return Futures.immediateFuture(Rpcs.getRpcResult(status.isSuccess(), rpcResultType, null));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.adsal;
-
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Future;
-
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.flowprogrammer.Flow;
-import org.opendaylight.controller.sal.reader.FlowOnNode;
-import org.opendaylight.controller.sal.reader.IReadService;
-import org.opendaylight.controller.sal.reader.IReadServiceListener;
-import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
-import org.opendaylight.controller.sal.reader.NodeDescription;
-import org.opendaylight.controller.sal.reader.NodeTableStatistics;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.FromSalConversionsUtils;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.InventoryMapping;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.ToSalConversionsUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Bytes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.BytesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Packets;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.PacketsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMapBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-
-public class FlowStatisticsAdapter implements OpendaylightFlowStatisticsService, IReadServiceListener{
-
- private static final Logger LOG = LoggerFactory.getLogger(FlowStatisticsAdapter.class);
- private IReadService readDelegate;
- private NotificationProviderService notifier;
-
- @Override
- public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
- GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
- //TODO: No supported API exist in AD-SAL, it can either be implemented by fetching all the stats of the flows and
- // generating aggregate flow statistics out of those individual flow stats.
- return null;
- }
-
- @Override
- public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
- GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
- //TODO: No supported API exist in AD-SAL, it can either be implemented by fetching all the stats of the flows and
- // generating aggregate flow statistics out of those individual flow stats.
- return null;
- }
-
- @Override
- public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
- GetAllFlowStatisticsFromFlowTableInput input) {
- GetAllFlowStatisticsFromFlowTableOutput rpcResultType = null;
- boolean rpcResultBool = false;
-
- try {
- Node adNode = NodeMapping.toADNode(input.getNode());
- List<FlowOnNode> flowsOnNode = readDelegate.readAllFlows(adNode);
- List<FlowAndStatisticsMapList> flowsStatistics = toOdFlowsStatistics(flowsOnNode);
- GetAllFlowStatisticsFromFlowTableOutputBuilder builder = new GetAllFlowStatisticsFromFlowTableOutputBuilder();
- builder.setTransactionId(new TransactionId(BigInteger.ZERO));
- rpcResultType = builder.setFlowAndStatisticsMapList(flowsStatistics).build();
-
- rpcResultBool = true;
- } catch (ConstructionException e) {
- LOG.error(e.getMessage());
- }
-
- return Futures.immediateFuture(RpcResultBuilder.<GetAllFlowStatisticsFromFlowTableOutput>
- status(rpcResultBool).withResult(rpcResultType).build());
- }
-
- /**
- * Essentially this API will return the same result as getAllFlowStatisticsFromFlowTable
- */
- @Override
- public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
- GetAllFlowsStatisticsFromAllFlowTablesInput input) {
-
- GetAllFlowsStatisticsFromAllFlowTablesOutput rpcResultType = null;
- boolean rpcResultBool = false;
-
- try {
- Node adNode = NodeMapping.toADNode(input.getNode());
- List<FlowOnNode> flowsOnNode = readDelegate.readAllFlows(adNode);
- List<FlowAndStatisticsMapList> flowsStatistics = toOdFlowsStatistics(flowsOnNode);
- GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder builder = new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder();
- builder.setTransactionId(new TransactionId(BigInteger.ZERO));
- rpcResultType = builder.setFlowAndStatisticsMapList(flowsStatistics).build();
-
- rpcResultBool = true;
- } catch (ConstructionException e) {
- LOG.error(e.getMessage());
- }
-
- return Futures.immediateFuture(RpcResultBuilder.<GetAllFlowsStatisticsFromAllFlowTablesOutput>
- status(rpcResultBool).withResult(rpcResultType).build());
- }
-
- @Override
- public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
- GetFlowStatisticsFromFlowTableInput input) {
- GetFlowStatisticsFromFlowTableOutput rpcResultType = null;
- boolean rpcResultBool = false;
-
- try {
- Node node = NodeMapping.toADNode(input.getNode());
- Flow flow = ToSalConversionsUtils.toFlow(input, null);
- FlowOnNode readFlow = readDelegate.readFlow(node, flow);
- List<FlowAndStatisticsMapList> flowOnNodeToFlowStatistics = new ArrayList<FlowAndStatisticsMapList>();
- flowOnNodeToFlowStatistics.add(toOdFlowStatistics(readFlow));
- rpcResultType = new GetFlowStatisticsFromFlowTableOutputBuilder().setFlowAndStatisticsMapList(flowOnNodeToFlowStatistics).build();
- rpcResultBool = true;
- } catch (ConstructionException e) {
- LOG.error(e.getMessage());
- }
-
- return Futures.immediateFuture(RpcResultBuilder.<GetFlowStatisticsFromFlowTableOutput>
- status(rpcResultBool).withResult(rpcResultType).build());
- }
-
- @Override
- public void nodeFlowStatisticsUpdated(Node node, List<FlowOnNode> flowStatsList) {
- List<FlowAndStatisticsMapList> flowStatistics = toOdFlowsStatistics(flowStatsList);
- FlowsStatisticsUpdateBuilder flowsStatisticsUpdateBuilder = new FlowsStatisticsUpdateBuilder();
- flowsStatisticsUpdateBuilder.setFlowAndStatisticsMapList(flowStatistics);
- flowsStatisticsUpdateBuilder.setMoreReplies(false);
- flowsStatisticsUpdateBuilder.setTransactionId(null);
- flowsStatisticsUpdateBuilder.setId(InventoryMapping.toNodeKey(node).getId());
- notifier.publish(flowsStatisticsUpdateBuilder.build());
- }
-
- @Override
- public void nodeConnectorStatisticsUpdated(Node node, List<NodeConnectorStatistics> ncStatsList) {
- NodeConnectorStatisticsUpdateBuilder nodeConnectorStatisticsUpdateBuilder = new NodeConnectorStatisticsUpdateBuilder();
- List<NodeConnectorStatisticsAndPortNumberMap> nodeConnectorStatistics = toOdNodeConnectorStatistics(ncStatsList);
-
- nodeConnectorStatisticsUpdateBuilder.setNodeConnectorStatisticsAndPortNumberMap(nodeConnectorStatistics);
- nodeConnectorStatisticsUpdateBuilder.setMoreReplies(false);
- nodeConnectorStatisticsUpdateBuilder.setTransactionId(null);
- nodeConnectorStatisticsUpdateBuilder.setId(InventoryMapping.toNodeKey(node).getId());
- notifier.publish(nodeConnectorStatisticsUpdateBuilder.build());
- }
-
- @Override
- public void nodeTableStatisticsUpdated(Node node, List<NodeTableStatistics> tableStatsList) {
-
- FlowTableStatisticsUpdateBuilder flowTableStatisticsUpdateBuilder = new FlowTableStatisticsUpdateBuilder();
-
- List<FlowTableAndStatisticsMap> flowTableStatistics = toOdFlowTableStatistics(tableStatsList);
- flowTableStatisticsUpdateBuilder.setFlowTableAndStatisticsMap(flowTableStatistics);
- flowTableStatisticsUpdateBuilder.setMoreReplies(false);
- flowTableStatisticsUpdateBuilder.setTransactionId(null);
- flowTableStatisticsUpdateBuilder.setId(InventoryMapping.toNodeKey(node).getId());
- notifier.publish(flowTableStatisticsUpdateBuilder.build());
-}
-
- @Override
- public void descriptionStatisticsUpdated(Node node, NodeDescription nodeDescription) {
- // TODO which *StatisticsUpdated interface should be used?
-
- }
-
- private List<FlowAndStatisticsMapList> toOdFlowsStatistics(List<FlowOnNode> flowsOnNode) {
- List<FlowAndStatisticsMapList> flowsStatistics = new ArrayList<>();
- for (FlowOnNode flowOnNode : flowsOnNode) {
- flowsStatistics.add(toOdFlowStatistics(flowOnNode));
- }
- return flowsStatistics;
- }
-
- private FlowAndStatisticsMapList toOdFlowStatistics(FlowOnNode flowOnNode) {
- FlowAndStatisticsMapListBuilder builder = new FlowAndStatisticsMapListBuilder();
-
- builder.setByteCount(toCounter64(flowOnNode.getByteCount()));
- builder.setPacketCount(toCounter64(flowOnNode.getPacketCount()));
- builder.setDuration(extractDuration(flowOnNode));
- builder.setMatch(FromSalConversionsUtils.toMatch(flowOnNode.getFlow().getMatch()));
- builder.setPriority((int)flowOnNode.getFlow().getPriority());
- builder.setHardTimeout((int)flowOnNode.getFlow().getHardTimeout());
- builder.setIdleTimeout((int)flowOnNode.getFlow().getIdleTimeout());
- //TODO: actions to instruction conversion
- builder.setInstructions(null);
- return builder.build();
- }
-
- private org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.Duration extractDuration(FlowOnNode flowOnNode) {
- DurationBuilder builder = new DurationBuilder();
- builder.setNanosecond(new Counter32((long)flowOnNode.getDurationNanoseconds()));
- builder.setSecond(new Counter32((long)flowOnNode.getDurationSeconds()));
- return builder.build();
- }
-
- private Counter64 toCounter64(long num) {
- String byteCountStr = String.valueOf(num);
- BigInteger byteCountBigInt = new BigInteger(byteCountStr);
- return new Counter64(byteCountBigInt);
- }
-
- private List<FlowTableAndStatisticsMap> toOdFlowTableStatistics(List<NodeTableStatistics> tableStatsList) {
-
- List<FlowTableAndStatisticsMap> flowTableStatsMap = new ArrayList<FlowTableAndStatisticsMap>();
- for (NodeTableStatistics nodeTableStatistics : tableStatsList) {
- FlowTableAndStatisticsMapBuilder flowTableAndStatisticsMapBuilder = new FlowTableAndStatisticsMapBuilder();
- flowTableAndStatisticsMapBuilder.setActiveFlows(new Counter32((long) nodeTableStatistics.getActiveCount()));
- flowTableAndStatisticsMapBuilder.setPacketsLookedUp(toCounter64(nodeTableStatistics.getLookupCount()));
- flowTableAndStatisticsMapBuilder.setPacketsMatched(toCounter64(nodeTableStatistics.getMatchedCount()));
- flowTableAndStatisticsMapBuilder.setActiveFlows(new Counter32((long) nodeTableStatistics.getActiveCount()));
- flowTableAndStatisticsMapBuilder.setTableId(new TableId((short)nodeTableStatistics.getNodeTable().getID()));
- flowTableStatsMap.add(flowTableAndStatisticsMapBuilder.build());
- }
-
- return flowTableStatsMap;
- }
-
- private List<NodeConnectorStatisticsAndPortNumberMap> toOdNodeConnectorStatistics(
- List<NodeConnectorStatistics> ncStatsList) {
- List<NodeConnectorStatisticsAndPortNumberMap> nodeConnectorStatisticsList = new ArrayList<NodeConnectorStatisticsAndPortNumberMap>();
- for(NodeConnectorStatistics ofNodeConnectorStatistics : ncStatsList){
- NodeConnectorStatisticsAndPortNumberMapBuilder nodeConnectorStatisticsAndPortNumberMapBuilder = new NodeConnectorStatisticsAndPortNumberMapBuilder();
-
- nodeConnectorStatisticsAndPortNumberMapBuilder.setBytes(extractBytes(ofNodeConnectorStatistics));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setCollisionCount(toBI(ofNodeConnectorStatistics.getCollisionCount()));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setDuration(null);
- nodeConnectorStatisticsAndPortNumberMapBuilder.setPackets(extractPackets(ofNodeConnectorStatistics));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setReceiveCrcError(toBI(ofNodeConnectorStatistics.getReceiveCRCErrorCount()));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setReceiveDrops(toBI(ofNodeConnectorStatistics.getReceiveDropCount()));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setReceiveErrors(toBI(ofNodeConnectorStatistics.getReceiveErrorCount()));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setReceiveFrameError(toBI(ofNodeConnectorStatistics.getReceiveFrameErrorCount()));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setReceiveOverRunError(toBI(ofNodeConnectorStatistics.getReceiveOverRunErrorCount()));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setTransmitDrops(toBI(ofNodeConnectorStatistics.getTransmitDropCount()));
- nodeConnectorStatisticsAndPortNumberMapBuilder.setTransmitErrors(toBI(ofNodeConnectorStatistics.getTransmitErrorCount()));
- nodeConnectorStatisticsList.add(nodeConnectorStatisticsAndPortNumberMapBuilder.build());
- }
-
- return nodeConnectorStatisticsList;
- }
-
- private BigInteger toBI(long num) {
- String numStr = String.valueOf(num);
- return new BigInteger(numStr);
- }
-
- private Packets extractPackets(NodeConnectorStatistics nodeConnectorStatistics) {
- long receivePacketCount = nodeConnectorStatistics.getReceivePacketCount();
- long transmitPacketCount = nodeConnectorStatistics.getTransmitPacketCount();
-
- PacketsBuilder builder = new PacketsBuilder();
- builder.setReceived(toBI(receivePacketCount));
- builder.setTransmitted(toBI(transmitPacketCount));
-
- return builder.build();
- }
-
- private Bytes extractBytes(NodeConnectorStatistics nodeConnectorStatistics) {
- long transmitByteCount = nodeConnectorStatistics.getTransmitByteCount();
- long receiveByteCount = nodeConnectorStatistics.getReceiveByteCount();
-
- BytesBuilder builder = new BytesBuilder();
- builder.setReceived(toBI(receiveByteCount));
- builder.setTransmitted(toBI(transmitByteCount));
-
- return builder.build();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.topology;
-
-import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
-import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
-import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-import com.google.common.base.Preconditions;
-
-public class TopologyAdapter implements IPluginInTopologyService {
- private final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(new TopologyId("flow:1"))).toInstance();
-
- // Injected via Apache DM
- private IPluginOutTopologyService topologyPublisher;
-
-
- private DataProviderService dataService;
-
- public void setDataService(final DataProviderService dataService) {
- this.dataService = Preconditions.checkNotNull(dataService);
- }
-
- @Override
- public void sollicitRefresh() {
- final TypeSafeDataReader reader = TypeSafeDataReader.forReader(dataService);
- final Topology t = reader.readOperationalData(topology);
- topologyPublisher.edgeUpdate(TopologyMapping.toADEdgeUpdates(t, reader));
- }
-
- public IPluginOutTopologyService getTopologyPublisher() {
- return topologyPublisher;
- }
-
- public void setTopologyPublisher(final IPluginOutTopologyService topologyPublisher) {
- this.topologyPublisher = topologyPublisher;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.topology;
-
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyMapping.toAdEdge;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyMapping.toTopoEdgeUpdate;
-
-import java.util.Map.Entry;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
-import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
-import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
-import org.opendaylight.controller.sal.core.UpdateType;
-import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
-import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TopologyCommitHandler implements DataChangeListener {
- private static final Logger LOG = LoggerFactory.getLogger(TopologyCommitHandler.class);
-
- private IPluginOutTopologyService topologyPublisher;
-
- private final DataProviderService dataService;
-
- public TopologyCommitHandler(final DataProviderService dataService, final IPluginOutTopologyService topologyPub) {
- this.topologyPublisher = topologyPub;
- this.dataService = dataService;
- }
-
- @Override
- public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> modification) {
- CopyOnWriteArrayList<TopoEdgeUpdate> msg = new CopyOnWriteArrayList<TopoEdgeUpdate>();
- try {
- TypeSafeDataReader reader = TypeSafeDataReader.forReader(dataService);
- InstanceIdentifier<Topology> topologyPath = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(new TopologyId("flow:1"))).build();
- Topology topology = reader.readOperationalData(topologyPath);
-
- for (Entry<InstanceIdentifier<? extends DataObject>, DataObject> entry : modification
- .getCreatedOperationalData().entrySet()) {
- if (entry.getValue() instanceof Link
- && modification.getCreatedOperationalData().containsKey(entry.getKey())) {
- msg.add(toTopoEdgeUpdate(toAdEdge((Link) entry.getValue(), topology), UpdateType.ADDED, reader));
- }
- }
-
- for (Entry<InstanceIdentifier<? extends DataObject>, DataObject> entry : modification
- .getUpdatedOperationalData().entrySet()) {
- if (entry.getValue() instanceof Link) {
- msg.add(toTopoEdgeUpdate(toAdEdge((Link) entry.getValue(), topology), UpdateType.CHANGED, reader));
- }
- }
- for (InstanceIdentifier<? extends DataObject> path : modification.getRemovedOperationalData()) {
- if (path.getTargetType() == Link.class) {
- Link link = (Link) modification.getOriginalOperationalData().get(path);
- msg.add(toTopoEdgeUpdate(toAdEdge(link, topology), UpdateType.REMOVED, reader));
- }
-
- }
-
- if (topologyPublisher != null && msg != null && !msg.isEmpty()) {
- topologyPublisher.edgeUpdate(msg);
- }
-
- } catch (Exception e) {
- LOG.error("Exception caught", e);
- }
- }
-
- protected IPluginOutTopologyService getTopologyPublisher() {
- return topologyPublisher;
- }
-
- protected void setTopologyPublisher(final IPluginOutTopologyService topologyPublisher) {
- this.topologyPublisher = topologyPublisher;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.topology;
-
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-
-import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Edge;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.Node.NodeIDType;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
-import org.opendaylight.controller.sal.core.Property;
-import org.opendaylight.controller.sal.core.UpdateType;
-import org.opendaylight.controller.sal.topology.TopoEdgeUpdate;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.regex.Pattern;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public final class TopologyMapping {
- private static final Logger LOG = LoggerFactory.getLogger(TopologyMapping.class);
- private final static Pattern NUMBERS_ONLY = Pattern.compile("[0-9]+");
-
- private TopologyMapping() {
- throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
- }
-
- public static List<TopoEdgeUpdate> toADEdgeUpdates(final Topology topology,final TypeSafeDataReader reader) {
- final List<TopoEdgeUpdate> result = new CopyOnWriteArrayList<>();
- return FluentIterable.from(topology.getLink()).transform(
- new Function<Link, TopoEdgeUpdate>() {
- @Override
- public TopoEdgeUpdate apply(final Link input) {
- try {
- return toTopoEdgeUpdate(toAdEdge(input, topology), reader);
- } catch (ConstructionException e) {
- throw new IllegalArgumentException(String.format("Failed to construct edge update for {}", input), e);
- }
- }}
- ).copyInto(result);
- }
-
- public static Edge toAdEdge(final Link link, final Topology topology) throws ConstructionException {
- final NodeConnector adSrc = toADNodeConnector(link.getSource().getSourceTp(), link.getSource().getSourceNode());
- final NodeConnector adDst = toADNodeConnector(link.getDestination().getDestTp(), link.getDestination().getDestNode());
- return new Edge(adSrc, adDst);
- }
-
- public static TopoEdgeUpdate toTopoEdgeUpdate(final Edge e, final TypeSafeDataReader reader) {
- return toTopoEdgeUpdate(e, UpdateType.ADDED, reader);
- }
-
- public static TopoEdgeUpdate toTopoEdgeUpdate(final Edge e,final UpdateType type,final TypeSafeDataReader reader) {
- return new TopoEdgeUpdate(e, toAdEdgeProperties(e, reader), type);
- }
-
- public static Set<Property> toAdEdgeProperties(final Edge e,final TypeSafeDataReader reader) {
- final NodeConnectorRef ncref = NodeMapping.toNodeConnectorRef(e.getTailNodeConnector());
- if(ncref == null) {
- LOG.debug("Edge {} ncref {}",e,ncref);
- return null;
- }
-
- @SuppressWarnings("unchecked")
- final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector> ncInstanceId =
- (InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector>) ncref.getValue();
- if(ncInstanceId == null) {
- LOG.debug("Edge {} ncref {}",e,ncref);
- return null;
- }
-
- final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc = reader.readOperationalData(ncInstanceId);
- if(nc == null) {
- return null;
- }
- return NodeMapping.toADNodeConnectorProperties(nc);
- }
-
- public static String toADNodeId(final NodeId nodeId) {
- return nodeId.getValue().replaceFirst("^.*:", "");
- }
-
- public static NodeConnector toADNodeConnector(final TpId source, final NodeId nodeId) throws ConstructionException {
- checkNotNull(source);
- String nodeConnectorIdStripped = toADNodeConnectorId(source);
- if (NUMBERS_ONLY.matcher(nodeConnectorIdStripped).matches()) {
- return new NodeConnector(NodeConnectorIDType.OPENFLOW, Short.valueOf(nodeConnectorIdStripped), toADNode(nodeId));
- }
- LOG.debug("NodeConnectorId does not match openflow id type, using " + NodeMapping.MD_SAL_TYPE + "instead");
- NodeConnectorIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class, NodeMapping.MD_SAL_TYPE);
- return new NodeConnector(NodeMapping.MD_SAL_TYPE, nodeConnectorIdStripped, toADNode(nodeId));
- }
-
- public static String toADNodeConnectorId(final TpId nodeConnectorId) {
- return nodeConnectorId.getValue().replaceFirst("^.*:", "");
- }
-
- public static Node toADNode(final NodeId nodeId) throws ConstructionException {
- checkNotNull(nodeId);
- String nodeIdStripped = toADNodeId(nodeId);
- if (NUMBERS_ONLY.matcher(nodeIdStripped).matches()) {
- return new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeIdStripped));
- }
- LOG.debug("NodeId does not match openflow id type, using " + NodeMapping.MD_SAL_TYPE + "instead");
- NodeIDType.registerIDType(NodeMapping.MD_SAL_TYPE, String.class);
- return new Node(NodeMapping.MD_SAL_TYPE, nodeId.getValue());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.topology;
-
-import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
-import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-
-public class TopologyProvider implements AutoCloseable{
- private static final Logger LOG = LoggerFactory.getLogger(TopologyProvider.class);
- private static final InstanceIdentifier<Link> PATH = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class ,new TopologyKey(new TopologyId("flow:1")))
- .child(Link.class)
- .toInstance();
- private TopologyCommitHandler commitHandler;
-
- private ListenerRegistration<DataChangeListener> listenerRegistration;
- private IPluginOutTopologyService topologyPublisher;
- private DataProviderService dataService;
-
- public void startAdapter() {
- if(dataService == null){
- LOG.error("dataService not set");
- return;
- }
- commitHandler = new TopologyCommitHandler(dataService,topologyPublisher);
- listenerRegistration = dataService.registerDataChangeListener(PATH, commitHandler);
- LOG.info("TopologyProvider started");
- }
-
- @Override
- public void close() {
- if (listenerRegistration != null) {
- listenerRegistration.close();
- }
- }
-
- void setTopologyPublisher(final IPluginOutTopologyService topologyPublisher) {
- this.topologyPublisher = topologyPublisher;
- if (commitHandler != null) {
- commitHandler.setTopologyPublisher(topologyPublisher);
- }
- }
-
- public void setDataService(final DataProviderService dataService) {
- this.dataService = Preconditions.checkNotNull(dataService);
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.test;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.FromSalConversionsUtils;
-
-/**
- * test of {@link FromSalConversionsUtils}
- */
-public class FromSalConversionsUtilsTest {
-
- /**
- * Test method for {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.FromSalConversionsUtils#dscpToTos(int)}.
- */
- @Test
- public void testDscpToTos() {
- Assert.assertEquals(0, FromSalConversionsUtils.dscpToTos(0));
- Assert.assertEquals(4, FromSalConversionsUtils.dscpToTos(1));
- Assert.assertEquals(252, FromSalConversionsUtils.dscpToTos(63));
- Assert.assertEquals(256, FromSalConversionsUtils.dscpToTos(64));
- Assert.assertEquals(-4, FromSalConversionsUtils.dscpToTos(-1));
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.test;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.controller.sal.action.Action;
-import org.opendaylight.controller.sal.action.PushVlan;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.Node.NodeIDType;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
-import org.opendaylight.controller.sal.utils.EtherTypes;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.MDFlowMapping;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
-
-/**
- * test for {@link MDFlowMapping}
- */
-public class MDFlowMappingTest {
-
- /**
- * Test method for {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.MDFlowMapping#toUri(org.opendaylight.controller.sal.core.NodeConnector)}.
- * @throws ConstructionException
- */
- @Test
- public void testToUri() throws ConstructionException {
- Node node = new Node(NodeIDType.OPENFLOW, 41L);
- NodeConnector connector = new NodeConnector(NodeConnectorIDType.OPENFLOW, (short) 42, node);
- Uri observed = MDFlowMapping.toUri(connector );
-
- Assert.assertEquals("openflow:41:42", observed.getValue());
- }
-
- /**
- * Test method for {@link MDFlowMapping#toAction(Action, int)}.
- */
- @Test
- public void testToAction() {
- // PUSH_VLAN test.
- EtherTypes[] tags = {EtherTypes.VLANTAGGED, EtherTypes.QINQ};
- int order = 0;
- for (EtherTypes tag: tags) {
- Action action = new PushVlan(tag);
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.
- rev131112.action.list.Action mdActionList =
- MDFlowMapping.toAction(action, order);
- Assert.assertEquals(order, mdActionList.getOrder().intValue());
-
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.
- rev131112.action.Action mdAction = mdActionList.getAction();
- Assert.assertTrue(mdAction instanceof PushVlanActionCase);
- PushVlanActionCase pushVlan = (PushVlanActionCase)mdAction;
- Assert.assertEquals(tag.intValue(),
- pushVlan.getPushVlanAction().getEthernetType().
- intValue());
- order++;
- }
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2013 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.test;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.MacAddress;
-import org.opendaylight.controller.sal.core.Node.NodeIDType;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-/**
- * test of {@link NodeMapping} utility class
- */
-public class NodeMappingTest {
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#toADMacAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)}
- * .
- */
- @Test
- public void testToADMacAddress() {
- NodeId[] nodeIds = new NodeId[] {
- // 0x0000|0000 0000002a (answer to the ultimate question of life, universe and everything)
- new NodeId("42"),
- // 0x7fff|ffff ffffffff (max long -> 2**63 - 1)
- new NodeId("9223372036854775807"),
- // 0x7fff|7fff ffffffff
- new NodeId("9223231299366420479"),
- // 0x8fff|7fff ffffffff (more than biggest positive long)
- new NodeId("10376152803973267455"),
- // 0xca13|764a e9ace65a (BUG-770)
- new NodeId("14561112084339025498")
- };
-
- byte[][] expectedMacs = new byte[][] {
- {0, 0, 0, 0, 0, 0x2a},
- {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff},
- {(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff},
- {(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff},
- {(byte) 0x76, (byte) 0x4a, (byte) 0xe9, (byte) 0xac, (byte) 0xe6, (byte) 0x5a}
- };
-
- Assert.assertEquals(expectedMacs.length, nodeIds.length);
-
- for (int i = 0; i < expectedMacs.length; i++) {
- NodeId nodeId = nodeIds[i];
- MacAddress mac = NodeMapping.toADMacAddress(nodeId);
- Assert.assertArrayEquals(expectedMacs[i], mac.getMacAddress());
- }
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#toAdNodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)}
- * .
- */
- @Test
- public void testToAdNodeId() {
- NodeId observed;
- observed = NodeMapping.toAdNodeId(null);
- Assert.assertNull(observed);
-
- observed = NodeMapping.toAdNodeId(new NodeConnectorId("openflow:5:2"));
- Assert.assertEquals("openflow:5", observed.getValue());
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#toADNode(NodeId)}
- * .
- */
- @Test
- public void testToAdNode1() {
- org.opendaylight.controller.sal.core.Node observed;
- try {
- observed = NodeMapping.toADNode((NodeId) null);
- } catch (NullPointerException | ConstructionException e) {
- //expected
- }
-
- NodeId nodeId = new NodeId("openflow:1");
- try {
- observed = NodeMapping.toADNode(nodeId);
- Assert.assertEquals("OF|00:00:00:00:00:00:00:01", observed.toString());
- } catch (ConstructionException e) {
- Assert.fail("should succeed to construct Node: "+e.getMessage());
- }
-
- final String nodeUriPrefix = "opendaylight-inventory:nodes/node/";
- nodeId = new NodeId(nodeUriPrefix + "iosv-2");
- try {
- observed = NodeMapping.toADNode(nodeId);
- Assert.assertEquals("PR|opendaylight-inventory:nodes/node/iosv-2", observed.toString());
- } catch (ConstructionException e) {
- Assert.fail("should succeed to construct Node: "+e.getMessage());
- }
-
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#toNodeConnectorType(NodeConnectorId, NodeId)}
- * .
- */
- @Test
- public void testToNodeConnectorType() {
- NodeConnectorId ncId;
- NodeId nodeId = buildNodeId("1");
-
- ncId = buildNodeConnectorId("1", "42");
- Assert.assertEquals(NodeConnectorIDType.OPENFLOW, NodeMapping.toNodeConnectorType(ncId, nodeId ));
-
- ncId = buildNodeConnectorId("1", OutputPortValues.CONTROLLER.toString());
- Assert.assertEquals(NodeConnectorIDType.CONTROLLER, NodeMapping.toNodeConnectorType(ncId, nodeId ));
-
- ncId = buildNodeConnectorId("1", OutputPortValues.NORMAL.toString());
- Assert.assertEquals(NodeConnectorIDType.HWPATH, NodeMapping.toNodeConnectorType(ncId, nodeId ));
-
- ncId = buildNodeConnectorId("1", OutputPortValues.LOCAL.toString());
- Assert.assertEquals(NodeConnectorIDType.SWSTACK, NodeMapping.toNodeConnectorType(ncId, nodeId ));
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#toADNodeConnectorId(NodeConnectorId, NodeId)}
- * .
- */
- @Test
- public void testToAdNodeConnectorId() {
- NodeConnectorId nodeConnectorId = buildNodeConnectorId("1", "2");
- NodeId nodeId = buildNodeId("1");
- Assert.assertEquals(Short.valueOf((short) 2), NodeMapping.toADNodeConnectorId(nodeConnectorId , nodeId));
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#toNodeRef(Node)}
- * .
- * @throws ConstructionException
- */
- @Test
- public void testToNodeRef() throws ConstructionException {
- org.opendaylight.controller.sal.core.Node node = new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, 42L);
- InstanceIdentifier<?> nodePath = NodeMapping.toNodeRef(node).getValue();
-
- String observedId = nodePath.firstKeyOf(Node.class, NodeKey.class).getId().getValue();
- Assert.assertEquals("openflow:42", observedId);
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#toNodeConnectorRef(org.opendaylight.controller.sal.core.NodeConnector)}
- * .
- * @throws ConstructionException
- */
- @Test
- public void testToNodeConnectorRef() throws ConstructionException {
- org.opendaylight.controller.sal.core.Node node = new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, 42L);
- org.opendaylight.controller.sal.core.NodeConnector nodeConnector =
- new org.opendaylight.controller.sal.core.NodeConnector(
- NodeConnectorIDType.OPENFLOW, (short) 1, node);
-
- InstanceIdentifier<?> nodeConnectorPath = NodeMapping.toNodeConnectorRef(nodeConnector ).getValue();
- String observedNodeId = nodeConnectorPath.firstKeyOf(Node.class, NodeKey.class).getId().getValue();
- Assert.assertEquals("openflow:42", observedNodeId);
-
- String observedNodeConnectorId = nodeConnectorPath.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue();
- Assert.assertEquals("openflow:1", observedNodeConnectorId);
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#openflowFullNodeIdToLong(String)}
- * .
- * @throws ConstructionException
- */
- @Test
- public void testOpenflowFullNodeIdToLong() throws ConstructionException {
- Assert.assertEquals(42L, NodeMapping.openflowFullNodeIdToLong("42").longValue());
- Assert.assertEquals(0xCC4E241C4A000000L, NodeMapping.openflowFullNodeIdToLong("14721743935839928320").longValue());
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#toNodeKey(org.opendaylight.controller.sal.core.Node)}
- * .
- * @throws ConstructionException
- */
- @Test
- public void testToNodeKey() throws ConstructionException {
- org.opendaylight.controller.sal.core.Node aDNode = new org.opendaylight.controller.sal.core.Node(NodeIDType.OPENFLOW, 42L);
- NodeKey nodeKey = NodeMapping.toNodeKey(aDNode);
- Assert.assertEquals("openflow:42", nodeKey.getId().getValue());
- }
-
- /**
- * Test method for
- * {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.NodeMapping#stripToColon(NodeConnectorId)}
- * .
- * @throws ConstructionException
- */
- @Test
- public void testStripToColon() {
- Assert.assertEquals("1", NodeMapping.stripToColon("openflow:42:1"));
- Assert.assertEquals("1", NodeMapping.stripToColon("openflow:1"));
- Assert.assertEquals("1", NodeMapping.stripToColon("1"));
- }
-
- /**
- * @param nodeId
- * @param portId
- * @return nodeConnectorId
- */
- public static NodeConnectorId buildNodeConnectorId(String nodeId, String portId) {
- return new NodeConnectorId(NodeConnectorIDType.OPENFLOW+"|" + nodeId + ":" + portId);
- }
-
- /**
- * @param id
- * @return nodeId
- */
- public static NodeId buildNodeId(String id) {
- return new NodeId(NodeConnectorIDType.OPENFLOW+"|" + id);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013-2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.CRUDP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.ETHERNET_ARP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.TCP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.UDP;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-import org.opendaylight.controller.sal.action.Action;
-import org.opendaylight.controller.sal.action.Flood;
-import org.opendaylight.controller.sal.action.FloodAll;
-import org.opendaylight.controller.sal.action.HwPath;
-import org.opendaylight.controller.sal.action.Loopback;
-import org.opendaylight.controller.sal.action.PopVlan;
-import org.opendaylight.controller.sal.action.PushVlan;
-import org.opendaylight.controller.sal.action.SetDlDst;
-import org.opendaylight.controller.sal.action.SetDlSrc;
-import org.opendaylight.controller.sal.action.SetDlType;
-import org.opendaylight.controller.sal.action.SetNextHop;
-import org.opendaylight.controller.sal.action.SetNwDst;
-import org.opendaylight.controller.sal.action.SetNwSrc;
-import org.opendaylight.controller.sal.action.SetNwTos;
-import org.opendaylight.controller.sal.action.SetTpDst;
-import org.opendaylight.controller.sal.action.SetTpSrc;
-import org.opendaylight.controller.sal.action.SetVlanCfi;
-import org.opendaylight.controller.sal.action.SetVlanId;
-import org.opendaylight.controller.sal.action.SetVlanPcp;
-import org.opendaylight.controller.sal.action.SwPath;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.Node.NodeIDType;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
-import org.opendaylight.controller.sal.flowprogrammer.Flow;
-import org.opendaylight.controller.sal.match.Match;
-import org.opendaylight.controller.sal.match.MatchType;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.MDFlowMapping;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.ToSalConversionsUtils;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch;
-
-import com.google.common.net.InetAddresses;
-
-public class TestFromSalConversionsUtils {
- private enum MtchType {
- other, untagged, ipv4, ipv6, arp, sctp, tcp, udp
- }
-
- @Test
- public void testFromSalConversion() throws ConstructionException {
-
- Flow salFlow = prepareSalFlowCommon();
- NodeFlow odNodeFlow = MDFlowMapping.flowAdded(salFlow);
-
- checkOdFlow(odNodeFlow);
-
- odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.other));
- checkOdMatch(odNodeFlow.getMatch(), MtchType.other);
-
- odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.untagged));
- checkOdMatch(odNodeFlow.getMatch(), MtchType.untagged);
-
- odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.arp));
- checkOdMatch(odNodeFlow.getMatch(), MtchType.arp);
-
- odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.ipv4));
- checkOdMatch(odNodeFlow.getMatch(), MtchType.ipv4);
-
- odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.ipv6));
- checkOdMatch(odNodeFlow.getMatch(), MtchType.ipv6);
-
- odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.sctp));
- checkOdMatch(odNodeFlow.getMatch(), MtchType.sctp);
-
- odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.tcp));
- checkOdMatch(odNodeFlow.getMatch(), MtchType.tcp);
-
- odNodeFlow = MDFlowMapping.flowAdded(prepareSalMatch(salFlow, MtchType.udp));
- checkOdMatch(odNodeFlow.getMatch(), MtchType.udp);
- }
-
- private void checkOdMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match match,
- MtchType mt) {
- switch (mt) {
- case arp:
- assertEquals("Ether type is incorrect.", ETHERNET_ARP, (long) match.getEthernetMatch().getEthernetType()
- .getType().getValue());
- Layer3Match layer3Match = match.getLayer3Match();
- boolean arpFound = false;
- if (layer3Match instanceof ArpMatch) {
- assertEquals("Source IP address is wrong.", "192.168.100.100/32", ((ArpMatch) layer3Match)
- .getArpSourceTransportAddress().getValue());
- assertEquals("Destination IP address is wrong.", "192.168.100.101/32", ((ArpMatch) layer3Match)
- .getArpTargetTransportAddress().getValue());
- assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", ((ArpMatch) layer3Match)
- .getArpSourceHardwareAddress().getAddress().getValue());
- assertEquals("Destination MAC address is wrong.", "ff:ee:dd:cc:bb:aa", ((ArpMatch) layer3Match)
- .getArpTargetHardwareAddress().getAddress().getValue());
- arpFound = true;
- }
- assertNotNull("Arp wasn't found", arpFound);
- break;
- case ipv4:
- assertEquals("Ether type is incorrect.", 0xffff, (long) match.getEthernetMatch().getEthernetType()
- .getType().getValue());
- boolean ipv4Found = false;
- layer3Match = match.getLayer3Match();
- if (layer3Match instanceof Ipv4Match) {
- assertEquals("Source IP address is wrong.", "192.168.100.102/32", ((Ipv4Match) layer3Match)
- .getIpv4Source().getValue());
- assertEquals("Destination IP address is wrong.", "192.168.100.103/32", ((Ipv4Match) layer3Match)
- .getIpv4Destination().getValue());
- }
- assertNotNull("Ipv4 wasn't found", ipv4Found);
- break;
- case ipv6:
- assertEquals("Ether type is incorrect.", 0xffff, (long) match.getEthernetMatch().getEthernetType()
- .getType().getValue());
- boolean ipv6Found = false;
- layer3Match = match.getLayer3Match();
- if (layer3Match instanceof Ipv6Match) {
- assertEquals("Source IP address is wrong.", "2001:db8:85a3::8a2e:370:7335/128", ((Ipv6Match) layer3Match)
- .getIpv6Source().getValue());
- assertEquals("Destination IP address is wrong.", "2001:db8:85a3::8a2e:370:7336/128",
- ((Ipv6Match) layer3Match).getIpv6Destination().getValue());
- }
- assertNotNull("Ipv6 wasn't found", ipv6Found);
- break;
- case other:
- assertEquals("Incoming port is wrong.", "openflow:12345:10", match.getInPort().getValue());
- assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch()
- .getEthernetSource().getAddress().getValue());
- assertEquals("Destinatio MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch()
- .getEthernetDestination().getAddress().getValue());
- assertEquals("Vlan ID is not present.", Boolean.TRUE, match.getVlanMatch().getVlanId().isVlanIdPresent());
- assertEquals("Vlan ID is wrong.", (Integer) 0xfff, match.getVlanMatch().getVlanId().getVlanId().getValue());
- assertEquals("Vlan ID priority is wrong.", (short) 0x7, (short) match.getVlanMatch().getVlanPcp()
- .getValue());
- assertEquals("DCSP is wrong.", (short) 0x3f, (short) match.getIpMatch().getIpDscp().getValue());
- break;
- case untagged:
- assertEquals("Source MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch()
- .getEthernetSource().getAddress().getValue());
- assertEquals("Destinatio MAC address is wrong.", "ff:ee:dd:cc:bb:aa", match.getEthernetMatch()
- .getEthernetDestination().getAddress().getValue());
- assertEquals("Vlan ID is present.", Boolean.FALSE, match.getVlanMatch().getVlanId().isVlanIdPresent());
- assertEquals("Vlan ID is wrong.", Integer.valueOf(0), match.getVlanMatch().getVlanId().getVlanId().getValue());
- assertEquals("DCSP is wrong.", (short) 0x3f, (short) match.getIpMatch().getIpDscp().getValue());
- break;
- case sctp:
- boolean sctpFound = false;
- assertEquals("Wrong protocol", CRUDP, match.getIpMatch().getIpProtocol().byteValue());
- Layer4Match layer4Match = match.getLayer4Match();
- if (layer4Match instanceof SctpMatch) {
- assertEquals("Sctp source port is incorrect.", 0xffff, (int) ((SctpMatch) layer4Match)
- .getSctpSourcePort().getValue());
- assertEquals("Sctp dest port is incorrect.", 0xfffe, (int) ((SctpMatch) layer4Match)
- .getSctpDestinationPort().getValue());
- sctpFound = true;
- }
- assertNotNull("Sctp wasn't found", sctpFound);
- break;
- case tcp:
- boolean tcpFound = false;
- assertEquals("Wrong protocol", TCP, match.getIpMatch().getIpProtocol().byteValue());
- layer4Match = match.getLayer4Match();
- if (layer4Match instanceof TcpMatch) {
- assertEquals("Tcp source port is incorrect.", 0xabcd, (int) ((TcpMatch) layer4Match)
- .getTcpSourcePort().getValue());
- assertEquals("Tcp dest port is incorrect.", 0xdcba, (int) ((TcpMatch) layer4Match)
- .getTcpDestinationPort().getValue());
- sctpFound = true;
- }
- assertNotNull("Tcp wasn't found", tcpFound);
- break;
- case udp:
- boolean udpFound = false;
- assertEquals("Wrong protocol", UDP, match.getIpMatch().getIpProtocol().byteValue());
- layer4Match = match.getLayer4Match();
- if (layer4Match instanceof UdpMatch) {
- assertEquals("Udp source port is incorrect.", 0xcdef, (int) ((UdpMatch) layer4Match)
- .getUdpSourcePort().getValue());
- assertEquals("Udp dest port is incorrect.", 0xfedc, (int) ((UdpMatch) layer4Match)
- .getUdpDestinationPort().getValue());
- sctpFound = true;
- }
- assertNotNull("Udp wasn't found", udpFound);
- break;
- }
-
- }
-
- private void checkOdFlow(NodeFlow odNodeFlow) {
- assertEquals("Cookie is incorrect.", 9223372036854775807L, odNodeFlow.getCookie().getValue().longValue());
- assertEquals("Hard timeout is incorrect.", 32765, odNodeFlow.getHardTimeout().shortValue());
- assertEquals("Iddle timeout is incorrect.", 32766, odNodeFlow.getIdleTimeout().shortValue());
- assertEquals("Priority is incorrect.", 32767, odNodeFlow.getPriority().shortValue());
-
- checkOdActions(ToSalConversionsUtils.getAction(odNodeFlow));
- }
-
- private void checkOdActions(
- List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions) {
- checkOdAction(actions, FloodActionCase.class);
- checkOdAction(actions, FloodAllActionCase.class);
- checkOdAction(actions, HwPathActionCase.class);
- checkOdAction(actions, LoopbackActionCase.class);
- checkOdAction(actions, PopVlanActionCase.class);
- checkOdAction(actions, PushVlanActionCase.class);
- checkOdAction(actions, SetDlDstActionCase.class);
- checkOdAction(actions, SetDlSrcActionCase.class);
- checkOdAction(actions, SetDlTypeActionCase.class);
- checkOdAction(actions, SetNwTosActionCase.class);
- checkOdAction(actions, SetNwDstActionCase.class);
- checkOdAction(actions, SetNwSrcActionCase.class);
- checkOdAction(actions, SetNextHopActionCase.class);
- checkOdAction(actions, SetTpDstActionCase.class);
- checkOdAction(actions, SetTpSrcActionCase.class);
- checkOdAction(actions, SetVlanCfiActionCase.class);
- checkOdAction(actions, SetVlanIdActionCase.class);
- checkOdAction(actions, SetVlanPcpActionCase.class);
- checkOdAction(actions, SwPathActionCase.class);
- }
-
- private void checkOdAction(
- List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions, Class<?> cl) {
- int numOfFoundActions = 0;
- for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action : actions) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action innerAction = action
- .getAction();
- if (cl.isInstance(innerAction)) {
- numOfFoundActions++;
- if (innerAction instanceof PushVlanActionCase) {
- assertEquals("Wrong value of tag in PushVlanAction.", (Integer) 0x8100,
- ((PushVlanActionCase) innerAction).getPushVlanAction().getEthernetType());
- } else if (innerAction instanceof SetDlDstActionCase) {
- assertEquals("Wrong MAC destination address in SetDlDstAction.", "ff:ee:dd:cc:bb:aa",
- ((SetDlDstActionCase) innerAction).getSetDlDstAction().getAddress().getValue());
- } else if (innerAction instanceof SetDlSrcActionCase) {
- assertEquals("Wrong MAC source address in SetDlDstAction.", "ff:ee:dd:cc:bb:aa",
- ((SetDlSrcActionCase) innerAction).getSetDlSrcAction().getAddress().getValue());
- } else if (innerAction instanceof SetDlTypeActionCase) {
- assertEquals("Wrong data link type in SetDlTypeAction.", 513,
- (long) ((SetDlTypeActionCase) innerAction).getSetDlTypeAction().getDlType().getValue());
- } else if (innerAction instanceof SetNextHopActionCase) {
- Address address = ((SetNextHopActionCase) innerAction).getSetNextHopAction().getAddress();
- boolean ipv4AddressFound = false;
- if (address instanceof Ipv4) {
- ipv4AddressFound = true;
- assertEquals("Wrong IP address type in SetNextHopAction.", "192.168.100.100/32", ((Ipv4) address)
- .getIpv4Address().getValue());
- }
- assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
- } else if (innerAction instanceof SetNwTosActionCase) {
- assertEquals("Wrong TOS in SetNwTosAction.", (Integer) 252, ((SetNwTosActionCase) innerAction).getSetNwTosAction().getTos());
- } else if (innerAction instanceof SetNwDstActionCase) {
- Address address = ((SetNwDstActionCase) innerAction).getSetNwDstAction().getAddress();
- boolean ipv4AddressFound = false;
- if (address instanceof Ipv4) {
- ipv4AddressFound = true;
- assertEquals("Wrong IP address type in SetNwDstAction.", "192.168.100.101/32", ((Ipv4) address)
- .getIpv4Address().getValue());
- }
- assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
- } else if (innerAction instanceof SetNwSrcActionCase) {
- Address address = ((SetNwSrcActionCase) innerAction).getSetNwSrcAction().getAddress();
- boolean ipv4AddressFound = false;
- if (address instanceof Ipv4) {
- ipv4AddressFound = true;
- assertEquals("Wrong IP address type in SetNwSrcAction.", "192.168.100.102/32", ((Ipv4) address)
- .getIpv4Address().getValue());
- }
- assertTrue("Ipv4 address wasn't found.", ipv4AddressFound);
- } else if (innerAction instanceof SetTpDstActionCase) {
- assertEquals("Port number is incorrect in SetTpDstAction.", (Integer) 65534,
- ((SetTpDstActionCase) innerAction).getSetTpDstAction().getPort().getValue());
- } else if (innerAction instanceof SetTpSrcActionCase) {
- assertEquals("Port number is incorrect in SetTpSrcAction.", (Integer) 65535,
- ((SetTpSrcActionCase) innerAction).getSetTpSrcAction().getPort().getValue());
- } else if (innerAction instanceof SetVlanCfiActionCase) {
- assertEquals("Vlan cfi number is incorrect in SetVlanCfiAction.", (Integer) 1,
- ((SetVlanCfiActionCase) innerAction).getSetVlanCfiAction().getVlanCfi().getValue());
- } else if (innerAction instanceof SetVlanIdActionCase) {
- assertEquals("Vlan id number is incorrect in SetVlanIdAction.", (Integer) 4095,
- ((SetVlanIdActionCase) innerAction).getSetVlanIdAction().getVlanId().getValue());
- } else if (innerAction instanceof SetVlanPcpActionCase) {
- assertEquals("Vlan pcp number is incorrect in SetVlanPcpAction.", new Short((short) 7),
- ((SetVlanPcpActionCase) innerAction).getSetVlanPcpAction().getVlanPcp().getValue());
- }
- }
- }
- assertEquals("Incorrrect number of action " + cl.getName() + ".", 1, numOfFoundActions);
-
- }
-
- private Flow prepareSalFlowCommon() {
- Flow salFlow = new Flow();
- salFlow.setId(9223372036854775807L);
- salFlow.setHardTimeout((short) 32765);
- salFlow.setIdleTimeout((short) 32766);
- salFlow.setPriority((short) 32767);
- salFlow.setActions(prepareSalActions());
- salFlow.setMatch(new Match());
-
- return salFlow;
- }
-
- private Flow prepareSalMatch(Flow salFlow, MtchType mt) throws ConstructionException {
- Match salMatch = new Match();
- switch (mt) {
- case arp:
- salMatch.setField(MatchType.DL_TYPE, ETHERNET_ARP);
- salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("192.168.100.100"));
- salMatch.setField(MatchType.NW_DST, InetAddresses.forString("192.168.100.101"));
- salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
- salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
- break;
- case ipv4:
- salMatch.setField(MatchType.DL_TYPE, (short) 0xffff);
- salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("192.168.100.102"));
- salMatch.setField(MatchType.NW_DST, InetAddresses.forString("192.168.100.103"));
- break;
- case ipv6:
- salMatch.setField(MatchType.DL_TYPE, (short) 0xffff);
- salMatch.setField(MatchType.NW_SRC, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7335"));
- salMatch.setField(MatchType.NW_DST, InetAddresses.forString("2001:0db8:85a3:0000:0000:8a2e:0370:7336"));
- break;
- case other:
- Node node = new Node(NodeIDType.OPENFLOW, 12345L);
- NodeConnector port = new NodeConnector(NodeConnectorIDType.OPENFLOW, Short.valueOf((short)10), node);
- salMatch.setField(MatchType.IN_PORT, port);
- salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
- salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
- salMatch.setField(MatchType.DL_VLAN, (short) 0xfff);
- salMatch.setField(MatchType.DL_VLAN_PR, (byte) 0x7);
- salMatch.setField(MatchType.NW_TOS, (byte) 0x3f);
- break;
- case untagged:
- salMatch.setField(MatchType.DL_SRC, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
- salMatch.setField(MatchType.DL_DST, new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa});
- salMatch.setField(MatchType.DL_VLAN, MatchType.DL_VLAN_NONE);
- salMatch.setField(MatchType.NW_TOS, (byte) 0x3f);
- break;
- case sctp:
- salMatch.setField(MatchType.NW_PROTO, CRUDP);
- salMatch.setField(MatchType.TP_SRC, (short) 0xffff);
- salMatch.setField(MatchType.TP_DST, (short) 0xfffe);
- break;
- case tcp:
- salMatch.setField(MatchType.NW_PROTO, TCP);
- salMatch.setField(MatchType.TP_SRC, (short) 0xabcd);
- salMatch.setField(MatchType.TP_DST, (short) 0xdcba);
- break;
- case udp:
- salMatch.setField(MatchType.NW_PROTO, UDP);
- salMatch.setField(MatchType.TP_SRC, (short) 0xcdef);
- salMatch.setField(MatchType.TP_DST, (short) 0xfedc);
- break;
- default:
- break;
-
- }
-
- salFlow.setMatch(salMatch);
- return salFlow;
- }
-
- private List<Action> prepareSalActions() {
- List<Action> salActions = new ArrayList<>();
- salActions.add(new Flood());
- salActions.add(new FloodAll());
- salActions.add(new HwPath());
- salActions.add(new Loopback());
- // salActions.add(new Output //TODO: mapping is missing
- salActions.add(new PopVlan());
- salActions.add(new PushVlan(0x8100));
- salActions.add(new SetDlDst(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}));
- salActions.add(new SetDlSrc(new byte[]{(byte )0xff,(byte )0xee,(byte )0xdd,(byte )0xcc,(byte )0xbb,(byte )0xaa}));
- salActions.add(new SetDlType(513));
- salActions.add(new SetNextHop(InetAddresses.forString("192.168.100.100")));
- salActions.add(new SetNwDst(InetAddresses.forString("192.168.100.101")));
- salActions.add(new SetNwSrc(InetAddresses.forString("192.168.100.102")));
- salActions.add(new SetNwTos(63));
- salActions.add(new SetTpDst(65534));
- salActions.add(new SetTpSrc(65535));
- salActions.add(new SetVlanCfi(1));
- salActions.add(new SetVlanId(4095));
- salActions.add(new SetVlanPcp(7));
- salActions.add(new SwPath());
-
- return salActions;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013-2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.CRUDP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.ETHERNET_ARP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.TCP;
-import static org.opendaylight.openflowplugin.legacy.sal.compatibility.ProtocolConstants.UDP;
-
-import com.google.common.net.InetAddresses;
-import java.math.BigInteger;
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.junit.Test;
-import org.opendaylight.controller.sal.action.Flood;
-import org.opendaylight.controller.sal.action.FloodAll;
-import org.opendaylight.controller.sal.action.HwPath;
-import org.opendaylight.controller.sal.action.Loopback;
-import org.opendaylight.controller.sal.action.Output;
-import org.opendaylight.controller.sal.action.PopVlan;
-import org.opendaylight.controller.sal.action.PushVlan;
-import org.opendaylight.controller.sal.action.SetDlDst;
-import org.opendaylight.controller.sal.action.SetDlSrc;
-import org.opendaylight.controller.sal.action.SetDlType;
-import org.opendaylight.controller.sal.action.SetNextHop;
-import org.opendaylight.controller.sal.action.SetNwDst;
-import org.opendaylight.controller.sal.action.SetNwSrc;
-import org.opendaylight.controller.sal.action.SetNwTos;
-import org.opendaylight.controller.sal.action.SetTpDst;
-import org.opendaylight.controller.sal.action.SetTpSrc;
-import org.opendaylight.controller.sal.action.SetVlanCfi;
-import org.opendaylight.controller.sal.action.SetVlanId;
-import org.opendaylight.controller.sal.action.SetVlanPcp;
-import org.opendaylight.controller.sal.action.SwPath;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.Node.NodeIDType;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
-import org.opendaylight.controller.sal.flowprogrammer.Flow;
-import org.opendaylight.controller.sal.match.MatchType;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.ToSalConversionsUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.ControllerActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.FloodAllActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.HwPathActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.LoopbackActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlTypeActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNextHopActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanCfiActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SwPathActionCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.type.action._case.SetDlTypeActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.next.hop.action._case.SetNextHopActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.cfi.action._case.SetVlanCfiActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowAddedBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpTargetHardwareAddressBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSource;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.SctpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
-
-public class TestToSalConversionsUtils {
- // prefix:
- // od|Od = Open Daylight
- private enum MtchType {
- other, untagged, ipv4, ipv6, arp, sctp, tcp, udp
- }
-
- @Test
- public void testToSalConversion() throws ConstructionException {
- FlowAddedBuilder odNodeFlowBuilder = new FlowAddedBuilder();
- odNodeFlowBuilder = prepareOdFlowCommon();
-
- final Node node = new Node(NodeIDType.OPENFLOW,(long)1);
-
- Flow salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.other), node);
- checkSalMatch(salFlow.getMatch(), MtchType.other);
-
- salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.untagged), node);
- checkSalMatch(salFlow.getMatch(), MtchType.untagged);
-
- salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.ipv4), node);
- checkSalMatch(salFlow.getMatch(), MtchType.ipv4);
-
- salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.ipv6), node);
- checkSalMatch(salFlow.getMatch(), MtchType.ipv6);
-
- salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.arp), node);
- checkSalMatch(salFlow.getMatch(), MtchType.arp);
-
- salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.sctp), node);
- checkSalMatch(salFlow.getMatch(), MtchType.sctp);
-
- salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.tcp), node);
- checkSalMatch(salFlow.getMatch(), MtchType.tcp);
-
- salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.udp), node);
- checkSalMatch(salFlow.getMatch(), MtchType.udp);
-
- checkSalFlow(salFlow);
- }
-
- /**
- * test of {@link ToSalConversionsUtils#fromNodeConnectorRef(Uri, Node)}
- * @throws ConstructionException
- */
- @Test
- public void testFromNodeConnectorRef() throws ConstructionException {
- final Node node = new Node(NodeIDType.OPENFLOW, 42L);
- final NodeConnector nodeConnector = ToSalConversionsUtils.fromNodeConnectorRef(new Uri("1"), node);
- assertEquals("OF|1@OF|00:00:00:00:00:00:00:2a", nodeConnector.toString());
- }
-
- @Test
- public void testActionFrom() throws ConstructionException {
- // Bug 2021: Convert AD-SAL notation into MD-SAL notation before calling NodeConnector
- final Node node = new Node(NodeIDType.OPENFLOW, 42L);
- final List<Action> odActions = new ArrayList<>();
-
- final OutputActionBuilder outputActionBuilder = new OutputActionBuilder();
- outputActionBuilder.setOutputNodeConnector(new Uri("openflow:42:CONTROLLER"));
- final OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder();
- outputActionCaseBuilder.setOutputAction(outputActionBuilder.build());
- odActions.add(new ActionBuilder().setAction(outputActionCaseBuilder.build()).build());
-
- final List<org.opendaylight.controller.sal.action.Action> targetAction =
- ToSalConversionsUtils.actionFrom(odActions, node);
- assertNotNull(targetAction);
- assertTrue( Output.class.isInstance(targetAction.get(0)) );
- final Output targetActionOutput = (Output) targetAction.get(0);
- final NodeConnector port = targetActionOutput.getPort();
- assertNotNull(port);
- assertEquals(port.getType(), NodeConnectorIDType.CONTROLLER);
- assertEquals(port.getID(), org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID);
- }
-
- private void checkSalMatch(final org.opendaylight.controller.sal.match.Match match, final MtchType mt) throws ConstructionException {
- switch (mt) {
- case other:
- /*assertNotNull("DL_DST isn't equal.", "3C:A9:F4:00:E0:C8",
- new String((byte[]) match.getField(MatchType.DL_DST).getValue()));
- assertEquals("DL_SRC isn't equal.", "24:77:03:7C:C5:F1",
- new String((byte[]) match.getField(MatchType.DL_SRC).getValue()));
- */
- final Node node = new Node(NodeIDType.OPENFLOW, 12L);
- final NodeConnector port = new NodeConnector(NodeConnectorIDType.OPENFLOW, Short.valueOf((short)345), node);
- assertEquals("IN_PORT isn't equal.", port, match.getField(MatchType.IN_PORT).getValue());
- assertEquals("DL_TYPE isn't equal.", (short) 0xffff, (short) match.getField(MatchType.DL_TYPE).getValue());
- assertEquals("NW_TOS isn't equal.", (byte) 0x33, (byte) match.getField(MatchType.NW_TOS).getValue());
- assertEquals("NW_PROTO isn't equal.", (byte) 0x3f, (byte) match.getField(MatchType.NW_PROTO).getValue());
- assertEquals("DL_VLAN isn't equal.", (short) 0xfff, (short) match.getField(MatchType.DL_VLAN).getValue());
- assertEquals("DL_VLAN_PR isn't equal.", (byte) 0x7, (byte) match.getField(MatchType.DL_VLAN_PR).getValue());
- break;
- case untagged:
- assertEquals("DL_TYPE isn't equal.", (short) 0xffff, (short) match.getField(MatchType.DL_TYPE).getValue());
- assertEquals("NW_TOS isn't equal.", (byte) 0x33, (byte) match.getField(MatchType.NW_TOS).getValue());
- assertEquals("NW_PROTO isn't equal.", (byte) 0x3f, (byte) match.getField(MatchType.NW_PROTO).getValue());
- assertEquals("DL_VLAN isn't equal.", MatchType.DL_VLAN_NONE, (short) match.getField(MatchType.DL_VLAN).getValue());
- break;
- case arp:
- /*
- assertEquals("DL_SRC isn't equal.", "22:44:66:88:AA:CC",
- new String((byte[]) match.getField(MatchType.DL_SRC).getValue()));
- assertEquals("DL_DST isn't equal.", "11:33:55:77:BB:DD",
- new String((byte[]) match.getField(MatchType.DL_DST).getValue()));
- */
- assertEquals("NW_SRC isn't equal.", "192.168.1.101",
- InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_SRC).getValue()));
- assertEquals("NW_DST isn't equal.", "192.168.1.102",
- InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_DST).getValue()));
- assertEquals("DL_TYPE isn't equal.", ETHERNET_ARP, match.getField(MatchType.DL_TYPE).getValue());
- break;
- case ipv4:
- assertEquals("NW_SRC isn't equal.", "192.168.1.104",
- InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_SRC).getValue()));
- assertEquals("NW_DST isn't equal.", "192.168.1.105",
- InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_DST).getValue()));
- break;
- case ipv6:
- assertEquals("NW_SRC isn't equal.", "3001:db8:85a3::8a2e:370:7334",
- InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_SRC).getValue()));
- assertEquals("NW_DST isn't equal.", "3001:db8:85a3::8a2e:370:7335",
- InetAddresses.toAddrString((InetAddress) match.getField(MatchType.NW_DST).getValue()));
- break;
- case sctp:
- assertEquals("TP_SRC isn't equal.", 31, (short) match.getField(MatchType.TP_SRC).getValue());
- assertEquals("TP_DST isn't equal.", 32, (short) match.getField(MatchType.TP_DST).getValue());
- assertEquals("NW_PROTO isn't equal.", CRUDP, (byte) match.getField(MatchType.NW_PROTO).getValue());
- break;
- case tcp:
- assertEquals("TP_SRC isn't equal.", 21, (short) match.getField(MatchType.TP_SRC).getValue());
- assertEquals("TP_DST isn't equal.", 22, (short) match.getField(MatchType.TP_DST).getValue());
- assertEquals("NW_PROTO isn't equal.", TCP, (byte) match.getField(MatchType.NW_PROTO).getValue());
- break;
- case udp:
- assertEquals("TP_SRC isn't equal.", 11, (short) match.getField(MatchType.TP_SRC).getValue());
- assertEquals("TP_DST isn't equal.", 12, (short) match.getField(MatchType.TP_DST).getValue());
- assertEquals("NW_PROTO isn't equal.", UDP, (byte) match.getField(MatchType.NW_PROTO).getValue());
- break;
- default:
- break;
-
- }
-
- }
-
- private void checkSalFlow(final Flow salFlow) {
- assertTrue("Id value is incorrect.", salFlow.getId() == 9223372036854775807L);
- assertTrue("Hard timeout is incorrect.", salFlow.getHardTimeout() == 32767);
- assertTrue("Iddle timeout is incorrect.", salFlow.getIdleTimeout() == 32767);
- assertTrue("Priority value is incorrect.", salFlow.getPriority() == 32767);
-
- checkSalActions(salFlow.getActions());
- }
-
- private void checkSalActions(final List<org.opendaylight.controller.sal.action.Action> actions) {
- checkSalAction(actions, Flood.class, 1);
- checkSalAction(actions, FloodAll.class, 1);
- checkSalAction(actions, HwPath.class, 1);
- checkSalAction(actions, Loopback.class, 1);
- checkSalAction(actions, Output.class, 1, true);
- checkSalAction(actions, PopVlan.class, 1);
- checkSalAction(actions, PushVlan.class, 1, true);
- checkSalAction(actions, SetDlDst.class, 1, true);
- checkSalAction(actions, SetDlSrc.class, 1, true);
- checkSalAction(actions, SetDlType.class, 1, true);
- checkSalAction(actions, SetNextHop.class, 2, true);
- checkSalAction(actions, SetNwDst.class, 2, true);
- checkSalAction(actions, SetNwSrc.class, 2, true);
- checkSalAction(actions, SetNwTos.class, 1, true);
- checkSalAction(actions, SetTpDst.class, 1, true);
- checkSalAction(actions, SetTpSrc.class, 1, true);
- checkSalAction(actions, SetVlanCfi.class, 1, true);
- checkSalAction(actions, SetVlanId.class, 1, true);
- checkSalAction(actions, SetVlanPcp.class, 1, true);
- checkSalAction(actions, SwPath.class, 1);
- }
-
- private void checkSalAction(final List<org.opendaylight.controller.sal.action.Action> actions, final Class<?> cls,
- final int numOfActions) {
- checkSalAction(actions, cls, numOfActions, false);
- }
-
- private void checkSalAction(final List<org.opendaylight.controller.sal.action.Action> actions, final Class<?> cls,
- final int numOfActions, final boolean additionalCheck) {
- int numOfEqualClass = 0;
- for (final org.opendaylight.controller.sal.action.Action action : actions) {
- if (action.getClass().equals(cls)) {
- if (additionalCheck) {
- additionalActionCheck(action);
- }
- numOfEqualClass++;
- }
- }
- assertEquals("Incorrect number of actions of type " + cls.getName() + " was found.", numOfActions,
- numOfEqualClass);
- }
-
- // implement special checks
- private void additionalActionCheck(final org.opendaylight.controller.sal.action.Action action) {
- if (action instanceof Output) {
- // ((Output)action).getPort() //TODO finish check when mapping will
- // be defined
- } else if (action instanceof PushVlan) {
- assertEquals("Wrong value for action PushVlan for tag.", 0x8100, ((PushVlan) action).getTag());
- } else if (action instanceof SetDlDst) {
- //assertEquals("Wrong value for action SetDlDst for MAC address.", "3C:A9:F4:00:E0:C8", new String(
- // ((SetDlDst) action).getDlAddress()));
- } else if (action instanceof SetDlSrc) {
- //assertEquals("Wrong value for action SetDlSrc for MAC address.", "24:77:03:7C:C5:F1", new String(
- // ((SetDlSrc) action).getDlAddress()));
- } else if (action instanceof SetDlType) {
- assertEquals("Wrong value for action SetDlType for.", 513L, ((SetDlType) action).getDlType());
- } else if (action instanceof SetNextHop) {
- final InetAddress inetAddress = ((SetNextHop) action).getAddress();
- checkIpAddresses(inetAddress, "192.168.100.100", "2001:db8:85a3::8a2e:370:7334");
- } else if (action instanceof SetNwDst) {
- final InetAddress inetAddress = ((SetNwDst) action).getAddress();
- checkIpAddresses(inetAddress, "192.168.100.101", "2001:db8:85a3::8a2e:370:7335");
- } else if (action instanceof SetNwSrc) {
- final InetAddress inetAddress = ((SetNwSrc) action).getAddress();
- checkIpAddresses(inetAddress, "192.168.100.102", "2001:db8:85a3::8a2e:370:7336");
- } else if (action instanceof SetNwTos) {
- assertEquals("Wrong value for action SetNwTos for tos.", 63, ((SetNwTos) action).getNwTos());
- } else if (action instanceof SetTpDst) {
- assertEquals("Wrong value for action SetTpDst for port.", 65535, ((SetTpDst) action).getPort());
- } else if (action instanceof SetTpSrc) {
- assertEquals("Wrong value for action SetTpSrc for port.", 65535, ((SetTpSrc) action).getPort());
- } else if (action instanceof SetVlanCfi) {
- assertEquals("Wrong value for action SetVlanCfi for port.", 1, ((SetVlanCfi) action).getCfi());
- } else if (action instanceof SetVlanId) {
- assertEquals("Wrong value for action SetVlanId for vlan ID.", 4095, ((SetVlanId) action).getVlanId());
- } else if (action instanceof SetVlanPcp) {
- assertEquals("Wrong value for action SetVlanPcp for vlan ID.", 7, ((SetVlanPcp) action).getPcp());
- }
- }
-
- private void checkIpAddresses(final InetAddress inetAddress, final String ipv4, final String ipv6) {
- if (inetAddress instanceof Inet4Address) {
- assertEquals("Wrong value for IP address.", ipv4, InetAddresses.toAddrString(inetAddress));
- } else if (inetAddress instanceof Inet6Address) {
- assertEquals("Wrong value for IP address.", ipv6, InetAddresses.toAddrString(inetAddress));
- }
- }
-
- private FlowAddedBuilder prepareOdFlowCommon() {
- final FlowAddedBuilder odNodeFlowBuilder = new FlowAddedBuilder();
-
- odNodeFlowBuilder.setCookie(new FlowCookie(new BigInteger("9223372036854775807")));
- odNodeFlowBuilder.setHardTimeout(32767);
- odNodeFlowBuilder.setIdleTimeout(32767);
- odNodeFlowBuilder.setPriority(32767);
- odNodeFlowBuilder.setInstructions(prepareOdActions());
- return odNodeFlowBuilder;
- }
-
- private NodeFlow prepareOdFlow(final FlowAddedBuilder odNodeFlowBuilder, final MtchType mt) {
- odNodeFlowBuilder.setMatch(prepOdMatch(mt));
- return odNodeFlowBuilder.build();
- }
-
- private Instructions prepareOdActions() {
- final List<Action> odActions = new ArrayList<>();
-
- final ControllerActionCaseBuilder controllerActionBuilder = new ControllerActionCaseBuilder();
- final DropActionCaseBuilder dropActionBuilder = new DropActionCaseBuilder();
- final FloodActionCaseBuilder floodActionBuilder = new FloodActionCaseBuilder();
- final FloodAllActionCaseBuilder floodAllActionBuilder = new FloodAllActionCaseBuilder();
- final HwPathActionCaseBuilder hwPathActionBuilder = new HwPathActionCaseBuilder();
- final LoopbackActionCaseBuilder loopbackActionBuilder = new LoopbackActionCaseBuilder();
- final OutputActionCaseBuilder outputActionBuilder = new OutputActionCaseBuilder();
- final PopMplsActionCaseBuilder popMplsActionBuilder = new PopMplsActionCaseBuilder();
- final PopVlanActionCaseBuilder popVlanActionBuilder = new PopVlanActionCaseBuilder();
- final PushMplsActionCaseBuilder pushMplsActionBuilder = new PushMplsActionCaseBuilder();
- final PushPbbActionCaseBuilder pushPbbActionBuilder = new PushPbbActionCaseBuilder();
- final PushVlanActionCaseBuilder pushVlanActionBuilder = new PushVlanActionCaseBuilder();
- final SetDlDstActionCaseBuilder setDlDstActionBuilder = new SetDlDstActionCaseBuilder();
- final SetDlSrcActionCaseBuilder setDlSrcActionBuilder = new SetDlSrcActionCaseBuilder();
- final SetDlTypeActionCaseBuilder setDlTypeActionBuilder = new SetDlTypeActionCaseBuilder();
- final SetMplsTtlActionCaseBuilder setMplsTtlActionBuilder = new SetMplsTtlActionCaseBuilder();
- final SetNwTosActionCaseBuilder setNwTosActionBuilder = new SetNwTosActionCaseBuilder();
- final SetNwTtlActionCaseBuilder setNwTtlActionBuilder = new SetNwTtlActionCaseBuilder();
- final SetQueueActionCaseBuilder setQueueActionBuilder = new SetQueueActionCaseBuilder();
- final SetTpDstActionCaseBuilder setTpDstActionBuilder = new SetTpDstActionCaseBuilder();
- final SetTpSrcActionCaseBuilder setTpSrcActionBuilder = new SetTpSrcActionCaseBuilder();
- final SetVlanCfiActionCaseBuilder setVlanCfiActionBuilder = new SetVlanCfiActionCaseBuilder();
- final SetVlanIdActionCaseBuilder setVlanIdActionBuilder = new SetVlanIdActionCaseBuilder();
- final SetVlanPcpActionCaseBuilder setVlanPcpActionBuilder = new SetVlanPcpActionCaseBuilder();
- final SwPathActionCaseBuilder swPathActionBuilder = new SwPathActionCaseBuilder();
-
- prepareActionOutput(outputActionBuilder);
- prepareActionPushVlan(pushVlanActionBuilder);
- prepareActionSetDlDst(setDlDstActionBuilder);
- prepareActionSetDlSrc(setDlSrcActionBuilder);
- prepareActionSetDlType(setDlTypeActionBuilder);
- prepareActionNextHop(odActions);
- prepareActionSetNwDst(odActions);
- prepareActionSetNwSrc(odActions);
- prepareActionSetNwTos(setNwTosActionBuilder);
- prepareActionSetTpDst(setTpDstActionBuilder);
- prepareActionSetTpSrc(setTpSrcActionBuilder);
- prepareActionSetVlanCfi(setVlanCfiActionBuilder);
- prepareActionSetVladId(setVlanIdActionBuilder);
- prepareActionSetVlanPcp(setVlanPcpActionBuilder);
-
- odActions.add(new ActionBuilder().setAction(controllerActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(dropActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(floodActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(floodAllActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(hwPathActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(loopbackActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(outputActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(popMplsActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(popVlanActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(pushMplsActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(pushPbbActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(pushVlanActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setDlDstActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setDlSrcActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setDlTypeActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setMplsTtlActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setNwTosActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setNwTtlActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setQueueActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setTpDstActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setTpSrcActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setVlanCfiActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setVlanIdActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(setVlanPcpActionBuilder.build()).build());
- odActions.add(new ActionBuilder().setAction(swPathActionBuilder.build()).build());
-
-
- final ApplyActionsCase innerInst = new ApplyActionsCaseBuilder().setApplyActions(new ApplyActionsBuilder().setAction(odActions).build()).build();
- final Instruction applyActions = new InstructionBuilder().setInstruction(innerInst).build();
- final List<Instruction> instructions = Collections.singletonList(applyActions );
- final InstructionsBuilder instBuilder = new InstructionsBuilder();
-
- instBuilder.setInstruction(instructions);
-
- return instBuilder.build();
- }
-
- private void prepareActionSetVlanPcp(final SetVlanPcpActionCaseBuilder wrapper) {
- final SetVlanPcpActionBuilder setVlanPcpActionBuilder = new SetVlanPcpActionBuilder();
- setVlanPcpActionBuilder.setVlanPcp(new VlanPcp((short) 7));
- wrapper.setSetVlanPcpAction(setVlanPcpActionBuilder.build());
- }
-
- private void prepareActionSetVladId(final SetVlanIdActionCaseBuilder wrapper) {
- final SetVlanIdActionBuilder setVlanIdActionBuilder = new SetVlanIdActionBuilder();
- setVlanIdActionBuilder.setVlanId(new VlanId(4095));
- wrapper.setSetVlanIdAction(setVlanIdActionBuilder.build());
- }
-
- private void prepareActionSetVlanCfi(final SetVlanCfiActionCaseBuilder wrapper) {
- final SetVlanCfiActionBuilder setVlanCfiActionBuilder = new SetVlanCfiActionBuilder();
- setVlanCfiActionBuilder.setVlanCfi(new VlanCfi(1));
- wrapper.setSetVlanCfiAction(setVlanCfiActionBuilder.build());
- }
-
- private void prepareActionSetTpDst(final SetTpDstActionCaseBuilder wrapper) {
- final SetTpDstActionBuilder setTpDstActionBuilder = new SetTpDstActionBuilder();
- setTpDstActionBuilder.setPort(new PortNumber(65535));
- wrapper.setSetTpDstAction(setTpDstActionBuilder.build());
- }
-
- private void prepareActionSetTpSrc(final SetTpSrcActionCaseBuilder wrapper) {
- final SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder();
- setTpSrcActionBuilder.setPort(new PortNumber(65535));
- wrapper.setSetTpSrcAction(setTpSrcActionBuilder.build());
- }
-
- private void prepareActionSetNwTos(final SetNwTosActionCaseBuilder wrapper) {
- final SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder();
- setNwTosActionBuilder.setTos(252);
- wrapper.setSetNwTosAction(setNwTosActionBuilder.build());
- }
-
- private void prepareActionSetNwSrc(final List<Action> odActions) {
- // test case for IPv4
- final SetNwSrcActionBuilder setNwSrcActionBuilderIpv4 = new SetNwSrcActionBuilder();
- setNwSrcActionBuilderIpv4.setAddress(prapareIpv4Address("192.168.100.102"));
- odActions.add(new ActionBuilder().setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwSrcActionBuilderIpv4.build()).build()).build());
-
- // test case for IPv6
- final SetNwSrcActionBuilder setNwSrcActionBuilderIpv6 = new SetNwSrcActionBuilder();
- setNwSrcActionBuilderIpv6.setAddress(prapareIpv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7336/128"));
- odActions.add(new ActionBuilder().setAction(new SetNwSrcActionCaseBuilder().setSetNwSrcAction(setNwSrcActionBuilderIpv6.build()).build()).build());
- }
-
- private void prepareActionSetNwDst(final List<Action> odActions) {
- // test case for IPv4
-
- final SetNwDstActionBuilder setNwDstActionBuilderIpv4 = new SetNwDstActionBuilder();
- setNwDstActionBuilderIpv4.setAddress(prapareIpv4Address("192.168.100.101"));
- odActions.add(new ActionBuilder().setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilderIpv4.build()).build()).build());
-
- // test case for IPv6
- final SetNwDstActionBuilder setNwDstActionBuilderIpv6 = new SetNwDstActionBuilder();
- setNwDstActionBuilderIpv6.setAddress(prapareIpv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7335/128"));
- odActions.add(new ActionBuilder().setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilderIpv6.build()).build()).build());
- }
-
- private void prepareActionNextHop(final List<Action> odActions) {
- // test case for IPv4
- final SetNextHopActionBuilder setNextHopActionBuilderIpv4 = new SetNextHopActionBuilder();
- setNextHopActionBuilderIpv4.setAddress(prapareIpv4Address("192.168.100.100"));
- odActions.add(new ActionBuilder().setAction(new SetNextHopActionCaseBuilder().setSetNextHopAction(setNextHopActionBuilderIpv4.build()).build()).build());
-
- // test case for IPv6
- final SetNextHopActionBuilder setNextHopActionBuilderIpv6 = new SetNextHopActionBuilder();
- setNextHopActionBuilderIpv6.setAddress(prapareIpv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/128"));
- odActions.add(new ActionBuilder().setAction(new SetNextHopActionCaseBuilder().setSetNextHopAction(setNextHopActionBuilderIpv6.build()).build()).build());
- }
-
- private Address prapareIpv4Address(final String ipv4Address) {
- final Ipv4Builder ipv4Builder = new Ipv4Builder();
- ipv4Builder.setIpv4Address(new Ipv4Prefix(ipv4Address + "/32"));
- return ipv4Builder.build();
- }
-
- private Address prapareIpv6Prefix(final String ipv6Address) {
- final Ipv6Builder ipv6Builder = new Ipv6Builder();
- ipv6Builder.setIpv6Address(new Ipv6Prefix(ipv6Address));
- return ipv6Builder.build();
- }
-
- private void prepareActionSetDlType(final SetDlTypeActionCaseBuilder wrapper) {
- final SetDlTypeActionBuilder setDlTypeActionBuilder = new SetDlTypeActionBuilder();
- setDlTypeActionBuilder.setDlType(new EtherType(513L));
- wrapper.setSetDlTypeAction(setDlTypeActionBuilder.build());
- }
-
- private void prepareActionSetDlSrc(final SetDlSrcActionCaseBuilder wrapper) {
- final SetDlSrcActionBuilder setDlSrcActionBuilder = new SetDlSrcActionBuilder();
- setDlSrcActionBuilder.setAddress(new MacAddress("24:77:03:7C:C5:F1"));
- wrapper.setSetDlSrcAction(setDlSrcActionBuilder.build());
- }
-
- private void prepareActionSetDlDst(final SetDlDstActionCaseBuilder wrapper) {
- final SetDlDstActionBuilder setDlDstActionBuilder = new SetDlDstActionBuilder();
- setDlDstActionBuilder.setAddress(new MacAddress("3C:A9:F4:00:E0:C8"));
- wrapper.setSetDlDstAction(setDlDstActionBuilder.build());
- }
-
- private void prepareActionPushVlan(final PushVlanActionCaseBuilder wrapper) {
- final PushVlanActionBuilder pushVlanActionBuilder = new PushVlanActionBuilder();
- pushVlanActionBuilder.setTag(0x8100); // 12 bit
- wrapper.setPushVlanAction(pushVlanActionBuilder.build());
- }
-
- private void prepareActionOutput(final OutputActionCaseBuilder wrapper) {
- final OutputActionBuilder outputActionBuilder = new OutputActionBuilder();
- outputActionBuilder.setOutputNodeConnector(new Uri("openflow:1:1"));
- wrapper.setOutputAction(outputActionBuilder.build());
- }
-
- private Match prepOdMatch(final MtchType mt) {
- final MatchBuilder odMatchBuilder = new MatchBuilder();
- switch (mt) {
- case other:
- odMatchBuilder.setInPort(new NodeConnectorId("openflow:12:345"));
- odMatchBuilder.setEthernetMatch(prepEthernetMatch());
- odMatchBuilder.setIpMatch(prepIpMatch());
- odMatchBuilder.setVlanMatch(prepVlanMatch());
- break;
- case untagged:
- odMatchBuilder.setEthernetMatch(prepEthernetMatch());
- odMatchBuilder.setIpMatch(prepIpMatch());
- odMatchBuilder.setVlanMatch(prepVlanNoneMatch());
- break;
- case ipv4:
- odMatchBuilder.setLayer3Match(prepLayer3MatchIpv4());
- break;
- case ipv6:
- odMatchBuilder.setLayer3Match(prepLayer3MatchIpv6());
- break;
- case arp:
- odMatchBuilder.setLayer3Match(prepLayer3MatchArp());
- break;
- case sctp:
- odMatchBuilder.setLayer4Match(prepLayer4MatchSctp());
- break;
- case tcp:
- odMatchBuilder.setLayer4Match(prepLayer4MatchTcp());
- break;
- case udp:
- odMatchBuilder.setLayer4Match(prepLayer4MatchUdp());
- break;
- }
- return odMatchBuilder.build();
- }
-
- private Layer4Match prepLayer4MatchUdp() {
- final UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
-
- udpMatchBuilder.setUdpSourcePort(new PortNumber(11));
- udpMatchBuilder.setUdpDestinationPort(new PortNumber(12));
-
- return udpMatchBuilder.build();
- }
-
- private Layer4Match prepLayer4MatchTcp() {
- final TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
-
- tcpMatchBuilder.setTcpSourcePort(new PortNumber(21));
- tcpMatchBuilder.setTcpDestinationPort(new PortNumber(22));
-
- return tcpMatchBuilder.build();
- }
-
- private Layer4Match prepLayer4MatchSctp() {
- final SctpMatchBuilder sctpMatchBuilder = new SctpMatchBuilder();
-
- sctpMatchBuilder.setSctpSourcePort(new PortNumber(31));
- sctpMatchBuilder.setSctpDestinationPort(new PortNumber(32));
-
- return sctpMatchBuilder.build();
- }
-
- private Layer3Match prepLayer3MatchIpv4() {
- final Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
- ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix("192.168.1.104/32"));
- ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix("192.168.1.105/32"));
- return ipv4MatchBuilder.build();
- }
-
- private Layer3Match prepLayer3MatchIpv6() {
- final Ipv6MatchBuilder ipv6MatchBuilder = new Ipv6MatchBuilder();
- ipv6MatchBuilder.setIpv6Source(new Ipv6Prefix("3001:0db8:85a3:0000:0000:8a2e:0370:7334/128"));
- ipv6MatchBuilder.setIpv6Destination(new Ipv6Prefix("3001:0db8:85a3:0000:0000:8a2e:0370:7335/128"));
- return ipv6MatchBuilder.build();
- }
-
- private Layer3Match prepLayer3MatchArp() {
- final ArpMatchBuilder arpMatchBuilder = new ArpMatchBuilder();
- arpMatchBuilder.setArpSourceTransportAddress(new Ipv4Prefix("192.168.1.101/32"));
- arpMatchBuilder.setArpTargetTransportAddress(new Ipv4Prefix("192.168.1.102/32"));
-
- final ArpSourceHardwareAddressBuilder arpSourAddressBuild = new ArpSourceHardwareAddressBuilder();
- arpSourAddressBuild.setAddress(new MacAddress("22:44:66:88:AA:CC"));
- arpMatchBuilder.setArpSourceHardwareAddress(arpSourAddressBuild.build());
-
- final ArpTargetHardwareAddressBuilder arpTarAddressBuild = new ArpTargetHardwareAddressBuilder();
- arpTarAddressBuild.setAddress(new MacAddress("11:33:55:77:BB:DD"));
- arpMatchBuilder.setArpTargetHardwareAddress(arpTarAddressBuild.build());
- return arpMatchBuilder.build();
- }
-
- private VlanMatch prepVlanMatch() {
- final VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
-
- final VlanIdBuilder vlanIdBuilder = new VlanIdBuilder().setVlanId(new VlanId(0xfff));
- vlanMatchBuilder.setVlanId(vlanIdBuilder.setVlanIdPresent(true).build());
- vlanMatchBuilder.setVlanPcp(new VlanPcp((short) 0x7));
-
- return vlanMatchBuilder.build();
- }
-
- private VlanMatch prepVlanNoneMatch() {
- final VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
-
- final VlanIdBuilder vlanIdBuilder = new VlanIdBuilder().
- setVlanIdPresent(false);
- vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
-
- return vlanMatchBuilder.build();
- }
-
- private IpMatch prepIpMatch() {
- final IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
- ipMatchBuilder.setIpDscp(new Dscp((short) 0x33));
- ipMatchBuilder.setIpProtocol((short) 0x3f);
- return ipMatchBuilder.build();
- }
-
- private EthernetMatch prepEthernetMatch() {
- final EthernetMatchBuilder odEthernetMatchBuilder = new EthernetMatchBuilder();
- odEthernetMatchBuilder.setEthernetDestination(prepEthDest());
- odEthernetMatchBuilder.setEthernetSource(prepEthSour());
- odEthernetMatchBuilder.setEthernetType(prepEthType());
- return odEthernetMatchBuilder.build();
- }
-
- private EthernetType prepEthType() {
- final EthernetTypeBuilder ethTypeBuild = new EthernetTypeBuilder();
- ethTypeBuild.setType(new EtherType(0xffffL));
- return ethTypeBuild.build();
- }
-
- private EthernetSource prepEthSour() {
- final EthernetSourceBuilder ethSourBuild = new EthernetSourceBuilder();
- ethSourBuild.setAddress(new MacAddress("24:77:03:7C:C5:F1"));
- return ethSourBuild.build();
- }
-
- private EthernetDestination prepEthDest() {
- final EthernetDestinationBuilder ethDestBuild = new EthernetDestinationBuilder();
- ethDestBuild.setAddress(new MacAddress("3C:A9:F4:00:E0:C8"));
- return ethDestBuild.build();
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.test;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.ToSalConversionsUtils;
-
-/**
- * test of {@link ToSalConversionsUtils}
- */
-public class ToSalConversionsUtilsTest {
-
- /**
- * Test method for {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.ToSalConversionsUtils#tosToNwDscp(int)}.
- */
- @Test
- public void testTosToNwDscp() {
- Assert.assertEquals(0, ToSalConversionsUtils.tosToNwDscp(0));
- Assert.assertEquals(0, ToSalConversionsUtils.tosToNwDscp(1));
- Assert.assertEquals(1, ToSalConversionsUtils.tosToNwDscp(4));
- Assert.assertEquals(63, ToSalConversionsUtils.tosToNwDscp(252));
- Assert.assertEquals(63, ToSalConversionsUtils.tosToNwDscp(253));
- Assert.assertEquals(-1, ToSalConversionsUtils.tosToNwDscp(-1));
- }
-}
+++ /dev/null
-/**
- * Copyright (c) 2014 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
- */
-package org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.test;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.opendaylight.controller.sal.core.ConstructionException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
-import org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyMapping;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
-
-/**
- * test for {@link TopologyMapping}
- */
-public class TopologyMappingTest {
-
- /**
- * Test method for {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyMapping#toADNodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)}.
- */
- @Test
- public void testToADNodeId() {
- NodeId nodeId = new NodeId("openflow:1");
- String observedNodeId = TopologyMapping.toADNodeId(nodeId);
-
- assertEquals("1", observedNodeId);
- }
-
- /**
- * Test method for {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyMapping#toADNodeConnector(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId, org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)}.
- * @throws ConstructionException
- */
- @Test
- public void testToADNodeConnector() throws ConstructionException {
- NodeId nodeId = new NodeId("openflow:1");
- TpId source = new TpId("foo:2");
- NodeConnector observedNodeConnector = TopologyMapping.toADNodeConnector(source, nodeId);
-
- assertEquals("OF|2@OF|00:00:00:00:00:00:00:01", observedNodeConnector.toString());
- }
-
- /**
- * Test method for {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyMapping#toADNodeConnectorId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId)}.
- */
- @Test
- public void testToADNodeConnectorId() {
- TpId source = new TpId("foo:2");
- String observedNodeConnectorId = TopologyMapping.toADNodeConnectorId(source);
-
- assertEquals("2", observedNodeConnectorId);
- }
-
- /**
- * Test method for {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyMapping#toADNode(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)}.
- * @throws ConstructionException
- */
- @Test
- public void testToADNode() throws ConstructionException {
- NodeId nodeId = new NodeId("openflow:1");
- Node observedNode = TopologyMapping.toADNode(nodeId);
-
- assertEquals("OF|00:00:00:00:00:00:00:01", observedNode.toString());
- }
-
- /**
- * Test method for {@link org.opendaylight.openflowplugin.legacy.sal.compatibility.topology.TopologyMapping#toADNodeConnector(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId, org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)}.
- * @throws ConstructionException
- */
- @Test
- public void bug1309ToADNodeConnector() throws ConstructionException {
- NodeId nodeId = new NodeId("some_unknown_node");
- TpId source = new TpId("192.168.0.1");
- NodeConnector observedNodeConnector = TopologyMapping.toADNodeConnector(source, nodeId);
-
- assertEquals("MD_SAL_DEPRECATED|192.168.0.1@MD_SAL_DEPRECATED|some_unknown_node", observedNodeConnector.toString());
- }
-
-}
<artifactId>model-inventory</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
+ <groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>opendaylight-l2-types</artifactId>
</dependency>
</dependencies>
<artifactId>model-inventory</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
+ <groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>opendaylight-l2-types</artifactId>
</dependency>
</dependencies>
<artifactId>model-inventory</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
+ <groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>opendaylight-l2-types</artifactId>
</dependency>
</dependencies>
<dependencies>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
</dependency>
<dependency>
<artifactId>yang-common</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
+ <groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>ietf-inet-types</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
+ <groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>ietf-yang-types</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
+ <groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>yang-ext</artifactId>
</dependency>
</dependencies>
<artifactId>yang-maven-plugin</artifactId>
<dependencies>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
boolean isSwitchFeaturesMandatory();
+ boolean isStatisticsPollingOff();
+ void setIsStatisticsPollingOff(final boolean isStatisticsPollingOff);
}
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MessageHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
+import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
* @param upperBound max amount of outstanding packetIns
*/
void updatePacketInRateLimit(long upperBound);
+
+ /**
+ * @return registry point for item life cycle sources of device
+ */
+ ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
}
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.api.openflow.registry;
+
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
+import org.opendaylight.yangtools.concepts.Registration;
+
+/**
+ * Registration point for any kind of lifecycle sources per device.
+ */
+public interface ItemLifeCycleRegistry {
+
+ /**
+ * register given life cycle source to known sources of device
+ *
+ * @param lifeCycleSource life cycle changes provider
+ * @return closeable registration
+ */
+ Registration registerLifeCycleSource(ItemLifeCycleSource lifeCycleSource);
+
+ /**
+ * close all existing registrations
+ */
+ void clear();
+
+ /**
+ * @return registered sources
+ */
+ Iterable<ItemLifeCycleSource> getLifeCycleSources();
+}
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.api.openflow.rpc;
+
+import javax.annotation.Nullable;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+
+/**
+ * provides read-write access to assigned {@link ItemLifecycleListener}
+ */
+public interface ItemLifeCycleKeeper extends ItemLifeCycleSource {
+
+ /**
+ * @return assigned item lifecycle listener
+ */
+ @Nullable
+ ItemLifecycleListener getItemLifecycleListener();
+}
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.api.openflow.rpc;
+
+import javax.annotation.Nullable;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+
+/**
+ * A source of switch item lifecycle enables for injecting of
+ * a {@link org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener}
+ * in order to act upon item lifecycle changes.
+ */
+public interface ItemLifeCycleSource {
+
+ /**
+ * @param itemLifecycleListener acts upon lifecycle changes
+ */
+ void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener);
+
+
+}
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.api.openflow.rpc.listener;
+
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+/**
+ * Flow/group/meter lifecycle listener - aimed on rpc result approved by barrier message.
+ */
+public interface ItemLifecycleListener {
+
+ /**
+ * react upon item added event
+ *
+ * @param itemPath keyed path in DS
+ * @param itemBody item body
+ */
+
+ <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onAdded(KeyedInstanceIdentifier<I, K> itemPath, I itemBody);
+
+ /**
+ * react upon item removed event
+ *
+ * @param itemPath keyed path in DS
+ */
+ <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onRemoved(KeyedInstanceIdentifier<I, K> itemPath);
+}
package org.opendaylight.openflowplugin.api.openflow.statistics;
+import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.Timeout;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
/**
* Created by Martin Bobak <mbobak@cisco.com> on 27.2.2015.
* @param pollTimeout handle to nearest scheduled statistics poll
*/
void setPollTimeout(Timeout pollTimeout);
+
+ /**
+ * @return handle to currently scheduled statistics polling
+ */
+ Optional<Timeout> getPollTimeout();
+
+ /**
+ * @return dedicated item life cycle change listener (per device)
+ */
+ ItemLifecycleListener getItemLifeCycleListener();
}
/**
* Created by Martin Bobak <mbobak@cisco.com> on 26.2.2015.
*/
-public interface StatisticsManager extends DeviceInitializator, DeviceInitializationPhaseHandler, DeviceContextClosedHandler {
+public interface StatisticsManager extends DeviceInitializator, DeviceInitializationPhaseHandler,
+ DeviceContextClosedHandler, AutoCloseable {
+ @Override
+ void close();
}
--- /dev/null
+module statistics-manager-control {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:openflowplugin:sm:control";
+ prefix "sm-control";
+
+ description
+ "Statistics manager control API";
+
+ revision "2015-08-12" {
+ description
+ "Initial proposal.";
+ }
+
+
+ typedef statistics-work-mode {
+ description "Statistics manager work modes.";
+ type enumeration {
+ enum COLLECT_ALL {
+ description "Default mode - all available statistics are being polled and processed";
+ }
+ enum FULLY_DISABLED {
+ description "No statistics are being polled at all";
+ }
+ }
+ }
+
+ rpc change-statistics-work-mode {
+ description "Set statistics manager work mode";
+ input {
+ leaf mode {
+ type statistics-work-mode;
+ }
+ }
+ }
+
+ rpc get-statistics-work-mode {
+ description "Get statistics manager work mode";
+ output {
+ leaf mode {
+ type statistics-work-mode;
+ }
+ }
+ }
+}
<rpc-requests-quota>20000</rpc-requests-quota>
<switch-features-mandatory>false</switch-features-mandatory>
<global-notification-quota>64000</global-notification-quota>
+ <is-statistics-polling-off>false</is-statistics-polling-off>
</module>
</modules>
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
private OfpRole role;
private Collection<SwitchConnectionProvider> switchConnectionProviders;
private boolean switchFeaturesMandatory = false;
+ private boolean isStatisticsPollingOff = false;
public OpenFlowPluginProviderImpl(final long rpcRequestsQuota, final Long globalNotificationQuota) {
Preconditions.checkArgument(rpcRequestsQuota > 0 && rpcRequestsQuota <= Integer.MAX_VALUE, "rpcRequestQuota has to be in range <1,%s>", Integer.MAX_VALUE);
this.globalNotificationQuota = Preconditions.checkNotNull(globalNotificationQuota);
}
+ @Override
+ public boolean isStatisticsPollingOff() {
+ return isStatisticsPollingOff;
+ }
+
+ @Override
+ public void setIsStatisticsPollingOff(final boolean isStatisticsPollingOff) {
+ this.isStatisticsPollingOff = isStatisticsPollingOff;
+ }
private void startSwitchConnections() {
final List<ListenableFuture<Boolean>> starterChain = new ArrayList<>(switchConnectionProviders.size());
registerMXBean(messageIntelligenceAgency);
deviceManager = new DeviceManagerImpl(dataBroker, messageIntelligenceAgency, switchFeaturesMandatory, globalNotificationQuota);
- statisticsManager = new StatisticsManagerImpl();
+ statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff);
rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota);
connectionManager.setDeviceConnectedHandler(deviceManager);
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.impl.common;
+
+import javax.annotation.Nullable;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleKeeper;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+
+/**
+ * simple standalone {@link ItemLifeCycleSource} implementation
+ */
+public class ItemLifeCycleSourceImpl implements ItemLifeCycleKeeper {
+
+ private ItemLifecycleListener itemLifecycleListener;
+
+ @Override
+ public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
+
+ this.itemLifecycleListener = itemLifecycleListener;
+ }
+
+ @Override
+ public ItemLifecycleListener getItemLifecycleListener() {
+ return itemLifecycleListener;
+ }
+}
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
+import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleKeeper;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
+import org.opendaylight.openflowplugin.impl.common.ItemLifeCycleSourceImpl;
import org.opendaylight.openflowplugin.impl.common.NodeStaticReplyTranslatorUtil;
import org.opendaylight.openflowplugin.impl.device.listener.MultiMsgCollectorImpl;
import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
+import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.registry.group.DeviceGroupRegistryImpl;
import org.opendaylight.openflowplugin.impl.registry.meter.DeviceMeterRegistryImpl;
import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
private final Collection<DeviceContextClosedHandler> closeHandlers = new HashSet<>();
private final PacketInRateLimiter packetInLimiter;
private final MessageSpy messageSpy;
+ private final ItemLifeCycleKeeper flowLifeCycleKeeper;
private NotificationPublishService notificationPublishService;
private NotificationService notificationService;
private final OutboundQueue outboundQueueProvider;
private Timeout barrierTaskTimeout;
private final MessageTranslator<PortGrouping, FlowCapableNodeConnector> portStatusTranslator;
private final MessageTranslator<PacketInMessage, PacketReceived> packetInTranslator;
+ private final MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved> flowRemovedTranslator;
private final TranslatorLibrary translatorLibrary;
private Map<Long, NodeConnectorRef> nodeConnectorCache;
+ private ItemLifeCycleRegistry itemLifeCycleSourceRegistry;
@VisibleForTesting
new TranslatorKey(deviceState.getVersion(), PortGrouping.class.getName()));
packetInTranslator = translatorLibrary.lookupTranslator(
new TranslatorKey(deviceState.getVersion(), PacketIn.class.getName()));
+ flowRemovedTranslator = translatorLibrary.lookupTranslator(
+ new TranslatorKey(deviceState.getVersion(), FlowRemoved.class.getName()));
+
+
nodeConnectorCache = new ConcurrentHashMap<>();
+
+ itemLifeCycleSourceRegistry = new ItemLifeCycleRegistryImpl();
+ flowLifeCycleKeeper = new ItemLifeCycleSourceImpl();
+ itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper);
}
/**
@Override
public void processFlowRemovedMessage(final FlowRemoved flowRemoved) {
- //TODO: will be defined later
+ final ItemLifecycleListener itemLifecycleListener = flowLifeCycleKeeper.getItemLifecycleListener();
+ if (itemLifecycleListener != null) {
+ //1. translate to general flow (table, priority, match, cookie)
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved flowRemovedNotification =
+ flowRemovedTranslator.translate(flowRemoved, this, null);
+ //2. create registry key
+ FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(flowRemovedNotification);
+ //3. lookup flowId
+ final FlowDescriptor flowDescriptor = deviceFlowRegistry.retrieveIdForFlow(flowRegKey);
+ //4. if flowId present:
+ if (flowDescriptor != null) {
+ // a) construct flow path
+ KeyedInstanceIdentifier<Flow, FlowKey> flowPath = getDeviceState().getNodeInstanceIdentifier()
+ .augmentation(FlowCapableNode.class)
+ .child(Table.class, flowDescriptor.getTableKey())
+ .child(Flow.class, new FlowKey(flowDescriptor.getFlowId()));
+ // b) notify listener
+ itemLifecycleListener.onRemoved(flowPath);
+ } else {
+ LOG.debug("flow id not found: nodeId={} tableId={}, priority={}",
+ getDeviceState().getNodeId(), flowRegKey.getTableId(), flowRemovedNotification.getPriority());
+ }
+ }
}
@Override
deviceFlowRegistry.close();
deviceMeterRegistry.close();
+ itemLifeCycleSourceRegistry.clear();
+
for (final DeviceContextClosedHandler deviceContextClosedHandler : closeHandlers) {
deviceContextClosedHandler.onDeviceContextClosed(this);
public void updatePacketInRateLimit(long upperBound) {
packetInLimiter.changeWaterMarks((int) (LOW_WATERMARK_FACTOR * upperBound), (int) (HIGH_WATERMARK_FACTOR * upperBound));
}
+
+ @Override
+ public ItemLifeCycleRegistry getItemLifeCycleSourceRegistry() {
+ return itemLifeCycleSourceRegistry;
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.impl.device;
+
+import java.util.Collections;
+import java.util.Set;
+import org.apache.mina.util.ConcurrentHashSet;
+import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
+import org.opendaylight.yangtools.concepts.Registration;
+
+/**
+ * default implementation
+ */
+public class ItemLifeCycleRegistryImpl implements ItemLifeCycleRegistry {
+
+ private final Set<ItemLifeCycleSource> registry;
+
+ public ItemLifeCycleRegistryImpl() {
+ registry = new ConcurrentHashSet<>();
+ }
+
+
+ @Override
+
+ public Registration registerLifeCycleSource(final ItemLifeCycleSource lifeCycleSource) {
+ registry.add(lifeCycleSource);
+ return new Registration() {
+ @Override
+ public void close() throws Exception {
+ registry.remove(lifeCycleSource);
+ }
+ };
+ }
+
+ @Override
+ public void clear() {
+ registry.clear();
+ }
+
+ @Override
+ public Iterable<ItemLifeCycleSource> getLifeCycleSources() {
+ return Collections.unmodifiableCollection(registry);
+ }
+}
LOG.trace("nothing to commit - submit returns true");
return true;
}
- wTx.submit();
+ final CheckedFuture<Void, TransactionCommitFailedException> submitFuture = wTx.submit();
+ Futures.addCallback(submitFuture, new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(Void result) {
+ //no action required
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ if (t instanceof TransactionCommitFailedException) {
+ LOG.error("Transaction commit failed. {}", t);
+ } else {
+ LOG.error("Exception during transaction submitting. {}", t);
+ }
+ }
+ });
wTx = null;
}
return true;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
routedRpcReg.registerPath(NodeContext.class, deviceContext.getDeviceState().getNodeInstanceIdentifier());
rpcRegistrations.add(routedRpcReg);
LOG.debug("Registration of service {} for device {}.", serviceClass, deviceContext.getDeviceState().getNodeInstanceIdentifier());
+
+ if (serviceInstance instanceof ItemLifeCycleSource) {
+ // TODO: collect registration for selective unregistering in case of tearing down only one rpc
+ deviceContext.getItemLifeCycleSourceRegistry().registerLifeCycleSource((ItemLifeCycleSource) serviceInstance);
+ }
}
/**
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.impl.rpc.listener;
+
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+/**
+ * General implementation of {@link ItemLifecycleListener} - keeping of DS/operational reflection up-to-date
+ */
+public class ItemLifecycleListenerImpl implements ItemLifecycleListener {
+
+ private final DeviceContext deviceContext;
+
+ public ItemLifecycleListenerImpl(DeviceContext deviceContext) {
+ this.deviceContext = deviceContext;
+ }
+
+ @Override
+ public <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onAdded(KeyedInstanceIdentifier<I, K> itemPath, I itemBody) {
+ deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, itemPath, itemBody);
+ deviceContext.submitTransaction();
+ }
+
+ @Override
+ public <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onRemoved(KeyedInstanceIdentifier<I, K> itemPath) {
+ deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, itemPath);
+ deviceContext.submitTransaction();
+ }
+}
import com.google.common.util.concurrent.SettableFuture;
import java.util.ArrayList;
import java.util.List;
+import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
Futures.addCallback(allFutures, new FutureCallback<List<RpcResult<O>>>() {
@Override
public void onSuccess(final List<RpcResult<O>> results) {
- RpcResultBuilder<O> rpcResultBuilder = RpcResultBuilder.success();
+ final ArrayList<RpcError> errors = new ArrayList();
+ for (RpcResult<O> flowModResult : results) {
+ if (flowModResult == null) {
+ errors.add(RpcResultBuilder.newError(
+ RpcError.ErrorType.PROTOCOL, OFConstants.APPLICATION_TAG,
+ "unexpected flowMod result (null) occurred"));
+ } else if (!flowModResult.isSuccessful()) {
+ errors.addAll(flowModResult.getErrors());
+ }
+ }
+
+ final RpcResultBuilder<O> rpcResultBuilder;
+ if (errors.isEmpty()) {
+ rpcResultBuilder = RpcResultBuilder.success();
+ } else {
+ rpcResultBuilder = RpcResultBuilder.<O>failed().withRpcErrors(errors);
+ }
+
finalFuture.set(rpcResultBuilder.build());
}
*/
package org.opendaylight.openflowplugin.impl.services;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
-
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Future;
+import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.util.FlowUtil;
import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SalFlowServiceImpl implements SalFlowService {
+public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
private static final Logger LOG = LoggerFactory.getLogger(SalFlowServiceImpl.class);
private final FlowService<UpdateFlowOutput> flowUpdate;
private final FlowService<AddFlowOutput> flowAdd;
private final FlowService<RemoveFlowOutput> flowRemove;
+ private final DeviceContext deviceContext;
+ private ItemLifecycleListener itemLifecycleListener;
public SalFlowServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ this.deviceContext = deviceContext;
flowRemove = new FlowService(requestContextStack, deviceContext, RemoveFlowOutput.class);
flowAdd = new FlowService<>(requestContextStack, deviceContext, AddFlowOutput.class);
flowUpdate = new FlowService<>(requestContextStack, deviceContext, UpdateFlowOutput.class);
}
+ @Override
+ public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
+ this.itemLifecycleListener = itemLifecycleListener;
+ }
+
@Override
public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
final FlowId flowId;
flowId = FlowUtil.createAlienFlowId(input.getTableId());
}
- final DeviceContext deviceContext = flowAdd.getDeviceContext();
final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(input.getTableId(), flowId);
deviceContext.getDeviceFlowRegistry().store(flowRegistryKey, flowDescriptor);
public void onSuccess(final RpcResult<AddFlowOutput> rpcResult) {
if (rpcResult.isSuccessful()) {
LOG.debug("flow add finished without error, id={}", flowId.getValue());
+ if (itemLifecycleListener != null) {
+ KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+ deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ final FlowBuilder flowBuilder = new FlowBuilder(input).setId(flowDescriptor.getFlowId());
+ itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
+ }
} else {
LOG.debug("flow add failed with error, id={}", flowId.getValue());
}
public void onSuccess(final RpcResult<RemoveFlowOutput> result) {
if (result.isSuccessful()) {
FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(input);
- flowRemove.getDeviceContext().getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
+ deviceContext.getDeviceFlowRegistry().markToBeremoved(flowRegistryKey);
+ if (itemLifecycleListener != null) {
+ final FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
+ if (flowDescriptor != null) {
+ KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+ deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ itemLifecycleListener.onRemoved(flowPath);
+ }
+ }
} else {
if (LOG.isTraceEnabled()) {
StringBuilder errors = new StringBuilder();
FlowRegistryKey updatedflowRegistryKey = FlowRegistryKeyFactory.create(updated);
final FlowRef flowRef = input.getFlowRef();
- final DeviceFlowRegistry deviceFlowRegistry = flowUpdate.getDeviceContext().getDeviceFlowRegistry();
+ final DeviceFlowRegistry deviceFlowRegistry = deviceContext.getDeviceFlowRegistry();
deviceFlowRegistry.markToBeremoved(flowRegistryKey);
+
+ if (itemLifecycleListener != null) {
+ final FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
+ if (flowDescriptor != null) {
+ KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+ deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ itemLifecycleListener.onRemoved(flowPath);
+ }
+ }
//if provided, store flow id to flow registry
if (flowRef != null) {
final FlowId flowId = flowRef.getValue().firstKeyOf(Flow.class, FlowKey.class).getId();
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create(updated.getTableId(), flowId);
deviceFlowRegistry.store(updatedflowRegistryKey, flowDescriptor);
+
+ if (itemLifecycleListener != null) {
+ KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
+ deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ final FlowBuilder flowBuilder = new FlowBuilder(input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
+ itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
+ }
}
}
});
return future;
}
+
+ @VisibleForTesting
+ static KeyedInstanceIdentifier<Flow, FlowKey> createFlowPath(FlowDescriptor flowDescriptor,
+ KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
+ return nodePath.augmentation(FlowCapableNode.class)
+ .child(Table.class, flowDescriptor.getTableKey())
+ .child(Flow.class, new FlowKey(flowDescriptor.getFlowId()));
+ }
}
package org.opendaylight.openflowplugin.impl.services;
import java.util.concurrent.Future;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
-public class SalGroupServiceImpl implements SalGroupService {
+public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource {
+ private static final Logger LOG = LoggerFactory.getLogger(SalGroupServiceImpl.class);
private final GroupService<AddGroupInput, AddGroupOutput> addGroup;
private final GroupService<Group, UpdateGroupOutput> updateGroup;
private final GroupService<RemoveGroupInput, RemoveGroupOutput> removeGroup;
+ private final DeviceContext deviceContext;
+ private ItemLifecycleListener itemLifecycleListener;
public SalGroupServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ this.deviceContext = deviceContext;
addGroup = new GroupService<>(requestContextStack, deviceContext, AddGroupOutput.class);
updateGroup = new GroupService<>(requestContextStack, deviceContext, UpdateGroupOutput.class);
removeGroup = new GroupService<>(requestContextStack, deviceContext, RemoveGroupOutput.class);
}
+ @Override
+ public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
+ this.itemLifecycleListener = itemLifecycleListener;
+ }
+
@Override
public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
addGroup.getDeviceContext().getDeviceGroupRegistry().store(input.getGroupId());
- return addGroup.handleServiceCall(input);
+ final ListenableFuture<RpcResult<AddGroupOutput>> resultFuture = addGroup.handleServiceCall(input);
+ Futures.addCallback(resultFuture, new FutureCallback<RpcResult<AddGroupOutput>>() {
+ @Override
+ public void onSuccess(RpcResult<AddGroupOutput> result) {
+ if (result.isSuccessful()) {
+ LOG.debug("group add finished without error, id={}", input.getGroupId().getValue());
+ addIfNecessaryToDS(input.getGroupId(), input);
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error("group add failed for id={}. Exception: {}", input.getGroupId().getValue(), t);
+ }
+ });
+
+ return resultFuture;
}
+
@Override
public Future<RpcResult<UpdateGroupOutput>> updateGroup(final UpdateGroupInput input) {
- return updateGroup.handleServiceCall(input.getUpdatedGroup());
+ final ListenableFuture<RpcResult<UpdateGroupOutput>> resultFuture = updateGroup.handleServiceCall(input.getUpdatedGroup());
+ Futures.addCallback(resultFuture, new FutureCallback<RpcResult<UpdateGroupOutput>>() {
+ @Override
+ public void onSuccess(@Nullable RpcResult<UpdateGroupOutput> result) {
+ if (result.isSuccessful()) {
+ LOG.debug("Group update succeded");
+ removeIfNecessaryFromDS(input.getOriginalGroup().getGroupId());
+ addIfNecessaryToDS(input.getUpdatedGroup().getGroupId(), input.getUpdatedGroup());
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.debug("Group update failed for id={}. Exception: {}", input.getOriginalGroup().getGroupId(), t);
+ }
+ });
+ return resultFuture;
}
@Override
public Future<RpcResult<RemoveGroupOutput>> removeGroup(final RemoveGroupInput input) {
removeGroup.getDeviceContext().getDeviceGroupRegistry().markToBeremoved(input.getGroupId());
- return removeGroup.handleServiceCall(input);
+ final ListenableFuture<RpcResult<RemoveGroupOutput>> resultFuture = removeGroup.handleServiceCall(input);
+ Futures.addCallback(resultFuture, new FutureCallback<RpcResult<RemoveGroupOutput>>() {
+ @Override
+ public void onSuccess(@Nullable RpcResult<RemoveGroupOutput> result) {
+ if (result.isSuccessful()) {
+ LOG.debug("Group remove succeded");
+ removeIfNecessaryFromDS(input.getGroupId());
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error("Group remove failed for id={}. Exception: {}", input.getGroupId(), t);
+ }
+ });
+ return resultFuture;
+ }
+
+ private void removeIfNecessaryFromDS(final GroupId groupId) {
+ if (itemLifecycleListener != null) {
+ KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey> groupPath
+ = createGroupPath(groupId,
+ deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ itemLifecycleListener.onRemoved(groupPath);
+ }
+ }
+
+ private void addIfNecessaryToDS(final GroupId groupId, final Group data) {
+ if (itemLifecycleListener != null) {
+ KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey> groupPath
+ = createGroupPath(groupId,
+ deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ itemLifecycleListener.onAdded(groupPath, new GroupBuilder(data).build());
+ }
+ }
+
+ static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey> createGroupPath(final GroupId groupId, final KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
+ return nodePath.augmentation(FlowCapableNode.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group.class, new GroupKey(groupId));
}
}
package org.opendaylight.openflowplugin.impl.services;
import java.util.concurrent.Future;
+
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
-public class SalMeterServiceImpl implements SalMeterService {
+public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource {
+ private static final Logger LOG = LoggerFactory.getLogger(SalMeterServiceImpl.class);
private final MeterService<AddMeterInput, AddMeterOutput> addMeter;
private final MeterService<Meter, UpdateMeterOutput> updateMeter;
private final MeterService<RemoveMeterInput, RemoveMeterOutput> removeMeter;
+ private ItemLifecycleListener itemLifecycleListener;
+ private final DeviceContext deviceContext;
public SalMeterServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+ this.deviceContext = deviceContext;
addMeter = new MeterService<>(requestContextStack, deviceContext, AddMeterOutput.class);
updateMeter = new MeterService<>(requestContextStack, deviceContext, UpdateMeterOutput.class);
removeMeter = new MeterService<>(requestContextStack, deviceContext, RemoveMeterOutput.class);
}
+ @Override
+ public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
+ this.itemLifecycleListener = itemLifecycleListener;
+ }
+
@Override
public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
addMeter.getDeviceContext().getDeviceMeterRegistry().store(input.getMeterId());
- return addMeter.handleServiceCall(input);
+ final ListenableFuture<RpcResult<AddMeterOutput>> resultFuture = addMeter.handleServiceCall(input);
+ Futures.addCallback(resultFuture, new FutureCallback<RpcResult<AddMeterOutput>>() {
+
+ @Override
+ public void onSuccess(@Nullable RpcResult<AddMeterOutput> result) {
+ if (result.isSuccessful()) {
+ LOG.debug("Meter add finished without error, id={}", input.getMeterId());
+ addIfNecessaryToDS(input.getMeterId(),input);
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error("Meter add failed for id={}. Exception {}", input.getMeterId(), t);
+ }
+ });
+
+ return resultFuture;
}
@Override
public Future<RpcResult<UpdateMeterOutput>> updateMeter(final UpdateMeterInput input) {
- return updateMeter.handleServiceCall(input.getUpdatedMeter());
+ final ListenableFuture<RpcResult<UpdateMeterOutput>> resultFuture = updateMeter.handleServiceCall(input.getUpdatedMeter());
+
+ Futures.addCallback(resultFuture, new FutureCallback<RpcResult<UpdateMeterOutput>>() {
+
+ @Override
+ public void onSuccess(@Nullable RpcResult<UpdateMeterOutput> result) {
+ if (result.isSuccessful()) {
+ LOG.debug("Meter update finished without error, id={}", input.getOriginalMeter().getMeterId());
+ if (itemLifecycleListener != null) {
+ removeIfNecessaryFromDS(input.getOriginalMeter().getMeterId());
+ addIfNecessaryToDS(input.getUpdatedMeter().getMeterId(),input.getUpdatedMeter());
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error("Meter update failed. for id={}. Exception {}.",input.getOriginalMeter().getMeterId(),t);
+ }
+ });
+ return resultFuture;
}
@Override
public Future<RpcResult<RemoveMeterOutput>> removeMeter(final RemoveMeterInput input) {
removeMeter.getDeviceContext().getDeviceMeterRegistry().markToBeremoved(input.getMeterId());
- return removeMeter.handleServiceCall(input);
+ final ListenableFuture<RpcResult<RemoveMeterOutput>> resultFuture = removeMeter.handleServiceCall(input);
+ Futures.addCallback(resultFuture, new FutureCallback<RpcResult<RemoveMeterOutput>>() {
+
+ @Override
+ public void onSuccess(@Nullable RpcResult<RemoveMeterOutput> result) {
+ if (result.isSuccessful()) {
+ LOG.debug("Meter remove finished without error, id={}", input.getMeterId());
+ removeIfNecessaryFromDS(input.getMeterId());
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ LOG.error("Meter remove failed for id={}. Exception {}",input.getMeterId(),t);
+ }
+ });
+
+ return resultFuture;
+ }
+
+ private void removeIfNecessaryFromDS(final MeterId meterId) {
+ if (itemLifecycleListener != null) {
+ KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> meterPath
+ = createMeterPath(meterId,
+ deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ itemLifecycleListener.onRemoved(meterPath);
+ }
}
+
+ private void addIfNecessaryToDS(final MeterId meterId, final Meter data) {
+ if (itemLifecycleListener != null) {
+ KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> groupPath
+ = createMeterPath(meterId,
+ deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ itemLifecycleListener.onAdded(groupPath, new MeterBuilder(data).build());
+ }
+ }
+
+ static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> createMeterPath(final MeterId meterId, final KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
+ return nodePath.augmentation(FlowCapableNode.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter.class, new MeterKey(meterId));
+ }
+
}
package org.opendaylight.openflowplugin.impl.statistics;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
+import org.opendaylight.openflowplugin.impl.rpc.listener.ItemLifecycleListenerImpl;
import org.opendaylight.openflowplugin.impl.services.RequestContextUtil;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
private static final Logger LOG = LoggerFactory.getLogger(StatisticsContextImpl.class);
private static final String CONNECTION_CLOSED = "Connection closed.";
+
+ private final ItemLifecycleListener itemLifeCycleListener;
private final Collection<RequestContext<?>> requestContexts = new HashSet<>();
private final DeviceContext deviceContext;
private final DeviceState devState;
statListForCollecting.add(MultipartType.OFPMPQUEUE);
}
collectingStatType = ImmutableList.<MultipartType>copyOf(statListForCollecting);
+ itemLifeCycleListener = new ItemLifecycleListenerImpl(deviceContext);
}
@Override
this.pollTimeout = pollTimeout;
}
+ @Override
+ public Optional<Timeout> getPollTimeout() {
+ return Optional.fromNullable(pollTimeout);
+ }
+
void statChainFuture(final Iterator<MultipartType> iterator, final SettableFuture<Boolean> resultFuture) {
if ( ! iterator.hasNext()) {
resultFuture.set(Boolean.TRUE);
this.statisticsGatheringOnTheFlyService = statisticsGatheringOnTheFlyService;
}
+ @Override
+ public ItemLifecycleListener getItemLifeCycleListener() {
+ return itemLifeCycleListener;
+ }
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
for (final FlowsStatisticsUpdate flowsStatistics : data) {
for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
+ flowBuilder.addAugmentation(FlowStatisticsData.class, refineFlowStatisticsAugmentation(flowStat).build());
+
final short tableId = flowStat.getTableId();
final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(flowBuilder.build());
final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey, tableId);
}
}
+ /**
+ * Method extracts flow statistics out of flowAndStatistics model
+ *
+ * @param flowAndStats
+ */
+ private static FlowStatisticsDataBuilder refineFlowStatisticsAugmentation(final FlowAndStatisticsMapList flowAndStats) {
+ final FlowStatisticsBuilder flowStatisticsBuilder = new FlowStatisticsBuilder(flowAndStats);
+ final FlowStatisticsDataBuilder flowStatisticsDataBld = new FlowStatisticsDataBuilder();
+ flowStatisticsDataBld.setFlowStatistics(flowStatisticsBuilder.build());
+ return flowStatisticsDataBld;
+ }
+
public static void deleteAllKnownFlows(final DeviceContext deviceContext) {
if (deviceContext.getDeviceState().deviceSynchronized()) {
InstanceIdentifier<FlowCapableNode> flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
package org.opendaylight.openflowplugin.impl.statistics;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Future;
+import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
+import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.ChangeStatisticsWorkModeInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.GetStatisticsWorkModeOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.GetStatisticsWorkModeOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsWorkMode;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Created by Martin Bobak <mbobak@cisco.com> on 1.4.2015.
*/
-public class StatisticsManagerImpl implements StatisticsManager {
+public class StatisticsManagerImpl implements StatisticsManager, StatisticsManagerControlService {
private static final Logger LOG = LoggerFactory.getLogger(StatisticsManagerImpl.class);
+ private final RpcProviderRegistry rpcProviderRegistry;
private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
private static long currentTimerDelay = basicTimerDelay;
private static long maximumTimerDelay = 900000; //wait max 15 minutes for next statistics
+ private StatisticsWorkMode workMode = StatisticsWorkMode.COLLECTALL;
+ private Semaphore workModeGuard = new Semaphore(1, true);
+ private boolean shuttingDownStatisticsPolling;
+ private BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
+
@Override
public void setDeviceInitializationPhaseHandler(final DeviceInitializationPhaseHandler handler) {
deviceInitPhaseHandler = handler;
}
+ public StatisticsManagerImpl(RpcProviderRegistry rpcProviderRegistry) {
+ this.rpcProviderRegistry = rpcProviderRegistry;
+ controlServiceRegistration = rpcProviderRegistry.addRpcImplementation(StatisticsManagerControlService.class, this);
+ }
+
+ public StatisticsManagerImpl(RpcProviderRegistry rpcProviderRegistry, final boolean shuttingDownStatisticsPolling) {
+ this(rpcProviderRegistry);
+ this.shuttingDownStatisticsPolling = shuttingDownStatisticsPolling;
+ }
+
@Override
public void onDeviceContextLevelUp(final DeviceContext deviceContext) {
final StatisticsContext statisticsContext,
final TimeCounter timeCounter) {
if (null != hashedWheelTimer) {
- Timeout pollTimeout = hashedWheelTimer.newTimeout(new TimerTask() {
- @Override
- public void run(final Timeout timeout) throws Exception {
- pollStatistics(deviceContext, statisticsContext, timeCounter);
- }
- }, currentTimerDelay, TimeUnit.MILLISECONDS);
- statisticsContext.setPollTimeout(pollTimeout);
+ if (!shuttingDownStatisticsPolling) {
+ Timeout pollTimeout = hashedWheelTimer.newTimeout(new TimerTask() {
+ @Override
+ public void run(final Timeout timeout) throws Exception {
+ pollStatistics(deviceContext, statisticsContext, timeCounter);
+ }
+ }, currentTimerDelay, TimeUnit.MILLISECONDS);
+ statisticsContext.setPollTimeout(pollTimeout);
+ }
}
}
- private void calculateTimerDelay(final TimeCounter timeCounter) {
+ @VisibleForTesting
+ protected void calculateTimerDelay(final TimeCounter timeCounter) {
+ // TODO: move into TimeCounter
long averageStatisticsGatheringTime = timeCounter.getAverageTimeBetweenMarks();
if (averageStatisticsGatheringTime > currentTimerDelay) {
currentTimerDelay *= 2;
}
}
+ @VisibleForTesting
+ protected static long getCurrentTimerDelay() {
+ return currentTimerDelay;
+ }
+
@Override
public void onDeviceContextClosed(final DeviceContext deviceContext) {
StatisticsContext statisticsContext = contexts.remove(deviceContext);
}
}
- private final class TimeCounter {
- private long beginningOfTime;
- private long delta;
- private int marksCount = 0;
-
- public void markStart() {
- beginningOfTime = System.nanoTime();
- delta = 0;
- marksCount = 0;
- }
-
- public void addTimeMark() {
- delta += System.nanoTime() - beginningOfTime;
- marksCount++;
- }
+ @Override
+ public Future<RpcResult<GetStatisticsWorkModeOutput>> getStatisticsWorkMode() {
+ GetStatisticsWorkModeOutputBuilder smModeOutputBld = new GetStatisticsWorkModeOutputBuilder();
+ smModeOutputBld.setMode(workMode);
+ return RpcResultBuilder.success(smModeOutputBld.build()).buildFuture();
+ }
- public long getAverageTimeBetweenMarks() {
- long average = 0;
- if (marksCount > 0) {
- average = delta / marksCount;
+ @Override
+ public Future<RpcResult<Void>> changeStatisticsWorkMode(ChangeStatisticsWorkModeInput input) {
+ final Future<RpcResult<Void>> result;
+ // acquire exclusive access
+ if (workModeGuard.tryAcquire()) {
+ final StatisticsWorkMode targetWorkMode = input.getMode();
+ if (!workMode.equals(targetWorkMode)) {
+ shuttingDownStatisticsPolling = StatisticsWorkMode.FULLYDISABLED.equals(targetWorkMode);
+ // iterate through stats-ctx: propagate mode
+ for (Map.Entry<DeviceContext, StatisticsContext> contextEntry : contexts.entrySet()) {
+ final DeviceContext deviceContext = contextEntry.getKey();
+ final StatisticsContext statisticsContext = contextEntry.getValue();
+ switch (targetWorkMode) {
+ case COLLECTALL:
+ scheduleNextPolling(deviceContext, statisticsContext, new TimeCounter());
+ for (ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
+ lifeCycleSource.setItemLifecycleListener(null);
+ }
+ break;
+ case FULLYDISABLED:
+ final Optional<Timeout> pollTimeout = statisticsContext.getPollTimeout();
+ if (pollTimeout.isPresent()) {
+ pollTimeout.get().cancel();
+ }
+ for (ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
+ lifeCycleSource.setItemLifecycleListener(statisticsContext.getItemLifeCycleListener());
+ }
+ break;
+ default:
+ LOG.warn("statistics work mode not supported: {}", targetWorkMode);
+ }
+ }
+ workMode = targetWorkMode;
}
- return TimeUnit.NANOSECONDS.toMillis(average);
+ workModeGuard.release();
+ result = RpcResultBuilder.<Void>success().buildFuture();
+ } else {
+ result = RpcResultBuilder.<Void>failed()
+ .withError(RpcError.ErrorType.APPLICATION, "mode change already in progress")
+ .buildFuture();
}
+ return result;
+ }
+ @Override
+ public void close() {
+ if (controlServiceRegistration != null) {
+ controlServiceRegistration.close();
+ controlServiceRegistration = null;
+ }
}
}
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.impl.statistics;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Moving average - measure and compute
+ */
+public class TimeCounter {
+ private long beginningOfLap;
+ private long delta;
+ private int marksCount = 0;
+
+ public void markStart() {
+ beginningOfLap = System.nanoTime();
+ delta = 0;
+ marksCount = 0;
+ }
+
+ public void addTimeMark() {
+ final long now = System.nanoTime();
+ delta += now - beginningOfLap;
+ marksCount++;
+ beginningOfLap = now;
+ }
+
+ public long getAverageTimeBetweenMarks() {
+ long average = 0;
+ if (marksCount > 0) {
+ average = delta / marksCount;
+ }
+ return TimeUnit.NANOSECONDS.toMillis(average);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+package org.opendaylight.openflowplugin.impl.translator;
+
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemovedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
+
+/**
+ * translate {@link FlowRemoved} message to FlowRemoved notification (omit instructions)
+ */
+public class FlowRemovedTranslator implements MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved> {
+
+ @Override
+ public org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved translate(FlowRemoved input, DeviceContext deviceContext, Object connectionDistinguisher) {
+ FlowRemovedBuilder flowRemovedBld = new FlowRemovedBuilder()
+ .setMatch(translateMatch(input, deviceContext).build())
+ .setCookie(new FlowCookie(input.getCookie()))
+ .setNode(new NodeRef(deviceContext.getDeviceState().getNodeInstanceIdentifier()))
+ .setPriority(input.getPriority())
+ .setTableId(input.getTableId().getValue().shortValue());
+
+ return flowRemovedBld.build();
+ }
+
+ protected MatchBuilder translateMatch(FlowRemoved flowRemoved, DeviceContext deviceContext) {
+ return MatchConvertorImpl.fromOFMatchToSALMatch(flowRemoved.getMatch(),
+ deviceContext.getDeviceState().getFeatures().getDatapathId(), OpenflowVersion.OF13);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.impl.translator;
+
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
+
+/**
+ * translate {@link FlowRemoved} message to FlowRemoved notification (omit instructions)
+ */
+public class FlowRemovedV10Translator extends FlowRemovedTranslator {
+
+ protected MatchBuilder translateMatch(FlowRemoved flowRemoved, DeviceContext deviceContext) {
+ return MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowRemoved.getMatchV10(),
+ deviceContext.getDeviceState().getFeatures().getDatapathId(), OpenflowVersion.OF10);
+ }
+}
import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian;
import org.opendaylight.openflowplugin.impl.translator.AggregatedFlowStatisticsTranslator;
+import org.opendaylight.openflowplugin.impl.translator.FlowRemovedTranslator;
+import org.opendaylight.openflowplugin.impl.translator.FlowRemovedV10Translator;
import org.opendaylight.openflowplugin.impl.translator.PacketReceivedTranslator;
import org.opendaylight.openflowplugin.impl.translator.PortUpdateTranslator;
import org.opendaylight.openflowplugin.impl.translator.TranslatorKeyFactory;
import org.opendaylight.openflowplugin.impl.translator.TranslatorLibraryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCase;
addTranslator(of13TranslatorKeyFactory.createTranslatorKey(PacketIn.class), new PacketReceivedTranslator()).
addTranslator(of13TranslatorKeyFactory.createTranslatorKey(PortGrouping.class), new PortUpdateTranslator()).
addTranslator(of13TranslatorKeyFactory.createTranslatorKey(MultipartReplyAggregateCase.class), new AggregatedFlowStatisticsTranslator()).
+ addTranslator(of13TranslatorKeyFactory.createTranslatorKey(FlowRemoved.class), new FlowRemovedTranslator()).
addTranslator(of10TranslatorKeyFactory.createTranslatorKey(PacketIn.class), new PacketReceivedTranslator()).
addTranslator(of10TranslatorKeyFactory.createTranslatorKey(PortGrouping.class), new PortUpdateTranslator()).
addTranslator(of10TranslatorKeyFactory.createTranslatorKey(MultipartReplyAggregateCase.class), new AggregatedFlowStatisticsTranslator()).
+ addTranslator(of10TranslatorKeyFactory.createTranslatorKey(FlowRemoved.class), new FlowRemovedV10Translator()).
build();
}
openflowPluginProvider.setNotificationProviderService(getNotificationAdapterDependency());
openflowPluginProvider.setNotificationPublishService(getNotificationPublishAdapterDependency());
openflowPluginProvider.setSwitchFeaturesMandatory(getSwitchFeaturesMandatory());
+ openflowPluginProvider.setIsStatisticsPollingOff(getIsStatisticsPollingOff());
openflowPluginProvider.initialize();
return openflowPluginProvider;
type uint32;
default 131072;
}
+ leaf is-statistics-polling-off {
+ type boolean;
+ default "false";
+ }
}
}
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
+import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
private BindingAwareBroker.RoutedRpcRegistration<RpcService> routedRpcRegistration;
@Mock
private DeviceState deviceState;
+ @Mock
+ private ItemLifeCycleRegistry itemLifeCycleRegistry;
+
private KeyedInstanceIdentifier<Node, NodeKey> nodePath;
@Before
Mockito.when(connectionContext.getFeatures()).thenReturn(features);
Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
+ Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
}
package org.opendaylight.openflowplugin.impl.services;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.math.BigInteger;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import junit.framework.TestCase;
import org.junit.Before;
+import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Matchers;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.*;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-import junit.framework.TestCase;
-import org.junit.Test;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-
-import java.math.BigInteger;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@RunWith(MockitoJUnitRunner.class)
public class SalFlowServiceImplTest extends TestCase {
private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444");
private static final Short DUMMY_VERSION = OFConstants.OFP_VERSION_1_3;
+ private static final String DUMMY_NODE_ID = "dummyNodeID";
+ private static final String DUMMY_FLOW_ID = "dummyFlowID";
+ private static final Short DUMMY_TABLE_ID = (short) 0;
+
+ private static final KeyedInstanceIdentifier<Node, NodeKey> NODE_II
+ = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(DUMMY_NODE_ID)));
+ private static final KeyedInstanceIdentifier<Table, TableKey> TABLE_II
+ = NODE_II.augmentation(FlowCapableNode.class).child(Table.class, new TableKey(DUMMY_TABLE_ID));
+
+ @Mock
+ private RequestContextStack mockedRequestContextStack;
@Mock
- RequestContextStack mockedRequestContextStack;
+ private DeviceContext mockedDeviceContext;
@Mock
- DeviceContext mockedDeviceContext;
+ private ConnectionContext mockedPrimConnectionContext;
@Mock
- ConnectionContext mockedPrimConnectionContext;
+ private FeaturesReply mockedFeatures;
@Mock
- FeaturesReply mockedFeatures;
+ private ConnectionAdapter mockedConnectionAdapter;
@Mock
- ConnectionAdapter mockedConnectionAdapter;
+ private MessageSpy mockedMessagSpy;
@Mock
- MessageSpy mockedMessagSpy;
+ private RequestContext<Object> requestContext;
+ @Mock
+ private OutboundQueue outboundQueue;
+ @Mock
+ private Match match;
+ private SalFlowServiceImpl salFlowService;
+ @Mock
+ DeviceState mockedDeviceState;
+ @Mock
+ private DeviceFlowRegistry deviceFlowRegistry;
@Before
public void initialization() {
when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
+ when(mockedPrimConnectionContext.getOutboundQueueProvider()).thenReturn(outboundQueue);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
- when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
+ when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(deviceFlowRegistry);
+ when(mockedRequestContextStack.createRequestContext()).thenReturn(requestContext);
+
+ when(requestContext.getXid()).thenReturn(new Xid(84L));
+ when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success().buildFuture());
+
+ salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext);
+
+
+ when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_II);
+ when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
}
@Test
public void testAddFlow() throws Exception {
- final SalFlowServiceImpl salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext);
+ addFlow(null);
+ }
- AddFlowInput mockedAddFlowInput = mock(AddFlowInput.class);
- when(mockedAddFlowInput.getMatch()).thenReturn(mock(Match.class));
+ @Test
+ public void testAddFlowWithItemLifecycle() throws Exception {
+ addFlow(mock(ItemLifecycleListener.class));
+ }
+
+ private void addFlow(final ItemLifecycleListener itemLifecycleListener) throws ExecutionException, InterruptedException {
+ AddFlowInput mockedAddFlowInput = createFlowMock(AddFlowInput.class);
+ salFlowService.setItemLifecycleListener(itemLifecycleListener);
verifyOutput(salFlowService.addFlow(mockedAddFlowInput));
+ if (itemLifecycleListener != null) {
+ Mockito.verify(itemLifecycleListener).onAdded(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
+ }
}
@Test
public void testRemoveFlow() throws Exception {
- final SalFlowServiceImpl salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext);
+ removeFlow(null);
+ }
+
+ @Test
+ public void testRemoveFlowWithItemLifecycle() throws Exception {
+ removeFlow(mock(ItemLifecycleListener.class));
+ }
+
+ private void removeFlow(final ItemLifecycleListener itemLifecycleListener) throws Exception {
+ RemoveFlowInput mockedRemoveFlowInput = createFlowMock(RemoveFlowInput.class);
+
+ if (itemLifecycleListener != null) {
+ salFlowService.setItemLifecycleListener(itemLifecycleListener);
+ mockingFlowRegistryLookup();
+
+ }
- RemoveFlowInput mockedRemoveFlowInput = mock(RemoveFlowInput.class);
verifyOutput(salFlowService.removeFlow(mockedRemoveFlowInput));
+ if (itemLifecycleListener != null) {
+ Mockito.verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any());
+ }
+
}
@Test
public void testUpdateFlow() throws Exception {
- final SalFlowServiceImpl salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext);
+ updateFlow(null);
+ }
- UpdateFlowInput mockedUpdateFlowInput = mock(UpdateFlowInput.class);
+ @Test
+ public void testUpdateFlowWithItemLifecycle() throws Exception {
+ updateFlow(mock(ItemLifecycleListener.class));
+ }
+ private void updateFlow(final ItemLifecycleListener itemLifecycleListener) throws Exception {
+ UpdateFlowInput mockedUpdateFlowInput = mock(UpdateFlowInput.class);
- UpdatedFlow mockedUpdateFlow = mock(UpdatedFlow.class);
- when(mockedUpdateFlow.getMatch()).thenReturn(mock(Match.class));
+ UpdatedFlow mockedUpdateFlow = createFlowMock(UpdatedFlow.class);
when(mockedUpdateFlowInput.getUpdatedFlow()).thenReturn(mockedUpdateFlow);
+ FlowRef mockedFlowRef = mock(FlowRef.class);
+ Mockito.doReturn(TABLE_II.child(Flow.class, new FlowKey(new FlowId(DUMMY_FLOW_ID)))).when(mockedFlowRef).getValue();
+ when(mockedUpdateFlowInput.getFlowRef()).thenReturn(mockedFlowRef);
- OriginalFlow mockedOriginalFlow = mock(OriginalFlow.class);
- when(mockedOriginalFlow.getMatch()).thenReturn(mock(Match.class));
+ OriginalFlow mockedOriginalFlow = createFlowMock(OriginalFlow.class);
when(mockedUpdateFlowInput.getOriginalFlow()).thenReturn(mockedOriginalFlow);
+ if (itemLifecycleListener != null) {
+ salFlowService.setItemLifecycleListener(itemLifecycleListener);
+ mockingFlowRegistryLookup();
+ }
+
verifyOutput(salFlowService.updateFlow(mockedUpdateFlowInput));
+
+ if (itemLifecycleListener != null) {
+ Mockito.verify(itemLifecycleListener).onAdded(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
+ Mockito.verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any());
+ }
+
+ }
+
+ private void mockingFlowRegistryLookup() {
+ FlowDescriptor mockedFlowDescriptor = mock(FlowDescriptor.class);
+ when(mockedFlowDescriptor.getFlowId()).thenReturn(new FlowId(DUMMY_FLOW_ID));
+ when(mockedFlowDescriptor.getTableKey()).thenReturn(new TableKey(DUMMY_TABLE_ID));
+
+ when(deviceFlowRegistry.retrieveIdForFlow(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
}
private <T extends DataObject> void verifyOutput(Future<RpcResult<T>> rpcResultFuture) throws ExecutionException, InterruptedException {
assertNotNull(addFlowOutputRpcResult);
assertTrue(addFlowOutputRpcResult.isSuccessful());
}
+
+ private <T extends org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow> T createFlowMock(Class<T> flowClazz) {
+ T mockedFlow = mock(flowClazz);
+ when(mockedFlow.getMatch()).thenReturn(match);
+ return mockedFlow;
+ }
}
\ No newline at end of file
package org.opendaylight.openflowplugin.impl.services;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import org.junit.Test;
+import org.mockito.Matchers;
import org.mockito.Mock;
import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroupBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
public class SalGroupServiceImplTest extends ServiceMocking {
private static final Long DUMMY_GROUP_ID = 15L;
- public SalGroupService salGroupService;
@Mock
DeviceGroupRegistry mockedDeviceGroupRegistry;
+ SalGroupServiceImpl salGroupService;
+
@Override
public void initialization() {
super.initialization();
- salGroupService = new SalGroupServiceImpl(mockedRequestContextStack, mockedDeviceContext);
when(mockedDeviceContext.getDeviceGroupRegistry()).thenReturn(mockedDeviceGroupRegistry);
+ salGroupService = new SalGroupServiceImpl(mockedRequestContextStack, mockedDeviceContext);
}
@Test
public void testAddGroup() throws Exception {
+ addGroup(null);
+ }
+
+ @Test
+ public void testAddGroupWithItemLifecycle() throws Exception {
+ addGroup(mock(ItemLifecycleListener.class));
+ }
+
+ private void addGroup(final ItemLifecycleListener itemLifecycleListener) {
final GroupId dummyGroupId = new GroupId(DUMMY_GROUP_ID);
AddGroupInput addGroupInput = new AddGroupInputBuilder().setGroupId(dummyGroupId).build();
+ this.<AddGroupOutput>mockSuccessfulFuture();
+
+ salGroupService.setItemLifecycleListener(itemLifecycleListener);
+
salGroupService.addGroup(addGroupInput);
verify(mockedRequestContextStack).createRequestContext();
verify(mockedDeviceGroupRegistry).store(eq(dummyGroupId));
+
+ if (itemLifecycleListener != null) {
+ verify(itemLifecycleListener).onAdded(Matchers.<KeyedInstanceIdentifier<Group, GroupKey>>any(),Matchers.<Group>any());
+ }
}
@Test
public void testUpdateGroup() throws Exception {
- UpdatedGroup mockedUptatedGroup = mock(UpdatedGroup.class);
- final UpdateGroupInput updateGroupInput = new UpdateGroupInputBuilder().setUpdatedGroup(mockedUptatedGroup).build();
+ updateGroup(null);
+ }
+
+ @Test
+ public void testUpdateGroupWithItemLifecycle() throws Exception {
+ updateGroup(mock(ItemLifecycleListener.class));
+ }
+
+ private void updateGroup(final ItemLifecycleListener itemLifecycleListener) {
+ final UpdatedGroup updatedGroup = new UpdatedGroupBuilder().setGroupId(new GroupId(DUMMY_GROUP_ID)).build();
+ final OriginalGroup originalGroup = new OriginalGroupBuilder().setGroupId(new GroupId(DUMMY_GROUP_ID)).build();
+ final UpdateGroupInput updateGroupInput = new UpdateGroupInputBuilder().setUpdatedGroup(updatedGroup).setOriginalGroup(originalGroup).build();
+
+ this.<UpdateGroupOutput>mockSuccessfulFuture();
+
+ salGroupService.setItemLifecycleListener(itemLifecycleListener);
+
salGroupService.updateGroup(updateGroupInput);
verify(mockedRequestContextStack).createRequestContext();
+
+ if (itemLifecycleListener != null) {
+ verify(itemLifecycleListener).onAdded(Matchers.<KeyedInstanceIdentifier<Group, GroupKey>>any(),Matchers.<Group>any());
+ verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Group, GroupKey>>any());
+ }
}
@Test
public void testRemoveGroup() throws Exception {
+ removeGroup(null);
+ }
+
+ @Test
+ public void testRemoveGroupWithItemLifecycle() throws Exception {
+ removeGroup(mock(ItemLifecycleListener.class));
+ }
+
+ private void removeGroup(final ItemLifecycleListener itemLifecycleListener) throws Exception {
final GroupId dummyGroupId = new GroupId(DUMMY_GROUP_ID);
RemoveGroupInput removeGroupInput = new RemoveGroupInputBuilder().setGroupId(dummyGroupId).build();
+ this.<RemoveGroupOutput>mockSuccessfulFuture();
+
+ salGroupService.setItemLifecycleListener(itemLifecycleListener);
+
salGroupService.removeGroup(removeGroupInput);
verify(mockedRequestContextStack).createRequestContext();
verify(mockedDeviceGroupRegistry).markToBeremoved(eq(dummyGroupId));
+
+ if (itemLifecycleListener != null) {
+ verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Group, GroupKey>>any());
+ }
}
}
\ No newline at end of file
package org.opendaylight.openflowplugin.impl.services;
-import junit.framework.TestCase;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import org.junit.Test;
+import org.mockito.Matchers;
import org.mockito.Mock;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.mockito.Mockito;
import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
+import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
public class SalMeterServiceImplTest extends ServiceMocking {
private static final Long DUMMY_METER_ID = 15L;
- public SalMeterService salMeterService;
+ private static final Long DUMMY_METTER_ID = 2000L;
@Mock
DeviceMeterRegistry mockedDeviceMeterRegistry;
+ SalMeterServiceImpl salMeterService;
+
@Override
public void initialization() {
super.initialization();
- salMeterService = new SalMeterServiceImpl(mockedRequestContextStack, mockedDeviceContext);
when(mockedDeviceContext.getDeviceMeterRegistry()).thenReturn(mockedDeviceMeterRegistry);
+ salMeterService = new SalMeterServiceImpl(mockedRequestContextStack, mockedDeviceContext);
}
@Test
public void testAddMeter() throws Exception {
+ addMeter(null);
+ }
+
+ @Test
+ public void testAddMeterWithItemLifecycle() throws Exception {
+ addMeter(mock(ItemLifecycleListener.class));
+ }
+
+ private void addMeter(final ItemLifecycleListener itemLifecycleListener) {
final MeterId dummyMeterId = new MeterId(DUMMY_METER_ID);
AddMeterInput addMeterInput = new AddMeterInputBuilder().setMeterId(dummyMeterId).build();
+ this.<AddMeterOutput>mockSuccessfulFuture();
+
+ salMeterService.setItemLifecycleListener(itemLifecycleListener);
+
salMeterService.addMeter(addMeterInput);
verify(mockedRequestContextStack).createRequestContext();
verify(mockedDeviceMeterRegistry).store(eq(dummyMeterId));
+
+ if (itemLifecycleListener != null) {
+ verify(itemLifecycleListener).onAdded(Matchers.<KeyedInstanceIdentifier<Meter, MeterKey>>any(),Matchers.<Meter>any());
+ }
}
@Test
public void testUpdateMeter() throws Exception {
- UpdatedMeter mockedUptatedMeter = mock(UpdatedMeter.class);
- final UpdateMeterInput updateMeterInput = new UpdateMeterInputBuilder().setUpdatedMeter(mockedUptatedMeter).build();
+ updateMeter(null);
+ }
+
+ @Test
+ public void testUpdateMeterWithItemLifecycle() throws Exception {
+ updateMeter(mock(ItemLifecycleListener.class));
+ }
+
+ private void updateMeter(final ItemLifecycleListener itemLifecycleListener) throws Exception {
+ final UpdatedMeter dummyUpdatedMeter = new UpdatedMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build();
+ final OriginalMeter dummyOriginalMeter = new OriginalMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build();
+
+ final UpdateMeterInput updateMeterInput = new UpdateMeterInputBuilder().setUpdatedMeter(dummyUpdatedMeter).setOriginalMeter(dummyOriginalMeter).build();
+
+ this.<AddMeterOutput>mockSuccessfulFuture();
+
+ salMeterService.setItemLifecycleListener(itemLifecycleListener);
+
salMeterService.updateMeter(updateMeterInput);
verify(mockedRequestContextStack).createRequestContext();
+
+ if (itemLifecycleListener != null) {
+ verify(itemLifecycleListener).onAdded(Matchers.<KeyedInstanceIdentifier<Meter, MeterKey>>any(),Matchers.<Meter>any());
+ verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Meter, MeterKey>>any());
+ }
}
@Test
public void testRemoveMeter() throws Exception {
+ removeMeter(null);
+ }
+
+ @Test
+ public void testRemoveMeterWithItemLifecycle() throws Exception {
+ removeMeter(mock(ItemLifecycleListener.class));
+ }
+
+ private void removeMeter(final ItemLifecycleListener itemLifecycleListener) throws Exception {
final MeterId dummyMeterId = new MeterId(DUMMY_METER_ID);
RemoveMeterInput removeMeterInput = new RemoveMeterInputBuilder().setMeterId(dummyMeterId).build();
+ this.<RemoveMeterOutput>mockSuccessfulFuture();
+
+ salMeterService.setItemLifecycleListener(itemLifecycleListener);
+
salMeterService.removeMeter(removeMeterInput);
verify(mockedRequestContextStack).createRequestContext();
verify(mockedDeviceMeterRegistry).markToBeremoved(eq(dummyMeterId));
+
+ if (itemLifecycleListener != null) {
+ verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Meter, MeterKey>>any());
+ }
}
}
\ No newline at end of file
package org.opendaylight.openflowplugin.impl.services;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.HashedWheelTimer;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.*;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import java.math.BigInteger;
public abstract class ServiceMocking {
private static final BigInteger DUMMY_DATAPATH_ID = new BigInteger("444");
private static final Short DUMMY_VERSION = OFConstants.OFP_VERSION_1_3;
+ private static final Long DUMMY_XID_VALUE = 2121L;
+ private static final Xid DUMMY_XID = new Xid(DUMMY_XID_VALUE);
+
+ private static final String DUMMY_NODE_ID = "dummyNodeID";
+ private static final KeyedInstanceIdentifier<Node, NodeKey> NODE_II
+ = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(DUMMY_NODE_ID)));
+
@Mock
RequestContextStack mockedRequestContextStack;
DeviceState mockedDeviceState;
@Mock
DeviceInitializationPhaseHandler mockedDevicePhaseHandler;
+ @Mock
+ RequestContext mockedRequestContext;
+ @Mock
+ OutboundQueue mockedOutboundQueue;
@Before
public void initialization() {
+ when(mockedRequestContextStack.createRequestContext()).thenReturn(mockedRequestContext);
+ when(mockedRequestContext.getXid()).thenReturn(DUMMY_XID);
+
when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION);
when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures);
when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
when(mockedPrimConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
+ when(mockedPrimConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
+
+ when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_II);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
when(mockedDeviceContext.getTimer()).thenReturn(mock(HashedWheelTimer.class));
}
+
+ protected <T> void mockSuccessfulFuture() {
+ ListenableFuture<RpcResult<T>> dummySuccessfulFuture = Futures.immediateFuture(RpcResultBuilder.success((T) null).build());
+ when(mockedRequestContext.getFuture()).thenReturn(dummySuccessfulFuture);
+ }
+
}
package org.opendaylight.openflowplugin.impl.statistics;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
import io.netty.util.HashedWheelTimer;
+import java.math.BigInteger;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
-import java.math.BigInteger;
-
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
@RunWith(MockitoJUnitRunner.class)
public class StatisticsManagerImplTest extends TestCase {
DeviceState mockedDeviceState;
@Mock
DeviceInitializationPhaseHandler mockedDevicePhaseHandler;
+ @Mock
+ private RpcProviderRegistry rpcProviderRegistry;
@Before
public void initialization() {
@Test
public void testOnDeviceContextLevelUp() throws Exception {
- final StatisticsManagerImpl statisticsManager = new StatisticsManagerImpl();
+ final StatisticsManagerImpl statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry);
statisticsManager.setDeviceInitializationPhaseHandler(mockedDevicePhaseHandler);
statisticsManager.onDeviceContextLevelUp(mockedDeviceContext);
verify(mockedDeviceState).setDeviceSynchronized(eq(true));
--- /dev/null
+/*
+ * Copyright (c) 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
+ */
+
+package org.opendaylight.openflowplugin.impl.statistics;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test for {@link TimeCounter}.
+ */
+public class TimeCounterTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TimeCounterTest.class);
+ private TimeCounter timeCounter;
+
+ @Before
+ public void setUp() throws Exception {
+ timeCounter = new TimeCounter();
+ }
+
+ /**
+ * tm = time mark
+ * - tm1 at time 2 ms
+ * - tm2 at time 4 ms
+ * - tm3 at time 9 ms
+ *
+ * awaited average time:
+ * - tm1 = 2/1 = 2 ms
+ * - tm2 = 4/2 = 2 ms
+ * - tm3 = 9/3 = 3 ms
+ *
+ * But this times are only theoretical if whole test is executed without latency and atomically. Therefore awaited
+ * average times can't be compared to exact values of awaited average time (therefore == was replaced with >=)
+ * @throws Exception
+ */
+ @Test
+ public void testGetAverageTimeBetweenMarks() throws Exception {
+ Assert.assertEquals(0, timeCounter.getAverageTimeBetweenMarks());
+ timeCounter.markStart();
+ Assert.assertEquals(0, timeCounter.getAverageTimeBetweenMarks());
+
+ zzz(2L);
+ timeCounter.addTimeMark();
+ Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 2);
+
+ zzz(2L);
+ timeCounter.addTimeMark();
+ Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 2);
+
+ zzz(5L);
+ timeCounter.addTimeMark();
+ Assert.assertTrue(timeCounter.getAverageTimeBetweenMarks() >= 3);
+ }
+
+ private void zzz(long length) {
+ try {
+ Thread.sleep(length);
+ } catch (InterruptedException e) {
+ LOG.error("processing sleep interrupted", e);
+ }
+ }
+}
\ No newline at end of file
</dependency>
<dependency>
- <groupId>org.openexi</groupId>
- <artifactId>nagasena</artifactId>
- <scope>test</scope>
+ <groupId>openexi</groupId>
+ <artifactId>nagasena</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.openexi</groupId>
- <artifactId>nagasena-rta</artifactId>
- <scope>test</scope>
+ <groupId>openexi</groupId>
+ <artifactId>nagasena-rta</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
mavenBundle(OFPLUGIN, "openflowplugin").versionAsInProject(),
mavenBundle(OFPLUGIN_APPS, "forwardingrules-manager").versionAsInProject(),
mavenBundle(OFPLUGIN_APPS, "inventory-manager").versionAsInProject(),
- mavenBundle("org.openexi", "nagasena").versionAsInProject()
+ mavenBundle("openexi", "nagasena").versionAsInProject()
);
}
<version>${config.version}</version>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>${yangtools.version}</version>
<type>jar</type>
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
*/
public class HandshakeManagerImpl implements HandshakeManager {
+ private static final long activeXID = 20L;
+
private static final Logger LOG = LoggerFactory
.getLogger(HandshakeManagerImpl.class);
private Short version;
private ErrorHandler errorHandler;
- private long maxTimeout = 8000;
- private TimeUnit maxTimeoutUnit = TimeUnit.MILLISECONDS;
+
+
private Short highestVersion;
private Long activeXid;
}
LOG.trace("handshake STARTED");
- setActiveXid(20L);
+ setActiveXid(activeXID);
try {
if (receivedHello == null) {
* @throws Exception
*/
private ListenableFuture<Void> sendHelloMessage(Short helloVersion, final Long helloXid) throws Exception {
-
-
+
+
HelloInput helloInput = MessageFactory.createHelloInput(helloVersion, helloXid, versionOrder);
final SettableFuture<Void> resultFtr = SettableFuture.create();
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
import org.opendaylight.openflowplugin.openflow.md.core.extension.MatchExtensionHelper;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
-import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.duration.DurationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Class is an utility class for converting flow related statistics messages coming from openflow
* switch to MD-SAL messages.
salFlowStatsBuilder.setPriority(flowStats.getPriority());
salFlowStatsBuilder.setTableId(flowStats.getTableId());
if(flowStats.getMatchV10() != null){
- salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowStats.getMatchV10(),datapathid, OpenflowVersion.OF10));
+ salFlowStatsBuilder.setMatch(MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowStats.getMatchV10(), datapathid, OpenflowVersion.OF10).build());
if(flowStats.getAction() != null && flowStats.getAction().size()!=0){
salFlowStatsBuilder.setInstructions(OFToMDSalFlowConvertor.wrapOF10ActionsToInstruction(flowStats.getAction(), ofVersion));
}
import static org.opendaylight.openflowjava.util.ByteBufUtils.macAddressToString;
+import com.google.common.base.Optional;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-
+import javax.annotation.Nonnull;
import org.opendaylight.openflowjava.util.ByteBufUtils;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.arp.match.fields.ArpSourceHardwareAddressBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Optional;
-
/**
* Utility class for converting a MD-SAL Flow into the OF flow mod
*/
* @return
* @author avishnoi@in.ibm.com
*/
- public static Match fromOFMatchV10ToSALMatch(final MatchV10 swMatch, final BigInteger datapathid, final OpenflowVersion ofVersion) {
+ public static MatchBuilder fromOFMatchV10ToSALMatch(@Nonnull final MatchV10 swMatch, @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
MatchBuilder matchBuilder = new MatchBuilder();
EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
matchBuilder.setIpMatch(ipMatchBuilder.build());
}
- return matchBuilder.build();
+ return matchBuilder;
}
/**
* @author avishnoi@in.ibm.com
*/
public static MatchBuilder fromOFMatchToSALMatch(
- final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match swMatch,
- final BigInteger datapathid, final OpenflowVersion ofVersion) {
+ @Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match swMatch,
+ @Nonnull final BigInteger datapathid, @Nonnull final OpenflowVersion ofVersion) {
return OfMatchToSALMatchConvertor(swMatch.getMatchEntry(), datapathid, ofVersion);
}
if (ofMatch != null) {
salFlowRemoved.setMatch(fromMatch(ofMatch, sc.getFeatures().getDatapathId(), ofVersion));
} else if (ofFlow.getMatchV10() != null) {
- MatchBuilder matchBuilder = new MatchBuilder(MatchConvertorImpl.fromOFMatchV10ToSALMatch(ofFlow.getMatchV10(), sc.getFeatures().getDatapathId(), ofVersion));
+ MatchBuilder matchBuilder = new MatchBuilder(MatchConvertorImpl.fromOFMatchV10ToSALMatch(ofFlow.getMatchV10(), sc.getFeatures().getDatapathId(), ofVersion).build());
salFlowRemoved.setMatch(matchBuilder.build());
}
salFlowRemoved.setNode(new NodeRef(InventoryDataServiceUtil.identifierFromDatapathId(sc.getFeatures()
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;
import static org.junit.Assert.assertEquals;
+
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
FlowWildcardsV10 wc = wcBuilder.build();
MatchV10 ofMatch = builder.setWildcards(wc).build();
Match match = MatchConvertorImpl.fromOFMatchV10ToSALMatch(
- ofMatch, DPID, OpenflowVersion.OF10);
+ ofMatch, DPID, OpenflowVersion.OF10).build();
checkDefaultV10(match, wc, vid);
IpMatch ipMatch = match.getIpMatch();
wc = wcBuilder.setAll(true).build();
ofMatch = builder.setWildcards(wc).build();
match = MatchConvertorImpl.fromOFMatchV10ToSALMatch(
- ofMatch, DPID, OpenflowVersion.OF10);
+ ofMatch, DPID, OpenflowVersion.OF10).build();
checkDefaultV10(match, wc, vid);
assertEquals(null, match.getIpMatch());
}
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match;\r
\r
import java.math.BigInteger;\r
-\r
import org.junit.Assert;\r
import org.junit.Before;\r
import org.junit.Test;\r
builder.setTpDst(4096);\r
MatchV10 match = builder.build();\r
\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10);\r
+ Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
\r
Assert.assertEquals("Wrong in port", "openflow:42:6653", salMatch.getInPort().getValue());\r
Assert.assertEquals("Wrong dl src", new MacAddress("01:01:01:01:01:01"), salMatch.getEthernetMatch()\r
builder.setTpDst(4096);\r
MatchV10 match = builder.build();\r
\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10);\r
+ Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
true, true, true, true, true, true));\r
MatchV10 match = builder.build();\r
\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10);\r
+ Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
builder.setTpDst(4096);\r
MatchV10 match = builder.build();\r
\r
- Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10);\r
+ Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(match, new BigInteger("42"), OpenflowVersion.OF10).build();\r
\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl match", null, salMatch.getEthernetMatch());\r
\r
BigInteger dpid = BigInteger.valueOf(12345L);\r
Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl src",\r
true, true, false, true, true, true, false, true, true, true);\r
match = builder.setWildcards(wc).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl src",\r
Short ipProto = 1;\r
match = builder.setNwProto(ipProto).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
IpMatch ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
true, true, false, true, true, true, false, true, true, false);\r
match = builder.setWildcards(wc).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Short icmpType = 10;\r
match = builder.setTpSrc(icmpType.intValue()).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
Icmpv4Match icmpv4Match = salMatch.getIcmpv4Match();\r
true, true, false, true, true, true, false, true, false, false);\r
match = builder.setWildcards(wc).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
icmpv4Match = salMatch.getIcmpv4Match();\r
Short icmpCode = 33;\r
match = builder.setTpSrc(null).setTpDst(icmpCode.intValue()).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
icmpv4Match = salMatch.getIcmpv4Match();\r
match = builder.setTpSrc(icmpType.intValue()).\r
setTpDst(icmpCode.intValue()).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
icmpv4Match = salMatch.getIcmpv4Match();\r
\r
BigInteger dpid = BigInteger.valueOf(12345L);\r
Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl src",\r
Short ipProto = 6;\r
match = builder.setNwProto(ipProto).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
IpMatch ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
true, true, false, true, true, true, false, true, true, false);\r
match = builder.setWildcards(wc).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Integer srcPort = 60000;\r
match = builder.setTpSrc(srcPort).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
TcpMatch tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
true, true, false, true, true, true, false, true, false, false);\r
match = builder.setWildcards(wc).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
Integer dstPort = 6653;\r
match = builder.setTpSrc(null).setTpDst(dstPort).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
dstPort = 9999;\r
match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
tcpMatch = (TcpMatch)salMatch.getLayer4Match();\r
\r
BigInteger dpid = BigInteger.valueOf(12345L);\r
Match salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
EthernetMatch etherMatch = salMatch.getEthernetMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Assert.assertEquals("Wrong dl src",\r
Short ipProto = 17;\r
match = builder.setNwProto(ipProto).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
IpMatch ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
true, true, false, true, true, true, false, true, true, false);\r
match = builder.setWildcards(wc).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
Assert.assertEquals("Wrong in port", null, salMatch.getInPort());\r
Integer srcPort = 60000;\r
match = builder.setTpSrc(srcPort).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
UdpMatch udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
true, true, false, true, true, true, false, true, false, false);\r
match = builder.setWildcards(wc).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
Integer dstPort = 6653;\r
match = builder.setTpSrc(null).setTpDst(dstPort).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
dstPort = 9999;\r
match = builder.setTpSrc(srcPort).setTpDst(dstPort).build();\r
salMatch = MatchConvertorImpl.fromOFMatchV10ToSALMatch(\r
- match, dpid, OpenflowVersion.OF10);\r
+ match, dpid, OpenflowVersion.OF10).build();\r
etherMatch = salMatch.getEthernetMatch();\r
ipMatch = salMatch.getIpMatch();\r
udpMatch = (UdpMatch)salMatch.getLayer4Match();\r
<openflowjava.version>0.7.0-SNAPSHOT</openflowjava.version>
<openflowplugin.version>0.2.0-SNAPSHOT</openflowplugin.version>
<sal.api.version>0.10.0-SNAPSHOT</sal.api.version>
- <build.helper.version>1.8</build.helper.version>
<jmxGeneratorPath>src/main/yang-gen-config</jmxGeneratorPath>
<salGeneratorPath>src/main/yang-gen-sal</salGeneratorPath>
- <exi.nagasena.version>0000.0002.0038.0</exi.nagasena.version>
+ <exi.nagasena.version>0000.0002.0053.0</exi.nagasena.version>
<controller.distribution.version>0.3.0-SNAPSHOT</controller.distribution.version>
- <features.test.version>1.6.0-SNAPSHOT</features.test.version>
<!-- Sonar config -->
<sonar-jacoco-listeners.version>2.4</sonar-jacoco-listeners.version>
<config.version>0.4.0-SNAPSHOT</config.version>
<mdsal.version>1.3.0-SNAPSHOT</mdsal.version>
<yangtools.version>0.8.0-SNAPSHOT</yangtools.version>
-
- <features.test.version>1.6.0-SNAPSHOT</features.test.version>
- <karaf.distro.empty.version>1.6.0-SNAPSHOT</karaf.distro.empty.version>
- <dlux.version>0.3.0-SNAPSHOT</dlux.version>
</properties>
<dependencyManagement>
<scope>import</scope>
<type>pom</type>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-artifacts</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal.model</groupId>
+ <artifactId>mdsal-model-artifacts</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>config-artifacts</artifactId>
<scope>import</scope>
<type>pom</type>
</dependency>
- <dependency>
- <groupId>org.opendaylight.odlparent</groupId>
- <artifactId>features-test</artifactId>
- <version>${features.test.version}</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
<!-- thirdparty -->
<dependency>
- <groupId>org.openexi</groupId>
+ <groupId>openexi</groupId>
<artifactId>nagasena</artifactId>
<version>${exi.nagasena.version}</version>
</dependency>
<dependency>
- <groupId>org.openexi</groupId>
+ <groupId>openexi</groupId>
<artifactId>nagasena-rta</artifactId>
<version>${exi.nagasena.version}</version>
</dependency>
- <dependency>
- <groupId>xml-apis</groupId>
- <artifactId>xml-apis</artifactId>
- <version>1.4.01</version>
- </dependency>
</dependencies>
</dependencyManagement>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
- <version>${build.helper.version}</version>
<executions>
<execution>
<id>add-source</id>
</profile>
</profiles>
</project>
-
<module>samples/learning-switch</module>
<module>applications</module>
<module>model</module>
- <module>legacy</module>
</modules>
</project>
<artifactId>sal-binding-api</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
</dependency>
<dependency>
<artifactId>sal-binding-api</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools</groupId>
+ <groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
</dependency>
<dependency>
*.pyc
/.pydevproject
*.log
+.tox/
-Whole descriptions
+Wiki documentation
==================
https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin::Python_test_scripts
==========
note:
- all script have help which descipble all parameters
+ all script have help which describe all parameters
1. > python odl_crud_tests.py --odlhost 172.16.4.212 --fxmls 1,2
- This runs tests f1 and f2 aginast ODL running on specified IP.
-
- To run with all XMLs, omit the '--xmls' option.
+ This runs tests f1 and f2 against ODL running on the specified IP.
+
+ To run with all XMLs, omit the '--xmls' option.
For more options, type 'sudo python odl_crud_tests.py --help'
-
+
3. > src has to be in PYTHONPATH so you are able to run sudo PYTHONPATH=src stress_test python2.6 stress_test.py
@author: <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
'''
-import requests
+import xml.dom.minidom as md
from xml.dom.minidom import Element
+import requests
+
from openvswitch.parser_tools import ParseTools
from tools.crud_test_with_param_superclass import OF_CRUD_Test_Base
from tools.xml_parser_tools import XMLtoDictParserTools
-import xml.dom.minidom as md
METER_ID_TAG_NAME = 'meter-id'
# TODO : find why band-burst-size has same value as dscp-remark (same for band-rate)
-IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON = ['meter-name', 'container-name', 'band-burst-size', 'band-rate', 'flags', 'perc_level', 'barrier']
-
+IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON = [
+ 'meter-name',
+ 'container-name',
+ 'band-burst-size',
+ 'band-rate',
+ 'flags',
+ 'perc_level',
+ 'barrier']
METER_TAGS_FOR_UPDATE = ['band-burst-size', 'band-rate']
-class OF_CRUD_Test_Meters( OF_CRUD_Test_Base ):
+class OF_CRUD_Test_Meters(OF_CRUD_Test_Base):
- def setUp( self ):
- super( OF_CRUD_Test_Meters, self ).setUp()
+ def setUp(self):
+ super(OF_CRUD_Test_Meters, self).setUp()
# ----- PUT -----
- ids = ParseTools.get_values( self.xml_input_DOM, METER_ID_TAG_NAME )
- data = ( self.host, self.port, ids[METER_ID_TAG_NAME] )
+ ids = ParseTools.get_values(self.xml_input_DOM, METER_ID_TAG_NAME)
+ data = (self.host, self.port, ids[METER_ID_TAG_NAME])
self.conf_url = 'http://%s:%d/restconf/config/opendaylight-inventory:nodes' \
- '/node/openflow:1/meter/%s' % data
+ '/node/openflow:1/meter/%s' % data
self.oper_url = 'http://%s:%d/restconf/operational/opendaylight-inventory:nodes' \
- '/node/openflow:1/meter/%s' % data
+ '/node/openflow:1/meter/%s' % data
# ----- POST -----
- data = ( self.host, self.port )
+ data = (self.host, self.port)
self.conf_url_post = 'http://%s:%d/restconf/config/opendaylight-inventory:nodes' \
- '/node/openflow:1/' % data
+ '/node/openflow:1/' % data
# ----- SAL SERVICE OPERATIONS -----
self.oper_url_add = 'http://%s:%d/restconf/operations/sal-meter:add-meter' % data
self.oper_url_upd = 'http://%s:%d/restconf/operations/sal-meter:update-meter' % data
self.oper_url_del = 'http://%s:%d/restconf/operations/sal-meter:remove-meter' % data
# Modify input data
self.data_from_file_input = ''
- for node in self.xml_input_DOM.documentElement.childNodes :
- self.data_from_file_input += node.toxml( encoding = 'utf-8' )
+ for node in self.xml_input_DOM.documentElement.childNodes:
+ self.data_from_file_input += node.toxml(encoding='utf-8')
# The xml body without data - data come from file (all meter subtags)
self.oper_input_stream = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' \
- '<input xmlns="urn:opendaylight:meter:service">\n' \
- '%s' \
- '<node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node[inv:id="openflow:1"]</node>\n' \
- '</input>' % self.data_from_file_input
-
+ '<input xmlns="urn:opendaylight:meter:service">\n' \
+ ' %s' \
+ ' <node xmlns:inv="urn:opendaylight:inventory">' \
+ '/inv:nodes/inv:node[inv:id="openflow:1"]</node>\n' \
+ '</input>' % self.data_from_file_input
- def tearDown( self ) :
+ def tearDown(self):
# cleaning configuration DataStore without a response validation
- self.log.info( self._paint_msg_cyan( 'Uncontrolled cleaning after meter test' ) )
- requests.delete( self.conf_url, auth = self._get_auth(),
- headers = self._get_xml_result_header() )
+ self.log.info(self._paint_msg_cyan('Uncontrolled cleaning after meter test'))
+ requests.delete(self.conf_url,
+ auth=self._get_auth(),
+ headers=self._get_xml_result_header())
# cleaning device without a response validation
- requests.post( self.oper_url_del, data = self.oper_input_stream, auth = self._get_auth(),
- headers = self._get_xml_request_result_header() )
- super( OF_CRUD_Test_Meters, self ).tearDown()
-
-
- def test_conf_PUT( self ):
- self.log.info( "--- Meter conf. PUT test ---" )
+ requests.post(self.oper_url_del,
+ data=self.oper_input_stream,
+ auth=self._get_auth(),
+ headers=self._get_xml_request_result_header())
+ super(OF_CRUD_Test_Meters, self).tearDown()
+
+ def test_conf_PUT(self):
+ self.log.info("--- Meter conf. PUT test ---")
# -------------- CREATE -------------------
- self.log.info( self._paint_msg_yellow( " CREATE Meter by PUT REST" ) )
+ self.log.info(self._paint_msg_yellow(" CREATE Meter by PUT REST"))
# send request via RESTCONF
- self.put_REST_XML_conf_request( self.conf_url, self.xml_input_stream )
+ self.put_REST_XML_conf_request(self.conf_url, self.xml_input_stream)
# check request content against restconf's config datastore
- response = self.get_REST_XML_response( self.conf_url )
- xml_resp_stream = ( response.text ).encode( 'utf-8', 'ignore' )
- xml_resp_DOM = md.parseString( xml_resp_stream )
- self.assertDataDOM( self.xml_input_DOM, xml_resp_DOM )
+ response = self.get_REST_XML_response(self.conf_url)
+ xml_resp_stream = (response.text).encode('utf-8', 'ignore')
+ xml_resp_DOM = md.parseString(xml_resp_stream)
+ self.assertDataDOM(self.xml_input_DOM, xml_resp_DOM)
# check request content against restconf's operational datastore
- response = self.get_REST_XML_response( self.oper_url )
- self.__validate_contain_meter( response, self.xml_input_DOM )
+ response = self.get_REST_XML_response(self.oper_url)
+ self.__validate_contain_meter(response, self.xml_input_DOM)
# -------------- UPDATE -------------------
- self.log.info( self._paint_msg_yellow( " UPDATE Meter by PUT REST" ) )
+ self.log.info(self._paint_msg_yellow(" UPDATE Meter by PUT REST"))
xml_updated_stream = self.__update_meter_input()
- self.put_REST_XML_conf_request( self.conf_url, xml_updated_stream )
+ self.put_REST_XML_conf_request(self.conf_url, xml_updated_stream)
# check request content against restconf's config datastore
- response = self.get_REST_XML_response( self.conf_url )
- xml_resp_stream = ( response.text ).encode( 'utf-8', 'ignore' )
- xml_resp_DOM = md.parseString( xml_resp_stream )
- xml_upd_DOM = md.parseString( xml_updated_stream )
- self.assertDataDOM( xml_upd_DOM, xml_resp_DOM )
+ response = self.get_REST_XML_response(self.conf_url)
+ xml_resp_stream = (response.text).encode('utf-8', 'ignore')
+ xml_resp_DOM = md.parseString(xml_resp_stream)
+ xml_upd_DOM = md.parseString(xml_updated_stream)
+ self.assertDataDOM(xml_upd_DOM, xml_resp_DOM)
# check request content against restconf's operational datastore
- response = self.get_REST_XML_response( self.oper_url )
- self.__validate_contain_meter( response, xml_upd_DOM )
+ response = self.get_REST_XML_response(self.oper_url)
+ self.__validate_contain_meter(response, xml_upd_DOM)
# -------------- DELETE -------------------
- self.log.info( self._paint_msg_yellow( " DELETE Meter by DELETE REST " ) )
+ self.log.info(self._paint_msg_yellow(" DELETE Meter by DELETE REST "))
# Delte data from config DataStore
- response = self.delete_REST_XML_response( self.conf_url )
+ response = self.delete_REST_XML_response(self.conf_url)
# Data has been deleted, so we expect the 404 response code
- response = self.get_REST_XML_deleted_response( self.conf_url )
+ response = self.get_REST_XML_deleted_response(self.conf_url)
# Meter operational data has a specific content
# and the comparable data has to be filtered before comparison
- response = self.get_REST_XML_response( self.oper_url )
- self.__validate_contain_meter( response, self.xml_input_DOM, False )
+ response = self.get_REST_XML_response(self.oper_url)
+ self.__validate_contain_meter(response, self.xml_input_DOM, False)
-
- def test_conf_POST( self ):
- self.log.info( "--- Meter conf. POST test ---" )
+ def test_conf_POST(self):
+ self.log.info("--- Meter conf. POST test ---")
# -------------- CREATE -------------------
- self.log.info( self._paint_msg_yellow( " CREATE Meter by POST REST" ) )
+ self.log.info(self._paint_msg_yellow(" CREATE Meter by POST REST"))
# send request via RESTCONF
- self.post_REST_XML_request( self.conf_url_post, self.xml_input_stream )
+ self.post_REST_XML_request(self.conf_url_post, self.xml_input_stream)
# check request content against restconf's config datastore
- response = self.get_REST_XML_response( self.conf_url )
- xml_resp_stream = ( response.text ).encode( 'utf-8', 'ignore' )
- xml_resp_DOM = md.parseString( xml_resp_stream )
- self.assertDataDOM( self.xml_input_DOM, xml_resp_DOM )
+ response = self.get_REST_XML_response(self.conf_url)
+ xml_resp_stream = (response.text).encode('utf-8', 'ignore')
+ xml_resp_DOM = md.parseString(xml_resp_stream)
+ self.assertDataDOM(self.xml_input_DOM, xml_resp_DOM)
# check request content against restconf's operational datastore
- response = self.get_REST_XML_response( self.oper_url )
- self.__validate_contain_meter( response, self.xml_input_DOM )
+ response = self.get_REST_XML_response(self.oper_url)
+ self.__validate_contain_meter(response, self.xml_input_DOM)
# test error for double create (POST could create data only)
- self.log.info( self._paint_msg_yellow( " UPDATE Meter by POST REST" ) )
- response = self.post_REST_XML_repeat_request( self.conf_url_post, self.xml_input_stream )
+ self.log.info(self._paint_msg_yellow(" UPDATE Meter by POST REST"))
+ response = self.post_REST_XML_repeat_request(self.conf_url_post, self.xml_input_stream)
# -------------- DELETE -------------------
- self.log.info( self._paint_msg_yellow( " DELETE Meter by DELETE REST" ) )
+ self.log.info(self._paint_msg_yellow(" DELETE Meter by DELETE REST"))
# Delte data from config DataStore
- response = self.delete_REST_XML_response( self.conf_url )
+ response = self.delete_REST_XML_response(self.conf_url)
# Data has been deleted, so we expect the 404 response code
- response = self.get_REST_XML_deleted_response( self.conf_url )
+ response = self.get_REST_XML_deleted_response(self.conf_url)
# Meter operational data has a specific content
# and the comparable data has to be filtered before comparison
- response = self.get_REST_XML_response( self.oper_url )
- self.__validate_contain_meter( response, self.xml_input_DOM, False )
-
+ response = self.get_REST_XML_response(self.oper_url)
+ self.__validate_contain_meter(response, self.xml_input_DOM, False)
# sal-meter services
- def test_operations_POST( self ):
- self.log.info( "--- Meter operations sal-service test ---" )
+ def test_operations_POST(self):
+ self.log.info("--- Meter operations sal-service test ---")
# -------------- CREATE -------------------
- self.log.info( self._paint_msg_yellow( " CREATE Meter by add-sal-service" ) )
+ self.log.info(self._paint_msg_yellow(" CREATE Meter by add-sal-service"))
# send request via RESTCONF
- self.post_REST_XML_request( self.oper_url_add, self.oper_input_stream )
+ self.post_REST_XML_request(self.oper_url_add, self.oper_input_stream)
# TODO : check no empty transaction_id from post add_service
# check request content against restconf's config datastore
# operation service don't change anything in a Config. Data Store
# so we expect 404 response code (same as a check after delete
- self.get_REST_XML_deleted_response( self.conf_url )
+ self.get_REST_XML_deleted_response(self.conf_url)
# check request content against restconf's operational datastore
# operational Data Store has to present new meter
- response = self.get_REST_XML_response( self.oper_url )
- self.__validate_contain_meter( response, self.xml_input_DOM )
+ response = self.get_REST_XML_response(self.oper_url)
+ self.__validate_contain_meter(response, self.xml_input_DOM)
# -------------- UPDATE -------------------
- self.log.info( self._paint_msg_yellow( " UPDATE Meter by update-sal-service" ) )
- xml_updated_stream = self.__update_meter_input();
- xml_updated_DOM = md.parseString( xml_updated_stream )
+ self.log.info(self._paint_msg_yellow(" UPDATE Meter by update-sal-service"))
+ xml_updated_stream = self.__update_meter_input()
+ xml_updated_DOM = md.parseString(xml_updated_stream)
data_from_updated_stream = ''
- for node in xml_updated_DOM.documentElement.childNodes :
- data_from_updated_stream += node.toxml( encoding = 'utf-8' )
+ for node in xml_updated_DOM.documentElement.childNodes:
+ data_from_updated_stream += node.toxml(encoding='utf-8')
# The xml body without data - data come from file (all meters's subtags)
oper_update_stream = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' \
- '<input xmlns="urn:opendaylight:meter:service">\n' \
- '<original-meter>\n' \
- '%s' \
- '</original-meter>\n' \
- '<updated-meter>\n'\
- '%s'\
- '</updated-meter>\n'\
- '<node xmlns:inv="urn:opendaylight:inventory">/inv:nodes/inv:node[inv:id="openflow:1"]</node>\n' \
- '</input>' % ( self.data_from_file_input, data_from_updated_stream )
-
- self.post_REST_XML_request( self.oper_url_upd, oper_update_stream )
+ '<input xmlns="urn:opendaylight:meter:service">\n' \
+ ' <original-meter>\n' \
+ ' %s' \
+ ' </original-meter>\n' \
+ ' <updated-meter>\n' \
+ ' %s' \
+ ' </updated-meter>\n' \
+ ' <node xmlns:inv="urn:opendaylight:inventory">' \
+ '/inv:nodes/inv:node[inv:id="openflow:1"]</node>\n' \
+ '</input>' % (self.data_from_file_input, data_from_updated_stream)
+
+ self.post_REST_XML_request(self.oper_url_upd, oper_update_stream)
# TODO : check no empty transaction_id from post add_service
# check request content against restconf's config datastore
# operation service don't change anything in a Config. Data Store
# so we expect 404 response code (same as a check after delete
- self.get_REST_XML_deleted_response( self.conf_url )
+ self.get_REST_XML_deleted_response(self.conf_url)
# check request content against restconf's operational datastore
# operational Data Store has to present updated meter
- response = self.get_REST_XML_response( self.oper_url )
- self.__validate_contain_meter( response, xml_updated_DOM )
+ response = self.get_REST_XML_response(self.oper_url)
+ self.__validate_contain_meter(response, xml_updated_DOM)
# -------------- DELETE -------------------
- self.log.info( self._paint_msg_yellow( " DELETE Meter by remove-sal-service" ) )
+ self.log.info(self._paint_msg_yellow(" DELETE Meter by remove-sal-service"))
# Delte data from config DataStore
- response = self.post_REST_XML_request( self.oper_url_del, self.oper_input_stream )
+ response = self.post_REST_XML_request(self.oper_url_del, self.oper_input_stream)
# Data never been added, so we expect the 404 response code
- response = self.get_REST_XML_deleted_response( self.conf_url )
+ response = self.get_REST_XML_deleted_response(self.conf_url)
# Meter operational data has a specific content
# and the comparable data has to be filtered before comparison
- response = self.get_REST_XML_response( self.oper_url )
- self.__validate_contain_meter( response, self.xml_input_DOM, False )
+ response = self.get_REST_XML_response(self.oper_url)
+ self.__validate_contain_meter(response, self.xml_input_DOM, False)
# --------------- HELP METHODS ---------------
+ def __validate_contain_meter(self, oper_resp, orig_DOM, exp_contain=True):
+ xml_resp_stream = (oper_resp.text).encode('utf-8', 'ignore')
+ xml_resp_DOM = md.parseString(xml_resp_stream)
+ nodeListOperMeters = xml_resp_DOM.getElementsByTagName('meter-config-stats')
+ if nodeListOperMeters.length > 1:
+ raise AssertionError('\n !!! Operational Data Store has more \'meter-config-stats\' tags as one \n')
- def __validate_contain_meter( self, oper_resp, orig_DOM, exp_contain = True ):
- xml_resp_stream = ( oper_resp.text ).encode( 'utf-8', 'ignore' )
- xml_resp_DOM = md.parseString( xml_resp_stream )
- nodeListOperMeters = xml_resp_DOM.getElementsByTagName( 'meter-config-stats' )
- if ( nodeListOperMeters.length > 1 ) :
- raise AssertionError( '\n !!! Operational Data Store has more \'meter-config-stats\' tags as one \n' )
-
- origDict = XMLtoDictParserTools.parseDOM_ToDict( orig_DOM._get_documentElement(),
- ignoreList = IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON )
- origDict['meter-config-stats'] = origDict.pop( 'meter' )
+ origDict = XMLtoDictParserTools.parseDOM_ToDict(
+ orig_DOM._get_documentElement(), ignoreList=IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON)
+ origDict['meter-config-stats'] = origDict.pop('meter')
nodeDict = {}
- for node in nodeListOperMeters :
- nodeDict = XMLtoDictParserTools.parseDOM_ToDict( node,
- ignoreList = IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON )
+ for node in nodeListOperMeters:
+ nodeDict = XMLtoDictParserTools.parseDOM_ToDict(
+ node, ignoreList=IGNORED_TAGS_FOR_OPERATIONAL_COMPARISON)
- if exp_contain :
- if nodeDict != origDict :
+ if exp_contain:
+ if nodeDict != origDict:
err_msg = '\n !!! Loaded operation statistics doesn\'t contain expected meter \n' \
' expected: %s\n found: %s\n differences: %s\n' \
- '' % ( origDict, nodeDict, XMLtoDictParserTools.getDifferenceDict( origDict, nodeDict ) )
- self.log.error( self._paint_msg_red( err_msg ) )
- raise AssertionError( err_msg )
- else :
- if nodeDict == origDict :
+ '' % (origDict, nodeDict, XMLtoDictParserTools.getDifferenceDict(origDict, nodeDict))
+ self.log.error(self._paint_msg_red(err_msg))
+ raise AssertionError(err_msg)
+ else:
+ if nodeDict == origDict:
err_msg = '\n !!! Loaded operation statistics contains expected meter \n' \
- ' found: %s\n ' % ( nodeDict )
- self.log.error( self._paint_msg_red( err_msg ) )
- raise AssertionError( err_msg )
-
+ ' found: %s\n ' % (nodeDict)
+ self.log.error(self._paint_msg_red(err_msg))
+ raise AssertionError(err_msg)
- def __update_meter_input( self ):
+ def __update_meter_input(self):
# action only for yet
- xml_dom_input = md.parseString( self.xml_input_stream )
- for tag_name in METER_TAGS_FOR_UPDATE :
- tag_list = xml_dom_input.getElementsByTagName( tag_name )
- if tag_list is not None and len( tag_list ) > 0 :
+ xml_dom_input = md.parseString(self.xml_input_stream)
+ for tag_name in METER_TAGS_FOR_UPDATE:
+ tag_list = xml_dom_input.getElementsByTagName(tag_name)
+ if tag_list is not None and len(tag_list) > 0:
tag_elm = tag_list[0]
- for child in tag_elm.childNodes :
- if child.nodeType == Element.TEXT_NODE :
- nodeValue = ( child.nodeValue ).encode( 'utf-8', 'ignore' )
- if ( len( nodeValue.strip( ' \t\n\r' ) ) ) > 0 :
- newValue = self.returnReverseInputTest( nodeValue )
- newTagEl = child.ownerDocument.createTextNode( newValue )
- self.log.info( self._paint_msg_cyan( 'Meter change for %s from %s to %s' % ( tag_name, nodeValue, newValue ) ) )
- child.parentNode.replaceChild( newTagEl, child )
-
- return xml_dom_input.toxml( encoding = 'utf-8' )
+ for child in tag_elm.childNodes:
+ if child.nodeType == Element.TEXT_NODE:
+ nodeValue = (child.nodeValue).encode('utf-8', 'ignore')
+ if len(nodeValue.strip(' \t\n\r')) > 0:
+ newValue = self.returnReverseInputTest(nodeValue)
+ newTagEl = child.ownerDocument.createTextNode(newValue)
+ self.log.info(self._paint_msg_cyan(
+ 'Meter change for %s from %s to %s' % (tag_name, nodeValue, newValue)))
+ child.parentNode.replaceChild(newTagEl, child)
+
+ return xml_dom_input.toxml(encoding='utf-8')
@author: vdemcak
'''
+from exceptions import StandardError
import logging
import os
import re
@staticmethod
def buildXmlDocDictionaryForComarableElements(element, flow_dict, p_elm_name=None, kwd=None, akwd=None, mkwd=None):
act_key_dict = kwd if (kwd > None) else akwd if (akwd > None) else mkwd if (mkwd > None) else None
- if element > None :
+ if element > None:
elm_alias = element.tag if (act_key_dict.get(element.tag, None) > None) else None
if ((element.getchildren() > None) & (len(element.getchildren()) > 0)):
- for child in element.getchildren() :
- if (element.tag == 'match') :
+ for child in element.getchildren():
+ if (element.tag == 'match'):
Loader.buildXmlDocDictionaryForComarableElements(child, flow_dict, mkwd=mkwd)
- elif (element.tag == 'actions') :
+ elif (element.tag == 'actions'):
Loader.buildXmlDocDictionaryForComarableElements(child, flow_dict, akwd=akwd)
- else :
- Loader.buildXmlDocDictionaryForComarableElements(child, flow_dict, elm_alias, kwd, akwd, mkwd);
- else :
- if element.text > None :
- text = re.sub( '[\s]+','', element.text, count=1)
+ else:
+ Loader.buildXmlDocDictionaryForComarableElements(child, flow_dict, elm_alias, kwd, akwd, mkwd)
+ else:
+ if element.text > None:
+ text = re.sub('[\s]+', '', element.text, count=1)
a_key = p_elm_name if (p_elm_name > None) else element.tag
- flow_dict[a_key] = text;
+ flow_dict[a_key] = text
return
type_int = 1
type_ipv4 = 4
type_ipv6 = 5
+
class Field():
"""
fields to check, arguments:
class XMLValidator():
log = logging.getLogger('XMLValidator')
- log.propagate=False
+ log.propagate = False
channel = logging.StreamHandler()
log.addHandler(channel)
def create_dictionaries(self, file_name):
self.test_name = file_name
-
+
formatter = logging.Formatter('TEST {0}: %(levelname)s: %(message)s'.format(self.test_name))
XMLValidator.channel.setFormatter(formatter)
self.flow_dict = dict()
treeXml1, self.xml_string = Loader.loadXml(file_name)
- Loader.buildXmlDocDictionaryForComarableElements(treeXml1, self.flow_dict, kwd=self.kwd, akwd=self.akwd, mkwd=self.mkwd)
+ Loader.buildXmlDocDictionaryForComarableElements(
+ treeXml1, self.flow_dict, kwd=self.kwd, akwd=self.akwd, mkwd=self.mkwd)
XMLValidator.log.debug('loaded dict from xml: {0}'.format(self.flow_dict))
-
def fill_fields(self):
Matchers.fill_validator(self)
max_range = (2**16) - 1
for n in numbers:
- #if n == '' then the number is 0000 which is always smaller than max_range
+ # if n == '' then the number is 0000 which is always smaller than max_range
if n != '' and int(n, 16) > max_range:
raise StandardError('number: {0} in ipv6 address: {1} larger than: {2}'.format(n, a, max_range))
ethernet_regexp = re.compile("^[0-9,A-F,a-f]{2}(:[0-9,A-F,a-f]{2}){5}$")
try:
- if value_type == type_boolean and value in ['true', 'false']: #boolean values
+ if value_type == type_boolean and value in ['true', 'false']: # boolean values
self.boolean_check(value, bits)
- elif value_type == type_ethernet and ethernet_regexp.match(value): #ethernet address
+ elif value_type == type_ethernet and ethernet_regexp.match(value): # ethernet address
self.ethernet_check(value)
- elif value_type == type_ipv4 and ipv4_regexp.match(value): #IPV4 address
+ elif value_type == type_ipv4 and ipv4_regexp.match(value): # IPV4 address
self.ipv4_check(value)
- elif value_type == type_ipv6 and ipv6_regexp.match(value): #IPV6 address
+ elif value_type == type_ipv6 and ipv6_regexp.match(value): # IPV6 address
self.ipv6_check(value)
- elif value_type == type_int: #integer values
+ elif value_type == type_int: # integer values
self.integer_check(value, bits, convert_from)
else:
raise StandardError
XMLValidator.log.error('problem checking size for value: {0}, reason: {1}'.format(value, str(e)))
self.xml_ok = False
-
def has_prerequisite(self, key, values, convert_from, flow_dict):
XMLValidator.log.debug('checking prerequisite: {0} - {1}'.format(key, values))
try:
flow_value_raw = flow_dict[key]
- #if prerequisites values are [None] we don't care about actual value
+ # if prerequisites values are [None] we don't care about actual value
if values != [None]:
flow_value = int(flow_value_raw, convert_from)
if flow_value not in values:
raise StandardError()
- XMLValidator.log.info('prerequisite {0}: {1} to value {2} validated successfully'.format(key, values, flow_value_raw))
+ XMLValidator.log.info('prerequisite {0}: {1} to value {2} validated successfully'.format(
+ key, values, flow_value_raw))
except KeyError:
- XMLValidator.log.error('can\'t find element: {0} in xml {1} or in keywords {2}'.format(key, self.xml_string, self.mkwd.keys()))
+ XMLValidator.log.error('can\'t find element: {0} in xml {1} or in keywords {2}'.format(
+ key, self.xml_string, self.mkwd.keys()))
self.xml_ok = False
except ValueError or TypeError:
# flow_value_raw is string that cannot be converted to decimal or hex number or None
if flow_value_raw not in values:
- XMLValidator.log.error('can\'t find element: {0} with value value: {1} '
- 'in expected values {2}'.format(key, flow_value_raw, values))
+ XMLValidator.log.error(
+ 'can\'t find element: {0} with value value: {1} '
+ 'in expected values {2}'.format(key, flow_value_raw, values))
self.xml_ok = False
else:
- XMLValidator.log.info('prerequisite {0}: {1} to value {2} validated successfully'.format(key, values, flow_value_raw))
+ XMLValidator.log.info('prerequisite {0}: {1} to value {2} validated successfully'.format(
+ key, values, flow_value_raw))
except StandardError:
- XMLValidator.log.error('can\'t find element: {0} with value value: {1} '
- 'in expected values {2}'.format(key, flow_value, values))
+ XMLValidator.log.error(
+ 'can\'t find element: {0} with value value: {1} '
+ 'in expected values {2}'.format(key, flow_value, values))
self.xml_ok = False
def check_all_prerequisites(self, prerequisites_dict, convert_from, flow_dict):
return self.xml_ok
+
class Matchers():
IN_PORT = Field('in-port', 32)
TUNNEL_ID = Field('tunnel-id', 64)
IPV6_EXTHDR = Field('ipv6-exthdr', 9, {'ethernet-type': [34525]})
-
@staticmethod
def fill_validator(validator):
"""
validator.add_field(Matchers.ETH_DST)
validator.add_field(Matchers.ETH_SRC)
validator.add_field(Matchers.ETH_TYPE)
- #validator.add_field(Matchers.VLAN_VID) - incorrenct XML parsing, if vlan-id-present is present its overriden by it, need to fix loader
+ # incorrenct XML parsing, if vlan-id-present is present its overriden by it, need to fix loader
+ # validator.add_field(Matchers.VLAN_VID)
validator.add_field(Matchers.VLAN_PCP)
validator.add_field(Matchers.IP_DSCP)
validator.add_field(Matchers.IP_ENC)
with open(os.path.abspath(__file__ + '/../../../keywords.csv')) as f:
keywords = dict(line.strip().split(';') for line in f if not line.startswith('#'))
- #print keywords
+ # print keywords
match_keywords = None
with open(os.path.abspath(__file__ + '/../../../match-keywords.csv')) as f:
match_keywords = dict(line.strip().split(';') for line in f if not line.startswith('#'))
- #print match_keywords
+ # print match_keywords
action_keywords = None
with open(os.path.abspath(__file__ + '/../../../action-keywords.csv')) as f:
paths_to_xml = list()
for i in range(1, 50):
- #paths_to_xml = ['xmls/f5.xml', 'xmls/f14.xml', 'xmls/f23.xml', 'xmls/f25.xml']
+ # paths_to_xml = ['xmls/f5.xml', 'xmls/f14.xml', 'xmls/f23.xml', 'xmls/f25.xml']
paths_to_xml.append('xmls/f%d.xml' % i)
validator = XMLValidator(keywords, action_keywords, match_keywords, logging.ERROR)
for path in paths_to_xml:
validator.create_dictionaries(path)
validator.validate()
-
--- /dev/null
+[tox]
+envlist = pep8
+skipsdist = true
+
+[testenv:pep8]
+deps = flake8
+commands = flake8
+
+[flake8]
+max-line-length = 120
+
+