aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
blob: 06b6ffa0b50165d039462e4d20c116add4aff650 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/*
 * Copyright 2014-2015 Open Networking Laboratory
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onosproject.net.flow;

import java.util.List;

import org.onlab.packet.EthType;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.core.GroupId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.ExtensionTreatment;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
import org.onosproject.net.meter.MeterId;

/**
 * Abstraction of network traffic treatment.
 */
public interface TrafficTreatment {

    /**
     * Returns the list of treatment instructions that will be applied
     * further down the pipeline.
     * @return list of treatment instructions
     */
    List<Instruction> deferred();

    /**
     * Returns the list of treatment instructions that will be applied
     * immediately.
     * @return list of treatment instructions
     */
    List<Instruction> immediate();

    /**
     * Returns the list of all instructions in the treatment, both immediate and
     * deferred.
     *
     * @return list of treatment instructions
     */
    List<Instruction> allInstructions();

    /**
     * Returns the next table in the pipeline.
     * @return a table transition; may be null.
     */
    Instructions.TableTypeTransition tableTransition();

    /**
     * Whether the deferred treatment instructions will be cleared
     * by the device.
     * @return a boolean
     */
    boolean clearedDeferred();

    /**
     * Returns the metadata instruction if there is one.
     *
     * @return a metadata instruction that may be null
     */
    Instructions.MetadataInstruction writeMetadata();

    /**
     * Returns the meter instruction if there is one.
     *
     * @return a meter instruction that may be null
     */
    Instructions.MeterInstruction metered();

    /**
     * Builder of traffic treatment entities.
     */
    interface Builder {

        /**
         * Adds an instruction to the builder.
         *
         * @param instruction an instruction
         * @return a treatment builder
         */
        Builder add(Instruction instruction);

        /**
         * Adds a drop instruction.
         *
         * @return a treatment builder
         */
        Builder drop();

        /**
         * Adds a punt-to-controller instruction.
         *
         * @return a treatment builder
         */
        Builder punt();

        /**
         * Set the output port.
         *
         * @param number the out port
         * @return a treatment builder
         */
        Builder setOutput(PortNumber number);

        /**
         * Sets the src l2 address.
         *
         * @param addr a macaddress
         * @return a treatment builder
         */
        Builder setEthSrc(MacAddress addr);

        /**
         * Sets the dst l2 address.
         *
         * @param addr a macaddress
         * @return a treatment builder
         */
        Builder setEthDst(MacAddress addr);

        /**
         * Sets the vlan id.
         *
         * @param id a vlanid
         * @return a treatment builder
         */
        Builder setVlanId(VlanId id);

        /**
         * Sets the vlan priority.
         *
         * @param pcp a vlan priority
         * @return a treatment builder
         */
        Builder setVlanPcp(Byte pcp);

        /**
         * Sets the src l3 address.
         *
         * @param addr an ip
         * @return a treatment builder
         */
        Builder setIpSrc(IpAddress addr);

        /**
         * Sets the dst l3 address.
         *
         * @param addr an ip
         * @return a treatment builder
         */
        Builder setIpDst(IpAddress addr);

        /**
         * Decrement the TTL in IP header by one.
         *
         * @return a treatment builder
         */
        Builder decNwTtl();

        /**
         * Copy the TTL to outer protocol layer.
         *
         * @return a treatment builder
         */
        Builder copyTtlOut();

        /**
         * Copy the TTL to inner protocol layer.
         *
         * @return a treatment builder
         */
        Builder copyTtlIn();

        /**
         * Push MPLS ether type.
         *
         * @return a treatment builder
         */
        Builder pushMpls();

        /**
         * Pops MPLS ether type.
         *
         * @return a treatment builder
         */
        Builder popMpls();

        /**
         * Pops MPLS ether type and set the new ethertype.
         *
         * @param etherType an ether type
         * @return a treatment builder
         * @deprecated in Drake Release
         */
        @Deprecated
        Builder popMpls(int etherType);

        /**
         * Pops MPLS ether type and set the new ethertype.
         *
         * @param etherType an ether type
         * @return a treatment builder
         */
        Builder popMpls(EthType etherType);

        /**
         * Sets the mpls label.
         *
         * @param mplsLabel MPLS label
         * @return a treatment builder
         */
        Builder setMpls(MplsLabel mplsLabel);

        /**
         * Sets the mpls bottom-of-stack indicator bit.
         *
         * @param mplsBos boolean to set BOS=1 (true) or BOS=0 (false)
         * @return a treatment builder.
         */
        Builder setMplsBos(boolean mplsBos);

