ONOS-4415 Remove OmsPort out of core.

Change-Id: Ic796c4e715789ba18f350f28e29db04dd537822f
diff --git a/core/api/src/main/java/org/onosproject/net/OmsPort.java b/core/api/src/main/java/org/onosproject/net/OmsPort.java
index 206a0c8..e1e54ca 100644
--- a/core/api/src/main/java/org/onosproject/net/OmsPort.java
+++ b/core/api/src/main/java/org/onosproject/net/OmsPort.java
@@ -28,7 +28,10 @@
  * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
  *
  * Assumes we only support fixed grid for now.
+ *
+ * @deprecated in Goldeneye (1.6.0)
  */
+@Deprecated
 public class OmsPort extends DefaultPort {
 
     private final Frequency minFrequency;     // Minimum frequency
diff --git a/core/api/src/main/java/org/onosproject/net/device/OmsPortDescription.java b/core/api/src/main/java/org/onosproject/net/device/OmsPortDescription.java
index 74c040f..4d88476 100644
--- a/core/api/src/main/java/org/onosproject/net/device/OmsPortDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/device/OmsPortDescription.java
@@ -23,7 +23,10 @@
 
 /**
  * Default implementation of immutable OMS port description.
+ *
+ * @deprecated in Goldeneye (1.6.0)
  */
+@Deprecated
 public class OmsPortDescription extends DefaultPortDescription {
 
     private final Frequency minFrequency;
@@ -39,7 +42,10 @@
      * @param maxFrequency  maximum frequency
      * @param grid          grid spacing frequency
      * @param annotations   optional key/value annotations map
+     *
+     * @deprecated in Goldeneye (1.6.0)
      */
+    @Deprecated
     public OmsPortDescription(PortNumber number, boolean isEnabled, Frequency minFrequency, Frequency maxFrequency,
                               Frequency grid, SparseAnnotations... annotations) {
         super(number, isEnabled, Port.Type.OMS, 0, annotations);
@@ -56,7 +62,10 @@
      * @param maxFrequency  maximum frequency
      * @param grid          grid spacing frequency
      * @param annotations   optional key/value annotations map
+     *
+     * @deprecated in Goldeneye (1.6.0)
      */
+    @Deprecated
     public OmsPortDescription(PortDescription base, Frequency minFrequency, Frequency maxFrequency,
                               Frequency grid, SparseAnnotations annotations) {
         super(base, annotations);
diff --git a/core/api/src/main/java/org/onosproject/net/optical/OmsPort.java b/core/api/src/main/java/org/onosproject/net/optical/OmsPort.java
new file mode 100644
index 0000000..a08ab5f
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/OmsPort.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2016-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.net.optical;
+
+import org.onlab.util.Frequency;
+import org.onosproject.net.Port;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * OMS port (Optical Multiplexing Section).
+ * Also referred to as a WDM port or W-port.
+ * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
+ *
+ * Assumes we only support fixed grid for now.
+ */
+@Beta
+public interface OmsPort extends Port {
+
+    /**
+     * Returns the total number of channels on the port.
+     *
+     * @return total number of channels
+     */
+    default short totalChannels() {
+        Frequency diff = maxFrequency().subtract(minFrequency());
+        return (short) (diff.asHz() / grid().asHz());
+    }
+
+    /**
+     * Returns the minimum frequency.
+     *
+     * @return minimum frequency
+     */
+    Frequency minFrequency();
+
+    /**
+     * Returns the maximum frequency.
+     *
+     * @return maximum frequency
+     */
+    Frequency maxFrequency();
+
+    /**
+     * Returns the grid spacing frequency.
+     *
+     * @return grid spacing frequency
+     */
+    Frequency grid();
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/optical/device/DefaultOpticalDevice.java b/core/api/src/main/java/org/onosproject/net/optical/device/DefaultOpticalDevice.java
index 5a30cf7..0b4ff68 100644
--- a/core/api/src/main/java/org/onosproject/net/optical/device/DefaultOpticalDevice.java
+++ b/core/api/src/main/java/org/onosproject/net/optical/device/DefaultOpticalDevice.java
@@ -28,8 +28,10 @@
 import org.onosproject.net.driver.AbstractBehaviour;
 import org.onosproject.net.driver.DriverData;
 import org.onosproject.net.optical.OchPort;
+import org.onosproject.net.optical.OmsPort;
 import org.onosproject.net.optical.OpticalDevice;
 import org.onosproject.net.optical.device.port.OchPortMapper;
+import org.onosproject.net.optical.device.port.OmsPortMapper;
 import org.onosproject.net.optical.device.port.PortMapper;
 import org.onosproject.net.optical.utils.ForwardingDevice;
 import org.slf4j.Logger;
@@ -60,6 +62,7 @@
     private static final Map<Class<? extends Port>, PortMapper<? extends Port>> MAPPERS
         = ImmutableMap.<Class<? extends Port>, PortMapper<? extends Port>>builder()
             .put(OchPort.class, new OchPortMapper())
+            .put(OmsPort.class, new OmsPortMapper())
             // TODO add other optical port type here
             .build();
 
diff --git a/core/api/src/main/java/org/onosproject/net/optical/device/OmsPortHelper.java b/core/api/src/main/java/org/onosproject/net/optical/device/OmsPortHelper.java
new file mode 100644
index 0000000..2c99c53
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/device/OmsPortHelper.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2016-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.net.optical.device;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Optional;
+
+import org.onlab.util.Frequency;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.SparseAnnotations;
+import org.onosproject.net.DefaultAnnotations.Builder;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.optical.OmsPort;
+import org.onosproject.net.optical.impl.DefaultOmsPort;
+import org.slf4j.Logger;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * OMS port related helpers.
+ */
+@Beta
+public final class OmsPortHelper {
+
+    private static final Logger log = getLogger(OmsPortHelper.class);
+
+    // Annotation keys
+    /**
+     * minFrequency in Hz.
+     */
+    private static final String MIN_FREQ_HZ = "minFrequency";
+    /**
+     * maxFrequency in Hz.
+     */
+    private static final String MAX_FREQ_HZ = "maxFrequency";
+    /**
+     * grid in Hz.
+     */
+    private static final String GRID_HZ = "grid";
+
+    /**
+     * Creates OMS port description based on the supplied information.
+     *
+     * @param number        port number
+     * @param isEnabled     port enabled state
+     * @param minFrequency  minimum frequency
+     * @param maxFrequency  maximum frequency
+     * @param grid          grid spacing frequency
+     * @param annotations   key/value annotations map
+     */
+    public static PortDescription omsPortDescription(PortNumber number,
+                                              boolean isEnabled,
+                                              Frequency minFrequency,
+                                              Frequency maxFrequency,
+                                              Frequency grid,
+                                              SparseAnnotations annotations) {
+
+        Builder builder = DefaultAnnotations.builder();
+        builder.putAll(annotations);
+
+        builder.set(MIN_FREQ_HZ, String.valueOf(minFrequency.asHz()));
+        builder.set(MAX_FREQ_HZ, String.valueOf(maxFrequency.asHz()));
+        builder.set(GRID_HZ, String.valueOf(grid.asHz()));
+
+        long portSpeed = 0;
+        return new DefaultPortDescription(number, isEnabled, Port.Type.OMS, portSpeed, builder.build());
+    }
+
+    /**
+     * Creates OMS port description based on the supplied information.
+     *
+     * @param number        port number
+     * @param isEnabled     port enabled state
+     * @param minFrequency  minimum frequency
+     * @param maxFrequency  maximum frequency
+     * @param grid          grid spacing frequency
+     */
+    public static PortDescription omsPortDescription(PortNumber number,
+                                              boolean isEnabled,
+                                              Frequency minFrequency,
+                                              Frequency maxFrequency,
+                                              Frequency grid) {
+        return omsPortDescription(number, isEnabled, minFrequency, maxFrequency, grid, DefaultAnnotations.EMPTY);
+    }
+
+    /**
+     * Creates OMS port description based on the supplied information.
+     *
+     * @param base          PortDescription to get basic information from
+     * @param minFrequency  minimum frequency
+     * @param maxFrequency  maximum frequency
+     * @param grid          grid spacing frequency
+     * @param annotations   key/value annotations map
+     */
+    public static PortDescription omsPortDescription(PortDescription base,
+                                              Frequency minFrequency,
+                                              Frequency maxFrequency,
+                                              Frequency grid,
+                                              SparseAnnotations annotations) {
+
+        return omsPortDescription(base.portNumber(), base.isEnabled(),
+                                  minFrequency, maxFrequency, grid,
+                                  annotations);
+    }
+
+    public static Optional<OmsPort> asOmsPort(Port port) {
+        if (port instanceof OmsPort) {
+            return Optional.of((OmsPort) port);
+        }
+
+        try {
+            Annotations an = port.annotations();
+
+            Frequency minFrequency = Frequency.ofHz(Long.parseLong(an.value(MIN_FREQ_HZ)));
+            Frequency maxFrequency = Frequency.ofHz(Long.parseLong(an.value(MAX_FREQ_HZ)));
+            Frequency grid = Frequency.ofHz(Long.parseLong(an.value(GRID_HZ)));
+
+            return Optional.of(new DefaultOmsPort(port, minFrequency, maxFrequency, grid));
+
+        } catch (NumberFormatException e) {
+
+            log.warn("{} was not well-formed OMS port.", port, e);
+            return Optional.empty();
+        }
+    }
+
+    // not meant to be instantiated
+    private OmsPortHelper() {}
+}
diff --git a/core/api/src/main/java/org/onosproject/net/optical/device/port/OmsPortMapper.java b/core/api/src/main/java/org/onosproject/net/optical/device/port/OmsPortMapper.java
new file mode 100644
index 0000000..70a8aa9
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/device/port/OmsPortMapper.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2016-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.net.optical.device.port;
+
+import java.util.Optional;
+
+import org.onosproject.net.Port;
+import org.onosproject.net.optical.OmsPort;
+import org.onosproject.net.optical.device.OmsPortHelper;
+import org.onosproject.net.optical.impl.DefaultOmsPort;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * {@link PortMapper} to handler {@link OmsPort} translation.
+ */
+@Beta
+public class OmsPortMapper extends AbstractPortMapper<OmsPort> {
+
+    @Override
+    public boolean is(Port port) {
+        return port != null &&
+               port.type() == Port.Type.OMS &&
+               super.is(port);
+    }
+
+    @Override
+    public Optional<OmsPort> as(Port port) {
+        if (port instanceof OmsPort) {
+            return Optional.of((OmsPort) port);
+        }
+        return super.as(port);
+    }
+
+    @Override
+    protected Optional<OmsPort> mapPort(Port port) {
+        if (port instanceof OmsPort) {
+            return Optional.of((OmsPort) port);
+        } else if (port instanceof org.onosproject.net.OmsPort) {
+            // TODO remove after deprecation of old OmsPort is complete
+
+            // translate to new OmsPort
+            org.onosproject.net.OmsPort old = (org.onosproject.net.OmsPort) port;
+            return Optional.of(new DefaultOmsPort(old,
+                                                  old.minFrequency(),
+                                                  old.maxFrequency(),
+                                                  old.grid()));
+        }
+
+        return OmsPortHelper.asOmsPort(port);
+    }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOmsPort.java b/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOmsPort.java
new file mode 100644
index 0000000..4c1c7e3
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOmsPort.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2016-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.net.optical.impl;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+
+import org.onlab.util.Frequency;
+import org.onosproject.net.Port;
+import org.onosproject.net.optical.OmsPort;
+import org.onosproject.net.optical.utils.ForwardingPort;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Implementation of OMS port (Optical Multiplexing Section).
+ * Also referred to as a WDM port or W-port.
+ * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
+ *
+ * Assumes we only support fixed grid for now.
+ */
+@Beta
+public class DefaultOmsPort extends ForwardingPort implements OmsPort {
+
+    private final Frequency minFrequency;     // Minimum frequency
+    private final Frequency maxFrequency;     // Maximum frequency
+    private final Frequency grid;             // Grid spacing frequency
+
+    /**
+     * Creates an OMS port.
+     *
+     * @param delegate      Port
+     * @param minFrequency  minimum frequency
+     * @param maxFrequency  maximum frequency
+     * @param grid          grid spacing frequency
+     */
+    public DefaultOmsPort(Port delegate, Frequency minFrequency, Frequency maxFrequency, Frequency grid) {
+        super(delegate);
+
+        this.minFrequency = checkNotNull(minFrequency);
+        this.maxFrequency = checkNotNull(maxFrequency);
+        this.grid = checkNotNull(grid);
+    }
+
+    @Override
+    public Type type() {
+        return Type.OMS;
+    }
+
+    @Override
+    public long portSpeed() {
+        return 0;
+    }
+
+    @Override
+    public Frequency minFrequency() {
+        return minFrequency;
+    }
+
+    @Override
+    public Frequency maxFrequency() {
+        return maxFrequency;
+    }
+
+    @Override
+    public Frequency grid() {
+        return grid;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(super.hashCode(),
+                            minFrequency(),
+                            maxFrequency(),
+                            grid());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj != null && getClass() == obj.getClass()) {
+            final DefaultOmsPort that = (DefaultOmsPort) obj;
+            return super.toEqualsBuilder(that)
+                    .append(this.minFrequency(), that.minFrequency())
+                    .append(this.maxFrequency(), that.maxFrequency())
+                    .append(this.grid(), that.grid())
+                    .isEquals();
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return super.toStringHelper()
+                .add("minFrequency", minFrequency())
+                .add("maxFrequency", maxFrequency())
+                .add("grid", grid())
+                .toString();
+    }
+
+}