【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/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