HIGUCHI Yuta
Committed by Yuta HIGUCHI

ONOS-4417 Remove OtuPort out of core.

Change-Id: Ibc72ee617b238005585f0bcd873b9123e48ee7fc
......@@ -25,7 +25,6 @@ import org.apache.karaf.shell.commands.Option;
import org.onlab.util.Frequency;
import org.onosproject.utils.Comparators;
import org.onosproject.net.Device;
import org.onosproject.net.OtuPort;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
......@@ -33,6 +32,8 @@ 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.OtuPort;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -227,9 +228,21 @@ public class DevicePortsListCommand extends DevicesListCommand {
print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations);
break;
case OTU:
if (port instanceof org.onosproject.net.OtuPort) {
org.onosproject.net.OtuPort otu = (org.onosproject.net.OtuPort) port;
print("WARN: OtuPort in old model");
print(FMT_ODUCLT_OTU, portName, portIsEnabled, portType,
otu.signalType().toString(), annotations);
break;
}
if (port instanceof OtuPort) {
print(FMT_ODUCLT_OTU, portName, portIsEnabled, portType,
((OtuPort) port).signalType().toString(), annotations);
break;
}
print("WARN: OtuPort but not on OpticalDevice or ill-formed");
print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations);
break;
default:
print(FMT, portName, portIsEnabled, portType, port.portSpeed(), annotations);
break;
......
......@@ -21,8 +21,10 @@ import static com.google.common.base.MoreObjects.toStringHelper;
/**
* Implementation of OTU port (Optical channel Transport Unit).
*
* @deprecated in Goldeneye (1.6.0)
*/
@Deprecated
public class OtuPort extends DefaultPort {
private final OtuSignalType signalType;
......
......@@ -24,7 +24,10 @@ import org.onosproject.net.SparseAnnotations;
/**
* Default implementation of immutable OTU port description.
*
* @deprecated in Goldeneye (1.6.0)
*/
@Deprecated
public class OtuPortDescription extends DefaultPortDescription {
private final OtuSignalType signalType;
......
/*
* 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();
}
......@@ -31,9 +31,11 @@ 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.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 @@ public class DefaultOpticalDevice
.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();
......
/*
* 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() {}
}
/*
* 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);
}
}
/*
* 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();
}
}
......@@ -18,6 +18,7 @@ package org.onosproject.net.device.impl;
import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription;
import static org.slf4j.LoggerFactory.getLogger;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -25,7 +26,6 @@ import org.onosproject.net.config.ConfigOperator;
import org.onosproject.net.config.basics.OpticalPortConfig;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.OtuPort;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
......@@ -39,6 +39,7 @@ 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.OtuPort;
import org.slf4j.Logger;
/**
......@@ -135,8 +136,12 @@ public final class OpticalPortOperator implements ConfigOperator {
return new DefaultPortDescription(port, descr.isEnabled(), descr.type(),
descr.portSpeed(), sa);
case OTU:
if (descr instanceof OtuPortDescription) {
// TODO This block can go away once deprecation is complete.
OtuPortDescription otu = (OtuPortDescription) descr;
return new OtuPortDescription(port, otu.isEnabled(), otu.signalType(), sa);
return otuPortDescription(port, otu.isEnabled(), otu.signalType(), sa);
}
return descr;
default:
log.warn("Unsupported optical port type {} - can't update", descr.type());
return descr;
......@@ -242,8 +247,19 @@ public final class OpticalPortOperator implements ConfigOperator {
}
return new DefaultPortDescription(ptn, isup, port.type(), port.portSpeed(), an);
case OTU:
if (port instanceof org.onosproject.net.OtuPort) {
// remove if-block once deprecation is complete
org.onosproject.net.OtuPort otu = (org.onosproject.net.OtuPort) port;
return otuPortDescription(ptn, isup, otu.signalType(), an);
}
if (port.element().is(OpticalDevice.class)) {
OpticalDevice optDevice = port.element().as(OpticalDevice.class);
if (optDevice.portIs(port, OtuPort.class)) {
OtuPort otu = (OtuPort) port;
return new OtuPortDescription(ptn, isup, otu.signalType(), an);
return otuPortDescription(ptn, isup, otu.signalType(), an);
}
}
return new DefaultPortDescription(ptn, isup, port.type(), port.portSpeed(), an);
default:
return new DefaultPortDescription(ptn, isup, port.type(), port.portSpeed(), an);
}
......
......@@ -30,7 +30,6 @@ import org.onosproject.net.LinkKey;
import org.onosproject.net.OduSignalId;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.OduSignalUtils;
import org.onosproject.net.OtuPort;
import org.onosproject.net.Path;
import org.onosproject.net.Port;
import org.onosproject.net.TributarySlot;
......@@ -50,6 +49,7 @@ import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.OpticalOduIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.optical.OduCltPort;
import org.onosproject.net.optical.OtuPort;
import org.onosproject.net.resource.Resource;
import org.onosproject.net.resource.ResourceService;
import org.onosproject.net.resource.ResourceAllocation;
......
......@@ -38,7 +38,6 @@ import org.onosproject.net.Link;
import org.onosproject.net.OduSignalId;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.OduSignalUtils;
import org.onosproject.net.OtuPort;
import org.onosproject.net.OtuSignalType;
import org.onosproject.net.Path;
import org.onosproject.net.Port;
......@@ -58,7 +57,9 @@ import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.intent.OpticalOduIntent;
import org.onosproject.net.optical.OduCltPort;
import org.onosproject.net.optical.OtuPort;
import org.onosproject.net.optical.impl.DefaultOduCltPort;
import org.onosproject.net.optical.impl.DefaultOtuPort;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.Topology;
......@@ -129,13 +130,17 @@ public class OpticalOduIntentCompilerTest {
// Otu ports with signalType=ODU2
private static final OtuPort D1P2 =
new OtuPort(device1, PortNumber.portNumber(2), true, OtuSignalType.OTU2, annotations2);
new DefaultOtuPort(new DefaultPort(device1, PortNumber.portNumber(2), true, annotations2),
OtuSignalType.OTU2);
private static final OtuPort D2P1 =
new OtuPort(device2, PortNumber.portNumber(1), true, OtuSignalType.OTU2, annotations2);
new DefaultOtuPort(new DefaultPort(device2, PortNumber.portNumber(1), true, annotations2),
OtuSignalType.OTU2);
private static final OtuPort D2P2 =
new OtuPort(device2, PortNumber.portNumber(2), true, OtuSignalType.OTU2, annotations2);
new DefaultOtuPort(new DefaultPort(device2, PortNumber.portNumber(2), true, annotations2),
OtuSignalType.OTU2);
private static final OtuPort D3P1 =
new OtuPort(device3, PortNumber.portNumber(1), true, OtuSignalType.OTU2, annotations2);
new DefaultOtuPort(new DefaultPort(device3, PortNumber.portNumber(1), true, annotations2),
OtuSignalType.OTU2);
// OduClt ports with signalType=10GBE
private static final OduCltPort D1P3 =
......
......@@ -20,6 +20,7 @@ import static org.onosproject.net.DefaultAnnotations.union;
import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription;
import java.util.Collections;
import java.util.Map;
......@@ -157,11 +158,19 @@ class DeviceDescriptions {
}
break;
case OTU:
if (newDesc.value() instanceof OtuPortDescription) {
// remove if-block after deprecation is complete
OtuPortDescription otuDesc = (OtuPortDescription) (newDesc.value());
newOne = new Timestamped<>(
new OtuPortDescription(
otuPortDescription(
otuDesc, otuDesc.signalType(), merged),
newDesc.timestamp());
} else {
// same as default case
newOne = new Timestamped<>(
new DefaultPortDescription(newDesc.value(), merged),
newDesc.timestamp());
}
break;
default:
newOne = new Timestamped<>(
......
......@@ -1116,8 +1116,14 @@ public class GossipDeviceStore
return new DefaultPort(device, number, isEnabled, description.type(),
description.portSpeed(), annotations);
case OTU:
if (description instanceof OtuPortDescription) {
// remove if-block once deprecation is complete
OtuPortDescription otuDesc = (OtuPortDescription) description;
return new OtuPort(device, number, isEnabled, otuDesc.signalType(), annotations);
}
// same as default
return new DefaultPort(device, number, isEnabled, description.type(),
description.portSpeed(), annotations);
default:
return new DefaultPort(device, number, isEnabled, description.type(),
description.portSpeed(), annotations);
......
......@@ -17,7 +17,6 @@ package org.onosproject.driver.query;
import org.onlab.util.GuavaCollectors;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.OtuPort;
import org.onosproject.net.OtuSignalType;
import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
......@@ -25,6 +24,7 @@ import org.onosproject.net.TributarySlot;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.AbstractHandlerBehaviour;
import org.onosproject.net.optical.OchPort;
import org.onosproject.net.optical.OtuPort;
import org.onosproject.net.behaviour.TributarySlotQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -70,7 +70,7 @@ public class DefaultTributarySlotQuery extends AbstractHandlerBehaviour implemen
case OCH:
return queryOchTributarySlots(p);
case OTU:
return queryOtuTributarySlots((OtuPort) p);
return queryOtuTributarySlots(p);
default:
return Collections.emptySet();
}
......@@ -102,8 +102,21 @@ public class DefaultTributarySlotQuery extends AbstractHandlerBehaviour implemen
}
}
private Set<TributarySlot> queryOtuTributarySlots(OtuPort otuPort) {
OtuSignalType signalType = otuPort.signalType();
private Set<TributarySlot> queryOtuTributarySlots(Port otuPort) {
OtuSignalType signalType = null;
if (otuPort instanceof org.onosproject.net.OtuPort) {
// remove once deprecation of old OtuPort model is done
signalType = ((org.onosproject.net.OtuPort) otuPort).signalType();
}
if (otuPort instanceof OtuPort) {
signalType = ((OtuPort) otuPort).signalType();
}
if (signalType == null) {
log.warn("{} was not an OtuPort", otuPort);
return Collections.emptySet();
}
switch (signalType) {
case OTU2:
return ENTIRE_ODU2_TRIBUTARY_SLOTS;
......
......@@ -24,6 +24,7 @@ import static org.onosproject.net.Port.Type.FIBER;
import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription;
import static org.onosproject.openflow.controller.Dpid.dpid;
import static org.onosproject.openflow.controller.Dpid.uri;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -68,7 +69,6 @@ import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.OtuPortDescription;
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.device.PortStatistics;
import org.onosproject.net.provider.AbstractProvider;
......@@ -624,7 +624,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
OtuSignalType otuSignalType =
((sigType == OFPortOpticalTransportSignalType.OTU2) ? OtuSignalType.OTU2 :
OtuSignalType.OTU4);
portDes = new OtuPortDescription(portNo, enabled, otuSignalType, annotations);
portDes = otuPortDescription(portNo, enabled, otuSignalType, annotations);
break;
default:
break;
......