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