blob: 1a7ffd611b8eadfdc952a52ce89a4739624605c7 [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska96d55b12015-05-11 08:52:03 -07003 *
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 */
Thomas Vachuska4998caa2015-08-26 13:28:38 -070016package org.onosproject.net.config.basics;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070017
18import org.onosproject.net.Device;
19import org.onosproject.net.DeviceId;
Claudine Chiu5951bda2016-02-19 04:04:52 +000020import org.onosproject.net.key.DeviceKeyId;
Simon Hunt1e20dae2016-10-28 11:26:26 -070021
Jordan Halterman83949a12017-06-21 10:35:38 -070022import static com.google.common.base.Preconditions.checkArgument;
23
Thomas Vachuska96d55b12015-05-11 08:52:03 -070024/**
25 * Basic configuration for network infrastructure devices.
26 */
Thomas Vachuska36008462016-01-07 15:38:20 -080027public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
Thomas Vachuska96d55b12015-05-11 08:52:03 -070028
Thomas Vachuska36008462016-01-07 15:38:20 -080029 private static final String TYPE = "type";
30 private static final String DRIVER = "driver";
31 private static final String MANAGEMENT_ADDRESS = "managementAddress";
Carmelo Cascone3977ea42019-02-28 13:43:42 -080032 private static final String PIPECONF = "pipeconf";
Andrea Campanellab75b4882016-01-15 15:15:09 -080033 private static final String MANUFACTURER = "manufacturer";
34 private static final String HW_VERSION = "hwVersion";
35 private static final String SW_VERSION = "swVersion";
36 private static final String SERIAL = "serial";
Claudine Chiu5951bda2016-02-19 04:04:52 +000037 private static final String DEVICE_KEY_ID = "deviceKeyId";
Thomas Vachuska36008462016-01-07 15:38:20 -080038
Jordan Halterman83949a12017-06-21 10:35:38 -070039 private static final int DRIVER_MAX_LENGTH = 256;
40 private static final int MANUFACTURER_MAX_LENGTH = 256;
41 private static final int HW_VERSION_MAX_LENGTH = 256;
42 private static final int SW_VERSION_MAX_LENGTH = 256;
43 private static final int SERIAL_MAX_LENGTH = 256;
44 private static final int MANAGEMENT_ADDRESS_MAX_LENGTH = 1024;
Carmelo Cascone3977ea42019-02-28 13:43:42 -080045 private static final int PIPECONF_MAX_LENGTH = 256;
Jordan Halterman83949a12017-06-21 10:35:38 -070046
Thomas Vachuska36008462016-01-07 15:38:20 -080047 @Override
48 public boolean isValid() {
Jordan Halterman83949a12017-06-21 10:35:38 -070049 // Validate type/DeviceKeyId
50 type();
51 deviceKeyId();
52
53 return super.isValid()
54 && hasOnlyFields(ALLOWED, NAME, LOC_TYPE, LATITUDE, LONGITUDE,
Thomas Vachuska0d933862018-04-06 00:29:30 -070055 GRID_Y, GRID_X, UI_TYPE, RACK_ADDRESS, OWNER, TYPE, DRIVER, ROLES,
Simon Huntbc30e682017-02-15 18:39:23 -080056 MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL,
Carmelo Cascone3977ea42019-02-28 13:43:42 -080057 MANAGEMENT_ADDRESS, PIPECONF, DEVICE_KEY_ID)
Jordan Halterman83949a12017-06-21 10:35:38 -070058 && isValidLength(DRIVER, DRIVER_MAX_LENGTH)
59 && isValidLength(MANUFACTURER, MANUFACTURER_MAX_LENGTH)
60 && isValidLength(HW_VERSION, MANUFACTURER_MAX_LENGTH)
61 && isValidLength(SW_VERSION, MANUFACTURER_MAX_LENGTH)
62 && isValidLength(SERIAL, MANUFACTURER_MAX_LENGTH)
Carmelo Cascone3977ea42019-02-28 13:43:42 -080063 && isValidLength(MANAGEMENT_ADDRESS, MANAGEMENT_ADDRESS_MAX_LENGTH)
64 && isValidLength(PIPECONF, PIPECONF_MAX_LENGTH);
Thomas Vachuska36008462016-01-07 15:38:20 -080065 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -070066
67 /**
68 * Returns the device type.
69 *
70 * @return device type override
71 */
72 public Device.Type type() {
Thomas Vachuska2d6c5992016-07-01 12:42:26 +020073 return get(TYPE, null, Device.Type.class);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070074 }
75
76 /**
77 * Sets the device type.
78 *
79 * @param type device type override
80 * @return self
81 */
82 public BasicDeviceConfig type(Device.Type type) {
83 return (BasicDeviceConfig) setOrClear(TYPE, type);
84 }
85
86 /**
87 * Returns the device driver name.
88 *
Andrea Campanellab75b4882016-01-15 15:15:09 -080089 * @return driver name or null if not set
Thomas Vachuska96d55b12015-05-11 08:52:03 -070090 */
91 public String driver() {
Thomas Vachuska138de8b2016-01-11 21:31:38 -080092 return get(DRIVER, null);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070093 }
94
95 /**
96 * Sets the driver name.
97 *
98 * @param driverName new driver name; null to clear
99 * @return self
100 */
Andrea Campanellab75b4882016-01-15 15:15:09 -0800101 public BasicDeviceConfig driver(String driverName) {
Jordan Halterman83949a12017-06-21 10:35:38 -0700102 checkArgument(driverName.length() <= DRIVER_MAX_LENGTH,
103 "driver exceeds maximum length " + DRIVER_MAX_LENGTH);
Andrea Campanellab75b4882016-01-15 15:15:09 -0800104 return (BasicDeviceConfig) setOrClear(DRIVER, driverName);
105 }
106
107 /**
108 * Returns the device manufacturer.
109 *
110 * @return manufacturer or null if not set
111 */
112 public String manufacturer() {
113 return get(MANUFACTURER, null);
114 }
115
116 /**
117 * Sets the device manufacturer.
118 *
119 * @param manufacturerName new manufacturer; null to clear
120 * @return self
121 */
122 public BasicDeviceConfig manufacturer(String manufacturerName) {
Jordan Halterman83949a12017-06-21 10:35:38 -0700123 checkArgument(manufacturerName.length() <= MANUFACTURER_MAX_LENGTH,
124 "manufacturer exceeds maximum length " + MANUFACTURER_MAX_LENGTH);
Andrea Campanellab75b4882016-01-15 15:15:09 -0800125 return (BasicDeviceConfig) setOrClear(MANUFACTURER, manufacturerName);
126 }
127
128 /**
129 * Returns the device hardware version.
130 *
131 * @return hardware version or null if not set
132 */
133 public String hwVersion() {
134 return get(HW_VERSION, null);
135 }
136
137 /**
138 * Sets the device hardware version.
139 *
140 * @param hwVersion new hardware version; null to clear
141 * @return self
142 */
143 public BasicDeviceConfig hwVersion(String hwVersion) {
Jordan Halterman83949a12017-06-21 10:35:38 -0700144 checkArgument(hwVersion.length() <= HW_VERSION_MAX_LENGTH,
145 "hwVersion exceeds maximum length " + HW_VERSION_MAX_LENGTH);
Andrea Campanellab75b4882016-01-15 15:15:09 -0800146 return (BasicDeviceConfig) setOrClear(HW_VERSION, hwVersion);
147 }
148
149 /**
150 * Returns the device software version.
151 *
152 * @return software version or null if not set
153 */
154 public String swVersion() {
155 return get(SW_VERSION, null);
156 }
157
158 /**
159 * Sets the device software version.
160 *
161 * @param swVersion new software version; null to clear
162 * @return self
163 */
164 public BasicDeviceConfig swVersion(String swVersion) {
Jordan Halterman83949a12017-06-21 10:35:38 -0700165 checkArgument(swVersion.length() <= SW_VERSION_MAX_LENGTH,
166 "swVersion exceeds maximum length " + SW_VERSION_MAX_LENGTH);
Andrea Campanellab75b4882016-01-15 15:15:09 -0800167 return (BasicDeviceConfig) setOrClear(SW_VERSION, swVersion);
168 }
169
170 /**
171 * Returns the device serial number.
172 *
173 * @return serial number or null if not set
174 */
175 public String serial() {
176 return get(SERIAL, null);
177 }
178
179 /**
180 * Sets the device serial number.
181 *
182 * @param serial new serial number; null to clear
183 * @return self
184 */
185 public BasicDeviceConfig serial(String serial) {
Jordan Halterman83949a12017-06-21 10:35:38 -0700186 checkArgument(serial.length() <= SERIAL_MAX_LENGTH,
187 "serial exceeds maximum length " + SERIAL_MAX_LENGTH);
Andrea Campanellab75b4882016-01-15 15:15:09 -0800188 return (BasicDeviceConfig) setOrClear(SERIAL, serial);
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700189 }
190
andreafe3308f2015-10-06 15:51:25 -0700191 /**
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800192 * Returns the device management address (e.g, "ip:port" or full URI
193 * string).
andreafe3308f2015-10-06 15:51:25 -0700194 *
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800195 * @return device management address or null if not set
andreafe3308f2015-10-06 15:51:25 -0700196 */
197 public String managementAddress() {
198 return get(MANAGEMENT_ADDRESS, null);
199 }
200
201 /**
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800202 * Returns the device pipeconf.
203 *
204 * @return device pipeconf or null if not set
205 */
206 public String pipeconf() {
207 return get(PIPECONF, null);
208 }
209
210 /**
Claudine Chiu5951bda2016-02-19 04:04:52 +0000211 * Sets the device management ip (ip:port).
andreafe3308f2015-10-06 15:51:25 -0700212 *
213 * @param managementAddress new device management address (ip:port); null to clear
214 * @return self
215 */
Andrea Campanellab75b4882016-01-15 15:15:09 -0800216 public BasicDeviceConfig managementAddress(String managementAddress) {
Jordan Halterman83949a12017-06-21 10:35:38 -0700217 checkArgument(managementAddress.length() <= MANAGEMENT_ADDRESS_MAX_LENGTH,
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800218 "managementAddress exceeds maximum length " + MANAGEMENT_ADDRESS_MAX_LENGTH);
Andrea Campanellab75b4882016-01-15 15:15:09 -0800219 return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress);
andreafe3308f2015-10-06 15:51:25 -0700220 }
221
Claudine Chiu5951bda2016-02-19 04:04:52 +0000222 /**
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800223 * Sets the device pipeconf.
224 *
225 * @param pipeconf new device pipeconf
226 * @return self
227 */
228 public BasicDeviceConfig pipeconf(String pipeconf) {
229 checkArgument(pipeconf.length() <= PIPECONF_MAX_LENGTH,
230 "pipeconf exceeds maximum length " + MANAGEMENT_ADDRESS_MAX_LENGTH);
231 return (BasicDeviceConfig) setOrClear(PIPECONF, pipeconf);
232 }
233
234 /**
Claudine Chiu5951bda2016-02-19 04:04:52 +0000235 * Returns the device key id.
236 *
237 * @return device key id or null if not set
238 */
239 public DeviceKeyId deviceKeyId() {
240 String s = get(DEVICE_KEY_ID, null);
241 return s == null ? null : DeviceKeyId.deviceKeyId(s);
242 }
243
244 /**
245 * Sets the device key id.
246 *
Simon Hunt1e20dae2016-10-28 11:26:26 -0700247 * @param deviceKeyId the new device key id; null to clear
Claudine Chiu5951bda2016-02-19 04:04:52 +0000248 * @return self
249 */
250 public BasicDeviceConfig deviceKeyId(DeviceKeyId deviceKeyId) {
251 return (BasicDeviceConfig) setOrClear(DEVICE_KEY_ID,
Simon Hunt1e20dae2016-10-28 11:26:26 -0700252 deviceKeyId != null ? deviceKeyId.id() : null);
Claudine Chiu5951bda2016-02-19 04:04:52 +0000253 }
254
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700255 // TODO: device port meta-data to be configured via BasicPortsConfig
Thomas Vachuska36008462016-01-07 15:38:20 -0800256 // TODO: device credentials/keys; in a separate config
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700257
258}