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