diff --git a/apps/test/pom.xml b/apps/test/pom.xml index f3b717ee37..27661713d5 100644 --- a/apps/test/pom.xml +++ b/apps/test/pom.xml @@ -36,6 +36,7 @@ intent-perf messaging-perf demo + samples distributed-primitives diff --git a/apps/test/samples/pom.xml b/apps/test/samples/pom.xml new file mode 100644 index 0000000000..54467325e1 --- /dev/null +++ b/apps/test/samples/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + + org.onosproject + onos-apps-test + 1.2.0-SNAPSHOT + ../pom.xml + + + onos-app-samples + bundle + + Flow throughput test application + + + org.onosproject.flowrule + + + + + org.osgi + org.osgi.compendium + + + org.apache.karaf.shell + org.apache.karaf.shell.console + + + + org.osgi + org.osgi.core + + + + + + 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 0000000000..ebe8391793 --- /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 0000000000..ccfc06794d --- /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 0000000000..213dbe99a8 --- /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 0000000000..6836a9502e --- /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 0000000000..743d863c9a --- /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 0000000000..806a91fa41 --- /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 0000000000..ec1bc01ae5 --- /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 0000000000..d8cfd99186 --- /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 f123df6274..0be9bd4d7b 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.ObjectMapper; 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 class FlowsListCommand extends AbstractShellCommand { 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 @@ public class FlowsListCommand extends AbstractShellCommand { 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()); }