Showing
4 changed files
with
240 additions
and
10 deletions
| 1 | package org.onlab.onos.net.flow.criteria; | 1 | package org.onlab.onos.net.flow.criteria; |
| 2 | 2 | ||
| 3 | +import org.onlab.onos.net.PortNumber; | ||
| 4 | +import org.onlab.onos.net.flow.criteria.Criterion.Type; | ||
| 5 | +import org.onlab.packet.IPAddress; | ||
| 6 | +import org.onlab.packet.MACAddress; | ||
| 7 | +import org.onlab.packet.VLANID; | ||
| 8 | + | ||
| 3 | /** | 9 | /** |
| 4 | * Factory class to create various traffic selection criteria. | 10 | * Factory class to create various traffic selection criteria. |
| 5 | */ | 11 | */ |
| 6 | public final class Criteria { | 12 | public final class Criteria { |
| 7 | 13 | ||
| 14 | + //TODO: incomplete type implementation. Need to implement complete list from Criterion | ||
| 15 | + | ||
| 8 | // Ban construction | 16 | // Ban construction |
| 9 | private Criteria() { | 17 | private Criteria() { |
| 10 | } | 18 | } |
| 11 | 19 | ||
| 12 | /** | 20 | /** |
| 21 | + * Creates a match on IN_PORT field using the specified value. | ||
| 22 | + * | ||
| 23 | + * @param port inport value | ||
| 24 | + * @return match criterion | ||
| 25 | + */ | ||
| 26 | + public static Criterion matchInPort(PortNumber port) { | ||
| 27 | + return new PortCriterion(port); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /** | ||
| 13 | * Creates a match on ETH_SRC field using the specified value. This value | 31 | * Creates a match on ETH_SRC field using the specified value. This value |
| 14 | * may be a wildcard mask. | 32 | * may be a wildcard mask. |
| 15 | * | 33 | * |
| 16 | * @param macValue MAC address value or wildcard mask | 34 | * @param macValue MAC address value or wildcard mask |
| 17 | * @return match criterion | 35 | * @return match criterion |
| 18 | */ | 36 | */ |
| 19 | - public static Criterion matchEthSrc(MACValue macValue) { | 37 | + public static Criterion matchEthSrc(MACAddress mac) { |
| 20 | - return null; | 38 | + return new EthCriterion(mac, Type.ETH_SRC); |
| 21 | } | 39 | } |
| 22 | 40 | ||
| 23 | /** | 41 | /** |
| ... | @@ -27,11 +45,214 @@ public final class Criteria { | ... | @@ -27,11 +45,214 @@ public final class Criteria { |
| 27 | * @param macValue MAC address value or wildcard mask | 45 | * @param macValue MAC address value or wildcard mask |
| 28 | * @return match criterion | 46 | * @return match criterion |
| 29 | */ | 47 | */ |
| 30 | - public static Criterion matchEthDst(MACValue macValue) { | 48 | + public static Criterion matchEthDst(MACAddress mac) { |
| 31 | - return null; | 49 | + return new EthCriterion(mac, Type.ETH_DST); |
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * Creates a match on ETH_TYPE field using the specified value. | ||
| 54 | + * | ||
| 55 | + * @param ethType eth type value | ||
| 56 | + * @return match criterion | ||
| 57 | + */ | ||
| 58 | + public static Criterion matchEthType(Short ethType) { | ||
| 59 | + return new EthTypeCriterion(ethType); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Creates a match on VLAN ID field using the specified value. | ||
| 64 | + * | ||
| 65 | + * @param vlanId vlan id value | ||
| 66 | + * @return match criterion | ||
| 67 | + */ | ||
| 68 | + public static Criterion matchVlanId(VLANID vlanId) { | ||
| 69 | + return new VlanIdCriterion(vlanId); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * Creates a match on VLAN PCP field using the specified value. | ||
| 74 | + * | ||
| 75 | + * @param vlanPcp vlan pcp value | ||
| 76 | + * @return match criterion | ||
| 77 | + */ | ||
| 78 | + public static Criterion matchVlanId(Byte vlanPcp) { | ||
| 79 | + return new VlanPcpCriterion(vlanPcp); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * Creates a match on IP proto field using the specified value. | ||
| 84 | + * | ||
| 85 | + * @param proto ip protocol value | ||
| 86 | + * @return match criterion | ||
| 87 | + */ | ||
| 88 | + public static Criterion matchIPProtocol(Byte proto) { | ||
| 89 | + return new IPProtocolCriterion(proto); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * Creates a match on IP src field using the specified value. | ||
| 94 | + * | ||
| 95 | + * @param ip ip src value | ||
| 96 | + * @return match criterion | ||
| 97 | + */ | ||
| 98 | + public static Criterion matchIPSrc(IPAddress ip) { | ||
| 99 | + return new IPCriterion(ip, Type.IPV4_SRC); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Creates a match on IP dst field using the specified value. | ||
| 104 | + * | ||
| 105 | + * @param ip ip src value | ||
| 106 | + * @return match criterion | ||
| 107 | + */ | ||
| 108 | + public static Criterion matchIPDst(IPAddress ip) { | ||
| 109 | + return new IPCriterion(ip, Type.IPV4_DST); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + | ||
| 113 | + /* | ||
| 114 | + * Implementations of criteria. | ||
| 115 | + */ | ||
| 116 | + | ||
| 117 | + public static final class PortCriterion implements Criterion { | ||
| 118 | + private final PortNumber port; | ||
| 119 | + | ||
| 120 | + public PortCriterion(PortNumber port) { | ||
| 121 | + this.port = port; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @Override | ||
| 125 | + public Type type() { | ||
| 126 | + return Type.IN_PORT; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + public PortNumber port() { | ||
| 130 | + return this.port; | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + | ||
| 135 | + public static final class EthCriterion implements Criterion { | ||
| 136 | + private final MACAddress mac; | ||
| 137 | + private final Type type; | ||
| 138 | + | ||
| 139 | + public EthCriterion(MACAddress mac, Type type) { | ||
| 140 | + this.mac = mac; | ||
| 141 | + this.type = type; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + @Override | ||
| 145 | + public Type type() { | ||
| 146 | + return this.type; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + public MACAddress mac() { | ||
| 150 | + return this.mac; | ||
| 151 | + } | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + public static final class EthTypeCriterion implements Criterion { | ||
| 155 | + | ||
| 156 | + private final Short ethType; | ||
| 157 | + | ||
| 158 | + public EthTypeCriterion(Short ethType) { | ||
| 159 | + this.ethType = ethType; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + @Override | ||
| 163 | + public Type type() { | ||
| 164 | + return Type.ETH_TYPE; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + public Short ethType() { | ||
| 168 | + return ethType; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + | ||
| 174 | + public static final class IPCriterion implements Criterion { | ||
| 175 | + | ||
| 176 | + private final IPAddress ip; | ||
| 177 | + private final Type type; | ||
| 178 | + | ||
| 179 | + public IPCriterion(IPAddress ip, Type type) { | ||
| 180 | + this.ip = ip; | ||
| 181 | + this.type = type; | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + @Override | ||
| 185 | + public Type type() { | ||
| 186 | + return this.type; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + public IPAddress ip() { | ||
| 190 | + return this.ip; | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + | ||
| 197 | + public static final class IPProtocolCriterion implements Criterion { | ||
| 198 | + | ||
| 199 | + private final Byte proto; | ||
| 200 | + | ||
| 201 | + public IPProtocolCriterion(Byte protocol) { | ||
| 202 | + this.proto = protocol; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + @Override | ||
| 206 | + public Type type() { | ||
| 207 | + return Type.IP_PROTO; | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + public Byte protocol() { | ||
| 211 | + return proto; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + | ||
| 217 | + public static final class VlanPcpCriterion implements Criterion { | ||
| 218 | + | ||
| 219 | + private final Byte vlanPcp; | ||
| 220 | + | ||
| 221 | + public VlanPcpCriterion(Byte vlanPcp) { | ||
| 222 | + this.vlanPcp = vlanPcp; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + @Override | ||
| 226 | + public Type type() { | ||
| 227 | + return Type.VLAN_PCP; | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + public Byte protocol() { | ||
| 231 | + return vlanPcp; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + | ||
| 237 | + public static final class VlanIdCriterion implements Criterion { | ||
| 238 | + | ||
| 239 | + | ||
| 240 | + private final VLANID vlanId; | ||
| 241 | + | ||
| 242 | + public VlanIdCriterion(VLANID vlanId) { | ||
| 243 | + this.vlanId = vlanId; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + @Override | ||
| 247 | + public Type type() { | ||
| 248 | + return Type.VLAN_VID; | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + public VLANID vlanId() { | ||
| 252 | + return vlanId; | ||
| 253 | + } | ||
| 254 | + | ||
| 32 | } | 255 | } |
| 33 | 256 | ||
| 34 | 257 | ||
| 35 | - // Dummy to illustrate the concept for now; delete ASAP | ||
| 36 | - private static class MACValue { } | ||
| 37 | } | 258 | } | ... | ... |
| 1 | package org.onlab.onos.net.flow.criteria; | 1 | package org.onlab.onos.net.flow.criteria; |
| 2 | 2 | ||
| 3 | + | ||
| 3 | /** | 4 | /** |
| 4 | * Representation of a single header field selection. | 5 | * Representation of a single header field selection. |
| 5 | */ | 6 | */ |
| ... | @@ -92,6 +93,12 @@ public interface Criterion { | ... | @@ -92,6 +93,12 @@ public interface Criterion { |
| 92 | IPV6_EXTHDR | 93 | IPV6_EXTHDR |
| 93 | } | 94 | } |
| 94 | 95 | ||
| 96 | + /** | ||
| 97 | + * Returns the type of criterion. | ||
| 98 | + * @return type of criterion | ||
| 99 | + */ | ||
| 100 | + public Type type(); | ||
| 101 | + | ||
| 95 | // TODO: Create factory class 'Criteria' that will have various factory | 102 | // TODO: Create factory class 'Criteria' that will have various factory |
| 96 | // to create specific criterions. | 103 | // to create specific criterions. |
| 97 | 104 | ... | ... |
| ... | @@ -10,6 +10,7 @@ import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstr | ... | @@ -10,6 +10,7 @@ import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstr |
| 10 | import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPProtoInstruction; | 10 | import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPProtoInstruction; |
| 11 | import org.onlab.packet.IPAddress; | 11 | import org.onlab.packet.IPAddress; |
| 12 | import org.onlab.packet.MACAddress; | 12 | import org.onlab.packet.MACAddress; |
| 13 | +import org.onlab.packet.VLANID; | ||
| 13 | /** | 14 | /** |
| 14 | * Factory class for creating various traffic treatment instructions. | 15 | * Factory class for creating various traffic treatment instructions. |
| 15 | */ | 16 | */ |
| ... | @@ -74,7 +75,7 @@ public final class Instructions { | ... | @@ -74,7 +75,7 @@ public final class Instructions { |
| 74 | * @param vlanId the vlan id to modify to. | 75 | * @param vlanId the vlan id to modify to. |
| 75 | * @return a L2 modification | 76 | * @return a L2 modification |
| 76 | */ | 77 | */ |
| 77 | - public static L2ModificationInstruction modVlanId(Short vlanId) { | 78 | + public static L2ModificationInstruction modVlanId(VLANID vlanId) { |
| 78 | checkNotNull(vlanId, "VLAN id cannot be null"); | 79 | checkNotNull(vlanId, "VLAN id cannot be null"); |
| 79 | return new L2ModificationInstruction.ModVlanIdInstruction(vlanId); | 80 | return new L2ModificationInstruction.ModVlanIdInstruction(vlanId); |
| 80 | } | 81 | } | ... | ... |
| 1 | package org.onlab.onos.net.flow.instructions; | 1 | package org.onlab.onos.net.flow.instructions; |
| 2 | 2 | ||
| 3 | import org.onlab.packet.MACAddress; | 3 | import org.onlab.packet.MACAddress; |
| 4 | +import org.onlab.packet.VLANID; | ||
| 4 | 5 | ||
| 5 | /** | 6 | /** |
| 6 | * Abstraction of a single traffic treatment step. | 7 | * Abstraction of a single traffic treatment step. |
| ... | @@ -100,9 +101,9 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -100,9 +101,9 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 100 | */ | 101 | */ |
| 101 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { | 102 | public static final class ModVlanIdInstruction extends L2ModificationInstruction { |
| 102 | 103 | ||
| 103 | - public final Short vlanId; | 104 | + public final VLANID vlanId; |
| 104 | 105 | ||
| 105 | - public ModVlanIdInstruction(Short vlanId) { | 106 | + public ModVlanIdInstruction(VLANID vlanId) { |
| 106 | this.vlanId = vlanId; | 107 | this.vlanId = vlanId; |
| 107 | } | 108 | } |
| 108 | 109 | ||
| ... | @@ -111,7 +112,7 @@ public abstract class L2ModificationInstruction implements Instruction { | ... | @@ -111,7 +112,7 @@ public abstract class L2ModificationInstruction implements Instruction { |
| 111 | return L2SubType.VLAN_ID; | 112 | return L2SubType.VLAN_ID; |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | - public Short vlanId() { | 115 | + public VLANID vlanId() { |
| 115 | return this.vlanId; | 116 | return this.vlanId; |
| 116 | } | 117 | } |
| 117 | 118 | ... | ... |
-
Please register or login to post a comment