Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [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.net.flow.criteria; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 20 | /** |
| 21 | * Implementation of IPv6 Extension Header pseudo-field criterion |
| 22 | * (16 bits). Those are defined in Criterion.IPv6ExthdrFlags. |
| 23 | */ |
| 24 | public 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 Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 55 | return type().toString() + SEPARATOR + Long.toHexString(exthdrFlags); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 60 | return Objects.hash(type().ordinal(), exthdrFlags); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 61 | } |
| 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 | } |