alshabib | 7410fea | 2014-09-16 13:48:39 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.flow.criteria; |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 2 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 3 | import org.onlab.onos.net.PortNumber; |
| 4 | import org.onlab.onos.net.flow.criteria.Criterion.Type; |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 5 | import org.onlab.packet.IpPrefix; |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 6 | import org.onlab.packet.MacAddress; |
| 7 | import org.onlab.packet.VlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 8 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 9 | /** |
| 10 | * Factory class to create various traffic selection criteria. |
| 11 | */ |
| 12 | public final class Criteria { |
| 13 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 14 | //TODO: incomplete type implementation. Need to implement complete list from Criterion |
| 15 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 16 | // Ban construction |
| 17 | private Criteria() { |
| 18 | } |
| 19 | |
| 20 | /** |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 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 | /** |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 31 | * Creates a match on ETH_SRC field using the specified value. This value |
| 32 | * may be a wildcard mask. |
| 33 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 34 | * @param mac MAC address value or wildcard mask |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 35 | * @return match criterion |
| 36 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 37 | public static Criterion matchEthSrc(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 38 | return new EthCriterion(mac, Type.ETH_SRC); |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 39 | } |
| 40 | |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 41 | /** |
| 42 | * Creates a match on ETH_DST field using the specified value. This value |
| 43 | * may be a wildcard mask. |
| 44 | * |
tom | c104d28 | 2014-09-19 10:57:55 -0700 | [diff] [blame] | 45 | * @param mac MAC address value or wildcard mask |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 46 | * @return match criterion |
| 47 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 48 | public static Criterion matchEthDst(MacAddress mac) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 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 | */ |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 68 | public static Criterion matchVlanId(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 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 | */ |
alshabib | b45d196 | 2014-09-18 14:25:45 -0700 | [diff] [blame] | 78 | public static Criterion matchVlanPcp(Byte vlanPcp) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 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 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 98 | public static Criterion matchIPSrc(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 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 | */ |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 108 | public static Criterion matchIPDst(IpPrefix ip) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 109 | return new IPCriterion(ip, Type.IPV4_DST); |
alshabib | 369d294 | 2014-09-12 17:59:35 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 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 { |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 136 | private final MacAddress mac; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 137 | private final Type type; |
| 138 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 139 | public EthCriterion(MacAddress mac, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 140 | this.mac = mac; |
| 141 | this.type = type; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public Type type() { |
| 146 | return this.type; |
| 147 | } |
| 148 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 149 | public MacAddress mac() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 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 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 176 | private final IpPrefix ip; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 177 | private final Type type; |
| 178 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 179 | public IPCriterion(IpPrefix ip, Type type) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 180 | this.ip = ip; |
| 181 | this.type = type; |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public Type type() { |
| 186 | return this.type; |
| 187 | } |
| 188 | |
Ayaka Koshibe | 1d56fe4 | 2014-09-19 16:51:58 -0700 | [diff] [blame^] | 189 | public IpPrefix ip() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 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 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 230 | public Byte priority() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 231 | return vlanPcp; |
| 232 | } |
| 233 | |
| 234 | } |
| 235 | |
| 236 | |
| 237 | public static final class VlanIdCriterion implements Criterion { |
| 238 | |
| 239 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 240 | private final VlanId vlanId; |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 241 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 242 | public VlanIdCriterion(VlanId vlanId) { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 243 | this.vlanId = vlanId; |
| 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public Type type() { |
| 248 | return Type.VLAN_VID; |
| 249 | } |
| 250 | |
Ayaka Koshibe | a9c199f | 2014-09-16 16:21:40 -0700 | [diff] [blame] | 251 | public VlanId vlanId() { |
alshabib | 7b79549 | 2014-09-16 14:38:39 -0700 | [diff] [blame] | 252 | return vlanId; |
| 253 | } |
| 254 | |
| 255 | } |
| 256 | |
| 257 | |
tom | 8bb1606 | 2014-09-12 14:47:46 -0700 | [diff] [blame] | 258 | } |