blob: aa3c8107d899527f3d0959f3df246f54d70fc6f8 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020030import org.onosproject.net.PortNumber;
Luca Prete670ac5d2017-02-03 15:55:43 -080031import org.onosproject.net.ResourceGroup;
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;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020040import org.onosproject.net.intent.constraint.DomainConstraint;
Michele Santuari05b882c2015-11-25 09:40:46 +010041import org.onosproject.net.intent.constraint.EncapsulationConstraint;
jaegonkim7e876632017-01-25 06:01:49 +090042import org.onosproject.net.intent.constraint.HashedPathSelectionConstraint;
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
Michele Santuari05b882c2015-11-25 09:40:46 +0100174 @Option(name = "--partial", description = "Allow partial installation",
175 required = false, multiValued = false)
176 private boolean partial = false;
177
178 @Option(name = "-e", aliases = "--encapsulation", description = "Encapsulation type",
179 required = false, multiValued = false)
180 private String encapsulationString = null;
181
jaegonkim7e876632017-01-25 06:01:49 +0900182 @Option(name = "--hashed", description = "Hashed path selection",
183 required = false, multiValued = false)
184 private boolean hashedPathSelection = false;
185
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200186 @Option(name = "--domains", description = "Allow domain delegation",
187 required = false, multiValued = false)
188 private boolean domains = false;
189
Luca Prete670ac5d2017-02-03 15:55:43 -0800190 // Resource Group
191 @Option(name = "-r", aliases = "--resourceGroup", description = "Resource Group Id",
192 required = false, multiValued = false)
193 private String resourceGroupId = null;
194
Michele Santuari05b882c2015-11-25 09:40:46 +0100195
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700196 /**
197 * Constructs a traffic selector based on the command line arguments
198 * presented to the command.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800199 * @return traffic selector
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700200 */
201 protected TrafficSelector buildTrafficSelector() {
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700202 IpPrefix srcIpPrefix = null;
203 IpPrefix dstIpPrefix = null;
Ray Milkeycaa450b2014-10-29 15:54:24 -0700204
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700205 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
206
207 if (!isNullOrEmpty(srcIpString)) {
208 srcIpPrefix = IpPrefix.valueOf(srcIpString);
209 if (srcIpPrefix.isIp4()) {
210 selectorBuilder.matchIPSrc(srcIpPrefix);
211 } else {
212 selectorBuilder.matchIPv6Src(srcIpPrefix);
213 }
214 }
215
216 if (!isNullOrEmpty(dstIpString)) {
217 dstIpPrefix = IpPrefix.valueOf(dstIpString);
218 if (dstIpPrefix.isIp4()) {
219 selectorBuilder.matchIPDst(dstIpPrefix);
220 } else {
221 selectorBuilder.matchIPv6Dst(dstIpPrefix);
222 }
223 }
224
225 if ((srcIpPrefix != null) && (dstIpPrefix != null) &&
226 (srcIpPrefix.version() != dstIpPrefix.version())) {
227 // ERROR: IP src/dst version mismatch
228 throw new IllegalArgumentException(
229 "IP source and destination version mismatch");
230 }
231
232 //
233 // Set the default EthType based on the IP version if the matching
234 // source or destination IP prefixes.
235 //
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700236 Short ethType = null;
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700237 if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) {
238 ethType = EthType.IPV6.value();
239 }
240 if ((dstIpPrefix != null) && dstIpPrefix.isIp6()) {
241 ethType = EthType.IPV6.value();
242 }
Ray Milkey460f4022014-11-05 15:41:43 -0800243 if (!isNullOrEmpty(ethTypeString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800244 ethType = EthType.parseFromString(ethTypeString);
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700245 }
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700246 if (ethType != null) {
247 selectorBuilder.matchEthType(ethType);
248 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200249 if (!isNullOrEmpty(vlanString)) {
250 selectorBuilder.matchVlanId(VlanId.vlanId(Short.parseShort(vlanString)));
251 }
Ray Milkey460f4022014-11-05 15:41:43 -0800252 if (!isNullOrEmpty(srcMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700253 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
254 }
255
Ray Milkey460f4022014-11-05 15:41:43 -0800256 if (!isNullOrEmpty(dstMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700257 selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString));
258 }
259
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800260 if (!isNullOrEmpty(ipProtoString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800261 short ipProtoShort = IpProtocol.parseFromString(ipProtoString);
262 selectorBuilder.matchIPProtocol((byte) ipProtoShort);
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800263 }
264
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800265 if (!isNullOrEmpty(fLabelString)) {
266 selectorBuilder.matchIPv6FlowLabel(Integer.parseInt(fLabelString));
267 }
268
269 if (!isNullOrEmpty(icmp6TypeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800270 byte icmp6Type = Icmp6Type.parseFromString(icmp6TypeString);
271 selectorBuilder.matchIcmpv6Type(icmp6Type);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800272 }
273
274 if (!isNullOrEmpty(icmp6CodeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800275 byte icmp6Code = Icmp6Code.parseFromString(icmp6CodeString);
276 selectorBuilder.matchIcmpv6Code(icmp6Code);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800277 }
278
279 if (!isNullOrEmpty(ndTargetString)) {
280 selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString));
281 }
282
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800283 if (!isNullOrEmpty(ndSllString)) {
284 selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800285 }
286
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800287 if (!isNullOrEmpty(ndTllString)) {
288 selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800289 }
290
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800291 if (!isNullOrEmpty(srcTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700292 selectorBuilder.matchTcpSrc(TpPort.tpPort(Integer.parseInt(srcTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800293 }
294
295 if (!isNullOrEmpty(dstTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700296 selectorBuilder.matchTcpDst(TpPort.tpPort(Integer.parseInt(dstTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800297 }
298
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800299 if (extHdrStringList != null) {
300 short extHdr = 0;
301 for (String extHdrString : extHdrStringList) {
302 extHdr = (short) (extHdr | ExtHeader.parseFromString(extHdrString));
303 }
304 selectorBuilder.matchIPv6ExthdrFlags(extHdr);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800305 }
306
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700307 return selectorBuilder.build();
308 }
309
Ray Milkey460f4022014-11-05 15:41:43 -0800310 /**
Jonathan Hart2c25e362014-11-17 18:14:19 -0800311 * Generates a traffic treatment for this intent based on command line
312 * arguments presented to the command.
313 *
314 * @return traffic treatment
315 */
316 protected TrafficTreatment buildTrafficTreatment() {
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800317 final TrafficTreatment.Builder treatmentBuilder = builder();
Brian O'Connor11ff8702015-04-29 19:37:15 -0700318 boolean emptyTreatment = true;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800319
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800320 if (!isNullOrEmpty(setEthSrcString)) {
321 treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700322 emptyTreatment = false;
Brian O'Connor4f5a98a2015-03-14 19:50:09 -0700323 }
324
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800325 if (!isNullOrEmpty(setEthDstString)) {
326 treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700327 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800328 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800329
330 if (!isNullOrEmpty(setIpSrcString)) {
331 treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700332 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800333 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800334
335 if (!isNullOrEmpty(setIpDstString)) {
Charles Chand4489882016-04-05 11:38:09 -0700336 treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700337 emptyTreatment = false;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800338 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200339 if (!isNullOrEmpty(setVlan)) {
340 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
341 emptyTreatment = false;
342 }
343 if (popVlan) {
344 treatmentBuilder.popVlan();
345 emptyTreatment = false;
346 }
347 if (!isNullOrEmpty(pushVlan)) {
348 treatmentBuilder.pushVlan();
349 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
350 emptyTreatment = false;
351 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200352 if (!isNullOrEmpty(setQueue)) {
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200353 // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
354 if (setQueue.contains("/")) {
355 String[] queueConfig = setQueue.split("/");
356 PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
357 long queueId = Long.parseLong(queueConfig[1]);
358 treatmentBuilder.setQueue(queueId, port);
359 } else {
360 treatmentBuilder.setQueue(Long.parseLong(setQueue));
361 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200362 emptyTreatment = false;
363 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800364
Brian O'Connor11ff8702015-04-29 19:37:15 -0700365 if (emptyTreatment) {
366 return DefaultTrafficTreatment.emptyTreatment();
367 } else {
368 return treatmentBuilder.build();
369 }
Jonathan Hart2c25e362014-11-17 18:14:19 -0800370 }
371
372 /**
Ray Milkey460f4022014-11-05 15:41:43 -0800373 * Builds the constraint list for this command based on the command line
374 * parameters.
375 *
376 * @return List of constraint objects describing the constraints requested
377 */
378 protected List<Constraint> buildConstraints() {
379 final List<Constraint> constraints = new LinkedList<>();
380
381 // Check for a bandwidth specification
382 if (!isNullOrEmpty(bandwidthString)) {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800383 Bandwidth bandwidth;
384 try {
385 bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
386 // when the string can't be parsed as long, then try to parse as double
387 } catch (NumberFormatException e) {
388 bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
389 }
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800390 constraints.add(new BandwidthConstraint(bandwidth));
Ray Milkey460f4022014-11-05 15:41:43 -0800391 }
392
Michele Santuari05b882c2015-11-25 09:40:46 +0100393 // Check for partial failure specification
Jonathan Hart96c5a4a2015-07-31 14:23:33 -0700394 if (partial) {
395 constraints.add(new PartialFailureConstraint());
396 }
397
Michele Santuari05b882c2015-11-25 09:40:46 +0100398 // Check for encapsulation specification
399 if (!isNullOrEmpty(encapsulationString)) {
400 final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
401 constraints.add(new EncapsulationConstraint(encapType));
402 }
403
jaegonkim7e876632017-01-25 06:01:49 +0900404 // Check for hashed path selection
405 if (hashedPathSelection) {
406 constraints.add(new HashedPathSelectionConstraint());
407 }
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200408
409 // Check for domain processing
410 if (domains) {
411 constraints.add(DomainConstraint.domain());
412 }
Ray Milkey460f4022014-11-05 15:41:43 -0800413 return constraints;
414 }
Ray Milkey5b3717e2015-02-05 11:44:08 -0800415
Ray Milkey95c50872015-04-14 14:32:31 -0700416 @Override
417 protected ApplicationId appId() {
418 ApplicationId appIdForIntent;
419 if (appId == null) {
420 appIdForIntent = super.appId();
421 } else {
422 CoreService service = get(CoreService.class);
423 appIdForIntent = service.getAppId(appId);
424 }
425 return appIdForIntent;
426 }
427
Luca Prete670ac5d2017-02-03 15:55:43 -0800428 protected ResourceGroup resourceGroup() {
429 if (resourceGroupId != null) {
430 if (resourceGroupId.toLowerCase().startsWith("0x")) {
431 return ResourceGroup.of(Long.parseUnsignedLong(resourceGroupId.substring(2), 16));
432 } else {
433 return ResourceGroup.of(Long.parseUnsignedLong(resourceGroupId));
434 }
435 } else {
436 return null;
437 }
438 }
439
Ray Milkey5b3717e2015-02-05 11:44:08 -0800440 /**
441 * Creates a key for an intent based on command line arguments. If a key
442 * has been specified, it is returned. If no key is specified, null
443 * is returned.
444 *
445 * @return intent key if specified, null otherwise
446 */
447 protected Key key() {
448 Key key = null;
Ray Milkey95c50872015-04-14 14:32:31 -0700449
Ray Milkey5b3717e2015-02-05 11:44:08 -0800450 if (intentKey != null) {
451 key = Key.of(intentKey, appId());
452 }
453 return key;
454 }
Ray Milkeyc24cde32015-03-10 18:20:18 -0700455
456 /**
457 * Gets the priority to use for the intent.
458 *
459 * @return priority
460 */
461 protected int priority() {
462 return priority;
463 }
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700464}