blob: fdef29569a0584c9ce5853fd2ee42dc7fd0e0f48 [file] [log] [blame]
Aihua Guo1ce2dd12016-08-12 23:37:44 -04001/**
2 * Copyright 2016 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.tetopology.management.api.link;
17
18import java.util.Objects;
19
20import org.onlab.packet.Ip4Address;
21
22import com.google.common.base.MoreObjects;
23
24/**
25 * Implementation of IPv4 address as an ElementType.
26 */
27public class TeIpv4 implements ElementType {
28 private Ip4Address v4Address;
29 private short v4PrefixLength;
30 private boolean v4Loose;
31
32 /**
33 * Creates an instance of TeIpv4.
34 */
35 public TeIpv4() {
36 }
37
38 /**
39 * Sets the v4 address.
40 *
41 * @param v4Address the v4Address to set
42 */
43 public void setV4Address(Ip4Address v4Address) {
44 this.v4Address = v4Address;
45 }
46
47 /**
48 * Sets the prefix length.
49 *
50 * @param v4PrefixLength the v4PrefixLength to set
51 */
52 public void setV4PrefixLength(short v4PrefixLength) {
53 this.v4PrefixLength = v4PrefixLength;
54 }
55
56 /**
57 * Sets the loose flag.
58 *
59 * @param v4Loose the v4Loose to set
60 */
61 public void setV4Loose(boolean v4Loose) {
62 this.v4Loose = v4Loose;
63 }
64
65 /**
66 * Returns the v4Address.
67 *
68 * @return IPv4 address
69 */
70 public Ip4Address v4Address() {
71 return v4Address;
72 }
73
74 /**
75 * Returns the v4PrefixLength.
76 *
77 * @return IPv4 address prefix length
78 */
79 public short v4PrefixLength() {
80 return v4PrefixLength;
81 }
82
83 /**
84 * Returns the v4Loose.
85 *
86 * @return true if the address specifies a loose hop; false otherwise
87 */
88 public boolean v4Loose() {
89 return v4Loose;
90 }
91
92 @Override
93 public int hashCode() {
94 return Objects.hash(v4Address, v4PrefixLength, v4Loose);
95 }
96
97 @Override
98 public boolean equals(Object obj) {
99 if (this == obj) {
100 return true;
101 }
102 if (obj instanceof TeIpv4) {
103 TeIpv4 other = (TeIpv4) obj;
104 return Objects.equals(v4Address, other.v4Address) &&
105 Objects.equals(v4PrefixLength, other.v4PrefixLength) &&
106 Objects.equals(v4Loose, other.v4Loose);
107 }
108 return false;
109 }
110
111 @Override
112 public String toString() {
113 return MoreObjects.toStringHelper(getClass())
114 .add("v4Address", v4Address)
115 .add("v4PrefixLength", v4PrefixLength)
116 .add("v4Loose", v4Loose)
117 .toString();
118 }
119
120}