Pavlin Radoslavov

Implement some of the missing Selector and Match Conditions

Work toward ONOS-509

The following match conditions are added/implemented:
 - UDP_SRC, UDP_DST
 - SCTP_SRC, SCTP_DST
 - ICMPV4_TYPE, ICMPV4_CODE
 - IPV6_FLABEL
 - IPV6_ND_TARGET
 - IPV6_ND_SLL
 - IPV6_ND_TLL

Also:
 * Renamed method
     TrafficSelector.Builder.matchInport(PortNumber port)
   to
     TrafficSelector.Builder.matchInPort(PortNumber port)
   (for consistency with the corresponding method(s) elsewhere)
 * Reordered the code for some of the existing matching conditions
   to follow the order in the OpenFlow spec, so it is easier to
   cross-reference such code.
 * Added missing Javadoc
 * Added few more Criterion.Type values as per OpenFlow spec 1.5.0

Change-Id: I7fc1656f32d8a7280c67d7827e4aa84528b0eafc
...@@ -288,7 +288,7 @@ public class ReactiveForwarding { ...@@ -288,7 +288,7 @@ public class ReactiveForwarding {
288 builder.matchEthType(inPkt.getEtherType()) 288 builder.matchEthType(inPkt.getEtherType())
289 .matchEthSrc(inPkt.getSourceMAC()) 289 .matchEthSrc(inPkt.getSourceMAC())
290 .matchEthDst(inPkt.getDestinationMAC()) 290 .matchEthDst(inPkt.getDestinationMAC())
291 - .matchInport(context.inPacket().receivedFrom().port()); 291 + .matchInPort(context.inPacket().receivedFrom().port());
292 292
293 TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder(); 293 TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
294 treat.setOutput(portNumber); 294 treat.setOutput(portNumber);
......
...@@ -107,21 +107,21 @@ public class LambdaForwarding { ...@@ -107,21 +107,21 @@ public class LambdaForwarding {
107 case 1: 107 case 1:
108 inport = 10; 108 inport = 10;
109 outport = 20; 109 outport = 20;
110 - sbuilder.matchInport(PortNumber.portNumber(inport)); 110 + sbuilder.matchInPort(PortNumber.portNumber(inport));
111 tbuilder.setOutput(PortNumber.portNumber(outport)).setLambda(lambda); 111 tbuilder.setOutput(PortNumber.portNumber(outport)).setLambda(lambda);
112 break; 112 break;
113 case 2: 113 case 2:
114 inport = 21; 114 inport = 21;
115 outport = 11; 115 outport = 11;
116 sbuilder.matchLambda(lambda). 116 sbuilder.matchLambda(lambda).
117 - matchInport(PortNumber.portNumber(inport)); // match sigtype 117 + matchInPort(PortNumber.portNumber(inport)); // match sigtype
118 tbuilder.setOutput(PortNumber.portNumber(outport)); 118 tbuilder.setOutput(PortNumber.portNumber(outport));
119 break; 119 break;
120 case 3: 120 case 3:
121 inport = 30; 121 inport = 30;
122 outport = 31; 122 outport = 31;
123 sbuilder.matchLambda(lambda). 123 sbuilder.matchLambda(lambda).
124 - matchInport(PortNumber.portNumber(inport)); 124 + matchInPort(PortNumber.portNumber(inport));
125 tbuilder.setOutput(PortNumber.portNumber(outport)).setLambda(lambda); 125 tbuilder.setOutput(PortNumber.portNumber(outport)).setLambda(lambda);
126 break; 126 break;
127 default: 127 default:
......
...@@ -106,7 +106,7 @@ public class MPLSForwarding { ...@@ -106,7 +106,7 @@ public class MPLSForwarding {
106 106
107 switch (switchNumber) { 107 switch (switchNumber) {
108 case 1: 108 case 1:
109 - sbuilder.matchInport(PortNumber.portNumber(inport)); 109 + sbuilder.matchInPort(PortNumber.portNumber(inport));
110 tbuilder.setOutput(PortNumber.portNumber(outport)) 110 tbuilder.setOutput(PortNumber.portNumber(outport))
111 .pushMpls() 111 .pushMpls()
112 .setMpls(mplsLabel); 112 .setMpls(mplsLabel);
...@@ -114,13 +114,13 @@ public class MPLSForwarding { ...@@ -114,13 +114,13 @@ public class MPLSForwarding {
114 case 2: 114 case 2:
115 sbuilder.matchMplsLabel(mplsLabel) 115 sbuilder.matchMplsLabel(mplsLabel)
116 .matchEthType(Ethernet.MPLS_UNICAST) 116 .matchEthType(Ethernet.MPLS_UNICAST)
117 - .matchInport(PortNumber.portNumber(inport)); 117 + .matchInPort(PortNumber.portNumber(inport));
118 tbuilder.setOutput(PortNumber.portNumber(outport)); 118 tbuilder.setOutput(PortNumber.portNumber(outport));
119 break; 119 break;
120 case 3: 120 case 3:
121 sbuilder.matchMplsLabel(mplsLabel) 121 sbuilder.matchMplsLabel(mplsLabel)
122 .matchEthType(Ethernet.MPLS_UNICAST) 122 .matchEthType(Ethernet.MPLS_UNICAST)
123 - .matchInport(PortNumber.portNumber(inport)); 123 + .matchInPort(PortNumber.portNumber(inport));
124 tbuilder.popMpls().setOutput(PortNumber.portNumber(outport)); 124 tbuilder.popMpls().setOutput(PortNumber.portNumber(outport));
125 break; 125 break;
126 default: 126 default:
......
...@@ -24,6 +24,7 @@ import org.onosproject.net.PortNumber; ...@@ -24,6 +24,7 @@ import org.onosproject.net.PortNumber;
24 import org.onosproject.net.flow.criteria.Criteria; 24 import org.onosproject.net.flow.criteria.Criteria;
25 import org.onosproject.net.flow.criteria.Criterion; 25 import org.onosproject.net.flow.criteria.Criterion;
26 import org.onlab.packet.IpPrefix; 26 import org.onlab.packet.IpPrefix;
27 +import org.onlab.packet.Ip6Address;
27 import org.onlab.packet.MacAddress; 28 import org.onlab.packet.MacAddress;
28 import org.onlab.packet.VlanId; 29 import org.onlab.packet.VlanId;
29 30
...@@ -129,22 +130,22 @@ public final class DefaultTrafficSelector implements TrafficSelector { ...@@ -129,22 +130,22 @@ public final class DefaultTrafficSelector implements TrafficSelector {
129 } 130 }
130 131
131 @Override 132 @Override
132 - public Builder matchInport(PortNumber port) { 133 + public Builder matchInPort(PortNumber port) {
133 return add(Criteria.matchInPort(port)); 134 return add(Criteria.matchInPort(port));
134 } 135 }
135 136
136 @Override 137 @Override
137 - public Builder matchEthSrc(MacAddress addr) { 138 + public Builder matchEthDst(MacAddress addr) {
138 - return add(Criteria.matchEthSrc(addr)); 139 + return add(Criteria.matchEthDst(addr));
139 } 140 }
140 141
141 @Override 142 @Override
142 - public Builder matchEthDst(MacAddress addr) { 143 + public Builder matchEthSrc(MacAddress addr) {
143 - return add(Criteria.matchEthDst(addr)); 144 + return add(Criteria.matchEthSrc(addr));
144 } 145 }
145 146
146 @Override 147 @Override
147 - public Builder matchEthType(short ethType) { 148 + public Builder matchEthType(Short ethType) {
148 return add(Criteria.matchEthType(ethType)); 149 return add(Criteria.matchEthType(ethType));
149 } 150 }
150 151
...@@ -184,6 +185,36 @@ public final class DefaultTrafficSelector implements TrafficSelector { ...@@ -184,6 +185,36 @@ public final class DefaultTrafficSelector implements TrafficSelector {
184 } 185 }
185 186
186 @Override 187 @Override
188 + public Builder matchUdpSrc(Short udpPort) {
189 + return add(Criteria.matchUdpSrc(udpPort));
190 + }
191 +
192 + @Override
193 + public Builder matchUdpDst(Short udpPort) {
194 + return add(Criteria.matchUdpDst(udpPort));
195 + }
196 +
197 + @Override
198 + public Builder matchSctpSrc(Short sctpPort) {
199 + return add(Criteria.matchSctpSrc(sctpPort));
200 + }
201 +
202 + @Override
203 + public Builder matchSctpDst(Short sctpPort) {
204 + return add(Criteria.matchSctpDst(sctpPort));
205 + }
206 +
207 + @Override
208 + public Builder matchIcmpType(Byte icmpType) {
209 + return add(Criteria.matchIcmpType(icmpType));
210 + }
211 +
212 + @Override
213 + public Builder matchIcmpCode(Byte icmpCode) {
214 + return add(Criteria.matchIcmpCode(icmpCode));
215 + }
216 +
217 + @Override
187 public Builder matchIPv6Src(IpPrefix ip) { 218 public Builder matchIPv6Src(IpPrefix ip) {
188 return add(Criteria.matchIPv6Src(ip)); 219 return add(Criteria.matchIPv6Src(ip));
189 } 220 }
...@@ -194,6 +225,11 @@ public final class DefaultTrafficSelector implements TrafficSelector { ...@@ -194,6 +225,11 @@ public final class DefaultTrafficSelector implements TrafficSelector {
194 } 225 }
195 226
196 @Override 227 @Override
228 + public Builder matchIPv6FlowLabel(Integer flowLabel) {
229 + return add(Criteria.matchIPv6FlowLabel(flowLabel));
230 + }
231 +
232 + @Override
197 public Builder matchIcmpv6Type(Byte icmpv6Type) { 233 public Builder matchIcmpv6Type(Byte icmpv6Type) {
198 return add(Criteria.matchIcmpv6Type(icmpv6Type)); 234 return add(Criteria.matchIcmpv6Type(icmpv6Type));
199 } 235 }
...@@ -204,6 +240,21 @@ public final class DefaultTrafficSelector implements TrafficSelector { ...@@ -204,6 +240,21 @@ public final class DefaultTrafficSelector implements TrafficSelector {
204 } 240 }
205 241
206 @Override 242 @Override
243 + public Builder matchIPv6NDTargetAddress(Ip6Address targetAddress) {
244 + return add(Criteria.matchIPv6NDTargetAddress(targetAddress));
245 + }
246 +
247 + @Override
248 + public Builder matchIPv6NDSourceLinkLayerAddress(MacAddress mac) {
249 + return add(Criteria.matchIPv6NDSourceLinkLayerAddress(mac));
250 + }
251 +
252 + @Override
253 + public Builder matchIPv6NDTargetLinkLayerAddress(MacAddress mac) {
254 + return add(Criteria.matchIPv6NDTargetLinkLayerAddress(mac));
255 + }
256 +
257 + @Override
207 public Builder matchMplsLabel(Integer mplsLabel) { 258 public Builder matchMplsLabel(Integer mplsLabel) {
208 return add(Criteria.matchMplsLabel(mplsLabel)); 259 return add(Criteria.matchMplsLabel(mplsLabel));
209 } 260 }
......
...@@ -20,6 +20,7 @@ import java.util.Set; ...@@ -20,6 +20,7 @@ import java.util.Set;
20 import org.onosproject.net.PortNumber; 20 import org.onosproject.net.PortNumber;
21 import org.onosproject.net.flow.criteria.Criterion; 21 import org.onosproject.net.flow.criteria.Criterion;
22 import org.onlab.packet.IpPrefix; 22 import org.onlab.packet.IpPrefix;
23 +import org.onlab.packet.Ip6Address;
23 import org.onlab.packet.MacAddress; 24 import org.onlab.packet.MacAddress;
24 import org.onlab.packet.VlanId; 25 import org.onlab.packet.VlanId;
25 26
...@@ -64,23 +65,23 @@ public interface TrafficSelector { ...@@ -64,23 +65,23 @@ public interface TrafficSelector {
64 * @param port the inport 65 * @param port the inport
65 * @return a selection builder 66 * @return a selection builder
66 */ 67 */
67 - public Builder matchInport(PortNumber port); 68 + public Builder matchInPort(PortNumber port);
68 69
69 /** 70 /**
70 - * Matches a l2 src address. 71 + * Matches a l2 dst address.
71 * 72 *
72 * @param addr a l2 address 73 * @param addr a l2 address
73 * @return a selection builder 74 * @return a selection builder
74 */ 75 */
75 - public Builder matchEthSrc(MacAddress addr); 76 + public Builder matchEthDst(MacAddress addr);
76 77
77 /** 78 /**
78 - * Matches a l2 dst address. 79 + * Matches a l2 src address.
79 * 80 *
80 * @param addr a l2 address 81 * @param addr a l2 address
81 * @return a selection builder 82 * @return a selection builder
82 */ 83 */
83 - public Builder matchEthDst(MacAddress addr); 84 + public Builder matchEthSrc(MacAddress addr);
84 85
85 /** 86 /**
86 * Matches the ethernet type. 87 * Matches the ethernet type.
...@@ -88,7 +89,7 @@ public interface TrafficSelector { ...@@ -88,7 +89,7 @@ public interface TrafficSelector {
88 * @param ethType an ethernet type 89 * @param ethType an ethernet type
89 * @return a selection builder 90 * @return a selection builder
90 */ 91 */
91 - public Builder matchEthType(short ethType); 92 + public Builder matchEthType(Short ethType);
92 93
93 /** 94 /**
94 * Matches the vlan id. 95 * Matches the vlan id.
...@@ -147,6 +148,54 @@ public interface TrafficSelector { ...@@ -147,6 +148,54 @@ public interface TrafficSelector {
147 public Builder matchTcpDst(Short tcpPort); 148 public Builder matchTcpDst(Short tcpPort);
148 149
149 /** 150 /**
151 + * Matches an UDP source port number.
152 + *
153 + * @param udpPort an UDP source port number
154 + * @return a selection builder
155 + */
156 + public Builder matchUdpSrc(Short udpPort);
157 +
158 + /**
159 + * Matches an UDP destination port number.
160 + *
161 + * @param udpPort an UDP destination port number
162 + * @return a selection builder
163 + */
164 + public Builder matchUdpDst(Short udpPort);
165 +
166 + /**
167 + * Matches a SCTP source port number.
168 + *
169 + * @param sctpPort a SCTP source port number
170 + * @return a selection builder
171 + */
172 + public Builder matchSctpSrc(Short sctpPort);
173 +
174 + /**
175 + * Matches a SCTP destination port number.
176 + *
177 + * @param sctpPort a SCTP destination port number
178 + * @return a selection builder
179 + */
180 + public Builder matchSctpDst(Short sctpPort);
181 +
182 + /**
183 + * Matches an ICMP type.
184 + *
185 + * @param icmpType an ICMP type
186 + * @return a selection builder
187 + */
188 + public Builder matchIcmpType(Byte icmpType);
189 +
190 + /**
191 + * Matches an ICMP code.
192 + *
193 + * @param icmpCode an ICMP code
194 + * @return a selection builder
195 + */
196 + public Builder matchIcmpCode(Byte icmpCode);
197 +
198 + /**
150 * Matches a l3 IPv6 address. 199 * Matches a l3 IPv6 address.
151 * 200 *
152 * @param ip a l3 IPv6 address 201 * @param ip a l3 IPv6 address
...@@ -163,23 +212,56 @@ public interface TrafficSelector { ...@@ -163,23 +212,56 @@ public interface TrafficSelector {
163 public Builder matchIPv6Dst(IpPrefix ip); 212 public Builder matchIPv6Dst(IpPrefix ip);
164 213
165 /** 214 /**
166 - * Matches a ICMPv6 type. 215 + * Matches an IPv6 flow label.
167 * 216 *
168 - * @param icmpv6Type a ICMPv6 type 217 + * @param flowLabel an IPv6 flow label
218 + * @return a selection builder
219 + */
220 + public Builder matchIPv6FlowLabel(Integer flowLabel);
221 +
222 + /**
223 + * Matches an ICMPv6 type.
224 + *
225 + * @param icmpv6Type an ICMPv6 type
169 * @return a selection builder 226 * @return a selection builder
170 */ 227 */
171 public Builder matchIcmpv6Type(Byte icmpv6Type); 228 public Builder matchIcmpv6Type(Byte icmpv6Type);
172 229
173 /** 230 /**
174 - * Matches a ICMPv6 code. 231 + * Matches an ICMPv6 code.
175 * 232 *
176 - * @param icmpv6Code a ICMPv6 code 233 + * @param icmpv6Code an ICMPv6 code
177 * @return a selection builder 234 * @return a selection builder
178 */ 235 */
179 public Builder matchIcmpv6Code(Byte icmpv6Code); 236 public Builder matchIcmpv6Code(Byte icmpv6Code);
180 237
181 /** 238 /**
182 - * Matches on a MPLS label . 239 + * Matches an IPv6 Neighbor Discovery target address.
240 + *
241 + * @param targetAddress an IPv6 Neighbor Discovery target address
242 + * @return a selection builder
243 + */
244 + public Builder matchIPv6NDTargetAddress(Ip6Address targetAddress);
245 +
246 + /**
247 + * Matches an IPv6 Neighbor Discovery source link-layer address.
248 + *
249 + * @param mac an IPv6 Neighbor Discovery source link-layer address
250 + * @return a selection builder
251 + */
252 + public Builder matchIPv6NDSourceLinkLayerAddress(MacAddress mac);
253 +
254 + /**
255 + * Matches an IPv6 Neighbor Discovery target link-layer address.
256 + *
257 + * @param mac an IPv6 Neighbor Discovery target link-layer address
258 + * @return a selection builder
259 + */
260 + public Builder matchIPv6NDTargetLinkLayerAddress(MacAddress mac);
261 +
262 + /**
263 + * Matches on a MPLS label.
264 + *
183 * @param mplsLabel a MPLS label. 265 * @param mplsLabel a MPLS label.
184 * @return a selection builder 266 * @return a selection builder
185 */ 267 */
...@@ -208,5 +290,4 @@ public interface TrafficSelector { ...@@ -208,5 +290,4 @@ public interface TrafficSelector {
208 */ 290 */
209 TrafficSelector build(); 291 TrafficSelector build();
210 } 292 }
211 -
212 } 293 }
......
...@@ -21,6 +21,7 @@ import java.util.Objects; ...@@ -21,6 +21,7 @@ import java.util.Objects;
21 import org.onosproject.net.PortNumber; 21 import org.onosproject.net.PortNumber;
22 import org.onosproject.net.flow.criteria.Criterion.Type; 22 import org.onosproject.net.flow.criteria.Criterion.Type;
23 import org.onlab.packet.IpPrefix; 23 import org.onlab.packet.IpPrefix;
24 +import org.onlab.packet.Ip6Address;
24 import org.onlab.packet.MacAddress; 25 import org.onlab.packet.MacAddress;
25 import org.onlab.packet.VlanId; 26 import org.onlab.packet.VlanId;
26 27
...@@ -46,25 +47,25 @@ public final class Criteria { ...@@ -46,25 +47,25 @@ public final class Criteria {
46 } 47 }
47 48
48 /** 49 /**
49 - * Creates a match on ETH_SRC field using the specified value. This value 50 + * Creates a match on ETH_DST field using the specified value. This value
50 * may be a wildcard mask. 51 * may be a wildcard mask.
51 * 52 *
52 * @param mac MAC address value or wildcard mask 53 * @param mac MAC address value or wildcard mask
53 * @return match criterion 54 * @return match criterion
54 */ 55 */
55 - public static Criterion matchEthSrc(MacAddress mac) { 56 + public static Criterion matchEthDst(MacAddress mac) {
56 - return new EthCriterion(mac, Type.ETH_SRC); 57 + return new EthCriterion(mac, Type.ETH_DST);
57 } 58 }
58 59
59 /** 60 /**
60 - * Creates a match on ETH_DST field using the specified value. This value 61 + * Creates a match on ETH_SRC field using the specified value. This value
61 * may be a wildcard mask. 62 * may be a wildcard mask.
62 * 63 *
63 * @param mac MAC address value or wildcard mask 64 * @param mac MAC address value or wildcard mask
64 * @return match criterion 65 * @return match criterion
65 */ 66 */
66 - public static Criterion matchEthDst(MacAddress mac) { 67 + public static Criterion matchEthSrc(MacAddress mac) {
67 - return new EthCriterion(mac, Type.ETH_DST); 68 + return new EthCriterion(mac, Type.ETH_SRC);
68 } 69 }
69 70
70 /** 71 /**
...@@ -148,6 +149,67 @@ public final class Criteria { ...@@ -148,6 +149,67 @@ public final class Criteria {
148 } 149 }
149 150
150 /** 151 /**
152 + * Creates a match on UDP source port field using the specified value.
153 + *
154 + * @param udpPort UDP source port
155 + * @return match criterion
156 + */
157 + public static Criterion matchUdpSrc(Short udpPort) {
158 + return new UdpPortCriterion(udpPort, Type.UDP_SRC);
159 + }
160 +
161 + /**
162 + * Creates a match on UDP destination port field using the specified value.
163 + *
164 + * @param udpPort UDP destination port
165 + * @return match criterion
166 + */
167 + public static Criterion matchUdpDst(Short udpPort) {
168 + return new UdpPortCriterion(udpPort, Type.UDP_DST);
169 + }
170 +
171 + /**
172 + * Creates a match on SCTP source port field using the specified value.
173 + *
174 + * @param sctpPort SCTP source port
175 + * @return match criterion
176 + */
177 + public static Criterion matchSctpSrc(Short sctpPort) {
178 + return new SctpPortCriterion(sctpPort, Type.SCTP_SRC);
179 + }
180 +
181 + /**
182 + * Creates a match on SCTP destination port field using the specified
183 + * value.
184 + *
185 + * @param sctpPort SCTP destination port
186 + * @return match criterion
187 + */
188 + public static Criterion matchSctpDst(Short sctpPort) {
189 + return new SctpPortCriterion(sctpPort, Type.SCTP_DST);
190 + }
191 +
192 + /**
193 + * Creates a match on ICMP type field using the specified value.
194 + *
195 + * @param icmpType ICMP type
196 + * @return match criterion
197 + */
198 + public static Criterion matchIcmpType(Byte icmpType) {
199 + return new IcmpTypeCriterion(icmpType);
200 + }
201 +
202 + /**
203 + * Creates a match on ICMP code field using the specified value.
204 + *
205 + * @param icmpCode ICMP code
206 + * @return match criterion
207 + */
208 + public static Criterion matchIcmpCode(Byte icmpCode) {
209 + return new IcmpCodeCriterion(icmpCode);
210 + }
211 +
212 + /**
151 * Creates a match on IPv6 source field using the specified value. 213 * Creates a match on IPv6 source field using the specified value.
152 * 214 *
153 * @param ip ipv6 source value 215 * @param ip ipv6 source value
...@@ -160,14 +222,24 @@ public final class Criteria { ...@@ -160,14 +222,24 @@ public final class Criteria {
160 /** 222 /**
161 * Creates a match on IPv6 destination field using the specified value. 223 * Creates a match on IPv6 destination field using the specified value.
162 * 224 *
163 - * @param ip ipv6 source value 225 + * @param ip ipv6 destination value
164 * @return match criterion 226 * @return match criterion
165 */ 227 */
166 public static Criterion matchIPv6Dst(IpPrefix ip) { 228 public static Criterion matchIPv6Dst(IpPrefix ip) {
167 return new IPCriterion(ip, Type.IPV6_DST); 229 return new IPCriterion(ip, Type.IPV6_DST);
168 } 230 }
169 231
170 - /* 232 + /**
233 + * Creates a match on IPv6 flow label field using the specified value.
234 + *
235 + * @param flowLabel IPv6 flow label
236 + * @return match criterion
237 + */
238 + public static Criterion matchIPv6FlowLabel(Integer flowLabel) {
239 + return new IPv6FlowLabelCriterion(flowLabel);
240 + }
241 +
242 + /**
171 * Creates a match on ICMPv6 type field using the specified value. 243 * Creates a match on ICMPv6 type field using the specified value.
172 * 244 *
173 * @param icmpv6Type ICMPv6 type 245 * @param icmpv6Type ICMPv6 type
...@@ -188,11 +260,44 @@ public final class Criteria { ...@@ -188,11 +260,44 @@ public final class Criteria {
188 } 260 }
189 261
190 /** 262 /**
263 + * Creates a match on IPv6 Neighbor Discovery target address using the
264 + * specified value.
265 + *
266 + * @param targetAddress IPv6 Neighbor Discovery target address
267 + * @return match criterion
268 + */
269 + public static Criterion matchIPv6NDTargetAddress(Ip6Address targetAddress) {
270 + return new IPv6NDTargetAddressCriterion(targetAddress);
271 + }
272 +
273 + /**
274 + * Creates a match on IPv6 Neighbor Discovery source link-layer address
275 + * using the specified value.
276 + *
277 + * @param mac IPv6 Neighbor Discovery source link-layer address
278 + * @return match criterion
279 + */
280 + public static Criterion matchIPv6NDSourceLinkLayerAddress(MacAddress mac) {
281 + return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_SLL);
282 + }
283 +
284 + /**
285 + * Creates a match on IPv6 Neighbor Discovery target link-layer address
286 + * using the specified value.
287 + *
288 + * @param mac IPv6 Neighbor Discovery target link-layer address
289 + * @return match criterion
290 + */
291 + public static Criterion matchIPv6NDTargetLinkLayerAddress(MacAddress mac) {
292 + return new IPv6NDLinkLayerAddressCriterion(mac, Type.IPV6_ND_TLL);
293 + }
294 +
295 + /**
191 * Creates a match on MPLS label. 296 * Creates a match on MPLS label.
297 + *
192 * @param mplsLabel MPLS label 298 * @param mplsLabel MPLS label
193 * @return match criterion 299 * @return match criterion
194 */ 300 */
195 -
196 public static Criterion matchMplsLabel(Integer mplsLabel) { 301 public static Criterion matchMplsLabel(Integer mplsLabel) {
197 return new MplsCriterion(mplsLabel); 302 return new MplsCriterion(mplsLabel);
198 } 303 }
...@@ -223,6 +328,11 @@ public final class Criteria { ...@@ -223,6 +328,11 @@ public final class Criteria {
223 public static final class PortCriterion implements Criterion { 328 public static final class PortCriterion implements Criterion {
224 private final PortNumber port; 329 private final PortNumber port;
225 330
331 + /**
332 + * Constructor.
333 + *
334 + * @param port the input port number to match
335 + */
226 public PortCriterion(PortNumber port) { 336 public PortCriterion(PortNumber port) {
227 this.port = port; 337 this.port = port;
228 } 338 }
...@@ -232,6 +342,11 @@ public final class Criteria { ...@@ -232,6 +342,11 @@ public final class Criteria {
232 return Type.IN_PORT; 342 return Type.IN_PORT;
233 } 343 }
234 344
345 + /**
346 + * Gets the input port number to match.
347 + *
348 + * @return the input port number to match
349 + */
235 public PortNumber port() { 350 public PortNumber port() {
236 return this.port; 351 return this.port;
237 } 352 }
...@@ -260,10 +375,8 @@ public final class Criteria { ...@@ -260,10 +375,8 @@ public final class Criteria {
260 } 375 }
261 return false; 376 return false;
262 } 377 }
263 -
264 } 378 }
265 379
266 -
267 /** 380 /**
268 * Implementation of MAC address criterion. 381 * Implementation of MAC address criterion.
269 */ 382 */
...@@ -271,6 +384,13 @@ public final class Criteria { ...@@ -271,6 +384,13 @@ public final class Criteria {
271 private final MacAddress mac; 384 private final MacAddress mac;
272 private final Type type; 385 private final Type type;
273 386
387 + /**
388 + * Constructor.
389 + *
390 + * @param mac the source or destination MAC address to match
391 + * @param type the match type. Should be either Type.ETH_DST or
392 + * Type.ETH_SRC
393 + */
274 public EthCriterion(MacAddress mac, Type type) { 394 public EthCriterion(MacAddress mac, Type type) {
275 this.mac = mac; 395 this.mac = mac;
276 this.type = type; 396 this.type = type;
...@@ -281,6 +401,11 @@ public final class Criteria { ...@@ -281,6 +401,11 @@ public final class Criteria {
281 return this.type; 401 return this.type;
282 } 402 }
283 403
404 + /**
405 + * Gets the MAC address to match.
406 + *
407 + * @return the MAC address to match
408 + */
284 public MacAddress mac() { 409 public MacAddress mac() {
285 return this.mac; 410 return this.mac;
286 } 411 }
...@@ -305,22 +430,22 @@ public final class Criteria { ...@@ -305,22 +430,22 @@ public final class Criteria {
305 EthCriterion that = (EthCriterion) obj; 430 EthCriterion that = (EthCriterion) obj;
306 return Objects.equals(mac, that.mac) && 431 return Objects.equals(mac, that.mac) &&
307 Objects.equals(type, that.type); 432 Objects.equals(type, that.type);
308 -
309 -
310 } 433 }
311 return false; 434 return false;
312 } 435 }
313 -
314 -
315 } 436 }
316 437
317 /** 438 /**
318 * Implementation of Ethernet type criterion. 439 * Implementation of Ethernet type criterion.
319 */ 440 */
320 public static final class EthTypeCriterion implements Criterion { 441 public static final class EthTypeCriterion implements Criterion {
321 -
322 private final Short ethType; 442 private final Short ethType;
323 443
444 + /**
445 + * Constructor.
446 + *
447 + * @param ethType the Ethernet frame type to match
448 + */
324 public EthTypeCriterion(Short ethType) { 449 public EthTypeCriterion(Short ethType) {
325 this.ethType = ethType; 450 this.ethType = ethType;
326 } 451 }
...@@ -330,6 +455,11 @@ public final class Criteria { ...@@ -330,6 +455,11 @@ public final class Criteria {
330 return Type.ETH_TYPE; 455 return Type.ETH_TYPE;
331 } 456 }
332 457
458 + /**
459 + * Gets the Ethernet frame type to match.
460 + *
461 + * @return the Ethernet frame type to match
462 + */
333 public Short ethType() { 463 public Short ethType() {
334 return ethType; 464 return ethType;
335 } 465 }
...@@ -360,40 +490,46 @@ public final class Criteria { ...@@ -360,40 +490,46 @@ public final class Criteria {
360 } 490 }
361 return false; 491 return false;
362 } 492 }
363 -
364 } 493 }
365 494
366 /** 495 /**
367 - * Implementation of IP address criterion. 496 + * Implementation of VLAN ID criterion.
368 */ 497 */
369 - public static final class IPCriterion implements Criterion { 498 + public static final class VlanIdCriterion implements Criterion {
370 - 499 + private final VlanId vlanId;
371 - private final IpPrefix ip;
372 - private final Type type;
373 500
374 - public IPCriterion(IpPrefix ip, Type type) { 501 + /**
375 - this.ip = ip; 502 + * Constructor.
376 - this.type = type; 503 + *
504 + * @param vlanId the VLAN ID to match
505 + */
506 + public VlanIdCriterion(VlanId vlanId) {
507 + this.vlanId = vlanId;
377 } 508 }
378 509
379 @Override 510 @Override
380 public Type type() { 511 public Type type() {
381 - return this.type; 512 + return Type.VLAN_VID;
382 } 513 }
383 514
384 - public IpPrefix ip() { 515 + /**
385 - return this.ip; 516 + * Gets the VLAN ID to match.
517 + *
518 + * @return the VLAN ID to match
519 + */
520 + public VlanId vlanId() {
521 + return vlanId;
386 } 522 }
387 523
388 @Override 524 @Override
389 public String toString() { 525 public String toString() {
390 return toStringHelper(type().toString()) 526 return toStringHelper(type().toString())
391 - .add("ip", ip).toString(); 527 + .add("vlanId", vlanId).toString();
392 } 528 }
393 529
394 @Override 530 @Override
395 public int hashCode() { 531 public int hashCode() {
396 - return Objects.hash(type, ip); 532 + return Objects.hash(type(), vlanId);
397 } 533 }
398 534
399 @Override 535 @Override
...@@ -401,25 +537,80 @@ public final class Criteria { ...@@ -401,25 +537,80 @@ public final class Criteria {
401 if (this == obj) { 537 if (this == obj) {
402 return true; 538 return true;
403 } 539 }
404 - if (obj instanceof IPCriterion) { 540 + if (obj instanceof VlanIdCriterion) {
405 - IPCriterion that = (IPCriterion) obj; 541 + VlanIdCriterion that = (VlanIdCriterion) obj;
406 - return Objects.equals(ip, that.ip) && 542 + return Objects.equals(vlanId, that.vlanId) &&
407 - Objects.equals(type, that.type); 543 + Objects.equals(this.type(), that.type());
544 + }
545 + return false;
546 + }
547 + }
548 +
549 + /**
550 + * Implementation of VLAN priority criterion.
551 + */
552 + public static final class VlanPcpCriterion implements Criterion {
553 + private final Byte vlanPcp;
408 554
555 + /**
556 + * Constructor.
557 + *
558 + * @param vlanPcp the VLAN priority to match
559 + */
560 + public VlanPcpCriterion(Byte vlanPcp) {
561 + this.vlanPcp = vlanPcp;
562 + }
563 +
564 + @Override
565 + public Type type() {
566 + return Type.VLAN_PCP;
567 + }
409 568
569 + /**
570 + * Gets the VLAN priority to match.
571 + *
572 + * @return the VLAN priority to match
573 + */
574 + public Byte priority() {
575 + return vlanPcp;
576 + }
577 +
578 + @Override
579 + public String toString() {
580 + return toStringHelper(type().toString())
581 + .add("priority", Long.toHexString(vlanPcp)).toString();
582 + }
583 +
584 + @Override
585 + public int hashCode() {
586 + return Objects.hash(type(), vlanPcp);
587 + }
588 +
589 + @Override
590 + public boolean equals(Object obj) {
591 + if (this == obj) {
592 + return true;
593 + }
594 + if (obj instanceof VlanPcpCriterion) {
595 + VlanPcpCriterion that = (VlanPcpCriterion) obj;
596 + return Objects.equals(vlanPcp, that.vlanPcp) &&
597 + Objects.equals(this.type(), that.type());
410 } 598 }
411 return false; 599 return false;
412 } 600 }
413 -
414 } 601 }
415 602
416 /** 603 /**
417 * Implementation of Internet Protocol Number criterion. 604 * Implementation of Internet Protocol Number criterion.
418 */ 605 */
419 public static final class IPProtocolCriterion implements Criterion { 606 public static final class IPProtocolCriterion implements Criterion {
420 -
421 private final Byte proto; 607 private final Byte proto;
422 608
609 + /**
610 + * Constructor.
611 + *
612 + * @param protocol the IP protocol to match (e.g., TCP=6, UDP=17).
613 + */
423 public IPProtocolCriterion(Byte protocol) { 614 public IPProtocolCriterion(Byte protocol) {
424 this.proto = protocol; 615 this.proto = protocol;
425 } 616 }
...@@ -429,6 +620,11 @@ public final class Criteria { ...@@ -429,6 +620,11 @@ public final class Criteria {
429 return Type.IP_PROTO; 620 return Type.IP_PROTO;
430 } 621 }
431 622
623 + /**
624 + * Gets the IP protocol to match.
625 + *
626 + * @return the IP protocol to match
627 + */
432 public Byte protocol() { 628 public Byte protocol() {
433 return proto; 629 return proto;
434 } 630 }
...@@ -453,43 +649,111 @@ public final class Criteria { ...@@ -453,43 +649,111 @@ public final class Criteria {
453 if (obj instanceof IPProtocolCriterion) { 649 if (obj instanceof IPProtocolCriterion) {
454 IPProtocolCriterion that = (IPProtocolCriterion) obj; 650 IPProtocolCriterion that = (IPProtocolCriterion) obj;
455 return Objects.equals(proto, that.proto); 651 return Objects.equals(proto, that.proto);
652 + }
653 + return false;
654 + }
655 + }
456 656
657 + /**
658 + * Implementation of IP address criterion.
659 + */
660 + public static final class IPCriterion implements Criterion {
661 + private final IpPrefix ip;
662 + private final Type type;
663 +
664 + /**
665 + * Constructor.
666 + *
667 + * @param ip the IP prefix to match. Could be either IPv4 or IPv6
668 + * @param type the match type. Should be one of the following:
669 + * Type.IPV4_SRC, Type.IPV4_DST, Type.IPV6_SRC, Type.IPV6_DST
670 + */
671 + public IPCriterion(IpPrefix ip, Type type) {
672 + this.ip = ip;
673 + this.type = type;
674 + }
675 +
676 + @Override
677 + public Type type() {
678 + return this.type;
679 + }
680 +
681 + /**
682 + * Gets the IP prefix to match.
683 + *
684 + * @return the IP prefix to match
685 + */
686 + public IpPrefix ip() {
687 + return this.ip;
688 + }
689 +
690 + @Override
691 + public String toString() {
692 + return toStringHelper(type().toString())
693 + .add("ip", ip).toString();
694 + }
695 +
696 + @Override
697 + public int hashCode() {
698 + return Objects.hash(type, ip);
699 + }
457 700
701 + @Override
702 + public boolean equals(Object obj) {
703 + if (this == obj) {
704 + return true;
705 + }
706 + if (obj instanceof IPCriterion) {
707 + IPCriterion that = (IPCriterion) obj;
708 + return Objects.equals(ip, that.ip) &&
709 + Objects.equals(type, that.type);
458 } 710 }
459 return false; 711 return false;
460 } 712 }
461 -
462 } 713 }
463 714
464 /** 715 /**
465 - * Implementation of VLAN priority criterion. 716 + * Implementation of TCP port criterion.
466 */ 717 */
467 - public static final class VlanPcpCriterion implements Criterion { 718 + public static final class TcpPortCriterion implements Criterion {
468 - 719 + private final Short tcpPort;
469 - private final Byte vlanPcp; 720 + private final Type type;
470 721
471 - public VlanPcpCriterion(Byte vlanPcp) { 722 + /**
472 - this.vlanPcp = vlanPcp; 723 + * Constructor.
724 + *
725 + * @param tcpPort the TCP port to match
726 + * @param type the match type. Should be either Type.TCP_SRC or
727 + * Type.TCP_DST
728 + */
729 + public TcpPortCriterion(Short tcpPort, Type type) {
730 + this.tcpPort = tcpPort;
731 + this.type = type;
473 } 732 }
474 733
475 @Override 734 @Override
476 public Type type() { 735 public Type type() {
477 - return Type.VLAN_PCP; 736 + return this.type;
478 } 737 }
479 738
480 - public Byte priority() { 739 + /**
481 - return vlanPcp; 740 + * Gets the TCP port to match.
741 + *
742 + * @return the TCP port to match
743 + */
744 + public Short tcpPort() {
745 + return this.tcpPort;
482 } 746 }
483 747
484 @Override 748 @Override
485 public String toString() { 749 public String toString() {
486 return toStringHelper(type().toString()) 750 return toStringHelper(type().toString())
487 - .add("pcp", Long.toHexString(vlanPcp)).toString(); 751 + .add("tcpPort", tcpPort & 0xffff).toString();
488 } 752 }
489 753
490 @Override 754 @Override
491 public int hashCode() { 755 public int hashCode() {
492 - return Objects.hash(type(), vlanPcp); 756 + return Objects.hash(type, tcpPort);
493 } 757 }
494 758
495 @Override 759 @Override
...@@ -497,48 +761,169 @@ public final class Criteria { ...@@ -497,48 +761,169 @@ public final class Criteria {
497 if (this == obj) { 761 if (this == obj) {
498 return true; 762 return true;
499 } 763 }
500 - if (obj instanceof VlanPcpCriterion) { 764 + if (obj instanceof TcpPortCriterion) {
501 - VlanPcpCriterion that = (VlanPcpCriterion) obj; 765 + TcpPortCriterion that = (TcpPortCriterion) obj;
502 - return Objects.equals(vlanPcp, that.vlanPcp) && 766 + return Objects.equals(tcpPort, that.tcpPort) &&
503 - Objects.equals(this.type(), that.type()); 767 + Objects.equals(type, that.type);
768 + }
769 + return false;
770 + }
771 + }
772 +
773 + /**
774 + * Implementation of UDP port criterion.
775 + */
776 + public static final class UdpPortCriterion implements Criterion {
777 + private final Short udpPort;
778 + private final Type type;
504 779
780 + /**
781 + * Constructor.
782 + *
783 + * @param udpPort the UDP port to match
784 + * @param type the match type. Should be either Type.UDP_SRC or
785 + * Type.UDP_DST
786 + */
787 + public UdpPortCriterion(Short udpPort, Type type) {
788 + this.udpPort = udpPort;
789 + this.type = type;
790 + }
791 +
792 + @Override
793 + public Type type() {
794 + return this.type;
795 + }
505 796
797 + /**
798 + * Gets the UDP port to match.
799 + *
800 + * @return the UDP port to match
801 + */
802 + public Short udpPort() {
803 + return this.udpPort;
804 + }
805 +
806 + @Override
807 + public String toString() {
808 + return toStringHelper(type().toString())
809 + .add("udpPort", udpPort & 0xffff).toString();
810 + }
811 +
812 + @Override
813 + public int hashCode() {
814 + return Objects.hash(type, udpPort);
815 + }
816 +
817 + @Override
818 + public boolean equals(Object obj) {
819 + if (this == obj) {
820 + return true;
821 + }
822 + if (obj instanceof UdpPortCriterion) {
823 + UdpPortCriterion that = (UdpPortCriterion) obj;
824 + return Objects.equals(udpPort, that.udpPort) &&
825 + Objects.equals(type, that.type);
506 } 826 }
507 return false; 827 return false;
508 } 828 }
509 -
510 } 829 }
511 830
512 /** 831 /**
513 - * Implementation of VLAN ID criterion. 832 + * Implementation of SCTP port criterion.
514 */ 833 */
515 - public static final class VlanIdCriterion implements Criterion { 834 + public static final class SctpPortCriterion implements Criterion {
835 + private final Short sctpPort;
836 + private final Type type;
516 837
838 + /**
839 + * Constructor.
840 + *
841 + * @param sctpPort the SCTP port to match
842 + * @param type the match type. Should be either Type.SCTP_SRC or
843 + * Type.SCTP_DST
844 + */
845 + public SctpPortCriterion(Short sctpPort, Type type) {
846 + this.sctpPort = sctpPort;
847 + this.type = type;
848 + }
517 849
518 - private final VlanId vlanId; 850 + @Override
851 + public Type type() {
852 + return this.type;
853 + }
519 854
520 - public VlanIdCriterion(VlanId vlanId) { 855 + /**
521 - this.vlanId = vlanId; 856 + * Gets the SCTP port to match.
857 + *
858 + * @return the SCTP port to match
859 + */
860 + public Short sctpPort() {
861 + return this.sctpPort;
862 + }
863 +
864 + @Override
865 + public String toString() {
866 + return toStringHelper(type().toString())
867 + .add("sctpPort", sctpPort & 0xffff).toString();
868 + }
869 +
870 + @Override
871 + public int hashCode() {
872 + return Objects.hash(type, sctpPort);
873 + }
874 +
875 + @Override
876 + public boolean equals(Object obj) {
877 + if (this == obj) {
878 + return true;
879 + }
880 + if (obj instanceof SctpPortCriterion) {
881 + SctpPortCriterion that = (SctpPortCriterion) obj;
882 + return Objects.equals(sctpPort, that.sctpPort) &&
883 + Objects.equals(type, that.type);
884 + }
885 + return false;
886 + }
887 + }
888 +
889 + /**
890 + * Implementation of ICMP type criterion.
891 + */
892 + public static final class IcmpTypeCriterion implements Criterion {
893 + private final Byte icmpType;
894 +
895 + /**
896 + * Constructor.
897 + *
898 + * @param icmpType the ICMP type to match
899 + */
900 + public IcmpTypeCriterion(Byte icmpType) {
901 + this.icmpType = icmpType;
522 } 902 }
523 903
524 @Override 904 @Override
525 public Type type() { 905 public Type type() {
526 - return Type.VLAN_VID; 906 + return Type.ICMPV4_TYPE;
527 } 907 }
528 908
529 - public VlanId vlanId() { 909 + /**
530 - return vlanId; 910 + * Gets the ICMP type to match.
911 + *
912 + * @return the ICMP type to match
913 + */
914 + public Byte icmpType() {
915 + return icmpType;
531 } 916 }
532 917
533 @Override 918 @Override
534 public String toString() { 919 public String toString() {
535 return toStringHelper(type().toString()) 920 return toStringHelper(type().toString())
536 - .add("id", vlanId).toString(); 921 + .add("icmpType", icmpType & 0xff).toString();
537 } 922 }
538 923
539 @Override 924 @Override
540 public int hashCode() { 925 public int hashCode() {
541 - return Objects.hash(type(), vlanId); 926 + return Objects.hash(type(), icmpType);
542 } 927 }
543 928
544 @Override 929 @Override
...@@ -546,49 +931,53 @@ public final class Criteria { ...@@ -546,49 +931,53 @@ public final class Criteria {
546 if (this == obj) { 931 if (this == obj) {
547 return true; 932 return true;
548 } 933 }
549 - if (obj instanceof VlanIdCriterion) { 934 + if (obj instanceof IcmpTypeCriterion) {
550 - VlanIdCriterion that = (VlanIdCriterion) obj; 935 + IcmpTypeCriterion that = (IcmpTypeCriterion) obj;
551 - return Objects.equals(vlanId, that.vlanId) && 936 + return Objects.equals(icmpType, that.icmpType) &&
552 Objects.equals(this.type(), that.type()); 937 Objects.equals(this.type(), that.type());
553 -
554 -
555 } 938 }
556 return false; 939 return false;
557 } 940 }
558 -
559 } 941 }
560 942
561 /** 943 /**
562 - * Implementation of TCP port criterion. 944 + * Implementation of ICMP code criterion.
563 */ 945 */
564 - public static final class TcpPortCriterion implements Criterion { 946 + public static final class IcmpCodeCriterion implements Criterion {
947 + private final Byte icmpCode;
565 948
566 - private final Short tcpPort; 949 + /**
567 - private final Type type; 950 + * Constructor.
568 - 951 + *
569 - public TcpPortCriterion(Short tcpPort, Type type) { 952 + * @param icmpCode the ICMP code to match
570 - this.tcpPort = tcpPort; 953 + */
571 - this.type = type; 954 + public IcmpCodeCriterion(Byte icmpCode) {
955 + this.icmpCode = icmpCode;
572 } 956 }
573 957
574 @Override 958 @Override
575 public Type type() { 959 public Type type() {
576 - return this.type; 960 + return Type.ICMPV4_CODE;
577 } 961 }
578 962
579 - public Short tcpPort() { 963 + /**
580 - return this.tcpPort; 964 + * Gets the ICMP code to match.
965 + *
966 + * @return the ICMP code to match
967 + */
968 + public Byte icmpCode() {
969 + return icmpCode;
581 } 970 }
582 971
583 @Override 972 @Override
584 public String toString() { 973 public String toString() {
585 return toStringHelper(type().toString()) 974 return toStringHelper(type().toString())
586 - .add("tcpPort", tcpPort & 0xffff).toString(); 975 + .add("icmpCode", icmpCode & 0xff).toString();
587 } 976 }
588 977
589 @Override 978 @Override
590 public int hashCode() { 979 public int hashCode() {
591 - return Objects.hash(type, tcpPort); 980 + return Objects.hash(type(), icmpCode);
592 } 981 }
593 982
594 @Override 983 @Override
...@@ -596,12 +985,65 @@ public final class Criteria { ...@@ -596,12 +985,65 @@ public final class Criteria {
596 if (this == obj) { 985 if (this == obj) {
597 return true; 986 return true;
598 } 987 }
599 - if (obj instanceof TcpPortCriterion) { 988 + if (obj instanceof IcmpCodeCriterion) {
600 - TcpPortCriterion that = (TcpPortCriterion) obj; 989 + IcmpCodeCriterion that = (IcmpCodeCriterion) obj;
601 - return Objects.equals(tcpPort, that.tcpPort) && 990 + return Objects.equals(icmpCode, that.icmpCode) &&
602 - Objects.equals(type, that.type); 991 + Objects.equals(this.type(), that.type());
992 + }
993 + return false;
994 + }
995 + }
996 +
997 + /**
998 + * Implementation of IPv6 Flow Label criterion (RFC 6437).
999 + */
1000 + public static final class IPv6FlowLabelCriterion implements Criterion {
1001 + private static final int FLOW_LABEL_MASK = 0xfffff;
1002 + private final Integer flowLabel; // IPv6 flow label: 20 bits
1003 +
1004 + /**
1005 + * Constructor.
1006 + *
1007 + * @param flowLabel the IPv6 flow label to match
1008 + */
1009 + public IPv6FlowLabelCriterion(Integer flowLabel) {
1010 + this.flowLabel = flowLabel & FLOW_LABEL_MASK;
1011 + }
1012 +
1013 + @Override
1014 + public Type type() {
1015 + return Type.IPV6_FLABEL;
1016 + }
603 1017
1018 + /**
1019 + * Gets the IPv6 flow label to match.
1020 + *
1021 + * @return the IPv6 flow label to match
1022 + */
1023 + public Integer flowLabel() {
1024 + return flowLabel;
1025 + }
1026 +
1027 + @Override
1028 + public String toString() {
1029 + return toStringHelper(type().toString())
1030 + .add("flowLabel", flowLabel).toString();
1031 + }
1032 +
1033 + @Override
1034 + public int hashCode() {
1035 + return Objects.hash(type(), flowLabel);
1036 + }
604 1037
1038 + @Override
1039 + public boolean equals(Object obj) {
1040 + if (this == obj) {
1041 + return true;
1042 + }
1043 + if (obj instanceof IPv6FlowLabelCriterion) {
1044 + IPv6FlowLabelCriterion that = (IPv6FlowLabelCriterion) obj;
1045 + return Objects.equals(flowLabel, that.flowLabel) &&
1046 + Objects.equals(this.type(), that.type());
605 } 1047 }
606 return false; 1048 return false;
607 } 1049 }
...@@ -611,9 +1053,13 @@ public final class Criteria { ...@@ -611,9 +1053,13 @@ public final class Criteria {
611 * Implementation of ICMPv6 type criterion. 1053 * Implementation of ICMPv6 type criterion.
612 */ 1054 */
613 public static final class Icmpv6TypeCriterion implements Criterion { 1055 public static final class Icmpv6TypeCriterion implements Criterion {
614 -
615 private final Byte icmpv6Type; 1056 private final Byte icmpv6Type;
616 1057
1058 + /**
1059 + * Constructor.
1060 + *
1061 + * @param icmpv6Type the ICMPv6 type to match
1062 + */
617 public Icmpv6TypeCriterion(Byte icmpv6Type) { 1063 public Icmpv6TypeCriterion(Byte icmpv6Type) {
618 this.icmpv6Type = icmpv6Type; 1064 this.icmpv6Type = icmpv6Type;
619 } 1065 }
...@@ -623,6 +1069,11 @@ public final class Criteria { ...@@ -623,6 +1069,11 @@ public final class Criteria {
623 return Type.ICMPV6_TYPE; 1069 return Type.ICMPV6_TYPE;
624 } 1070 }
625 1071
1072 + /**
1073 + * Gets the ICMPv6 type to match.
1074 + *
1075 + * @return the ICMPv6 type to match
1076 + */
626 public Byte icmpv6Type() { 1077 public Byte icmpv6Type() {
627 return icmpv6Type; 1078 return icmpv6Type;
628 } 1079 }
...@@ -635,7 +1086,7 @@ public final class Criteria { ...@@ -635,7 +1086,7 @@ public final class Criteria {
635 1086
636 @Override 1087 @Override
637 public int hashCode() { 1088 public int hashCode() {
638 - return Objects.hash(icmpv6Type, type()); 1089 + return Objects.hash(type(), icmpv6Type);
639 } 1090 }
640 1091
641 @Override 1092 @Override
...@@ -656,9 +1107,13 @@ public final class Criteria { ...@@ -656,9 +1107,13 @@ public final class Criteria {
656 * Implementation of ICMPv6 code criterion. 1107 * Implementation of ICMPv6 code criterion.
657 */ 1108 */
658 public static final class Icmpv6CodeCriterion implements Criterion { 1109 public static final class Icmpv6CodeCriterion implements Criterion {
659 -
660 private final Byte icmpv6Code; 1110 private final Byte icmpv6Code;
661 1111
1112 + /**
1113 + * Constructor.
1114 + *
1115 + * @param icmpv6Code the ICMPv6 code to match
1116 + */
662 public Icmpv6CodeCriterion(Byte icmpv6Code) { 1117 public Icmpv6CodeCriterion(Byte icmpv6Code) {
663 this.icmpv6Code = icmpv6Code; 1118 this.icmpv6Code = icmpv6Code;
664 } 1119 }
...@@ -668,6 +1123,11 @@ public final class Criteria { ...@@ -668,6 +1123,11 @@ public final class Criteria {
668 return Type.ICMPV6_CODE; 1123 return Type.ICMPV6_CODE;
669 } 1124 }
670 1125
1126 + /**
1127 + * Gets the ICMPv6 code to match.
1128 + *
1129 + * @return the ICMPv6 code to match
1130 + */
671 public Byte icmpv6Code() { 1131 public Byte icmpv6Code() {
672 return icmpv6Code; 1132 return icmpv6Code;
673 } 1133 }
...@@ -680,7 +1140,7 @@ public final class Criteria { ...@@ -680,7 +1140,7 @@ public final class Criteria {
680 1140
681 @Override 1141 @Override
682 public int hashCode() { 1142 public int hashCode() {
683 - return Objects.hash(icmpv6Code, type()); 1143 + return Objects.hash(type(), icmpv6Code);
684 } 1144 }
685 1145
686 @Override 1146 @Override
...@@ -698,12 +1158,132 @@ public final class Criteria { ...@@ -698,12 +1158,132 @@ public final class Criteria {
698 } 1158 }
699 1159
700 /** 1160 /**
1161 + * Implementation of IPv6 Neighbor Discovery target address criterion.
1162 + */
1163 + public static final class IPv6NDTargetAddressCriterion
1164 + implements Criterion {
1165 + private final Ip6Address targetAddress;
1166 +
1167 + /**
1168 + * Constructor.
1169 + *
1170 + * @param targetAddress the IPv6 target address to match
1171 + */
1172 + public IPv6NDTargetAddressCriterion(Ip6Address targetAddress) {
1173 + this.targetAddress = targetAddress;
1174 + }
1175 +
1176 + @Override
1177 + public Type type() {
1178 + return Type.IPV6_ND_TARGET;
1179 + }
1180 +
1181 + /**
1182 + * Gets the IPv6 target address to match.
1183 + *
1184 + * @return the IPv6 target address to match
1185 + */
1186 + public Ip6Address targetAddress() {
1187 + return this.targetAddress;
1188 + }
1189 +
1190 + @Override
1191 + public String toString() {
1192 + return toStringHelper(type().toString())
1193 + .add("targetAddress", targetAddress).toString();
1194 + }
1195 +
1196 + @Override
1197 + public int hashCode() {
1198 + return Objects.hash(type(), targetAddress);
1199 + }
1200 +
1201 + @Override
1202 + public boolean equals(Object obj) {
1203 + if (this == obj) {
1204 + return true;
1205 + }
1206 + if (obj instanceof IPv6NDTargetAddressCriterion) {
1207 + IPv6NDTargetAddressCriterion that =
1208 + (IPv6NDTargetAddressCriterion) obj;
1209 + return Objects.equals(targetAddress, that.targetAddress) &&
1210 + Objects.equals(type(), that.type());
1211 + }
1212 + return false;
1213 + }
1214 + }
1215 +
1216 + /**
1217 + * Implementation of IPv6 Neighbor Discovery link-layer address criterion.
1218 + */
1219 + public static final class IPv6NDLinkLayerAddressCriterion
1220 + implements Criterion {
1221 + private final MacAddress mac;
1222 + private final Type type;
1223 +
1224 + /**
1225 + * Constructor.
1226 + *
1227 + * @param mac the source or destination link-layer address to match
1228 + * @param type the match type. Should be either Type.IPV6_ND_SLL or
1229 + * Type.IPV6_ND_TLL
1230 + */
1231 + public IPv6NDLinkLayerAddressCriterion(MacAddress mac, Type type) {
1232 + this.mac = mac;
1233 + this.type = type;
1234 + }
1235 +
1236 + @Override
1237 + public Type type() {
1238 + return this.type;
1239 + }
1240 +
1241 + /**
1242 + * Gets the MAC link-layer address to match.
1243 + *
1244 + * @return the MAC link-layer address to match
1245 + */
1246 + public MacAddress mac() {
1247 + return this.mac;
1248 + }
1249 +
1250 + @Override
1251 + public String toString() {
1252 + return toStringHelper(type().toString())
1253 + .add("mac", mac).toString();
1254 + }
1255 +
1256 + @Override
1257 + public int hashCode() {
1258 + return Objects.hash(type, mac);
1259 + }
1260 +
1261 + @Override
1262 + public boolean equals(Object obj) {
1263 + if (this == obj) {
1264 + return true;
1265 + }
1266 + if (obj instanceof IPv6NDLinkLayerAddressCriterion) {
1267 + IPv6NDLinkLayerAddressCriterion that =
1268 + (IPv6NDLinkLayerAddressCriterion) obj;
1269 + return Objects.equals(mac, that.mac) &&
1270 + Objects.equals(type, that.type);
1271 + }
1272 + return false;
1273 + }
1274 + }
1275 +
1276 + /**
701 * Implementation of MPLS tag criterion. 1277 * Implementation of MPLS tag criterion.
702 */ 1278 */
703 public static final class MplsCriterion implements Criterion { 1279 public static final class MplsCriterion implements Criterion {
704 -
705 private final Integer mplsLabel; 1280 private final Integer mplsLabel;
706 1281
1282 + /**
1283 + * Constructor.
1284 + *
1285 + * @param mplsLabel the MPLS label to match
1286 + */
707 public MplsCriterion(Integer mplsLabel) { 1287 public MplsCriterion(Integer mplsLabel) {
708 this.mplsLabel = mplsLabel; 1288 this.mplsLabel = mplsLabel;
709 } 1289 }
...@@ -713,6 +1293,11 @@ public final class Criteria { ...@@ -713,6 +1293,11 @@ public final class Criteria {
713 return Type.MPLS_LABEL; 1293 return Type.MPLS_LABEL;
714 } 1294 }
715 1295
1296 + /**
1297 + * Gets the MPLS label to match.
1298 + *
1299 + * @return the MPLS label to match
1300 + */
716 public Integer label() { 1301 public Integer label() {
717 return mplsLabel; 1302 return mplsLabel;
718 } 1303 }
...@@ -720,12 +1305,12 @@ public final class Criteria { ...@@ -720,12 +1305,12 @@ public final class Criteria {
720 @Override 1305 @Override
721 public String toString() { 1306 public String toString() {
722 return toStringHelper(type().toString()) 1307 return toStringHelper(type().toString())
723 - .add("mpls", mplsLabel & 0xffffffffL).toString(); 1308 + .add("label", mplsLabel & 0xffffffffL).toString();
724 } 1309 }
725 1310
726 @Override 1311 @Override
727 public int hashCode() { 1312 public int hashCode() {
728 - return Objects.hash(mplsLabel, type()); 1313 + return Objects.hash(type(), mplsLabel);
729 } 1314 }
730 1315
731 @Override 1316 @Override
...@@ -737,8 +1322,6 @@ public final class Criteria { ...@@ -737,8 +1322,6 @@ public final class Criteria {
737 MplsCriterion that = (MplsCriterion) obj; 1322 MplsCriterion that = (MplsCriterion) obj;
738 return Objects.equals(mplsLabel, that.mplsLabel) && 1323 return Objects.equals(mplsLabel, that.mplsLabel) &&
739 Objects.equals(this.type(), that.type()); 1324 Objects.equals(this.type(), that.type());
740 -
741 -
742 } 1325 }
743 return false; 1326 return false;
744 } 1327 }
...@@ -749,10 +1332,15 @@ public final class Criteria { ...@@ -749,10 +1332,15 @@ public final class Criteria {
749 * Implementation of lambda (wavelength) criterion. 1332 * Implementation of lambda (wavelength) criterion.
750 */ 1333 */
751 public static final class LambdaCriterion implements Criterion { 1334 public static final class LambdaCriterion implements Criterion {
752 -
753 private final short lambda; 1335 private final short lambda;
754 private final Type type; 1336 private final Type type;
755 1337
1338 + /**
1339 + * Constructor.
1340 + *
1341 + * @param lambda the lambda (wavelength) to match
1342 + * @param type the match type. Should be Type.OCH_SIGID
1343 + */
756 public LambdaCriterion(short lambda, Type type) { 1344 public LambdaCriterion(short lambda, Type type) {
757 this.lambda = lambda; 1345 this.lambda = lambda;
758 this.type = type; 1346 this.type = type;
...@@ -763,6 +1351,11 @@ public final class Criteria { ...@@ -763,6 +1351,11 @@ public final class Criteria {
763 return this.type; 1351 return this.type;
764 } 1352 }
765 1353
1354 + /**
1355 + * Gets the lambda (wavelength) to match.
1356 + *
1357 + * @return the lambda (wavelength) to match.
1358 + */
766 public Short lambda() { 1359 public Short lambda() {
767 return this.lambda; 1360 return this.lambda;
768 } 1361 }
...@@ -796,10 +1389,15 @@ public final class Criteria { ...@@ -796,10 +1389,15 @@ public final class Criteria {
796 * Implementation of optical signal type criterion. 1389 * Implementation of optical signal type criterion.
797 */ 1390 */
798 public static final class OpticalSignalTypeCriterion implements Criterion { 1391 public static final class OpticalSignalTypeCriterion implements Criterion {
799 -
800 private final Short signalType; 1392 private final Short signalType;
801 private final Type type; 1393 private final Type type;
802 1394
1395 + /**
1396 + * Constructor.
1397 + *
1398 + * @param signalType the optical signal type to match
1399 + * @param type the match type. Should be Type.OCH_SIGTYPE
1400 + */
803 public OpticalSignalTypeCriterion(Short signalType, Type type) { 1401 public OpticalSignalTypeCriterion(Short signalType, Type type) {
804 this.signalType = signalType; 1402 this.signalType = signalType;
805 this.type = type; 1403 this.type = type;
...@@ -810,6 +1408,11 @@ public final class Criteria { ...@@ -810,6 +1408,11 @@ public final class Criteria {
810 return this.type; 1408 return this.type;
811 } 1409 }
812 1410
1411 + /**
1412 + * Gets the optical signal type to match.
1413 + *
1414 + * @return the optical signal type to match
1415 + */
813 public Short signalType() { 1416 public Short signalType() {
814 return this.signalType; 1417 return this.signalType;
815 } 1418 }
...@@ -838,5 +1441,4 @@ public final class Criteria { ...@@ -838,5 +1441,4 @@ public final class Criteria {
838 return false; 1441 return false;
839 } 1442 }
840 } 1443 }
841 -
842 } 1444 }
......
...@@ -24,7 +24,7 @@ public interface Criterion { ...@@ -24,7 +24,7 @@ public interface Criterion {
24 /** 24 /**
25 * Types of fields to which the selection criterion may apply. 25 * Types of fields to which the selection criterion may apply.
26 */ 26 */
27 - // From page 42 of OpenFlow 1.3.x spec 27 + // From page 75 of OpenFlow 1.5.0 spec
28 public enum Type { 28 public enum Type {
29 /** Switch input port. */ 29 /** Switch input port. */
30 IN_PORT, 30 IN_PORT,
...@@ -106,6 +106,21 @@ public interface Criterion { ...@@ -106,6 +106,21 @@ public interface Criterion {
106 TUNNEL_ID, 106 TUNNEL_ID,
107 /** IPv6 Extension Header pseudo-field. */ 107 /** IPv6 Extension Header pseudo-field. */
108 IPV6_EXTHDR, 108 IPV6_EXTHDR,
109 + /** Unassigned value: 40. */
110 + UNASSIGNED_40,
111 + /** PBB UCA header field. */
112 + PBB_UCA,
113 + /** TCP flags. */
114 + TCP_FLAGS,
115 + /** Output port from action set metadata. */
116 + ACTSET_OUTPUT,
117 + /** Packet type value. */
118 + PACKET_TYPE,
119 +
120 + //
121 + // NOTE: Everything below is defined elsewhere: ONOS-specific,
122 + // extensions, etc.
123 + //
109 /** Optical channel signal ID (lambda). */ 124 /** Optical channel signal ID (lambda). */
110 OCH_SIGID, 125 OCH_SIGID,
111 /** Optical channel signal type (fixed or flexible). */ 126 /** Optical channel signal type (fixed or flexible). */
......
...@@ -25,6 +25,7 @@ import org.junit.Test; ...@@ -25,6 +25,7 @@ import org.junit.Test;
25 import org.onosproject.net.PortNumber; 25 import org.onosproject.net.PortNumber;
26 import org.onosproject.net.flow.criteria.Criteria; 26 import org.onosproject.net.flow.criteria.Criteria;
27 import org.onosproject.net.flow.criteria.Criterion; 27 import org.onosproject.net.flow.criteria.Criterion;
28 +import org.onlab.packet.Ip6Address;
28 import org.onlab.packet.IpPrefix; 29 import org.onlab.packet.IpPrefix;
29 import org.onlab.packet.MacAddress; 30 import org.onlab.packet.MacAddress;
30 import org.onlab.packet.VlanId; 31 import org.onlab.packet.VlanId;
...@@ -126,22 +127,25 @@ public class DefaultTrafficSelectorTest { ...@@ -126,22 +127,25 @@ public class DefaultTrafficSelectorTest {
126 public void testCriteriaCreation() { 127 public void testCriteriaCreation() {
127 TrafficSelector selector; 128 TrafficSelector selector;
128 129
130 + final int intValue = 22;
129 final short shortValue = 33; 131 final short shortValue = 33;
130 final byte byteValue = 44; 132 final byte byteValue = 44;
133 + final MacAddress macValue = MacAddress.valueOf("11:22:33:44:55:66");
131 final IpPrefix ipPrefixValue = IpPrefix.valueOf("192.168.1.0/24"); 134 final IpPrefix ipPrefixValue = IpPrefix.valueOf("192.168.1.0/24");
132 final IpPrefix ipv6PrefixValue = IpPrefix.valueOf("fe80::1/64"); 135 final IpPrefix ipv6PrefixValue = IpPrefix.valueOf("fe80::1/64");
136 + final Ip6Address ipv6AddressValue = Ip6Address.valueOf("fe80::1");
133 137
134 selector = DefaultTrafficSelector.builder() 138 selector = DefaultTrafficSelector.builder()
135 - .matchInport(PortNumber.portNumber(11)).build(); 139 + .matchInPort(PortNumber.portNumber(11)).build();
136 assertThat(selector, hasCriterionWithType(Type.IN_PORT)); 140 assertThat(selector, hasCriterionWithType(Type.IN_PORT));
137 141
138 selector = DefaultTrafficSelector.builder() 142 selector = DefaultTrafficSelector.builder()
139 - .matchEthSrc(MacAddress.BROADCAST).build(); 143 + .matchEthDst(macValue).build();
140 - assertThat(selector, hasCriterionWithType(Type.ETH_SRC)); 144 + assertThat(selector, hasCriterionWithType(Type.ETH_DST));
141 145
142 selector = DefaultTrafficSelector.builder() 146 selector = DefaultTrafficSelector.builder()
143 - .matchEthDst(MacAddress.BROADCAST).build(); 147 + .matchEthSrc(macValue).build();
144 - assertThat(selector, hasCriterionWithType(Type.ETH_DST)); 148 + assertThat(selector, hasCriterionWithType(Type.ETH_SRC));
145 149
146 selector = DefaultTrafficSelector.builder() 150 selector = DefaultTrafficSelector.builder()
147 .matchEthType(shortValue).build(); 151 .matchEthType(shortValue).build();
...@@ -176,6 +180,30 @@ public class DefaultTrafficSelectorTest { ...@@ -176,6 +180,30 @@ public class DefaultTrafficSelectorTest {
176 assertThat(selector, hasCriterionWithType(Type.TCP_DST)); 180 assertThat(selector, hasCriterionWithType(Type.TCP_DST));
177 181
178 selector = DefaultTrafficSelector.builder() 182 selector = DefaultTrafficSelector.builder()
183 + .matchUdpSrc(shortValue).build();
184 + assertThat(selector, hasCriterionWithType(Type.UDP_SRC));
185 +
186 + selector = DefaultTrafficSelector.builder()
187 + .matchUdpDst(shortValue).build();
188 + assertThat(selector, hasCriterionWithType(Type.UDP_DST));
189 +
190 + selector = DefaultTrafficSelector.builder()
191 + .matchSctpSrc(shortValue).build();
192 + assertThat(selector, hasCriterionWithType(Type.SCTP_SRC));
193 +
194 + selector = DefaultTrafficSelector.builder()
195 + .matchSctpDst(shortValue).build();
196 + assertThat(selector, hasCriterionWithType(Type.SCTP_DST));
197 +
198 + selector = DefaultTrafficSelector.builder()
199 + .matchIcmpType(byteValue).build();
200 + assertThat(selector, hasCriterionWithType(Type.ICMPV4_TYPE));
201 +
202 + selector = DefaultTrafficSelector.builder()
203 + .matchIcmpCode(byteValue).build();
204 + assertThat(selector, hasCriterionWithType(Type.ICMPV4_CODE));
205 +
206 + selector = DefaultTrafficSelector.builder()
179 .matchIPv6Src(ipv6PrefixValue).build(); 207 .matchIPv6Src(ipv6PrefixValue).build();
180 assertThat(selector, hasCriterionWithType(Type.IPV6_SRC)); 208 assertThat(selector, hasCriterionWithType(Type.IPV6_SRC));
181 209
...@@ -184,6 +212,26 @@ public class DefaultTrafficSelectorTest { ...@@ -184,6 +212,26 @@ public class DefaultTrafficSelectorTest {
184 assertThat(selector, hasCriterionWithType(Type.IPV6_DST)); 212 assertThat(selector, hasCriterionWithType(Type.IPV6_DST));
185 213
186 selector = DefaultTrafficSelector.builder() 214 selector = DefaultTrafficSelector.builder()
215 + .matchIPv6FlowLabel(intValue).build();
216 + assertThat(selector, hasCriterionWithType(Type.IPV6_FLABEL));
217 +
218 + selector = DefaultTrafficSelector.builder()
219 + .matchIcmpv6Type(byteValue).build();
220 + assertThat(selector, hasCriterionWithType(Type.ICMPV6_TYPE));
221 +
222 + selector = DefaultTrafficSelector.builder()
223 + .matchIPv6NDTargetAddress(ipv6AddressValue).build();
224 + assertThat(selector, hasCriterionWithType(Type.IPV6_ND_TARGET));
225 +
226 + selector = DefaultTrafficSelector.builder()
227 + .matchIPv6NDSourceLinkLayerAddress(macValue).build();
228 + assertThat(selector, hasCriterionWithType(Type.IPV6_ND_SLL));
229 +
230 + selector = DefaultTrafficSelector.builder()
231 + .matchIPv6NDTargetLinkLayerAddress(macValue).build();
232 + assertThat(selector, hasCriterionWithType(Type.IPV6_ND_TLL));
233 +
234 + selector = DefaultTrafficSelector.builder()
187 .matchMplsLabel(3).build(); 235 .matchMplsLabel(3).build();
188 assertThat(selector, hasCriterionWithType(Type.MPLS_LABEL)); 236 assertThat(selector, hasCriterionWithType(Type.MPLS_LABEL));
189 237
...@@ -194,12 +242,21 @@ public class DefaultTrafficSelectorTest { ...@@ -194,12 +242,21 @@ public class DefaultTrafficSelectorTest {
194 selector = DefaultTrafficSelector.builder() 242 selector = DefaultTrafficSelector.builder()
195 .matchOpticalSignalType(shortValue).build(); 243 .matchOpticalSignalType(shortValue).build();
196 assertThat(selector, hasCriterionWithType(Type.OCH_SIGTYPE)); 244 assertThat(selector, hasCriterionWithType(Type.OCH_SIGTYPE));
245 + }
246 +
247 + /**
248 + * Tests the traffic selector builder.
249 + */
250 + @Test
251 + public void testTrafficSelectorBuilder() {
252 + TrafficSelector selector;
253 + final short shortValue = 33;
197 254
198 final TrafficSelector baseSelector = DefaultTrafficSelector.builder() 255 final TrafficSelector baseSelector = DefaultTrafficSelector.builder()
199 - .matchOpticalSignalType(shortValue).build(); 256 + .matchLambda(shortValue).build();
200 selector = DefaultTrafficSelector.builder(baseSelector) 257 selector = DefaultTrafficSelector.builder(baseSelector)
201 .build(); 258 .build();
202 - assertThat(selector, hasCriterionWithType(Type.OCH_SIGTYPE)); 259 + assertThat(selector, hasCriterionWithType(Type.OCH_SIGID));
203 260
204 final Criterion criterion = Criteria.matchLambda(shortValue); 261 final Criterion criterion = Criteria.matchLambda(shortValue);
205 selector = DefaultTrafficSelector.builder() 262 selector = DefaultTrafficSelector.builder()
......
...@@ -18,6 +18,7 @@ package org.onosproject.net.flow.criteria; ...@@ -18,6 +18,7 @@ package org.onosproject.net.flow.criteria;
18 import org.junit.Test; 18 import org.junit.Test;
19 import org.onosproject.net.PortNumber; 19 import org.onosproject.net.PortNumber;
20 import org.onlab.packet.IpPrefix; 20 import org.onlab.packet.IpPrefix;
21 +import org.onlab.packet.Ip6Address;
21 import org.onlab.packet.MacAddress; 22 import org.onlab.packet.MacAddress;
22 import org.onlab.packet.VlanId; 23 import org.onlab.packet.VlanId;
23 24
...@@ -44,14 +45,10 @@ public class CriteriaTest { ...@@ -44,14 +45,10 @@ public class CriteriaTest {
44 Criterion sameAsMatchInPort1 = Criteria.matchInPort(port1); 45 Criterion sameAsMatchInPort1 = Criteria.matchInPort(port1);
45 Criterion matchInPort2 = Criteria.matchInPort(port2); 46 Criterion matchInPort2 = Criteria.matchInPort(port2);
46 47
47 - Criterion matchTcpPort1 = Criteria.matchTcpSrc((short) 1);
48 - Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc((short) 1);
49 - Criterion matchTcpPort2 = Criteria.matchTcpDst((short) 2);
50 -
51 private static final String MAC1 = "00:00:00:00:00:01"; 48 private static final String MAC1 = "00:00:00:00:00:01";
52 private static final String MAC2 = "00:00:00:00:00:02"; 49 private static final String MAC2 = "00:00:00:00:00:02";
53 - private MacAddress mac1 = new MacAddress(MAC1.getBytes()); 50 + private MacAddress mac1 = MacAddress.valueOf(MAC1);
54 - private MacAddress mac2 = new MacAddress(MAC2.getBytes()); 51 + private MacAddress mac2 = MacAddress.valueOf(MAC2);
55 Criterion matchEth1 = Criteria.matchEthSrc(mac1); 52 Criterion matchEth1 = Criteria.matchEthSrc(mac1);
56 Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1); 53 Criterion sameAsMatchEth1 = Criteria.matchEthSrc(mac1);
57 Criterion matchEth2 = Criteria.matchEthDst(mac2); 54 Criterion matchEth2 = Criteria.matchEthDst(mac2);
...@@ -97,6 +94,82 @@ public class CriteriaTest { ...@@ -97,6 +94,82 @@ public class CriteriaTest {
97 Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61); 94 Criterion sameAsMatchIpv61 = Criteria.matchIPSrc(ipv61);
98 Criterion matchIpv62 = Criteria.matchIPSrc(ipv62); 95 Criterion matchIpv62 = Criteria.matchIPSrc(ipv62);
99 96
97 + Criterion matchTcpPort1 = Criteria.matchTcpSrc((short) 1);
98 + Criterion sameAsMatchTcpPort1 = Criteria.matchTcpSrc((short) 1);
99 + Criterion matchTcpPort2 = Criteria.matchTcpDst((short) 2);
100 +
101 + Criterion matchUdpPort1 = Criteria.matchUdpSrc((short) 1);
102 + Criterion sameAsMatchUdpPort1 = Criteria.matchUdpSrc((short) 1);
103 + Criterion matchUdpPort2 = Criteria.matchUdpDst((short) 2);
104 +
105 + Criterion matchSctpPort1 = Criteria.matchSctpSrc((short) 1);
106 + Criterion sameAsMatchSctpPort1 = Criteria.matchSctpSrc((short) 1);
107 + Criterion matchSctpPort2 = Criteria.matchSctpDst((short) 2);
108 +
109 + byte icmpType1 = 1;
110 + byte icmpType2 = 2;
111 + Criterion matchIcmpType1 = Criteria.matchIcmpType(icmpType1);
112 + Criterion sameAsMatchIcmpType1 = Criteria.matchIcmpType(icmpType1);
113 + Criterion matchIcmpType2 = Criteria.matchIcmpType(icmpType2);
114 +
115 + byte icmpCode1 = 1;
116 + byte icmpCode2 = 2;
117 + Criterion matchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
118 + Criterion sameAsMatchIcmpCode1 = Criteria.matchIcmpCode(icmpCode1);
119 + Criterion matchIcmpCode2 = Criteria.matchIcmpCode(icmpCode2);
120 +
121 + int flowLabel1 = 1;
122 + int flowLabel2 = 2;
123 + Criterion matchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
124 + Criterion sameAsMatchFlowLabel1 = Criteria.matchIPv6FlowLabel(flowLabel1);
125 + Criterion matchFlowLabel2 = Criteria.matchIPv6FlowLabel(flowLabel2);
126 +
127 + byte icmpv6Type1 = 1;
128 + byte icmpv6Type2 = 2;
129 + Criterion matchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
130 + Criterion sameAsMatchIcmpv6Type1 = Criteria.matchIcmpv6Type(icmpv6Type1);
131 + Criterion matchIcmpv6Type2 = Criteria.matchIcmpv6Type(icmpv6Type2);
132 +
133 + byte icmpv6Code1 = 1;
134 + byte icmpv6Code2 = 2;
135 + Criterion matchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
136 + Criterion sameAsMatchIcmpv6Code1 = Criteria.matchIcmpv6Code(icmpv6Code1);
137 + Criterion matchIcmpv6Code2 = Criteria.matchIcmpv6Code(icmpv6Code2);
138 +
139 + private static final String IPV6_ADDR1 = "fe80::1";
140 + private static final String IPV6_ADDR2 = "fe80::2";
141 + private Ip6Address ip6TargetAddress1 = Ip6Address.valueOf(IPV6_ADDR1);
142 + private Ip6Address ip6TargetAddress2 = Ip6Address.valueOf(IPV6_ADDR2);
143 + Criterion matchIpv6TargetAddr1 =
144 + Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
145 + Criterion sameAsMatchIpv6TargetAddr1 =
146 + Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
147 + Criterion matchIpv6TargetAddr2 =
148 + Criteria.matchIPv6NDTargetAddress(ip6TargetAddress2);
149 +
150 + private static final String LL_MAC1 = "00:00:00:00:00:01";
151 + private static final String LL_MAC2 = "00:00:00:00:00:02";
152 + private MacAddress llMac1 = MacAddress.valueOf(LL_MAC1);
153 + private MacAddress llMac2 = MacAddress.valueOf(LL_MAC2);
154 + Criterion matchSrcLlAddr1 =
155 + Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
156 + Criterion sameAsMatchSrcLlAddr1 =
157 + Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
158 + Criterion matchSrcLlAddr2 =
159 + Criteria.matchIPv6NDSourceLinkLayerAddress(llMac2);
160 + Criterion matchTargetLlAddr1 =
161 + Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
162 + Criterion sameAsMatchTargetLlAddr1 =
163 + Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
164 + Criterion matchTargetLlAddr2 =
165 + Criteria.matchIPv6NDTargetLinkLayerAddress(llMac2);
166 +
167 + int mpls1 = 1;
168 + int mpls2 = 2;
169 + Criterion matchMpls1 = Criteria.matchMplsLabel(mpls1);
170 + Criterion sameAsMatchMpls1 = Criteria.matchMplsLabel(mpls1);
171 + Criterion matchMpls2 = Criteria.matchMplsLabel(mpls2);
172 +
100 short lambda1 = 1; 173 short lambda1 = 1;
101 short lambda2 = 2; 174 short lambda2 = 2;
102 Criterion matchLambda1 = Criteria.matchLambda(lambda1); 175 Criterion matchLambda1 = Criteria.matchLambda(lambda1);
...@@ -143,11 +216,21 @@ public class CriteriaTest { ...@@ -143,11 +216,21 @@ public class CriteriaTest {
143 assertThatClassIsImmutable(Criteria.PortCriterion.class); 216 assertThatClassIsImmutable(Criteria.PortCriterion.class);
144 assertThatClassIsImmutable(Criteria.EthCriterion.class); 217 assertThatClassIsImmutable(Criteria.EthCriterion.class);
145 assertThatClassIsImmutable(Criteria.EthTypeCriterion.class); 218 assertThatClassIsImmutable(Criteria.EthTypeCriterion.class);
146 - assertThatClassIsImmutable(Criteria.IPCriterion.class);
147 - assertThatClassIsImmutable(Criteria.IPProtocolCriterion.class);
148 - assertThatClassIsImmutable(Criteria.VlanPcpCriterion.class);
149 assertThatClassIsImmutable(Criteria.VlanIdCriterion.class); 219 assertThatClassIsImmutable(Criteria.VlanIdCriterion.class);
220 + assertThatClassIsImmutable(Criteria.VlanPcpCriterion.class);
221 + assertThatClassIsImmutable(Criteria.IPProtocolCriterion.class);
222 + assertThatClassIsImmutable(Criteria.IPCriterion.class);
150 assertThatClassIsImmutable(Criteria.TcpPortCriterion.class); 223 assertThatClassIsImmutable(Criteria.TcpPortCriterion.class);
224 + assertThatClassIsImmutable(Criteria.UdpPortCriterion.class);
225 + assertThatClassIsImmutable(Criteria.SctpPortCriterion.class);
226 + assertThatClassIsImmutable(Criteria.IcmpTypeCriterion.class);
227 + assertThatClassIsImmutable(Criteria.IcmpCodeCriterion.class);
228 + assertThatClassIsImmutable(Criteria.IPv6FlowLabelCriterion.class);
229 + assertThatClassIsImmutable(Criteria.Icmpv6TypeCriterion.class);
230 + assertThatClassIsImmutable(Criteria.Icmpv6CodeCriterion.class);
231 + assertThatClassIsImmutable(Criteria.IPv6NDTargetAddressCriterion.class);
232 + assertThatClassIsImmutable(Criteria.IPv6NDLinkLayerAddressCriterion.class);
233 + assertThatClassIsImmutable(Criteria.MplsCriterion.class);
151 assertThatClassIsImmutable(Criteria.LambdaCriterion.class); 234 assertThatClassIsImmutable(Criteria.LambdaCriterion.class);
152 assertThatClassIsImmutable(Criteria.OpticalSignalTypeCriterion.class); 235 assertThatClassIsImmutable(Criteria.OpticalSignalTypeCriterion.class);
153 } 236 }
...@@ -182,6 +265,19 @@ public class CriteriaTest { ...@@ -182,6 +265,19 @@ public class CriteriaTest {
182 // EthCriterion class 265 // EthCriterion class
183 266
184 /** 267 /**
268 + * Test the matchEthDst method.
269 + */
270 + @Test
271 + public void testMatchEthDstMethod() {
272 + Criterion matchEthDst = Criteria.matchEthDst(mac1);
273 + Criteria.EthCriterion ethCriterion =
274 + checkAndConvert(matchEthDst,
275 + Criterion.Type.ETH_DST,
276 + Criteria.EthCriterion.class);
277 + assertThat(ethCriterion.mac(), is(equalTo(mac1)));
278 + }
279 +
280 + /**
185 * Test the matchEthSrc method. 281 * Test the matchEthSrc method.
186 */ 282 */
187 @Test 283 @Test
...@@ -195,19 +291,6 @@ public class CriteriaTest { ...@@ -195,19 +291,6 @@ public class CriteriaTest {
195 } 291 }
196 292
197 /** 293 /**
198 - * Test the matchEthDst method.
199 - */
200 - @Test
201 - public void testMatchEthDstMethod() {
202 - Criterion matchTcpDst = Criteria.matchEthDst(mac1);
203 - Criteria.EthCriterion ethCriterion =
204 - checkAndConvert(matchTcpDst,
205 - Criterion.Type.ETH_DST,
206 - Criteria.EthCriterion.class);
207 - assertThat(ethCriterion.mac(), is(equalTo(mac1)));
208 - }
209 -
210 - /**
211 * Test the equals() method of the EthCriterion class. 294 * Test the equals() method of the EthCriterion class.
212 */ 295 */
213 @Test 296 @Test
...@@ -218,45 +301,6 @@ public class CriteriaTest { ...@@ -218,45 +301,6 @@ public class CriteriaTest {
218 .testEquals(); 301 .testEquals();
219 } 302 }
220 303
221 - // TcpPortCriterion class
222 -
223 - /**
224 - * Test the matchTcpSrc method.
225 - */
226 - @Test
227 - public void testMatchTcpSrcMethod() {
228 - Criterion matchTcpSrc = Criteria.matchTcpSrc((short) 1);
229 - Criteria.TcpPortCriterion tcpPortCriterion =
230 - checkAndConvert(matchTcpSrc,
231 - Criterion.Type.TCP_SRC,
232 - Criteria.TcpPortCriterion.class);
233 - assertThat(tcpPortCriterion.tcpPort(), is(equalTo((short) 1)));
234 - }
235 -
236 - /**
237 - * Test the matchTcpDst method.
238 - */
239 - @Test
240 - public void testMatchTcpDstMethod() {
241 - Criterion matchTcpDst = Criteria.matchTcpDst((short) 1);
242 - Criteria.TcpPortCriterion tcpPortCriterion =
243 - checkAndConvert(matchTcpDst,
244 - Criterion.Type.TCP_DST,
245 - Criteria.TcpPortCriterion.class);
246 - assertThat(tcpPortCriterion.tcpPort(), is(equalTo((short) 1)));
247 - }
248 -
249 - /**
250 - * Test the equals() method of the TcpPortCriterion class.
251 - */
252 - @Test
253 - public void testTcpPortCriterionEquals() {
254 - new EqualsTester()
255 - .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
256 - .addEqualityGroup(matchTcpPort2)
257 - .testEquals();
258 - }
259 -
260 // EthTypeCriterion class 304 // EthTypeCriterion class
261 305
262 /** 306 /**
...@@ -365,7 +409,7 @@ public class CriteriaTest { ...@@ -365,7 +409,7 @@ public class CriteriaTest {
365 // IPCriterion class 409 // IPCriterion class
366 410
367 /** 411 /**
368 - * Test the matchIPSrc method. 412 + * Test the matchIPSrc method: IPv4.
369 */ 413 */
370 @Test 414 @Test
371 public void testMatchIPSrcMethod() { 415 public void testMatchIPSrcMethod() {
...@@ -378,7 +422,7 @@ public class CriteriaTest { ...@@ -378,7 +422,7 @@ public class CriteriaTest {
378 } 422 }
379 423
380 /** 424 /**
381 - * Test the matchIPDst method. 425 + * Test the matchIPDst method: IPv4.
382 */ 426 */
383 @Test 427 @Test
384 public void testMatchIPDstMethod() { 428 public void testMatchIPDstMethod() {
...@@ -391,7 +435,7 @@ public class CriteriaTest { ...@@ -391,7 +435,7 @@ public class CriteriaTest {
391 } 435 }
392 436
393 /** 437 /**
394 - * Test the matchIPSrc method. 438 + * Test the matchIPSrc method: IPv6.
395 */ 439 */
396 @Test 440 @Test
397 public void testMatchIPv6SrcMethod() { 441 public void testMatchIPv6SrcMethod() {
...@@ -404,7 +448,7 @@ public class CriteriaTest { ...@@ -404,7 +448,7 @@ public class CriteriaTest {
404 } 448 }
405 449
406 /** 450 /**
407 - * Test the matchIPDst method. 451 + * Test the matchIPDst method: IPv6.
408 */ 452 */
409 @Test 453 @Test
410 public void testMatchIPv6DstMethod() { 454 public void testMatchIPv6DstMethod() {
...@@ -432,6 +476,359 @@ public class CriteriaTest { ...@@ -432,6 +476,359 @@ public class CriteriaTest {
432 .testEquals(); 476 .testEquals();
433 } 477 }
434 478
479 + // TcpPortCriterion class
480 +
481 + /**
482 + * Test the matchTcpSrc method.
483 + */
484 + @Test
485 + public void testMatchTcpSrcMethod() {
486 + Criterion matchTcpSrc = Criteria.matchTcpSrc((short) 1);
487 + Criteria.TcpPortCriterion tcpPortCriterion =
488 + checkAndConvert(matchTcpSrc,
489 + Criterion.Type.TCP_SRC,
490 + Criteria.TcpPortCriterion.class);
491 + assertThat(tcpPortCriterion.tcpPort(), is(equalTo((short) 1)));
492 + }
493 +
494 + /**
495 + * Test the matchTcpDst method.
496 + */
497 + @Test
498 + public void testMatchTcpDstMethod() {
499 + Criterion matchTcpDst = Criteria.matchTcpDst((short) 1);
500 + Criteria.TcpPortCriterion tcpPortCriterion =
501 + checkAndConvert(matchTcpDst,
502 + Criterion.Type.TCP_DST,
503 + Criteria.TcpPortCriterion.class);
504 + assertThat(tcpPortCriterion.tcpPort(), is(equalTo((short) 1)));
505 + }
506 +
507 + /**
508 + * Test the equals() method of the TcpPortCriterion class.
509 + */
510 + @Test
511 + public void testTcpPortCriterionEquals() {
512 + new EqualsTester()
513 + .addEqualityGroup(matchTcpPort1, sameAsMatchTcpPort1)
514 + .addEqualityGroup(matchTcpPort2)
515 + .testEquals();
516 + }
517 +
518 + // UdpPortCriterion class
519 +
520 + /**
521 + * Test the matchUdpSrc method.
522 + */
523 + @Test
524 + public void testMatchUdpSrcMethod() {
525 + Criterion matchUdpSrc = Criteria.matchUdpSrc((short) 1);
526 + Criteria.UdpPortCriterion udpPortCriterion =
527 + checkAndConvert(matchUdpSrc,
528 + Criterion.Type.UDP_SRC,
529 + Criteria.UdpPortCriterion.class);
530 + assertThat(udpPortCriterion.udpPort(), is(equalTo((short) 1)));
531 + }
532 +
533 + /**
534 + * Test the matchUdpDst method.
535 + */
536 + @Test
537 + public void testMatchUdpDstMethod() {
538 + Criterion matchUdpDst = Criteria.matchUdpDst((short) 1);
539 + Criteria.UdpPortCriterion udpPortCriterion =
540 + checkAndConvert(matchUdpDst,
541 + Criterion.Type.UDP_DST,
542 + Criteria.UdpPortCriterion.class);
543 + assertThat(udpPortCriterion.udpPort(), is(equalTo((short) 1)));
544 + }
545 +
546 + /**
547 + * Test the equals() method of the UdpPortCriterion class.
548 + */
549 + @Test
550 + public void testUdpPortCriterionEquals() {
551 + new EqualsTester()
552 + .addEqualityGroup(matchUdpPort1, sameAsMatchUdpPort1)
553 + .addEqualityGroup(matchUdpPort2)
554 + .testEquals();
555 + }
556 +
557 + // SctpPortCriterion class
558 +
559 + /**
560 + * Test the matchSctpSrc method.
561 + */
562 + @Test
563 + public void testMatchSctpSrcMethod() {
564 + Criterion matchSctpSrc = Criteria.matchSctpSrc((short) 1);
565 + Criteria.SctpPortCriterion sctpPortCriterion =
566 + checkAndConvert(matchSctpSrc,
567 + Criterion.Type.SCTP_SRC,
568 + Criteria.SctpPortCriterion.class);
569 + assertThat(sctpPortCriterion.sctpPort(), is(equalTo((short) 1)));
570 + }
571 +
572 + /**
573 + * Test the matchSctpDst method.
574 + */
575 + @Test
576 + public void testMatchSctpDstMethod() {
577 + Criterion matchSctpDst = Criteria.matchSctpDst((short) 1);
578 + Criteria.SctpPortCriterion sctpPortCriterion =
579 + checkAndConvert(matchSctpDst,
580 + Criterion.Type.SCTP_DST,
581 + Criteria.SctpPortCriterion.class);
582 + assertThat(sctpPortCriterion.sctpPort(), is(equalTo((short) 1)));
583 + }
584 +
585 + /**
586 + * Test the equals() method of the SctpPortCriterion class.
587 + */
588 + @Test
589 + public void testSctpPortCriterionEquals() {
590 + new EqualsTester()
591 + .addEqualityGroup(matchSctpPort1, sameAsMatchSctpPort1)
592 + .addEqualityGroup(matchSctpPort2)
593 + .testEquals();
594 + }
595 +
596 + // IcmpTypeCriterion class
597 +
598 + /**
599 + * Test the matchIcmpType method.
600 + */
601 + @Test
602 + public void testMatchIcmpTypeMethod() {
603 + Byte icmpType = 12;
604 + Criterion matchIcmpType = Criteria.matchIcmpType(icmpType);
605 + Criteria.IcmpTypeCriterion icmpTypeCriterion =
606 + checkAndConvert(matchIcmpType,
607 + Criterion.Type.ICMPV4_TYPE,
608 + Criteria.IcmpTypeCriterion.class);
609 + assertThat(icmpTypeCriterion.icmpType(), is(equalTo(icmpType)));
610 + }
611 +
612 + /**
613 + * Test the equals() method of the IcmpTypeCriterion class.
614 + */
615 + @Test
616 + public void testIcmpTypeCriterionEquals() {
617 + new EqualsTester()
618 + .addEqualityGroup(matchIcmpType1, sameAsMatchIcmpType1)
619 + .addEqualityGroup(matchIcmpType2)
620 + .testEquals();
621 + }
622 +
623 + // IcmpCodeCriterion class
624 +
625 + /**
626 + * Test the matchIcmpCode method.
627 + */
628 + @Test
629 + public void testMatchIcmpCodeMethod() {
630 + Byte icmpCode = 12;
631 + Criterion matchIcmpCode = Criteria.matchIcmpCode(icmpCode);
632 + Criteria.IcmpCodeCriterion icmpCodeCriterion =
633 + checkAndConvert(matchIcmpCode,
634 + Criterion.Type.ICMPV4_CODE,
635 + Criteria.IcmpCodeCriterion.class);
636 + assertThat(icmpCodeCriterion.icmpCode(), is(equalTo(icmpCode)));
637 + }
638 +
639 + /**
640 + * Test the equals() method of the IcmpCodeCriterion class.
641 + */
642 + @Test
643 + public void testIcmpCodeCriterionEquals() {
644 + new EqualsTester()
645 + .addEqualityGroup(matchIcmpCode1, sameAsMatchIcmpCode1)
646 + .addEqualityGroup(matchIcmpCode2)
647 + .testEquals();
648 + }
649 +
650 + // IPv6FlowLabelCriterion class
651 +
652 + /**
653 + * Test the matchIPv6FlowLabel method.
654 + */
655 + @Test
656 + public void testMatchIPv6FlowLabelMethod() {
657 + Integer flowLabel = 12;
658 + Criterion matchFlowLabel = Criteria.matchIPv6FlowLabel(flowLabel);
659 + Criteria.IPv6FlowLabelCriterion flowLabelCriterion =
660 + checkAndConvert(matchFlowLabel,
661 + Criterion.Type.IPV6_FLABEL,
662 + Criteria.IPv6FlowLabelCriterion.class);
663 + assertThat(flowLabelCriterion.flowLabel(), is(equalTo(flowLabel)));
664 + }
665 +
666 + /**
667 + * Test the equals() method of the IPv6FlowLabelCriterion class.
668 + */
669 + @Test
670 + public void testIPv6FlowLabelCriterionEquals() {
671 + new EqualsTester()
672 + .addEqualityGroup(matchFlowLabel1, sameAsMatchFlowLabel1)
673 + .addEqualityGroup(matchFlowLabel2)
674 + .testEquals();
675 + }
676 +
677 + // Icmpv6TypeCriterion class
678 +
679 + /**
680 + * Test the matchIcmpv6Type method.
681 + */
682 + @Test
683 + public void testMatchIcmpv6TypeMethod() {
684 + Byte icmpv6Type = 12;
685 + Criterion matchIcmpv6Type = Criteria.matchIcmpv6Type(icmpv6Type);
686 + Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
687 + checkAndConvert(matchIcmpv6Type,
688 + Criterion.Type.ICMPV6_TYPE,
689 + Criteria.Icmpv6TypeCriterion.class);
690 + assertThat(icmpv6TypeCriterion.icmpv6Type(), is(equalTo(icmpv6Type)));
691 + }
692 +
693 + /**
694 + * Test the equals() method of the Icmpv6TypeCriterion class.
695 + */
696 + @Test
697 + public void testIcmpv6TypeCriterionEquals() {
698 + new EqualsTester()
699 + .addEqualityGroup(matchIcmpv6Type1, sameAsMatchIcmpv6Type1)
700 + .addEqualityGroup(matchIcmpv6Type2)
701 + .testEquals();
702 + }
703 +
704 + // Icmpv6CodeCriterion class
705 +
706 + /**
707 + * Test the matchIcmpv6Code method.
708 + */
709 + @Test
710 + public void testMatchIcmpv6CodeMethod() {
711 + Byte icmpv6Code = 12;
712 + Criterion matchIcmpv6Code = Criteria.matchIcmpv6Code(icmpv6Code);
713 + Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
714 + checkAndConvert(matchIcmpv6Code,
715 + Criterion.Type.ICMPV6_CODE,
716 + Criteria.Icmpv6CodeCriterion.class);
717 + assertThat(icmpv6CodeCriterion.icmpv6Code(), is(equalTo(icmpv6Code)));
718 + }
719 +
720 + /**
721 + * Test the equals() method of the Icmpv6CodeCriterion class.
722 + */
723 + @Test
724 + public void testIcmpv6CodeCriterionEquals() {
725 + new EqualsTester()
726 + .addEqualityGroup(matchIcmpv6Code1, sameAsMatchIcmpv6Code1)
727 + .addEqualityGroup(matchIcmpv6Code2)
728 + .testEquals();
729 + }
730 +
731 + // IPv6NDTargetAddressCriterion class
732 +
733 + /**
734 + * Test the matchIPv6NDTargetAddress method.
735 + */
736 + @Test
737 + public void testMatchIPv6NDTargetAddressMethod() {
738 + Criterion matchTargetAddress =
739 + Criteria.matchIPv6NDTargetAddress(ip6TargetAddress1);
740 + Criteria.IPv6NDTargetAddressCriterion targetAddressCriterion =
741 + checkAndConvert(matchTargetAddress,
742 + Criterion.Type.IPV6_ND_TARGET,
743 + Criteria.IPv6NDTargetAddressCriterion.class);
744 + assertThat(targetAddressCriterion.targetAddress(),
745 + is(ip6TargetAddress1));
746 + }
747 +
748 + /**
749 + * Test the equals() method of the IPv6NDTargetAddressCriterion class.
750 + */
751 + @Test
752 + public void testIPv6NDTargetAddressCriterionEquals() {
753 + new EqualsTester()
754 + .addEqualityGroup(matchIpv6TargetAddr1,
755 + sameAsMatchIpv6TargetAddr1)
756 + .addEqualityGroup(matchIpv6TargetAddr2)
757 + .testEquals();
758 + }
759 +
760 + // IPv6NDLinkLayerAddressCriterion class
761 +
762 + /**
763 + * Test the matchIPv6NDSourceLinkLayerAddress method.
764 + */
765 + @Test
766 + public void testMatchIPv6NDSourceLinkLayerAddressMethod() {
767 + Criterion matchSrcLlAddr =
768 + Criteria.matchIPv6NDSourceLinkLayerAddress(llMac1);
769 + Criteria.IPv6NDLinkLayerAddressCriterion srcLlCriterion =
770 + checkAndConvert(matchSrcLlAddr,
771 + Criterion.Type.IPV6_ND_SLL,
772 + Criteria.IPv6NDLinkLayerAddressCriterion.class);
773 + assertThat(srcLlCriterion.mac(), is(equalTo(llMac1)));
774 + }
775 +
776 + /**
777 + * Test the matchIPv6NDTargetLinkLayerAddress method.
778 + */
779 + @Test
780 + public void testMatchIPv6NDTargetLinkLayerAddressMethod() {
781 + Criterion matchTargetLlAddr =
782 + Criteria.matchIPv6NDTargetLinkLayerAddress(llMac1);
783 + Criteria.IPv6NDLinkLayerAddressCriterion targetLlCriterion =
784 + checkAndConvert(matchTargetLlAddr,
785 + Criterion.Type.IPV6_ND_TLL,
786 + Criteria.IPv6NDLinkLayerAddressCriterion.class);
787 + assertThat(targetLlCriterion.mac(), is(equalTo(llMac1)));
788 + }
789 +
790 + /**
791 + * Test the equals() method of the IPv6NDLinkLayerAddressCriterion class.
792 + */
793 + @Test
794 + public void testIPv6NDLinkLayerAddressCriterionEquals() {
795 + new EqualsTester()
796 + .addEqualityGroup(matchSrcLlAddr1, sameAsMatchSrcLlAddr1)
797 + .addEqualityGroup(matchSrcLlAddr2)
798 + .testEquals();
799 +
800 + new EqualsTester()
801 + .addEqualityGroup(matchTargetLlAddr1, sameAsMatchTargetLlAddr1)
802 + .addEqualityGroup(matchTargetLlAddr2)
803 + .testEquals();
804 + }
805 +
806 + // MplsCriterion class
807 +
808 + /**
809 + * Test the matchMplsLabel method.
810 + */
811 + @Test
812 + public void testMatchMplsLabelMethod() {
813 + Criterion matchMplsLabel = Criteria.matchMplsLabel(mpls1);
814 + Criteria.MplsCriterion mplsCriterion =
815 + checkAndConvert(matchMplsLabel,
816 + Criterion.Type.MPLS_LABEL,
817 + Criteria.MplsCriterion.class);
818 + assertThat(mplsCriterion.label(), is(equalTo(mpls1)));
819 + }
820 +
821 + /**
822 + * Test the equals() method of the MplsCriterion class.
823 + */
824 + @Test
825 + public void testMplsCriterionEquals() {
826 + new EqualsTester()
827 + .addEqualityGroup(matchMpls1, sameAsMatchMpls1)
828 + .addEqualityGroup(matchMpls2)
829 + .testEquals();
830 + }
831 +
435 // LambdaCriterion class 832 // LambdaCriterion class
436 833
437 /** 834 /**
......
...@@ -127,7 +127,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -127,7 +127,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
127 LinkResourceAllocations allocations, 127 LinkResourceAllocations allocations,
128 FlowRuleOperation operation) { 128 FlowRuleOperation operation) {
129 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); 129 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
130 - selectorBuilder.matchInport(intent.src().port()); 130 + selectorBuilder.matchInPort(intent.src().port());
131 131
132 List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); 132 List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
133 ConnectPoint prev = intent.src(); 133 ConnectPoint prev = intent.src();
...@@ -163,7 +163,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -163,7 +163,7 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
163 rules.add(new FlowRuleBatchEntry(operation, rule)); 163 rules.add(new FlowRuleBatchEntry(operation, rule));
164 164
165 prev = link.dst(); 165 prev = link.dst();
166 - selectorBuilder.matchInport(link.dst().port()); 166 + selectorBuilder.matchInPort(link.dst().port());
167 selectorBuilder.matchOpticalSignalType(SIGNAL_TYPE); //todo 167 selectorBuilder.matchOpticalSignalType(SIGNAL_TYPE); //todo
168 selectorBuilder.matchLambda((short) la.toInt()); 168 selectorBuilder.matchLambda((short) la.toInt());
169 169
......
...@@ -92,7 +92,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -92,7 +92,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
92 List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); 92 List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
93 // TODO Generate multiple batches 93 // TODO Generate multiple batches
94 while (links.hasNext()) { 94 while (links.hasNext()) {
95 - builder.matchInport(prev.port()); 95 + builder.matchInPort(prev.port());
96 Link link = links.next(); 96 Link link = links.next();
97 // if this is the last flow rule, apply the intent's treatments 97 // if this is the last flow rule, apply the intent's treatments
98 TrafficTreatment treatment = 98 TrafficTreatment treatment =
...@@ -124,7 +124,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -124,7 +124,7 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
124 List<FlowRuleBatchEntry> rules = Lists.newLinkedList(); 124 List<FlowRuleBatchEntry> rules = Lists.newLinkedList();
125 // TODO Generate multiple batches 125 // TODO Generate multiple batches
126 while (links.hasNext()) { 126 while (links.hasNext()) {
127 - builder.matchInport(prev.port()); 127 + builder.matchInPort(prev.port());
128 Link link = links.next(); 128 Link link = links.next();
129 // if this is the last flow rule, apply the intent's treatments 129 // if this is the last flow rule, apply the intent's treatments
130 TrafficTreatment treatment = 130 TrafficTreatment treatment =
......
...@@ -18,6 +18,7 @@ package org.onosproject.provider.of.flow.impl; ...@@ -18,6 +18,7 @@ package org.onosproject.provider.of.flow.impl;
18 import com.google.common.collect.Lists; 18 import com.google.common.collect.Lists;
19 import org.onlab.packet.Ip4Address; 19 import org.onlab.packet.Ip4Address;
20 import org.onlab.packet.Ip4Prefix; 20 import org.onlab.packet.Ip4Prefix;
21 +import org.onlab.packet.Ip6Address;
21 import org.onlab.packet.Ip6Prefix; 22 import org.onlab.packet.Ip6Prefix;
22 import org.onlab.packet.MacAddress; 23 import org.onlab.packet.MacAddress;
23 import org.onlab.packet.VlanId; 24 import org.onlab.packet.VlanId;
...@@ -348,124 +349,139 @@ public class FlowEntryBuilder { ...@@ -348,124 +349,139 @@ public class FlowEntryBuilder {
348 } 349 }
349 350
350 private TrafficSelector buildSelector() { 351 private TrafficSelector buildSelector() {
352 + MacAddress mac;
353 + Ip4Prefix ip4Prefix;
354 + Ip6Address ip6Address;
355 + Ip6Prefix ip6Prefix;
356 +
351 TrafficSelector.Builder builder = DefaultTrafficSelector.builder(); 357 TrafficSelector.Builder builder = DefaultTrafficSelector.builder();
352 for (MatchField<?> field : match.getMatchFields()) { 358 for (MatchField<?> field : match.getMatchFields()) {
353 switch (field.id) { 359 switch (field.id) {
354 case IN_PORT: 360 case IN_PORT:
355 - builder.matchInport(PortNumber 361 + builder.matchInPort(PortNumber
356 .portNumber(match.get(MatchField.IN_PORT).getPortNumber())); 362 .portNumber(match.get(MatchField.IN_PORT).getPortNumber()));
357 break; 363 break;
358 - case ETH_SRC:
359 - MacAddress sMac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
360 - builder.matchEthSrc(sMac);
361 - break;
362 case ETH_DST: 364 case ETH_DST:
363 - MacAddress dMac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong()); 365 + mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong());
364 - builder.matchEthDst(dMac); 366 + builder.matchEthDst(mac);
367 + break;
368 + case ETH_SRC:
369 + mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong());
370 + builder.matchEthSrc(mac);
365 break; 371 break;
366 case ETH_TYPE: 372 case ETH_TYPE:
367 int ethType = match.get(MatchField.ETH_TYPE).getValue(); 373 int ethType = match.get(MatchField.ETH_TYPE).getValue();
368 builder.matchEthType((short) ethType); 374 builder.matchEthType((short) ethType);
369 break; 375 break;
370 - case IPV4_DST: 376 + case VLAN_VID:
371 - Ip4Prefix dip; 377 + VlanId vlanId = null;
372 - if (match.isPartiallyMasked(MatchField.IPV4_DST)) { 378 + if (match.isPartiallyMasked(MatchField.VLAN_VID)) {
373 - Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST); 379 + Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID);
374 - 380 + if (masked.getValue().equals(OFVlanVidMatch.PRESENT)
375 - dip = Ip4Prefix.valueOf( 381 + && masked.getMask().equals(OFVlanVidMatch.PRESENT)) {
376 - maskedIp.getValue().getInt(), 382 + vlanId = VlanId.ANY;
377 - maskedIp.getMask().asCidrMaskLength()); 383 + }
378 } else { 384 } else {
379 - dip = Ip4Prefix.valueOf( 385 + vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan());
380 - match.get(MatchField.IPV4_DST).getInt(),
381 - Ip4Prefix.MAX_MASK_LENGTH);
382 } 386 }
383 - 387 + if (vlanId != null) {
384 - builder.matchIPDst(dip); 388 + builder.matchVlanId(vlanId);
389 + }
390 + break;
391 + case VLAN_PCP:
392 + byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
393 + builder.matchVlanPcp(vlanPcp);
394 + break;
395 + case IP_PROTO:
396 + short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
397 + builder.matchIPProtocol((byte) proto);
385 break; 398 break;
386 case IPV4_SRC: 399 case IPV4_SRC:
387 - Ip4Prefix sip;
388 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) { 400 if (match.isPartiallyMasked(MatchField.IPV4_SRC)) {
389 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC); 401 Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_SRC);
390 402
391 - sip = Ip4Prefix.valueOf( 403 + ip4Prefix = Ip4Prefix.valueOf(
392 maskedIp.getValue().getInt(), 404 maskedIp.getValue().getInt(),
393 maskedIp.getMask().asCidrMaskLength()); 405 maskedIp.getMask().asCidrMaskLength());
394 } else { 406 } else {
395 - sip = Ip4Prefix.valueOf( 407 + ip4Prefix = Ip4Prefix.valueOf(
396 match.get(MatchField.IPV4_SRC).getInt(), 408 match.get(MatchField.IPV4_SRC).getInt(),
397 Ip4Prefix.MAX_MASK_LENGTH); 409 Ip4Prefix.MAX_MASK_LENGTH);
398 } 410 }
399 411
400 - builder.matchIPSrc(sip); 412 + builder.matchIPSrc(ip4Prefix);
401 - break;
402 - case IP_PROTO:
403 - short proto = match.get(MatchField.IP_PROTO).getIpProtocolNumber();
404 - builder.matchIPProtocol((byte) proto);
405 - break;
406 - case VLAN_PCP:
407 - byte vlanPcp = match.get(MatchField.VLAN_PCP).getValue();
408 - builder.matchVlanPcp(vlanPcp);
409 break; 413 break;
410 - case VLAN_VID: 414 + case IPV4_DST:
411 - VlanId vlanId = null; 415 + if (match.isPartiallyMasked(MatchField.IPV4_DST)) {
412 - if (match.isPartiallyMasked(MatchField.VLAN_VID)) { 416 + Masked<IPv4Address> maskedIp = match.getMasked(MatchField.IPV4_DST);
413 - Masked<OFVlanVidMatch> masked = match.getMasked(MatchField.VLAN_VID); 417 +
414 - if (masked.getValue().equals(OFVlanVidMatch.PRESENT) 418 + ip4Prefix = Ip4Prefix.valueOf(
415 - && masked.getMask().equals(OFVlanVidMatch.PRESENT)) { 419 + maskedIp.getValue().getInt(),
416 - vlanId = VlanId.ANY; 420 + maskedIp.getMask().asCidrMaskLength());
417 - }
418 } else { 421 } else {
419 - vlanId = VlanId.vlanId(match.get(MatchField.VLAN_VID).getVlan()); 422 + ip4Prefix = Ip4Prefix.valueOf(
420 - } 423 + match.get(MatchField.IPV4_DST).getInt(),
421 - if (vlanId != null) { 424 + Ip4Prefix.MAX_MASK_LENGTH);
422 - builder.matchVlanId(vlanId);
423 } 425 }
426 +
427 + builder.matchIPDst(ip4Prefix);
428 + break;
429 + case TCP_SRC:
430 + builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort());
424 break; 431 break;
425 case TCP_DST: 432 case TCP_DST:
426 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort()); 433 builder.matchTcpDst((short) match.get(MatchField.TCP_DST).getPort());
427 break; 434 break;
428 - case TCP_SRC: 435 + case UDP_SRC:
429 - builder.matchTcpSrc((short) match.get(MatchField.TCP_SRC).getPort()); 436 + builder.matchUdpSrc((short) match.get(MatchField.UDP_SRC).getPort());
430 break; 437 break;
431 - case MPLS_LABEL: 438 + case UDP_DST:
432 - builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL) 439 + builder.matchUdpDst((short) match.get(MatchField.UDP_DST).getPort());
433 - .getValue());
434 break; 440 break;
435 - case OCH_SIGID: 441 + case SCTP_SRC:
436 - builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber()); 442 + builder.matchSctpSrc((short) match.get(MatchField.SCTP_SRC).getPort());
437 break; 443 break;
438 - case OCH_SIGTYPE: 444 + case SCTP_DST:
439 - builder.matchOpticalSignalType(match.get(MatchField 445 + builder.matchSctpDst((short) match.get(MatchField.SCTP_DST).getPort());
440 - .OCH_SIGTYPE).getValue());
441 break; 446 break;
442 - case IPV6_DST: 447 + case ICMPV4_TYPE:
443 - Ip6Prefix dipv6; 448 + byte icmpType = (byte) match.get(MatchField.ICMPV4_TYPE).getType();
444 - if (match.isPartiallyMasked(MatchField.IPV6_DST)) { 449 + builder.matchIcmpType(icmpType);
445 - Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST); 450 + break;
446 - dipv6 = Ip6Prefix.valueOf( 451 + case ICMPV4_CODE:
452 + byte icmpCode = (byte) match.get(MatchField.ICMPV4_CODE).getCode();
453 + builder.matchIcmpCode(icmpCode);
454 + break;
455 + case IPV6_SRC:
456 + if (match.isPartiallyMasked(MatchField.IPV6_SRC)) {
457 + Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC);
458 + ip6Prefix = Ip6Prefix.valueOf(
447 maskedIp.getValue().getBytes(), 459 maskedIp.getValue().getBytes(),
448 maskedIp.getMask().asCidrMaskLength()); 460 maskedIp.getMask().asCidrMaskLength());
449 } else { 461 } else {
450 - dipv6 = Ip6Prefix.valueOf( 462 + ip6Prefix = Ip6Prefix.valueOf(
451 - match.get(MatchField.IPV6_DST).getBytes(), 463 + match.get(MatchField.IPV6_SRC).getBytes(),
452 Ip6Prefix.MAX_MASK_LENGTH); 464 Ip6Prefix.MAX_MASK_LENGTH);
453 } 465 }
454 - builder.matchIPv6Dst(dipv6); 466 + builder.matchIPv6Src(ip6Prefix);
455 break; 467 break;
456 - case IPV6_SRC: 468 + case IPV6_DST:
457 - Ip6Prefix sipv6; 469 + if (match.isPartiallyMasked(MatchField.IPV6_DST)) {
458 - if (match.isPartiallyMasked(MatchField.IPV6_SRC)) { 470 + Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_DST);
459 - Masked<IPv6Address> maskedIp = match.getMasked(MatchField.IPV6_SRC); 471 + ip6Prefix = Ip6Prefix.valueOf(
460 - sipv6 = Ip6Prefix.valueOf(
461 maskedIp.getValue().getBytes(), 472 maskedIp.getValue().getBytes(),
462 maskedIp.getMask().asCidrMaskLength()); 473 maskedIp.getMask().asCidrMaskLength());
463 } else { 474 } else {
464 - sipv6 = Ip6Prefix.valueOf( 475 + ip6Prefix = Ip6Prefix.valueOf(
465 - match.get(MatchField.IPV6_SRC).getBytes(), 476 + match.get(MatchField.IPV6_DST).getBytes(),
466 Ip6Prefix.MAX_MASK_LENGTH); 477 Ip6Prefix.MAX_MASK_LENGTH);
467 } 478 }
468 - builder.matchIPv6Src(sipv6); 479 + builder.matchIPv6Dst(ip6Prefix);
480 + break;
481 + case IPV6_FLABEL:
482 + int flowLabel =
483 + match.get(MatchField.IPV6_FLABEL).getIPv6FlowLabelValue();
484 + builder.matchIPv6FlowLabel(flowLabel);
469 break; 485 break;
470 case ICMPV6_TYPE: 486 case ICMPV6_TYPE:
471 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue(); 487 byte icmpv6type = (byte) match.get(MatchField.ICMPV6_TYPE).getValue();
...@@ -475,27 +491,41 @@ public class FlowEntryBuilder { ...@@ -475,27 +491,41 @@ public class FlowEntryBuilder {
475 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue(); 491 byte icmpv6code = (byte) match.get(MatchField.ICMPV6_CODE).getValue();
476 builder.matchIcmpv6Code(icmpv6code); 492 builder.matchIcmpv6Code(icmpv6code);
477 break; 493 break;
494 + case IPV6_ND_TARGET:
495 + ip6Address =
496 + Ip6Address.valueOf(match.get(MatchField.IPV6_ND_TARGET).getBytes());
497 + builder.matchIPv6NDTargetAddress(ip6Address);
498 + break;
499 + case IPV6_ND_SLL:
500 + mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_SLL).getLong());
501 + builder.matchIPv6NDSourceLinkLayerAddress(mac);
502 + break;
503 + case IPV6_ND_TLL:
504 + mac = MacAddress.valueOf(match.get(MatchField.IPV6_ND_TLL).getLong());
505 + builder.matchIPv6NDTargetLinkLayerAddress(mac);
506 + break;
507 + case MPLS_LABEL:
508 + builder.matchMplsLabel((int) match.get(MatchField.MPLS_LABEL)
509 + .getValue());
510 + break;
511 + case OCH_SIGID:
512 + builder.matchLambda(match.get(MatchField.OCH_SIGID).getChannelNumber());
513 + break;
514 + case OCH_SIGTYPE:
515 + builder.matchOpticalSignalType(match.get(MatchField
516 + .OCH_SIGTYPE).getValue());
517 + break;
478 case ARP_OP: 518 case ARP_OP:
479 case ARP_SHA: 519 case ARP_SHA:
480 case ARP_SPA: 520 case ARP_SPA:
481 case ARP_THA: 521 case ARP_THA:
482 case ARP_TPA: 522 case ARP_TPA:
483 - case ICMPV4_CODE:
484 - case ICMPV4_TYPE:
485 case IN_PHY_PORT: 523 case IN_PHY_PORT:
486 - case IPV6_FLABEL:
487 - case IPV6_ND_SLL:
488 - case IPV6_ND_TARGET:
489 - case IPV6_ND_TLL:
490 case IP_DSCP: 524 case IP_DSCP:
491 case IP_ECN: 525 case IP_ECN:
492 case METADATA: 526 case METADATA:
493 case MPLS_TC: 527 case MPLS_TC:
494 - case SCTP_DST:
495 - case SCTP_SRC:
496 case TUNNEL_ID: 528 case TUNNEL_ID:
497 - case UDP_DST:
498 - case UDP_SRC:
499 default: 529 default:
500 log.warn("Match type {} not yet implemented.", field.id); 530 log.warn("Match type {} not yet implemented.", field.id);
501 } 531 }
......
...@@ -25,13 +25,20 @@ import org.onosproject.net.flow.TrafficSelector; ...@@ -25,13 +25,20 @@ import org.onosproject.net.flow.TrafficSelector;
25 import org.onosproject.net.flow.criteria.Criteria; 25 import org.onosproject.net.flow.criteria.Criteria;
26 import org.onosproject.net.flow.criteria.Criteria.EthCriterion; 26 import org.onosproject.net.flow.criteria.Criteria.EthCriterion;
27 import org.onosproject.net.flow.criteria.Criteria.EthTypeCriterion; 27 import org.onosproject.net.flow.criteria.Criteria.EthTypeCriterion;
28 -import org.onosproject.net.flow.criteria.Criteria.IPCriterion; 28 +import org.onosproject.net.flow.criteria.Criteria.IcmpCodeCriterion;
29 -import org.onosproject.net.flow.criteria.Criteria.IPProtocolCriterion; 29 +import org.onosproject.net.flow.criteria.Criteria.IcmpTypeCriterion;
30 import org.onosproject.net.flow.criteria.Criteria.Icmpv6CodeCriterion; 30 import org.onosproject.net.flow.criteria.Criteria.Icmpv6CodeCriterion;
31 import org.onosproject.net.flow.criteria.Criteria.Icmpv6TypeCriterion; 31 import org.onosproject.net.flow.criteria.Criteria.Icmpv6TypeCriterion;
32 +import org.onosproject.net.flow.criteria.Criteria.IPCriterion;
33 +import org.onosproject.net.flow.criteria.Criteria.IPProtocolCriterion;
34 +import org.onosproject.net.flow.criteria.Criteria.IPv6FlowLabelCriterion;
35 +import org.onosproject.net.flow.criteria.Criteria.IPv6NDLinkLayerAddressCriterion;
36 +import org.onosproject.net.flow.criteria.Criteria.IPv6NDTargetAddressCriterion;
32 import org.onosproject.net.flow.criteria.Criteria.LambdaCriterion; 37 import org.onosproject.net.flow.criteria.Criteria.LambdaCriterion;
33 import org.onosproject.net.flow.criteria.Criteria.PortCriterion; 38 import org.onosproject.net.flow.criteria.Criteria.PortCriterion;
39 +import org.onosproject.net.flow.criteria.Criteria.SctpPortCriterion;
34 import org.onosproject.net.flow.criteria.Criteria.TcpPortCriterion; 40 import org.onosproject.net.flow.criteria.Criteria.TcpPortCriterion;
41 +import org.onosproject.net.flow.criteria.Criteria.UdpPortCriterion;
35 import org.onosproject.net.flow.criteria.Criteria.VlanIdCriterion; 42 import org.onosproject.net.flow.criteria.Criteria.VlanIdCriterion;
36 import org.onosproject.net.flow.criteria.Criteria.VlanPcpCriterion; 43 import org.onosproject.net.flow.criteria.Criteria.VlanPcpCriterion;
37 import org.onosproject.net.flow.criteria.Criterion; 44 import org.onosproject.net.flow.criteria.Criterion;
...@@ -43,8 +50,11 @@ import org.projectfloodlight.openflow.protocol.match.Match; ...@@ -43,8 +50,11 @@ import org.projectfloodlight.openflow.protocol.match.Match;
43 import org.projectfloodlight.openflow.protocol.match.MatchField; 50 import org.projectfloodlight.openflow.protocol.match.MatchField;
44 import org.projectfloodlight.openflow.types.CircuitSignalID; 51 import org.projectfloodlight.openflow.types.CircuitSignalID;
45 import org.projectfloodlight.openflow.types.EthType; 52 import org.projectfloodlight.openflow.types.EthType;
53 +import org.projectfloodlight.openflow.types.ICMPv4Code;
54 +import org.projectfloodlight.openflow.types.ICMPv4Type;
46 import org.projectfloodlight.openflow.types.IPv4Address; 55 import org.projectfloodlight.openflow.types.IPv4Address;
47 import org.projectfloodlight.openflow.types.IPv6Address; 56 import org.projectfloodlight.openflow.types.IPv6Address;
57 +import org.projectfloodlight.openflow.types.IPv6FlowLabel;
48 import org.projectfloodlight.openflow.types.IpProtocol; 58 import org.projectfloodlight.openflow.types.IpProtocol;
49 import org.projectfloodlight.openflow.types.MacAddress; 59 import org.projectfloodlight.openflow.types.MacAddress;
50 import org.projectfloodlight.openflow.types.Masked; 60 import org.projectfloodlight.openflow.types.Masked;
...@@ -135,168 +145,223 @@ public abstract class FlowModBuilder { ...@@ -135,168 +145,223 @@ public abstract class FlowModBuilder {
135 * 145 *
136 * @return the match 146 * @return the match
137 */ 147 */
148 + // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
138 protected Match buildMatch() { 149 protected Match buildMatch() {
139 Match.Builder mBuilder = factory.buildMatch(); 150 Match.Builder mBuilder = factory.buildMatch();
140 - EthCriterion eth; 151 + Ip6Address ip6Address;
141 - IPCriterion ip;
142 Ip4Prefix ip4Prefix; 152 Ip4Prefix ip4Prefix;
143 Ip6Prefix ip6Prefix; 153 Ip6Prefix ip6Prefix;
144 - TcpPortCriterion tp; 154 + EthCriterion ethCriterion;
155 + IPCriterion ipCriterion;
156 + TcpPortCriterion tcpPortCriterion;
157 + UdpPortCriterion udpPortCriterion;
158 + SctpPortCriterion sctpPortCriterion;
159 + IPv6NDLinkLayerAddressCriterion llAddressCriterion;
160 +
145 for (Criterion c : selector.criteria()) { 161 for (Criterion c : selector.criteria()) {
146 switch (c.type()) { 162 switch (c.type()) {
147 case IN_PORT: 163 case IN_PORT:
148 PortCriterion inport = (PortCriterion) c; 164 PortCriterion inport = (PortCriterion) c;
149 mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inport.port().toLong())); 165 mBuilder.setExact(MatchField.IN_PORT, OFPort.of((int) inport.port().toLong()));
150 break; 166 break;
151 - case ETH_SRC:
152 - eth = (EthCriterion) c;
153 - mBuilder.setExact(MatchField.ETH_SRC, MacAddress.of(eth.mac().toLong()));
154 - break;
155 case ETH_DST: 167 case ETH_DST:
156 - eth = (EthCriterion) c; 168 + ethCriterion = (EthCriterion) c;
157 - mBuilder.setExact(MatchField.ETH_DST, MacAddress.of(eth.mac().toLong())); 169 + mBuilder.setExact(MatchField.ETH_DST,
170 + MacAddress.of(ethCriterion.mac().toLong()));
171 + break;
172 + case ETH_SRC:
173 + ethCriterion = (EthCriterion) c;
174 + mBuilder.setExact(MatchField.ETH_SRC,
175 + MacAddress.of(ethCriterion.mac().toLong()));
158 break; 176 break;
159 case ETH_TYPE: 177 case ETH_TYPE:
160 EthTypeCriterion ethType = (EthTypeCriterion) c; 178 EthTypeCriterion ethType = (EthTypeCriterion) c;
161 mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType())); 179 mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType()));
162 break; 180 break;
163 - case IPV4_DST: 181 + case VLAN_VID:
164 - ip = (IPCriterion) c; 182 + VlanIdCriterion vid = (VlanIdCriterion) c;
165 - ip4Prefix = ip.ip().getIp4Prefix(); 183 +
184 + if (vid.vlanId().equals(VlanId.ANY)) {
185 + mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT,
186 + OFVlanVidMatch.PRESENT);
187 + } else {
188 + mBuilder.setExact(MatchField.VLAN_VID,
189 + OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
190 + }
191 + break;
192 + case VLAN_PCP:
193 + VlanPcpCriterion vpcp = (VlanPcpCriterion) c;
194 + mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority()));
195 + break;
196 + case IP_PROTO:
197 + IPProtocolCriterion p = (IPProtocolCriterion) c;
198 + mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol()));
199 + break;
200 + case IPV4_SRC:
201 + ipCriterion = (IPCriterion) c;
202 + ip4Prefix = ipCriterion.ip().getIp4Prefix();
166 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) { 203 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
167 Ip4Address maskAddr = 204 Ip4Address maskAddr =
168 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength()); 205 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
169 Masked<IPv4Address> maskedIp = 206 Masked<IPv4Address> maskedIp =
170 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), 207 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
171 IPv4Address.of(maskAddr.toInt())); 208 IPv4Address.of(maskAddr.toInt()));
172 - mBuilder.setMasked(MatchField.IPV4_DST, maskedIp); 209 + mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
173 } else { 210 } else {
174 - mBuilder.setExact(MatchField.IPV4_DST, 211 + mBuilder.setExact(MatchField.IPV4_SRC,
175 IPv4Address.of(ip4Prefix.address().toInt())); 212 IPv4Address.of(ip4Prefix.address().toInt()));
176 } 213 }
177 break; 214 break;
178 - case IPV4_SRC: 215 + case IPV4_DST:
179 - ip = (IPCriterion) c; 216 + ipCriterion = (IPCriterion) c;
180 - ip4Prefix = ip.ip().getIp4Prefix(); 217 + ip4Prefix = ipCriterion.ip().getIp4Prefix();
181 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) { 218 if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
182 Ip4Address maskAddr = 219 Ip4Address maskAddr =
183 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength()); 220 Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
184 Masked<IPv4Address> maskedIp = 221 Masked<IPv4Address> maskedIp =
185 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()), 222 Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
186 IPv4Address.of(maskAddr.toInt())); 223 IPv4Address.of(maskAddr.toInt()));
187 - mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp); 224 + mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
188 } else { 225 } else {
189 - mBuilder.setExact(MatchField.IPV4_SRC, 226 + mBuilder.setExact(MatchField.IPV4_DST,
190 IPv4Address.of(ip4Prefix.address().toInt())); 227 IPv4Address.of(ip4Prefix.address().toInt()));
191 } 228 }
192 break; 229 break;
193 - case IP_PROTO: 230 + case TCP_SRC:
194 - IPProtocolCriterion p = (IPProtocolCriterion) c; 231 + tcpPortCriterion = (TcpPortCriterion) c;
195 - mBuilder.setExact(MatchField.IP_PROTO, IpProtocol.of(p.protocol())); 232 + mBuilder.setExact(MatchField.TCP_SRC,
233 + TransportPort.of(tcpPortCriterion.tcpPort()));
196 break; 234 break;
197 - case VLAN_PCP: 235 + case TCP_DST:
198 - VlanPcpCriterion vpcp = (VlanPcpCriterion) c; 236 + tcpPortCriterion = (TcpPortCriterion) c;
199 - mBuilder.setExact(MatchField.VLAN_PCP, VlanPcp.of(vpcp.priority())); 237 + mBuilder.setExact(MatchField.TCP_DST,
238 + TransportPort.of(tcpPortCriterion.tcpPort()));
200 break; 239 break;
201 - case VLAN_VID: 240 + case UDP_SRC:
202 - VlanIdCriterion vid = (VlanIdCriterion) c; 241 + udpPortCriterion = (UdpPortCriterion) c;
203 - 242 + mBuilder.setExact(MatchField.UDP_SRC,
204 - if (vid.vlanId().equals(VlanId.ANY)) { 243 + TransportPort.of(udpPortCriterion.udpPort()));
205 - mBuilder.setMasked(MatchField.VLAN_VID, OFVlanVidMatch.PRESENT,
206 - OFVlanVidMatch.PRESENT);
207 - } else {
208 - mBuilder.setExact(MatchField.VLAN_VID,
209 - OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vid.vlanId().toShort())));
210 - }
211 break; 244 break;
212 - case TCP_DST: 245 + case UDP_DST:
213 - tp = (TcpPortCriterion) c; 246 + udpPortCriterion = (UdpPortCriterion) c;
214 - mBuilder.setExact(MatchField.TCP_DST, TransportPort.of(tp.tcpPort())); 247 + mBuilder.setExact(MatchField.UDP_DST,
248 + TransportPort.of(udpPortCriterion.udpPort()));
215 break; 249 break;
216 - case TCP_SRC: 250 + case SCTP_SRC:
217 - tp = (TcpPortCriterion) c; 251 + sctpPortCriterion = (SctpPortCriterion) c;
218 - mBuilder.setExact(MatchField.TCP_SRC, TransportPort.of(tp.tcpPort())); 252 + mBuilder.setExact(MatchField.SCTP_SRC,
253 + TransportPort.of(sctpPortCriterion.sctpPort()));
219 break; 254 break;
220 - case MPLS_LABEL: 255 + case SCTP_DST:
221 - Criteria.MplsCriterion mp = (Criteria.MplsCriterion) c; 256 + sctpPortCriterion = (SctpPortCriterion) c;
222 - mBuilder.setExact(MatchField.MPLS_LABEL, 257 + mBuilder.setExact(MatchField.SCTP_DST,
223 - U32.of(mp.label().intValue())); 258 + TransportPort.of(sctpPortCriterion.sctpPort()));
224 break; 259 break;
225 - case OCH_SIGID: 260 + case ICMPV4_TYPE:
226 - LambdaCriterion lc = (LambdaCriterion) c; 261 + IcmpTypeCriterion icmpType = (IcmpTypeCriterion) c;
227 - mBuilder.setExact(MatchField.OCH_SIGID, 262 + mBuilder.setExact(MatchField.ICMPV4_TYPE,
228 - new CircuitSignalID((byte) 1, (byte) 2, lc.lambda(), (short) 1)); 263 + ICMPv4Type.of(icmpType.icmpType()));
229 break; 264 break;
230 - case OCH_SIGTYPE: 265 + case ICMPV4_CODE:
231 - Criteria.OpticalSignalTypeCriterion sc = 266 + IcmpCodeCriterion icmpCode = (IcmpCodeCriterion) c;
232 - (Criteria.OpticalSignalTypeCriterion) c; 267 + mBuilder.setExact(MatchField.ICMPV4_CODE,
233 - mBuilder.setExact(MatchField.OCH_SIGTYPE, 268 + ICMPv4Code.of(icmpCode.icmpCode()));
234 - U8.of(sc.signalType()));
235 break; 269 break;
236 - case IPV6_DST: 270 + case IPV6_SRC:
237 - ip = (IPCriterion) c; 271 + ipCriterion = (IPCriterion) c;
238 - ip6Prefix = ip.ip().getIp6Prefix(); 272 + ip6Prefix = ipCriterion.ip().getIp6Prefix();
239 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) { 273 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
240 Ip6Address maskAddr = 274 Ip6Address maskAddr =
241 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength()); 275 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
242 Masked<IPv6Address> maskedIp = 276 Masked<IPv6Address> maskedIp =
243 Masked.of(IPv6Address.of(ip6Prefix.address().toString()), 277 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
244 IPv6Address.of(maskAddr.toString())); 278 IPv6Address.of(maskAddr.toString()));
245 - mBuilder.setMasked(MatchField.IPV6_DST, maskedIp); 279 + mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp);
246 } else { 280 } else {
247 - mBuilder.setExact(MatchField.IPV6_DST, 281 + mBuilder.setExact(MatchField.IPV6_SRC,
248 IPv6Address.of(ip6Prefix.address().toString())); 282 IPv6Address.of(ip6Prefix.address().toString()));
249 } 283 }
250 break; 284 break;
251 - case IPV6_SRC: 285 + case IPV6_DST:
252 - ip = (IPCriterion) c; 286 + ipCriterion = (IPCriterion) c;
253 - ip6Prefix = ip.ip().getIp6Prefix(); 287 + ip6Prefix = ipCriterion.ip().getIp6Prefix();
254 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) { 288 if (ip6Prefix.prefixLength() != Ip6Prefix.MAX_MASK_LENGTH) {
255 Ip6Address maskAddr = 289 Ip6Address maskAddr =
256 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength()); 290 Ip6Address.makeMaskPrefix(ip6Prefix.prefixLength());
257 Masked<IPv6Address> maskedIp = 291 Masked<IPv6Address> maskedIp =
258 Masked.of(IPv6Address.of(ip6Prefix.address().toString()), 292 Masked.of(IPv6Address.of(ip6Prefix.address().toString()),
259 IPv6Address.of(maskAddr.toString())); 293 IPv6Address.of(maskAddr.toString()));
260 - mBuilder.setMasked(MatchField.IPV6_SRC, maskedIp); 294 + mBuilder.setMasked(MatchField.IPV6_DST, maskedIp);
261 } else { 295 } else {
262 - mBuilder.setExact(MatchField.IPV6_SRC, 296 + mBuilder.setExact(MatchField.IPV6_DST,
263 IPv6Address.of(ip6Prefix.address().toString())); 297 IPv6Address.of(ip6Prefix.address().toString()));
264 } 298 }
265 break; 299 break;
300 + case IPV6_FLABEL:
301 + IPv6FlowLabelCriterion flowLabelCriterion =
302 + (IPv6FlowLabelCriterion) c;
303 + mBuilder.setExact(MatchField.IPV6_FLABEL,
304 + IPv6FlowLabel.of(flowLabelCriterion.flowLabel()));
305 + break;
266 case ICMPV6_TYPE: 306 case ICMPV6_TYPE:
267 - Icmpv6TypeCriterion icmpv6type = (Icmpv6TypeCriterion) c; 307 + Icmpv6TypeCriterion icmpv6Type = (Icmpv6TypeCriterion) c;
268 mBuilder.setExact(MatchField.ICMPV6_TYPE, 308 mBuilder.setExact(MatchField.ICMPV6_TYPE,
269 - U8.of(icmpv6type.icmpv6Type().byteValue())); 309 + U8.of(icmpv6Type.icmpv6Type().byteValue()));
270 break; 310 break;
271 case ICMPV6_CODE: 311 case ICMPV6_CODE:
272 - Icmpv6CodeCriterion icmpv6code = (Icmpv6CodeCriterion) c; 312 + Icmpv6CodeCriterion icmpv6Code = (Icmpv6CodeCriterion) c;
273 mBuilder.setExact(MatchField.ICMPV6_CODE, 313 mBuilder.setExact(MatchField.ICMPV6_CODE,
274 - U8.of(icmpv6code.icmpv6Code().byteValue())); 314 + U8.of(icmpv6Code.icmpv6Code().byteValue()));
315 + break;
316 + case IPV6_ND_TARGET:
317 + IPv6NDTargetAddressCriterion targetAddressCriterion =
318 + (IPv6NDTargetAddressCriterion) c;
319 + ip6Address = targetAddressCriterion.targetAddress();
320 + mBuilder.setExact(MatchField.IPV6_ND_TARGET,
321 + IPv6Address.of(ip6Address.toOctets()));
322 + break;
323 + case IPV6_ND_SLL:
324 + llAddressCriterion =
325 + (IPv6NDLinkLayerAddressCriterion) c;
326 + mBuilder.setExact(MatchField.IPV6_ND_SLL,
327 + MacAddress.of(llAddressCriterion.mac().toLong()));
328 + break;
329 + case IPV6_ND_TLL:
330 + llAddressCriterion =
331 + (IPv6NDLinkLayerAddressCriterion) c;
332 + mBuilder.setExact(MatchField.IPV6_ND_TLL,
333 + MacAddress.of(llAddressCriterion.mac().toLong()));
334 + break;
335 + case MPLS_LABEL:
336 + Criteria.MplsCriterion mp = (Criteria.MplsCriterion) c;
337 + mBuilder.setExact(MatchField.MPLS_LABEL,
338 + U32.of(mp.label().intValue()));
339 + break;
340 + case OCH_SIGID:
341 + LambdaCriterion lc = (LambdaCriterion) c;
342 + mBuilder.setExact(MatchField.OCH_SIGID,
343 + new CircuitSignalID((byte) 1, (byte) 2, lc.lambda(), (short) 1));
344 + break;
345 + case OCH_SIGTYPE:
346 + Criteria.OpticalSignalTypeCriterion sc =
347 + (Criteria.OpticalSignalTypeCriterion) c;
348 + mBuilder.setExact(MatchField.OCH_SIGTYPE,
349 + U8.of(sc.signalType()));
275 break; 350 break;
276 case ARP_OP: 351 case ARP_OP:
277 case ARP_SHA: 352 case ARP_SHA:
278 case ARP_SPA: 353 case ARP_SPA:
279 case ARP_THA: 354 case ARP_THA:
280 case ARP_TPA: 355 case ARP_TPA:
281 - case ICMPV4_CODE:
282 - case ICMPV4_TYPE:
283 case IN_PHY_PORT: 356 case IN_PHY_PORT:
284 case IPV6_EXTHDR: 357 case IPV6_EXTHDR:
285 - case IPV6_FLABEL:
286 - case IPV6_ND_SLL:
287 - case IPV6_ND_TARGET:
288 - case IPV6_ND_TLL:
289 case IP_DSCP: 358 case IP_DSCP:
290 case IP_ECN: 359 case IP_ECN:
291 case METADATA: 360 case METADATA:
292 case MPLS_BOS: 361 case MPLS_BOS:
293 case MPLS_TC: 362 case MPLS_TC:
294 case PBB_ISID: 363 case PBB_ISID:
295 - case SCTP_DST:
296 - case SCTP_SRC:
297 case TUNNEL_ID: 364 case TUNNEL_ID:
298 - case UDP_DST:
299 - case UDP_SRC:
300 default: 365 default:
301 log.warn("Match type {} not yet implemented.", c.type()); 366 log.warn("Match type {} not yet implemented.", c.type());
302 } 367 }
......
...@@ -44,11 +44,11 @@ public class CriterionCodec extends JsonCodec<Criterion> { ...@@ -44,11 +44,11 @@ public class CriterionCodec extends JsonCodec<Criterion> {
44 44
45 case IN_PORT: 45 case IN_PORT:
46 final Criteria.PortCriterion portCriterion = (Criteria.PortCriterion) criterion; 46 final Criteria.PortCriterion portCriterion = (Criteria.PortCriterion) criterion;
47 - result.put("tcpPort", portCriterion.port().toLong()); 47 + result.put("port", portCriterion.port().toLong());
48 break; 48 break;
49 49
50 - case ETH_SRC:
51 case ETH_DST: 50 case ETH_DST:
51 + case ETH_SRC:
52 final Criteria.EthCriterion ethCriterion = (Criteria.EthCriterion) criterion; 52 final Criteria.EthCriterion ethCriterion = (Criteria.EthCriterion) criterion;
53 result.put("mac", ethCriterion.mac().toString()); 53 result.put("mac", ethCriterion.mac().toString());
54 break; 54 break;
...@@ -59,18 +59,10 @@ public class CriterionCodec extends JsonCodec<Criterion> { ...@@ -59,18 +59,10 @@ public class CriterionCodec extends JsonCodec<Criterion> {
59 result.put("ethType", ethTypeCriterion.ethType()); 59 result.put("ethType", ethTypeCriterion.ethType());
60 break; 60 break;
61 61
62 - case IPV4_SRC: 62 + case VLAN_VID:
63 - case IPV6_SRC: 63 + final Criteria.VlanIdCriterion vlanIdCriterion =
64 - case IPV4_DST: 64 + (Criteria.VlanIdCriterion) criterion;
65 - case IPV6_DST: 65 + result.put("vlanId", vlanIdCriterion.vlanId().toShort());
66 - final Criteria.IPCriterion iPCriterion = (Criteria.IPCriterion) criterion;
67 - result.put("ip", iPCriterion.ip().toString());
68 - break;
69 -
70 - case IP_PROTO:
71 - final Criteria.IPProtocolCriterion iPProtocolCriterion =
72 - (Criteria.IPProtocolCriterion) criterion;
73 - result.put("protocol", iPProtocolCriterion.protocol());
74 break; 66 break;
75 67
76 case VLAN_PCP: 68 case VLAN_PCP:
...@@ -79,10 +71,18 @@ public class CriterionCodec extends JsonCodec<Criterion> { ...@@ -79,10 +71,18 @@ public class CriterionCodec extends JsonCodec<Criterion> {
79 result.put("priority", vlanPcpCriterion.priority()); 71 result.put("priority", vlanPcpCriterion.priority());
80 break; 72 break;
81 73
82 - case VLAN_VID: 74 + case IP_PROTO:
83 - final Criteria.VlanIdCriterion vlanIdCriterion = 75 + final Criteria.IPProtocolCriterion iPProtocolCriterion =
84 - (Criteria.VlanIdCriterion) criterion; 76 + (Criteria.IPProtocolCriterion) criterion;
85 - result.put("vlanId", vlanIdCriterion.vlanId().toShort()); 77 + result.put("protocol", iPProtocolCriterion.protocol());
78 + break;
79 +
80 + case IPV4_SRC:
81 + case IPV4_DST:
82 + case IPV6_SRC:
83 + case IPV6_DST:
84 + final Criteria.IPCriterion iPCriterion = (Criteria.IPCriterion) criterion;
85 + result.put("ip", iPCriterion.ip().toString());
86 break; 86 break;
87 87
88 case TCP_SRC: 88 case TCP_SRC:
...@@ -92,6 +92,67 @@ public class CriterionCodec extends JsonCodec<Criterion> { ...@@ -92,6 +92,67 @@ public class CriterionCodec extends JsonCodec<Criterion> {
92 result.put("tcpPort", tcpPortCriterion.tcpPort().byteValue()); 92 result.put("tcpPort", tcpPortCriterion.tcpPort().byteValue());
93 break; 93 break;
94 94
95 + case UDP_SRC:
96 + case UDP_DST:
97 + final Criteria.UdpPortCriterion udpPortCriterion =
98 + (Criteria.UdpPortCriterion) criterion;
99 + result.put("udpPort", udpPortCriterion.udpPort().byteValue());
100 + break;
101 +
102 + case SCTP_SRC:
103 + case SCTP_DST:
104 + final Criteria.SctpPortCriterion sctpPortCriterion =
105 + (Criteria.SctpPortCriterion) criterion;
106 + result.put("sctpPort",
107 + sctpPortCriterion.sctpPort().byteValue());
108 + break;
109 +
110 + case ICMPV4_TYPE:
111 + final Criteria.IcmpTypeCriterion icmpTypeCriterion =
112 + (Criteria.IcmpTypeCriterion) criterion;
113 + result.put("icmpType", icmpTypeCriterion.icmpType());
114 + break;
115 +
116 + case ICMPV4_CODE:
117 + final Criteria.IcmpCodeCriterion icmpCodeCriterion =
118 + (Criteria.IcmpCodeCriterion) criterion;
119 + result.put("icmpCode", icmpCodeCriterion.icmpCode());
120 + break;
121 +
122 + case IPV6_FLABEL:
123 + final Criteria.IPv6FlowLabelCriterion ipv6FlowLabelCriterion =
124 + (Criteria.IPv6FlowLabelCriterion) criterion;
125 + result.put("flowLabel",
126 + ipv6FlowLabelCriterion.flowLabel());
127 + break;
128 +
129 + case ICMPV6_TYPE:
130 + final Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
131 + (Criteria.Icmpv6TypeCriterion) criterion;
132 + result.put("icmpv6Type", icmpv6TypeCriterion.icmpv6Type());
133 + break;
134 +
135 + case ICMPV6_CODE:
136 + final Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
137 + (Criteria.Icmpv6CodeCriterion) criterion;
138 + result.put("icmpv6Code", icmpv6CodeCriterion.icmpv6Code());
139 + break;
140 +
141 + case IPV6_ND_TARGET:
142 + final Criteria.IPv6NDTargetAddressCriterion ipv6NDTargetAddressCriterion
143 + = (Criteria.IPv6NDTargetAddressCriterion) criterion;
144 + result.put("targetAddress",
145 + ipv6NDTargetAddressCriterion.targetAddress().toString());
146 + break;
147 +
148 + case IPV6_ND_SLL:
149 + case IPV6_ND_TLL:
150 + final Criteria.IPv6NDLinkLayerAddressCriterion ipv6NDLinkLayerAddressCriterion
151 + = (Criteria.IPv6NDLinkLayerAddressCriterion) criterion;
152 + result.put("mac",
153 + ipv6NDLinkLayerAddressCriterion.mac().toString());
154 + break;
155 +
95 case MPLS_LABEL: 156 case MPLS_LABEL:
96 final Criteria.MplsCriterion mplsCriterion = 157 final Criteria.MplsCriterion mplsCriterion =
97 (Criteria.MplsCriterion) criterion; 158 (Criteria.MplsCriterion) criterion;
......
...@@ -33,6 +33,7 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo ...@@ -33,6 +33,7 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
33 criterion = criterionValue; 33 criterion = criterionValue;
34 } 34 }
35 35
36 + // CHECKSTYLE IGNORE MethodLength FOR NEXT 300 LINES
36 @Override 37 @Override
37 public boolean matchesSafely(JsonNode jsonCriterion, Description description) { 38 public boolean matchesSafely(JsonNode jsonCriterion, Description description) {
38 final String type = criterion.type().name(); 39 final String type = criterion.type().name();
...@@ -54,8 +55,8 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo ...@@ -54,8 +55,8 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
54 } 55 }
55 break; 56 break;
56 57
57 - case ETH_SRC:
58 case ETH_DST: 58 case ETH_DST:
59 + case ETH_SRC:
59 final Criteria.EthCriterion ethCriterion = (Criteria.EthCriterion) criterion; 60 final Criteria.EthCriterion ethCriterion = (Criteria.EthCriterion) criterion;
60 final String mac = ethCriterion.mac().toString(); 61 final String mac = ethCriterion.mac().toString();
61 final String jsonMac = jsonCriterion.get("mac").textValue(); 62 final String jsonMac = jsonCriterion.get("mac").textValue();
...@@ -76,15 +77,24 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo ...@@ -76,15 +77,24 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
76 } 77 }
77 break; 78 break;
78 79
79 - case IPV4_SRC: 80 + case VLAN_VID:
80 - case IPV6_SRC: 81 + final Criteria.VlanIdCriterion vlanIdCriterion =
81 - case IPV4_DST: 82 + (Criteria.VlanIdCriterion) criterion;
82 - case IPV6_DST: 83 + final short vlanId = vlanIdCriterion.vlanId().toShort();
83 - final Criteria.IPCriterion ipCriterion = (Criteria.IPCriterion) criterion; 84 + final short jsonVlanId = jsonCriterion.get("vlanId").shortValue();
84 - final String ip = ipCriterion.ip().toString(); 85 + if (vlanId != jsonVlanId) {
85 - final String jsonIp = jsonCriterion.get("ip").textValue(); 86 + description.appendText("vlanId was " + Short.toString(jsonVlanId));
86 - if (!ip.equals(jsonIp)) { 87 + return false;
87 - description.appendText("ip was " + jsonIp); 88 + }
89 + break;
90 +
91 + case VLAN_PCP:
92 + final Criteria.VlanPcpCriterion vlanPcpCriterion =
93 + (Criteria.VlanPcpCriterion) criterion;
94 + final byte priority = vlanPcpCriterion.priority();
95 + final byte jsonPriority = (byte) jsonCriterion.get("priority").shortValue();
96 + if (priority != jsonPriority) {
97 + description.appendText("priority was " + Byte.toString(jsonPriority));
88 return false; 98 return false;
89 } 99 }
90 break; 100 break;
...@@ -100,24 +110,15 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo ...@@ -100,24 +110,15 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
100 } 110 }
101 break; 111 break;
102 112
103 - case VLAN_PCP: 113 + case IPV4_SRC:
104 - final Criteria.VlanPcpCriterion vlanPcpCriterion = 114 + case IPV4_DST:
105 - (Criteria.VlanPcpCriterion) criterion; 115 + case IPV6_SRC:
106 - final byte priority = vlanPcpCriterion.priority(); 116 + case IPV6_DST:
107 - final byte jsonPriority = (byte) jsonCriterion.get("protocol").shortValue(); 117 + final Criteria.IPCriterion ipCriterion = (Criteria.IPCriterion) criterion;
108 - if (priority != jsonPriority) { 118 + final String ip = ipCriterion.ip().toString();
109 - description.appendText("priority was " + Byte.toString(jsonPriority)); 119 + final String jsonIp = jsonCriterion.get("ip").textValue();
110 - return false; 120 + if (!ip.equals(jsonIp)) {
111 - } 121 + description.appendText("ip was " + jsonIp);
112 - break;
113 -
114 - case VLAN_VID:
115 - final Criteria.VlanIdCriterion vlanIdCriterion =
116 - (Criteria.VlanIdCriterion) criterion;
117 - final short vlanId = vlanIdCriterion.vlanId().toShort();
118 - final short jsonvlanId = jsonCriterion.get("vlanId").shortValue();
119 - if (vlanId != jsonvlanId) {
120 - description.appendText("vlanId was " + Short.toString(jsonvlanId));
121 return false; 122 return false;
122 } 123 }
123 break; 124 break;
...@@ -126,10 +127,119 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo ...@@ -126,10 +127,119 @@ public final class CriterionJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNo
126 case TCP_DST: 127 case TCP_DST:
127 final Criteria.TcpPortCriterion tcpPortCriterion = 128 final Criteria.TcpPortCriterion tcpPortCriterion =
128 (Criteria.TcpPortCriterion) criterion; 129 (Criteria.TcpPortCriterion) criterion;
129 - final byte tcpPort = tcpPortCriterion.tcpPort().byteValue(); 130 + final short tcpPort = tcpPortCriterion.tcpPort();
130 - final byte jsonTcpPort = (byte) jsonCriterion.get("tcpPort").shortValue(); 131 + final short jsonTcpPort = jsonCriterion.get("tcpPort").shortValue();
131 if (tcpPort != jsonTcpPort) { 132 if (tcpPort != jsonTcpPort) {
132 - description.appendText("tcp port was " + Byte.toString(jsonTcpPort)); 133 + description.appendText("tcp port was " + Short.toString(jsonTcpPort));
134 + return false;
135 + }
136 + break;
137 +
138 + case UDP_SRC:
139 + case UDP_DST:
140 + final Criteria.UdpPortCriterion udpPortCriterion =
141 + (Criteria.UdpPortCriterion) criterion;
142 + final short udpPort = udpPortCriterion.udpPort();
143 + final short jsonUdpPort = jsonCriterion.get("udpPort").shortValue();
144 + if (udpPort != jsonUdpPort) {
145 + description.appendText("udp port was " + Short.toString(jsonUdpPort));
146 + return false;
147 + }
148 + break;
149 +
150 + case SCTP_SRC:
151 + case SCTP_DST:
152 + final Criteria.SctpPortCriterion sctpPortCriterion =
153 + (Criteria.SctpPortCriterion) criterion;
154 + final short sctpPort = sctpPortCriterion.sctpPort();
155 + final short jsonSctpPort = jsonCriterion.get("sctpPort").shortValue();
156 + if (sctpPort != jsonSctpPort) {
157 + description.appendText("sctp port was " + Short.toString(jsonSctpPort));
158 + return false;
159 + }
160 + break;
161 +
162 + case ICMPV4_TYPE:
163 + final Criteria.IcmpTypeCriterion icmpTypeCriterion =
164 + (Criteria.IcmpTypeCriterion) criterion;
165 + final byte icmpType = icmpTypeCriterion.icmpType();
166 + final byte jsonIcmpType = (byte) jsonCriterion.get("icmpType").shortValue();
167 + if (icmpType != jsonIcmpType) {
168 + description.appendText("icmp type was " + Byte.toString(jsonIcmpType));
169 + return false;
170 + }
171 + break;
172 +
173 + case ICMPV4_CODE:
174 + final Criteria.IcmpCodeCriterion icmpCodeCriterion =
175 + (Criteria.IcmpCodeCriterion) criterion;
176 + final byte icmpCode = icmpCodeCriterion.icmpCode();
177 + final byte jsonIcmpCode = (byte) jsonCriterion.get("icmpCode").shortValue();
178 + if (icmpCode != jsonIcmpCode) {
179 + description.appendText("icmp code was " + Byte.toString(jsonIcmpCode));
180 + return false;
181 + }
182 + break;
183 +
184 + case IPV6_FLABEL:
185 + final Criteria.IPv6FlowLabelCriterion ipv6FlowLabelCriterion =
186 + (Criteria.IPv6FlowLabelCriterion) criterion;
187 + final int flowLabel = ipv6FlowLabelCriterion.flowLabel();
188 + final int jsonFlowLabel = jsonCriterion.get("flowLabel").intValue();
189 + if (flowLabel != jsonFlowLabel) {
190 + description.appendText("IPv6 flow label was " + Integer.toString(jsonFlowLabel));
191 + return false;
192 + }
193 + break;
194 +
195 + case ICMPV6_TYPE:
196 + final Criteria.Icmpv6TypeCriterion icmpv6TypeCriterion =
197 + (Criteria.Icmpv6TypeCriterion) criterion;
198 + final byte icmpv6Type = icmpv6TypeCriterion.icmpv6Type();
199 + final byte jsonIcmpv6Type = (byte) jsonCriterion.get("icmpv6Type").shortValue();
200 + if (icmpv6Type != jsonIcmpv6Type) {
201 + description.appendText("icmpv6 type was " + Byte.toString(jsonIcmpv6Type));
202 + return false;
203 + }
204 + break;
205 +
206 + case ICMPV6_CODE:
207 + final Criteria.Icmpv6CodeCriterion icmpv6CodeCriterion =
208 + (Criteria.Icmpv6CodeCriterion) criterion;
209 + final byte icmpv6Code = icmpv6CodeCriterion.icmpv6Code();
210 + final byte jsonIcmpv6Code = (byte) jsonCriterion.get("icmpv6Code").shortValue();
211 + if (icmpv6Code != jsonIcmpv6Code) {
212 + description.appendText("icmpv6 code was " + Byte.toString(jsonIcmpv6Code));
213 + return false;
214 + }
215 + break;
216 +
217 + case IPV6_ND_TARGET:
218 + final Criteria.IPv6NDTargetAddressCriterion
219 + ipv6NDTargetAddressCriterion =
220 + (Criteria.IPv6NDTargetAddressCriterion) criterion;
221 + final String targetAddress =
222 + ipv6NDTargetAddressCriterion.targetAddress().toString();
223 + final String jsonTargetAddress =
224 + jsonCriterion.get("targetAddress").textValue();
225 + if (!targetAddress.equals(jsonTargetAddress)) {
226 + description.appendText("target address was " +
227 + jsonTargetAddress);
228 + return false;
229 + }
230 + break;
231 +
232 + case IPV6_ND_SLL:
233 + case IPV6_ND_TLL:
234 + final Criteria.IPv6NDLinkLayerAddressCriterion
235 + ipv6NDLinkLayerAddressCriterion =
236 + (Criteria.IPv6NDLinkLayerAddressCriterion) criterion;
237 + final String llAddress =
238 + ipv6NDLinkLayerAddressCriterion.mac().toString();
239 + final String jsonLlAddress =
240 + jsonCriterion.get("mac").textValue();
241 + if (!llAddress.equals(jsonLlAddress)) {
242 + description.appendText("mac was " + jsonLlAddress);
133 return false; 243 return false;
134 } 244 }
135 break; 245 break;
......