Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | 6e94828 | 2014-11-17 22:50:42 -0800 | [diff] [blame] | 18 | import static com.google.common.base.Strings.isNullOrEmpty; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; |
Jonathan Hart | 6e94828 | 2014-11-17 22:50:42 -0800 | [diff] [blame] | 20 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 21 | import java.util.LinkedList; |
| 22 | import java.util.List; |
| 23 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 24 | import org.apache.karaf.shell.commands.Option; |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 25 | import org.onlab.packet.Ip6Address; |
| 26 | import org.onlab.packet.IpAddress; |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 27 | import org.onlab.util.Bandwidth; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.cli.AbstractShellCommand; |
Ray Milkey | 95c5087 | 2015-04-14 14:32:31 -0700 | [diff] [blame] | 29 | import org.onosproject.core.ApplicationId; |
| 30 | import org.onosproject.core.CoreService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.Link; |
| 32 | import org.onosproject.net.flow.DefaultTrafficSelector; |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 33 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.TrafficSelector; |
| 35 | import org.onosproject.net.flow.TrafficTreatment; |
| 36 | import org.onosproject.net.intent.Constraint; |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 37 | import org.onosproject.net.intent.Intent; |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 38 | import org.onosproject.net.intent.Key; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 40 | import org.onosproject.net.intent.constraint.LambdaConstraint; |
| 41 | import org.onosproject.net.intent.constraint.LinkTypeConstraint; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame^] | 42 | import org.onosproject.net.resource.link.BandwidthResource; |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 43 | import org.onlab.packet.IpPrefix; |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 44 | import org.onlab.packet.MacAddress; |
| 45 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Base class for command line operations for connectivity based intents. |
| 48 | */ |
| 49 | public abstract class ConnectivityIntentCommand extends AbstractShellCommand { |
| 50 | |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 51 | // Selectors |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 52 | @Option(name = "-s", aliases = "--ethSrc", description = "Source MAC Address", |
| 53 | required = false, multiValued = false) |
| 54 | private String srcMacString = null; |
| 55 | |
| 56 | @Option(name = "-d", aliases = "--ethDst", description = "Destination MAC Address", |
| 57 | required = false, multiValued = false) |
| 58 | private String dstMacString = null; |
| 59 | |
| 60 | @Option(name = "-t", aliases = "--ethType", description = "Ethernet Type", |
| 61 | required = false, multiValued = false) |
Ray Milkey | 04c7832 | 2015-01-21 14:57:58 -0800 | [diff] [blame] | 62 | private String ethTypeString = null; |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 63 | |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 64 | @Option(name = "--ipProto", description = "IP Protocol", |
| 65 | required = false, multiValued = false) |
| 66 | private String ipProtoString = null; |
| 67 | |
Pavlin Radoslavov | 6ba7efc | 2015-03-20 16:26:10 -0700 | [diff] [blame] | 68 | @Option(name = "--ipSrc", description = "Source IP Prefix", |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 69 | required = false, multiValued = false) |
| 70 | private String srcIpString = null; |
| 71 | |
Pavlin Radoslavov | 6ba7efc | 2015-03-20 16:26:10 -0700 | [diff] [blame] | 72 | @Option(name = "--ipDst", description = "Destination IP Prefix", |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 73 | required = false, multiValued = false) |
| 74 | private String dstIpString = null; |
| 75 | |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 76 | @Option(name = "--fLabel", description = "IPv6 Flow Label", |
| 77 | required = false, multiValued = false) |
| 78 | private String fLabelString = null; |
| 79 | |
| 80 | @Option(name = "--icmp6Type", description = "ICMPv6 Type", |
| 81 | required = false, multiValued = false) |
| 82 | private String icmp6TypeString = null; |
| 83 | |
| 84 | @Option(name = "--icmp6Code", description = "ICMPv6 Code", |
| 85 | required = false, multiValued = false) |
| 86 | private String icmp6CodeString = null; |
| 87 | |
| 88 | @Option(name = "--ndTarget", description = "IPv6 Neighbor Discovery Target Address", |
| 89 | required = false, multiValued = false) |
| 90 | private String ndTargetString = null; |
| 91 | |
| 92 | @Option(name = "--ndSLL", description = "IPv6 Neighbor Discovery Source Link-Layer", |
| 93 | required = false, multiValued = false) |
| 94 | private String ndSLLString = null; |
| 95 | |
| 96 | @Option(name = "--ndTLL", description = "IPv6 Neighbor Discovery Target Link-Layer", |
| 97 | required = false, multiValued = false) |
| 98 | private String ndTLLString = null; |
| 99 | |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 100 | @Option(name = "--tcpSrc", description = "Source TCP Port", |
| 101 | required = false, multiValued = false) |
| 102 | private String srcTcpString = null; |
| 103 | |
| 104 | @Option(name = "--tcpDst", description = "Destination TCP Port", |
| 105 | required = false, multiValued = false) |
| 106 | private String dstTcpString = null; |
| 107 | |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 108 | @Option(name = "--extHdr", description = "IPv6 Extension Header Pseudo-field", |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 109 | required = false, multiValued = true) |
| 110 | private List<String> extHdrStringList = null; |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 111 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 112 | @Option(name = "-b", aliases = "--bandwidth", description = "Bandwidth", |
| 113 | required = false, multiValued = false) |
Ray Milkey | 04c7832 | 2015-01-21 14:57:58 -0800 | [diff] [blame] | 114 | private String bandwidthString = null; |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 115 | |
| 116 | @Option(name = "-l", aliases = "--lambda", description = "Lambda", |
| 117 | required = false, multiValued = false) |
| 118 | private boolean lambda = false; |
| 119 | |
Ray Milkey | 95c5087 | 2015-04-14 14:32:31 -0700 | [diff] [blame] | 120 | @Option(name = "-a", aliases = "--appId", description = "Application Id", |
| 121 | required = false, multiValued = false) |
| 122 | private String appId = null; |
| 123 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 124 | @Option(name = "-k", aliases = "--key", description = "Intent Key", |
| 125 | required = false, multiValued = false) |
| 126 | private String intentKey = null; |
| 127 | |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 128 | |
| 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. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 138 | @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 | |
| 146 | |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 147 | // Priorities |
| 148 | @Option(name = "-p", aliases = "--priority", description = "Priority", |
| 149 | required = false, multiValued = false) |
| 150 | private int priority = Intent.DEFAULT_INTENT_PRIORITY; |
| 151 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 152 | /** |
| 153 | * Constructs a traffic selector based on the command line arguments |
| 154 | * presented to the command. |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 155 | * @return traffic selector |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 156 | */ |
| 157 | protected TrafficSelector buildTrafficSelector() { |
Pavlin Radoslavov | 6ba7efc | 2015-03-20 16:26:10 -0700 | [diff] [blame] | 158 | IpPrefix srcIpPrefix = null; |
| 159 | IpPrefix dstIpPrefix = null; |
Ray Milkey | caa450b | 2014-10-29 15:54:24 -0700 | [diff] [blame] | 160 | |
Pavlin Radoslavov | 6ba7efc | 2015-03-20 16:26:10 -0700 | [diff] [blame] | 161 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
| 162 | |
| 163 | if (!isNullOrEmpty(srcIpString)) { |
| 164 | srcIpPrefix = IpPrefix.valueOf(srcIpString); |
| 165 | if (srcIpPrefix.isIp4()) { |
| 166 | selectorBuilder.matchIPSrc(srcIpPrefix); |
| 167 | } else { |
| 168 | selectorBuilder.matchIPv6Src(srcIpPrefix); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (!isNullOrEmpty(dstIpString)) { |
| 173 | dstIpPrefix = IpPrefix.valueOf(dstIpString); |
| 174 | if (dstIpPrefix.isIp4()) { |
| 175 | selectorBuilder.matchIPDst(dstIpPrefix); |
| 176 | } else { |
| 177 | selectorBuilder.matchIPv6Dst(dstIpPrefix); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if ((srcIpPrefix != null) && (dstIpPrefix != null) && |
| 182 | (srcIpPrefix.version() != dstIpPrefix.version())) { |
| 183 | // ERROR: IP src/dst version mismatch |
| 184 | throw new IllegalArgumentException( |
| 185 | "IP source and destination version mismatch"); |
| 186 | } |
| 187 | |
| 188 | // |
| 189 | // Set the default EthType based on the IP version if the matching |
| 190 | // source or destination IP prefixes. |
| 191 | // |
| 192 | short ethType = EthType.IPV4.value(); |
| 193 | if ((srcIpPrefix != null) && srcIpPrefix.isIp6()) { |
| 194 | ethType = EthType.IPV6.value(); |
| 195 | } |
| 196 | if ((dstIpPrefix != null) && dstIpPrefix.isIp6()) { |
| 197 | ethType = EthType.IPV6.value(); |
| 198 | } |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 199 | if (!isNullOrEmpty(ethTypeString)) { |
Jonathan Hart | 6e94828 | 2014-11-17 22:50:42 -0800 | [diff] [blame] | 200 | ethType = EthType.parseFromString(ethTypeString); |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 201 | } |
| 202 | selectorBuilder.matchEthType(ethType); |
| 203 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 204 | if (!isNullOrEmpty(srcMacString)) { |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 205 | selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString)); |
| 206 | } |
| 207 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 208 | if (!isNullOrEmpty(dstMacString)) { |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 209 | selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString)); |
| 210 | } |
| 211 | |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 212 | if (!isNullOrEmpty(ipProtoString)) { |
Jonathan Hart | 6e94828 | 2014-11-17 22:50:42 -0800 | [diff] [blame] | 213 | short ipProtoShort = IpProtocol.parseFromString(ipProtoString); |
| 214 | selectorBuilder.matchIPProtocol((byte) ipProtoShort); |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 217 | if (!isNullOrEmpty(fLabelString)) { |
| 218 | selectorBuilder.matchIPv6FlowLabel(Integer.parseInt(fLabelString)); |
| 219 | } |
| 220 | |
| 221 | if (!isNullOrEmpty(icmp6TypeString)) { |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 222 | byte icmp6Type = Icmp6Type.parseFromString(icmp6TypeString); |
| 223 | selectorBuilder.matchIcmpv6Type(icmp6Type); |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | if (!isNullOrEmpty(icmp6CodeString)) { |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 227 | byte icmp6Code = Icmp6Code.parseFromString(icmp6CodeString); |
| 228 | selectorBuilder.matchIcmpv6Code(icmp6Code); |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | if (!isNullOrEmpty(ndTargetString)) { |
| 232 | selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString)); |
| 233 | } |
| 234 | |
| 235 | if (!isNullOrEmpty(ndSLLString)) { |
| 236 | selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSLLString)); |
| 237 | } |
| 238 | |
| 239 | if (!isNullOrEmpty(ndTLLString)) { |
| 240 | selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTLLString)); |
| 241 | } |
| 242 | |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 243 | if (!isNullOrEmpty(srcTcpString)) { |
| 244 | selectorBuilder.matchTcpSrc((short) Integer.parseInt(srcTcpString)); |
| 245 | } |
| 246 | |
| 247 | if (!isNullOrEmpty(dstTcpString)) { |
Jonathan Hart | 5dfa43f | 2014-11-17 15:35:54 -0800 | [diff] [blame] | 248 | selectorBuilder.matchTcpDst((short) Integer.parseInt(dstTcpString)); |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 251 | if (extHdrStringList != null) { |
| 252 | short extHdr = 0; |
| 253 | for (String extHdrString : extHdrStringList) { |
| 254 | extHdr = (short) (extHdr | ExtHeader.parseFromString(extHdrString)); |
| 255 | } |
| 256 | selectorBuilder.matchIPv6ExthdrFlags(extHdr); |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 257 | } |
| 258 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 259 | return selectorBuilder.build(); |
| 260 | } |
| 261 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 262 | /** |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 263 | * Generates a traffic treatment for this intent based on command line |
| 264 | * arguments presented to the command. |
| 265 | * |
| 266 | * @return traffic treatment |
| 267 | */ |
| 268 | protected TrafficTreatment buildTrafficTreatment() { |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 269 | final TrafficTreatment.Builder treatmentBuilder = builder(); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 270 | boolean emptyTreatment = true; |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 271 | |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 272 | if (!isNullOrEmpty(setEthSrcString)) { |
| 273 | treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString)); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 274 | emptyTreatment = false; |
Brian O'Connor | 4f5a98a | 2015-03-14 19:50:09 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 277 | if (!isNullOrEmpty(setEthDstString)) { |
| 278 | treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString)); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 279 | emptyTreatment = false; |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 280 | } |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 281 | |
| 282 | if (!isNullOrEmpty(setIpSrcString)) { |
| 283 | treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString)); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 284 | emptyTreatment = false; |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 285 | } |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 286 | |
| 287 | if (!isNullOrEmpty(setIpDstString)) { |
| 288 | treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpDstString)); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 289 | emptyTreatment = false; |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 290 | } |
| 291 | |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 292 | if (emptyTreatment) { |
| 293 | return DefaultTrafficTreatment.emptyTreatment(); |
| 294 | } else { |
| 295 | return treatmentBuilder.build(); |
| 296 | } |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /** |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 300 | * Builds the constraint list for this command based on the command line |
| 301 | * parameters. |
| 302 | * |
| 303 | * @return List of constraint objects describing the constraints requested |
| 304 | */ |
| 305 | protected List<Constraint> buildConstraints() { |
| 306 | final List<Constraint> constraints = new LinkedList<>(); |
| 307 | |
| 308 | // Check for a bandwidth specification |
| 309 | if (!isNullOrEmpty(bandwidthString)) { |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 310 | final Bandwidth bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString)); |
| 311 | constraints.add(new BandwidthConstraint(new BandwidthResource(bandwidth))); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // Check for a lambda specification |
| 315 | if (lambda) { |
| 316 | constraints.add(new LambdaConstraint(null)); |
| 317 | } |
Thomas Vachuska | dea45ff | 2014-11-12 18:35:46 -0800 | [diff] [blame] | 318 | constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL)); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 319 | |
| 320 | return constraints; |
| 321 | } |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 322 | |
Ray Milkey | 95c5087 | 2015-04-14 14:32:31 -0700 | [diff] [blame] | 323 | @Override |
| 324 | protected ApplicationId appId() { |
| 325 | ApplicationId appIdForIntent; |
| 326 | if (appId == null) { |
| 327 | appIdForIntent = super.appId(); |
| 328 | } else { |
| 329 | CoreService service = get(CoreService.class); |
| 330 | appIdForIntent = service.getAppId(appId); |
| 331 | } |
| 332 | return appIdForIntent; |
| 333 | } |
| 334 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 335 | /** |
| 336 | * Creates a key for an intent based on command line arguments. If a key |
| 337 | * has been specified, it is returned. If no key is specified, null |
| 338 | * is returned. |
| 339 | * |
| 340 | * @return intent key if specified, null otherwise |
| 341 | */ |
| 342 | protected Key key() { |
| 343 | Key key = null; |
Ray Milkey | 95c5087 | 2015-04-14 14:32:31 -0700 | [diff] [blame] | 344 | ApplicationId appIdForIntent; |
| 345 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 346 | if (intentKey != null) { |
| 347 | key = Key.of(intentKey, appId()); |
| 348 | } |
| 349 | return key; |
| 350 | } |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 351 | |
| 352 | /** |
| 353 | * Gets the priority to use for the intent. |
| 354 | * |
| 355 | * @return priority |
| 356 | */ |
| 357 | protected int priority() { |
| 358 | return priority; |
| 359 | } |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 360 | } |