blob: baa033bf6cb34f88ceb51e5efc6db9a3f206ae60 [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Henry Yu4b4a7eb2016-11-09 20:07:53 -05003 *
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.tetopology.management.api.link;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.Ip6Address;
20
21import java.util.Objects;
22
23/**
24 * Implementation of an IPv6 address as an element type.
25 */
26public class TeIpv6 implements ElementType {
27 private final Ip6Address v6Address;
28 private final short v6PrefixLength;
29
30 /**
31 * Creates an IPv6 address.
32 *
33 * @param v6Address the IP v6 address to set
34 * @param v6PrefixLength the length of the IPv6 address prefix
35 */
36 public TeIpv6(Ip6Address v6Address, short v6PrefixLength) {
37 this.v6Address = v6Address;
38 this.v6PrefixLength = v6PrefixLength;
39 }
40
41 /**
42 * Returns the IPv6 address.
43 *
44 * @return the IPv6 address
45 */
46 public Ip6Address v6Address() {
47 return v6Address;
48 }
49
50 /**
51 * Returns the length of the IPv6 address prefix.
52 *
53 * @return IPv6 address prefix length
54 */
55 public short v6PrefixLength() {
56 return v6PrefixLength;
57 }
58
59 @Override
60 public int hashCode() {
61 return Objects.hash(v6Address, v6PrefixLength);
62 }
63
64 @Override
65 public boolean equals(Object obj) {
66 if (this == obj) {
67 return true;
68 }
69 if (obj instanceof TeIpv6) {
70 TeIpv6 other = (TeIpv6) obj;
71 return Objects.equals(v6Address, other.v6Address) &&
72 Objects.equals(v6PrefixLength, other.v6PrefixLength);
73 }
74 return false;
75 }
76
77 @Override
78 public String toString() {
79 return MoreObjects.toStringHelper(getClass())
80 .add("v6Address", v6Address)
81 .add("v6PrefixLength", v6PrefixLength)
82 .toString();
83 }
84}