tom

Merge remote-tracking branch 'origin/master'

...@@ -2,6 +2,8 @@ package org.onlab.onos.net.flow; ...@@ -2,6 +2,8 @@ package org.onlab.onos.net.flow;
2 2
3 import java.util.List; 3 import java.util.List;
4 4
5 +import org.onlab.onos.net.flow.criteria.Criterion;
6 +
5 /** 7 /**
6 * Abstraction of a slice of network traffic. 8 * Abstraction of a slice of network traffic.
7 */ 9 */
......
1 -package org.onlab.onos.net.flow; 1 +package org.onlab.onos.net.flow.criteria;
2 2
3 /** 3 /**
4 * Factory class to create various traffic selection criteria. 4 * Factory class to create various traffic selection criteria.
......
1 -package org.onlab.onos.net.flow; 1 +package org.onlab.onos.net.flow.criteria;
2 2
3 /** 3 /**
4 * Representation of a single header field selection. 4 * Representation of a single header field selection.
......
...@@ -5,6 +5,12 @@ package org.onlab.onos.net.flow.instructions; ...@@ -5,6 +5,12 @@ package org.onlab.onos.net.flow.instructions;
5 */ 5 */
6 public interface Instruction { 6 public interface Instruction {
7 7
8 + interface SubType { }
9 +
10 + public enum NoneSubType implements SubType {
11 + NONE;
12 + }
13 +
8 /** 14 /**
9 * Represents the type of traffic treatment. 15 * Represents the type of traffic treatment.
10 */ 16 */
...@@ -39,4 +45,10 @@ public interface Instruction { ...@@ -39,4 +45,10 @@ public interface Instruction {
39 */ 45 */
40 public Type type(); 46 public Type type();
41 47
48 + /**
49 + * Returns the subtype of the modification instruction.
50 + * @return type of instruction
51 + */
52 + public SubType subtype();
53 +
42 } 54 }
......
...@@ -3,8 +3,12 @@ package org.onlab.onos.net.flow.instructions; ...@@ -3,8 +3,12 @@ package org.onlab.onos.net.flow.instructions;
3 import static com.google.common.base.Preconditions.checkNotNull; 3 import static com.google.common.base.Preconditions.checkNotNull;
4 4
5 import org.onlab.onos.net.PortNumber; 5 import org.onlab.onos.net.PortNumber;
6 +import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.L2SubType;
6 import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; 7 import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
7 -import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.SubType; 8 +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.L3SubType;
9 +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
10 +import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPProtoInstruction;
11 +import org.onlab.packet.IPAddress;
8 import org.onlab.packet.MACAddress; 12 import org.onlab.packet.MACAddress;
9 /** 13 /**
10 * Factory class for creating various traffic treatment instructions. 14 * Factory class for creating various traffic treatment instructions.
...@@ -42,7 +46,7 @@ public final class Instructions { ...@@ -42,7 +46,7 @@ public final class Instructions {
42 */ 46 */
43 public static L2ModificationInstruction modL2Src(MACAddress addr) { 47 public static L2ModificationInstruction modL2Src(MACAddress addr) {
44 checkNotNull(addr, "Src l2 address cannot be null"); 48 checkNotNull(addr, "Src l2 address cannot be null");
45 - return new ModEtherInstruction(SubType.L2_SRC, addr); 49 + return new ModEtherInstruction(L2SubType.L2_SRC, addr);
46 } 50 }
47 51
48 /** 52 /**
...@@ -52,7 +56,7 @@ public final class Instructions { ...@@ -52,7 +56,7 @@ public final class Instructions {
52 */ 56 */
53 public static L2ModificationInstruction modL2Dst(MACAddress addr) { 57 public static L2ModificationInstruction modL2Dst(MACAddress addr) {
54 checkNotNull(addr, "Dst l2 address cannot be null"); 58 checkNotNull(addr, "Dst l2 address cannot be null");
55 - return new L2ModificationInstruction.ModEtherInstruction(SubType.L2_DST, addr); 59 + return new L2ModificationInstruction.ModEtherInstruction(L2SubType.L2_DST, addr);
56 } 60 }
57 61
58 /** 62 /**
...@@ -65,11 +69,56 @@ public final class Instructions { ...@@ -65,11 +69,56 @@ public final class Instructions {
65 return new L2ModificationInstruction.ModEtherTypeInstruction(l2Type); 69 return new L2ModificationInstruction.ModEtherTypeInstruction(l2Type);
66 } 70 }
67 71
72 + /**
73 + * Creates a Vlan id modification.
74 + * @param vlanId the vlan id to modify to.
75 + * @return a L2 modification
76 + */
68 public static L2ModificationInstruction modVlanId(Short vlanId) { 77 public static L2ModificationInstruction modVlanId(Short vlanId) {
69 checkNotNull(vlanId, "VLAN id cannot be null"); 78 checkNotNull(vlanId, "VLAN id cannot be null");
70 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId); 79 return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
71 } 80 }
72 81
82 + /**
83 + * Creates a Vlan pcp modification.
84 + * @param vlanPcp the pcp to modify to.
85 + * @return a L2 modification
86 + */
87 + public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
88 + checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
89 + return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
90 + }
91 +
92 + /**
93 + * Creates a L3 src modification.
94 + * @param addr the ip address to modify to.
95 + * @return a L3 modification
96 + */
97 + public static L3ModificationInstruction modL3Src(IPAddress addr) {
98 + checkNotNull(addr, "Src l3 address cannot be null");
99 + return new ModIPInstruction(L3SubType.L3_SRC, addr);
100 + }
101 +
102 + /**
103 + * Creates a L3 dst modification.
104 + * @param addr the ip address to modify to.
105 + * @return a L3 modification
106 + */
107 + public static L3ModificationInstruction modL3Dst(IPAddress addr) {
108 + checkNotNull(addr, "Dst l3 address cannot be null");
109 + return new ModIPInstruction(L3SubType.L3_DST, addr);
110 + }
111 +
112 + /**
113 + * Creates an L3 protocol modification.
114 + * @param proto the protocol to change to
115 + * @return a L3 modification
116 + */
117 + public static L3ModificationInstruction modIPProto(Byte proto) {
118 + checkNotNull(proto, "IP protocol cannot be null");
119 + return new ModIPProtoInstruction(proto);
120 + }
121 +
73 /* 122 /*
74 * Output instructions 123 * Output instructions
75 */ 124 */
...@@ -79,6 +128,11 @@ public final class Instructions { ...@@ -79,6 +128,11 @@ public final class Instructions {
79 public Type type() { 128 public Type type() {
80 return Type.DROP; 129 return Type.DROP;
81 } 130 }
131 +
132 + @Override
133 + public SubType subtype() {
134 + return NoneSubType.NONE;
135 + }
82 } 136 }
83 137
84 138
...@@ -97,6 +151,11 @@ public final class Instructions { ...@@ -97,6 +151,11 @@ public final class Instructions {
97 public Type type() { 151 public Type type() {
98 return Type.OUTPUT; 152 return Type.OUTPUT;
99 } 153 }
154 +
155 + @Override
156 + public SubType subtype() {
157 + return NoneSubType.NONE;
158 + }
100 } 159 }
101 160
102 } 161 }
......
...@@ -11,7 +11,7 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -11,7 +11,7 @@ public abstract class L2ModificationInstruction implements Instruction {
11 /** 11 /**
12 * Represents the type of traffic treatment. 12 * Represents the type of traffic treatment.
13 */ 13 */
14 - public enum SubType { 14 + public enum L2SubType implements SubType {
15 /** 15 /**
16 * Ether src modification. 16 * Ether src modification.
17 */ 17 */
...@@ -41,10 +41,7 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -41,10 +41,7 @@ public abstract class L2ModificationInstruction implements Instruction {
41 // TODO: Create factory class 'Instructions' that will have various factory 41 // TODO: Create factory class 'Instructions' that will have various factory
42 // to create specific instructions. 42 // to create specific instructions.
43 43
44 - /** 44 + @Override
45 - * Returns the subtype of the modification instruction.
46 - * @return type of instruction
47 - */
48 public abstract SubType subtype(); 45 public abstract SubType subtype();
49 46
50 @Override 47 @Override
...@@ -89,7 +86,7 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -89,7 +86,7 @@ public abstract class L2ModificationInstruction implements Instruction {
89 86
90 @Override 87 @Override
91 public SubType subtype() { 88 public SubType subtype() {
92 - return SubType.L2_TYPE; 89 + return L2SubType.L2_TYPE;
93 } 90 }
94 91
95 public short l2Type() { 92 public short l2Type() {
...@@ -111,7 +108,7 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -111,7 +108,7 @@ public abstract class L2ModificationInstruction implements Instruction {
111 108
112 @Override 109 @Override
113 public SubType subtype() { 110 public SubType subtype() {
114 - return SubType.VLAN_ID; 111 + return L2SubType.VLAN_ID;
115 } 112 }
116 113
117 public Short vlanId() { 114 public Short vlanId() {
...@@ -120,5 +117,27 @@ public abstract class L2ModificationInstruction implements Instruction { ...@@ -120,5 +117,27 @@ public abstract class L2ModificationInstruction implements Instruction {
120 117
121 } 118 }
122 119
120 + /**
121 + * Represents a VLAN PCP modification instruction.
122 + */
123 + public static final class ModVlanPcpInstruction extends L2ModificationInstruction {
124 +
125 + public final Byte vlanPcp;
126 +
127 + public ModVlanPcpInstruction(Byte vlanPcp) {
128 + this.vlanPcp = vlanPcp;
129 + }
130 +
131 + @Override
132 + public SubType subtype() {
133 + return L2SubType.VLAN_PCP;
134 + }
135 +
136 + public Byte vlanPcp() {
137 + return this.vlanPcp;
138 + }
139 +
140 + }
141 +
123 142
124 } 143 }
......
1 +package org.onlab.onos.net.flow.instructions;
2 +
3 +import org.onlab.packet.IPAddress;
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;
50 + private final IPAddress ip;
51 +
52 + public ModIPInstruction(SubType subType, IPAddress addr) {
53 + this.subtype = subType;
54 + this.ip = addr;
55 + }
56 +
57 + @Override
58 + public SubType subtype() {
59 + return this.subtype;
60 + }
61 +
62 + public IPAddress ip() {
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 +}