xuzhang | 91b2ff4 | 2015-08-11 11:05:19 +0800 | [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.app.vtnrsc; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import org.onlab.packet.IpAddress; |
| 23 | import org.onlab.packet.IpAddress.Version; |
| 24 | import org.onlab.packet.IpPrefix; |
| 25 | |
| 26 | /** |
| 27 | * Default implementation of Subnet interface . |
| 28 | */ |
| 29 | public final class DefaultSubnet implements Subnet { |
| 30 | private final SubnetId id; |
| 31 | private final String subnetName; |
| 32 | private final TenantNetworkId networkId; |
| 33 | private final TenantId tenantId; |
| 34 | private final Version ipVersion; |
| 35 | private final IpPrefix cidr; |
| 36 | private final IpAddress gatewayIp; |
| 37 | private final boolean dhcpEnabled; |
| 38 | private final boolean shared; |
| 39 | private final Mode ipV6AddressMode; |
| 40 | private final Mode ipV6RaMode; |
| 41 | private final Iterable<HostRoute> hostRoutes; |
| 42 | private final Iterable<AllocationPool> allocationPools; |
| 43 | |
| 44 | /** |
| 45 | * Creates a subnet object. |
| 46 | * |
| 47 | * @param id subnet identifier |
| 48 | * @param subnetName the name of subnet |
| 49 | * @param networkId network identifier |
| 50 | * @param tenantId tenant identifier |
| 51 | * @param cidr the cidr |
| 52 | * @param gatewayIp gateway ip |
| 53 | * @param dhcpEnabled dhcp enabled or not |
| 54 | * @param shared indicates whether this network is shared across all |
| 55 | * tenants, By default, only administrative user can change this |
| 56 | * value |
| 57 | * @param hostRoutes a collection of host routes |
| 58 | * @param ipV6AddressMode ipV6AddressMode |
| 59 | * @param ipV6RaMode ipV6RaMode |
| 60 | * @param allocationPoolsIt a collection of allocationPools |
| 61 | */ |
| 62 | public DefaultSubnet(SubnetId id, String subnetName, |
| 63 | TenantNetworkId networkId, TenantId tenantId, |
| 64 | Version ipVersion, IpPrefix cidr, IpAddress gatewayIp, |
| 65 | boolean dhcpEnabled, boolean shared, |
| 66 | Iterable<HostRoute> hostRoutes, Mode ipV6AddressMode, |
| 67 | Mode ipV6RaMode, |
| 68 | Iterable<AllocationPool> allocationPoolsIt) { |
| 69 | this.id = id; |
| 70 | this.subnetName = subnetName; |
| 71 | this.networkId = networkId; |
| 72 | this.tenantId = tenantId; |
| 73 | this.ipVersion = ipVersion; |
| 74 | this.cidr = cidr; |
| 75 | this.gatewayIp = gatewayIp; |
| 76 | this.dhcpEnabled = dhcpEnabled; |
| 77 | this.shared = shared; |
| 78 | this.ipV6AddressMode = ipV6AddressMode; |
| 79 | this.ipV6RaMode = ipV6RaMode; |
| 80 | this.hostRoutes = hostRoutes; |
| 81 | this.allocationPools = allocationPoolsIt; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public SubnetId id() { |
| 86 | return id; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public String subnetName() { |
| 91 | return subnetName; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public TenantNetworkId networkId() { |
| 96 | return networkId; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public TenantId tenantId() { |
| 101 | return tenantId; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public Version ipVersion() { |
| 106 | return ipVersion; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public IpPrefix cidr() { |
| 111 | return cidr; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public IpAddress gatewayIp() { |
| 116 | return gatewayIp; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public boolean dhcpEnabled() { |
| 121 | return dhcpEnabled; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public boolean shared() { |
| 126 | return shared; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public Iterable<HostRoute> hostRoutes() { |
| 131 | return hostRoutes; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public Mode ipV6AddressMode() { |
| 136 | return ipV6AddressMode; |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public Mode ipV6RaMode() { |
| 141 | return ipV6RaMode; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public Iterable<AllocationPool> allocationPools() { |
| 146 | return allocationPools; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public int hashCode() { |
| 151 | return Objects.hash(id, subnetName, ipVersion, cidr, gatewayIp, |
| 152 | dhcpEnabled, shared, tenantId); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public boolean equals(Object obj) { |
| 157 | if (this == obj) { |
| 158 | return true; |
| 159 | } |
| 160 | if (obj instanceof DefaultSubnet) { |
| 161 | final DefaultSubnet that = (DefaultSubnet) obj; |
| 162 | return Objects.equals(this.id, that.id) |
| 163 | && Objects.equals(this.subnetName, that.subnetName) |
| 164 | && Objects.equals(this.ipVersion, that.ipVersion) |
| 165 | && Objects.equals(this.cidr, that.cidr) |
| 166 | && Objects.equals(this.shared, that.shared) |
| 167 | && Objects.equals(this.gatewayIp, that.gatewayIp) |
| 168 | && Objects.equals(this.dhcpEnabled, that.dhcpEnabled); |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public String toString() { |
| 175 | return toStringHelper(this).add("id", id).add("subnetName", subnetName) |
| 176 | .add("ipVersion", ipVersion).add("cidr", cidr) |
| 177 | .add("shared", shared).add("gatewayIp", gatewayIp) |
| 178 | .add("dhcpEnabled", dhcpEnabled).toString(); |
| 179 | } |
| 180 | |
| 181 | } |