blob: e2753b2df239b57ccc7dfa70153ba987499e9654 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska7d693f52014-10-21 19:17:57 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070017
18import org.apache.karaf.shell.commands.Option;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +080019import org.onlab.packet.Ip6Address;
20import org.onlab.packet.IpAddress;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070021import org.onlab.packet.IpPrefix;
22import org.onlab.packet.MacAddress;
23import org.onlab.packet.TpPort;
Dusan Pajin6b887c92015-07-01 18:32:49 +020024import org.onlab.packet.VlanId;
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070025import org.onlab.util.Bandwidth;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.cli.AbstractShellCommand;
Ray Milkey95c50872015-04-14 14:32:31 -070027import org.onosproject.core.ApplicationId;
28import org.onosproject.core.CoreService;
Michele Santuari05b882c2015-11-25 09:40:46 +010029import org.onosproject.net.EncapsulationType;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.Link;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020031import org.onosproject.net.PortNumber;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.net.flow.DefaultTrafficSelector;
Brian O'Connor11ff8702015-04-29 19:37:15 -070033import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import org.onosproject.net.flow.TrafficSelector;
35import org.onosproject.net.flow.TrafficTreatment;
36import org.onosproject.net.intent.Constraint;
Ray Milkeyc24cde32015-03-10 18:20:18 -070037import org.onosproject.net.intent.Intent;
Ray Milkey5b3717e2015-02-05 11:44:08 -080038import org.onosproject.net.intent.Key;
Brian O'Connorabafb502014-12-02 22:26:20 -080039import org.onosproject.net.intent.constraint.BandwidthConstraint;
Michele Santuari05b882c2015-11-25 09:40:46 +010040import org.onosproject.net.intent.constraint.EncapsulationConstraint;
Brian O'Connorabafb502014-12-02 22:26:20 -080041import org.onosproject.net.intent.constraint.LambdaConstraint;
42import org.onosproject.net.intent.constraint.LinkTypeConstraint;
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070043import org.onosproject.net.intent.constraint.PartialFailureConstraint;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070044
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080045import java.util.LinkedList;
46import java.util.List;
47
48import static com.google.common.base.Strings.isNullOrEmpty;
49import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
50
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070051/**
52 * Base class for command line operations for connectivity based intents.
53 */
54public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
55
Jonathan Hart2c25e362014-11-17 18:14:19 -080056 // Selectors
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070057 @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address",
58 required = false, multiValued = false)
59 private String srcMacString = null;
60
61 @Option(name = "-d", aliases = "--ethDst", description = "Destination MAC Address",
62 required = false, multiValued = false)
63 private String dstMacString = null;
64
65 @Option(name = "-t", aliases = "--ethType", description = "Ethernet Type",
66 required = false, multiValued = false)
Ray Milkey04c78322015-01-21 14:57:58 -080067 private String ethTypeString = null;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070068
Dusan Pajin6b887c92015-07-01 18:32:49 +020069 @Option(name = "-v", aliases = "--vlan", description = "VLAN ID",
70 required = false, multiValued = false)
71 private String vlanString = null;
72
Jonathan Hart5f7097e2014-11-11 11:50:28 -080073 @Option(name = "--ipProto", description = "IP Protocol",
74 required = false, multiValued = false)
75 private String ipProtoString = null;
76
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -070077 @Option(name = "--ipSrc", description = "Source IP Prefix",
Jonathan Hart5f7097e2014-11-11 11:50:28 -080078 required = false, multiValued = false)
79 private String srcIpString = null;
80
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -070081 @Option(name = "--ipDst", description = "Destination IP Prefix",
Jonathan Hart5f7097e2014-11-11 11:50:28 -080082 required = false, multiValued = false)
83 private String dstIpString = null;
84
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +080085 @Option(name = "--fLabel", description = "IPv6 Flow Label",
86 required = false, multiValued = false)
87 private String fLabelString = null;
88
89 @Option(name = "--icmp6Type", description = "ICMPv6 Type",
90 required = false, multiValued = false)
91 private String icmp6TypeString = null;
92
93 @Option(name = "--icmp6Code", description = "ICMPv6 Code",
94 required = false, multiValued = false)
95 private String icmp6CodeString = null;
96
97 @Option(name = "--ndTarget", description = "IPv6 Neighbor Discovery Target Address",
98 required = false, multiValued = false)
99 private String ndTargetString = null;
100
101 @Option(name = "--ndSLL", description = "IPv6 Neighbor Discovery Source Link-Layer",
102 required = false, multiValued = false)
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800103 private String ndSllString = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800104
105 @Option(name = "--ndTLL", description = "IPv6 Neighbor Discovery Target Link-Layer",
106 required = false, multiValued = false)
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800107 private String ndTllString = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800108
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800109 @Option(name = "--tcpSrc", description = "Source TCP Port",
110 required = false, multiValued = false)
111 private String srcTcpString = null;
112
113 @Option(name = "--tcpDst", description = "Destination TCP Port",
114 required = false, multiValued = false)
115 private String dstTcpString = null;
116
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800117 @Option(name = "--extHdr", description = "IPv6 Extension Header Pseudo-field",
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800118 required = false, multiValued = true)
119 private List<String> extHdrStringList = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800120
Ray Milkey95c50872015-04-14 14:32:31 -0700121 @Option(name = "-a", aliases = "--appId", description = "Application Id",
122 required = false, multiValued = false)
123 private String appId = null;
124
Ray Milkey5b3717e2015-02-05 11:44:08 -0800125 @Option(name = "-k", aliases = "--key", description = "Intent Key",
126 required = false, multiValued = false)
127 private String intentKey = null;
128
Jonathan Hart2c25e362014-11-17 18:14:19 -0800129
130 // Treatments
131 @Option(name = "--setEthSrc", description = "Rewrite Source MAC Address",
132 required = false, multiValued = false)
133 private String setEthSrcString = null;
134
135 @Option(name = "--setEthDst", description = "Rewrite Destination MAC Address",
136 required = false, multiValued = false)
137 private String setEthDstString = null;
138
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800139 @Option(name = "--setIpSrc", description = "Rewrite Source IP Address",
140 required = false, multiValued = false)
141 private String setIpSrcString = null;
142
143 @Option(name = "--setIpDst", description = "Rewrite Destination IP Address",
144 required = false, multiValued = false)
145 private String setIpDstString = null;
146
Dusan Pajin6b887c92015-07-01 18:32:49 +0200147 @Option(name = "--setVlan", description = "Rewrite VLAN ID",
148 required = false, multiValued = false)
149 private String setVlan = null;
150
151 @Option(name = "--popVlan", description = "Pop VLAN Tag",
152 required = false, multiValued = false)
153 private boolean popVlan = false;
154
155 @Option(name = "--pushVlan", description = "Push VLAN ID",
156 required = false, multiValued = false)
157 private String pushVlan = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800158
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200159 @Option(name = "--setQueue", description = "Set Queue ID (for OpenFlow 1.0, " +
160 "also the port has to be specified, i.e., <port>/<queue>",
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200161 required = false, multiValued = false)
162 private String setQueue = null;
163
Ray Milkeyc24cde32015-03-10 18:20:18 -0700164 // Priorities
165 @Option(name = "-p", aliases = "--priority", description = "Priority",
166 required = false, multiValued = false)
167 private int priority = Intent.DEFAULT_INTENT_PRIORITY;
168
Michele Santuari05b882c2015-11-25 09:40:46 +0100169 // 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
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700187 /**
188 * Constructs a traffic selector based on the command line arguments
189 * presented to the command.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800190 * @return traffic selector
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700191 */
192 protected TrafficSelector buildTrafficSelector() {
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700193 IpPrefix srcIpPrefix = null;
194 IpPrefix dstIpPrefix = null;
Ray Milkeycaa450b2014-10-29 15:54:24 -0700195
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700196 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
197
198 if (!isNullOrEmpty(srcIpString)) {
199 srcIpPrefix = IpPrefix.valueOf(srcIpString);
200 if (srcIpPrefix.isIp4()) {
201 selectorBuilder.matchIPSrc(srcIpPrefix);
202 } else {
203 selectorBuilder.matchIPv6Src(srcIpPrefix);
204 }
205 }
206
207 if (!isNullOrEmpty(dstIpString)) {
208 dstIpPrefix = IpPrefix.valueOf(dstIpString);
209 if (dstIpPrefix.isIp4()) {
210 selectorBuilder.matchIPDst(dstIpPrefix);
211 } else {
212 selectorBuilder.matchIPv6Dst(dstIpPrefix);
213 }
214 }
215
216 if ((srcIpPrefix != null) && (dstIpPrefix != null) &&
217 (srcIpPrefix.version() != dstIpPrefix.version())) {
218 // ERROR: IP src/dst version mismatch
219 throw new IllegalArgumentException(
220 "IP source and destination version mismatch");
221 }
222
223 //
224 // Set the default EthType based on the IP version if the matching
225 // source or destination IP prefixes.
226 //
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700227 Short ethType = null;
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700228 if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) {
229 ethType = EthType.IPV6.value();
230 }
231 if ((dstIpPrefix != null) && dstIpPrefix.isIp6()) {
232 ethType = EthType.IPV6.value();
233 }
Ray Milkey460f4022014-11-05 15:41:43 -0800234 if (!isNullOrEmpty(ethTypeString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800235 ethType = EthType.parseFromString(ethTypeString);
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700236 }
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700237 if (ethType != null) {
238 selectorBuilder.matchEthType(ethType);
239 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200240 if (!isNullOrEmpty(vlanString)) {
241 selectorBuilder.matchVlanId(VlanId.vlanId(Short.parseShort(vlanString)));
242 }
Ray Milkey460f4022014-11-05 15:41:43 -0800243 if (!isNullOrEmpty(srcMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700244 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
245 }
246
Ray Milkey460f4022014-11-05 15:41:43 -0800247 if (!isNullOrEmpty(dstMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700248 selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString));
249 }
250
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800251 if (!isNullOrEmpty(ipProtoString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800252 short ipProtoShort = IpProtocol.parseFromString(ipProtoString);
253 selectorBuilder.matchIPProtocol((byte) ipProtoShort);
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800254 }
255
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800256 if (!isNullOrEmpty(fLabelString)) {
257 selectorBuilder.matchIPv6FlowLabel(Integer.parseInt(fLabelString));
258 }
259
260 if (!isNullOrEmpty(icmp6TypeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800261 byte icmp6Type = Icmp6Type.parseFromString(icmp6TypeString);
262 selectorBuilder.matchIcmpv6Type(icmp6Type);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800263 }
264
265 if (!isNullOrEmpty(icmp6CodeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800266 byte icmp6Code = Icmp6Code.parseFromString(icmp6CodeString);
267 selectorBuilder.matchIcmpv6Code(icmp6Code);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800268 }
269
270 if (!isNullOrEmpty(ndTargetString)) {
271 selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString));
272 }
273
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800274 if (!isNullOrEmpty(ndSllString)) {
275 selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800276 }
277
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800278 if (!isNullOrEmpty(ndTllString)) {
279 selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800280 }
281
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800282 if (!isNullOrEmpty(srcTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700283 selectorBuilder.matchTcpSrc(TpPort.tpPort(Integer.parseInt(srcTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800284 }
285
286 if (!isNullOrEmpty(dstTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700287 selectorBuilder.matchTcpDst(TpPort.tpPort(Integer.parseInt(dstTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800288 }
289
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800290 if (extHdrStringList != null) {
291 short extHdr = 0;
292 for (String extHdrString : extHdrStringList) {
293 extHdr = (short) (extHdr | ExtHeader.parseFromString(extHdrString));
294 }
295 selectorBuilder.matchIPv6ExthdrFlags(extHdr);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800296 }
297
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700298 return selectorBuilder.build();
299 }
300
Ray Milkey460f4022014-11-05 15:41:43 -0800301 /**
Jonathan Hart2c25e362014-11-17 18:14:19 -0800302 * Generates a traffic treatment for this intent based on command line
303 * arguments presented to the command.
304 *
305 * @return traffic treatment
306 */
307 protected TrafficTreatment buildTrafficTreatment() {
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800308 final TrafficTreatment.Builder treatmentBuilder = builder();
Brian O'Connor11ff8702015-04-29 19:37:15 -0700309 boolean emptyTreatment = true;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800310
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800311 if (!isNullOrEmpty(setEthSrcString)) {
312 treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700313 emptyTreatment = false;
Brian O'Connor4f5a98a2015-03-14 19:50:09 -0700314 }
315
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800316 if (!isNullOrEmpty(setEthDstString)) {
317 treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700318 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800319 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800320
321 if (!isNullOrEmpty(setIpSrcString)) {
322 treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700323 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800324 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800325
326 if (!isNullOrEmpty(setIpDstString)) {
327 treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700328 emptyTreatment = false;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800329 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200330 if (!isNullOrEmpty(setVlan)) {
331 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
332 emptyTreatment = false;
333 }
334 if (popVlan) {
335 treatmentBuilder.popVlan();
336 emptyTreatment = false;
337 }
338 if (!isNullOrEmpty(pushVlan)) {
339 treatmentBuilder.pushVlan();
340 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
341 emptyTreatment = false;
342 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200343 if (!isNullOrEmpty(setQueue)) {
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200344 // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
345 if (setQueue.contains("/")) {
346 String[] queueConfig = setQueue.split("/");
347 PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
348 long queueId = Long.parseLong(queueConfig[1]);
349 treatmentBuilder.setQueue(queueId, port);
350 } else {
351 treatmentBuilder.setQueue(Long.parseLong(setQueue));
352 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200353 emptyTreatment = false;
354 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800355
Brian O'Connor11ff8702015-04-29 19:37:15 -0700356 if (emptyTreatment) {
357 return DefaultTrafficTreatment.emptyTreatment();
358 } else {
359 return treatmentBuilder.build();
360 }
Jonathan Hart2c25e362014-11-17 18:14:19 -0800361 }
362
363 /**
Ray Milkey460f4022014-11-05 15:41:43 -0800364 * Builds the constraint list for this command based on the command line
365 * parameters.
366 *
367 * @return List of constraint objects describing the constraints requested
368 */
369 protected List<Constraint> buildConstraints() {
370 final List<Constraint> constraints = new LinkedList<>();
371
372 // Check for a bandwidth specification
373 if (!isNullOrEmpty(bandwidthString)) {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800374 Bandwidth bandwidth;
375 try {
376 bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
377 // when the string can't be parsed as long, then try to parse as double
378 } catch (NumberFormatException e) {
379 bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
380 }
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800381 constraints.add(new BandwidthConstraint(bandwidth));
Ray Milkey460f4022014-11-05 15:41:43 -0800382 }
383
384 // Check for a lambda specification
Sho SHIMIZU792c26b2015-06-08 19:08:32 -0700385 if (lambda) {
386 constraints.add(new LambdaConstraint(null));
Ray Milkey460f4022014-11-05 15:41:43 -0800387 }
Sho SHIMIZU792c26b2015-06-08 19:08:32 -0700388 constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL));
389
Michele Santuari05b882c2015-11-25 09:40:46 +0100390 // Check for partial failure specification
Jonathan Hart96c5a4a2015-07-31 14:23:33 -0700391 if (partial) {
392 constraints.add(new PartialFailureConstraint());
393 }
394
Michele Santuari05b882c2015-11-25 09:40:46 +0100395 // Check for encapsulation specification
396 if (!isNullOrEmpty(encapsulationString)) {
397 final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
398 constraints.add(new EncapsulationConstraint(encapType));
399 }
400
Ray Milkey460f4022014-11-05 15:41:43 -0800401 return constraints;
402 }
Ray Milkey5b3717e2015-02-05 11:44:08 -0800403
Ray Milkey95c50872015-04-14 14:32:31 -0700404 @Override
405 protected ApplicationId appId() {
406 ApplicationId appIdForIntent;
407 if (appId == null) {
408 appIdForIntent = super.appId();
409 } else {
410 CoreService service = get(CoreService.class);
411 appIdForIntent = service.getAppId(appId);
412 }
413 return appIdForIntent;
414 }
415
Ray Milkey5b3717e2015-02-05 11:44:08 -0800416 /**
417 * Creates a key for an intent based on command line arguments. If a key
418 * has been specified, it is returned. If no key is specified, null
419 * is returned.
420 *
421 * @return intent key if specified, null otherwise
422 */
423 protected Key key() {
424 Key key = null;
Ray Milkey95c50872015-04-14 14:32:31 -0700425 ApplicationId appIdForIntent;
426
Ray Milkey5b3717e2015-02-05 11:44:08 -0800427 if (intentKey != null) {
428 key = Key.of(intentKey, appId());
429 }
430 return key;
431 }
Ray Milkeyc24cde32015-03-10 18:20:18 -0700432
433 /**
434 * Gets the priority to use for the intent.
435 *
436 * @return priority
437 */
438 protected int priority() {
439 return priority;
440 }
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700441}