Committed by
Gerrit Code Review
Added builder and more logs for VtnService and VtnPort
Change-Id: I52f672caebf1946b9bb01c9de0ca2ad2cee23f69
Showing
6 changed files
with
422 additions
and
54 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,18 +39,7 @@ public final class VtnPort { | ... | @@ -36,18 +39,7 @@ 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 | - /** | ||
| 41 | - * Creates a new vtn port with the specified entities. | ||
| 42 | - * | ||
| 43 | - * @param id vtn port id | ||
| 44 | - * @param name vtn port name | ||
| 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, | 43 | String name, |
| 52 | VtnServiceId serviceId, | 44 | VtnServiceId serviceId, |
| 53 | MacAddress mac, | 45 | MacAddress mac, |
| ... | @@ -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 | } | ... | ... |
| ... | @@ -16,7 +16,8 @@ | ... | @@ -16,7 +16,8 @@ |
| 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.Sets; | 19 | +import com.google.common.base.Strings; |
| 20 | +import com.google.common.collect.ImmutableSet; | ||
| 20 | import org.onlab.packet.IpAddress; | 21 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.IpPrefix; | 22 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onosproject.xosclient.api.VtnServiceApi.NetworkType; | 23 | import org.onosproject.xosclient.api.VtnServiceApi.NetworkType; |
| ... | @@ -25,6 +26,7 @@ import org.onosproject.xosclient.api.VtnServiceApi.ServiceType; | ... | @@ -25,6 +26,7 @@ import org.onosproject.xosclient.api.VtnServiceApi.ServiceType; |
| 25 | import java.util.Objects; | 26 | import java.util.Objects; |
| 26 | import java.util.Set; | 27 | import java.util.Set; |
| 27 | 28 | ||
| 29 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 28 | import static com.google.common.base.Preconditions.checkNotNull; | 30 | import static com.google.common.base.Preconditions.checkNotNull; |
| 29 | 31 | ||
| 30 | /** | 32 | /** |
| ... | @@ -42,20 +44,7 @@ public final class VtnService { | ... | @@ -42,20 +44,7 @@ public final class VtnService { |
| 42 | private final Set<VtnServiceId> providerServices; | 44 | private final Set<VtnServiceId> providerServices; |
| 43 | private final Set<VtnServiceId> tenantServices; | 45 | private final Set<VtnServiceId> tenantServices; |
| 44 | 46 | ||
| 45 | - /** | 47 | + private VtnService(VtnServiceId id, |
| 46 | - * Creates a new VTN service with the specified entities. | ||
| 47 | - * | ||
| 48 | - * @param id service id | ||
| 49 | - * @param name user friendly name | ||
| 50 | - * @param serviceType service type | ||
| 51 | - * @param networkType network type | ||
| 52 | - * @param vni vni of this service network | ||
| 53 | - * @param subnet service network subnet range | ||
| 54 | - * @param serviceIp service ip for indirect service access | ||
| 55 | - * @param providerServices provider services | ||
| 56 | - * @param tenantServices tenant services | ||
| 57 | - */ | ||
| 58 | - public VtnService(VtnServiceId id, | ||
| 59 | String name, | 48 | String name, |
| 60 | ServiceType serviceType, | 49 | ServiceType serviceType, |
| 61 | NetworkType networkType, | 50 | NetworkType networkType, |
| ... | @@ -64,15 +53,15 @@ public final class VtnService { | ... | @@ -64,15 +53,15 @@ public final class VtnService { |
| 64 | IpAddress serviceIp, | 53 | IpAddress serviceIp, |
| 65 | Set<VtnServiceId> providerServices, | 54 | Set<VtnServiceId> providerServices, |
| 66 | Set<VtnServiceId> tenantServices) { | 55 | Set<VtnServiceId> tenantServices) { |
| 67 | - this.id = checkNotNull(id); | 56 | + this.id = id; |
| 68 | this.name = name; | 57 | this.name = name; |
| 69 | this.serviceType = serviceType; | 58 | this.serviceType = serviceType; |
| 70 | this.networkType = networkType; | 59 | this.networkType = networkType; |
| 71 | this.vni = vni; | 60 | this.vni = vni; |
| 72 | - this.subnet = checkNotNull(subnet); | 61 | + this.subnet = subnet; |
| 73 | - this.serviceIp = checkNotNull(serviceIp); | 62 | + this.serviceIp = serviceIp; |
| 74 | - this.providerServices = providerServices == null ? Sets.newHashSet() : providerServices; | 63 | + this.providerServices = providerServices; |
| 75 | - this.tenantServices = tenantServices == null ? Sets.newHashSet() : tenantServices; | 64 | + this.tenantServices = tenantServices; |
| 76 | } | 65 | } |
| 77 | 66 | ||
| 78 | /** | 67 | /** |
| ... | @@ -187,4 +176,231 @@ public final class VtnService { | ... | @@ -187,4 +176,231 @@ public final class VtnService { |
| 187 | .add("tenantServices", tenantServices) | 176 | .add("tenantServices", tenantServices) |
| 188 | .toString(); | 177 | .toString(); |
| 189 | } | 178 | } |
| 179 | + | ||
| 180 | + /** | ||
| 181 | + * Returns a new builder instance. | ||
| 182 | + * | ||
| 183 | + * @return new builder | ||
| 184 | + */ | ||
| 185 | + public static final Builder build() { | ||
| 186 | + return new Builder(); | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + /** | ||
| 190 | + * Builder of VTN service entities. | ||
| 191 | + */ | ||
| 192 | + public static final class Builder { | ||
| 193 | + | ||
| 194 | + private VtnServiceId id; | ||
| 195 | + private String name; | ||
| 196 | + private ServiceType serviceType; | ||
| 197 | + private NetworkType networkType; | ||
| 198 | + private long vni = -1; | ||
| 199 | + private IpPrefix subnet; | ||
| 200 | + private IpAddress serviceIp; | ||
| 201 | + private Set<VtnServiceId> providerServices; | ||
| 202 | + private Set<VtnServiceId> tenantServices; | ||
| 203 | + | ||
| 204 | + private Builder() { | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + /** | ||
| 208 | + * Builds an immutable VTN service. | ||
| 209 | + * | ||
| 210 | + * @return vtn service instance | ||
| 211 | + */ | ||
| 212 | + public VtnService build() { | ||
| 213 | + checkNotNull(id, "VTN service ID cannot be null"); | ||
| 214 | + checkArgument(!Strings.isNullOrEmpty(name), "VTN service name cannot be null"); | ||
| 215 | + checkNotNull(serviceType, "VTN service type cannot be null"); | ||
| 216 | + checkNotNull(networkType, "VTN network type cannot be null"); | ||
| 217 | + checkArgument(vni > 0, "VTN network VNI is not set"); | ||
| 218 | + checkNotNull(subnet, "VTN subnet cannot be null"); | ||
| 219 | + checkNotNull(serviceIp, "VTN service IP cannot be null"); | ||
| 220 | + | ||
| 221 | + providerServices = providerServices == null ? ImmutableSet.of() : providerServices; | ||
| 222 | + tenantServices = tenantServices == null ? ImmutableSet.of() : tenantServices; | ||
| 223 | + | ||
| 224 | + return new VtnService(id, | ||
| 225 | + name, | ||
| 226 | + serviceType, | ||
| 227 | + networkType, | ||
| 228 | + vni, | ||
| 229 | + subnet, | ||
| 230 | + serviceIp, | ||
| 231 | + providerServices, | ||
| 232 | + tenantServices); | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + /** | ||
| 236 | + * Returns VTN service builder with the supplied service ID. | ||
| 237 | + * | ||
| 238 | + * @param id service identifier | ||
| 239 | + * @return vtn service builder | ||
| 240 | + */ | ||
| 241 | + public Builder id(VtnServiceId id) { | ||
| 242 | + this.id = id; | ||
| 243 | + return this; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + /** | ||
| 247 | + * Returns VTN service builder with the supplied service name. | ||
| 248 | + * | ||
| 249 | + * @param name service name | ||
| 250 | + * @return vtn service builder | ||
| 251 | + */ | ||
| 252 | + public Builder name(String name) { | ||
| 253 | + if (Strings.isNullOrEmpty(name)) { | ||
| 254 | + final String msg = "VTN service name cannot be null"; | ||
| 255 | + throw new IllegalArgumentException(msg); | ||
| 256 | + } | ||
| 257 | + this.name = name; | ||
| 258 | + return this; | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + /** | ||
| 262 | + * Returns VTN service builder with the supplied service type. | ||
| 263 | + * | ||
| 264 | + * @param serviceType service type | ||
| 265 | + * @return vtn service builder | ||
| 266 | + */ | ||
| 267 | + public Builder serviceType(ServiceType serviceType) { | ||
| 268 | + this.serviceType = serviceType; | ||
| 269 | + return this; | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + /** | ||
| 273 | + * Returns VTN service builder with the supplied network type. | ||
| 274 | + * | ||
| 275 | + * @param networkType network type | ||
| 276 | + * @return vtn service builder | ||
| 277 | + */ | ||
| 278 | + public Builder networkType(NetworkType networkType) { | ||
| 279 | + this.networkType = networkType; | ||
| 280 | + return this; | ||
| 281 | + } | ||
| 282 | + | ||
| 283 | + /** | ||
| 284 | + * Returns VTN service builder with the supplied VNI. | ||
| 285 | + * | ||
| 286 | + * @param vni vni of the service network | ||
| 287 | + * @return vtn service builder | ||
| 288 | + */ | ||
| 289 | + public Builder vni(long vni) { | ||
| 290 | + if (vni < 0 || vni > 16777215) { | ||
| 291 | + final String msg = "VNI " + vni + " is out of range"; | ||
| 292 | + throw new IllegalArgumentException(msg); | ||
| 293 | + } | ||
| 294 | + this.vni = vni; | ||
| 295 | + return this; | ||
| 296 | + } | ||
| 297 | + | ||
| 298 | + /** | ||
| 299 | + * Returns VTN service builder with the supplied VNI. | ||
| 300 | + * | ||
| 301 | + * @param vni vni of the service network as a string | ||
| 302 | + * @return vtn service builder | ||
| 303 | + */ | ||
| 304 | + public Builder vni(String vni) { | ||
| 305 | + try { | ||
| 306 | + return vni(Long.parseLong(vni)); | ||
| 307 | + } catch (NumberFormatException | NullPointerException e) { | ||
| 308 | + final String msg = "Malformed number string " + vni + | ||
| 309 | + " for VTN network VNI"; | ||
| 310 | + throw new IllegalArgumentException(msg); | ||
| 311 | + } | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + /** | ||
| 315 | + * Returns VTN service builder with the supplied subnet. | ||
| 316 | + * | ||
| 317 | + * @param subnet subnet of the service network | ||
| 318 | + * @return vtn service builder | ||
| 319 | + */ | ||
| 320 | + public Builder subnet(IpPrefix subnet) { | ||
| 321 | + if (subnet == null) { | ||
| 322 | + final String msg = "VTN service subnet is null"; | ||
| 323 | + throw new IllegalArgumentException(msg); | ||
| 324 | + } | ||
| 325 | + this.subnet = subnet; | ||
| 326 | + return this; | ||
| 327 | + } | ||
| 328 | + | ||
| 329 | + /** | ||
| 330 | + * Returns VTN service builder with the supplied subnet. | ||
| 331 | + * | ||
| 332 | + * @param subnet subnet of the service network as a string | ||
| 333 | + * @return vtn service builder | ||
| 334 | + */ | ||
| 335 | + public Builder subnet(String subnet) { | ||
| 336 | + try { | ||
| 337 | + return subnet(IpPrefix.valueOf(subnet)); | ||
| 338 | + } catch (IllegalArgumentException | NullPointerException e) { | ||
| 339 | + final String msg = "Malformed IP prefix string " + subnet + | ||
| 340 | + " for VTN service subnet"; | ||
| 341 | + throw new IllegalArgumentException(msg); | ||
| 342 | + } | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + /** | ||
| 346 | + * Returns VTN service builder with the supplied service IP address. | ||
| 347 | + * | ||
| 348 | + * @param serviceIp service ip address | ||
| 349 | + * @return vtn service builder | ||
| 350 | + */ | ||
| 351 | + public Builder serviceIp(IpAddress serviceIp) { | ||
| 352 | + if (serviceIp == null) { | ||
| 353 | + final String msg = "VTN service IP cannot be null"; | ||
| 354 | + throw new IllegalArgumentException(msg); | ||
| 355 | + } | ||
| 356 | + this.serviceIp = serviceIp; | ||
| 357 | + return this; | ||
| 358 | + } | ||
| 359 | + | ||
| 360 | + /** | ||
| 361 | + * Returns VTN service builder with the supplied service IP address. | ||
| 362 | + * | ||
| 363 | + * @param serviceIp service ip address as a string | ||
| 364 | + * @return vtn service builder | ||
| 365 | + */ | ||
| 366 | + public Builder serviceIp(String serviceIp) { | ||
| 367 | + try { | ||
| 368 | + return serviceIp(IpAddress.valueOf(serviceIp)); | ||
| 369 | + } catch (IllegalArgumentException | NullPointerException e) { | ||
| 370 | + final String msg = "Malformed IP address string " + serviceIp + | ||
| 371 | + " for VTN service IP address"; | ||
| 372 | + throw new IllegalArgumentException(msg); | ||
| 373 | + } | ||
| 374 | + } | ||
| 375 | + | ||
| 376 | + /** | ||
| 377 | + * Returns VTN service builder with the supplied provider services. | ||
| 378 | + * | ||
| 379 | + * @param pServices provider services | ||
| 380 | + * @return vtn service builder | ||
| 381 | + */ | ||
| 382 | + public Builder providerServices(Set<VtnServiceId> pServices) { | ||
| 383 | + if (pServices == null) { | ||
| 384 | + final String msg = "Provider services cannot be null"; | ||
| 385 | + throw new IllegalArgumentException(msg); | ||
| 386 | + } | ||
| 387 | + this.providerServices = pServices; | ||
| 388 | + return this; | ||
| 389 | + } | ||
| 390 | + | ||
| 391 | + /** | ||
| 392 | + * Returns VTN service builder with the supplied tenant services. | ||
| 393 | + * | ||
| 394 | + * @param tServices tenant services | ||
| 395 | + * @return vtn service builder | ||
| 396 | + */ | ||
| 397 | + public Builder tenantServices(Set<VtnServiceId> tServices) { | ||
| 398 | + if (tServices == null) { | ||
| 399 | + final String msg = "Tenant services cannot be null"; | ||
| 400 | + throw new IllegalArgumentException(msg); | ||
| 401 | + } | ||
| 402 | + this.tenantServices = tServices; | ||
| 403 | + return this; | ||
| 404 | + } | ||
| 405 | + } | ||
| 190 | } | 406 | } | ... | ... |
| ... | @@ -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