blob: c4428765e165cca4fe83b61209bcebfbcbbef973 [file] [log] [blame]
Daniel Parkd02d7bd2018-08-23 23:04:31 +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.DpdkInterface;
20
21import java.util.Objects;
22
23import static com.google.common.base.Preconditions.checkArgument;
24
25
26/**
27 * Implementation of dpdk interface.
28 */
29public final class DefaultDpdkInterface implements DpdkInterface {
30 private final String deviceName;
31 private final String intf;
32 private final String pciAddress;
33 private final Type type;
34 private final Long mtu;
35 private static final String NOT_NULL_MSG = "% cannot be null";
36
37 private DefaultDpdkInterface(String deviceName,
38 String intf,
39 String pciAddress,
40 Type type,
41 Long mtu) {
42 this.deviceName = deviceName;
43 this.intf = intf;
44 this.pciAddress = pciAddress;
45 this.type = type;
46 this.mtu = mtu;
47 }
48
49 /**
50 * Returns the name of the device where the dpdk interface is.
51 *
52 * @return device name
53 */
54 @Override
55 public String deviceName() {
56 return deviceName;
57 }
58
59 /**
60 * Returns the name of the dpdk interface.
61 *
62 * @return dpdk interface name
63 */
64 @Override
65 public String intf() {
66 return intf;
67 }
68
69 /**
70 * Returns the dpdk device arguments of this dpdk port.
71 * ex) "0000:85:00.1"
72 *
73 * @return pci address
74 */
75 @Override
76 public String pciAddress() {
77 return pciAddress;
78 }
79
80 /**
81 * Returns the dpdk interface type.
82 *
83 * @return type
84 */
85 @Override
86 public Type type() {
87 return type;
88 }
89
90 /**
91 * Returns the mtu size.
92 *
93 * @return mtu
94 */
95 @Override
96 public Long mtu() {
97 return mtu;
98 }
99
100 @Override
101 public String toString() {
102 return MoreObjects.toStringHelper(getClass())
103 .add("deviceName", deviceName)
104 .add("intf", intf)
105 .add("pciAddress", pciAddress)
106 .add("type", type)
107 .add("mtu", mtu)
108 .toString();
109 }
110
111 @Override
112 public int hashCode() {
113 return Objects.hash(deviceName,
114 intf,
115 pciAddress,
116 type,
117 mtu);
118 }
119
120 @Override
121 public boolean equals(Object o) {
122 if (this == o) {
123 return true;
124 }
125 if (!(o instanceof DefaultDpdkInterface)) {
126 return false;
127 }
128 DefaultDpdkInterface that = (DefaultDpdkInterface) o;
129 return Objects.equals(deviceName, that.deviceName) &&
130 Objects.equals(intf, that.intf) &&
131 Objects.equals(pciAddress, that.pciAddress) &&
132 type == that.type &&
133 Objects.equals(mtu, that.mtu);
134 }
135
136 /**
137 * Returns new builder instance.
138 *
139 * @return dpdk interface builder instance.
140 */
141 public static Builder builder() {
142 return new Builder();
143 }
144
145 /**
146 * Builder of dpdk interface instance.
147 */
148 public static final class Builder implements DpdkInterface.Builder {
149 private String deviceName;
150 private String intf;
151 private String pciAddress;
152 private Type type;
153 private Long mtu = DpdkInterface.DEFAULT_MTU_SIZE;
154
155 private Builder() {
156 }
157
158 @Override
159 public DpdkInterface build() {
160 checkArgument(deviceName != null, NOT_NULL_MSG, "deviceName");
161 checkArgument(intf != null, NOT_NULL_MSG, "intf");
162 checkArgument(pciAddress != null, NOT_NULL_MSG, "pciAddress");
163 checkArgument(type != null, NOT_NULL_MSG, "type");
164
165 return new DefaultDpdkInterface(deviceName,
166 intf,
167 pciAddress,
168 type,
169 mtu);
170 }
171
172 @Override
173 public Builder deviceName(String deviceName) {
174 this.deviceName = deviceName;
175 return this;
176 }
177
178 @Override
179 public Builder intf(String name) {
180 this.intf = name;
181 return this;
182 }
183
184 @Override
185 public Builder pciAddress(String pciAddress) {
186 this.pciAddress = pciAddress;
187 return this;
188 }
189
190 @Override
191 public Builder type(Type type) {
192 this.type = type;
193 return this;
194 }
195
196 @Override
197 public Builder mtu(Long mtu) {
198 this.mtu = mtu;
199 return this;
200 }
201 }
202}