blob: ae82cd940a33f298364bcfb4ec9038f89487b4bd [file] [log] [blame]
alshabib7410fea2014-09-16 13:48:39 -07001package org.onlab.onos.net.flow.instructions;
2
alshabib99b8fdc2014-09-25 14:30:22 -07003import static com.google.common.base.MoreObjects.toStringHelper;
4
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -07005import org.onlab.packet.IpPrefix;
alshabib7410fea2014-09-16 13:48:39 -07006
7/**
8 * Abstraction of a single traffic treatment step.
alshabib7410fea2014-09-16 13:48:39 -07009 */
10public abstract class L3ModificationInstruction implements Instruction {
11
12 /**
13 * Represents the type of traffic treatment.
14 */
alshabib35edb1a2014-09-16 17:44:44 -070015 public enum L3SubType {
alshabib7410fea2014-09-16 13:48:39 -070016 /**
17 * Ether src modification.
18 */
alshabib99b8fdc2014-09-25 14:30:22 -070019 IP_SRC,
alshabib7410fea2014-09-16 13:48:39 -070020
21 /**
22 * Ether dst modification.
23 */
alshabib99b8fdc2014-09-25 14:30:22 -070024 IP_DST
alshabib7410fea2014-09-16 13:48:39 -070025
26 //TODO: remaining types
27 }
28
29 /**
30 * Returns the subtype of the modification instruction.
31 * @return type of instruction
32 */
alshabib35edb1a2014-09-16 17:44:44 -070033 public abstract L3SubType subtype();
alshabib7410fea2014-09-16 13:48:39 -070034
35 @Override
36 public Type type() {
alshabib35edb1a2014-09-16 17:44:44 -070037 return Type.L3MODIFICATION;
alshabib7410fea2014-09-16 13:48:39 -070038 }
39
40 /**
41 * Represents a L3 src/dst modification instruction.
42 */
43 public static final class ModIPInstruction extends L3ModificationInstruction {
44
alshabib35edb1a2014-09-16 17:44:44 -070045 private final L3SubType subtype;
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070046 private final IpPrefix ip;
alshabib7410fea2014-09-16 13:48:39 -070047
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070048 public ModIPInstruction(L3SubType subType, IpPrefix addr) {
alshabib64231f62014-09-16 17:58:36 -070049
alshabib7410fea2014-09-16 13:48:39 -070050 this.subtype = subType;
51 this.ip = addr;
52 }
53
54 @Override
alshabib35edb1a2014-09-16 17:44:44 -070055 public L3SubType subtype() {
alshabib7410fea2014-09-16 13:48:39 -070056 return this.subtype;
57 }
58
Ayaka Koshibe1d56fe42014-09-19 16:51:58 -070059 public IpPrefix ip() {
alshabib7410fea2014-09-16 13:48:39 -070060 return this.ip;
61 }
62
alshabib99b8fdc2014-09-25 14:30:22 -070063 @Override
64 public String toString() {
65 return toStringHelper(subtype().toString())
66 .add("ip", ip).toString();
67 }
68
alshabib7410fea2014-09-16 13:48:39 -070069 }
alshabib7410fea2014-09-16 13:48:39 -070070}