blob: 2463bf640bdbee6546a498936e2ede249f7d68a6 [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
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 */
16package org.onosproject.net.flow.criteria;
17
18import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Implementation of IPv6 Extension Header pseudo-field criterion
24 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags.
25 */
26public final class IPv6ExthdrFlagsCriterion implements Criterion {
27 private static final int MASK = 0xffff;
28 private final int exthdrFlags; // IPv6 Exthdr flags: 16 bits
29
30 /**
31 * Constructor.
32 *
33 * @param exthdrFlags the IPv6 Extension Header pseudo-field flags
34 * to match (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
35 */
36 IPv6ExthdrFlagsCriterion(int exthdrFlags) {
37 this.exthdrFlags = exthdrFlags & MASK;
38 }
39
40 @Override
41 public Type type() {
42 return Type.IPV6_EXTHDR;
43 }
44
45 /**
46 * Gets the IPv6 Extension Header pseudo-field flags to match.
47 *
48 * @return the IPv6 Extension Header pseudo-field flags to match
49 * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags
50 */
51 public int exthdrFlags() {
52 return exthdrFlags;
53 }
54
55 @Override
56 public String toString() {
57 return toStringHelper(type().toString())
58 .add("exthdrFlags", Long.toHexString(exthdrFlags)).toString();
59 }
60
61 @Override
62 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070063 return Objects.hash(type().ordinal(), exthdrFlags);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070064 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (this == obj) {
69 return true;
70 }
71 if (obj instanceof IPv6ExthdrFlagsCriterion) {
72 IPv6ExthdrFlagsCriterion that = (IPv6ExthdrFlagsCriterion) obj;
73 return Objects.equals(exthdrFlags, that.exthdrFlags) &&
74 Objects.equals(this.type(), that.type());
75 }
76 return false;
77 }
78}