Arista Switch pipelines should filter the clear deffered action (seems like juniper pipeline)

Change-Id: I2f1bdd5a4ba614466c3722f4ed833ece739f0404
diff --git a/drivers/default/src/main/java/org/onosproject/driver/pipeline/AristaPipeliner.java b/drivers/default/src/main/java/org/onosproject/driver/pipeline/AristaPipeliner.java
new file mode 100644
index 0000000..8b1a508
--- /dev/null
+++ b/drivers/default/src/main/java/org/onosproject/driver/pipeline/AristaPipeliner.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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 org.onlab.osgi.ServiceDirectory;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Device;
+import org.onosproject.net.behaviour.PipelinerContext;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.DefaultTrafficTreatment;
+import org.onosproject.net.flow.TrafficTreatment;
+import org.onosproject.net.flowobjective.DefaultForwardingObjective;
+import org.onosproject.net.flowobjective.ForwardingObjective;
+import org.slf4j.Logger;
+
+import java.util.Optional;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Simple single table pipeline abstraction.
+ */
+public class AristaPipeliner extends DefaultSingleTablePipeline {
+
+    private final Logger log = getLogger(getClass());
+    private ServiceDirectory serviceDirectory;
+    private DeviceId deviceId;
+
+    protected DeviceService deviceSetvice;
+    @Override
+    public void init(DeviceId deviceId, PipelinerContext context) {
+        this.deviceId = deviceId;
+        this.serviceDirectory = context.directory();
+        this.deviceSetvice = serviceDirectory.get(DeviceService.class);
+    }
+
+
+    @Override
+    public void forward(ForwardingObjective forwardObjective) {
+        ForwardingObjective newFwd = forwardObjective;
+
+        Device device = deviceSetvice.getDevice(deviceId);
+        if (forwardObjective.treatment() != null && forwardObjective.treatment().clearedDeferred()) {
+            log.warn("Using 'clear actions' instruction which is not supported by {} {} {} Switch"
+                            + " removing the clear deferred from the forwarding objective",
+                    device.id(), device.manufacturer(), device.hwVersion());
+            newFwd = forwardingObjectiveWithoutCleardDef(forwardObjective).orElse(forwardObjective);
+        }
+
+        super.forward(newFwd);
+    }
+
+
+    private Optional<ForwardingObjective> forwardingObjectiveWithoutCleardDef(ForwardingObjective forwardingObjective) {
+        TrafficTreatment treatment = trafficTreatmentWithoutClearedDeffered(forwardingObjective.treatment());
+
+        DefaultForwardingObjective.Builder foBuilder = (DefaultForwardingObjective.Builder) forwardingObjective.copy();
+        foBuilder.withTreatment(treatment);
+
+        switch (forwardingObjective.op()) {
+            case ADD:
+                return Optional.of(foBuilder.add(forwardingObjective.context().orElse(null)));
+            case REMOVE:
+                return Optional.of(foBuilder.remove(forwardingObjective.context().orElse(null)));
+            default:
+                log.warn("Driver Not support other operations for forwarding objective");
+                return Optional.empty();
+        }
+
+    }
+
+
+    private TrafficTreatment trafficTreatmentWithoutClearedDeffered(TrafficTreatment treatment) {
+        return DefaultTrafficTreatment.builder(treatment)
+                .notWipeDeferred()
+                .build();
+    }
+
+}
diff --git a/drivers/default/src/main/resources/onos-drivers.xml b/drivers/default/src/main/resources/onos-drivers.xml
index f45bc23..f25d11d 100644
--- a/drivers/default/src/main/resources/onos-drivers.xml
+++ b/drivers/default/src/main/resources/onos-drivers.xml
@@ -279,5 +279,11 @@
                    impl="org.onosproject.driver.pipeline.CentecV350Pipeline"/>
     </driver>
     -->
+
+    <driver name="Arista" extends="default"
+            manufacturer="Arista.*" hwVersion="DCS.*" swVersion=".*">
+        <behaviour api="org.onosproject.net.behaviour.Pipeliner"
+                   impl="org.onosproject.driver.pipeline.AristaPipeliner"/>
+    </driver>
 </drivers>