blob: 6eaa2c3569b18a58d9e5960e044a39204f26fe20 [file] [log] [blame]
alshabib1d4cace2014-09-13 19:16:26 -07001package org.onlab.onos.net.flow;
2
3import static org.slf4j.LoggerFactory.getLogger;
4
5import java.util.Collections;
6import java.util.LinkedList;
7import java.util.List;
8
alshabib1d4cace2014-09-13 19:16:26 -07009import org.slf4j.Logger;
10
11@SuppressWarnings("rawtypes")
12public class DefaultTrafficTreatment implements TrafficTreatment {
13
14 private final List<Instruction> instructions;
15
16 public DefaultTrafficTreatment(List<Instruction> instructions) {
17 this.instructions = Collections.unmodifiableList(instructions);
18 }
19
20 @Override
21 public List<Instruction> instructions() {
22 return instructions;
23 }
24
25 /**
26 * Builds a list of treatments following the following order.
27 * Modifications -> Group -> Output (including drop)
28 *
29 */
30
31 public static class Builder implements TrafficTreatment.Builder {
32
33 private final Logger log = getLogger(getClass());
34
alshabib030111e2014-09-15 15:56:42 -070035 boolean drop = false;
36
37 List<Instruction> outputs = new LinkedList<>();
alshabib1d4cace2014-09-13 19:16:26 -070038
39 // TODO: should be a list of instructions based on group objects
alshabib030111e2014-09-15 15:56:42 -070040 List<Instruction> groups = new LinkedList<>();
alshabib1d4cace2014-09-13 19:16:26 -070041
42 // TODO: should be a list of instructions based on modification objects
alshabib030111e2014-09-15 15:56:42 -070043 List<Instruction> modifications = new LinkedList<>();
alshabib1d4cace2014-09-13 19:16:26 -070044
45
alshabib1d4cace2014-09-13 19:16:26 -070046 @Override
47 public Builder add(Instruction instruction) {
48 switch (instruction.type()) {
alshabib1d4cace2014-09-13 19:16:26 -070049 case DROP:
alshabib030111e2014-09-15 15:56:42 -070050 drop = true;
51 break;
52 case OUTPUT:
alshabib1d4cace2014-09-13 19:16:26 -070053 outputs.add(instruction);
54 break;
55 case MODIFICATION:
56 // TODO: enforce modification order if any
57 modifications.add(instruction);
alshabib030111e2014-09-15 15:56:42 -070058 break;
alshabib1d4cace2014-09-13 19:16:26 -070059 case GROUP:
60 groups.add(instruction);
alshabib030111e2014-09-15 15:56:42 -070061 break;
alshabib1d4cace2014-09-13 19:16:26 -070062 default:
63 log.warn("Unknown instruction type {}", instruction.type());
64 }
65 return this;
66 }
67
68 @Override
69 public TrafficTreatment build() {
alshabib030111e2014-09-15 15:56:42 -070070
71 //If we are dropping should we just return an emptry list?
alshabib1d4cace2014-09-13 19:16:26 -070072 List<Instruction> instructions = new LinkedList<Instruction>();
73 instructions.addAll(modifications);
74 instructions.addAll(groups);
alshabib030111e2014-09-15 15:56:42 -070075 if (!drop) {
76 instructions.addAll(outputs);
77 }
alshabib1d4cace2014-09-13 19:16:26 -070078
79 return new DefaultTrafficTreatment(instructions);
80 }
81
82 }
83
84}