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