blob: 7ebc3be846d169956a12d3e8f7cbed2b6cd40cec [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;
Michele Santuari05b882c2015-11-25 09:40:46 +010040import org.onosproject.net.intent.constraint.EncapsulationConstraint;
jaegonkim7e876632017-01-25 06:01:49 +090041import org.onosproject.net.intent.constraint.HashedPathSelectionConstraint;
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070042import org.onosproject.net.intent.constraint.PartialFailureConstraint;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070043
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080044import java.util.LinkedList;
45import java.util.List;
46
47import static com.google.common.base.Strings.isNullOrEmpty;
48import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
49
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070050/**
51 * Base class for command line operations for connectivity based intents.
52 */
53public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
54
Jonathan Hart2c25e362014-11-17 18:14:19 -080055 // Selectors
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070056 @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address",
57 required = false, multiValued = false)
58 private String srcMacString = null;
59
60 @Option(name = "-d", aliases = "--ethDst", description = "Destination MAC Address",
61 required = false, multiValued = false)
62 private String dstMacString = null;
63
64 @Option(name = "-t", aliases = "--ethType", description = "Ethernet Type",
65 required = false, multiValued = false)
Ray Milkey04c78322015-01-21 14:57:58 -080066 private String ethTypeString = null;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070067
Dusan Pajin6b887c92015-07-01 18:32:49 +020068 @Option(name = "-v", aliases = "--vlan", description = "VLAN ID",
69 required = false, multiValued = false)
70 private String vlanString = null;
71
Jonathan Hart5f7097e2014-11-11 11:50:28 -080072 @Option(name = "--ipProto", description = "IP Protocol",
73 required = false, multiValued = false)
74 private String ipProtoString = null;
75
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -070076 @Option(name = "--ipSrc", description = "Source IP Prefix",
Jonathan Hart5f7097e2014-11-11 11:50:28 -080077 required = false, multiValued = false)
78 private String srcIpString = null;
79
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -070080 @Option(name = "--ipDst", description = "Destination IP Prefix",
Jonathan Hart5f7097e2014-11-11 11:50:28 -080081 required = false, multiValued = false)
82 private String dstIpString = null;
83
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +080084 @Option(name = "--fLabel", description = "IPv6 Flow Label",
85 required = false, multiValued = false)
86 private String fLabelString = null;
87
88 @Option(name = "--icmp6Type", description = "ICMPv6 Type",
89 required = false, multiValued = false)
90 private String icmp6TypeString = null;
91
92 @Option(name = "--icmp6Code", description = "ICMPv6 Code",
93 required = false, multiValued = false)
94 private String icmp6CodeString = null;
95
96 @Option(name = "--ndTarget", description = "IPv6 Neighbor Discovery Target Address",
97 required = false, multiValued = false)
98 private String ndTargetString = null;
99
100 @Option(name = "--ndSLL", description = "IPv6 Neighbor Discovery Source Link-Layer",
101 required = false, multiValued = false)
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800102 private String ndSllString = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800103
104 @Option(name = "--ndTLL", description = "IPv6 Neighbor Discovery Target Link-Layer",
105 required = false, multiValued = false)
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800106 private String ndTllString = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800107
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800108 @Option(name = "--tcpSrc", description = "Source TCP Port",
109 required = false, multiValued = false)
110 private String srcTcpString = null;
111
112 @Option(name = "--tcpDst", description = "Destination TCP Port",
113 required = false, multiValued = false)
114 private String dstTcpString = null;
115
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800116 @Option(name = "--extHdr", description = "IPv6 Extension Header Pseudo-field",
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800117 required = false, multiValued = true)
118 private List<String> extHdrStringList = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800119
Ray Milkey95c50872015-04-14 14:32:31 -0700120 @Option(name = "-a", aliases = "--appId", description = "Application Id",
121 required = false, multiValued = false)
122 private String appId = null;
123
Ray Milkey5b3717e2015-02-05 11:44:08 -0800124 @Option(name = "-k", aliases = "--key", description = "Intent Key",
125 required = false, multiValued = false)
126 private String intentKey = null;
127
Jonathan Hart2c25e362014-11-17 18:14:19 -0800128
129 // Treatments
130 @Option(name = "--setEthSrc", description = "Rewrite Source MAC Address",
131 required = false, multiValued = false)
132 private String setEthSrcString = null;
133
134 @Option(name = "--setEthDst", description = "Rewrite Destination MAC Address",
135 required = false, multiValued = false)
136 private String setEthDstString = null;
137
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800138 @Option(name = "--setIpSrc", description = "Rewrite Source IP Address",
139 required = false, multiValued = false)
140 private String setIpSrcString = null;
141
142 @Option(name = "--setIpDst", description = "Rewrite Destination IP Address",
143 required = false, multiValued = false)
144 private String setIpDstString = null;
145
Dusan Pajin6b887c92015-07-01 18:32:49 +0200146 @Option(name = "--setVlan", description = "Rewrite VLAN ID",
147 required = false, multiValued = false)
148 private String setVlan = null;
149
150 @Option(name = "--popVlan", description = "Pop VLAN Tag",
151 required = false, multiValued = false)
152 private boolean popVlan = false;
153
154 @Option(name = "--pushVlan", description = "Push VLAN ID",
155 required = false, multiValued = false)
156 private String pushVlan = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800157
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200158 @Option(name = "--setQueue", description = "Set Queue ID (for OpenFlow 1.0, " +
159 "also the port has to be specified, i.e., <port>/<queue>",
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200160 required = false, multiValued = false)
161 private String setQueue = null;
162
Ray Milkeyc24cde32015-03-10 18:20:18 -0700163 // Priorities
164 @Option(name = "-p", aliases = "--priority", description = "Priority",
165 required = false, multiValued = false)
166 private int priority = Intent.DEFAULT_INTENT_PRIORITY;
167
Michele Santuari05b882c2015-11-25 09:40:46 +0100168 // Constraints
169 @Option(name = "-b", aliases = "--bandwidth", description = "Bandwidth",
170 required = false, multiValued = false)
171 private String bandwidthString = null;
172
Michele Santuari05b882c2015-11-25 09:40:46 +0100173 @Option(name = "--partial", description = "Allow partial installation",
174 required = false, multiValued = false)
175 private boolean partial = false;
176
177 @Option(name = "-e", aliases = "--encapsulation", description = "Encapsulation type",
178 required = false, multiValued = false)
179 private String encapsulationString = null;
180
jaegonkim7e876632017-01-25 06:01:49 +0900181 @Option(name = "--hashed", description = "Hashed path selection",
182 required = false, multiValued = false)
183 private boolean hashedPathSelection = false;
184
Luca Prete670ac5d2017-02-03 15:55:43 -0800185 // Resource Group
186 @Option(name = "-r", aliases = "--resourceGroup", description = "Resource Group Id",
187 required = false, multiValued = false)
188 private String resourceGroupId = null;
189
Michele Santuari05b882c2015-11-25 09:40:46 +0100190
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700191 /**
192 * Constructs a traffic selector based on the command line arguments
193 * presented to the command.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800194 * @return traffic selector
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700195 */
196 protected TrafficSelector buildTrafficSelector() {
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700197 IpPrefix srcIpPrefix = null;
198 IpPrefix dstIpPrefix = null;
Ray Milkeycaa450b2014-10-29 15:54:24 -0700199
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700200 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
201
202 if (!isNullOrEmpty(srcIpString)) {
203 srcIpPrefix = IpPrefix.valueOf(srcIpString);
204 if (srcIpPrefix.isIp4()) {
205 selectorBuilder.matchIPSrc(srcIpPrefix);
206 } else {
207 selectorBuilder.matchIPv6Src(srcIpPrefix);
208 }
209 }
210
211 if (!isNullOrEmpty(dstIpString)) {
212 dstIpPrefix = IpPrefix.valueOf(dstIpString);
213 if (dstIpPrefix.isIp4()) {
214 selectorBuilder.matchIPDst(dstIpPrefix);
215 } else {
216 selectorBuilder.matchIPv6Dst(dstIpPrefix);
217 }
218 }
219
220 if ((srcIpPrefix != null) && (dstIpPrefix != null) &&
221 (srcIpPrefix.version() != dstIpPrefix.version())) {
222 // ERROR: IP src/dst version mismatch
223 throw new IllegalArgumentException(
224 "IP source and destination version mismatch");
225 }
226
227 //
228 // Set the default EthType based on the IP version if the matching
229 // source or destination IP prefixes.
230 //
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700231 Short ethType = null;
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700232 if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) {
233 ethType = EthType.IPV6.value();
234 }
235 if ((dstIpPrefix != null) && dstIpPrefix.isIp6()) {
236 ethType = EthType.IPV6.value();
237 }
Ray Milkey460f4022014-11-05 15:41:43 -0800238 if (!isNullOrEmpty(ethTypeString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800239 ethType = EthType.parseFromString(ethTypeString);
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700240 }
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700241 if (ethType != null) {
242 selectorBuilder.matchEthType(ethType);
243 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200244 if (!isNullOrEmpty(vlanString)) {
245 selectorBuilder.matchVlanId(VlanId.vlanId(Short.parseShort(vlanString)));
246 }
Ray Milkey460f4022014-11-05 15:41:43 -0800247 if (!isNullOrEmpty(srcMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700248 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
249 }
250
Ray Milkey460f4022014-11-05 15:41:43 -0800251 if (!isNullOrEmpty(dstMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700252 selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString));
253 }
254
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800255 if (!isNullOrEmpty(ipProtoString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800256 short ipProtoShort = IpProtocol.parseFromString(ipProtoString);
257 selectorBuilder.matchIPProtocol((byte) ipProtoShort);
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800258 }
259
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800260 if (!isNullOrEmpty(fLabelString)) {
261 selectorBuilder.matchIPv6FlowLabel(Integer.parseInt(fLabelString));
262 }
263
264 if (!isNullOrEmpty(icmp6TypeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800265 byte icmp6Type = Icmp6Type.parseFromString(icmp6TypeString);
266 selectorBuilder.matchIcmpv6Type(icmp6Type);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800267 }
268
269 if (!isNullOrEmpty(icmp6CodeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800270 byte icmp6Code = Icmp6Code.parseFromString(icmp6CodeString);
271 selectorBuilder.matchIcmpv6Code(icmp6Code);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800272 }
273
274 if (!isNullOrEmpty(ndTargetString)) {
275 selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString));
276 }
277
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800278 if (!isNullOrEmpty(ndSllString)) {
279 selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800280 }
281
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800282 if (!isNullOrEmpty(ndTllString)) {
283 selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800284 }
285
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800286 if (!isNullOrEmpty(srcTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700287 selectorBuilder.matchTcpSrc(TpPort.tpPort(Integer.parseInt(srcTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800288 }
289
290 if (!isNullOrEmpty(dstTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700291 selectorBuilder.matchTcpDst(TpPort.tpPort(Integer.parseInt(dstTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800292 }
293
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800294 if (extHdrStringList != null) {
295 short extHdr = 0;
296 for (String extHdrString : extHdrStringList) {
297 extHdr = (short) (extHdr | ExtHeader.parseFromString(extHdrString));
298 }
299 selectorBuilder.matchIPv6ExthdrFlags(extHdr);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800300 }
301
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700302 return selectorBuilder.build();
303 }
304
Ray Milkey460f4022014-11-05 15:41:43 -0800305 /**
Jonathan Hart2c25e362014-11-17 18:14:19 -0800306 * Generates a traffic treatment for this intent based on command line
307 * arguments presented to the command.
308 *
309 * @return traffic treatment
310 */
311 protected TrafficTreatment buildTrafficTreatment() {
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800312 final TrafficTreatment.Builder treatmentBuilder = builder();
Brian O'Connor11ff8702015-04-29 19:37:15 -0700313 boolean emptyTreatment = true;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800314
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800315 if (!isNullOrEmpty(setEthSrcString)) {
316 treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700317 emptyTreatment = false;
Brian O'Connor4f5a98a2015-03-14 19:50:09 -0700318 }
319
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800320 if (!isNullOrEmpty(setEthDstString)) {
321 treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700322 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800323 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800324
325 if (!isNullOrEmpty(setIpSrcString)) {
326 treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
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(setIpDstString)) {
Charles Chand4489882016-04-05 11:38:09 -0700331 treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700332 emptyTreatment = false;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800333 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200334 if (!isNullOrEmpty(setVlan)) {
335 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
336 emptyTreatment = false;
337 }
338 if (popVlan) {
339 treatmentBuilder.popVlan();
340 emptyTreatment = false;
341 }
342 if (!isNullOrEmpty(pushVlan)) {
343 treatmentBuilder.pushVlan();
344 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
345 emptyTreatment = false;
346 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200347 if (!isNullOrEmpty(setQueue)) {
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200348 // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
349 if (setQueue.contains("/")) {
350 String[] queueConfig = setQueue.split("/");
351 PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
352 long queueId = Long.parseLong(queueConfig[1]);
353 treatmentBuilder.setQueue(queueId, port);
354 } else {
355 treatmentBuilder.setQueue(Long.parseLong(setQueue));
356 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200357 emptyTreatment = false;
358 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800359
Brian O'Connor11ff8702015-04-29 19:37:15 -0700360 if (emptyTreatment) {
361 return DefaultTrafficTreatment.emptyTreatment();
362 } else {
363 return treatmentBuilder.build();
364 }
Jonathan Hart2c25e362014-11-17 18:14:19 -0800365 }
366
367 /**
Ray Milkey460f4022014-11-05 15:41:43 -0800368 * Builds the constraint list for this command based on the command line
369 * parameters.
370 *
371 * @return List of constraint objects describing the constraints requested
372 */
373 protected List<Constraint> buildConstraints() {
374 final List<Constraint> constraints = new LinkedList<>();
375
376 // Check for a bandwidth specification
377 if (!isNullOrEmpty(bandwidthString)) {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800378 Bandwidth bandwidth;
379 try {
380 bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
381 // when the string can't be parsed as long, then try to parse as double
382 } catch (NumberFormatException e) {
383 bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
384 }
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800385 constraints.add(new BandwidthConstraint(bandwidth));
Ray Milkey460f4022014-11-05 15:41:43 -0800386 }
387
Michele Santuari05b882c2015-11-25 09:40:46 +0100388 // Check for partial failure specification
Jonathan Hart96c5a4a2015-07-31 14:23:33 -0700389 if (partial) {
390 constraints.add(new PartialFailureConstraint());
391 }
392
Michele Santuari05b882c2015-11-25 09:40:46 +0100393 // Check for encapsulation specification
394 if (!isNullOrEmpty(encapsulationString)) {
395 final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
396 constraints.add(new EncapsulationConstraint(encapType));
397 }
398
jaegonkim7e876632017-01-25 06:01:49 +0900399 // Check for hashed path selection
400 if (hashedPathSelection) {
401 constraints.add(new HashedPathSelectionConstraint());
402 }
Ray Milkey460f4022014-11-05 15:41:43 -0800403 return constraints;
404 }
Ray Milkey5b3717e2015-02-05 11:44:08 -0800405
Ray Milkey95c50872015-04-14 14:32:31 -0700406 @Override
407 protected ApplicationId appId() {
408 ApplicationId appIdForIntent;
409 if (appId == null) {
410 appIdForIntent = super.appId();
411 } else {
412 CoreService service = get(CoreService.class);
413 appIdForIntent = service.getAppId(appId);
414 }
415 return appIdForIntent;
416 }
417
Luca Prete670ac5d2017-02-03 15:55:43 -0800418 protected ResourceGroup resourceGroup() {
419 if (resourceGroupId != null) {
420 if (resourceGroupId.toLowerCase().startsWith("0x")) {
421 return ResourceGroup.of(Long.parseUnsignedLong(resourceGroupId.substring(2), 16));
422 } else {
423 return ResourceGroup.of(Long.parseUnsignedLong(resourceGroupId));
424 }
425 } else {
426 return null;
427 }
428 }
429
Ray Milkey5b3717e2015-02-05 11:44:08 -0800430 /**
431 * Creates a key for an intent based on command line arguments. If a key
432 * has been specified, it is returned. If no key is specified, null
433 * is returned.
434 *
435 * @return intent key if specified, null otherwise
436 */
437 protected Key key() {
438 Key key = null;
Ray Milkey95c50872015-04-14 14:32:31 -0700439 ApplicationId appIdForIntent;
440
Ray Milkey5b3717e2015-02-05 11:44:08 -0800441 if (intentKey != null) {
442 key = Key.of(intentKey, appId());
443 }
444 return key;
445 }
Ray Milkeyc24cde32015-03-10 18:20:18 -0700446
447 /**
448 * Gets the priority to use for the intent.
449 *
450 * @return priority
451 */
452 protected int priority() {
453 return priority;
454 }
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700455}