Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -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 | 83e090e | 2014-10-22 14:25:35 -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 | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 17 | |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 18 | import org.onlab.packet.IpAddress; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 19 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 20 | import org.onlab.packet.MplsLabel; |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 21 | import org.onlab.packet.VlanId; |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 22 | import org.onosproject.core.GroupId; |
| 23 | import org.onosproject.net.PortNumber; |
| 24 | import org.onosproject.net.flow.instructions.Instruction; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flow.instructions.Instructions; |
alshabib | 55a55d9 | 2014-09-16 11:59:31 -0700 | [diff] [blame] | 26 | |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 27 | import java.util.List; |
| 28 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Abstraction of network traffic treatment. |
| 31 | */ |
| 32 | public interface TrafficTreatment { |
| 33 | |
| 34 | /** |
| 35 | * Returns list of instructions on how to treat traffic. |
| 36 | * |
| 37 | * @return list of treatment instructions |
| 38 | */ |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 39 | @Deprecated |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 40 | List<Instruction> instructions(); |
| 41 | |
| 42 | /** |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 43 | * Returns the list of treatment instructions that will be applied |
| 44 | * further down the pipeline. |
| 45 | * @return list of treatment instructions |
| 46 | */ |
| 47 | List<Instruction> deferred(); |
| 48 | |
| 49 | /** |
| 50 | * Returns the list of treatment instructions that will be applied |
| 51 | * immediately. |
| 52 | * @return list of treatment instructions |
| 53 | */ |
| 54 | List<Instruction> immediate(); |
| 55 | |
| 56 | /** |
Jonathan Hart | 8ef6d3b | 2015-03-08 21:21:27 -0700 | [diff] [blame] | 57 | * Returns the list of all instructions in the treatment, both immediate and |
| 58 | * deferred. |
| 59 | * |
| 60 | * @return list of treatment instructions |
| 61 | */ |
| 62 | List<Instruction> allInstructions(); |
| 63 | |
| 64 | /** |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 65 | * Returns the next table in the pipeline. |
| 66 | * @return a table transition; may be null. |
| 67 | */ |
| 68 | Instructions.TableTypeTransition tableTransition(); |
| 69 | |
| 70 | /** |
| 71 | * Whether the deferred treatment instructions will be cleared |
| 72 | * by the device. |
| 73 | * @return a boolean |
| 74 | */ |
| 75 | Boolean clearedDeferred(); |
| 76 | |
| 77 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 78 | * Builder of traffic treatment entities. |
| 79 | */ |
| 80 | public interface Builder { |
| 81 | |
| 82 | /** |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 83 | * Adds an instruction to the builder. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 84 | * |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 85 | * @param instruction an instruction |
| 86 | * @return a treatment builder |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 87 | */ |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 88 | Builder add(Instruction instruction); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 91 | * Adds a drop instruction. |
| 92 | * |
| 93 | * @return a treatment builder |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 94 | */ |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 95 | public Builder drop(); |
| 96 | |
| 97 | /** |
| 98 | * Adds a punt-to-controller instruction. |
| 99 | * |
| 100 | * @return a treatment builder |
| 101 | */ |
| 102 | public Builder punt(); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Set the output port. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 106 | * |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 107 | * @param number the out port |
| 108 | * @return a treatment builder |
| 109 | */ |
| 110 | public Builder setOutput(PortNumber number); |
| 111 | |
| 112 | /** |
| 113 | * Sets the src l2 address. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 114 | * |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 115 | * @param addr a macaddress |
| 116 | * @return a treatment builder |
| 117 | */ |
| 118 | public Builder setEthSrc(MacAddress addr); |
| 119 | |
| 120 | /** |
| 121 | * Sets the dst l2 address. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 122 | * |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 123 | * @param addr a macaddress |
| 124 | * @return a treatment builder |
| 125 | */ |
| 126 | public Builder setEthDst(MacAddress addr); |
| 127 | |
| 128 | /** |
| 129 | * Sets the vlan id. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 130 | * |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 131 | * @param id a vlanid |
| 132 | * @return a treatment builder |
| 133 | */ |
| 134 | public Builder setVlanId(VlanId id); |
| 135 | |
| 136 | /** |
| 137 | * Sets the vlan priority. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 138 | * |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 139 | * @param pcp a vlan priority |
| 140 | * @return a treatment builder |
| 141 | */ |
| 142 | public Builder setVlanPcp(Byte pcp); |
| 143 | |
| 144 | /** |
alshabib | ab21b2d | 2015-03-04 18:35:33 -0800 | [diff] [blame] | 145 | * Strips the vlan tag if there is one. |
| 146 | * @return a treatment builder |
| 147 | */ |
| 148 | public Builder stripVlan(); |
| 149 | |
| 150 | /** |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 151 | * Sets the src l3 address. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 152 | * |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 153 | * @param addr an ip |
| 154 | * @return a treatment builder |
| 155 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 156 | public Builder setIpSrc(IpAddress addr); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 157 | |
| 158 | /** |
| 159 | * Sets the dst l3 address. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 160 | * |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 161 | * @param addr an ip |
| 162 | * @return a treatment builder |
| 163 | */ |
Pavlin Radoslavov | 855ea2d | 2014-10-30 15:32:39 -0700 | [diff] [blame] | 164 | public Builder setIpDst(IpAddress addr); |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 165 | |
| 166 | /** |
Pavlin Radoslavov | febe82c | 2015-02-11 19:08:15 -0800 | [diff] [blame] | 167 | * Decrement the TTL in IP header by one. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 168 | * |
| 169 | * @return a treatment builder |
| 170 | */ |
| 171 | public Builder decNwTtl(); |
| 172 | |
| 173 | /** |
| 174 | * Copy the TTL to outer protocol layer. |
| 175 | * |
| 176 | * @return a treatment builder |
| 177 | */ |
| 178 | public Builder copyTtlOut(); |
| 179 | |
| 180 | /** |
| 181 | * Copy the TTL to inner protocol layer. |
| 182 | * |
| 183 | * @return a treatment builder |
| 184 | */ |
| 185 | public Builder copyTtlIn(); |
| 186 | |
| 187 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 188 | * Push MPLS ether type. |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 189 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 190 | * @return a treatment builder. |
| 191 | */ |
| 192 | public Builder pushMpls(); |
| 193 | |
| 194 | /** |
| 195 | * Pops MPLS ether type. |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 196 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 197 | * @return a treatment builder. |
| 198 | */ |
| 199 | public Builder popMpls(); |
| 200 | |
| 201 | /** |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 202 | * Pops MPLS ether type and set the new ethertype. |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 203 | * |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 204 | * @param etherType an ether type |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 205 | * @return a treatment builder. |
| 206 | */ |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 207 | public Builder popMpls(Short etherType); |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 208 | |
| 209 | /** |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 210 | * Sets the mpls label. |
Thomas Vachuska | f4df005 | 2015-01-06 12:30:11 -0800 | [diff] [blame] | 211 | * |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 212 | * @param mplsLabel MPLS label. |
| 213 | * @return a treatment builder. |
| 214 | */ |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 215 | public Builder setMpls(MplsLabel mplsLabel); |
Praseed Balakrishnan | 8c67d17 | 2014-11-10 10:15:41 -0800 | [diff] [blame] | 216 | |
| 217 | /** |
sangho | 3f97a17d | 2015-01-29 22:56:29 -0800 | [diff] [blame] | 218 | * Decrement MPLS TTL. |
| 219 | * |
| 220 | * @return a treatment builder |
| 221 | */ |
| 222 | public Builder decMplsTtl(); |
| 223 | |
| 224 | /** |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 225 | * Sets the optical channel ID or lambda. |
Sho SHIMIZU | bdaea83 | 2014-11-12 11:29:38 -0800 | [diff] [blame] | 226 | * |
Marc De Leenheer | 4908775 | 2014-10-23 13:54:09 -0700 | [diff] [blame] | 227 | * @param lambda optical channel ID |
| 228 | * @return a treatment builder |
| 229 | */ |
| 230 | public Builder setLambda(short lambda); |
| 231 | |
| 232 | /** |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 233 | * Sets the group ID. |
| 234 | * |
| 235 | * @param groupId group ID |
| 236 | * @return a treatment builder |
| 237 | */ |
| 238 | public Builder group(GroupId groupId); |
| 239 | |
alshabib | 9af7007 | 2015-02-09 14:34:16 -0800 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * Sets the next table type to transition to. |
| 243 | * |
| 244 | * @param type the table type |
| 245 | * @return a treatement builder |
| 246 | */ |
| 247 | public Builder transition(FlowRule.Type type); |
| 248 | |
sangho | 8995ac5 | 2015-02-04 11:29:03 -0800 | [diff] [blame] | 249 | /** |
Saurav Das | fbe25c5 | 2015-03-04 11:12:00 -0800 | [diff] [blame] | 250 | * Pops outermost VLAN tag. |
| 251 | * |
| 252 | * @return a treatment builder. |
| 253 | */ |
| 254 | public Builder popVlan(); |
| 255 | |
| 256 | /** |
Jonathan Hart | 54b406b | 2015-03-06 16:24:14 -0800 | [diff] [blame] | 257 | * Pushes a new VLAN tag. |
| 258 | * |
| 259 | * @return a treatment builder. |
| 260 | */ |
| 261 | public Builder pushVlan(); |
| 262 | |
| 263 | /** |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 264 | * Any instructions preceded by this method call will be deferred. |
| 265 | * @return a treatment builder |
| 266 | */ |
| 267 | public Builder deferred(); |
| 268 | |
| 269 | /** |
| 270 | * Any instructions preceded by this method call will be immediate. |
| 271 | * @return a treatment builder |
| 272 | */ |
| 273 | public Builder immediate(); |
| 274 | |
| 275 | |
| 276 | /** |
| 277 | * Instructs the device to clear the deferred instructions set. |
| 278 | * @return a treatment builder |
| 279 | */ |
| 280 | public Builder wipeDeferred(); |
| 281 | |
| 282 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 283 | * Builds an immutable traffic treatment descriptor. |
Brian O'Connor | 6b52813 | 2015-03-10 16:39:52 -0700 | [diff] [blame] | 284 | * <p> |
| 285 | * If the treatment is empty when build() is called, it will add a default |
| 286 | * drop rule automatically. For a treatment that is actually empty, use |
| 287 | * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}. |
| 288 | * </p> |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 289 | * |
| 290 | * @return traffic treatment |
| 291 | */ |
| 292 | TrafficTreatment build(); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 293 | } |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 294 | } |