Pingping Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.routing.config; |
| 17 | |
Pingping Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
Pingping Lin | c9e16bf | 2015-04-10 14:42:41 -0700 | [diff] [blame] | 22 | import org.onlab.packet.IpAddress; |
Pingping Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 23 | import org.onlab.packet.IpPrefix; |
| 24 | |
| 25 | /** |
| 26 | * Configuration details for an IP prefix entry. |
| 27 | */ |
| 28 | public class LocalIpPrefixEntry { |
| 29 | private final IpPrefix ipPrefix; |
| 30 | private final IpPrefixType type; |
Pingping Lin | c9e16bf | 2015-04-10 14:42:41 -0700 | [diff] [blame] | 31 | private final IpAddress gatewayIpAddress; |
Pingping Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 32 | |
| 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 Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 55 | * @param ipPrefix an IP prefix |
Thomas Vachuska | e10f56b | 2015-04-15 18:20:08 -0700 | [diff] [blame] | 56 | * @param type an IP prefix type as an IpPrefixType |
| 57 | * @param gatewayIpAddress IP of the gateway |
Pingping Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 58 | */ |
Pingping Lin | 9a445c8 | 2016-04-07 11:40:29 -0700 | [diff] [blame] | 59 | public LocalIpPrefixEntry(IpPrefix ipPrefix, |
| 60 | IpPrefixType type, |
| 61 | IpAddress gatewayIpAddress) { |
| 62 | this.ipPrefix = ipPrefix; |
Pingping Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 63 | this.type = type; |
Pingping Lin | c9e16bf | 2015-04-10 14:42:41 -0700 | [diff] [blame] | 64 | this.gatewayIpAddress = gatewayIpAddress; |
Pingping Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 65 | } |
| 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 Lin | c9e16bf | 2015-04-10 14:42:41 -0700 | [diff] [blame] | 86 | * 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 Lin | e28ae4c | 2015-03-13 11:37:03 -0700 | [diff] [blame] | 95 | * 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 | } |