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