Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 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 | |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 18 | import java.io.IOException; |
| 19 | import java.io.InputStream; |
| 20 | import java.util.Collection; |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 21 | import java.util.EnumMap; |
| 22 | |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 23 | import com.fasterxml.jackson.databind.JsonNode; |
| 24 | import org.hamcrest.MatcherAssert; |
| 25 | import org.junit.Assert; |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 26 | import org.junit.Before; |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 27 | import org.junit.Test; |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 28 | import org.onlab.packet.Ip6Address; |
| 29 | import org.onlab.packet.IpPrefix; |
| 30 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 31 | import org.onlab.packet.MplsLabel; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 32 | import org.onlab.packet.TpPort; |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 33 | import org.onlab.packet.VlanId; |
| 34 | import org.onosproject.codec.CodecContext; |
| 35 | import org.onosproject.codec.JsonCodec; |
Sho SHIMIZU | c44c0c3 | 2015-06-01 11:40:48 -0700 | [diff] [blame] | 36 | import org.onosproject.net.ChannelSpacing; |
| 37 | import org.onosproject.net.GridType; |
| 38 | import org.onosproject.net.Lambda; |
Sho SHIMIZU | 6c70f64 | 2015-05-29 17:27:22 -0700 | [diff] [blame] | 39 | import org.onosproject.net.OchSignalType; |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 40 | import org.onosproject.net.OduSignalId; |
| 41 | import org.onosproject.net.OduSignalType; |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 42 | import org.onosproject.net.PortNumber; |
| 43 | import org.onosproject.net.flow.criteria.Criteria; |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 44 | import org.onosproject.net.flow.criteria.Criterion; |
| 45 | |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 46 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 47 | import org.onosproject.net.flow.criteria.PiCriterion; |
| 48 | import org.onosproject.net.pi.model.PiMatchFieldId; |
| 49 | import org.onosproject.net.pi.runtime.PiExactFieldMatch; |
| 50 | import org.onosproject.net.pi.runtime.PiFieldMatch; |
| 51 | import org.onosproject.net.pi.runtime.PiLpmFieldMatch; |
Daniele Moro | cdac24f | 2020-12-18 10:55:57 +0100 | [diff] [blame] | 52 | import org.onosproject.net.pi.runtime.PiOptionalFieldMatch; |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 53 | import org.onosproject.net.pi.runtime.PiRangeFieldMatch; |
| 54 | import org.onosproject.net.pi.runtime.PiTernaryFieldMatch; |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 55 | |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 56 | import static org.hamcrest.MatcherAssert.assertThat; |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 57 | import static org.hamcrest.Matchers.is; |
Ray Milkey | 0cc189e | 2015-02-09 11:08:01 -0800 | [diff] [blame] | 58 | import static org.hamcrest.Matchers.notNullValue; |
| 59 | import static org.onlab.junit.TestUtils.getField; |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 60 | import static org.onlab.util.ImmutableByteSequence.copyFrom; |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 61 | import static org.onosproject.codec.impl.CriterionJsonMatcher.matchesCriterion; |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * Unit tests for criterion codec. |
| 65 | */ |
| 66 | public class CriterionCodecTest { |
| 67 | |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 68 | CodecContext context; |
| 69 | JsonCodec<Criterion> criterionCodec; |
| 70 | final PortNumber port = PortNumber.portNumber(1); |
| 71 | final IpPrefix ipPrefix4 = IpPrefix.valueOf("10.1.1.0/24"); |
| 72 | final IpPrefix ipPrefix6 = IpPrefix.valueOf("fe80::/64"); |
| 73 | final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01"); |
Seyeon Jeong | 8f01414 | 2020-02-26 12:51:03 -0800 | [diff] [blame] | 74 | final MacAddress mcastMac = MacAddress.valueOf("01:00:5E:00:00:01"); |
| 75 | final MacAddress mcastMacMask = MacAddress.valueOf("FF:FF:FF:80:00:00"); |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 76 | final TpPort tpPort = TpPort.tpPort(40000); |
David Glantz | e3c605e | 2021-09-21 15:39:19 -0500 | [diff] [blame] | 77 | final TpPort tpPortMask = TpPort.tpPort(65472); |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 78 | final int tributaryPortNumber = 11; |
| 79 | final int tributarySlotLen = 80; |
| 80 | final byte[] tributarySlotBitmap = new byte[] {1, 2, 3, 4, 2, 3, 4, 2, 3, 4}; |
| 81 | |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * Sets up for each test. Creates a context and fetches the criterion |
| 85 | * codec. |
| 86 | */ |
| 87 | @Before |
| 88 | public void setUp() { |
| 89 | context = new MockCodecContext(); |
| 90 | criterionCodec = context.codec(Criterion.class); |
| 91 | assertThat(criterionCodec, notNullValue()); |
| 92 | } |
| 93 | |
| 94 | |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 95 | /** |
| 96 | * Checks that all criterion types are covered by the codec. |
| 97 | */ |
| 98 | @Test |
| 99 | public void checkCriterionTypes() throws Exception { |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 100 | EncodeCriterionCodecHelper encoder = new EncodeCriterionCodecHelper( |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 101 | Criteria.dummy(), context); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 102 | EnumMap<Criterion.Type, Object> formatMap = |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 103 | getField(encoder, "formatMap"); |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 104 | assertThat(formatMap, notNullValue()); |
| 105 | |
| 106 | for (Criterion.Type type : Criterion.Type.values()) { |
| 107 | assertThat("Entry not found for " + type.toString(), |
| 108 | formatMap.get(type), notNullValue()); |
| 109 | } |
| 110 | } |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * Tests in port criterion. |
| 114 | */ |
| 115 | @Test |
| 116 | public void matchInPortTest() { |
| 117 | Criterion criterion = Criteria.matchInPort(port); |
| 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 in physical port criterion. |
| 124 | */ |
| 125 | @Test |
| 126 | public void matchInPhyPortTest() { |
| 127 | Criterion criterion = Criteria.matchInPhyPort(port); |
| 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 metadata criterion. |
| 134 | */ |
| 135 | @Test |
| 136 | public void matchMetadataTest() { |
| 137 | Criterion criterion = Criteria.matchMetadata(0xabcdL); |
| 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 ethernet destination criterion. |
| 144 | */ |
| 145 | @Test |
| 146 | public void matchEthDstTest() { |
| 147 | Criterion criterion = Criteria.matchEthDst(mac1); |
| 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 | /** |
Seyeon Jeong | 8f01414 | 2020-02-26 12:51:03 -0800 | [diff] [blame] | 153 | * Tests masked ethernet destination criterion (Criterion.Type.ETH_DST_MASKED). |
| 154 | */ |
| 155 | @Test |
| 156 | public void matchEthDstMaskTest() { |
| 157 | Criterion criterion = Criteria.matchEthDstMasked(mcastMac, mcastMacMask); |
| 158 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 159 | assertThat(result, matchesCriterion(criterion)); |
| 160 | } |
| 161 | |
| 162 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 163 | * Tests ethernet source criterion. |
| 164 | */ |
| 165 | @Test |
| 166 | public void matchEthSrcTest() { |
| 167 | Criterion criterion = Criteria.matchEthSrc(mac1); |
| 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 | /** |
David Glantz | e3c605e | 2021-09-21 15:39:19 -0500 | [diff] [blame] | 173 | * Tests masked ethernet source criterion (Criterion.Type.ETH_SRC_MASKED). |
| 174 | */ |
| 175 | @Test |
| 176 | public void matchEthSrcMaskTest() { |
| 177 | Criterion criterion = Criteria.matchEthSrcMasked(mcastMac, mcastMacMask); |
| 178 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 179 | assertThat(result, matchesCriterion(criterion)); |
| 180 | } |
| 181 | |
| 182 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 183 | * Tests ethernet type criterion. |
| 184 | */ |
| 185 | @Test |
| 186 | public void matchEthTypeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 187 | Criterion criterion = Criteria.matchEthType((short) 0x8844); |
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 VLAN Id criterion. |
| 194 | */ |
| 195 | @Test |
| 196 | public void matchVlanIdTest() { |
| 197 | Criterion criterion = Criteria.matchVlanId(VlanId.ANY); |
| 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 VLAN PCP criterion. |
| 204 | */ |
| 205 | @Test |
| 206 | public void matchVlanPcpTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 207 | Criterion criterion = Criteria.matchVlanPcp((byte) 7); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 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 IP DSCP criterion. |
| 214 | */ |
| 215 | @Test |
| 216 | public void matchIPDscpTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 217 | Criterion criterion = Criteria.matchIPDscp((byte) 63); |
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 IP ECN criterion. |
| 224 | */ |
| 225 | @Test |
| 226 | public void matchIPEcnTest() { |
Pavlin Radoslavov | ab8553a | 2015-02-20 14:13:50 -0800 | [diff] [blame] | 227 | Criterion criterion = Criteria.matchIPEcn((byte) 3); |
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 IP protocol criterion. |
| 234 | */ |
| 235 | @Test |
| 236 | public void matchIPProtocolTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 237 | Criterion criterion = Criteria.matchIPProtocol((byte) 250); |
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 IP source criterion. |
| 244 | */ |
| 245 | @Test |
| 246 | public void matchIPSrcTest() { |
| 247 | Criterion criterion = Criteria.matchIPSrc(ipPrefix4); |
| 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 IP destination criterion. |
| 254 | */ |
| 255 | @Test |
| 256 | public void matchIPDstTest() { |
| 257 | Criterion criterion = Criteria.matchIPDst(ipPrefix4); |
| 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 source TCP port criterion. |
| 264 | */ |
| 265 | @Test |
| 266 | public void matchTcpSrcTest() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 267 | Criterion criterion = Criteria.matchTcpSrc(tpPort); |
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 | /** |
David Glantz | e3c605e | 2021-09-21 15:39:19 -0500 | [diff] [blame] | 273 | * Tests source TCP port masked criterion. |
| 274 | */ |
| 275 | @Test |
| 276 | public void matchTcpSrcMaskedTest() { |
| 277 | Criterion criterion = Criteria.matchTcpSrcMasked(tpPort, tpPortMask); |
| 278 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 279 | assertThat(result, matchesCriterion(criterion)); |
| 280 | } |
| 281 | |
| 282 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 283 | * Tests destination TCP port criterion. |
| 284 | */ |
| 285 | @Test |
| 286 | public void matchTcpDstTest() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 287 | Criterion criterion = Criteria.matchTcpDst(tpPort); |
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 | /** |
David Glantz | e3c605e | 2021-09-21 15:39:19 -0500 | [diff] [blame] | 293 | * Tests destination TCP port masked criterion. |
| 294 | */ |
| 295 | @Test |
| 296 | public void matchTcpDstMaskedTest() { |
| 297 | Criterion criterion = Criteria.matchTcpDstMasked(tpPort, tpPortMask); |
| 298 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 299 | assertThat(result, matchesCriterion(criterion)); |
| 300 | } |
| 301 | |
| 302 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 303 | * Tests source UDP port criterion. |
| 304 | */ |
| 305 | @Test |
| 306 | public void matchUdpSrcTest() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 307 | Criterion criterion = Criteria.matchUdpSrc(tpPort); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 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 | /** |
David Glantz | e3c605e | 2021-09-21 15:39:19 -0500 | [diff] [blame] | 313 | * Tests source UDP port masked criterion. |
| 314 | */ |
| 315 | @Test |
| 316 | public void matchUdpSrcMaskedTest() { |
| 317 | Criterion criterion = Criteria.matchUdpSrcMasked(tpPort, tpPortMask); |
| 318 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 319 | assertThat(result, matchesCriterion(criterion)); |
| 320 | } |
| 321 | |
| 322 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 323 | * Tests destination UDP criterion. |
| 324 | */ |
| 325 | @Test |
| 326 | public void matchUdpDstTest() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 327 | Criterion criterion = Criteria.matchUdpDst(tpPort); |
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 | /** |
David Glantz | e3c605e | 2021-09-21 15:39:19 -0500 | [diff] [blame] | 333 | * Tests destination UDP port masked criterion. |
| 334 | */ |
| 335 | @Test |
| 336 | public void matchUdpDstMaskedTest() { |
| 337 | Criterion criterion = Criteria.matchUdpDstMasked(tpPort, tpPortMask); |
| 338 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 339 | assertThat(result, matchesCriterion(criterion)); |
| 340 | } |
| 341 | |
| 342 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 343 | * Tests source SCTP criterion. |
| 344 | */ |
| 345 | @Test |
| 346 | public void matchSctpSrcTest() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 347 | Criterion criterion = Criteria.matchSctpSrc(tpPort); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 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 | /** |
David Glantz | e3c605e | 2021-09-21 15:39:19 -0500 | [diff] [blame] | 353 | * Tests source SCTP port masked criterion. |
| 354 | */ |
| 355 | @Test |
| 356 | public void matchSctpSrcMaskedTest() { |
| 357 | Criterion criterion = Criteria.matchSctpSrcMasked(tpPort, tpPortMask); |
| 358 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 359 | assertThat(result, matchesCriterion(criterion)); |
| 360 | } |
| 361 | |
| 362 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 363 | * Tests destination SCTP criterion. |
| 364 | */ |
| 365 | @Test |
| 366 | public void matchSctpDstTest() { |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 367 | Criterion criterion = Criteria.matchSctpDst(tpPort); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 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 | /** |
David Glantz | e3c605e | 2021-09-21 15:39:19 -0500 | [diff] [blame] | 373 | * Tests destination SCTP port masked criterion. |
| 374 | */ |
| 375 | @Test |
| 376 | public void matchSctpDstMaskedTest() { |
| 377 | Criterion criterion = Criteria.matchSctpDstMasked(tpPort, tpPortMask); |
| 378 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 379 | assertThat(result, matchesCriterion(criterion)); |
| 380 | } |
| 381 | |
| 382 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 383 | * Tests ICMP type criterion. |
| 384 | */ |
| 385 | @Test |
| 386 | public void matchIcmpTypeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 387 | Criterion criterion = Criteria.matchIcmpType((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 388 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 389 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Tests ICMP code criterion. |
| 394 | */ |
| 395 | @Test |
| 396 | public void matchIcmpCodeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 397 | Criterion criterion = Criteria.matchIcmpCode((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 398 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 399 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Tests IPv6 source criterion. |
| 404 | */ |
| 405 | @Test |
| 406 | public void matchIPv6SrcTest() { |
| 407 | Criterion criterion = Criteria.matchIPv6Src(ipPrefix6); |
| 408 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 409 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Tests IPv6 destination criterion. |
| 414 | */ |
| 415 | @Test |
| 416 | public void matchIPv6DstTest() { |
| 417 | Criterion criterion = Criteria.matchIPv6Dst(ipPrefix6); |
| 418 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 419 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Tests IPv6 flow label criterion. |
| 424 | */ |
| 425 | @Test |
| 426 | public void matchIPv6FlowLabelTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 427 | Criterion criterion = Criteria.matchIPv6FlowLabel(0xffffe); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 428 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 429 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Tests ICMP v6 type criterion. |
| 434 | */ |
| 435 | @Test |
| 436 | public void matchIcmpv6TypeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 437 | Criterion criterion = Criteria.matchIcmpv6Type((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 438 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 439 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Tests ICMP v6 code criterion. |
| 444 | */ |
| 445 | @Test |
| 446 | public void matchIcmpv6CodeTest() { |
Pavlin Radoslavov | f3b6933 | 2015-02-06 15:47:05 -0800 | [diff] [blame] | 447 | Criterion criterion = Criteria.matchIcmpv6Code((byte) 250); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 448 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 449 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Tests IPV6 target address criterion. |
| 454 | */ |
| 455 | @Test |
| 456 | public void matchIPv6NDTargetAddressTest() { |
| 457 | Criterion criterion = |
| 458 | Criteria.matchIPv6NDTargetAddress( |
| 459 | Ip6Address.valueOf("1111:2222::")); |
| 460 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 461 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /** |
| 465 | * Tests IPV6 SLL criterion. |
| 466 | */ |
| 467 | @Test |
| 468 | public void matchIPv6NDSourceLinkLayerAddressTest() { |
| 469 | Criterion criterion = Criteria.matchIPv6NDSourceLinkLayerAddress(mac1); |
| 470 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 471 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
| 475 | * Tests IPV6 TLL criterion. |
| 476 | */ |
| 477 | @Test |
| 478 | public void matchIPv6NDTargetLinkLayerAddressTest() { |
| 479 | Criterion criterion = Criteria.matchIPv6NDTargetLinkLayerAddress(mac1); |
| 480 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 481 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Tests MPLS label criterion. |
| 486 | */ |
| 487 | @Test |
| 488 | public void matchMplsLabelTest() { |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 489 | Criterion criterion = Criteria.matchMplsLabel(MplsLabel.mplsLabel(0xffffe)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 490 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 491 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /** |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 495 | * Tests IPv6 Extension Header pseudo-field flags criterion. |
| 496 | */ |
| 497 | @Test |
| 498 | public void matchIPv6ExthdrFlagsTest() { |
| 499 | int exthdrFlags = |
| 500 | Criterion.IPv6ExthdrFlags.NONEXT.getValue() | |
| 501 | Criterion.IPv6ExthdrFlags.ESP.getValue() | |
| 502 | Criterion.IPv6ExthdrFlags.AUTH.getValue() | |
| 503 | Criterion.IPv6ExthdrFlags.DEST.getValue() | |
| 504 | Criterion.IPv6ExthdrFlags.FRAG.getValue() | |
| 505 | Criterion.IPv6ExthdrFlags.ROUTER.getValue() | |
| 506 | Criterion.IPv6ExthdrFlags.HOP.getValue() | |
| 507 | Criterion.IPv6ExthdrFlags.UNREP.getValue() | |
| 508 | Criterion.IPv6ExthdrFlags.UNSEQ.getValue(); |
| 509 | Criterion criterion = Criteria.matchIPv6ExthdrFlags(exthdrFlags); |
| 510 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 511 | |
| 512 | assertThat(result, matchesCriterion(criterion)); |
Pavlin Radoslavov | 5e4f754 | 2015-02-06 18:18:21 -0800 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /** |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 516 | * Tests lambda criterion. |
| 517 | */ |
| 518 | @Test |
Sho SHIMIZU | c44c0c3 | 2015-06-01 11:40:48 -0700 | [diff] [blame] | 519 | public void matchOchSignal() { |
| 520 | Lambda ochSignal = Lambda.ochSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 4, 8); |
| 521 | Criterion criterion = Criteria.matchLambda(ochSignal); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 522 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 523 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /** |
Sho SHIMIZU | 68b8c1f | 2015-05-29 18:42:26 -0700 | [diff] [blame] | 527 | * Tests Och signal type criterion. |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 528 | */ |
| 529 | @Test |
Sho SHIMIZU | 68b8c1f | 2015-05-29 18:42:26 -0700 | [diff] [blame] | 530 | public void matchOchSignalTypeTest() { |
Sho SHIMIZU | 6c70f64 | 2015-05-29 17:27:22 -0700 | [diff] [blame] | 531 | Criterion criterion = Criteria.matchOchSignalType(OchSignalType.FIXED_GRID); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 532 | ObjectNode result = criterionCodec.encode(criterion, context); |
Ray Milkey | 46670a8 | 2015-02-08 17:57:17 -0800 | [diff] [blame] | 533 | assertThat(result, matchesCriterion(criterion)); |
Ray Milkey | 9ee62f5 | 2015-02-06 13:47:35 -0800 | [diff] [blame] | 534 | } |
Yafit Hadar | 5796d97 | 2015-10-15 13:16:11 +0300 | [diff] [blame] | 535 | |
| 536 | /** |
| 537 | * Tests Odu Signal ID criterion. |
| 538 | */ |
| 539 | @Test |
| 540 | public void matchOduSignalIdTest() { |
| 541 | |
| 542 | OduSignalId oduSignalId = OduSignalId.oduSignalId(tributaryPortNumber, tributarySlotLen, tributarySlotBitmap); |
| 543 | |
| 544 | Criterion criterion = Criteria.matchOduSignalId(oduSignalId); |
| 545 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 546 | assertThat(result, matchesCriterion(criterion)); |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Tests Odu Signal Type criterion. |
| 551 | */ |
| 552 | @Test |
| 553 | public void matchOduSignalTypeTest() { |
| 554 | |
| 555 | OduSignalType signalType = OduSignalType.ODU2; |
| 556 | |
| 557 | Criterion criterion = Criteria.matchOduSignalType(signalType); |
| 558 | ObjectNode result = criterionCodec.encode(criterion, context); |
| 559 | assertThat(result, matchesCriterion(criterion)); |
| 560 | } |
| 561 | |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 562 | /** |
| 563 | * Tests protocol-independent type criterion encoding. |
| 564 | */ |
| 565 | @Test |
| 566 | public void matchPiTypeEncodingTest() { |
| 567 | |
| 568 | PiMatchFieldId ethMatchFieldId = PiMatchFieldId.of("ethernet_t.etherType"); |
| 569 | byte[] matchExactBytes1 = {0x08, 0x00}; |
| 570 | Criterion exactBytesCriterion = PiCriterion.builder().matchExact(ethMatchFieldId, matchExactBytes1).build(); |
| 571 | ObjectNode exactResult = criterionCodec.encode(exactBytesCriterion, context); |
| 572 | assertThat(exactResult, matchesCriterion(exactBytesCriterion)); |
| 573 | |
| 574 | PiMatchFieldId ipv4MatchFieldId = PiMatchFieldId.of("ipv4_t.dstAddr"); |
| 575 | int mask = 0x00ffffff; |
| 576 | byte[] matchLpmBytes1 = {0x0a, 0x01, 0x01, 0x01}; |
| 577 | Criterion lpmBytesCriterion = PiCriterion.builder().matchLpm(ipv4MatchFieldId, matchLpmBytes1, mask).build(); |
| 578 | ObjectNode lpmResult = criterionCodec.encode(lpmBytesCriterion, context); |
| 579 | assertThat(lpmResult, matchesCriterion(lpmBytesCriterion)); |
| 580 | |
| 581 | byte[] matchTernaryBytes1 = {0x0a, 0x01, 0x01, 0x01}; |
| 582 | byte[] matchTernaryMaskBytes = {0x7f, 0x7f, 0x7f, 0x00}; |
| 583 | Criterion ternaryBytesCriterion = PiCriterion.builder().matchTernary(ipv4MatchFieldId, matchTernaryBytes1, |
| 584 | matchTernaryMaskBytes).build(); |
| 585 | ObjectNode ternaryResult = criterionCodec.encode(ternaryBytesCriterion, context); |
| 586 | assertThat(ternaryResult, matchesCriterion(ternaryBytesCriterion)); |
| 587 | |
| 588 | byte[] matchRangeBytes1 = {0x10}; |
| 589 | byte[] matchRangeHighBytes = {0x30}; |
| 590 | Criterion rangeBytesCriterion = PiCriterion.builder() |
| 591 | .matchRange(ipv4MatchFieldId, matchRangeBytes1, matchRangeHighBytes).build(); |
| 592 | ObjectNode rangeResult = criterionCodec.encode(rangeBytesCriterion, context); |
| 593 | assertThat(rangeResult, matchesCriterion(rangeBytesCriterion)); |
Daniele Moro | cdac24f | 2020-12-18 10:55:57 +0100 | [diff] [blame] | 594 | |
| 595 | byte[] matchOptionalBytes = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; |
| 596 | Criterion optionalBytesCriterion = PiCriterion.builder().matchOptional(ethMatchFieldId, |
| 597 | matchOptionalBytes).build(); |
| 598 | ObjectNode optionalResult = criterionCodec.encode(optionalBytesCriterion, context); |
| 599 | assertThat(optionalResult, matchesCriterion(optionalBytesCriterion)); |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /** |
| 603 | * Tests protocol-independent type criterion decoding. |
| 604 | */ |
| 605 | @Test |
| 606 | public void matchPiTypeDecodingTest() throws IOException { |
| 607 | Criterion criterion = getCriterion("PiCriterion.json"); |
| 608 | Assert.assertThat(criterion.type(), is(Criterion.Type.PROTOCOL_INDEPENDENT)); |
| 609 | Collection<PiFieldMatch> piFieldMatches = ((PiCriterion) criterion).fieldMatches(); |
| 610 | for (PiFieldMatch piFieldMatch : piFieldMatches) { |
| 611 | switch (piFieldMatch.type()) { |
| 612 | case EXACT: |
| 613 | Assert.assertThat(piFieldMatch.fieldId().id(), is("ingress_port")); |
| 614 | Assert.assertThat(((PiExactFieldMatch) piFieldMatch).value(), is( |
| 615 | copyFrom((byte) 0x10))); |
| 616 | break; |
| 617 | case LPM: |
| 618 | Assert.assertThat(piFieldMatch.fieldId().id(), is("src_addr")); |
| 619 | Assert.assertThat(((PiLpmFieldMatch) piFieldMatch).value(), |
| 620 | is(copyFrom(0xa010101))); |
| 621 | Assert.assertThat(((PiLpmFieldMatch) piFieldMatch).prefixLength(), is(24)); |
| 622 | break; |
| 623 | case TERNARY: |
| 624 | Assert.assertThat(piFieldMatch.fieldId().id(), is("dst_addr")); |
| 625 | Assert.assertThat(((PiTernaryFieldMatch) piFieldMatch).value(), |
| 626 | is(copyFrom(0xa010101))); |
| 627 | Assert.assertThat(((PiTernaryFieldMatch) piFieldMatch).mask(), |
| 628 | is(copyFrom(0xfffffff))); |
| 629 | break; |
| 630 | case RANGE: |
| 631 | Assert.assertThat(piFieldMatch.fieldId().id(), is("egress_port")); |
| 632 | Assert.assertThat(((PiRangeFieldMatch) piFieldMatch).highValue(), |
| 633 | is(copyFrom((byte) 0x20))); |
| 634 | Assert.assertThat(((PiRangeFieldMatch) piFieldMatch).lowValue(), |
| 635 | is(copyFrom((byte) 0x10))); |
| 636 | break; |
Daniele Moro | cdac24f | 2020-12-18 10:55:57 +0100 | [diff] [blame] | 637 | case OPTIONAL: |
| 638 | Assert.assertThat(piFieldMatch.fieldId().id(), is("eth_dst")); |
| 639 | Assert.assertThat(((PiOptionalFieldMatch) piFieldMatch).value(), |
| 640 | is(copyFrom(new byte[]{0x00, 0x11, 0x22, 0x33, 0x44, 0x55}))); |
| 641 | break; |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 642 | default: |
Carmelo Cascone | 6af4e17 | 2018-06-15 16:01:30 +0200 | [diff] [blame] | 643 | Assert.fail(); |
Frank Wang | 74ce2c1 | 2018-04-11 20:26:45 +0800 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * Reads in a criterion from the given resource and decodes it. |
| 650 | * |
| 651 | * @param resourceName resource to use to read the JSON for the rule |
| 652 | * @return decoded criterion |
| 653 | * @throws IOException if processing the resource fails |
| 654 | */ |
| 655 | private Criterion getCriterion(String resourceName) throws IOException { |
| 656 | InputStream jsonStream = CriterionCodecTest.class.getResourceAsStream(resourceName); |
| 657 | JsonNode json = context.mapper().readTree(jsonStream); |
| 658 | MatcherAssert.assertThat(json, notNullValue()); |
| 659 | Criterion criterion = criterionCodec.decode((ObjectNode) json, context); |
| 660 | Assert.assertThat(criterion, notNullValue()); |
| 661 | return criterion; |
| 662 | } |
Ray Milkey | 73ba84a | 2015-02-04 17:08:41 -0800 | [diff] [blame] | 663 | } |