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