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