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; ...@@ -26,6 +26,7 @@ import org.onlab.util.Bandwidth;
26 import org.onosproject.cli.AbstractShellCommand; 26 import org.onosproject.cli.AbstractShellCommand;
27 import org.onosproject.core.ApplicationId; 27 import org.onosproject.core.ApplicationId;
28 import org.onosproject.core.CoreService; 28 import org.onosproject.core.CoreService;
29 +import org.onosproject.net.EncapsulationType;
29 import org.onosproject.net.Link; 30 import org.onosproject.net.Link;
30 import org.onosproject.net.PortNumber; 31 import org.onosproject.net.PortNumber;
31 import org.onosproject.net.flow.DefaultTrafficSelector; 32 import org.onosproject.net.flow.DefaultTrafficSelector;
...@@ -36,6 +37,7 @@ import org.onosproject.net.intent.Constraint; ...@@ -36,6 +37,7 @@ import org.onosproject.net.intent.Constraint;
36 import org.onosproject.net.intent.Intent; 37 import org.onosproject.net.intent.Intent;
37 import org.onosproject.net.intent.Key; 38 import org.onosproject.net.intent.Key;
38 import org.onosproject.net.intent.constraint.BandwidthConstraint; 39 import org.onosproject.net.intent.constraint.BandwidthConstraint;
40 +import org.onosproject.net.intent.constraint.EncapsulationConstraint;
39 import org.onosproject.net.intent.constraint.LambdaConstraint; 41 import org.onosproject.net.intent.constraint.LambdaConstraint;
40 import org.onosproject.net.intent.constraint.LinkTypeConstraint; 42 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
41 import org.onosproject.net.intent.constraint.PartialFailureConstraint; 43 import org.onosproject.net.intent.constraint.PartialFailureConstraint;
...@@ -116,14 +118,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -116,14 +118,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
116 required = false, multiValued = true) 118 required = false, multiValued = true)
117 private List<String> extHdrStringList = null; 119 private List<String> extHdrStringList = null;
118 120
119 - @Option(name = "-b", aliases = "--bandwidth", description = "Bandwidth",
120 - required = false, multiValued = false)
121 - private String bandwidthString = null;
122 -
123 - @Option(name = "-l", aliases = "--lambda", description = "Lambda",
124 - required = false, multiValued = false)
125 - private boolean lambda = false;
126 -
127 @Option(name = "-a", aliases = "--appId", description = "Application Id", 121 @Option(name = "-a", aliases = "--appId", description = "Application Id",
128 required = false, multiValued = false) 122 required = false, multiValued = false)
129 private String appId = null; 123 private String appId = null;
...@@ -132,10 +126,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -132,10 +126,6 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
132 required = false, multiValued = false) 126 required = false, multiValued = false)
133 private String intentKey = null; 127 private String intentKey = null;
134 128
135 - @Option(name = "--partial", description = "Allow partial installation",
136 - required = false, multiValued = false)
137 - private boolean partial = false;
138 -
139 129
140 // Treatments 130 // Treatments
141 @Option(name = "--setEthSrc", description = "Rewrite Source MAC Address", 131 @Option(name = "--setEthSrc", description = "Rewrite Source MAC Address",
...@@ -176,6 +166,24 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -176,6 +166,24 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
176 required = false, multiValued = false) 166 required = false, multiValued = false)
177 private int priority = Intent.DEFAULT_INTENT_PRIORITY; 167 private int priority = Intent.DEFAULT_INTENT_PRIORITY;
178 168
169 + // Constraints
170 + @Option(name = "-b", aliases = "--bandwidth", description = "Bandwidth",
171 + required = false, multiValued = false)
172 + private String bandwidthString = null;
173 +
174 + @Option(name = "-l", aliases = "--lambda", description = "Lambda",
175 + required = false, multiValued = false)
176 + private boolean lambda = false;
177 +
178 + @Option(name = "--partial", description = "Allow partial installation",
179 + required = false, multiValued = false)
180 + private boolean partial = false;
181 +
182 + @Option(name = "-e", aliases = "--encapsulation", description = "Encapsulation type",
183 + required = false, multiValued = false)
184 + private String encapsulationString = null;
185 +
186 +
179 /** 187 /**
180 * Constructs a traffic selector based on the command line arguments 188 * Constructs a traffic selector based on the command line arguments
181 * presented to the command. 189 * presented to the command.
...@@ -373,10 +381,17 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { ...@@ -373,10 +381,17 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
373 } 381 }
374 constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL)); 382 constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL));
375 383
384 + // Check for partial failure specification
376 if (partial) { 385 if (partial) {
377 constraints.add(new PartialFailureConstraint()); 386 constraints.add(new PartialFailureConstraint());
378 } 387 }
379 388
389 + // Check for encapsulation specification
390 + if (!isNullOrEmpty(encapsulationString)) {
391 + final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
392 + constraints.add(new EncapsulationConstraint(encapType));
393 + }
394 +
380 return constraints; 395 return constraints;
381 } 396 }
382 397
......
1 +package org.onosproject.cli.net;
2 +
3 +import org.apache.karaf.shell.console.Completer;
4 +import org.apache.karaf.shell.console.completer.StringsCompleter;
5 +import org.onosproject.net.EncapsulationType;
6 +
7 +import java.util.List;
8 +import java.util.SortedSet;
9 +
10 +/**
11 + * Encapsulation type completer.
12 + */
13 +public class EncapTypeCompleter implements Completer {
14 +
15 + @Override
16 + public int complete(String buffer, int cursor, List<String> candidates) {
17 + // Delegate string completer
18 + StringsCompleter delegate = new StringsCompleter();
19 + SortedSet<String> strings = delegate.getStrings();
20 +
21 + for (EncapsulationType encapType : EncapsulationType.values()) {
22 + strings.add(encapType.toString());
23 + }
24 +
25 + // Now let the completer do the work for figuring out what to offer.
26 + return delegate.complete(buffer, cursor, candidates);
27 + }
28 +}
...@@ -201,6 +201,7 @@ ...@@ -201,6 +201,7 @@
201 <entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/> 201 <entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/>
202 <entry key="--extHdr" value-ref="ExtHeaderCompleter"/> 202 <entry key="--extHdr" value-ref="ExtHeaderCompleter"/>
203 <entry key="-a" value-ref="allAppNameCompleter"/> 203 <entry key="-a" value-ref="allAppNameCompleter"/>
204 + <entry key="-e" value-ref="encapTypeCompleter"/>
204 </optional-completers> 205 </optional-completers>
205 </command> 206 </command>
206 <command> 207 <command>
...@@ -216,6 +217,7 @@ ...@@ -216,6 +217,7 @@
216 <entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/> 217 <entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/>
217 <entry key="--extHdr" value-ref="ExtHeaderCompleter"/> 218 <entry key="--extHdr" value-ref="ExtHeaderCompleter"/>
218 <entry key="-a" value-ref="allAppNameCompleter"/> 219 <entry key="-a" value-ref="allAppNameCompleter"/>
220 + <entry key="-e" value-ref="encapTypeCompleter"/>
219 </optional-completers> 221 </optional-completers>
220 </command> 222 </command>
221 <command> 223 <command>
...@@ -252,6 +254,7 @@ ...@@ -252,6 +254,7 @@
252 <entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/> 254 <entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/>
253 <entry key="--extHdr" value-ref="ExtHeaderCompleter"/> 255 <entry key="--extHdr" value-ref="ExtHeaderCompleter"/>
254 <entry key="-a" value-ref="allAppNameCompleter"/> 256 <entry key="-a" value-ref="allAppNameCompleter"/>
257 + <entry key="-e" value-ref="encapTypeCompleter"/>
255 </optional-completers> 258 </optional-completers>
256 </command> 259 </command>
257 <command> 260 <command>
...@@ -266,6 +269,7 @@ ...@@ -266,6 +269,7 @@
266 <entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/> 269 <entry key="--icmp6Code" value-ref="Icmp6CodeCompleter"/>
267 <entry key="--extHdr" value-ref="ExtHeaderCompleter"/> 270 <entry key="--extHdr" value-ref="ExtHeaderCompleter"/>
268 <entry key="-a" value-ref="allAppNameCompleter"/> 271 <entry key="-a" value-ref="allAppNameCompleter"/>
272 + <entry key="-e" value-ref="encapTypeCompleter"/>
269 </optional-completers> 273 </optional-completers>
270 </command> 274 </command>
271 <command> 275 <command>
...@@ -499,5 +503,6 @@ ...@@ -499,5 +503,6 @@
499 <bean id="startStopCompleter" class="org.onosproject.cli.StartStopCompleter"/> 503 <bean id="startStopCompleter" class="org.onosproject.cli.StartStopCompleter"/>
500 <bean id="metricNameCompleter" class="org.onosproject.cli.MetricNameCompleter"/> 504 <bean id="metricNameCompleter" class="org.onosproject.cli.MetricNameCompleter"/>
501 <bean id="upDownCompleter" class="org.onosproject.cli.UpDownCompleter"/> 505 <bean id="upDownCompleter" class="org.onosproject.cli.UpDownCompleter"/>
506 + <bean id="encapTypeCompleter" class="org.onosproject.cli.net.EncapTypeCompleter"/>
502 507
503 </blueprint> 508 </blueprint>
......