Open Kilda Java Documentation
Address.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.testing.service.traffexam.model;
17 
18 import com.fasterxml.jackson.annotation.JsonCreator;
19 import com.fasterxml.jackson.annotation.JsonProperty;
20 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
22 import lombok.Value;
23 
24 import java.net.Inet4Address;
25 import java.net.UnknownHostException;
26 import java.util.InputMismatchException;
27 import java.util.UUID;
28 
29 @Value
30 public class Address extends HostResource {
31 
32  @JsonSerialize(using = VlanJsonSerializer.class)
33  private Vlan vlan;
34  private Inet4Address address;
35  private int prefix;
36 
37  public Address(Inet4Address address, int prefix, Vlan vlan) {
38  super(null);
39  this.address = address;
40  this.prefix = prefix;
41  this.vlan = vlan;
42  }
43 
44  @JsonCreator
45  public Address(
46  @JsonProperty("idnr") UUID id,
47  @JsonProperty("address") String address,
48  @JsonProperty("prefix") int prefix,
49  @JsonProperty("vlan")
50  @JsonDeserialize(using = VlanJsonDeserializer.class) Vlan vlan) {
51  super(id);
52 
53  try {
54  this.address = (Inet4Address) Inet4Address.getByName(address);
55  } catch (UnknownHostException e) {
56  throw new InputMismatchException(String.format("Invalid value for \"address\" property: %s", address));
57  }
58 
59  this.prefix = prefix;
60  this.vlan = vlan;
61  }
62 }
Address(Inet4Address address, int prefix, Vlan vlan)
Definition: Address.java:37
Address( @JsonProperty("idnr") UUID id, @JsonProperty("address") String address, @JsonProperty("prefix") int prefix, @JsonProperty("vlan") @JsonDeserialize(using=VlanJsonDeserializer.class) Vlan vlan)
Definition: Address.java:45