diff --git a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java index 8427d76caf..adea3af451 100644 --- a/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java +++ b/core/api/src/main/java/org/onosproject/net/AnnotationKeys.java @@ -85,6 +85,10 @@ public final class AnnotationKeys { */ public static final String ROUTER_ID = "routerId"; + public static final String STATIC_LAMBDA = "staticLambda"; + + public static final String STATIC_PORT = "staticPort"; + /** * Returns the value annotated object for the specified annotation key. * The annotated value is expected to be String that can be parsed as double. diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java index fc62b257d3..557288cb1c 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java @@ -23,8 +23,8 @@ import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; +import org.onosproject.net.AnnotationKeys; import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; import org.onosproject.net.OchPort; import org.onosproject.net.OduCltPort; import org.onosproject.net.OduSignalType; @@ -138,7 +138,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler mapping = deviceResourceService.getMapping(resource); - // TODO: hardcoded 10 x 10G - return mapping.size() < 10; + if (mapping == null) { + return true; + } + + // TODO: hardcoded 80% utilization + return mapping.size() < 8; + } + + private boolean isAllowed(OpticalCircuitIntent circuitIntent, OpticalConnectivityIntent connIntent) { + ConnectPoint srcStaticPort = staticPort(circuitIntent.getSrc()); + if (srcStaticPort != null) { + if (!srcStaticPort.equals(connIntent.getSrc())) { + return false; + } + } + + ConnectPoint dstStaticPort = staticPort(circuitIntent.getDst()); + if (dstStaticPort != null) { + if (!dstStaticPort.equals(connIntent.getDst())) { + return false; + } + } + + return true; } /** @@ -191,7 +218,13 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler ports = deviceService.getPorts(deviceId); + private ConnectPoint staticPort(ConnectPoint connectPoint) { + Port port = deviceService.getPort(connectPoint.deviceId(), connectPoint.port()); + + String staticPort = port.annotations().value(AnnotationKeys.STATIC_PORT); + + // FIXME: need a better way to match the port + if (staticPort != null) { + for (Port p : deviceService.getPorts(connectPoint.deviceId())) { + if (staticPort.equals(p.number().name())) { + return new ConnectPoint(p.element().id(), p.number()); + } + } + } + + return null; + } + + private OchPort findAvailableOchPort(ConnectPoint oduPort, OpticalCircuitIntent circuitIntent) { + // First see if the port mappings are constrained + ConnectPoint ochCP = staticPort(oduPort); + + if (ochCP != null) { + OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); + IntentId intentId = deviceResourceService.getAllocations(ochPort); + if (isAvailable(circuitIntent, intentId)) { + return ochPort; + } + } + + // No port constraints, so find any port that works + List ports = deviceService.getPorts(oduPort.deviceId()); for (Port port : ports) { if (!(port instanceof OchPort)) { continue; } - // Port is not used IntentId intentId = deviceResourceService.getAllocations(port); - if (intentId == null) { - return (OchPort) port; - } - - // Port is used but has free resources if (isAvailable(circuitIntent, intentId)) { return (OchPort) port; } @@ -226,16 +282,14 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler findPorts(OpticalCircuitIntent intent) { - OchPort srcPort = findAvailableOchPort(intent.getSrc().deviceId(), intent); + OchPort srcPort = findAvailableOchPort(intent.getSrc(), intent); if (srcPort == null) { return null; } - OchPort dstPort = findAvailableOchPort(intent.getDst().deviceId(), intent); + OchPort dstPort = findAvailableOchPort(intent.getDst(), intent); if (dstPort == null) { return null; } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java index 13a2b6b53b..e5a8e3b0da 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java @@ -26,8 +26,10 @@ import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.onlab.util.Frequency; +import org.onosproject.net.AnnotationKeys; import org.onosproject.net.ChannelSpacing; import org.onosproject.net.ConnectPoint; +import org.onosproject.net.DeviceId; import org.onosproject.net.GridType; import org.onosproject.net.Link; import org.onosproject.net.OchPort; @@ -123,17 +125,26 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler getMapping(IntentId intentId) { - return intentMapping.get(intentId).value(); + Versioned> result = intentMapping.get(intentId); + + if (result == null) { + return result.value(); + } + + return null; } @Override @@ -174,10 +180,11 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { if (versionedIntents == null) { - intentMapping.put(keyIntentId, Collections.singleton(valIntentId)); + Set newSet = new HashSet<>(); + newSet.add(valIntentId); + intentMapping.put(keyIntentId, newSet); } else { versionedIntents.value().add(valIntentId); - intentMapping.put(keyIntentId, versionedIntents.value()); } return true; diff --git a/web/api/src/main/java/org/onosproject/rest/resources/ConfigProvider.java b/web/api/src/main/java/org/onosproject/rest/resources/ConfigProvider.java index 55a14f33be..296337f221 100644 --- a/web/api/src/main/java/org/onosproject/rest/resources/ConfigProvider.java +++ b/web/api/src/main/java/org/onosproject/rest/resources/ConfigProvider.java @@ -214,15 +214,28 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { private void parsePorts(DeviceId deviceId, JsonNode nodes) { List ports = new ArrayList<>(); for (JsonNode node : nodes) { - ports.add(parsePort(node)); + ports.add(parsePort(deviceId, node)); } deviceProviderService.updatePorts(deviceId, ports); } // Parses the given node with port information. - private PortDescription parsePort(JsonNode node) { + private PortDescription parsePort(DeviceId deviceId, JsonNode node) { Port.Type type = Port.Type.valueOf(node.path("type").asText("COPPER")); - PortNumber port = portNumber(node.path("port").asLong(0)); + // TL1-based ports have a name + PortNumber port = null; + if (node.has("name")) { + for (Port p : deviceService.getPorts(deviceId)) { + if (p.number().name().equals(node.get("name").asText())) { + port = p.number(); + break; + } + } + } else { + port = portNumber(node.path("port").asLong(0)); + } + + checkNotNull(port); String portName = Strings.emptyToNull(port.name()); SparseAnnotations annotations = null; if (portName != null) { @@ -239,6 +252,22 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { return new OmsPortDescription(port, node.path("enabled").asBoolean(true), CENTER, CENTER.add(TOTAL), Frequency.ofGHz(100), annotations); + case ODUCLT: + annotations = annotations(node.get("annotations")); + OduCltPort oduCltPort = (OduCltPort) deviceService.getPort(deviceId, port); + return new OduCltPortDescription(port, node.path("enabled").asBoolean(true), + oduCltPort.signalType(), annotations); + case OCH: + annotations = annotations(node.get("annotations")); + OchPort ochPort = (OchPort) deviceService.getPort(deviceId, port); + return new OchPortDescription(port, node.path("enabled").asBoolean(true), + ochPort.signalType(), ochPort.isTunable(), + ochPort.lambda(), annotations); + case OMS: + annotations = annotations(node.get("annotations")); + OmsPort omsPort = (OmsPort) deviceService.getPort(deviceId, port); + return new OmsPortDescription(port, node.path("enabled").asBoolean(true), + omsPort.minFrequency(), omsPort.maxFrequency(), omsPort.grid(), annotations); default: log.warn("{}: Unsupported Port Type"); }