Ayaka Koshibe

Fixes for resource-related test CLI commands:

- Tweak to assumptions in base command for ConnectivityIntents
- Check before casting between port types

Change-Id: I5db84ec435029f2de84abb0f3f5ddc726035bf1b
......@@ -115,7 +115,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
@Option(name = "-l", aliases = "--lambda", description = "Lambda",
required = false, multiValued = false)
private boolean lambda = false;
private Boolean lambda = null;
@Option(name = "-a", aliases = "--appId", description = "Application Id",
required = false, multiValued = false)
......@@ -189,7 +189,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
// Set the default EthType based on the IP version if the matching
// source or destination IP prefixes.
//
short ethType = EthType.IPV4.value();
Short ethType = null;
if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) {
ethType = EthType.IPV6.value();
}
......@@ -199,8 +199,9 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
if (!isNullOrEmpty(ethTypeString)) {
ethType = EthType.parseFromString(ethTypeString);
}
selectorBuilder.matchEthType(ethType);
if (ethType != null) {
selectorBuilder.matchEthType(ethType);
}
if (!isNullOrEmpty(srcMacString)) {
selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
}
......@@ -312,11 +313,12 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
}
// Check for a lambda specification
if (lambda) {
constraints.add(new LambdaConstraint(null));
if (lambda != null) {
if (lambda) {
constraints.add(new LambdaConstraint(null));
}
constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL));
}
constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL));
return constraints;
}
......
......@@ -24,6 +24,7 @@ import org.onlab.util.KryoNamespace;
import org.onlab.util.PositionalParameterStringFormatter;
import org.onosproject.net.Link;
import org.onosproject.net.LinkKey;
import org.onosproject.net.Port;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.link.LinkService;
import org.onosproject.net.resource.link.BandwidthResource;
......@@ -140,14 +141,15 @@ public class ConsistentLinkResourceStore extends
private Set<LambdaResourceAllocation> getLambdaResourceCapacity(Link link) {
Set<LambdaResourceAllocation> allocations = new HashSet<>();
Port port = deviceService.getPort(link.src().deviceId(), link.src().port());
if (port instanceof OmsPort) {
OmsPort omsPort = (OmsPort) port;
OmsPort port = (OmsPort) deviceService.getPort(link.src().deviceId(), link.src().port());
// Assume fixed grid for now
for (int i = 0; i < port.totalChannels(); i++) {
allocations.add(new LambdaResourceAllocation(LambdaResource.valueOf(i)));
// Assume fixed grid for now
for (int i = 0; i < omsPort.totalChannels(); i++) {
allocations.add(new LambdaResourceAllocation(LambdaResource.valueOf(i)));
}
}
return allocations;
}
......