Michele Santuari
Committed by Gerrit Code Review

encasulation CLI paramter and completer ONOS-3446

Change-Id: I7ceabf34ae9e055c511302341bbf86488a112f5f
......@@ -26,6 +26,7 @@ import org.onlab.util.Bandwidth;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.EncapsulationType;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultTrafficSelector;
......@@ -36,6 +37,7 @@ import org.onosproject.net.intent.Constraint;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.net.intent.constraint.LambdaConstraint;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import org.onosproject.net.intent.constraint.PartialFailureConstraint;
......@@ -116,14 +118,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
required = false, multiValued = true)
private List<String> extHdrStringList = null;
@Option(name = "-b", aliases = "--bandwidth", description = "Bandwidth",
required = false, multiValued = false)
private String bandwidthString = null;
@Option(name = "-l", aliases = "--lambda", description = "Lambda",
required = false, multiValued = false)
private boolean lambda = false;
@Option(name = "-a", aliases = "--appId", description = "Application Id",
required = false, multiValued = false)
private String appId = null;
......@@ -132,10 +126,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
required = false, multiValued = false)
private String intentKey = null;
@Option(name = "--partial", description = "Allow partial installation",
required = false, multiValued = false)
private boolean partial = false;
// Treatments
@Option(name = "--setEthSrc", description = "Rewrite Source MAC Address",
......@@ -176,6 +166,24 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
required = false, multiValued = false)
private int priority = Intent.DEFAULT_INTENT_PRIORITY;
// Constraints
@Option(name = "-b", aliases = "--bandwidth", description = "Bandwidth",
required = false, multiValued = false)
private String bandwidthString = null;
@Option(name = "-l", aliases = "--lambda", description = "Lambda",
required = false, multiValued = false)
private boolean lambda = false;
@Option(name = "--partial", description = "Allow partial installation",
required = false, multiValued = false)
private boolean partial = false;
@Option(name = "-e", aliases = "--encapsulation", description = "Encapsulation type",
required = false, multiValued = false)
private String encapsulationString = null;
/**
* Constructs a traffic selector based on the command line arguments
* presented to the command.
......@@ -373,10 +381,17 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
}
constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL));
// Check for partial failure specification
if (partial) {
constraints.add(new PartialFailureConstraint());
}
// Check for encapsulation specification
if (!isNullOrEmpty(encapsulationString)) {
final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
constraints.add(new EncapsulationConstraint(encapType));
}
return constraints;
}
......
package org.onosproject.cli.net;
import org.apache.karaf.shell.console.Completer;
import org.apache.karaf.shell.console.completer.StringsCompleter;
import org.onosproject.net.EncapsulationType;
import java.util.List;
import java.util.SortedSet;
/**
* Encapsulation type completer.
*/
public class EncapTypeCompleter implements Completer {
@Override
public int complete(String buffer, int cursor, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
SortedSet<String> strings = delegate.getStrings();
for (EncapsulationType encapType : EncapsulationType.values()) {
strings.add(encapType.toString());
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(buffer, cursor, candidates);
}
}
......@@ -201,6 +201,7 @@
<entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/>
<entry key="--extHdr" value-ref="ExtHeaderCompleter"/>
<entry key="-a" value-ref="allAppNameCompleter"/>
<entry key="-e" value-ref="encapTypeCompleter"/>
</optional-completers>
</command>
<command>
......@@ -216,6 +217,7 @@
<entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/>
<entry key="--extHdr" value-ref="ExtHeaderCompleter"/>
<entry key="-a" value-ref="allAppNameCompleter"/>
<entry key="-e" value-ref="encapTypeCompleter"/>
</optional-completers>
</command>
<command>
......@@ -252,6 +254,7 @@
<entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/>
<entry key="--extHdr" value-ref="ExtHeaderCompleter"/>
<entry key="-a" value-ref="allAppNameCompleter"/>
<entry key="-e" value-ref="encapTypeCompleter"/>
</optional-completers>
</command>
<command>
......@@ -266,6 +269,7 @@
<entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/>
<entry key="--extHdr" value-ref="ExtHeaderCompleter"/>
<entry key="-a" value-ref="allAppNameCompleter"/>
<entry key="-e" value-ref="encapTypeCompleter"/>
</optional-completers>
</command>
<command>
......@@ -499,5 +503,6 @@
<bean id="startStopCompleter" class="org.onosproject.cli.StartStopCompleter"/>
<bean id="metricNameCompleter" class="org.onosproject.cli.MetricNameCompleter"/>
<bean id="upDownCompleter" class="org.onosproject.cli.UpDownCompleter"/>
<bean id="encapTypeCompleter" class="org.onosproject.cli.net.EncapTypeCompleter"/>
</blueprint>
......