ONOS-4416 Remove OduCltPort out of core.
Change-Id: I04324a72e48af84afdbfa32b84c8e57f39411000
diff --git a/core/api/src/main/java/org/onosproject/net/OduCltPort.java b/core/api/src/main/java/org/onosproject/net/OduCltPort.java
index 0f3a729..4af663c 100644
--- a/core/api/src/main/java/org/onosproject/net/OduCltPort.java
+++ b/core/api/src/main/java/org/onosproject/net/OduCltPort.java
@@ -24,8 +24,10 @@
* Implementation of ODU client port (Optical channel Data Unit).
* Also referred to as a T-port or wide band port.
* See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
+ *
+ * @deprecated in Goldeneye (1.6.0)
*/
-
+@Deprecated
public class OduCltPort extends DefaultPort {
private final CltSignalType signalType;
diff --git a/core/api/src/main/java/org/onosproject/net/device/OduCltPortDescription.java b/core/api/src/main/java/org/onosproject/net/device/OduCltPortDescription.java
index 379f54e..e601a9f 100644
--- a/core/api/src/main/java/org/onosproject/net/device/OduCltPortDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/device/OduCltPortDescription.java
@@ -23,7 +23,10 @@
/**
* Default implementation of immutable ODU client port description.
+ *
+ * @deprecated in Goldeneye (1.6.0)
*/
+@Deprecated
public class OduCltPortDescription extends DefaultPortDescription {
private final CltSignalType signalType;
diff --git a/core/api/src/main/java/org/onosproject/net/optical/OduCltPort.java b/core/api/src/main/java/org/onosproject/net/optical/OduCltPort.java
new file mode 100644
index 0000000..b4342f4
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/OduCltPort.java
@@ -0,0 +1,37 @@
+/*
+ * 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.onosproject.net.CltSignalType;
+import org.onosproject.net.Port;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * ODU client port (Optical channel Data Unit).
+ * Also referred to as a T-port or wide band port.
+ * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
+ */
+@Beta
+public interface OduCltPort extends Port {
+
+ /**
+ * Returns ODU client signal type.
+ *
+ * @return ODU client signal type
+ */
+ CltSignalType 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 0b4ff68..0015cf9 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,9 +28,11 @@
import org.onosproject.net.driver.AbstractBehaviour;
import org.onosproject.net.driver.DriverData;
import org.onosproject.net.optical.OchPort;
+import org.onosproject.net.optical.OduCltPort;
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.OduCltPortMapper;
import org.onosproject.net.optical.device.port.OmsPortMapper;
import org.onosproject.net.optical.device.port.PortMapper;
import org.onosproject.net.optical.utils.ForwardingDevice;
@@ -63,6 +65,7 @@
= ImmutableMap.<Class<? extends Port>, PortMapper<? extends Port>>builder()
.put(OchPort.class, new OchPortMapper())
.put(OmsPort.class, new OmsPortMapper())
+ .put(OduCltPort.class, new OduCltPortMapper())
// TODO add other optical port type here
.build();
diff --git a/core/api/src/main/java/org/onosproject/net/optical/device/OduCltPortHelper.java b/core/api/src/main/java/org/onosproject/net/optical/device/OduCltPortHelper.java
new file mode 100644
index 0000000..efda401
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/device/OduCltPortHelper.java
@@ -0,0 +1,127 @@
+/*
+ * 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.CltSignalType;
+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.OduCltPort;
+import org.onosproject.net.optical.impl.DefaultOduCltPort;
+import org.slf4j.Logger;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * ODU client port related helpers.
+ */
+@Beta
+public final class OduCltPortHelper {
+
+ private static final Logger log = getLogger(OduCltPortHelper.class);
+
+ // Annotation keys
+ /**
+ * {@link CltSignalType} as String.
+ */
+ private static final String SIGNAL_TYPE = "signalType";
+
+ /**
+ * Creates ODU client port description based on the supplied information.
+ *
+ * @param number port number
+ * @param isEnabled port enabled state
+ * @param signalType ODU client signal type
+ */
+ public static PortDescription oduCltPortDescription(PortNumber number,
+ boolean isEnabled,
+ CltSignalType signalType) {
+ return oduCltPortDescription(number, isEnabled, signalType, DefaultAnnotations.EMPTY);
+ }
+
+ /**
+ * Creates ODU client port description based on the supplied information.
+ *
+ * @param number port number
+ * @param isEnabled port enabled state
+ * @param signalType ODU client signal type
+ * @param annotations key/value annotations map
+ */
+ public static PortDescription oduCltPortDescription(PortNumber number,
+ boolean isEnabled,
+ CltSignalType signalType,
+ SparseAnnotations annotations) {
+ Builder builder = DefaultAnnotations.builder();
+ builder.putAll(annotations);
+
+ builder.set(SIGNAL_TYPE, signalType.toString());
+
+ long portSpeed = signalType.bitRate();
+ return new DefaultPortDescription(number,
+ isEnabled,
+ Port.Type.ODUCLT,
+ portSpeed,
+ builder.build());
+ }
+
+ /**
+ * Creates ODU client port description based on the supplied information.
+ *
+ * @param base PortDescription to get basic information from
+ * @param signalType ODU client signal type
+ * @param annotations key/value annotations map
+ */
+ public static PortDescription oduCltPortDescription(PortDescription base,
+ CltSignalType signalType,
+ SparseAnnotations annotations) {
+ return oduCltPortDescription(base.portNumber(), base.isEnabled(), signalType, annotations);
+ }
+
+ public static Optional<OduCltPort> asOduCltPort(Port port) {
+ if (port instanceof OduCltPort) {
+ return Optional.of((OduCltPort) port);
+ }
+
+ try {
+ Annotations an = port.annotations();
+
+ CltSignalType signalType = Enum.valueOf(CltSignalType.class,
+ an.value(SIGNAL_TYPE));
+
+
+ // Note: ODU specific annotations is not filtered-out here.
+ // DefaultOduCltPort should filter them, if necessary.
+ return Optional.of(new DefaultOduCltPort(port, signalType));
+
+ } catch (NullPointerException | IllegalArgumentException e) {
+
+ log.warn("{} was not well-formed OduClt port.", port, e);
+ return Optional.empty();
+ }
+ }
+
+ // not meant to be instantiated
+ private OduCltPortHelper() {}
+}
diff --git a/core/api/src/main/java/org/onosproject/net/optical/device/port/OduCltPortMapper.java b/core/api/src/main/java/org/onosproject/net/optical/device/port/OduCltPortMapper.java
new file mode 100644
index 0000000..6eeb631
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/device/port/OduCltPortMapper.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.device.port;
+
+import java.util.Optional;
+
+import org.onosproject.net.Port;
+import org.onosproject.net.optical.OduCltPort;
+import org.onosproject.net.optical.device.OduCltPortHelper;
+import org.onosproject.net.optical.impl.DefaultOduCltPort;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * {@link PortMapper} to handler {@link OduCltPort} translation.
+ */
+@Beta
+public class OduCltPortMapper extends AbstractPortMapper<OduCltPort> {
+
+ @Override
+ public boolean is(Port port) {
+ return port != null &&
+ port.type() == Port.Type.ODUCLT &&
+ super.is(port);
+ }
+
+ @Override
+ public Optional<OduCltPort> as(Port port) {
+ if (port instanceof OduCltPort) {
+ return Optional.of((OduCltPort) port);
+ }
+ return super.as(port);
+ }
+
+ @Override
+ protected Optional<OduCltPort> mapPort(Port port) {
+ if (port instanceof OduCltPort) {
+ return Optional.of((OduCltPort) port);
+ } else if (port instanceof org.onosproject.net.OduCltPort) {
+ // TODO remove after deprecation of old OduCltPort is complete
+
+ // translate to new OduCltPort
+ org.onosproject.net.OduCltPort old = (org.onosproject.net.OduCltPort) port;
+ return Optional.of(new DefaultOduCltPort(old,
+ old.signalType()));
+ }
+
+ return OduCltPortHelper.asOduCltPort(port);
+ }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOduCltPort.java b/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOduCltPort.java
new file mode 100644
index 0000000..f98becd
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/optical/impl/DefaultOduCltPort.java
@@ -0,0 +1,93 @@
+/*
+ * 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.CltSignalType;
+import org.onosproject.net.Port;
+import org.onosproject.net.optical.OduCltPort;
+import org.onosproject.net.optical.utils.ForwardingPort;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Implementation of ODU client port (Optical channel Data Unit).
+ * Also referred to as a T-port or wide band port.
+ * See ITU G.709 "Interfaces for the Optical Transport Network (OTN)"
+ */
+@Beta
+public class DefaultOduCltPort extends ForwardingPort implements OduCltPort {
+
+ private final CltSignalType signalType;
+
+ /**
+ * Creates an ODU client port.
+ *
+ * @param delegate Port
+ * @param signalType ODU client signal type
+ */
+ public DefaultOduCltPort(Port delegate, CltSignalType signalType) {
+ super(delegate);
+ this.signalType = checkNotNull(signalType);
+ }
+
+ @Override
+ public Type type() {
+ return Type.ODUCLT;
+ }
+
+ @Override
+ public long portSpeed() {
+ return signalType().bitRate();
+ }
+
+ @Override
+ public CltSignalType 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 DefaultOduCltPort that = (DefaultOduCltPort) obj;
+ return super.toEqualsBuilder(that)
+ .append(this.signalType(), that.signalType())
+ .isEquals();
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return super.toStringHelper()
+ .add("signalType", signalType())
+ .toString();
+ }
+
+}