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