ONOS-4417 Remove OtuPort out of core.

Change-Id: Ibc72ee617b238005585f0bcd873b9123e48ee7fc
diff --git a/core/api/src/main/java/org/onosproject/net/OtuPort.java b/core/api/src/main/java/org/onosproject/net/OtuPort.java
index 25c7295..60456cd 100644
--- a/core/api/src/main/java/org/onosproject/net/OtuPort.java
+++ b/core/api/src/main/java/org/onosproject/net/OtuPort.java
@@ -21,8 +21,10 @@
 
 /**
  * Implementation of OTU port (Optical channel Transport Unit).
+ *
+ * @deprecated in Goldeneye (1.6.0)
  */
-
+@Deprecated
 public class OtuPort extends DefaultPort {
 
     private final OtuSignalType signalType;
diff --git a/core/api/src/main/java/org/onosproject/net/device/OtuPortDescription.java b/core/api/src/main/java/org/onosproject/net/device/OtuPortDescription.java
index ac5d855..5495524 100644
--- a/core/api/src/main/java/org/onosproject/net/device/OtuPortDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/device/OtuPortDescription.java
@@ -24,7 +24,10 @@
 
 /**
  * Default implementation of immutable OTU port description.
+ *
+ * @deprecated in Goldeneye (1.6.0)
  */
+@Deprecated
 public class OtuPortDescription extends DefaultPortDescription {
 
     private final OtuSignalType signalType;
diff --git a/core/api/src/main/java/org/onosproject/net/optical/OtuPort.java b/core/api/src/main/java/org/onosproject/net/optical/OtuPort.java
new file mode 100644
index 0000000..15f284d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/OtuPort.java
@@ -0,0 +1,39 @@
+/*
+ * 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 gcd ~/Dooverning permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.optical;
+
+import org.onosproject.net.OtuSignalType;
+import org.onosproject.net.Port;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * OTU port (Optical channel Transport Unit).
+ * <p>
+ * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)" and
+ * Open Networking Foundation "Optical Transport Protocol Extensions Version 1.0".
+ */
+@Beta
+public interface OtuPort extends Port {
+
+    /**
+     * Returns OTU signal type.
+     *
+     * @return OTU signal type
+     */
+    public OtuSignalType signalType();
+
+}
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 0015cf9..d7608b9 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
@@ -31,9 +31,11 @@
 import org.onosproject.net.optical.OduCltPort;
 import org.onosproject.net.optical.OmsPort;
 import org.onosproject.net.optical.OpticalDevice;
+import org.onosproject.net.optical.OtuPort;
 import org.onosproject.net.optical.device.port.OchPortMapper;
 import org.onosproject.net.optical.device.port.OduCltPortMapper;
 import org.onosproject.net.optical.device.port.OmsPortMapper;
+import org.onosproject.net.optical.device.port.OtuPortMapper;
 import org.onosproject.net.optical.device.port.PortMapper;
 import org.onosproject.net.optical.utils.ForwardingDevice;
 import org.slf4j.Logger;
@@ -66,6 +68,7 @@
             .put(OchPort.class, new OchPortMapper())
             .put(OmsPort.class, new OmsPortMapper())
             .put(OduCltPort.class, new OduCltPortMapper())
+            .put(OtuPort.class, new OtuPortMapper())
             // TODO add other optical port type here
             .build();
 
diff --git a/core/api/src/main/java/org/onosproject/net/optical/device/OtuPortHelper.java b/core/api/src/main/java/org/onosproject/net/optical/device/OtuPortHelper.java
new file mode 100644
index 0000000..aeac4f9
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/device/OtuPortHelper.java
@@ -0,0 +1,129 @@
+/*
+ * 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.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.OtuSignalType;
+import org.onosproject.net.device.DefaultPortDescription;
+import org.onosproject.net.device.PortDescription;
+import org.onosproject.net.optical.OtuPort;
+import org.onosproject.net.optical.impl.DefaultOtuPort;
+import org.slf4j.Logger;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * OTU port related helpers.
+ */
+@Beta
+public final class OtuPortHelper {
+
+    private static final Logger log = getLogger(OtuPortHelper.class);
+
+    // Annotation keys
+    /**
+     * {@link OtuSignalType} as String.
+     */
+    private static final String SIGNAL_TYPE = "signalType";
+
+    /**
+     * Creates OTU port description based on the supplied information.
+     *
+     * @param number        port number
+     * @param isEnabled     port enabled state
+     * @param signalType    OTU client signal type
+     */
+    public static PortDescription otuPortDescription(PortNumber number,
+                                                     boolean isEnabled,
+                                                     OtuSignalType signalType) {
+        return otuPortDescription(number, isEnabled, signalType, DefaultAnnotations.EMPTY);
+    }
+
+    /**
+     * Creates OTU port description based on the supplied information.
+     *
+     * @param number        port number
+     * @param isEnabled     port enabled state
+     * @param signalType    OTU client signal type
+     * @param annotations   key/value annotations map
+     */
+    public static PortDescription otuPortDescription(PortNumber number,
+                                                     boolean isEnabled,
+                                                     OtuSignalType signalType,
+                                                     SparseAnnotations annotations) {
+        Builder builder = DefaultAnnotations.builder();
+        builder.putAll(annotations);
+
+        builder.set(SIGNAL_TYPE, signalType.toString());
+
+        long portSpeed = 0; // TODO specify appropriate value?
+        return new DefaultPortDescription(number,
+                                          isEnabled,
+                                          Port.Type.OTU,
+                                          portSpeed,
+                                          builder.build());
+    }
+
+    /**
+     * Creates OTU port description based on the supplied information.
+     *
+     * @param base          PortDescription to get basic information from
+     * @param signalType    OTU client signal type
+     * @param annotations   key/value annotations map
+     */
+    public static PortDescription otuPortDescription(PortDescription base,
+                                                     OtuSignalType signalType,
+                                                     SparseAnnotations annotations) {
+        return otuPortDescription(base.portNumber(), base.isEnabled(), signalType, annotations);
+    }
+
+    public static Optional<OtuPort> asOtuPort(Port port) {
+        if (port instanceof OtuPort) {
+            return Optional.of((OtuPort) port);
+        }
+
+        try {
+            Annotations an = port.annotations();
+
+            OtuSignalType signalType = Enum.valueOf(OtuSignalType.class,
+                                                    an.value(SIGNAL_TYPE));
+
+
+            // Note: OTU specific annotations is not filtered-out here.
+            //       DefaultOtuPort should filter them, if necessary.
+            return Optional.of(new DefaultOtuPort(port, signalType));
+
+        } catch (NullPointerException | IllegalArgumentException e) {
+
+            log.warn("{} was not well-formed Otu port.", port, e);
+            return Optional.empty();
+        }
+    }
+
+
+    // not meant to be instantiated
+    private OtuPortHelper() {}
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/optical/device/port/OtuPortMapper.java b/core/api/src/main/java/org/onosproject/net/optical/device/port/OtuPortMapper.java
new file mode 100644
index 0000000..c70033a
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/device/port/OtuPortMapper.java
@@ -0,0 +1,65 @@
+/*
+ * 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.OtuPort;
+import org.onosproject.net.optical.device.OtuPortHelper;
+import org.onosproject.net.optical.impl.DefaultOtuPort;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * {@link PortMapper} to handler {@link OtuPort} translation.
+ */
+@Beta
+public class OtuPortMapper extends AbstractPortMapper<OtuPort> {
+
+    @Override
+    public boolean is(Port port) {
+        return port != null &&
+               port.type() == Port.Type.OTU &&
+               super.is(port);
+    }
+
+    @Override
+    public Optional<OtuPort> as(Port port) {
+        if (port instanceof OtuPort) {
+            return Optional.of((OtuPort) port);
+        }
+        return super.as(port);
+    }
+
+    @Override
+    protected Optional<OtuPort> mapPort(Port port) {
+        if (port instanceof OtuPort) {
+            return Optional.of((OtuPort) port);
+        } else if (port instanceof org.onosproject.net.OtuPort) {
+            // TODO remove after deprecation of old OtuPort is complete
+
+            // translate to new OtuPort
+            org.onosproject.net.OtuPort old = (org.onosproject.net.OtuPort) port;
+            return Optional.of(new DefaultOtuPort(old,
+                                                  old.signalType()));
+        }
+
+        return OtuPortHelper.asOtuPort(port);
+    }
+
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOtuPort.java b/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOtuPort.java
new file mode 100644
index 0000000..4a5a79b
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOtuPort.java
@@ -0,0 +1,92 @@
+/*
+ * 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.onosproject.net.OtuSignalType;
+import org.onosproject.net.Port;
+import org.onosproject.net.optical.OtuPort;
+import org.onosproject.net.optical.utils.ForwardingPort;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Implementation of OTU port (Optical channel Transport Unit).
+ *
+ */
+@Beta
+public class DefaultOtuPort extends ForwardingPort implements OtuPort {
+
+    private final OtuSignalType signalType;
+
+    /**
+     * Creates an ODU client port.
+     *
+     * @param delegate      Port
+     * @param signalType    OTU signal type
+     */
+    public DefaultOtuPort(Port delegate, OtuSignalType signalType) {
+        super(delegate);
+        this.signalType = checkNotNull(signalType);
+    }
+
+    @Override
+    public Type type() {
+        return Type.OTU;
+    }
+
+//    @Override
+//    public long portSpeed() {
+//        return signalType().bitRate();
+//    }
+
+    @Override
+    public OtuSignalType signalType() {
+        return signalType;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(super.hashCode(),
+                            signalType());
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+
+        if (obj != null && getClass() == obj.getClass()) {
+            final DefaultOtuPort that = (DefaultOtuPort) obj;
+            return super.toEqualsBuilder(that)
+                    .append(this.signalType(), that.signalType())
+                    .isEquals();
+        }
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        return super.toStringHelper()
+                .add("signalType", signalType())
+                .toString();
+    }
+
+}