Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [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.net.flow.criteria; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import 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 | */ |
| 26 | public 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 Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 63 | return Objects.hash(type().ordinal(), exthdrFlags); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 64 | } |
| 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 | } |