HIGUCHI Yuta
Committed by Gerrit Code Review

[ONOS-4513] Remove optical dependency from store/dist

- Ensure only generic port description will go into the DeviceStore

Change-Id: I7ba6c1680c2d5e3a5579337193c620c89f5f7f41
......@@ -22,6 +22,8 @@ import static org.onlab.util.Tools.nullIsNotFound;
import static org.onosproject.net.MastershipRole.MASTER;
import static org.onosproject.net.MastershipRole.NONE;
import static org.onosproject.net.MastershipRole.STANDBY;
import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.onosproject.security.AppPermission.Type.DEVICE_READ;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -74,8 +76,14 @@ import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.device.DeviceStore;
import org.onosproject.net.device.DeviceStoreDelegate;
import org.onosproject.net.device.OchPortDescription;
import org.onosproject.net.device.OduCltPortDescription;
import org.onosproject.net.device.OmsPortDescription;
import org.onosproject.net.device.OtuPortDescription;
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.device.PortStatistics;
import org.onosproject.net.optical.device.OmsPortHelper;
import org.onosproject.net.optical.device.OtuPortHelper;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
......@@ -420,6 +428,60 @@ public class DeviceManager
}
}
/**
* Transforms optical specific PortDescription to generic PortDescription.
*
* @param descr PortDescription
* @return generic PortDescription
* @deprecated in Goldeneye (1.6.0)
*/
@Deprecated
private PortDescription ensureGeneric(PortDescription descr) {
switch (descr.type()) {
case OCH:
if (descr instanceof OchPortDescription) {
OchPortDescription och = (OchPortDescription) descr;
return ochPortDescription(och,
och.signalType(),
och.isTunable(),
och.lambda(),
och.annotations());
}
break;
case ODUCLT:
if (descr instanceof OduCltPortDescription) {
OduCltPortDescription clt = (OduCltPortDescription) descr;
return oduCltPortDescription(clt,
clt.signalType(),
clt.annotations());
}
break;
case OMS:
if (descr instanceof OmsPortDescription) {
OmsPortDescription oms = (OmsPortDescription) descr;
return OmsPortHelper.omsPortDescription(oms,
oms.minFrequency(),
oms.maxFrequency(),
oms.grid(),
oms.annotations());
}
break;
case OTU:
if (descr instanceof OtuPortDescription) {
OtuPortDescription otu = (OtuPortDescription) descr;
return OtuPortHelper.otuPortDescription(otu,
otu.signalType(),
otu.annotations());
}
break;
default:
// no-op
break;
}
return descr;
}
@Override
public void updatePorts(DeviceId deviceId,
List<PortDescription> portDescriptions) {
......@@ -434,6 +496,7 @@ public class DeviceManager
}
portDescriptions = portDescriptions.stream()
.map(e -> consolidate(deviceId, e))
.map(this::ensureGeneric)
.collect(Collectors.toList());
List<DeviceEvent> events = store.updatePorts(this.provider().id(),
deviceId, portDescriptions);
......@@ -462,12 +525,14 @@ public class DeviceManager
if ((Device.Type.ROADM.equals(device.type())) ||
(Device.Type.OTN.equals(device.type()))) {
Port port = getPort(deviceId, portDescription.portNumber());
// FIXME This is ignoring all other info in portDescription given as input??
portDescription = OpticalPortOperator.descriptionOf(port, portDescription.isEnabled());
}
portDescription = consolidate(deviceId, portDescription);
final DeviceEvent event = store.updatePortStatus(this.provider().id(),
deviceId, portDescription);
deviceId,
ensureGeneric(portDescription));
if (event != null) {
log.info("Device {} port {} status changed", deviceId, event.port().number());
post(event);
......
......@@ -17,11 +17,6 @@ package org.onosproject.store.device.impl;
import static com.google.common.base.Preconditions.checkNotNull;
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;
import java.util.concurrent.ConcurrentHashMap;
......@@ -32,10 +27,6 @@ import org.onosproject.net.SparseAnnotations;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DefaultPortDescription;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.OchPortDescription;
import org.onosproject.net.device.OduCltPortDescription;
import org.onosproject.net.device.OmsPortDescription;
import org.onosproject.net.device.OtuPortDescription;
import org.onosproject.net.device.PortDescription;
import org.onosproject.store.Timestamp;
import org.onosproject.store.impl.Timestamped;
......@@ -105,78 +96,9 @@ class DeviceDescriptions {
if (oldOne != null) {
SparseAnnotations merged = union(oldOne.value().annotations(),
newDesc.value().annotations());
newOne = null;
switch (newDesc.value().type()) {
case OMS:
if (newDesc.value() instanceof OmsPortDescription) {
// remove if-block after deprecation is complete
OmsPortDescription omsDesc = (OmsPortDescription) (newDesc.value());
newOne = new Timestamped<>(
omsPortDescription(omsDesc,
omsDesc.minFrequency(),
omsDesc.maxFrequency(),
omsDesc.grid(), merged),
newDesc.timestamp());
} else {
// same as default case
newOne = new Timestamped<>(
new DefaultPortDescription(newDesc.value(), merged),
newDesc.timestamp());
}
break;
case OCH:
if (newDesc.value() instanceof OchPortDescription) {
// remove if-block after Och related deprecation is complete
OchPortDescription ochDesc = (OchPortDescription) (newDesc.value());
newOne = new Timestamped<>(
ochPortDescription(ochDesc,
ochDesc.signalType(),
ochDesc.isTunable(),
ochDesc.lambda(), merged),
newDesc.timestamp());
} else {
// same as default case
newOne = new Timestamped<>(
new DefaultPortDescription(newDesc.value(), merged),
newDesc.timestamp());
}
break;
case ODUCLT:
if (newDesc.value() instanceof OduCltPortDescription) {
// remove if-block after deprecation is complete
OduCltPortDescription ocDesc = (OduCltPortDescription) (newDesc.value());
newOne = new Timestamped<>(
oduCltPortDescription(ocDesc,
ocDesc.signalType(),
merged),
newDesc.timestamp());
} else {
// same as default case
newOne = new Timestamped<>(
new DefaultPortDescription(newDesc.value(), merged),
newDesc.timestamp());
}
break;
case OTU:
if (newDesc.value() instanceof OtuPortDescription) {
// remove if-block after deprecation is complete
OtuPortDescription otuDesc = (OtuPortDescription) (newDesc.value());
newOne = new Timestamped<>(
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<>(
newOne = new Timestamped<>(
new DefaultPortDescription(newDesc.value(), merged),
newDesc.timestamp());
}
}
portDescs.put(newOne.value().portNumber(), newOne);
}
......