blob: d206c97feaa9bef6d7f1b245aff01c0f54671796 [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
9import org.onlab.onos.net.PortNumber;
10import org.slf4j.Logger;
11
12@SuppressWarnings("rawtypes")
13public class DefaultTrafficTreatment implements TrafficTreatment {
14
15 private final List<Instruction> instructions;
16
17 public DefaultTrafficTreatment(List<Instruction> instructions) {
18 this.instructions = Collections.unmodifiableList(instructions);
19 }
20
21 @Override
22 public List<Instruction> instructions() {
23 return instructions;
24 }
25
26 /**
27 * Builds a list of treatments following the following order.
28 * Modifications -> Group -> Output (including drop)
29 *
30 */
31
32 public static class Builder implements TrafficTreatment.Builder {
33
34 private final Logger log = getLogger(getClass());
35
36 List<Instruction<PortNumber>> outputs = new LinkedList<>();
37
38 // TODO: should be a list of instructions based on group objects
39 List<Instruction<Object>> groups = new LinkedList<>();
40
41 // TODO: should be a list of instructions based on modification objects
42 List<Instruction<Object>> modifications = new LinkedList<>();
43
44
45 @SuppressWarnings("unchecked")
46 @Override
47 public Builder add(Instruction instruction) {
48 switch (instruction.type()) {
49 case OUTPUT:
50 case DROP:
51 // TODO: should check that there is only one drop instruction.
52 outputs.add(instruction);
53 break;
54 case MODIFICATION:
55 // TODO: enforce modification order if any
56 modifications.add(instruction);
57 case GROUP:
58 groups.add(instruction);
59 default:
60 log.warn("Unknown instruction type {}", instruction.type());
61 }
62 return this;
63 }
64
65 @Override
66 public TrafficTreatment build() {
67 List<Instruction> instructions = new LinkedList<Instruction>();
68 instructions.addAll(modifications);
69 instructions.addAll(groups);
70 instructions.addAll(outputs);
71
72 return new DefaultTrafficTreatment(instructions);
73 }
74
75 }
76
77}