blob: 8c5398c6d2019504304775c587cd89595ac586db [file] [log] [blame]
BitOhenry11620c92015-11-27 08:42:36 +08001/*
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 */
16package org.onosproject.net.flow.criteria;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20import java.util.Objects;
21
22/**
23 * Implementation of arp operation type criterion.
24 */
25public final class ArpOpCriterion implements Criterion {
26 private final int arpOp;
27 private final Type type;
28
29 /**
30 * Constructor.
31 *
32 * @param arpOp the arp operation type to match.
33 * @param type the match type. Should be the following:
34 * Type.ARP_OP
35 */
36 ArpOpCriterion(int arpOp, Type type) {
37 this.arpOp = arpOp;
38 this.type = type;
39 }
40
41 @Override
42 public Type type() {
43 return this.type;
44 }
45
46 /**
47 * Gets the arp operation type to match.
48 *
49 * @return the arp operation type to match
50 */
51 public int arpOp() {
52 return this.arpOp;
53 }
54
55 @Override
56 public String toString() {
57 return toStringHelper(type().toString())
58 .add("arpOp", arpOp).toString();
59 }
60
61 @Override
62 public int hashCode() {
63 return Objects.hash(type().ordinal(), arpOp);
64 }
65
66 @Override
67 public boolean equals(Object obj) {
68 if (this == obj) {
69 return true;
70 }
71 if (obj instanceof ArpOpCriterion) {
72 ArpOpCriterion that = (ArpOpCriterion) obj;
73 return Objects.equals(arpOp, that.arpOp) &&
74 Objects.equals(type, that.type);
75 }
76 return false;
77 }
78}