blob: 1cae8f266e5552148335b84d8dbf5105c008d451 [file] [log] [blame]
Jian Li4eb0cf42020-12-19 04:01:49 +09001/*
2 * Copyright 2020-present Open Networking Foundation
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 */
16package org.onosproject.kubevirtnode.api;
17
18import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
21
22import static com.google.common.base.Preconditions.checkArgument;
23
24/**
25 * Implementation class of kubevirt physical interface.
26 */
27public class DefaultKubevirtPhyInterface implements KubevirtPhyInterface {
28
29 private final String network;
30 private final String intf;
31
32 private static final String NOT_NULL_MSG = "% cannot be null";
33
34 /**
35 * A default constructor of kubevirt physical interface.
36 *
37 * @param network network that this physical interface connects with
38 * @param intf name of physical interface
39 */
40 protected DefaultKubevirtPhyInterface(String network, String intf) {
41 this.network = network;
42 this.intf = intf;
43 }
44
45 @Override
46 public String network() {
47 return network;
48 }
49
50 @Override
51 public String intf() {
52 return intf;
53 }
54
55 @Override
56 public boolean equals(Object o) {
57 if (this == o) {
58 return true;
59 }
60 if (o == null || getClass() != o.getClass()) {
61 return false;
62 }
63 DefaultKubevirtPhyInterface that = (DefaultKubevirtPhyInterface) o;
64 return network.equals(that.network) &&
65 intf.equals(that.intf);
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(network, intf);
71 }
72
73 @Override
74 public String toString() {
75 return MoreObjects.toStringHelper(this)
76 .add("network", network)
77 .add("intf", intf)
78 .toString();
79 }
80
81 /**
82 * Returns new builder instance.
83 *
84 * @return kubevirt physical interface builder
85 */
86 public static Builder builder() {
87 return new Builder();
88 }
89
90 public static final class Builder implements KubevirtPhyInterface.Builder {
91
92 private String network;
93 private String intf;
94
95 // private constructor not intended to use from external
96 private Builder() {
97 }
98
99 @Override
100 public KubevirtPhyInterface build() {
101 checkArgument(network != null, NOT_NULL_MSG, "network");
102 checkArgument(intf != null, NOT_NULL_MSG, "intf");
103
104 return new DefaultKubevirtPhyInterface(network, intf);
105 }
106
107 @Override
108 public KubevirtPhyInterface.Builder network(String network) {
109 this.network = network;
110 return this;
111 }
112
113 @Override
114 public KubevirtPhyInterface.Builder intf(String intf) {
115 this.intf = intf;
116 return this;
117 }
118 }
119}