Initial sketch and implementaion of Objectives.
These objective will be used to provide a layer of abstraction
that isolates applications for device pipeline details.
initial objective support
Change-Id: I019302822421f0fe1f508f2f7527d91578e30116
initial implemetation of a simple pipeline behaviour
Change-Id: Id0d9167896c717d05cda90e1524fc24c76e9fc9b
initial implementation of objectives
Change-Id: I768fa2020308d5feb95eaaff355aa511b323beca
diff --git a/drivers/pom.xml b/drivers/pom.xml
new file mode 100644
index 0000000..a4db521
--- /dev/null
+++ b/drivers/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2014 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</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-drivers</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS Default Device Drivers</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
diff --git a/drivers/src/main/java/org/onosproject/driver/pipeline/DefaultSingleTablePipeline.java b/drivers/src/main/java/org/onosproject/driver/pipeline/DefaultSingleTablePipeline.java
new file mode 100644
index 0000000..8516697
--- /dev/null
+++ b/drivers/src/main/java/org/onosproject/driver/pipeline/DefaultSingleTablePipeline.java
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+package org.onosproject.driver.pipeline;
+
+import com.google.common.util.concurrent.SettableFuture;
+import org.onlab.osgi.ServiceDirectory;
+import org.onosproject.core.DefaultGroupId;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.behaviour.Pipeliner;
+import org.onosproject.net.flow.DefaultFlowRule;
+import org.onosproject.net.flow.FlowRule;
+import org.onosproject.net.flow.FlowRuleOperations;
+import org.onosproject.net.flow.FlowRuleOperationsContext;
+import org.onosproject.net.flow.FlowRuleService;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flowobjective.FilteringObjective;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.concurrent.Future;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Simple single table pipeline abstraction.
+ */
+public class DefaultSingleTablePipeline implements Pipeliner {
+
+ private final Logger log = getLogger(getClass());
+
+ private ServiceDirectory serviceDirectory;
+ private FlowRuleService flowRuleService;
+ private DeviceId deviceId;
+
+ @Override
+ public void init(DeviceId deviceId, ServiceDirectory serviceDirectory) {
+ this.serviceDirectory = serviceDirectory;
+ this.deviceId = deviceId;
+
+ flowRuleService = serviceDirectory.get(FlowRuleService.class);
+
+ }
+
+ @Override
+ public Future<Boolean> filter(Collection<FilteringObjective> filters) {
+ throw new UnsupportedOperationException("Single table does not filter.");
+ }
+
+ @Override
+ public Future<Boolean> forward(Collection<ForwardingObjective> forwardings) {
+ FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder();
+ forwardings.forEach(fwd -> {
+ if (fwd.flag() != ForwardingObjective.Flag.VERSATILE) {
+ throw new UnsupportedOperationException(
+ "Only VERSATILE is supported.");
+ }
+
+ TrafficSelector selector = fwd.selector();
+
+ FlowRule rule = new DefaultFlowRule(deviceId, selector,
+ fwd.treatment(),
+ fwd.priority(), fwd.appId(),
+ new DefaultGroupId(fwd.id()),
+ fwd.timeout(), fwd.permanent());
+
+ switch (fwd.op()) {
+
+ case ADD:
+ flowBuilder.add(rule);
+ break;
+ case REMOVE:
+ flowBuilder.remove(rule);
+ break;
+ default:
+ log.warn("Unknown operation {}", fwd.op());
+ }
+
+ });
+
+ SettableFuture<Boolean> future = SettableFuture.create();
+
+ flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() {
+ @Override
+ public void onSuccess(FlowRuleOperations ops) {
+ future.set(true);
+ }
+
+ @Override
+ public void onError(FlowRuleOperations ops) {
+ future.set(false);
+ }
+ }));
+ return future;
+ }
+}