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