blob: 126c1f97448d8db6c1bfc894da15792b771e7c41 [file] [log] [blame]
alshabib7410fea2014-09-16 13:48:39 -07001package org.onlab.onos.net.flow.instructions;
2
Ayaka Koshibea9c199f2014-09-16 16:21:40 -07003import org.onlab.packet.IpAddress;
alshabib7410fea2014-09-16 13:48:39 -07004
5/**
6 * Abstraction of a single traffic treatment step.
7 * @param <T> the type parameter for the instruction
8 */
9public abstract class L3ModificationInstruction implements Instruction {
10
11 /**
12 * Represents the type of traffic treatment.
13 */
14 public enum L3SubType implements SubType {
15 /**
16 * Ether src modification.
17 */
18 L3_SRC,
19
20 /**
21 * Ether dst modification.
22 */
23 L3_DST,
24
25 /**
26 * Ethertype modification.
27 */
28 L3_PROTO,
29
30 //TODO: remaining types
31 }
32
33 /**
34 * Returns the subtype of the modification instruction.
35 * @return type of instruction
36 */
37 public abstract SubType subtype();
38
39 @Override
40 public Type type() {
41 return Type.MODIFICATION;
42 }
43
44 /**
45 * Represents a L3 src/dst modification instruction.
46 */
47 public static final class ModIPInstruction extends L3ModificationInstruction {
48
49 private final SubType subtype;
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070050 private final IpAddress ip;
alshabib7410fea2014-09-16 13:48:39 -070051
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070052 public ModIPInstruction(SubType subType, IpAddress addr) {
alshabib7410fea2014-09-16 13:48:39 -070053 this.subtype = subType;
54 this.ip = addr;
55 }
56
57 @Override
58 public SubType subtype() {
59 return this.subtype;
60 }
61
Ayaka Koshibea9c199f2014-09-16 16:21:40 -070062 public IpAddress ip() {
alshabib7410fea2014-09-16 13:48:39 -070063 return this.ip;
64 }
65
66 }
67
68 /**
69 * Represents a L3 proto modification instruction.
70 */
71 public static final class ModIPProtoInstruction extends L3ModificationInstruction {
72
73 public final Byte proto;
74
75 public ModIPProtoInstruction(Byte proto) {
76 this.proto = proto;
77 }
78
79 @Override
80 public SubType subtype() {
81 return L3SubType.L3_PROTO;
82 }
83
84 public short proto() {
85 return this.proto;
86 }
87
88 }
89}