alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.flow.instructions; |
| 2 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 3 | import org.onlab.packet.IpAddress; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 4 | |
| 5 | /** |
| 6 | * Abstraction of a single traffic treatment step. |
| 7 | * @param <T> the type parameter for the instruction |
| 8 | */ |
| 9 | public 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 Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 50 | private final IpAddress ip; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 51 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 52 | public ModIPInstruction(SubType subType, IpAddress addr) { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 53 | this.subtype = subType; |
| 54 | this.ip = addr; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public SubType subtype() { |
| 59 | return this.subtype; |
| 60 | } |
| 61 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 62 | public IpAddress ip() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 63 | 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 | } |