blob: 00c598f9df1c9d826b4aab3434cc82f92963da19 [file] [log] [blame]
Pingping Line28ae4c2015-03-13 11:37:03 -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.routing.config;
17
Pingping Line28ae4c2015-03-13 11:37:03 -070018import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
Pingping Linc9e16bf2015-04-10 14:42:41 -070022import org.onlab.packet.IpAddress;
Pingping Line28ae4c2015-03-13 11:37:03 -070023import org.onlab.packet.IpPrefix;
24
25/**
26 * Configuration details for an IP prefix entry.
27 */
28public class LocalIpPrefixEntry {
29 private final IpPrefix ipPrefix;
30 private final IpPrefixType type;
Pingping Linc9e16bf2015-04-10 14:42:41 -070031 private final IpAddress gatewayIpAddress;
Pingping Line28ae4c2015-03-13 11:37:03 -070032
33 /**
34 * Specifies the type of local IP prefix.
35 */
36 public enum IpPrefixType {
37 /**
38 * Public IP prefixes should be exchanged by eBGP.
39 */
40 PUBLIC,
41 /**
42 * Private IP prefixes should be used only locally and not exchanged
43 * by eBGP.
44 */
45 PRIVATE,
46 /**
47 * For IP prefixes in blacklist.
48 */
49 BLACK_LIST
50 }
51
52 /**
53 * Creates a new IP prefix entry.
54 *
Pingping Lin9a445c82016-04-07 11:40:29 -070055 * @param ipPrefix an IP prefix
Thomas Vachuskae10f56b2015-04-15 18:20:08 -070056 * @param type an IP prefix type as an IpPrefixType
57 * @param gatewayIpAddress IP of the gateway
Pingping Line28ae4c2015-03-13 11:37:03 -070058 */
Pingping Lin9a445c82016-04-07 11:40:29 -070059 public LocalIpPrefixEntry(IpPrefix ipPrefix,
60 IpPrefixType type,
61 IpAddress gatewayIpAddress) {
62 this.ipPrefix = ipPrefix;
Pingping Line28ae4c2015-03-13 11:37:03 -070063 this.type = type;
Pingping Linc9e16bf2015-04-10 14:42:41 -070064 this.gatewayIpAddress = gatewayIpAddress;
Pingping Line28ae4c2015-03-13 11:37:03 -070065 }
66
67 /**
68 * Gets the IP prefix of the IP prefix entry.
69 *
70 * @return the IP prefix
71 */
72 public IpPrefix ipPrefix() {
73 return ipPrefix;
74 }
75
76 /**
77 * Gets the IP prefix type of the IP prefix entry.
78 *
79 * @return the IP prefix type
80 */
81 public IpPrefixType ipPrefixType() {
82 return type;
83 }
84
85 /**
Pingping Linc9e16bf2015-04-10 14:42:41 -070086 * Gets the gateway IP address of the IP prefix entry.
87 *
88 * @return the gateway IP address
89 */
90 public IpAddress getGatewayIpAddress() {
91 return gatewayIpAddress;
92 }
93
94 /**
Pingping Line28ae4c2015-03-13 11:37:03 -070095 * Tests whether the IP version of this entry is IPv4.
96 *
97 * @return true if the IP version of this entry is IPv4, otherwise false.
98 */
99 public boolean isIp4() {
100 return ipPrefix.isIp4();
101 }
102
103 /**
104 * Tests whether the IP version of this entry is IPv6.
105 *
106 * @return true if the IP version of this entry is IPv6, otherwise false.
107 */
108 public boolean isIp6() {
109 return ipPrefix.isIp6();
110 }
111
112 @Override
113 public int hashCode() {
114 return Objects.hash(ipPrefix, type);
115 }
116
117 @Override
118 public boolean equals(Object obj) {
119 if (obj == this) {
120 return true;
121 }
122
123 if (!(obj instanceof LocalIpPrefixEntry)) {
124 return false;
125 }
126
127 LocalIpPrefixEntry that = (LocalIpPrefixEntry) obj;
128 return Objects.equals(this.ipPrefix, that.ipPrefix)
129 && Objects.equals(this.type, that.type);
130 }
131
132 @Override
133 public String toString() {
134 return MoreObjects.toStringHelper(getClass())
135 .add("ipPrefix", ipPrefix)
136 .add("ipPrefixType", type)
137 .toString();
138 }
139}