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