blob: 9162916c8ce11169e9c56a44257b8dfcd76cd841 [file] [log] [blame]
danielbb83ebc2015-10-29 15:13:06 +09001/*
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 */
sangho93447f12016-02-24 00:33:22 +090016package org.onosproject.openstackinterface;
danielbb83ebc2015-10-29 15:13:06 +090017
sanghoshin46297d22015-11-03 17:51:24 +090018import org.onlab.packet.Ip4Address;
19
sangho5db8e052016-01-29 16:08:23 +090020import java.util.Collection;
21import java.util.Collections;
sanghoshin46297d22015-11-03 17:51:24 +090022import java.util.List;
23
danielbb83ebc2015-10-29 15:13:06 +090024import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Represents the subnet information given by Neutron.
28 *
29 */
30public final class OpenstackSubnet {
31 private String name;
32 private boolean enableHhcp;
33 private String networkId;
34 private String tenantId;
sanghoshin46297d22015-11-03 17:51:24 +090035 private List<Ip4Address> dnsNameservers;
danielbb83ebc2015-10-29 15:13:06 +090036 private String gatewayIp;
37 private String cidr;
38 private String id;
sangho5db8e052016-01-29 16:08:23 +090039 private Collection<String> securityGroups;
danielbb83ebc2015-10-29 15:13:06 +090040
41 private OpenstackSubnet(String name, boolean enableHhcp, String networkId,
sanghoshin46297d22015-11-03 17:51:24 +090042 String tenantId, List<Ip4Address> dnsNameservers, String gatewayIp,
sangho5db8e052016-01-29 16:08:23 +090043 String cidr, String id, Collection<String> securityGroups) {
danielbb83ebc2015-10-29 15:13:06 +090044 this.name = name;
45 this.enableHhcp = enableHhcp;
46 this.networkId = checkNotNull(networkId);
47 this.tenantId = checkNotNull(tenantId);
48 this.dnsNameservers = dnsNameservers;
49 this.gatewayIp = gatewayIp;
50 this.cidr = checkNotNull(cidr);
51 this.id = checkNotNull(id);
sangho5db8e052016-01-29 16:08:23 +090052 this.securityGroups = securityGroups;
danielbb83ebc2015-10-29 15:13:06 +090053 }
54
55 /**
56 * Returns OpenstackSubnet builder object.
57 *
58 * @return OpenstackSubnet builder
59 */
60 public static OpenstackSubnet.Builder builder() {
61 return new Builder();
62 }
63
64 public String name() {
65 return name;
66 }
67
68 public boolean enableHhcp() {
69 return enableHhcp;
70 }
71
72 public String networkId() {
73 return networkId;
74 }
75
76 public String tenantId() {
77 return tenantId;
78 }
79
sanghoshin46297d22015-11-03 17:51:24 +090080 public List<Ip4Address> dnsNameservers() {
danielbb83ebc2015-10-29 15:13:06 +090081 return dnsNameservers;
82 }
83
84 public String gatewayIp() {
85 return gatewayIp;
86 }
87
88 public String cidr() {
89 return cidr;
90 }
91
92 public String id() {
93 return id;
94 }
95
sangho5db8e052016-01-29 16:08:23 +090096 public Collection<String> securityGroups() {
97 return Collections.unmodifiableCollection(this.securityGroups);
98 }
99
danielbb83ebc2015-10-29 15:13:06 +0900100 /**
101 * OpenstackSubnet Builder class.
102 *
103 */
104 public static final class Builder {
105 private String name;
106 private boolean enableDhcp;
107 private String networkId;
108 private String tenantId;
sanghoshin46297d22015-11-03 17:51:24 +0900109 private List<Ip4Address> dnsNameservers;
danielbb83ebc2015-10-29 15:13:06 +0900110 private String gatewayIp;
111 private String cidr;
112 private String id;
sangho5db8e052016-01-29 16:08:23 +0900113 private Collection<String> securityGroups;
danielbb83ebc2015-10-29 15:13:06 +0900114
115 Builder() {}
116
117 public Builder setName(String name) {
118 this.name = name;
119
120 return this;
121 }
122
123 public Builder setEnableDhcp(boolean enableDhcp) {
124 this.enableDhcp = enableDhcp;
125
126 return this;
127 }
128
129 public Builder setNetworkId(String networkId) {
130 this.networkId = networkId;
131
132 return this;
133 }
134
135 public Builder setTenantId(String tenantId) {
136 this.tenantId = tenantId;
137
138 return this;
139 }
140
sanghoshin46297d22015-11-03 17:51:24 +0900141 public Builder setDnsNameservers(List<Ip4Address> dnsNameservers) {
danielbb83ebc2015-10-29 15:13:06 +0900142 this.dnsNameservers = dnsNameservers;
143
144 return this;
145 }
146
147 public Builder setGatewayIp(String gatewayIp) {
148 this.gatewayIp = gatewayIp;
149
150 return this;
151 }
152
153 public Builder setCidr(String cidr) {
154 this.cidr = cidr;
155
156 return this;
157 }
158
159 public Builder setId(String id) {
160 this.id = id;
161
162 return this;
163 }
164
sangho5db8e052016-01-29 16:08:23 +0900165 public Builder securityGroups(Collection<String> securityGroups) {
166 this.securityGroups = securityGroups;
167
168 return this;
169 }
170
danielbb83ebc2015-10-29 15:13:06 +0900171 public OpenstackSubnet build() {
172 return new OpenstackSubnet(name, enableDhcp, networkId, tenantId,
sangho5db8e052016-01-29 16:08:23 +0900173 dnsNameservers, gatewayIp, cidr, id, securityGroups);
danielbb83ebc2015-10-29 15:13:06 +0900174 }
175 }
176}