BitOhenry | 11620c9 | 2015-11-27 08:42:36 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
BitOhenry | 11620c9 | 2015-11-27 08:42:36 +0800 | [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 | |
BitOhenry | 11620c9 | 2015-11-27 08:42:36 +0800 | [diff] [blame] | 18 | import java.util.Objects; |
| 19 | |
| 20 | /** |
| 21 | * Implementation of arp operation type criterion. |
| 22 | */ |
| 23 | public final class ArpOpCriterion implements Criterion { |
| 24 | private final int arpOp; |
| 25 | private final Type type; |
| 26 | |
| 27 | /** |
| 28 | * Constructor. |
| 29 | * |
| 30 | * @param arpOp the arp operation type to match. |
| 31 | * @param type the match type. Should be the following: |
| 32 | * Type.ARP_OP |
| 33 | */ |
| 34 | ArpOpCriterion(int arpOp, Type type) { |
| 35 | this.arpOp = arpOp; |
| 36 | this.type = type; |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public Type type() { |
| 41 | return this.type; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Gets the arp operation type to match. |
| 46 | * |
| 47 | * @return the arp operation type to match |
| 48 | */ |
| 49 | public int arpOp() { |
| 50 | return this.arpOp; |
| 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 + arpOp; |
BitOhenry | 11620c9 | 2015-11-27 08:42:36 +0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public int hashCode() { |
| 60 | return Objects.hash(type().ordinal(), arpOp); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public boolean equals(Object obj) { |
| 65 | if (this == obj) { |
| 66 | return true; |
| 67 | } |
| 68 | if (obj instanceof ArpOpCriterion) { |
| 69 | ArpOpCriterion that = (ArpOpCriterion) obj; |
| 70 | return Objects.equals(arpOp, that.arpOp) && |
| 71 | Objects.equals(type, that.type); |
| 72 | } |
| 73 | return false; |
| 74 | } |
Jonathan Hart | c7840bd | 2016-01-21 23:26:29 -0800 | [diff] [blame] | 75 | } |