Committed by
Gerrit Code Review
Added builder and more logs for VtnService and VtnPort
Change-Id: I52f672caebf1946b9bb01c9de0ca2ad2cee23f69
Showing
6 changed files
with
191 additions
and
39 deletions
... | @@ -16,12 +16,15 @@ | ... | @@ -16,12 +16,15 @@ |
16 | package org.onosproject.xosclient.api; | 16 | package org.onosproject.xosclient.api; |
17 | 17 | ||
18 | import com.google.common.base.MoreObjects; | 18 | import com.google.common.base.MoreObjects; |
19 | +import com.google.common.collect.ImmutableMap; | ||
19 | import org.onlab.packet.IpAddress; | 20 | import org.onlab.packet.IpAddress; |
20 | import org.onlab.packet.MacAddress; | 21 | import org.onlab.packet.MacAddress; |
21 | 22 | ||
22 | import java.util.Map; | 23 | import java.util.Map; |
23 | import java.util.Objects; | 24 | import java.util.Objects; |
24 | 25 | ||
26 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
27 | + | ||
25 | /** | 28 | /** |
26 | * Representation of port in a CORD VTN controlled network, it can be for VM | 29 | * Representation of port in a CORD VTN controlled network, it can be for VM |
27 | * or container. | 30 | * or container. |
... | @@ -36,23 +39,12 @@ public final class VtnPort { | ... | @@ -36,23 +39,12 @@ public final class VtnPort { |
36 | // TODO remove this when XOS provides vSG information | 39 | // TODO remove this when XOS provides vSG information |
37 | private final Map<IpAddress, MacAddress> addressPairs; | 40 | private final Map<IpAddress, MacAddress> addressPairs; |
38 | 41 | ||
39 | - | 42 | + private VtnPort(VtnPortId id, |
40 | - /** | 43 | + String name, |
41 | - * Creates a new vtn port with the specified entities. | 44 | + VtnServiceId serviceId, |
42 | - * | 45 | + MacAddress mac, |
43 | - * @param id vtn port id | 46 | + IpAddress ip, |
44 | - * @param name vtn port name | 47 | + Map<IpAddress, MacAddress> addressPairs) { |
45 | - * @param serviceId id of the service this port is in | ||
46 | - * @param mac mac address | ||
47 | - * @param ip ip address | ||
48 | - * @param addressPairs ip and mac pairs of nested container | ||
49 | - */ | ||
50 | - public VtnPort(VtnPortId id, | ||
51 | - String name, | ||
52 | - VtnServiceId serviceId, | ||
53 | - MacAddress mac, | ||
54 | - IpAddress ip, | ||
55 | - Map<IpAddress, MacAddress> addressPairs) { | ||
56 | this.id = id; | 48 | this.id = id; |
57 | this.name = name; | 49 | this.name = name; |
58 | this.serviceId = serviceId; | 50 | this.serviceId = serviceId; |
... | @@ -143,4 +135,161 @@ public final class VtnPort { | ... | @@ -143,4 +135,161 @@ public final class VtnPort { |
143 | .add("addressPairs", addressPairs) | 135 | .add("addressPairs", addressPairs) |
144 | .toString(); | 136 | .toString(); |
145 | } | 137 | } |
138 | + | ||
139 | + /** | ||
140 | + * Returns a new vtn port builder instance. | ||
141 | + * | ||
142 | + * @return new vtn port builder | ||
143 | + */ | ||
144 | + public static final Builder builder() { | ||
145 | + return new Builder(); | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Builder of VTN port entities. | ||
150 | + */ | ||
151 | + public static final class Builder { | ||
152 | + | ||
153 | + private VtnPortId id; | ||
154 | + private String name; | ||
155 | + private VtnServiceId serviceId; | ||
156 | + private MacAddress mac; | ||
157 | + private IpAddress ip; | ||
158 | + // TODO remove this when XOS provides vSG information | ||
159 | + private Map<IpAddress, MacAddress> addressPairs; | ||
160 | + | ||
161 | + private Builder() { | ||
162 | + } | ||
163 | + | ||
164 | + /** | ||
165 | + * Builds an immutable VTN port. | ||
166 | + * | ||
167 | + * @return vtn port instance | ||
168 | + */ | ||
169 | + public VtnPort build() { | ||
170 | + checkNotNull(id, "VTN port ID cannot be null"); | ||
171 | + checkNotNull(serviceId, "VTN port service ID cannot be null"); | ||
172 | + checkNotNull(mac, "VTN port MAC address cannot be null"); | ||
173 | + checkNotNull(ip, "VTN port IP address cannot be null"); | ||
174 | + addressPairs = addressPairs == null ? ImmutableMap.of() : addressPairs; | ||
175 | + | ||
176 | + return new VtnPort(id, | ||
177 | + name, | ||
178 | + serviceId, | ||
179 | + mac, | ||
180 | + ip, | ||
181 | + addressPairs); | ||
182 | + } | ||
183 | + | ||
184 | + /** | ||
185 | + * Returns VTN port builder with the supplied port ID. | ||
186 | + * | ||
187 | + * @param id port identifier | ||
188 | + * @return vtn port builder | ||
189 | + */ | ||
190 | + public Builder id(VtnPortId id) { | ||
191 | + this.id = id; | ||
192 | + return this; | ||
193 | + } | ||
194 | + | ||
195 | + /** | ||
196 | + * Returns VTN port builder with the supplied port name. | ||
197 | + * Port name can be null. | ||
198 | + * | ||
199 | + * @param name port name | ||
200 | + * @return vtn port builder | ||
201 | + */ | ||
202 | + public Builder name(String name) { | ||
203 | + this.name = name; | ||
204 | + return this; | ||
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * Returns VTN port builder with the supplied service ID. | ||
209 | + * | ||
210 | + * @param serviceId vtn port service id | ||
211 | + * @return vtn port builder | ||
212 | + */ | ||
213 | + public Builder serviceId(VtnServiceId serviceId) { | ||
214 | + this.serviceId = serviceId; | ||
215 | + return this; | ||
216 | + } | ||
217 | + | ||
218 | + /** | ||
219 | + * Returns VTN port builder with the supplied MAC address. | ||
220 | + * | ||
221 | + * @param mac mac address | ||
222 | + * @return vtn port builder | ||
223 | + */ | ||
224 | + public Builder mac(MacAddress mac) { | ||
225 | + if (mac == null) { | ||
226 | + final String msg = "VTN port MAC address cannot be null"; | ||
227 | + throw new IllegalArgumentException(msg); | ||
228 | + } | ||
229 | + this.mac = mac; | ||
230 | + return this; | ||
231 | + } | ||
232 | + | ||
233 | + /** | ||
234 | + * Returns VTN port builder with the supplied MAC address. | ||
235 | + * | ||
236 | + * @param mac mac address as a string | ||
237 | + * @return vtn port builder | ||
238 | + */ | ||
239 | + public Builder mac(String mac) { | ||
240 | + try { | ||
241 | + return mac(MacAddress.valueOf(mac)); | ||
242 | + } catch (IllegalArgumentException | NullPointerException e) { | ||
243 | + final String msg = "Malformed MAC address string " + mac + | ||
244 | + " for VTN port MAC address"; | ||
245 | + throw new IllegalArgumentException(msg); | ||
246 | + } | ||
247 | + } | ||
248 | + | ||
249 | + /** | ||
250 | + * Returns VTN port builder with the supplied IP address. | ||
251 | + * | ||
252 | + * @param ip ip address | ||
253 | + * @return vtn port builder | ||
254 | + */ | ||
255 | + public Builder ip(IpAddress ip) { | ||
256 | + if (ip == null) { | ||
257 | + final String msg = "VTN port IP address cannot be null"; | ||
258 | + throw new IllegalArgumentException(msg); | ||
259 | + } | ||
260 | + this.ip = ip; | ||
261 | + return this; | ||
262 | + } | ||
263 | + | ||
264 | + /** | ||
265 | + * Returns VTN port builder with the supplied IP address. | ||
266 | + * | ||
267 | + * @param ip ip address as a string | ||
268 | + * @return vtn port builder | ||
269 | + */ | ||
270 | + public Builder ip(String ip) { | ||
271 | + try { | ||
272 | + return ip(IpAddress.valueOf(ip)); | ||
273 | + } catch (IllegalArgumentException | NullPointerException e) { | ||
274 | + final String msg = "Malformed IP address string " + ip + | ||
275 | + " for VTN port IP address"; | ||
276 | + throw new IllegalArgumentException(msg); | ||
277 | + } | ||
278 | + } | ||
279 | + | ||
280 | + /** | ||
281 | + * Returns VTN port builder with the supplied address pairs. | ||
282 | + * | ||
283 | + * @param addressPairs address pairs | ||
284 | + * @return vtn port builder | ||
285 | + */ | ||
286 | + public Builder addressPairs(Map<IpAddress, MacAddress> addressPairs) { | ||
287 | + if (addressPairs == null) { | ||
288 | + final String msg = "VTN address pairs cannot be null"; | ||
289 | + throw new IllegalArgumentException(msg); | ||
290 | + } | ||
291 | + this.addressPairs = addressPairs; | ||
292 | + return this; | ||
293 | + } | ||
294 | + } | ||
146 | } | 295 | } | ... | ... |
... | @@ -36,7 +36,7 @@ public final class VtnPortId extends Identifier<String> { | ... | @@ -36,7 +36,7 @@ public final class VtnPortId extends Identifier<String> { |
36 | * @return instance port id | 36 | * @return instance port id |
37 | */ | 37 | */ |
38 | public static VtnPortId of(String id) { | 38 | public static VtnPortId of(String id) { |
39 | - checkArgument(!Strings.isNullOrEmpty(id)); | 39 | + checkArgument(!Strings.isNullOrEmpty(id), "VTN port ID cannot be null"); |
40 | return new VtnPortId(id); | 40 | return new VtnPortId(id); |
41 | } | 41 | } |
42 | } | 42 | } | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -15,9 +15,10 @@ | ... | @@ -15,9 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.xosclient.api; | 16 | package org.onosproject.xosclient.api; |
17 | 17 | ||
18 | +import com.google.common.base.Strings; | ||
18 | import org.onlab.util.Identifier; | 19 | import org.onlab.util.Identifier; |
19 | 20 | ||
20 | -import static com.google.common.base.Preconditions.checkNotNull; | 21 | +import static com.google.common.base.Preconditions.checkArgument; |
21 | 22 | ||
22 | /** | 23 | /** |
23 | * Representation of VTN service identifier. | 24 | * Representation of VTN service identifier. |
... | @@ -39,7 +40,7 @@ public final class VtnServiceId extends Identifier<String> { | ... | @@ -39,7 +40,7 @@ public final class VtnServiceId extends Identifier<String> { |
39 | * @return CordServiceId | 40 | * @return CordServiceId |
40 | */ | 41 | */ |
41 | public static VtnServiceId of(String id) { | 42 | public static VtnServiceId of(String id) { |
42 | - checkNotNull(id); | 43 | + checkArgument(!Strings.isNullOrEmpty(id), "VTN service ID cannot be null"); |
43 | return new VtnServiceId(id); | 44 | return new VtnServiceId(id); |
44 | } | 45 | } |
45 | } | 46 | } | ... | ... |
... | @@ -119,12 +119,14 @@ public final class DefaultVtnPortApi extends XosApi implements VtnPortApi { | ... | @@ -119,12 +119,14 @@ public final class DefaultVtnPortApi extends XosApi implements VtnPortApi { |
119 | pair -> addressPairs.put(IpAddress.valueOf(pair.getIpAddress()), | 119 | pair -> addressPairs.put(IpAddress.valueOf(pair.getIpAddress()), |
120 | MacAddress.valueOf(pair.getMacAddress()))); | 120 | MacAddress.valueOf(pair.getMacAddress()))); |
121 | 121 | ||
122 | - return new VtnPort(VtnPortId.of(osPort.getId()), | 122 | + return VtnPort.builder() |
123 | - osPort.getName(), | 123 | + .id(VtnPortId.of(osPort.getId())) |
124 | - VtnServiceId.of(osPort.getNetworkId()), | 124 | + .name(osPort.getName()) |
125 | - MacAddress.valueOf(osPort.getMacAddress()), | 125 | + .serviceId(VtnServiceId.of(osPort.getNetworkId())) |
126 | - IpAddress.valueOf(ipAddr.getIpAddress()), | 126 | + .mac(osPort.getMacAddress()) |
127 | - addressPairs); | 127 | + .ip(ipAddr.getIpAddress()) |
128 | + .addressPairs(addressPairs) | ||
129 | + .build(); | ||
128 | } | 130 | } |
129 | 131 | ||
130 | // TODO remove this when XOS provides this information | 132 | // TODO remove this when XOS provides this information | ... | ... |
... | @@ -19,8 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; | ... | @@ -19,8 +19,6 @@ import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.google.common.base.Strings; | 20 | import com.google.common.base.Strings; |
21 | import com.google.common.collect.Sets; | 21 | import com.google.common.collect.Sets; |
22 | -import org.onlab.packet.IpAddress; | ||
23 | -import org.onlab.packet.IpPrefix; | ||
24 | import org.onosproject.xosclient.api.OpenStackAccess; | 22 | import org.onosproject.xosclient.api.OpenStackAccess; |
25 | import org.onosproject.xosclient.api.VtnServiceApi; | 23 | import org.onosproject.xosclient.api.VtnServiceApi; |
26 | import org.onosproject.xosclient.api.XosAccess; | 24 | import org.onosproject.xosclient.api.XosAccess; |
... | @@ -146,15 +144,17 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi | ... | @@ -146,15 +144,17 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi |
146 | return null; | 144 | return null; |
147 | } | 145 | } |
148 | 146 | ||
149 | - return new VtnService(serviceId, | 147 | + return VtnService.build() |
150 | - osNet.getName(), | 148 | + .id(serviceId) |
151 | - serviceType(osNet.getName()), | 149 | + .name(osNet.getName()) |
152 | - networkType(osNet.getName()), | 150 | + .serviceType(serviceType(osNet.getName())) |
153 | - Long.parseLong(osNet.getProviderSegID()), | 151 | + .networkType(networkType(osNet.getName())) |
154 | - IpPrefix.valueOf(osSubnet.getCidr()), | 152 | + .vni(osNet.getProviderSegID()) |
155 | - IpAddress.valueOf(osSubnet.getGateway()), | 153 | + .subnet(osSubnet.getCidr()) |
156 | - providerServices(serviceId), | 154 | + .serviceIp(osSubnet.getGateway()) |
157 | - tenantServices(serviceId)); | 155 | + .providerServices(providerServices(serviceId)) |
156 | + .tenantServices(tenantServices(serviceId)) | ||
157 | + .build(); | ||
158 | } | 158 | } |
159 | 159 | ||
160 | // TODO remove this when XOS provides this information | 160 | // TODO remove this when XOS provides this information |
... | @@ -177,7 +177,7 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi | ... | @@ -177,7 +177,7 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi |
177 | 177 | ||
178 | // TODO remove this when XOS provides this information | 178 | // TODO remove this when XOS provides this information |
179 | private NetworkType networkType(String netName) { | 179 | private NetworkType networkType(String netName) { |
180 | - checkArgument(!Strings.isNullOrEmpty(netName)); | 180 | + checkArgument(!Strings.isNullOrEmpty(netName), "VTN network name cannot be null"); |
181 | 181 | ||
182 | String name = netName.toUpperCase(); | 182 | String name = netName.toUpperCase(); |
183 | if (name.contains(PUBLIC.name())) { | 183 | if (name.contains(PUBLIC.name())) { |
... | @@ -193,7 +193,7 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi | ... | @@ -193,7 +193,7 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi |
193 | 193 | ||
194 | // TODO remove this when XOS provides this information | 194 | // TODO remove this when XOS provides this information |
195 | private ServiceType serviceType(String netName) { | 195 | private ServiceType serviceType(String netName) { |
196 | - checkArgument(!Strings.isNullOrEmpty(netName)); | 196 | + checkArgument(!Strings.isNullOrEmpty(netName), "VTN network name cannot be null"); |
197 | 197 | ||
198 | String name = netName.toUpperCase(); | 198 | String name = netName.toUpperCase(); |
199 | if (name.contains(VSG.name())) { | 199 | if (name.contains(VSG.name())) { | ... | ... |
-
Please register or login to post a comment