blob: 32df86e40e073548307e1047cbb306c640d97cae [file] [log] [blame]
Jian Lie6312162018-03-21 21:41:00 +09001/*
2 * Copyright 2018-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 */
Jian Li2a2d26c2018-10-08 11:29:31 +090016package org.onosproject.openstacknode.api;
Jian Lie6312162018-03-21 21:41:00 +090017
18import com.google.common.base.MoreObjects;
Jian Lie6312162018-03-21 21:41:00 +090019
20import java.util.Objects;
21
22import static com.google.common.base.Preconditions.checkArgument;
23
Jian Li789fadb2018-07-10 13:59:47 +090024/**
25 * Implementation class of openstack physical interface.
26 */
Jian Lie6312162018-03-21 21:41:00 +090027public class DefaultOpenstackPhyInterface implements OpenstackPhyInterface {
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 Openstack physical interface.
36 *
37 * @param network network that this physical interface connects with
38 * @param intf name of physical interface
39 */
40 protected DefaultOpenstackPhyInterface(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 obj) {
57 if (this == obj) {
58 return true;
59 }
60
61 if (obj instanceof DefaultOpenstackPhyInterface) {
62 DefaultOpenstackPhyInterface that = (DefaultOpenstackPhyInterface) obj;
63 return Objects.equals(network, that.network) &&
64 Objects.equals(intf, that.intf);
65 }
66 return false;
67 }
68
69 @Override
70 public int hashCode() {
71 return Objects.hash(network, intf);
72 }
73
74 @Override
75 public String toString() {
76 return MoreObjects.toStringHelper(getClass())
77 .add("network", network)
78 .add("intf", intf)
79 .toString();
80 }
81
82 /**
83 * Returns new builder instance.
84 *
85 * @return openstack physical interface builder
86 */
87 public static Builder builder() {
88 return new Builder();
89 }
90
91 /**
92 * A builder class for openstack physical interface.
93 */
94 public static final class Builder implements OpenstackPhyInterface.Builder {
95
96 private String network;
97 private String intf;
98
99 // private constructor not intended to use from external
100 private Builder() {
101 }
102
103 @Override
104 public OpenstackPhyInterface build() {
105 checkArgument(network != null, NOT_NULL_MSG, "network");
106 checkArgument(intf != null, NOT_NULL_MSG, "intf");
107
108 return new DefaultOpenstackPhyInterface(network, intf);
109 }
110
111 @Override
112 public OpenstackPhyInterface.Builder network(String network) {
113 this.network = network;
114 return this;
115 }
116
117 @Override
118 public OpenstackPhyInterface.Builder intf(String intf) {
119 this.intf = intf;
120 return this;
121 }
122 }
123}