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 IP DSCP (Differentiated Services Code Point) |
| 24 | * criterion (6 bits). |
| 25 | */ |
| 26 | public final class IPDscpCriterion implements Criterion { |
| 27 | private static final byte MASK = 0x3f; |
| 28 | private final byte ipDscp; // IP DSCP value: 6 bits |
| 29 | |
| 30 | /** |
| 31 | * Constructor. |
| 32 | * |
| 33 | * @param ipDscp the IP DSCP value to match |
| 34 | */ |
| 35 | IPDscpCriterion(byte ipDscp) { |
| 36 | this.ipDscp = (byte) (ipDscp & MASK); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public Type type() { |
| 41 | return Type.IP_DSCP; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Gets the IP DSCP value to match. |
| 46 | * |
| 47 | * @return the IP DSCP value to match |
| 48 | */ |
| 49 | public byte ipDscp() { |
| 50 | return ipDscp; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public String toString() { |
| 55 | return toStringHelper(type().toString()) |
| 56 | .add("ipDscp", Long.toHexString(ipDscp)).toString(); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 61 | return Objects.hash(type().ordinal(), ipDscp); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public boolean equals(Object obj) { |
| 66 | if (this == obj) { |
| 67 | return true; |
| 68 | } |
| 69 | if (obj instanceof IPDscpCriterion) { |
| 70 | IPDscpCriterion that = (IPDscpCriterion) obj; |
| 71 | return Objects.equals(ipDscp, that.ipDscp) && |
| 72 | Objects.equals(this.type(), that.type()); |
| 73 | } |
| 74 | return false; |
| 75 | } |
| 76 | } |