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