alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.flow.instructions; |
| 2 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 3 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 4 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 5 | import java.util.Objects; |
| 6 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 7 | import org.onlab.packet.IpPrefix; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * Abstraction of a single traffic treatment step. |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 11 | */ |
| 12 | public abstract class L3ModificationInstruction implements Instruction { |
| 13 | |
| 14 | /** |
| 15 | * Represents the type of traffic treatment. |
| 16 | */ |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 17 | public enum L3SubType { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 18 | /** |
| 19 | * Ether src modification. |
| 20 | */ |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 21 | IP_SRC, |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Ether dst modification. |
| 25 | */ |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 26 | IP_DST |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 27 | |
| 28 | //TODO: remaining types |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Returns the subtype of the modification instruction. |
| 33 | * @return type of instruction |
| 34 | */ |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 35 | public abstract L3SubType subtype(); |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 36 | |
| 37 | @Override |
| 38 | public Type type() { |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 39 | return Type.L3MODIFICATION; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Represents a L3 src/dst modification instruction. |
| 44 | */ |
| 45 | public static final class ModIPInstruction extends L3ModificationInstruction { |
| 46 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 47 | private final L3SubType subtype; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 48 | private final IpPrefix ip; |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 49 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 50 | public ModIPInstruction(L3SubType subType, IpPrefix addr) { |
alshabib | 64231f6 | 2014-09-16 17:58:36 -0700 | [diff] [blame] | 51 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 52 | this.subtype = subType; |
| 53 | this.ip = addr; |
| 54 | } |
| 55 | |
| 56 | @Override |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 57 | public L3SubType subtype() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 58 | return this.subtype; |
| 59 | } |
| 60 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame] | 61 | public IpPrefix ip() { |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 62 | return this.ip; |
| 63 | } |
| 64 | |
alshabib | 99b8fdc | 2014-09-25 14:30:22 -0700 | [diff] [blame] | 65 | @Override |
| 66 | public String toString() { |
| 67 | return toStringHelper(subtype().toString()) |
| 68 | .add("ip", ip).toString(); |
| 69 | } |
| 70 | |
alshabib | 8ca5390 | 2014-10-07 13:11:17 -0700 | [diff] [blame] | 71 | @Override |
| 72 | public int hashCode() { |
| 73 | return Objects.hash(ip, subtype()); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public boolean equals(Object obj) { |
| 78 | if (this == obj) { |
| 79 | return true; |
| 80 | } |
| 81 | if (obj instanceof ModIPInstruction) { |
| 82 | ModIPInstruction that = (ModIPInstruction) obj; |
| 83 | return Objects.equals(ip, that.ip); |
| 84 | |
| 85 | } |
| 86 | return false; |
| 87 | } |
| 88 | |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 89 | } |
alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 90 | } |