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 { ...@@ -115,7 +115,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
115 115
116 @Option(name = "-l", aliases = "--lambda", description = "Lambda", 116 @Option(name = "-l", aliases = "--lambda", description = "Lambda",
117 required = false, multiValued = false) 117 required = false, multiValued = false)
118 - private boolean lambda = false; 118 + private Boolean lambda = null;
119 119
120 @Option(name = "-a", aliases = "--appId", description = "Application Id", 120 @Option(name = "-a", aliases = "--appId", description = "Application Id",
121 required = false, multiValued = false) 121 required = false, multiValued = false)
...@@ -189,7 +189,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -189,7 +189,7 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
189 // Set the default EthType based on the IP version if the matching 189 // Set the default EthType based on the IP version if the matching
190 // source or destination IP prefixes. 190 // source or destination IP prefixes.
191 // 191 //
192 - short ethType = EthType.IPV4.value(); 192 + Short ethType = null;
193 if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) { 193 if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) {
194 ethType = EthType.IPV6.value(); 194 ethType = EthType.IPV6.value();
195 } 195 }
...@@ -199,8 +199,9 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -199,8 +199,9 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
199 if (!isNullOrEmpty(ethTypeString)) { 199 if (!isNullOrEmpty(ethTypeString)) {
200 ethType = EthType.parseFromString(ethTypeString); 200 ethType = EthType.parseFromString(ethTypeString);
201 } 201 }
202 + if (ethType != null) {
202 selectorBuilder.matchEthType(ethType); 203 selectorBuilder.matchEthType(ethType);
203 - 204 + }
204 if (!isNullOrEmpty(srcMacString)) { 205 if (!isNullOrEmpty(srcMacString)) {
205 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString)); 206 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
206 } 207 }
...@@ -312,11 +313,12 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -312,11 +313,12 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
312 } 313 }
313 314
314 // Check for a lambda specification 315 // Check for a lambda specification
316 + if (lambda != null) {
315 if (lambda) { 317 if (lambda) {
316 constraints.add(new LambdaConstraint(null)); 318 constraints.add(new LambdaConstraint(null));
317 } 319 }
318 constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL)); 320 constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL));
319 - 321 + }
320 return constraints; 322 return constraints;
321 } 323 }
322 324
......
...@@ -24,6 +24,7 @@ import org.onlab.util.KryoNamespace; ...@@ -24,6 +24,7 @@ import org.onlab.util.KryoNamespace;
24 import org.onlab.util.PositionalParameterStringFormatter; 24 import org.onlab.util.PositionalParameterStringFormatter;
25 import org.onosproject.net.Link; 25 import org.onosproject.net.Link;
26 import org.onosproject.net.LinkKey; 26 import org.onosproject.net.LinkKey;
27 +import org.onosproject.net.Port;
27 import org.onosproject.net.intent.IntentId; 28 import org.onosproject.net.intent.IntentId;
28 import org.onosproject.net.link.LinkService; 29 import org.onosproject.net.link.LinkService;
29 import org.onosproject.net.resource.link.BandwidthResource; 30 import org.onosproject.net.resource.link.BandwidthResource;
...@@ -140,14 +141,15 @@ public class ConsistentLinkResourceStore extends ...@@ -140,14 +141,15 @@ public class ConsistentLinkResourceStore extends
140 141
141 private Set<LambdaResourceAllocation> getLambdaResourceCapacity(Link link) { 142 private Set<LambdaResourceAllocation> getLambdaResourceCapacity(Link link) {
142 Set<LambdaResourceAllocation> allocations = new HashSet<>(); 143 Set<LambdaResourceAllocation> allocations = new HashSet<>();
143 - 144 + Port port = deviceService.getPort(link.src().deviceId(), link.src().port());
144 - OmsPort port = (OmsPort) deviceService.getPort(link.src().deviceId(), link.src().port()); 145 + if (port instanceof OmsPort) {
146 + OmsPort omsPort = (OmsPort) port;
145 147
146 // Assume fixed grid for now 148 // Assume fixed grid for now
147 - for (int i = 0; i < port.totalChannels(); i++) { 149 + for (int i = 0; i < omsPort.totalChannels(); i++) {
148 allocations.add(new LambdaResourceAllocation(LambdaResource.valueOf(i))); 150 allocations.add(new LambdaResourceAllocation(LambdaResource.valueOf(i)));
149 } 151 }
150 - 152 + }
151 return allocations; 153 return allocations;
152 } 154 }
153 155
......