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