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 IP ECN (Explicit Congestion Notification) criterion |
| 22 | * (2 bits). |
| 23 | */ |
| 24 | public final class IPEcnCriterion implements Criterion { |
| 25 | private static final byte MASK = 0x3; |
| 26 | private final byte ipEcn; // IP ECN value: 2 bits |
| 27 | |
| 28 | /** |
| 29 | * Constructor. |
| 30 | * |
| 31 | * @param ipEcn the IP ECN value to match (2 bits) |
| 32 | */ |
| 33 | IPEcnCriterion(byte ipEcn) { |
| 34 | this.ipEcn = (byte) (ipEcn & MASK); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public Type type() { |
| 39 | return Type.IP_ECN; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Gets the IP ECN value to match. |
| 44 | * |
| 45 | * @return the IP ECN value to match (2 bits) |
| 46 | */ |
| 47 | public byte ipEcn() { |
| 48 | return ipEcn; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public String toString() { |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 53 | return type().toString() + SEPARATOR + Long.toHexString(ipEcn); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public int hashCode() { |
Thomas Vachuska | 6c8eff3 | 2015-05-27 16:11:44 -0700 | [diff] [blame] | 58 | return Objects.hash(type().ordinal(), ipEcn); |
Sho SHIMIZU | fbc80e5 | 2015-04-28 10:41:58 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean equals(Object obj) { |
| 63 | if (this == obj) { |
| 64 | return true; |
| 65 | } |
| 66 | if (obj instanceof IPEcnCriterion) { |
| 67 | IPEcnCriterion that = (IPEcnCriterion) obj; |
| 68 | return Objects.equals(ipEcn, that.ipEcn) && |
| 69 | Objects.equals(this.type(), that.type()); |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | } |