blob: 7a21d461481562bfc5a0f3f67e494d67e799744a [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07003 *
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 */
16package org.onosproject.net.flow.criteria;
17
18import java.util.Objects;
19
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070020/**
21 * Implementation of IPv6 Extension Header pseudo-field criterion
22 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags.
23 */
24public final class IPv6ExthdrFlagsCriterion implements Criterion {
25 private static final int MASK = 0xffff;
26 private final int exthdrFlags; // IPv6 Exthdr flags: 16 bits
27
28 /**
29 * Constructor.
30 *
31 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
32 * to match (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
33 */
34 IPv6ExthdrFlagsCriterion(int exthdrFlags) {
35 this.exthdrFlags = exthdrFlags & MASK;
36 }
37
38 @Override
39 public Type type() {
40 return Type.IPV6_EXTHDR;
41 }
42
43 /**
44 * Gets the IPv6 Extension Header pseudo-field flags to match.
45 *
46 * @return the IPv6 Extension Header pseudo-field flags to match
47 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
48 */
49 public int exthdrFlags() {
50 return exthdrFlags;
51 }
52
53 @Override
54 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080055 return type().toString() + SEPARATOR + Long.toHexString(exthdrFlags);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070056 }
57
58 @Override
59 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070060 return Objects.hash(type().ordinal(), exthdrFlags);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070061 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj instanceof IPv6ExthdrFlagsCriterion) {
69 IPv6ExthdrFlagsCriterion that = (IPv6ExthdrFlagsCriterion) obj;
70 return Objects.equals(exthdrFlags, that.exthdrFlags) &&
71 Objects.equals(this.type(), that.type());
72 }
73 return false;
74 }
75}