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