Refactored cross connect helpers to optical drivers package.

Change-Id: Iae23025cf0b33c51123911f3ff1249cabc812be2
diff --git a/drivers/lumentum/BUCK b/drivers/lumentum/BUCK
index 02ea7ea..03ae2a9 100644
--- a/drivers/lumentum/BUCK
+++ b/drivers/lumentum/BUCK
@@ -7,6 +7,7 @@
     '//protocols/tl1/ctl:onos-protocols-tl1-ctl',
     '//incubator/api:onos-incubator-api',
     '//apps/optical-model:onos-apps-optical-model',
+    '//drivers/optical:onos-drivers-optical',
 ]
 
 TEST_DEPS = [
diff --git a/drivers/lumentum/pom.xml b/drivers/lumentum/pom.xml
index 79bf59e..e7a17c7 100644
--- a/drivers/lumentum/pom.xml
+++ b/drivers/lumentum/pom.xml
@@ -49,7 +49,6 @@
             <artifactId>onos-optical-model</artifactId>
             <version>${project.version}</version>
         </dependency>
-
         <dependency>
             <groupId>org.apache.servicemix.bundles</groupId>
             <artifactId>org.apache.servicemix.bundles.snmp4j</artifactId>
@@ -70,5 +69,10 @@
             <artifactId>onos-tl1-ctl</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-drivers-optical</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 </project>
diff --git a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumSdnRoadmFlowRuleProgrammable.java b/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumSdnRoadmFlowRuleProgrammable.java
index 7dde491..840fc99 100644
--- a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumSdnRoadmFlowRuleProgrammable.java
+++ b/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/LumentumSdnRoadmFlowRuleProgrammable.java
@@ -17,6 +17,8 @@
 
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.tuple.Pair;
+import org.onosproject.driver.optical.flowrule.CrossConnectCache;
+import org.onosproject.driver.optical.flowrule.CrossConnectFlowRule;
 import org.onosproject.net.ChannelSpacing;
 import org.onosproject.net.GridType;
 import org.onosproject.net.OchSignal;
diff --git a/drivers/optical/pom.xml b/drivers/optical/pom.xml
index b136ea9..c5bcf00 100644
--- a/drivers/optical/pom.xml
+++ b/drivers/optical/pom.xml
@@ -59,6 +59,7 @@
             <groupId>org.onosproject</groupId>
             <artifactId>openflowj</artifactId>
         </dependency>
+
         <dependency>
             <groupId>org.onosproject</groupId>
             <artifactId>onos-of-api</artifactId>
diff --git a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnect.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnect.java
similarity index 91%
rename from drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnect.java
rename to drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnect.java
index cd397ba..b1131ac 100644
--- a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnect.java
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnect.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-present Open Networking Laboratory
+ * 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.
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.drivers.lumentum;
+package org.onosproject.driver.optical.flowrule;
 
 import org.onosproject.net.OchSignal;
 import org.onosproject.net.PortNumber;
diff --git a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnectCache.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnectCache.java
similarity index 90%
rename from drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnectCache.java
rename to drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnectCache.java
index ca2aa87..ff16376 100644
--- a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnectCache.java
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnectCache.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-present Open Networking Laboratory
+ * 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.
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.drivers.lumentum;
+package org.onosproject.driver.optical.flowrule;
 
 import org.apache.commons.lang3.tuple.Pair;
 import org.onosproject.net.flow.FlowId;
@@ -21,7 +21,7 @@
 /**
  * Simple interface to cache flow ID and priority of cross connect flows.
  */
-interface CrossConnectCache {
+public interface CrossConnectCache {
     /**
      * Returns the flow ID and priority corresponding to the flow hash.
      *
diff --git a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnectFlowRule.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnectFlowRule.java
similarity index 96%
rename from drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnectFlowRule.java
rename to drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnectFlowRule.java
index 56cceef..7b0579f 100644
--- a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/CrossConnectFlowRule.java
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/CrossConnectFlowRule.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-present Open Networking Laboratory
+ * 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.
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.drivers.lumentum;
+package org.onosproject.driver.optical.flowrule;
 
 import org.onosproject.net.OchSignal;
 import org.onosproject.net.PortNumber;
diff --git a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/DefaultCrossConnectCache.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/DefaultCrossConnectCache.java
similarity index 94%
rename from drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/DefaultCrossConnectCache.java
rename to drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/DefaultCrossConnectCache.java
index 032ddbc..1a73698 100644
--- a/drivers/lumentum/src/main/java/org/onosproject/drivers/lumentum/DefaultCrossConnectCache.java
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/DefaultCrossConnectCache.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016-present Open Networking Laboratory
+ * 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.
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.drivers.lumentum;
+package org.onosproject.driver.optical.flowrule;
 
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.felix.scr.annotations.Component;
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/package-info.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/package-info.java
new file mode 100644
index 0000000..6e3e8e0
--- /dev/null
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/flowrule/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Implementations of the {@link org.onosproject.net.flow.FlowRuleProgrammable} behaviour for optical devices.
+ */
+package org.onosproject.driver.optical.flowrule;
\ No newline at end of file
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/LincOELambdaQuery.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/LincOELambdaQuery.java
index 9f7bada..d7fc40a 100644
--- a/drivers/optical/src/main/java/org/onosproject/driver/optical/query/LincOELambdaQuery.java
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/query/LincOELambdaQuery.java
@@ -47,7 +47,7 @@
      * OMS ports expose 80 fixed grid lambdas of 50GHz width,
      * centered around the ITU-T center frequency 193.1 THz.
      */
-    private static final Set<OchSignal> OMS_LAMDAS = IntStream.range(0, LAMBDA_COUNT)
+    private static final Set<OchSignal> OMS_LAMBDAS = IntStream.range(0, LAMBDA_COUNT)
             .mapToObj(x -> new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, x - (LAMBDA_COUNT / 2), 4))
             .collect(GuavaCollectors.toImmutableSet());
 
@@ -63,6 +63,6 @@
             return ImmutableSet.of();
         }
 
-        return OMS_LAMDAS;
+        return OMS_LAMBDAS;
     }
 }
