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