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) |
Sho SHIMIZU | 792c26b | 2015-06-08 19:08:32 -0700 | [diff] [blame^] | 118 | private boolean lambda = false; |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 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 | // |
Ayaka Koshibe | 8117f36 | 2015-06-02 13:44:01 -0700 | [diff] [blame] | 192 | Short ethType = null; |
Pavlin Radoslavov | 6ba7efc | 2015-03-20 16:26:10 -0700 | [diff] [blame] | 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 | } |
Ayaka Koshibe | 8117f36 | 2015-06-02 13:44:01 -0700 | [diff] [blame] | 202 | if (ethType != null) { |
| 203 | selectorBuilder.matchEthType(ethType); |
| 204 | } |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 205 | if (!isNullOrEmpty(srcMacString)) { |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 206 | selectorBuilder.matchEthSrc(MacAddress.valueOf(srcMacString)); |
| 207 | } |
| 208 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 209 | if (!isNullOrEmpty(dstMacString)) { |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 210 | selectorBuilder.matchEthDst(MacAddress.valueOf(dstMacString)); |
| 211 | } |
| 212 | |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 213 | if (!isNullOrEmpty(ipProtoString)) { |
Jonathan Hart | 6e94828 | 2014-11-17 22:50:42 -0800 | [diff] [blame] | 214 | short ipProtoShort = IpProtocol.parseFromString(ipProtoString); |
| 215 | selectorBuilder.matchIPProtocol((byte) ipProtoShort); |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 216 | } |
| 217 | |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 218 | if (!isNullOrEmpty(fLabelString)) { |
| 219 | selectorBuilder.matchIPv6FlowLabel(Integer.parseInt(fLabelString)); |
| 220 | } |
| 221 | |
| 222 | if (!isNullOrEmpty(icmp6TypeString)) { |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 223 | byte icmp6Type = Icmp6Type.parseFromString(icmp6TypeString); |
| 224 | selectorBuilder.matchIcmpv6Type(icmp6Type); |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | if (!isNullOrEmpty(icmp6CodeString)) { |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 228 | byte icmp6Code = Icmp6Code.parseFromString(icmp6CodeString); |
| 229 | selectorBuilder.matchIcmpv6Code(icmp6Code); |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | if (!isNullOrEmpty(ndTargetString)) { |
| 233 | selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString)); |
| 234 | } |
| 235 | |
| 236 | if (!isNullOrEmpty(ndSLLString)) { |
| 237 | selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSLLString)); |
| 238 | } |
| 239 | |
| 240 | if (!isNullOrEmpty(ndTLLString)) { |
| 241 | selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTLLString)); |
| 242 | } |
| 243 | |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 244 | if (!isNullOrEmpty(srcTcpString)) { |
| 245 | selectorBuilder.matchTcpSrc((short) Integer.parseInt(srcTcpString)); |
| 246 | } |
| 247 | |
| 248 | if (!isNullOrEmpty(dstTcpString)) { |
Jonathan Hart | 5dfa43f | 2014-11-17 15:35:54 -0800 | [diff] [blame] | 249 | selectorBuilder.matchTcpDst((short) Integer.parseInt(dstTcpString)); |
Jonathan Hart | 5f7097e | 2014-11-11 11:50:28 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Charles M.C. Chan | 2184de1 | 2015-04-26 02:24:53 +0800 | [diff] [blame] | 252 | if (extHdrStringList != null) { |
| 253 | short extHdr = 0; |
| 254 | for (String extHdrString : extHdrStringList) { |
| 255 | extHdr = (short) (extHdr | ExtHeader.parseFromString(extHdrString)); |
| 256 | } |
| 257 | selectorBuilder.matchIPv6ExthdrFlags(extHdr); |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 258 | } |
| 259 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 260 | return selectorBuilder.build(); |
| 261 | } |
| 262 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 263 | /** |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 264 | * Generates a traffic treatment for this intent based on command line |
| 265 | * arguments presented to the command. |
| 266 | * |
| 267 | * @return traffic treatment |
| 268 | */ |
| 269 | protected TrafficTreatment buildTrafficTreatment() { |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 270 | final TrafficTreatment.Builder treatmentBuilder = builder(); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 271 | boolean emptyTreatment = true; |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 272 | |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 273 | if (!isNullOrEmpty(setEthSrcString)) { |
| 274 | treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString)); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 275 | emptyTreatment = false; |
Brian O'Connor | 4f5a98a | 2015-03-14 19:50:09 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 278 | if (!isNullOrEmpty(setEthDstString)) { |
| 279 | treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString)); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 280 | emptyTreatment = false; |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 281 | } |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 282 | |
| 283 | if (!isNullOrEmpty(setIpSrcString)) { |
| 284 | treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString)); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 285 | emptyTreatment = false; |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 286 | } |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 287 | |
| 288 | if (!isNullOrEmpty(setIpDstString)) { |
| 289 | treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpDstString)); |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 290 | emptyTreatment = false; |
Charles M.C. Chan | e9c8bbc | 2015-04-24 05:03:02 +0800 | [diff] [blame] | 291 | } |
| 292 | |
Brian O'Connor | 11ff870 | 2015-04-29 19:37:15 -0700 | [diff] [blame] | 293 | if (emptyTreatment) { |
| 294 | return DefaultTrafficTreatment.emptyTreatment(); |
| 295 | } else { |
| 296 | return treatmentBuilder.build(); |
| 297 | } |
Jonathan Hart | 2c25e36 | 2014-11-17 18:14:19 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 301 | * Builds the constraint list for this command based on the command line |
| 302 | * parameters. |
| 303 | * |
| 304 | * @return List of constraint objects describing the constraints requested |
| 305 | */ |
| 306 | protected List<Constraint> buildConstraints() { |
| 307 | final List<Constraint> constraints = new LinkedList<>(); |
| 308 | |
| 309 | // Check for a bandwidth specification |
| 310 | if (!isNullOrEmpty(bandwidthString)) { |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 311 | final Bandwidth bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString)); |
| 312 | constraints.add(new BandwidthConstraint(new BandwidthResource(bandwidth))); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | // Check for a lambda specification |
Sho SHIMIZU | 792c26b | 2015-06-08 19:08:32 -0700 | [diff] [blame^] | 316 | if (lambda) { |
| 317 | constraints.add(new LambdaConstraint(null)); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 318 | } |
Sho SHIMIZU | 792c26b | 2015-06-08 19:08:32 -0700 | [diff] [blame^] | 319 | constraints.add(new LinkTypeConstraint(lambda, Link.Type.OPTICAL)); |
| 320 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 321 | return constraints; |
| 322 | } |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 323 | |
Ray Milkey | 95c5087 | 2015-04-14 14:32:31 -0700 | [diff] [blame] | 324 | @Override |
| 325 | protected ApplicationId appId() { |
| 326 | ApplicationId appIdForIntent; |
| 327 | if (appId == null) { |
| 328 | appIdForIntent = super.appId(); |
| 329 | } else { |
| 330 | CoreService service = get(CoreService.class); |
| 331 | appIdForIntent = service.getAppId(appId); |
| 332 | } |
| 333 | return appIdForIntent; |
| 334 | } |
| 335 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 336 | /** |
| 337 | * Creates a key for an intent based on command line arguments. If a key |
| 338 | * has been specified, it is returned. If no key is specified, null |
| 339 | * is returned. |
| 340 | * |
| 341 | * @return intent key if specified, null otherwise |
| 342 | */ |
| 343 | protected Key key() { |
| 344 | Key key = null; |
Ray Milkey | 95c5087 | 2015-04-14 14:32:31 -0700 | [diff] [blame] | 345 | ApplicationId appIdForIntent; |
| 346 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 347 | if (intentKey != null) { |
| 348 | key = Key.of(intentKey, appId()); |
| 349 | } |
| 350 | return key; |
| 351 | } |
Ray Milkey | c24cde3 | 2015-03-10 18:20:18 -0700 | [diff] [blame] | 352 | |
| 353 | /** |
| 354 | * Gets the priority to use for the intent. |
| 355 | * |
| 356 | * @return priority |
| 357 | */ |
| 358 | protected int priority() { |
| 359 | return priority; |
| 360 | } |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 361 | } |