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