Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.codec.impl; |
| 17 | |
| 18 | import java.util.EnumMap; |
| 19 | |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 20 | import org.junit.Before; |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 21 | import org.junit.Test; |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 22 | import org.onlab.packet.Ip6Address; |
| 23 | import org.onlab.packet.IpPrefix; |
| 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onlab.packet.VlanId; |
| 26 | import org.onosproject.codec.CodecContext; |
| 27 | import org.onosproject.codec.JsonCodec; |
| 28 | import org.onosproject.net.PortNumber; |
| 29 | import org.onosproject.net.flow.criteria.Criteria; |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 30 | import org.onosproject.net.flow.criteria.Criterion; |
| 31 | |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 32 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 33 | |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 34 | import static org.hamcrest.MatcherAssert.assertThat; |
Ray Milkey | 0cc189e | 2015-02-09 11:08:01 -0800 | [diff] [blame^] | 35 | import static org.hamcrest.Matchers.is; |
| 36 | import static org.hamcrest.Matchers.notNullValue; |
| 37 | import static org.onlab.junit.TestUtils.getField; |
| 38 | import static org.onlab.junit.TestUtils.setField; |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 39 | import static org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion; |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Unit tests for criterion codec. |
| 43 | */ |
| 44 | public class CriterionCodecTest { |
| 45 | |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 46 | CodecContext context; |
| 47 | JsonCodec<Criterion> criterionCodec; |
| 48 | final PortNumber port = PortNumber.portNumber(1); |
| 49 | final IpPrefix ipPrefix4 = IpPrefix.valueOf("10.1.1.0/24"); |
| 50 | final IpPrefix ipPrefix6 = IpPrefix.valueOf("fe80::/64"); |
| 51 | final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01"); |
| 52 | |
| 53 | /** |
| 54 | * Sets up for each test. Creates a context and fetches the criterion |
| 55 | * codec. |
| 56 | */ |
| 57 | @Before |
| 58 | public void setUp() { |
| 59 | context = new MockCodecContext(); |
| 60 | criterionCodec = context.codec(Criterion.class); |
| 61 | assertThat(criterionCodec, notNullValue()); |
| 62 | } |
| 63 | |
| 64 | |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Checks that all criterion types are covered by the codec. |
| 67 | */ |
| 68 | @Test |
| 69 | public void checkCriterionTypes() throws Exception { |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 70 | EnumMap<Criterion.Type, Object> formatMap = |
| 71 | getField(criterionCodec, "formatMap"); |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 72 | assertThat(formatMap, notNullValue()); |
| 73 | |
| 74 | for (Criterion.Type type : Criterion.Type.values()) { |
| 75 | assertThat("Entry not found for " + type.toString(), |
| 76 | formatMap.get(type), notNullValue()); |
| 77 | } |
| 78 | } |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Tests in port criterion. |
| 82 | */ |
| 83 | @Test |
| 84 | public void matchInPortTest() { |
| 85 | Criterion criterion = Criteria.matchInPort(port); |
| 86 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 87 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Tests in physical port criterion. |
| 92 | */ |
| 93 | @Test |
| 94 | public void matchInPhyPortTest() { |
| 95 | Criterion criterion = Criteria.matchInPhyPort(port); |
| 96 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 97 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Tests metadata criterion. |
| 102 | */ |
| 103 | @Test |
| 104 | public void matchMetadataTest() { |
| 105 | Criterion criterion = Criteria.matchMetadata(0xabcdL); |
| 106 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 107 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Tests ethernet destination criterion. |
| 112 | */ |
| 113 | @Test |
| 114 | public void matchEthDstTest() { |
| 115 | Criterion criterion = Criteria.matchEthDst(mac1); |
| 116 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 117 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Tests ethernet source criterion. |
| 122 | */ |
| 123 | @Test |
| 124 | public void matchEthSrcTest() { |
| 125 | Criterion criterion = Criteria.matchEthSrc(mac1); |
| 126 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 127 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Tests ethernet type criterion. |
| 132 | */ |
| 133 | @Test |
| 134 | public void matchEthTypeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 135 | Criterion criterion = Criteria.matchEthType((short) 0x8844); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 136 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 137 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Tests VLAN Id criterion. |
| 142 | */ |
| 143 | @Test |
| 144 | public void matchVlanIdTest() { |
| 145 | Criterion criterion = Criteria.matchVlanId(VlanId.ANY); |
| 146 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 147 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Tests VLAN PCP criterion. |
| 152 | */ |
| 153 | @Test |
| 154 | public void matchVlanPcpTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 155 | Criterion criterion = Criteria.matchVlanPcp((byte) 7); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 156 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 157 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Tests IP DSCP criterion. |
| 162 | */ |
| 163 | @Test |
| 164 | public void matchIPDscpTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 165 | Criterion criterion = Criteria.matchIPDscp((byte) 63); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 166 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 167 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Tests IP ECN criterion. |
| 172 | */ |
| 173 | @Test |
| 174 | public void matchIPEcnTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 175 | Criterion criterion = Criteria.matchIPEcn((byte) 7); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 176 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 177 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Tests IP protocol criterion. |
| 182 | */ |
| 183 | @Test |
| 184 | public void matchIPProtocolTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 185 | Criterion criterion = Criteria.matchIPProtocol((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 186 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 187 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Tests IP source criterion. |
| 192 | */ |
| 193 | @Test |
| 194 | public void matchIPSrcTest() { |
| 195 | Criterion criterion = Criteria.matchIPSrc(ipPrefix4); |
| 196 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 197 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Tests IP destination criterion. |
| 202 | */ |
| 203 | @Test |
| 204 | public void matchIPDstTest() { |
| 205 | Criterion criterion = Criteria.matchIPDst(ipPrefix4); |
| 206 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 207 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Tests source TCP port criterion. |
| 212 | */ |
| 213 | @Test |
| 214 | public void matchTcpSrcTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 215 | Criterion criterion = Criteria.matchTcpSrc((short) 40000); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 216 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 217 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Tests destination TCP port criterion. |
| 222 | */ |
| 223 | @Test |
| 224 | public void matchTcpDstTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 225 | Criterion criterion = Criteria.matchTcpDst((short) 40000); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 226 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 227 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Tests source UDP port criterion. |
| 232 | */ |
| 233 | @Test |
| 234 | public void matchUdpSrcTest() { |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 235 | Criterion criterion = Criteria.matchUdpSrc(40000); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 236 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 237 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Tests destination UDP criterion. |
| 242 | */ |
| 243 | @Test |
| 244 | public void matchUdpDstTest() { |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 245 | Criterion criterion = Criteria.matchUdpDst(40000); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 246 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 247 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Tests source SCTP criterion. |
| 252 | */ |
| 253 | @Test |
| 254 | public void matchSctpSrcTest() { |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 255 | Criterion criterion = Criteria.matchSctpSrc(40000); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 256 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 257 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Tests destination SCTP criterion. |
| 262 | */ |
| 263 | @Test |
| 264 | public void matchSctpDstTest() { |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 265 | Criterion criterion = Criteria.matchSctpDst(40000); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 266 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 267 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Tests ICMP type criterion. |
| 272 | */ |
| 273 | @Test |
| 274 | public void matchIcmpTypeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 275 | Criterion criterion = Criteria.matchIcmpType((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 276 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 277 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Tests ICMP code criterion. |
| 282 | */ |
| 283 | @Test |
| 284 | public void matchIcmpCodeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 285 | Criterion criterion = Criteria.matchIcmpCode((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 286 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 287 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Tests IPv6 source criterion. |
| 292 | */ |
| 293 | @Test |
| 294 | public void matchIPv6SrcTest() { |
| 295 | Criterion criterion = Criteria.matchIPv6Src(ipPrefix6); |
| 296 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 297 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Tests IPv6 destination criterion. |
| 302 | */ |
| 303 | @Test |
| 304 | public void matchIPv6DstTest() { |
| 305 | Criterion criterion = Criteria.matchIPv6Dst(ipPrefix6); |
| 306 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 307 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Tests IPv6 flow label criterion. |
| 312 | */ |
| 313 | @Test |
| 314 | public void matchIPv6FlowLabelTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 315 | Criterion criterion = Criteria.matchIPv6FlowLabel(0xffffe); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 316 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 317 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Tests ICMP v6 type criterion. |
| 322 | */ |
| 323 | @Test |
| 324 | public void matchIcmpv6TypeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 325 | Criterion criterion = Criteria.matchIcmpv6Type((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 326 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 327 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Tests ICMP v6 code criterion. |
| 332 | */ |
| 333 | @Test |
| 334 | public void matchIcmpv6CodeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 335 | Criterion criterion = Criteria.matchIcmpv6Code((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 336 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 337 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /** |
| 341 | * Tests IPV6 target address criterion. |
| 342 | */ |
| 343 | @Test |
| 344 | public void matchIPv6NDTargetAddressTest() { |
| 345 | Criterion criterion = |
| 346 | Criteria.matchIPv6NDTargetAddress( |
| 347 | Ip6Address.valueOf("1111:2222::")); |
| 348 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 349 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Tests IPV6 SLL criterion. |
| 354 | */ |
| 355 | @Test |
| 356 | public void matchIPv6NDSourceLinkLayerAddressTest() { |
| 357 | Criterion criterion = Criteria.matchIPv6NDSourceLinkLayerAddress(mac1); |
| 358 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 359 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Tests IPV6 TLL criterion. |
| 364 | */ |
| 365 | @Test |
| 366 | public void matchIPv6NDTargetLinkLayerAddressTest() { |
| 367 | Criterion criterion = Criteria.matchIPv6NDTargetLinkLayerAddress(mac1); |
| 368 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 369 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Tests MPLS label criterion. |
| 374 | */ |
| 375 | @Test |
| 376 | public void matchMplsLabelTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 377 | Criterion criterion = Criteria.matchMplsLabel(0xffffe); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 378 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 379 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /** |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 383 | * Tests IPv6 Extension Header pseudo-field flags criterion. |
| 384 | */ |
| 385 | @Test |
| 386 | public void matchIPv6ExthdrFlagsTest() { |
| 387 | int exthdrFlags = |
| 388 | Criterion.IPv6ExthdrFlags.NONEXT.getValue() | |
| 389 | Criterion.IPv6ExthdrFlags.ESP.getValue() | |
| 390 | Criterion.IPv6ExthdrFlags.AUTH.getValue() | |
| 391 | Criterion.IPv6ExthdrFlags.DEST.getValue() | |
| 392 | Criterion.IPv6ExthdrFlags.FRAG.getValue() | |
| 393 | Criterion.IPv6ExthdrFlags.ROUTER.getValue() | |
| 394 | Criterion.IPv6ExthdrFlags.HOP.getValue() | |
| 395 | Criterion.IPv6ExthdrFlags.UNREP.getValue() | |
| 396 | Criterion.IPv6ExthdrFlags.UNSEQ.getValue(); |
| 397 | Criterion criterion = Criteria.matchIPv6ExthdrFlags(exthdrFlags); |
| 398 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 399 | |
| 400 | assertThat(result, matchesCriterion(criterion)); |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 404 | * Tests lambda criterion. |
| 405 | */ |
| 406 | @Test |
| 407 | public void matchLambdaTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 408 | Criterion criterion = Criteria.matchLambda((short) 40000); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 409 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 410 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Tests optical signal type criterion. |
| 415 | */ |
| 416 | @Test |
| 417 | public void matchOpticalSignalTypeTest() { |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 418 | Criterion criterion = Criteria.matchOpticalSignalType((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 419 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 420 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Ray Milkey | 0cc189e | 2015-02-09 11:08:01 -0800 | [diff] [blame^] | 423 | /** |
| 424 | * Tests that an unimplemented criterion type only returns the type and |
| 425 | * no other data. |
| 426 | */ |
| 427 | @Test |
| 428 | public void matchUnknownTypeTest() throws Exception { |
| 429 | Criterion criterion = Criteria.matchOpticalSignalType((byte) 250); |
| 430 | setField(criterion, "type", Criterion.Type.UNASSIGNED_40); |
| 431 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 432 | assertThat(result.get("type").textValue(), is(criterion.type().toString())); |
| 433 | assertThat(result.size(), is(1)); |
| 434 | } |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 435 | } |