【ONOS-1871】Provide CLI support on flowrule subsystem extension for QA
purposes。
Create a new test application to apply a flow rule to a third-party
random device automatically.
and modfiy FlowsListCommand to show third-party flow rule.
Change-Id: I8902b1577c91c43a7755afd4c1c40fc5ba87d54f
diff --git a/apps/test/pom.xml b/apps/test/pom.xml
index f3b717e..2766171 100644
--- a/apps/test/pom.xml
+++ b/apps/test/pom.xml
@@ -36,6 +36,7 @@
<module>intent-perf</module>
<module>messaging-perf</module>
<module>demo</module>
+ <module>samples</module>
<module>distributed-primitives</module>
</modules>
diff --git a/apps/test/samples/pom.xml b/apps/test/samples/pom.xml
new file mode 100644
index 0000000..5446732
--- /dev/null
+++ b/apps/test/samples/pom.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2015 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-apps-test</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-app-samples</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Flow throughput test application</description>
+
+ <properties>
+ <onos.app.name>org.onosproject.flowrule</onos.app.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ </dependency>
+ <!-- Required for javadoc generation -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ </dependencies>
+
+
+
+</project>
diff --git a/apps/test/samples/src/main/java/org/onosproject/flowrule/AppTestService.java b/apps/test/samples/src/main/java/org/onosproject/flowrule/AppTestService.java
new file mode 100644
index 0000000..ebe8391
--- /dev/null
+++ b/apps/test/samples/src/main/java/org/onosproject/flowrule/AppTestService.java
@@ -0,0 +1,8 @@
+package org.onosproject.flowrule;
+
+/**
+ * Applications test service.
+ */
+public interface AppTestService {
+
+}
diff --git a/apps/test/samples/src/main/java/org/onosproject/flowrule/dispatch/FlowRuleTest.java b/apps/test/samples/src/main/java/org/onosproject/flowrule/dispatch/FlowRuleTest.java
new file mode 100644
index 0000000..ccfc067
--- /dev/null
+++ b/apps/test/samples/src/main/java/org/onosproject/flowrule/dispatch/FlowRuleTest.java
@@ -0,0 +1,96 @@
+package org.onosproject.flowrule.dispatch;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.FlowRuleExtPayLoad;
+import org.onosproject.net.flow.FlowRuleService;
+import org.slf4j.Logger;
+
+/**
+ * third party flow rule test code.
+ */
+public class FlowRuleTest {
+
+ private final Logger log = getLogger(getClass());
+ protected FlowRuleService flowRuleService;
+ protected DeviceService deviceService;
+ private ApplicationId appId;
+ private FlowRule[] flowSet = new DefaultFlowRule[10];
+ private DeviceId deviceId;
+ private static final String FILE_NAME = "/src/main/resource/org/onosproject/flowrule/resource/flowrule.txt";
+
+ /**
+ * Creates a flow rule test object.
+ * @param flowRuleService service for injecting flow rules into the environment
+ * @param deviceService service for interacting with the inventory of infrastructure devices
+ * @param appId application identifier
+ */
+ public FlowRuleTest(FlowRuleService flowRuleService,
+ DeviceService deviceService, ApplicationId appId) {
+ this.flowRuleService = flowRuleService;
+ this.deviceService = deviceService;
+ this.deviceId = deviceService.getAvailableDevices().iterator().next().id();
+ this.appId = appId;
+ loadFile();
+ }
+
+ private void loadFile() {
+ String relativelyPath = System.getProperty("user.dir");
+ File flowFile = new File(relativelyPath + FILE_NAME);
+ BufferedReader br = null;
+ try {
+ FileReader in = new FileReader(flowFile);
+ br = new BufferedReader(in);
+ FlowRule rule = null;
+ int i = 0;
+ String flow = "";
+ while ((flow = br.readLine()) != null) {
+ rule = buildFlowRule(flow);
+ flowSet[i++] = rule;
+ }
+ } catch (IOException e) {
+ log.info("file does not exist.");
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ log.info("nothing");
+ }
+ }
+ }
+ }
+
+ private FlowRule buildFlowRule(String flow) {
+ FlowRuleExtPayLoad payLoad = FlowRuleExtPayLoad.flowRuleExtPayLoad(flow
+ .getBytes());
+ FlowRule flowRule = new DefaultFlowRule(deviceId, null, null, 0, appId,
+ 0, false, payLoad);
+ return flowRule;
+ }
+
+ /**
+ * Apply flow rules to specific devices.
+ */
+ public void applyFlowRules() {
+ flowRuleService.applyFlowRules(flowSet);
+ }
+
+ /**
+ * Remove flow rules from specific devices.
+ */
+ public void removeFlowRules() {
+ flowRuleService.removeFlowRules(flowSet);
+ }
+
+}
diff --git a/apps/test/samples/src/main/java/org/onosproject/flowrule/dispatch/package-info.java b/apps/test/samples/src/main/java/org/onosproject/flowrule/dispatch/package-info.java
new file mode 100644
index 0000000..213dbe9
--- /dev/null
+++ b/apps/test/samples/src/main/java/org/onosproject/flowrule/dispatch/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Provide for specific functional test script. e.g. flow rule subsystem extension.
+ * You can create a new class to test other functions.
+ */
+package org.onosproject.flowrule.dispatch;
\ No newline at end of file
diff --git a/apps/test/samples/src/main/java/org/onosproject/flowrule/impl/AppTestManager.java b/apps/test/samples/src/main/java/org/onosproject/flowrule/impl/AppTestManager.java
new file mode 100644
index 0000000..6836a95
--- /dev/null
+++ b/apps/test/samples/src/main/java/org/onosproject/flowrule/impl/AppTestManager.java
@@ -0,0 +1,51 @@
+package org.onosproject.flowrule.impl;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.flowrule.AppTestService;
+import org.onosproject.flowrule.dispatch.FlowRuleTest;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.FlowRuleService;
+import org.slf4j.Logger;
+
+/**
+ * Test for a application.
+ */
+@Component(immediate = true)
+@Service
+public class AppTestManager implements AppTestService {
+
+ private static final String APP_TEST = "org.onosproject.apptest";
+ private final Logger log = getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected FlowRuleService flowRuleService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected DeviceService deviceService;
+ private ApplicationId appId;
+ FlowRuleTest flowRule;
+
+ @Activate
+ protected void activate() {
+ log.info("APP-TEST started");
+ appId = coreService.registerApplication(APP_TEST);
+ flowRule = new FlowRuleTest(flowRuleService, deviceService, appId);
+ flowRule.applyFlowRules();
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ flowRule.removeFlowRules();
+ log.info("APP-TEST Stopped");
+ }
+}
diff --git a/apps/test/samples/src/main/java/org/onosproject/flowrule/impl/package-info.java b/apps/test/samples/src/main/java/org/onosproject/flowrule/impl/package-info.java
new file mode 100644
index 0000000..743d863
--- /dev/null
+++ b/apps/test/samples/src/main/java/org/onosproject/flowrule/impl/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Test for flow rule subsystem extension.
+ * Also used to test other functions, but it need be extended.
+ */
+package org.onosproject.flowrule.impl;
diff --git a/apps/test/samples/src/main/java/org/onosproject/flowrule/package-info.java b/apps/test/samples/src/main/java/org/onosproject/flowrule/package-info.java
new file mode 100644
index 0000000..806a91f
--- /dev/null
+++ b/apps/test/samples/src/main/java/org/onosproject/flowrule/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Test for flow rule subsystem extension.
+ * Now it has no APIs, Maybe it can add other methods in future.
+ */
+package org.onosproject.flowrule;
diff --git a/apps/test/samples/src/main/resource/org/onosproject/flowrule/resource/flowrule.txt b/apps/test/samples/src/main/resource/org/onosproject/flowrule/resource/flowrule.txt
new file mode 100644
index 0000000..ec1bc01
--- /dev/null
+++ b/apps/test/samples/src/main/resource/org/onosproject/flowrule/resource/flowrule.txt
@@ -0,0 +1 @@
+050e009000000000000000000000000000000000000000000701000000000000000000000000000000000000000000020001001080001702010180001902010200040030000000000000001000000006000000000000000000130008001300000019001080001a0101000000000000000002000000000000000000000000000100000000000000010001000003000000
\ No newline at end of file
diff --git a/apps/test/samples/src/main/resource/org/onosproject/flowrule/resource/package-info.java b/apps/test/samples/src/main/resource/org/onosproject/flowrule/resource/package-info.java
new file mode 100644
index 0000000..d8cfd99
--- /dev/null
+++ b/apps/test/samples/src/main/resource/org/onosproject/flowrule/resource/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2014-2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * applications live here.
+ */
+package org.onosproject.flowrule.resource;
\ No newline at end of file
diff --git a/cli/src/main/java/org/onosproject/cli/net/FlowsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/FlowsListCommand.java
index f123df6..0be9bd4 100644
--- a/cli/src/main/java/org/onosproject/cli/net/FlowsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/FlowsListCommand.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.cli.net;
+import static com.google.common.collect.Lists.newArrayList;
+
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -38,10 +40,8 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import static com.google.common.collect.Lists.newArrayList;
-
/**
- * Lists all currently-known hosts.
+ * Lists all currently-known flows.
*/
@Command(scope = "onos", name = "flows",
description = "Lists all currently-known flows.")
@@ -50,7 +50,7 @@
public static final String ANY = "any";
private static final String FMT =
- " id=%s, state=%s, bytes=%s, packets=%s, duration=%s, priority=%s, tableId=%s, timeout=%s, appId=%s";
+ " id=%s, state=%s, bytes=%s, packets=%s, duration=%s, priority=%s, tableId=%s appId=%s, payLoad=%s";
private static final String TFMT = " treatment=%s";
private static final String SFMT = " selector=%s";
@@ -156,7 +156,8 @@
for (FlowEntry f : flows) {
print(FMT, Long.toHexString(f.id().value()), f.state(),
f.bytes(), f.packets(), f.life(), f.priority(), f.tableId(),
- f.timeout(), coreService.getAppId(f.appId()).name());
+ coreService.getAppId(f.appId()).name(),
+ f.payLoad() == null ? null : f.payLoad().payLoad().toString());
print(SFMT, f.selector().criteria());
print(TFMT, f.treatment());
}