        /**
         * Decrement MPLS TTL.
         *
         * @return a treatment builder
         */
        Builder decMplsTtl();

        /**
         * Sets the optical channel ID or lambda.
         *
         * @param lambda optical channel ID
         * @return a treatment builder
         * @deprecated in Drake Release
         */
        @Deprecated
        Builder setLambda(short lambda);

        /**
         * Sets the group ID.
         *
         * @param groupId group ID
         * @return a treatment builder
         */
        Builder group(GroupId groupId);

        /**
         * Sets the Queue ID.
         *
         * @param queueId a queue ID
         * @return a treatment builder
         */
        Builder setQueue(long queueId);

        /**
         * Sets the Queue ID for a specific port.
         *
         * @param queueId a queue ID
         * @param port a port number
         * @return a treatment builder
         */
        Builder setQueue(long queueId, PortNumber port);

        /**
         * Sets a meter to be used by this flow.
         *
         * @param meterId a meter id
         * @return a treatment builder
         */
        Builder meter(MeterId meterId);

        /**
         * Sets the next table id to transition to.
         *
         * @param tableId the table table
         * @return a treatement builder
         */
        Builder transition(Integer tableId);


        /**
         * Pops outermost VLAN tag.
         *
         * @return a treatment builder
         */
        Builder popVlan();

        /**
         * Pushes a new VLAN tag.
         *
         * @return a treatment builder
         */
        Builder pushVlan();

        /**
         * Any instructions preceded by this method call will be deferred.
         * @return a treatment builder
         */
        Builder deferred();

        /**
         * Any instructions preceded by this method call will be immediate.
         * @return a treatment builder
         */
        Builder immediate();


        /**
         * Instructs the device to clear the deferred instructions set.
         * @return a treatment builder
         */
        Builder wipeDeferred();

        /**
         * Writes metadata to associate with a packet.
         * <pre>
         * {@code
         * new_metadata = (old_metadata &  ̃mask) | (value & mask)
         * }
         * </pre>
         *
         * @param value the metadata to write
         * @param mask  the masked bits for the value
         * @return a treatment builder
         */
        Builder writeMetadata(long value, long mask);

        /**
         * Sets the tunnel id.
         *
         * @param tunnelId a tunnel id
         * @return a treatment builder
         */
        Builder setTunnelId(long tunnelId);

        /**
         * Sets the src TCP port.
         *
         * @param port a port number
         * @return a treatment builder
         * @deprecated in Drake release
         */
        @Deprecated
        Builder setTcpSrc(short port);

        /**
         * Sets the src TCP port.
         *
         * @param port a port number
         * @return a treatment builder
         */
        Builder setTcpSrc(TpPort port);

        /**
         * Sets the dst TCP port.
         *
         * @param port a port number
         * @return a treatment builder
         * @deprecated in Drake release
         */
        @Deprecated
        Builder setTcpDst(short port);

        /**
         * Sets the dst TCP port.
         *
         * @param port a port number
         * @return a treatment builder
         */
        Builder setTcpDst(TpPort port);

        /**
         * Sets the src UDP port.
         *
         * @param port a port number
         * @return a treatment builder
         * @deprecated in Drake release
         */
        @Deprecated
        Builder setUdpSrc(short port);

        /**
         * Sets the src UDP port.
         *
         * @param port a port number
         * @return a treatment builder
         */
        Builder setUdpSrc(TpPort port);

        /**
         * Sets the dst UDP port.
         *
         * @param port a port number
         * @return a treatment builder
         * @deprecated in Drake release
         */
        @Deprecated
        Builder setUdpDst(short port);

        /**
         * Sets the dst UDP port.
         *
         * @param port a port number
         * @return a treatment builder
         */
        Builder setUdpDst(TpPort port);

        /**
         * Uses an extension treatment.
         *
         * @param extension extension treatment
         * @param deviceId device ID
         * @return a treatment builder
         */
        Builder extension(ExtensionTreatment extension, DeviceId deviceId);

        /**
         * Builds an immutable traffic treatment descriptor.
         * <p>
         * If the treatment is empty when build() is called, it will add a default
         * drop rule automatically. For a treatment that is actually empty, use
         * {@link org.onosproject.net.flow.DefaultTrafficTreatment#emptyTreatment}.
         * </p>
         *
         * @return traffic treatment
         */
        TrafficTreatment build();

    }

}