blob: ffef044a0b7bdf36b299b997ed0a3efcf2270f03 [file] [log] [blame]
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -07001/*
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 org.onlab.packet.Ip6Address;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Implementation of IPv6 Neighbor Discovery target address criterion.
26 */
27public final class IPv6NDTargetAddressCriterion implements Criterion {
28 private final Ip6Address targetAddress;
29
30 /**
31 * Constructor.
32 *
33 * @param targetAddress the IPv6 target address to match
34 */
35 IPv6NDTargetAddressCriterion(Ip6Address targetAddress) {
36 this.targetAddress = targetAddress;
37 }
38
39 @Override
40 public Type type() {
41 return Type.IPV6_ND_TARGET;
42 }
43
44 /**
45 * Gets the IPv6 target address to match.
46 *
47 * @return the IPv6 target address to match
48 */
49 public Ip6Address targetAddress() {
50 return this.targetAddress;
51 }
52
53 @Override
54 public String toString() {
55 return toStringHelper(type().toString())
56 .add("targetAddress", targetAddress).toString();
57 }
58
59 @Override
60 public int hashCode() {
Thomas Vachuska6c8eff32015-05-27 16:11:44 -070061 return Objects.hash(type().ordinal(), targetAddress);
Sho SHIMIZUfbc80e52015-04-28 10:41:58 -070062 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (this == obj) {
67 return true;
68 }
69 if (obj instanceof IPv6NDTargetAddressCriterion) {
70 IPv6NDTargetAddressCriterion that =
71 (IPv6NDTargetAddressCriterion) obj;
72 return Objects.equals(targetAddress, that.targetAddress) &&
73 Objects.equals(type(), that.type());
74 }
75 return false;
76 }
77}