blob: 9cfa346ca8afc29527693e29e2c3a41d362006c5 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.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;
dingdamud3a0b212017-05-16 11:18:27 +020043import org.onosproject.net.intent.constraint.LatencyConstraint;
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070044import org.onosproject.net.intent.constraint.PartialFailureConstraint;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070045
dingdamud3a0b212017-05-16 11:18:27 +020046import java.time.Duration;
47import java.time.temporal.ChronoUnit;
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080048import java.util.LinkedList;
49import java.util.List;
50
51import static com.google.common.base.Strings.isNullOrEmpty;
52import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
53
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070054/**
55 * Base class for command line operations for connectivity based intents.
56 */
57public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
58
Jonathan Hart2c25e362014-11-17 18:14:19 -080059 // Selectors
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070060 @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address",
61 required = false, multiValued = false)
62 private String srcMacString = null;
63
64 @Option(name = "-d", aliases = "--ethDst", description = "Destination MAC Address",
65 required = false, multiValued = false)
66 private String dstMacString = null;
67
68 @Option(name = "-t", aliases = "--ethType", description = "Ethernet Type",
69 required = false, multiValued = false)
Ray Milkey04c78322015-01-21 14:57:58 -080070 private String ethTypeString = null;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070071
Dusan Pajin6b887c92015-07-01 18:32:49 +020072 @Option(name = "-v", aliases = "--vlan", description = "VLAN ID",
73 required = false, multiValued = false)
74 private String vlanString = null;
75
Jonathan Hart5f7097e2014-11-11 11:50:28 -080076 @Option(name = "--ipProto", description = "IP Protocol",
77 required = false, multiValued = false)
78 private String ipProtoString = null;
79
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -070080 @Option(name = "--ipSrc", description = "Source IP Prefix",
Jonathan Hart5f7097e2014-11-11 11:50:28 -080081 required = false, multiValued = false)
82 private String srcIpString = null;
83
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -070084 @Option(name = "--ipDst", description = "Destination IP Prefix",
Jonathan Hart5f7097e2014-11-11 11:50:28 -080085 required = false, multiValued = false)
86 private String dstIpString = null;
87
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +080088 @Option(name = "--fLabel", description = "IPv6 Flow Label",
89 required = false, multiValued = false)
90 private String fLabelString = null;
91
92 @Option(name = "--icmp6Type", description = "ICMPv6 Type",
93 required = false, multiValued = false)
94 private String icmp6TypeString = null;
95
96 @Option(name = "--icmp6Code", description = "ICMPv6 Code",
97 required = false, multiValued = false)
98 private String icmp6CodeString = null;
99
100 @Option(name = "--ndTarget", description = "IPv6 Neighbor Discovery Target Address",
101 required = false, multiValued = false)
102 private String ndTargetString = null;
103
104 @Option(name = "--ndSLL", description = "IPv6 Neighbor Discovery Source Link-Layer",
105 required = false, multiValued = false)
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800106 private String ndSllString = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800107
108 @Option(name = "--ndTLL", description = "IPv6 Neighbor Discovery Target Link-Layer",
109 required = false, multiValued = false)
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800110 private String ndTllString = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800111
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800112 @Option(name = "--tcpSrc", description = "Source TCP Port",
113 required = false, multiValued = false)
114 private String srcTcpString = null;
115
116 @Option(name = "--tcpDst", description = "Destination TCP Port",
117 required = false, multiValued = false)
118 private String dstTcpString = null;
119
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800120 @Option(name = "--extHdr", description = "IPv6 Extension Header Pseudo-field",
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800121 required = false, multiValued = true)
122 private List<String> extHdrStringList = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800123
Ray Milkey95c50872015-04-14 14:32:31 -0700124 @Option(name = "-a", aliases = "--appId", description = "Application Id",
125 required = false, multiValued = false)
126 private String appId = null;
127
Ray Milkey5b3717e2015-02-05 11:44:08 -0800128 @Option(name = "-k", aliases = "--key", description = "Intent Key",
129 required = false, multiValued = false)
130 private String intentKey = null;
131
Jonathan Hart2c25e362014-11-17 18:14:19 -0800132
133 // Treatments
134 @Option(name = "--setEthSrc", description = "Rewrite Source MAC Address",
135 required = false, multiValued = false)
136 private String setEthSrcString = null;
137
138 @Option(name = "--setEthDst", description = "Rewrite Destination MAC Address",
139 required = false, multiValued = false)
140 private String setEthDstString = null;
141
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800142 @Option(name = "--setIpSrc", description = "Rewrite Source IP Address",
143 required = false, multiValued = false)
144 private String setIpSrcString = null;
145
146 @Option(name = "--setIpDst", description = "Rewrite Destination IP Address",
147 required = false, multiValued = false)
148 private String setIpDstString = null;
149
Dusan Pajin6b887c92015-07-01 18:32:49 +0200150 @Option(name = "--setVlan", description = "Rewrite VLAN ID",
151 required = false, multiValued = false)
152 private String setVlan = null;
153
154 @Option(name = "--popVlan", description = "Pop VLAN Tag",
155 required = false, multiValued = false)
156 private boolean popVlan = false;
157
158 @Option(name = "--pushVlan", description = "Push VLAN ID",
159 required = false, multiValued = false)
160 private String pushVlan = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800161
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200162 @Option(name = "--setQueue", description = "Set Queue ID (for OpenFlow 1.0, " +
163 "also the port has to be specified, i.e., <port>/<queue>",
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200164 required = false, multiValued = false)
165 private String setQueue = null;
166
Ray Milkeyc24cde32015-03-10 18:20:18 -0700167 // Priorities
168 @Option(name = "-p", aliases = "--priority", description = "Priority",
169 required = false, multiValued = false)
170 private int priority = Intent.DEFAULT_INTENT_PRIORITY;
171
Michele Santuari05b882c2015-11-25 09:40:46 +0100172 // Constraints
173 @Option(name = "-b", aliases = "--bandwidth", description = "Bandwidth",
174 required = false, multiValued = false)
175 private String bandwidthString = null;
176
Michele Santuari05b882c2015-11-25 09:40:46 +0100177 @Option(name = "--partial", description = "Allow partial installation",
178 required = false, multiValued = false)
179 private boolean partial = false;
180
181 @Option(name = "-e", aliases = "--encapsulation", description = "Encapsulation type",
182 required = false, multiValued = false)
183 private String encapsulationString = null;
184
jaegonkim7e876632017-01-25 06:01:49 +0900185 @Option(name = "--hashed", description = "Hashed path selection",
186 required = false, multiValued = false)
187 private boolean hashedPathSelection = false;
188
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200189 @Option(name = "--domains", description = "Allow domain delegation",
190 required = false, multiValued = false)
191 private boolean domains = false;
192
dingdamud3a0b212017-05-16 11:18:27 +0200193 @Option(name = "-l", aliases = "--latency",
194 description = "Max latency in nanoseconds tolerated by the intent", required = false,
195 multiValued = false)
196 String latConstraint = null;
197
Luca Prete670ac5d2017-02-03 15:55:43 -0800198 // Resource Group
199 @Option(name = "-r", aliases = "--resourceGroup", description = "Resource Group Id",
200 required = false, multiValued = false)
201 private String resourceGroupId = null;
202
Michele Santuari05b882c2015-11-25 09:40:46 +0100203
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700204 /**
205 * Constructs a traffic selector based on the command line arguments
206 * presented to the command.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800207 * @return traffic selector
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700208 */
209 protected TrafficSelector buildTrafficSelector() {
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700210 IpPrefix srcIpPrefix = null;
211 IpPrefix dstIpPrefix = null;
Ray Milkeycaa450b2014-10-29 15:54:24 -0700212
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700213 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
214
215 if (!isNullOrEmpty(srcIpString)) {
216 srcIpPrefix = IpPrefix.valueOf(srcIpString);
217 if (srcIpPrefix.isIp4()) {
218 selectorBuilder.matchIPSrc(srcIpPrefix);
219 } else {
220 selectorBuilder.matchIPv6Src(srcIpPrefix);
221 }
222 }
223
224 if (!isNullOrEmpty(dstIpString)) {
225 dstIpPrefix = IpPrefix.valueOf(dstIpString);
226 if (dstIpPrefix.isIp4()) {
227 selectorBuilder.matchIPDst(dstIpPrefix);
228 } else {
229 selectorBuilder.matchIPv6Dst(dstIpPrefix);
230 }
231 }
232
233 if ((srcIpPrefix != null) && (dstIpPrefix != null) &&
234 (srcIpPrefix.version() != dstIpPrefix.version())) {
235 // ERROR: IP src/dst version mismatch
236 throw new IllegalArgumentException(
237 "IP source and destination version mismatch");
238 }
239
240 //
241 // Set the default EthType based on the IP version if the matching
242 // source or destination IP prefixes.
243 //
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700244 Short ethType = null;
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700245 if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) {
246 ethType = EthType.IPV6.value();
247 }
248 if ((dstIpPrefix != null) && dstIpPrefix.isIp6()) {
249 ethType = EthType.IPV6.value();
250 }
Ray Milkey460f4022014-11-05 15:41:43 -0800251 if (!isNullOrEmpty(ethTypeString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800252 ethType = EthType.parseFromString(ethTypeString);
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700253 }
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700254 if (ethType != null) {
255 selectorBuilder.matchEthType(ethType);
256 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200257 if (!isNullOrEmpty(vlanString)) {
258 selectorBuilder.matchVlanId(VlanId.vlanId(Short.parseShort(vlanString)));
259 }
Ray Milkey460f4022014-11-05 15:41:43 -0800260 if (!isNullOrEmpty(srcMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700261 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
262 }
263
Ray Milkey460f4022014-11-05 15:41:43 -0800264 if (!isNullOrEmpty(dstMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700265 selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString));
266 }
267
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800268 if (!isNullOrEmpty(ipProtoString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800269 short ipProtoShort = IpProtocol.parseFromString(ipProtoString);
270 selectorBuilder.matchIPProtocol((byte) ipProtoShort);
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800271 }
272
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800273 if (!isNullOrEmpty(fLabelString)) {
274 selectorBuilder.matchIPv6FlowLabel(Integer.parseInt(fLabelString));
275 }
276
277 if (!isNullOrEmpty(icmp6TypeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800278 byte icmp6Type = Icmp6Type.parseFromString(icmp6TypeString);
279 selectorBuilder.matchIcmpv6Type(icmp6Type);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800280 }
281
282 if (!isNullOrEmpty(icmp6CodeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800283 byte icmp6Code = Icmp6Code.parseFromString(icmp6CodeString);
284 selectorBuilder.matchIcmpv6Code(icmp6Code);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800285 }
286
287 if (!isNullOrEmpty(ndTargetString)) {
288 selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString));
289 }
290
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800291 if (!isNullOrEmpty(ndSllString)) {
292 selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800293 }
294
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800295 if (!isNullOrEmpty(ndTllString)) {
296 selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800297 }
298
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800299 if (!isNullOrEmpty(srcTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700300 selectorBuilder.matchTcpSrc(TpPort.tpPort(Integer.parseInt(srcTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800301 }
302
303 if (!isNullOrEmpty(dstTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700304 selectorBuilder.matchTcpDst(TpPort.tpPort(Integer.parseInt(dstTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800305 }
306
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800307 if (extHdrStringList != null) {
308 short extHdr = 0;
309 for (String extHdrString : extHdrStringList) {
310 extHdr = (short) (extHdr | ExtHeader.parseFromString(extHdrString));
311 }
312 selectorBuilder.matchIPv6ExthdrFlags(extHdr);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800313 }
314
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700315 return selectorBuilder.build();
316 }
317
Ray Milkey460f4022014-11-05 15:41:43 -0800318 /**
Jonathan Hart2c25e362014-11-17 18:14:19 -0800319 * Generates a traffic treatment for this intent based on command line
320 * arguments presented to the command.
321 *
322 * @return traffic treatment
323 */
324 protected TrafficTreatment buildTrafficTreatment() {
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800325 final TrafficTreatment.Builder treatmentBuilder = builder();
Brian O'Connor11ff8702015-04-29 19:37:15 -0700326 boolean emptyTreatment = true;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800327
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800328 if (!isNullOrEmpty(setEthSrcString)) {
329 treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700330 emptyTreatment = false;
Brian O'Connor4f5a98a2015-03-14 19:50:09 -0700331 }
332
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800333 if (!isNullOrEmpty(setEthDstString)) {
334 treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700335 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800336 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800337
338 if (!isNullOrEmpty(setIpSrcString)) {
339 treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700340 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800341 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800342
343 if (!isNullOrEmpty(setIpDstString)) {
Charles Chand4489882016-04-05 11:38:09 -0700344 treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700345 emptyTreatment = false;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800346 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200347 if (!isNullOrEmpty(setVlan)) {
348 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
349 emptyTreatment = false;
350 }
351 if (popVlan) {
352 treatmentBuilder.popVlan();
353 emptyTreatment = false;
354 }
355 if (!isNullOrEmpty(pushVlan)) {
356 treatmentBuilder.pushVlan();
357 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
358 emptyTreatment = false;
359 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200360 if (!isNullOrEmpty(setQueue)) {
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200361 // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
362 if (setQueue.contains("/")) {
363 String[] queueConfig = setQueue.split("/");
364 PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
365 long queueId = Long.parseLong(queueConfig[1]);
366 treatmentBuilder.setQueue(queueId, port);
367 } else {
368 treatmentBuilder.setQueue(Long.parseLong(setQueue));
369 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200370 emptyTreatment = false;
371 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800372
Brian O'Connor11ff8702015-04-29 19:37:15 -0700373 if (emptyTreatment) {
374 return DefaultTrafficTreatment.emptyTreatment();
375 } else {
376 return treatmentBuilder.build();
377 }
Jonathan Hart2c25e362014-11-17 18:14:19 -0800378 }
379
380 /**
Ray Milkey460f4022014-11-05 15:41:43 -0800381 * Builds the constraint list for this command based on the command line
382 * parameters.
383 *
384 * @return List of constraint objects describing the constraints requested
385 */
386 protected List<Constraint> buildConstraints() {
387 final List<Constraint> constraints = new LinkedList<>();
388
389 // Check for a bandwidth specification
390 if (!isNullOrEmpty(bandwidthString)) {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800391 Bandwidth bandwidth;
392 try {
393 bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
394 // when the string can't be parsed as long, then try to parse as double
395 } catch (NumberFormatException e) {
396 bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
397 }
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800398 constraints.add(new BandwidthConstraint(bandwidth));
Ray Milkey460f4022014-11-05 15:41:43 -0800399 }
400
Michele Santuari05b882c2015-11-25 09:40:46 +0100401 // Check for partial failure specification
Jonathan Hart96c5a4a2015-07-31 14:23:33 -0700402 if (partial) {
403 constraints.add(new PartialFailureConstraint());
404 }
405
Michele Santuari05b882c2015-11-25 09:40:46 +0100406 // Check for encapsulation specification
407 if (!isNullOrEmpty(encapsulationString)) {
408 final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
409 constraints.add(new EncapsulationConstraint(encapType));
410 }
411
jaegonkim7e876632017-01-25 06:01:49 +0900412 // Check for hashed path selection
413 if (hashedPathSelection) {
414 constraints.add(new HashedPathSelectionConstraint());
415 }
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200416
417 // Check for domain processing
418 if (domains) {
419 constraints.add(DomainConstraint.domain());
420 }
dingdamud3a0b212017-05-16 11:18:27 +0200421 // Check for a latency specification
422 if (!isNullOrEmpty(latConstraint)) {
423 try {
424 long lat = Long.parseLong(latConstraint);
425 constraints.add(new LatencyConstraint(Duration.of(lat, ChronoUnit.NANOS)));
426 } catch (NumberFormatException e) {
427 double lat = Double.parseDouble(latConstraint);
428 constraints.add(new LatencyConstraint(Duration.of((long) lat, ChronoUnit.NANOS)));
429 }
430 }
Ray Milkey460f4022014-11-05 15:41:43 -0800431 return constraints;
432 }
Ray Milkey5b3717e2015-02-05 11:44:08 -0800433
Ray Milkey95c50872015-04-14 14:32:31 -0700434 @Override
435 protected ApplicationId appId() {
436 ApplicationId appIdForIntent;
437 if (appId == null) {
438 appIdForIntent = super.appId();
439 } else {
440 CoreService service = get(CoreService.class);
441 appIdForIntent = service.getAppId(appId);
442 }
443 return appIdForIntent;
444 }
445
Luca Prete670ac5d2017-02-03 15:55:43 -0800446 protected ResourceGroup resourceGroup() {
447 if (resourceGroupId != null) {
448 if (resourceGroupId.toLowerCase().startsWith("0x")) {
449 return ResourceGroup.of(Long.parseUnsignedLong(resourceGroupId.substring(2), 16));
450 } else {
451 return ResourceGroup.of(Long.parseUnsignedLong(resourceGroupId));
452 }
453 } else {
454 return null;
455 }
456 }
457
Ray Milkey5b3717e2015-02-05 11:44:08 -0800458 /**
459 * Creates a key for an intent based on command line arguments. If a key
460 * has been specified, it is returned. If no key is specified, null
461 * is returned.
462 *
463 * @return intent key if specified, null otherwise
464 */
465 protected Key key() {
466 Key key = null;
Ray Milkey95c50872015-04-14 14:32:31 -0700467
Ray Milkey5b3717e2015-02-05 11:44:08 -0800468 if (intentKey != null) {
469 key = Key.of(intentKey, appId());
470 }
471 return key;
472 }
Ray Milkeyc24cde32015-03-10 18:20:18 -0700473
474 /**
475 * Gets the priority to use for the intent.
476 *
477 * @return priority
478 */
479 protected int priority() {
480 return priority;
481 }
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700482}