diff --git a/drivers/optical/src/main/resources/optical-drivers.xml b/drivers/optical/src/main/resources/optical-drivers.xml
index e483945..35563e0 100644
--- a/drivers/optical/src/main/resources/optical-drivers.xml
+++ b/drivers/optical/src/main/resources/optical-drivers.xml
@@ -33,10 +33,8 @@
                    impl="org.onosproject.driver.optical.handshaker.CalientFiberSwitchHandshaker"/>
         <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
                    impl="org.onosproject.driver.optical.query.CalientLambdaQuery"/>
-
         <behaviour api="org.onosproject.net.optical.OpticalDevice"
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
-
     </driver>
 
     <driver name="eci" extends="default"
@@ -70,12 +68,10 @@
 
     <driver name="oplk_ops" extends="default"
             manufacturer="Oplink a Molex company" hwVersion="protection-switch" swVersion="of-agent-1.0">
-
         <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.OplinkSwitchHandshaker"/>
+                   impl="org.onosproject.driver.optical.handshaker.OplinkSwitchHandshaker"/>
         <behaviour api="org.onosproject.net.behaviour.protection.ProtectionConfigBehaviour"
                    impl="org.onosproject.driver.optical.protection.OplinkSwitchProtection"/>
         <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
@@ -86,10 +82,8 @@
 
     <driver name="oplk-edfa" extends="default"
             manufacturer="Oplink a Molex company" hwVersion="edfa" swVersion="of-agent-1.0">
-
         <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.OplinkEdfaHandshaker"/>
         <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
@@ -102,31 +96,23 @@
     <driver name="polatis-config" 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.net.device.DeviceDescriptionDiscovery"
                    impl="org.onosproject.driver.optical.config.PolatisDeviceDiscovery"/>
-
         <behaviour api="org.onosproject.net.flow.FlowRuleProgrammable"
-            impl="org.onosproject.driver.optical.config.ConfigFlowRuleProgrammable"/>
-
+                   impl="org.onosproject.driver.optical.config.ConfigFlowRuleProgrammable"/>
         <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
                    impl="org.onosproject.driver.optical.query.ConfigLambdaQuery"/>
-
     </driver>
 
     <driver name="optical-config" manufacturer="config" hwVersion="config" swVersion="config">
         <behaviour api="org.onosproject.net.optical.OpticalDevice"
                    impl="org.onosproject.net.optical.DefaultOpticalDevice"/>
-
         <behaviour api="org.onosproject.net.device.DeviceDescriptionDiscovery"
                    impl="org.onosproject.driver.optical.config.ConfigOpticalDeviceDiscovery"/>
-
         <behaviour api="org.onosproject.net.flow.FlowRuleProgrammable"
-            impl="org.onosproject.driver.optical.config.ConfigFlowRuleProgrammable"/>
-
+                   impl="org.onosproject.driver.optical.config.ConfigFlowRuleProgrammable"/>
         <behaviour api="org.onosproject.net.behaviour.LambdaQuery"
                    impl="org.onosproject.driver.optical.query.ConfigLambdaQuery"/>
-
     </driver>
 
 </drivers>
diff --git a/utils/misc/src/main/java/org/onlab/util/Frequency.java b/utils/misc/src/main/java/org/onlab/util/Frequency.java
index 3a60015..9fd296e 100644
--- a/utils/misc/src/main/java/org/onlab/util/Frequency.java
+++ b/utils/misc/src/main/java/org/onlab/util/Frequency.java
@@ -57,6 +57,42 @@
     }
 
     /**
+     * Return the value this instance represents as KHz.
+     *
+     * @return frequency in kHz
+     */
+    public double asKHz() {
+        return (double) frequency / KHZ;
+    }
+
+    /**
+     * Return the value this instance represents as MHz.
+     *
+     * @return frequency in MHz
+     */
+    public double asMHz() {
+        return (double) frequency / MHZ;
+    }
+
+    /**
+     * Return the value this instance represents as GHz.
+     *
+     * @return frequency in GHz
+     */
+    public double asGHz() {
+        return (double) frequency / GHZ;
+    }
+
+    /**
+     * Return the value this instance represents as THz.
+     *
+     * @return frequency in THz
+     */
+    public double asTHz() {
+        return (double) frequency / THZ;
+    }
+
+    /**
      * Returns an instance representing the specified value in Hz.
      *
      * @param value frequency in Hz