blob: 43961f36c4965cd7dce541f6f88379b289e2ed3f [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 Milkey0068fd02018-10-11 15:45:39 -070018import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.apache.karaf.shell.api.action.Option;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +080020import org.onlab.packet.Ip6Address;
21import org.onlab.packet.IpAddress;
Hyunsun Mooncf732fb2015-08-22 21:04:23 -070022import org.onlab.packet.IpPrefix;
23import org.onlab.packet.MacAddress;
24import org.onlab.packet.TpPort;
Dusan Pajin6b887c92015-07-01 18:32:49 +020025import org.onlab.packet.VlanId;
Sho SHIMIZU6d01d3d2015-05-08 14:08:36 -070026import org.onlab.util.Bandwidth;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.cli.AbstractShellCommand;
Ray Milkey0068fd02018-10-11 15:45:39 -070028import org.onosproject.cli.app.AllApplicationNamesCompleter;
Ray Milkey95c50872015-04-14 14:32:31 -070029import org.onosproject.core.ApplicationId;
30import org.onosproject.core.CoreService;
Michele Santuari05b882c2015-11-25 09:40:46 +010031import org.onosproject.net.EncapsulationType;
Steffen Gebertba2d3b72015-10-22 11:14:31 +020032import org.onosproject.net.PortNumber;
Luca Prete670ac5d2017-02-03 15:55:43 -080033import org.onosproject.net.ResourceGroup;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import org.onosproject.net.flow.DefaultTrafficSelector;
Brian O'Connor11ff8702015-04-29 19:37:15 -070035import org.onosproject.net.flow.DefaultTrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.flow.TrafficSelector;
37import org.onosproject.net.flow.TrafficTreatment;
38import org.onosproject.net.intent.Constraint;
Ray Milkeyc24cde32015-03-10 18:20:18 -070039import org.onosproject.net.intent.Intent;
Ray Milkey5b3717e2015-02-05 11:44:08 -080040import org.onosproject.net.intent.Key;
Brian O'Connorabafb502014-12-02 22:26:20 -080041import org.onosproject.net.intent.constraint.BandwidthConstraint;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020042import org.onosproject.net.intent.constraint.DomainConstraint;
Michele Santuari05b882c2015-11-25 09:40:46 +010043import org.onosproject.net.intent.constraint.EncapsulationConstraint;
jaegonkim7e876632017-01-25 06:01:49 +090044import org.onosproject.net.intent.constraint.HashedPathSelectionConstraint;
dingdamud3a0b212017-05-16 11:18:27 +020045import org.onosproject.net.intent.constraint.LatencyConstraint;
Jonathan Hart96c5a4a2015-07-31 14:23:33 -070046import org.onosproject.net.intent.constraint.PartialFailureConstraint;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070047
dingdamud3a0b212017-05-16 11:18:27 +020048import java.time.Duration;
49import java.time.temporal.ChronoUnit;
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080050import java.util.LinkedList;
51import java.util.List;
52
53import static com.google.common.base.Strings.isNullOrEmpty;
54import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
55
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070056/**
57 * Base class for command line operations for connectivity based intents.
58 */
59public abstract class ConnectivityIntentCommand extends AbstractShellCommand {
60
Jonathan Hart2c25e362014-11-17 18:14:19 -080061 // Selectors
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070062 @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address",
63 required = false, multiValued = false)
64 private String srcMacString = null;
65
66 @Option(name = "-d", aliases = "--ethDst", description = "Destination MAC Address",
67 required = false, multiValued = false)
68 private String dstMacString = null;
69
70 @Option(name = "-t", aliases = "--ethType", description = "Ethernet Type",
71 required = false, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070072 @Completion(EthTypeCompleter.class)
Ray Milkey04c78322015-01-21 14:57:58 -080073 private String ethTypeString = null;
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070074
Dusan Pajin6b887c92015-07-01 18:32:49 +020075 @Option(name = "-v", aliases = "--vlan", description = "VLAN ID",
76 required = false, multiValued = false)
77 private String vlanString = null;
78
Jonathan Hart5f7097e2014-11-11 11:50:28 -080079 @Option(name = "--ipProto", description = "IP Protocol",
80 required = false, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070081 @Completion(IpProtocolCompleter.class)
Jonathan Hart5f7097e2014-11-11 11:50:28 -080082 private String ipProtoString = null;
83
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -070084 @Option(name = "--ipSrc", description = "Source IP Prefix",
Jonathan Hart5f7097e2014-11-11 11:50:28 -080085 required = false, multiValued = false)
86 private String srcIpString = null;
87
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -070088 @Option(name = "--ipDst", description = "Destination IP Prefix",
Jonathan Hart5f7097e2014-11-11 11:50:28 -080089 required = false, multiValued = false)
90 private String dstIpString = null;
91
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +080092 @Option(name = "--fLabel", description = "IPv6 Flow Label",
93 required = false, multiValued = false)
94 private String fLabelString = null;
95
96 @Option(name = "--icmp6Type", description = "ICMPv6 Type",
97 required = false, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070098 @Completion(Icmp6TypeCompleter.class)
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +080099 private String icmp6TypeString = null;
100
101 @Option(name = "--icmp6Code", description = "ICMPv6 Code",
102 required = false, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -0700103 @Completion(Icmp6CodeCompleter.class)
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800104 private String icmp6CodeString = null;
105
106 @Option(name = "--ndTarget", description = "IPv6 Neighbor Discovery Target Address",
107 required = false, multiValued = false)
108 private String ndTargetString = null;
109
110 @Option(name = "--ndSLL", description = "IPv6 Neighbor Discovery Source Link-Layer",
111 required = false, multiValued = false)
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800112 private String ndSllString = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800113
114 @Option(name = "--ndTLL", description = "IPv6 Neighbor Discovery Target Link-Layer",
115 required = false, multiValued = false)
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800116 private String ndTllString = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800117
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800118 @Option(name = "--tcpSrc", description = "Source TCP Port",
119 required = false, multiValued = false)
120 private String srcTcpString = null;
121
122 @Option(name = "--tcpDst", description = "Destination TCP Port",
123 required = false, multiValued = false)
124 private String dstTcpString = null;
125
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800126 @Option(name = "--extHdr", description = "IPv6 Extension Header Pseudo-field",
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800127 required = false, multiValued = true)
Ray Milkey0068fd02018-10-11 15:45:39 -0700128 @Completion(ExtHeaderCompleter.class)
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800129 private List<String> extHdrStringList = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800130
Ray Milkey95c50872015-04-14 14:32:31 -0700131 @Option(name = "-a", aliases = "--appId", description = "Application Id",
132 required = false, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -0700133 @Completion(AllApplicationNamesCompleter.class)
Ray Milkey95c50872015-04-14 14:32:31 -0700134 private String appId = null;
135
Ray Milkey5b3717e2015-02-05 11:44:08 -0800136 @Option(name = "-k", aliases = "--key", description = "Intent Key",
137 required = false, multiValued = false)
138 private String intentKey = null;
139
Jonathan Hart2c25e362014-11-17 18:14:19 -0800140
141 // Treatments
142 @Option(name = "--setEthSrc", description = "Rewrite Source MAC Address",
143 required = false, multiValued = false)
144 private String setEthSrcString = null;
145
146 @Option(name = "--setEthDst", description = "Rewrite Destination MAC Address",
147 required = false, multiValued = false)
148 private String setEthDstString = null;
149
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800150 @Option(name = "--setIpSrc", description = "Rewrite Source IP Address",
151 required = false, multiValued = false)
152 private String setIpSrcString = null;
153
154 @Option(name = "--setIpDst", description = "Rewrite Destination IP Address",
155 required = false, multiValued = false)
156 private String setIpDstString = null;
157
Dusan Pajin6b887c92015-07-01 18:32:49 +0200158 @Option(name = "--setVlan", description = "Rewrite VLAN ID",
159 required = false, multiValued = false)
160 private String setVlan = null;
161
162 @Option(name = "--popVlan", description = "Pop VLAN Tag",
163 required = false, multiValued = false)
164 private boolean popVlan = false;
165
166 @Option(name = "--pushVlan", description = "Push VLAN ID",
167 required = false, multiValued = false)
168 private String pushVlan = null;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800169
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200170 @Option(name = "--setQueue", description = "Set Queue ID (for OpenFlow 1.0, " +
171 "also the port has to be specified, i.e., <port>/<queue>",
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200172 required = false, multiValued = false)
173 private String setQueue = null;
174
Ray Milkeyc24cde32015-03-10 18:20:18 -0700175 // Priorities
176 @Option(name = "-p", aliases = "--priority", description = "Priority",
177 required = false, multiValued = false)
178 private int priority = Intent.DEFAULT_INTENT_PRIORITY;
179
Michele Santuari05b882c2015-11-25 09:40:46 +0100180 // Constraints
181 @Option(name = "-b", aliases = "--bandwidth", description = "Bandwidth",
182 required = false, multiValued = false)
183 private String bandwidthString = null;
184
Michele Santuari05b882c2015-11-25 09:40:46 +0100185 @Option(name = "--partial", description = "Allow partial installation",
186 required = false, multiValued = false)
187 private boolean partial = false;
188
189 @Option(name = "-e", aliases = "--encapsulation", description = "Encapsulation type",
190 required = false, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -0700191 @Completion(EncapTypeCompleter.class)
Michele Santuari05b882c2015-11-25 09:40:46 +0100192 private String encapsulationString = null;
193
jaegonkim7e876632017-01-25 06:01:49 +0900194 @Option(name = "--hashed", description = "Hashed path selection",
195 required = false, multiValued = false)
196 private boolean hashedPathSelection = false;
197
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200198 @Option(name = "--domains", description = "Allow domain delegation",
199 required = false, multiValued = false)
200 private boolean domains = false;
201
dingdamud3a0b212017-05-16 11:18:27 +0200202 @Option(name = "-l", aliases = "--latency",
203 description = "Max latency in nanoseconds tolerated by the intent", required = false,
204 multiValued = false)
205 String latConstraint = null;
206
Luca Prete670ac5d2017-02-03 15:55:43 -0800207 // Resource Group
208 @Option(name = "-r", aliases = "--resourceGroup", description = "Resource Group Id",
209 required = false, multiValued = false)
210 private String resourceGroupId = null;
211
Michele Santuari05b882c2015-11-25 09:40:46 +0100212
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700213 /**
214 * Constructs a traffic selector based on the command line arguments
215 * presented to the command.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -0800216 * @return traffic selector
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700217 */
218 protected TrafficSelector buildTrafficSelector() {
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700219 IpPrefix srcIpPrefix = null;
220 IpPrefix dstIpPrefix = null;
Ray Milkeycaa450b2014-10-29 15:54:24 -0700221
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700222 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
223
224 if (!isNullOrEmpty(srcIpString)) {
225 srcIpPrefix = IpPrefix.valueOf(srcIpString);
226 if (srcIpPrefix.isIp4()) {
227 selectorBuilder.matchIPSrc(srcIpPrefix);
228 } else {
229 selectorBuilder.matchIPv6Src(srcIpPrefix);
230 }
231 }
232
233 if (!isNullOrEmpty(dstIpString)) {
234 dstIpPrefix = IpPrefix.valueOf(dstIpString);
235 if (dstIpPrefix.isIp4()) {
236 selectorBuilder.matchIPDst(dstIpPrefix);
237 } else {
238 selectorBuilder.matchIPv6Dst(dstIpPrefix);
239 }
240 }
241
242 if ((srcIpPrefix != null) && (dstIpPrefix != null) &&
243 (srcIpPrefix.version() != dstIpPrefix.version())) {
244 // ERROR: IP src/dst version mismatch
245 throw new IllegalArgumentException(
246 "IP source and destination version mismatch");
247 }
248
249 //
250 // Set the default EthType based on the IP version if the matching
251 // source or destination IP prefixes.
252 //
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700253 Short ethType = null;
Pavlin Radoslavov6ba7efc2015-03-20 16:26:10 -0700254 if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) {
255 ethType = EthType.IPV6.value();
256 }
257 if ((dstIpPrefix != null) && dstIpPrefix.isIp6()) {
258 ethType = EthType.IPV6.value();
259 }
Ray Milkey460f4022014-11-05 15:41:43 -0800260 if (!isNullOrEmpty(ethTypeString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800261 ethType = EthType.parseFromString(ethTypeString);
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700262 }
Ayaka Koshibe8117f362015-06-02 13:44:01 -0700263 if (ethType != null) {
264 selectorBuilder.matchEthType(ethType);
265 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200266 if (!isNullOrEmpty(vlanString)) {
267 selectorBuilder.matchVlanId(VlanId.vlanId(Short.parseShort(vlanString)));
268 }
Ray Milkey460f4022014-11-05 15:41:43 -0800269 if (!isNullOrEmpty(srcMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700270 selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString));
271 }
272
Ray Milkey460f4022014-11-05 15:41:43 -0800273 if (!isNullOrEmpty(dstMacString)) {
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700274 selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString));
275 }
276
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800277 if (!isNullOrEmpty(ipProtoString)) {
Jonathan Hart6e948282014-11-17 22:50:42 -0800278 short ipProtoShort = IpProtocol.parseFromString(ipProtoString);
279 selectorBuilder.matchIPProtocol((byte) ipProtoShort);
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800280 }
281
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800282 if (!isNullOrEmpty(fLabelString)) {
283 selectorBuilder.matchIPv6FlowLabel(Integer.parseInt(fLabelString));
284 }
285
286 if (!isNullOrEmpty(icmp6TypeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800287 byte icmp6Type = Icmp6Type.parseFromString(icmp6TypeString);
288 selectorBuilder.matchIcmpv6Type(icmp6Type);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800289 }
290
291 if (!isNullOrEmpty(icmp6CodeString)) {
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800292 byte icmp6Code = Icmp6Code.parseFromString(icmp6CodeString);
293 selectorBuilder.matchIcmpv6Code(icmp6Code);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800294 }
295
296 if (!isNullOrEmpty(ndTargetString)) {
297 selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString));
298 }
299
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800300 if (!isNullOrEmpty(ndSllString)) {
301 selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800302 }
303
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800304 if (!isNullOrEmpty(ndTllString)) {
305 selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTllString));
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800306 }
307
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800308 if (!isNullOrEmpty(srcTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700309 selectorBuilder.matchTcpSrc(TpPort.tpPort(Integer.parseInt(srcTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800310 }
311
312 if (!isNullOrEmpty(dstTcpString)) {
Hyunsun Mooncf732fb2015-08-22 21:04:23 -0700313 selectorBuilder.matchTcpDst(TpPort.tpPort(Integer.parseInt(dstTcpString)));
Jonathan Hart5f7097e2014-11-11 11:50:28 -0800314 }
315
Charles M.C. Chan2184de12015-04-26 02:24:53 +0800316 if (extHdrStringList != null) {
317 short extHdr = 0;
318 for (String extHdrString : extHdrStringList) {
319 extHdr = (short) (extHdr | ExtHeader.parseFromString(extHdrString));
320 }
321 selectorBuilder.matchIPv6ExthdrFlags(extHdr);
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800322 }
323
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700324 return selectorBuilder.build();
325 }
326
Ray Milkey460f4022014-11-05 15:41:43 -0800327 /**
Jonathan Hart2c25e362014-11-17 18:14:19 -0800328 * Generates a traffic treatment for this intent based on command line
329 * arguments presented to the command.
330 *
331 * @return traffic treatment
332 */
333 protected TrafficTreatment buildTrafficTreatment() {
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800334 final TrafficTreatment.Builder treatmentBuilder = builder();
Brian O'Connor11ff8702015-04-29 19:37:15 -0700335 boolean emptyTreatment = true;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800336
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800337 if (!isNullOrEmpty(setEthSrcString)) {
338 treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700339 emptyTreatment = false;
Brian O'Connor4f5a98a2015-03-14 19:50:09 -0700340 }
341
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800342 if (!isNullOrEmpty(setEthDstString)) {
343 treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700344 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800345 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800346
347 if (!isNullOrEmpty(setIpSrcString)) {
348 treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700349 emptyTreatment = false;
Jonathan Hart2c25e362014-11-17 18:14:19 -0800350 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800351
352 if (!isNullOrEmpty(setIpDstString)) {
Charles Chand4489882016-04-05 11:38:09 -0700353 treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
Brian O'Connor11ff8702015-04-29 19:37:15 -0700354 emptyTreatment = false;
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800355 }
Dusan Pajin6b887c92015-07-01 18:32:49 +0200356 if (!isNullOrEmpty(setVlan)) {
357 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
358 emptyTreatment = false;
359 }
360 if (popVlan) {
361 treatmentBuilder.popVlan();
362 emptyTreatment = false;
363 }
364 if (!isNullOrEmpty(pushVlan)) {
365 treatmentBuilder.pushVlan();
366 treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
367 emptyTreatment = false;
368 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200369 if (!isNullOrEmpty(setQueue)) {
Steffen Gebertba2d3b72015-10-22 11:14:31 +0200370 // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
371 if (setQueue.contains("/")) {
372 String[] queueConfig = setQueue.split("/");
373 PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
374 long queueId = Long.parseLong(queueConfig[1]);
375 treatmentBuilder.setQueue(queueId, port);
376 } else {
377 treatmentBuilder.setQueue(Long.parseLong(setQueue));
378 }
Steffen Gebertbbfdaaa2015-09-29 11:01:46 +0200379 emptyTreatment = false;
380 }
Charles M.C. Chane9c8bbc2015-04-24 05:03:02 +0800381
Brian O'Connor11ff8702015-04-29 19:37:15 -0700382 if (emptyTreatment) {
383 return DefaultTrafficTreatment.emptyTreatment();
384 } else {
385 return treatmentBuilder.build();
386 }
Jonathan Hart2c25e362014-11-17 18:14:19 -0800387 }
388
389 /**
Ray Milkey460f4022014-11-05 15:41:43 -0800390 * Builds the constraint list for this command based on the command line
391 * parameters.
392 *
393 * @return List of constraint objects describing the constraints requested
394 */
395 protected List<Constraint> buildConstraints() {
396 final List<Constraint> constraints = new LinkedList<>();
397
398 // Check for a bandwidth specification
399 if (!isNullOrEmpty(bandwidthString)) {
Sho SHIMIZU31f37ed2016-01-08 18:45:54 -0800400 Bandwidth bandwidth;
401 try {
402 bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
403 // when the string can't be parsed as long, then try to parse as double
404 } catch (NumberFormatException e) {
405 bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
406 }
Sho SHIMIZUa88db492015-11-23 13:21:04 -0800407 constraints.add(new BandwidthConstraint(bandwidth));
Ray Milkey460f4022014-11-05 15:41:43 -0800408 }
409
Michele Santuari05b882c2015-11-25 09:40:46 +0100410 // Check for partial failure specification
Jonathan Hart96c5a4a2015-07-31 14:23:33 -0700411 if (partial) {
412 constraints.add(new PartialFailureConstraint());
413 }
414
Michele Santuari05b882c2015-11-25 09:40:46 +0100415 // Check for encapsulation specification
416 if (!isNullOrEmpty(encapsulationString)) {
417 final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
418 constraints.add(new EncapsulationConstraint(encapType));
419 }
420
jaegonkim7e876632017-01-25 06:01:49 +0900421 // Check for hashed path selection
422 if (hashedPathSelection) {
423 constraints.add(new HashedPathSelectionConstraint());
424 }
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200425
426 // Check for domain processing
427 if (domains) {
428 constraints.add(DomainConstraint.domain());
429 }
dingdamud3a0b212017-05-16 11:18:27 +0200430 // Check for a latency specification
431 if (!isNullOrEmpty(latConstraint)) {
432 try {
433 long lat = Long.parseLong(latConstraint);
434 constraints.add(new LatencyConstraint(Duration.of(lat, ChronoUnit.NANOS)));
435 } catch (NumberFormatException e) {
436 double lat = Double.parseDouble(latConstraint);
437 constraints.add(new LatencyConstraint(Duration.of((long) lat, ChronoUnit.NANOS)));
438 }
439 }
Ray Milkey460f4022014-11-05 15:41:43 -0800440 return constraints;
441 }
Ray Milkey5b3717e2015-02-05 11:44:08 -0800442
Ray Milkey95c50872015-04-14 14:32:31 -0700443 @Override
444 protected ApplicationId appId() {
445 ApplicationId appIdForIntent;
446 if (appId == null) {
447 appIdForIntent = super.appId();
448 } else {
449 CoreService service = get(CoreService.class);
450 appIdForIntent = service.getAppId(appId);
451 }
452 return appIdForIntent;
453 }
454
Luca Prete670ac5d2017-02-03 15:55:43 -0800455 protected ResourceGroup resourceGroup() {
456 if (resourceGroupId != null) {
457 if (resourceGroupId.toLowerCase().startsWith("0x")) {
458 return ResourceGroup.of(Long.parseUnsignedLong(resourceGroupId.substring(2), 16));
459 } else {
460 return ResourceGroup.of(Long.parseUnsignedLong(resourceGroupId));
461 }
462 } else {
463 return null;
464 }
465 }
466
Ray Milkey5b3717e2015-02-05 11:44:08 -0800467 /**
468 * Creates a key for an intent based on command line arguments. If a key
469 * has been specified, it is returned. If no key is specified, null
470 * is returned.
471 *
472 * @return intent key if specified, null otherwise
473 */
474 protected Key key() {
475 Key key = null;
Ray Milkey95c50872015-04-14 14:32:31 -0700476
Ray Milkey5b3717e2015-02-05 11:44:08 -0800477 if (intentKey != null) {
478 key = Key.of(intentKey, appId());
479 }
480 return key;
481 }
Ray Milkeyc24cde32015-03-10 18:20:18 -0700482
483 /**
484 * Gets the priority to use for the intent.
485 *
486 * @return priority
487 */
488 protected int priority() {
489 return priority;
490 }
Ray Milkey9fdf1ea2014-10-21 09:48:02 -0700491}