blob: f14c7e17ee8d60b6f811bc25ab04c6e8971274bf [file] [log] [blame]
lishuaia72d44d2015-10-19 17:27:38 +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
Jonathan Hartc7840bd2016-01-21 23:26:29 -080018import org.onlab.packet.Ip4Address;
lishuaia72d44d2015-10-19 17:27:38 +080019
20import java.util.Objects;
21
lishuaia72d44d2015-10-19 17:27:38 +080022/**
23 * Implementation of arp spa or tpa address criterion.
24 */
25public final class ArpPaCriterion implements Criterion {
26 private final Ip4Address ip;
27 private final Type type;
28
29 /**
30 * Constructor.
31 *
32 * @param ip the Ip4 Address to match.
33 * @param type the match type. Should be one of the following:
34 * Type.ARP_SPA, Type.ARP_TPA
35 */
36 ArpPaCriterion(Ip4Address ip, Type type) {
37 this.ip = ip;
38 this.type = type;
39 }
40
41 @Override
42 public Type type() {
43 return this.type;
44 }
45
46 /**
47 * Gets the Ip4 Address to match.
48 *
49 * @return the Ip4 Address to match
50 */
51 public Ip4Address ip() {
52 return this.ip;
53 }
54
55 @Override
56 public String toString() {
Jonathan Hartc7840bd2016-01-21 23:26:29 -080057 return type().toString() + SEPARATOR + ip;
lishuaia72d44d2015-10-19 17:27:38 +080058 }
59
60 @Override
61 public int hashCode() {
62 return Objects.hash(type().ordinal(), ip);
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj instanceof ArpPaCriterion) {
71 ArpPaCriterion that = (ArpPaCriterion) obj;
72 return Objects.equals(ip, that.ip) &&
73 Objects.equals(type, that.type);
74 }
75 return false;
76 }
Jonathan Hartc7840bd2016-01-21 23:26:29 -080077}