DefaultSubnet.java
5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.vtnrsc;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
import java.util.Set;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpAddress.Version;
import org.onlab.packet.IpPrefix;
/**
* Default implementation of Subnet interface .
*/
public final class DefaultSubnet implements Subnet {
private final SubnetId id;
private final String subnetName;
private final TenantNetworkId networkId;
private final TenantId tenantId;
private final Version ipVersion;
private final IpPrefix cidr;
private final IpAddress gatewayIp;
private final boolean dhcpEnabled;
private final boolean shared;
private final Mode ipV6AddressMode;
private final Mode ipV6RaMode;
private final Set<HostRoute> hostRoutes;
private final Set<AllocationPool> allocationPools;
/**
* Creates a subnet object.
*
* @param id subnet identifier
* @param subnetName the name of subnet
* @param networkId network identifier
* @param tenantId tenant identifier
* @param ipVersion Version of ipv4 or ipv6
* @param cidr the cidr
* @param gatewayIp gateway ip
* @param dhcpEnabled dhcp enabled or not
* @param shared indicates whether this network is shared across all
* tenants, By default, only administrative user can change this
* value
* @param hostRoutes a collection of host routes
* @param ipV6AddressMode ipV6AddressMode
* @param ipV6RaMode ipV6RaMode
* @param allocationPoolsIt a collection of allocationPools
*/
public DefaultSubnet(SubnetId id, String subnetName,
TenantNetworkId networkId, TenantId tenantId,
Version ipVersion, IpPrefix cidr, IpAddress gatewayIp,
boolean dhcpEnabled, boolean shared,
Set<HostRoute> hostRoutes, Mode ipV6AddressMode,
Mode ipV6RaMode,
Set<AllocationPool> allocationPoolsIt) {
this.id = id;
this.subnetName = subnetName;
this.networkId = networkId;
this.tenantId = tenantId;
this.ipVersion = ipVersion;
this.cidr = cidr;
this.gatewayIp = gatewayIp;
this.dhcpEnabled = dhcpEnabled;
this.shared = shared;
this.ipV6AddressMode = ipV6AddressMode;
this.ipV6RaMode = ipV6RaMode;
this.hostRoutes = hostRoutes;
this.allocationPools = allocationPoolsIt;
}
@Override
public SubnetId id() {
return id;
}
@Override
public String subnetName() {
return subnetName;
}
@Override
public TenantNetworkId networkId() {
return networkId;
}
@Override
public TenantId tenantId() {
return tenantId;
}
@Override
public Version ipVersion() {
return ipVersion;
}
@Override
public IpPrefix cidr() {
return cidr;
}
@Override
public IpAddress gatewayIp() {
return gatewayIp;
}
@Override
public boolean dhcpEnabled() {
return dhcpEnabled;
}
@Override
public boolean shared() {
return shared;
}
@Override
public Iterable<HostRoute> hostRoutes() {
return hostRoutes;
}
@Override
public Mode ipV6AddressMode() {
return ipV6AddressMode;
}
@Override
public Mode ipV6RaMode() {
return ipV6RaMode;
}
@Override
public Iterable<AllocationPool> allocationPools() {
return allocationPools;
}
@Override
public int hashCode() {
return Objects.hash(id, subnetName, ipVersion, cidr, gatewayIp,
dhcpEnabled, shared, tenantId);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DefaultSubnet) {
final DefaultSubnet that = (DefaultSubnet) obj;
return Objects.equals(this.id, that.id)
&& Objects.equals(this.subnetName, that.subnetName)
&& Objects.equals(this.ipVersion, that.ipVersion)
&& Objects.equals(this.cidr, that.cidr)
&& Objects.equals(this.shared, that.shared)
&& Objects.equals(this.gatewayIp, that.gatewayIp)
&& Objects.equals(this.dhcpEnabled, that.dhcpEnabled);
}
return false;
}
@Override
public String toString() {
return toStringHelper(this).add("id", id).add("subnetName", subnetName)
.add("ipVersion", ipVersion).add("cidr", cidr)
.add("shared", shared).add("gatewayIp", gatewayIp)
.add("dhcpEnabled", dhcpEnabled).toString();
}
}