[ONOS-6386] Polatis OpenFlow driver

- Handling Polatis extention for ofp_port_stats_prop_type (=OFPortStatsPropVer14)
  0x7C00 (=31744 in decimal) is future work.

Change-Id: I8ad309502737d2bff46e412e80f4310ca61bf254
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/handshaker/PolatisHandshaker.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/handshaker/PolatisHandshaker.java
new file mode 100644
index 0000000..4f69551
--- /dev/null
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/handshaker/PolatisHandshaker.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2017-present 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.optical.handshaker;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.List;
+import java.util.Set;
+import org.onosproject.net.Device.Type;
+import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
+import org.onosproject.openflow.controller.PortDescPropertyType;
+import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
+import org.projectfloodlight.openflow.protocol.OFMessage;
+import org.projectfloodlight.openflow.protocol.OFPortDesc;
+import org.slf4j.Logger;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Handshaker for Polatis fiber switch.
+ *
+ */
+public class PolatisHandshaker extends AbstractOpenFlowSwitch
+    implements OpenFlowOpticalSwitch {
+
+    private static final Logger log = getLogger(PolatisHandshaker.class);
+
+    @Override
+    public Boolean supportNxRole() {
+        // Device is OF1.4 so response doesn't matter.
+        return Boolean.FALSE;
+    }
+
+    @Override
+    public void startDriverHandshake() {
+        // nothing Device specific required
+    }
+
+    @Override
+    public boolean isDriverHandshakeComplete() {
+        // nothing Device specific to do
+        return true;
+    }
+
+    @Override
+    public void processDriverHandshakeMessage(OFMessage m) {
+        // nothing Device specific to do
+    }
+
+    @Override
+    public Type deviceType() {
+        return Type.FIBER_SWITCH;
+    }
+
+    @Override
+    public List<OFPortDesc> getPortsOf(PortDescPropertyType type) {
+        return this.getPorts().stream()
+            .filter(pd -> isPortType(type, pd))
+            .collect(ImmutableList.toImmutableList());
+    }
+
+    /**
+     * Tests if OFPortDesc {@code pd} is a {@code type}.
+     *
+     * @param type to test if {@code pd} is of port type
+     * @param pd OpenFlow port description to test.
+     * @return true if {@code pd} is of port description of {@code type}
+     */
+    private static boolean isPortType(PortDescPropertyType type, OFPortDesc pd) {
+        try {
+            return pd.getProperties().stream()
+                        .anyMatch(prop -> prop.getType() == type.valueOf());
+        } catch (UnsupportedOperationException e) {
+            log.warn("Unexpected OFPortDesc {} reveived", pd, e);
+            return false;
+        }
+    }
+
+    @Override
+    public Set<PortDescPropertyType> getPortTypes() {
+        return ImmutableSet.of(PortDescPropertyType.OPTICAL);
+    }
+}
diff --git a/drivers/optical/src/main/resources/optical-drivers.xml b/drivers/optical/src/main/resources/optical-drivers.xml
index 344436e..1dd44ff 100644
--- a/drivers/optical/src/main/resources/optical-drivers.xml
+++ b/drivers/optical/src/main/resources/optical-drivers.xml
@@ -93,7 +93,18 @@
 
     </driver>
 
-    <driver name="polatis-config" manufacturer="Polatis" hwVersion="N-VST-48x48-HU1-DMHNV-805" swVersion="6.6.1.7">
+    <driver name="polatis" extends="default"
+            manufacturer="Polatis" hwVersion="N-VST-48x48-HU1-DMHNV-805" swVersion="6.6.1.7">
+        <behaviour api="org.onosproject.net.optical.OpticalDevice"
+                   impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
+        <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
+                   impl="org.onosproject.driver.optical.handshaker.PolatisHandshaker"/>
+        <!-- TODO use OF1.4 reported information when ready -->
+        <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
+                   impl="org.onosproject.driver.optical.query.ConfigLambdaQuery"/>
+    </driver>
+
+    <driver name="polatis-config" manufacturer="Polatis" hwVersion="config" swVersion=".*">
         <behaviour api="org.onosproject.net.optical.OpticalDevice"
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
         <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"