blob: 498ce5ce21ca805bc376f9d102111afca702942e [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 */
16package org.onosproject.openstacknode.impl;
17
18import com.google.common.base.MoreObjects;
19import org.onosproject.openstacknode.api.OpenstackPhyInterface;
20
21import java.util.Objects;
22
23import static com.google.common.base.Preconditions.checkArgument;
24
Jian Li789fadb2018-07-10 13:59:47 +090025/**
26 * Implementation class of openstack physical interface.
27 */
Jian Lie6312162018-03-21 21:41:00 +090028public class DefaultOpenstackPhyInterface implements OpenstackPhyInterface {
29
30 private final String network;
31 private final String intf;
32
33 private static final String NOT_NULL_MSG = "% cannot be null";
34
35 /**
36 * A default constructor of Openstack physical interface.
37 *
38 * @param network network that this physical interface connects with
39 * @param intf name of physical interface
40 */
41 protected DefaultOpenstackPhyInterface(String network, String intf) {
42 this.network = network;
43 this.intf = intf;
44 }
45
46 @Override
47 public String network() {
48 return network;
49 }
50
51 @Override
52 public String intf() {
53 return intf;
54 }
55
56 @Override
57 public boolean equals(Object obj) {
58 if (this == obj) {
59 return true;
60 }
61
62 if (obj instanceof DefaultOpenstackPhyInterface) {
63 DefaultOpenstackPhyInterface that = (DefaultOpenstackPhyInterface) obj;
64 return Objects.equals(network, that.network) &&
65 Objects.equals(intf, that.intf);
66 }
67 return false;
68 }
69
70 @Override
71 public int hashCode() {
72 return Objects.hash(network, intf);
73 }
74
75 @Override
76 public String toString() {
77 return MoreObjects.toStringHelper(getClass())
78 .add("network", network)
79 .add("intf", intf)
80 .toString();
81 }
82
83 /**
84 * Returns new builder instance.
85 *
86 * @return openstack physical interface builder
87 */
88 public static Builder builder() {
89 return new Builder();
90 }
91
92 /**
93 * A builder class for openstack physical interface.
94 */
95 public static final class Builder implements OpenstackPhyInterface.Builder {
96
97 private String network;
98 private String intf;
99
100 // private constructor not intended to use from external
101 private Builder() {
102 }
103
104 @Override
105 public OpenstackPhyInterface build() {
106 checkArgument(network != null, NOT_NULL_MSG, "network");
107 checkArgument(intf != null, NOT_NULL_MSG, "intf");
108
109 return new DefaultOpenstackPhyInterface(network, intf);
110 }
111
112 @Override
113 public OpenstackPhyInterface.Builder network(String network) {
114 this.network = network;
115 return this;
116 }
117
118 @Override
119 public OpenstackPhyInterface.Builder intf(String intf) {
120 this.intf = intf;
121 return this;
122 }
123 }
124}