Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 1 | /* |
Jian Li | c7efc1d | 2018-08-23 16:37:34 +0900 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [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 | */ |
Jian Li | c7efc1d | 2018-08-23 16:37:34 +0900 | [diff] [blame] | 16 | package org.onosproject.simplefabric.api; |
Lee Yongjae | 7c27bb4 | 2017-11-17 12:00:45 +0900 | [diff] [blame] | 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.IpPrefix; |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onosproject.net.EncapsulationType; |
| 23 | |
| 24 | import java.util.Objects; |
| 25 | |
| 26 | /** |
| 27 | * Configuration details for an ip subnet entry. |
| 28 | */ |
| 29 | public class IpSubnet { |
| 30 | private final IpPrefix ipPrefix; |
| 31 | private final IpAddress gatewayIp; |
| 32 | private final MacAddress gatewayMac; |
| 33 | private EncapsulationType encapsulation; |
| 34 | private final String l2NetworkName; |
| 35 | |
| 36 | /** |
| 37 | * Creates a new ip subnet entry. |
| 38 | * |
| 39 | * @param ipPrefix an ip subnet |
| 40 | * @param gatewayIp IP of the virtual gateway |
| 41 | * @param gatewayMac MacAddress of the virtual gateway |
| 42 | * @param encapsulation EnacaptulatioType for routes related to this subnet |
| 43 | * @param l2NetworkName Name of L2 Network this subnet is bound |
| 44 | */ |
| 45 | public IpSubnet(IpPrefix ipPrefix, IpAddress gatewayIp, MacAddress gatewayMac, |
| 46 | EncapsulationType encapsulation, String l2NetworkName) { |
| 47 | this.ipPrefix = ipPrefix; |
| 48 | this.gatewayIp = gatewayIp; |
| 49 | this.gatewayMac = gatewayMac; |
| 50 | this.encapsulation = EncapsulationType.NONE; |
| 51 | this.l2NetworkName = l2NetworkName; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Gets the ip subnet of the ip subnet entry. |
| 56 | * |
| 57 | * @return the ip subnet |
| 58 | */ |
| 59 | public IpPrefix ipPrefix() { |
| 60 | return ipPrefix; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gets the virtual gateway IP address of the ip subnet entry. |
| 65 | * |
| 66 | * @return the virtual gateway IP address |
| 67 | */ |
| 68 | public IpAddress gatewayIp() { |
| 69 | return gatewayIp; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Gets the virtual gateway Mac address of the ip subnet entry. |
| 74 | * |
| 75 | * @return the virtuai gateway Mac address |
| 76 | */ |
| 77 | public MacAddress gatewayMac() { |
| 78 | return gatewayMac; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Gets the encapsulation type of ip subnet entry. |
| 83 | * |
| 84 | * @return the encapsulation type |
| 85 | */ |
| 86 | public EncapsulationType encapsulation() { |
| 87 | return encapsulation; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Gets the name of L2 Network this subnet is bound. |
| 92 | * |
| 93 | * @return the l2Network name this subnet is allocated |
| 94 | */ |
| 95 | public String l2NetworkName() { |
| 96 | return l2NetworkName; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Tests whether the IP version of this entry is IPv4. |
| 101 | * |
| 102 | * @return true if the IP version of this entry is IPv4, otherwise false. |
| 103 | */ |
| 104 | public boolean isIp4() { |
| 105 | return ipPrefix.isIp4(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Tests whether the IP version of this entry is IPv6. |
| 110 | * |
| 111 | * @return true if the IP version of this entry is IPv6, otherwise false. |
| 112 | */ |
| 113 | public boolean isIp6() { |
| 114 | return ipPrefix.isIp6(); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public int hashCode() { |
| 119 | return Objects.hash(ipPrefix, gatewayIp, gatewayMac, encapsulation, l2NetworkName); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public boolean equals(Object obj) { |
| 124 | if (obj == this) { |
| 125 | return true; |
| 126 | } |
| 127 | if (!(obj instanceof IpSubnet)) { |
| 128 | return false; |
| 129 | } |
| 130 | IpSubnet that = (IpSubnet) obj; |
| 131 | return Objects.equals(this.ipPrefix, that.ipPrefix) |
| 132 | && Objects.equals(this.gatewayIp, that.gatewayIp) |
| 133 | && Objects.equals(this.gatewayMac, that.gatewayMac) |
| 134 | && Objects.equals(this.encapsulation, that.encapsulation) |
| 135 | && Objects.equals(this.l2NetworkName, that.l2NetworkName); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public String toString() { |
| 140 | return MoreObjects.toStringHelper(getClass()) |
| 141 | .add("ipPrefix", ipPrefix) |
| 142 | .add("gatewayIp", gatewayIp) |
| 143 | .add("gatewayMac", gatewayMac) |
| 144 | .add("encapsulation", encapsulation) |
| 145 | .add("l2NetworkName", l2NetworkName) |
| 146 | .toString(); |
| 147 | } |
| 148 | } |