Marc De Leenheer

Fix optical port types in device store (ONOS-2046).

Fix CLI add-optical-intent cmd for TL1-based devices (ONOS-2045).

Change-Id: I4ba79476104d9906707cc7cc683fedd4ce4343bb
......@@ -206,7 +206,6 @@ public class OpticalPathProvisioner {
src = p2pIntent.ingressPoint();
dst = p2pIntent.egressPoint();
} else {
log.error("Unsupported intent type: {}", intent.getClass());
return;
}
......
......@@ -20,6 +20,7 @@ import org.apache.karaf.shell.commands.Command;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.OchPort;
import org.onosproject.net.OduCltPort;
import org.onosproject.net.DeviceId;
import org.onosproject.net.OduSignalType;
import org.onosproject.net.Port;
import org.onosproject.net.device.DeviceService;
......@@ -28,6 +29,10 @@ import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
/**
* Installs optical connectivity or circuit intents, depending on given port types.
*/
......@@ -45,13 +50,37 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
required = true, multiValued = false)
String egressDeviceString = null;
private ConnectPoint createConnectPoint(String devicePortString) {
String[] splitted = devicePortString.split("/");
checkArgument(splitted.length == 2,
"Connect point must be in \"deviceUri/portNumber\" format");
DeviceId deviceId = DeviceId.deviceId(splitted[0]);
DeviceService deviceService = get(DeviceService.class);
List<Port> ports = deviceService.getPorts(deviceId);
for (Port port : ports) {
if (splitted[1].equals(port.number().name())) {
return new ConnectPoint(deviceId, port.number());
}
}
return null;
}
@Override
protected void execute() {
IntentService service = get(IntentService.class);
ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
ConnectPoint ingress = createConnectPoint(ingressDeviceString);
ConnectPoint egress = createConnectPoint(egressDeviceString);
ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
if (ingress == null || egress == null) {
print("Could not create optical intent");
}
DeviceService deviceService = get(DeviceService.class);
Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());
......
......@@ -22,10 +22,17 @@ import org.onosproject.net.intent.IntentId;
import java.util.Set;
public interface DeviceResourceStore {
/**
* Returns unallocated ports on the given device.
*
* @param deviceId device ID
* @return set of unallocated ports
*/
Set<Port> getFreePorts(DeviceId deviceId);
/**
* Allocates the given ports to the given intent.
*
* @param ports set of ports to allocate
* @param intentId intent ID
* @return true if allocation was successful, false otherwise
......
......@@ -265,7 +265,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
if (edge.link().type() != Link.Type.OPTICAL) {
return -1;
}
return edge.link().annotations().value("optical.type").equals("WDM") ? +1 : -1;
//return edge.link().annotations().value("optical.type").equals("WDM") ? +1 : -1;
return 1;
}
};
......
......@@ -37,6 +37,7 @@ import org.onosproject.cluster.NodeId;
import org.onosproject.mastership.MastershipService;
import org.onosproject.mastership.MastershipTerm;
import org.onosproject.mastership.MastershipTermService;
import org.onosproject.net.Annotations;
import org.onosproject.net.AnnotationsUtil;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultDevice;
......@@ -1007,6 +1008,26 @@ public class GossipDeviceStore
chassisId, annotations);
}
private Port buildTypedPort(Device device, PortNumber number, boolean isEnabled,
PortDescription description, Annotations annotations) {
switch (description.type()) {
case OMS:
OmsPortDescription omsDesc = (OmsPortDescription) description;
return new OmsPort(device, number, isEnabled, omsDesc.minFrequency(),
omsDesc.maxFrequency(), omsDesc.grid(), annotations);
case OCH:
OchPortDescription ochDesc = (OchPortDescription) description;
return new OchPort(device, number, isEnabled, ochDesc.signalType(),
ochDesc.isTunable(), ochDesc.lambda(), annotations);
case ODUCLT:
OduCltPortDescription oduDesc = (OduCltPortDescription) description;
return new OduCltPort(device, number, isEnabled, oduDesc.signalType(), annotations);
default:
return new DefaultPort(device, number, isEnabled, description.type(),
description.portSpeed(), annotations);
}
}
/**
* Returns a Port, merging description given from multiple Providers.
*
......@@ -1048,25 +1069,7 @@ public class GossipDeviceStore
}
annotations = merge(annotations, otherPortDesc.value().annotations());
PortDescription other = otherPortDesc.value();
switch (other.type()) {
case OMS:
OmsPortDescription omsPortDesc = (OmsPortDescription) otherPortDesc.value();
updated = new OmsPort(device, number, isEnabled, omsPortDesc.minFrequency(),
omsPortDesc.maxFrequency(), omsPortDesc.grid(), annotations);
break;
case OCH:
OchPortDescription ochPortDesc = (OchPortDescription) otherPortDesc.value();
updated = new OchPort(device, number, isEnabled, ochPortDesc.signalType(),
ochPortDesc.isTunable(), ochPortDesc.lambda(), annotations);
break;
case ODUCLT:
OduCltPortDescription oduCltPortDesc = (OduCltPortDescription) otherPortDesc.value();
updated = new OduCltPort(device, number, isEnabled, oduCltPortDesc.signalType(), annotations);
break;
default:
updated = new DefaultPort(
device, number, isEnabled, other.type(), other.portSpeed(), annotations);
}
updated = buildTypedPort(device, number, isEnabled, other, annotations);
newest = otherPortDesc.timestamp();
}
}
......@@ -1075,7 +1078,7 @@ public class GossipDeviceStore
}
PortDescription current = portDesc.value();
return updated == null
? new DefaultPort(device, number, isEnabled, current.type(), current.portSpeed(), annotations)
? buildTypedPort(device, number, isEnabled, current, annotations)
: updated;
}
......