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 { ...@@ -206,7 +206,6 @@ public class OpticalPathProvisioner {
206 src = p2pIntent.ingressPoint(); 206 src = p2pIntent.ingressPoint();
207 dst = p2pIntent.egressPoint(); 207 dst = p2pIntent.egressPoint();
208 } else { 208 } else {
209 - log.error("Unsupported intent type: {}", intent.getClass());
210 return; 209 return;
211 } 210 }
212 211
......
...@@ -20,6 +20,7 @@ import org.apache.karaf.shell.commands.Command; ...@@ -20,6 +20,7 @@ import org.apache.karaf.shell.commands.Command;
20 import org.onosproject.net.ConnectPoint; 20 import org.onosproject.net.ConnectPoint;
21 import org.onosproject.net.OchPort; 21 import org.onosproject.net.OchPort;
22 import org.onosproject.net.OduCltPort; 22 import org.onosproject.net.OduCltPort;
23 +import org.onosproject.net.DeviceId;
23 import org.onosproject.net.OduSignalType; 24 import org.onosproject.net.OduSignalType;
24 import org.onosproject.net.Port; 25 import org.onosproject.net.Port;
25 import org.onosproject.net.device.DeviceService; 26 import org.onosproject.net.device.DeviceService;
...@@ -28,6 +29,10 @@ import org.onosproject.net.intent.IntentService; ...@@ -28,6 +29,10 @@ import org.onosproject.net.intent.IntentService;
28 import org.onosproject.net.intent.OpticalCircuitIntent; 29 import org.onosproject.net.intent.OpticalCircuitIntent;
29 import org.onosproject.net.intent.OpticalConnectivityIntent; 30 import org.onosproject.net.intent.OpticalConnectivityIntent;
30 31
32 +import java.util.List;
33 +
34 +import static com.google.common.base.Preconditions.checkArgument;
35 +
31 /** 36 /**
32 * Installs optical connectivity or circuit intents, depending on given port types. 37 * Installs optical connectivity or circuit intents, depending on given port types.
33 */ 38 */
...@@ -45,13 +50,37 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand { ...@@ -45,13 +50,37 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
45 required = true, multiValued = false) 50 required = true, multiValued = false)
46 String egressDeviceString = null; 51 String egressDeviceString = null;
47 52
53 + private ConnectPoint createConnectPoint(String devicePortString) {
54 + String[] splitted = devicePortString.split("/");
55 +
56 + checkArgument(splitted.length == 2,
57 + "Connect point must be in \"deviceUri/portNumber\" format");
58 +
59 + DeviceId deviceId = DeviceId.deviceId(splitted[0]);
60 +
61 + DeviceService deviceService = get(DeviceService.class);
62 +
63 + List<Port> ports = deviceService.getPorts(deviceId);
64 +
65 + for (Port port : ports) {
66 + if (splitted[1].equals(port.number().name())) {
67 + return new ConnectPoint(deviceId, port.number());
68 + }
69 + }
70 +
71 + return null;
72 + }
73 +
48 @Override 74 @Override
49 protected void execute() { 75 protected void execute() {
50 IntentService service = get(IntentService.class); 76 IntentService service = get(IntentService.class);
51 77
52 - ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString); 78 + ConnectPoint ingress = createConnectPoint(ingressDeviceString);
79 + ConnectPoint egress = createConnectPoint(egressDeviceString);
53 80
54 - ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); 81 + if (ingress == null || egress == null) {
82 + print("Could not create optical intent");
83 + }
55 84
56 DeviceService deviceService = get(DeviceService.class); 85 DeviceService deviceService = get(DeviceService.class);
57 Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port()); 86 Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());
......
...@@ -22,10 +22,17 @@ import org.onosproject.net.intent.IntentId; ...@@ -22,10 +22,17 @@ import org.onosproject.net.intent.IntentId;
22 import java.util.Set; 22 import java.util.Set;
23 23
24 public interface DeviceResourceStore { 24 public interface DeviceResourceStore {
25 + /**
26 + * Returns unallocated ports on the given device.
27 + *
28 + * @param deviceId device ID
29 + * @return set of unallocated ports
30 + */
25 Set<Port> getFreePorts(DeviceId deviceId); 31 Set<Port> getFreePorts(DeviceId deviceId);
26 32
27 /** 33 /**
28 * Allocates the given ports to the given intent. 34 * Allocates the given ports to the given intent.
35 + *
29 * @param ports set of ports to allocate 36 * @param ports set of ports to allocate
30 * @param intentId intent ID 37 * @param intentId intent ID
31 * @return true if allocation was successful, false otherwise 38 * @return true if allocation was successful, false otherwise
......
...@@ -265,7 +265,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -265,7 +265,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
265 if (edge.link().type() != Link.Type.OPTICAL) { 265 if (edge.link().type() != Link.Type.OPTICAL) {
266 return -1; 266 return -1;
267 } 267 }
268 - return edge.link().annotations().value("optical.type").equals("WDM") ? +1 : -1; 268 + //return edge.link().annotations().value("optical.type").equals("WDM") ? +1 : -1;
269 + return 1;
269 } 270 }
270 }; 271 };
271 272
......
...@@ -37,6 +37,7 @@ import org.onosproject.cluster.NodeId; ...@@ -37,6 +37,7 @@ import org.onosproject.cluster.NodeId;
37 import org.onosproject.mastership.MastershipService; 37 import org.onosproject.mastership.MastershipService;
38 import org.onosproject.mastership.MastershipTerm; 38 import org.onosproject.mastership.MastershipTerm;
39 import org.onosproject.mastership.MastershipTermService; 39 import org.onosproject.mastership.MastershipTermService;
40 +import org.onosproject.net.Annotations;
40 import org.onosproject.net.AnnotationsUtil; 41 import org.onosproject.net.AnnotationsUtil;
41 import org.onosproject.net.DefaultAnnotations; 42 import org.onosproject.net.DefaultAnnotations;
42 import org.onosproject.net.DefaultDevice; 43 import org.onosproject.net.DefaultDevice;
...@@ -1007,6 +1008,26 @@ public class GossipDeviceStore ...@@ -1007,6 +1008,26 @@ public class GossipDeviceStore
1007 chassisId, annotations); 1008 chassisId, annotations);
1008 } 1009 }
1009 1010
1011 + private Port buildTypedPort(Device device, PortNumber number, boolean isEnabled,
1012 + PortDescription description, Annotations annotations) {
1013 + switch (description.type()) {
1014 + case OMS:
1015 + OmsPortDescription omsDesc = (OmsPortDescription) description;
1016 + return new OmsPort(device, number, isEnabled, omsDesc.minFrequency(),
1017 + omsDesc.maxFrequency(), omsDesc.grid(), annotations);
1018 + case OCH:
1019 + OchPortDescription ochDesc = (OchPortDescription) description;
1020 + return new OchPort(device, number, isEnabled, ochDesc.signalType(),
1021 + ochDesc.isTunable(), ochDesc.lambda(), annotations);
1022 + case ODUCLT:
1023 + OduCltPortDescription oduDesc = (OduCltPortDescription) description;
1024 + return new OduCltPort(device, number, isEnabled, oduDesc.signalType(), annotations);
1025 + default:
1026 + return new DefaultPort(device, number, isEnabled, description.type(),
1027 + description.portSpeed(), annotations);
1028 + }
1029 + }
1030 +
1010 /** 1031 /**
1011 * Returns a Port, merging description given from multiple Providers. 1032 * Returns a Port, merging description given from multiple Providers.
1012 * 1033 *
...@@ -1048,25 +1069,7 @@ public class GossipDeviceStore ...@@ -1048,25 +1069,7 @@ public class GossipDeviceStore
1048 } 1069 }
1049 annotations = merge(annotations, otherPortDesc.value().annotations()); 1070 annotations = merge(annotations, otherPortDesc.value().annotations());
1050 PortDescription other = otherPortDesc.value(); 1071 PortDescription other = otherPortDesc.value();
1051 - switch (other.type()) { 1072 + updated = buildTypedPort(device, number, isEnabled, other, annotations);
1052 - case OMS:
1053 - OmsPortDescription omsPortDesc = (OmsPortDescription) otherPortDesc.value();
1054 - updated = new OmsPort(device, number, isEnabled, omsPortDesc.minFrequency(),
1055 - omsPortDesc.maxFrequency(), omsPortDesc.grid(), annotations);
1056 - break;
1057 - case OCH:
1058 - OchPortDescription ochPortDesc = (OchPortDescription) otherPortDesc.value();
1059 - updated = new OchPort(device, number, isEnabled, ochPortDesc.signalType(),
1060 - ochPortDesc.isTunable(), ochPortDesc.lambda(), annotations);
1061 - break;
1062 - case ODUCLT:
1063 - OduCltPortDescription oduCltPortDesc = (OduCltPortDescription) otherPortDesc.value();
1064 - updated = new OduCltPort(device, number, isEnabled, oduCltPortDesc.signalType(), annotations);
1065 - break;
1066 - default:
1067 - updated = new DefaultPort(
1068 - device, number, isEnabled, other.type(), other.portSpeed(), annotations);
1069 - }
1070 newest = otherPortDesc.timestamp(); 1073 newest = otherPortDesc.timestamp();
1071 } 1074 }
1072 } 1075 }
...@@ -1075,7 +1078,7 @@ public class GossipDeviceStore ...@@ -1075,7 +1078,7 @@ public class GossipDeviceStore
1075 } 1078 }
1076 PortDescription current = portDesc.value(); 1079 PortDescription current = portDesc.value();
1077 return updated == null 1080 return updated == null
1078 - ? new DefaultPort(device, number, isEnabled, current.type(), current.portSpeed(), annotations) 1081 + ? buildTypedPort(device, number, isEnabled, current, annotations)
1079 : updated; 1082 : updated;
1080 } 1083 }
1081 1084
......