blob: 6fa169ef6f48d70ede7fabda8c041a30e673f79f [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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
Thomas Vachuska96d55b12015-05-11 08:52:03 -070022/**
23 * Basic configuration for network infrastructure devices.
24 */
Thomas Vachuska36008462016-01-07 15:38:20 -080025public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
Thomas Vachuska96d55b12015-05-11 08:52:03 -070026
Thomas Vachuska36008462016-01-07 15:38:20 -080027 private static final String TYPE = "type";
28 private static final String DRIVER = "driver";
29 private static final String MANAGEMENT_ADDRESS = "managementAddress";
Andrea Campanellab75b4882016-01-15 15:15:09 -080030 private static final String MANUFACTURER = "manufacturer";
31 private static final String HW_VERSION = "hwVersion";
32 private static final String SW_VERSION = "swVersion";
33 private static final String SERIAL = "serial";
Claudine Chiu5951bda2016-02-19 04:04:52 +000034 private static final String DEVICE_KEY_ID = "deviceKeyId";
Thomas Vachuska36008462016-01-07 15:38:20 -080035
36 @Override
37 public boolean isValid() {
Simon Huntbc30e682017-02-15 18:39:23 -080038 return hasOnlyFields(ALLOWED, NAME, LOC_TYPE, LATITUDE, LONGITUDE,
39 GRID_Y, GRID_X, UI_TYPE, RACK_ADDRESS, OWNER, TYPE, DRIVER,
40 MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL,
41 MANAGEMENT_ADDRESS, DEVICE_KEY_ID);
Thomas Vachuska36008462016-01-07 15:38:20 -080042 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -070043
44 /**
45 * Returns the device type.
46 *
47 * @return device type override
48 */
49 public Device.Type type() {
Thomas Vachuska2d6c5992016-07-01 12:42:26 +020050 return get(TYPE, null, Device.Type.class);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070051 }
52
53 /**
54 * Sets the device type.
55 *
56 * @param type device type override
57 * @return self
58 */
59 public BasicDeviceConfig type(Device.Type type) {
60 return (BasicDeviceConfig) setOrClear(TYPE, type);
61 }
62
63 /**
64 * Returns the device driver name.
65 *
Andrea Campanellab75b4882016-01-15 15:15:09 -080066 * @return driver name or null if not set
Thomas Vachuska96d55b12015-05-11 08:52:03 -070067 */
68 public String driver() {
Thomas Vachuska138de8b2016-01-11 21:31:38 -080069 return get(DRIVER, null);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070070 }
71
72 /**
73 * Sets the driver name.
74 *
75 * @param driverName new driver name; null to clear
76 * @return self
77 */
Andrea Campanellab75b4882016-01-15 15:15:09 -080078 public BasicDeviceConfig driver(String driverName) {
79 return (BasicDeviceConfig) setOrClear(DRIVER, driverName);
80 }
81
82 /**
83 * Returns the device manufacturer.
84 *
85 * @return manufacturer or null if not set
86 */
87 public String manufacturer() {
88 return get(MANUFACTURER, null);
89 }
90
91 /**
92 * Sets the device manufacturer.
93 *
94 * @param manufacturerName new manufacturer; null to clear
95 * @return self
96 */
97 public BasicDeviceConfig manufacturer(String manufacturerName) {
98 return (BasicDeviceConfig) setOrClear(MANUFACTURER, manufacturerName);
99 }
100
101 /**
102 * Returns the device hardware version.
103 *
104 * @return hardware version or null if not set
105 */
106 public String hwVersion() {
107 return get(HW_VERSION, null);
108 }
109
110 /**
111 * Sets the device hardware version.
112 *
113 * @param hwVersion new hardware version; null to clear
114 * @return self
115 */
116 public BasicDeviceConfig hwVersion(String hwVersion) {
117 return (BasicDeviceConfig) setOrClear(HW_VERSION, hwVersion);
118 }
119
120 /**
121 * Returns the device software version.
122 *
123 * @return software version or null if not set
124 */
125 public String swVersion() {
126 return get(SW_VERSION, null);
127 }
128
129 /**
130 * Sets the device software version.
131 *
132 * @param swVersion new software version; null to clear
133 * @return self
134 */
135 public BasicDeviceConfig swVersion(String swVersion) {
136 return (BasicDeviceConfig) setOrClear(SW_VERSION, swVersion);
137 }
138
139 /**
140 * Returns the device serial number.
141 *
142 * @return serial number or null if not set
143 */
144 public String serial() {
145 return get(SERIAL, null);
146 }
147
148 /**
149 * Sets the device serial number.
150 *
151 * @param serial new serial number; null to clear
152 * @return self
153 */
154 public BasicDeviceConfig serial(String serial) {
155 return (BasicDeviceConfig) setOrClear(SERIAL, serial);
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700156 }
157
andreafe3308f2015-10-06 15:51:25 -0700158 /**
159 * Returns the device management ip (ip:port).
160 *
161 * @return device management address (ip:port) or null if not set
162 */
163 public String managementAddress() {
164 return get(MANAGEMENT_ADDRESS, null);
165 }
166
167 /**
Claudine Chiu5951bda2016-02-19 04:04:52 +0000168 * Sets the device management ip (ip:port).
andreafe3308f2015-10-06 15:51:25 -0700169 *
170 * @param managementAddress new device management address (ip:port); null to clear
171 * @return self
172 */
Andrea Campanellab75b4882016-01-15 15:15:09 -0800173 public BasicDeviceConfig managementAddress(String managementAddress) {
174 return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress);
andreafe3308f2015-10-06 15:51:25 -0700175 }
176
Claudine Chiu5951bda2016-02-19 04:04:52 +0000177 /**
178 * Returns the device key id.
179 *
180 * @return device key id or null if not set
181 */
182 public DeviceKeyId deviceKeyId() {
183 String s = get(DEVICE_KEY_ID, null);
184 return s == null ? null : DeviceKeyId.deviceKeyId(s);
185 }
186
187 /**
188 * Sets the device key id.
189 *
Simon Hunt1e20dae2016-10-28 11:26:26 -0700190 * @param deviceKeyId the new device key id; null to clear
Claudine Chiu5951bda2016-02-19 04:04:52 +0000191 * @return self
192 */
193 public BasicDeviceConfig deviceKeyId(DeviceKeyId deviceKeyId) {
194 return (BasicDeviceConfig) setOrClear(DEVICE_KEY_ID,
Simon Hunt1e20dae2016-10-28 11:26:26 -0700195 deviceKeyId != null ? deviceKeyId.id() : null);
Claudine Chiu5951bda2016-02-19 04:04:52 +0000196 }
197
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700198 // TODO: device port meta-data to be configured via BasicPortsConfig
Thomas Vachuska36008462016-01-07 15:38:20 -0800199 // TODO: device credentials/keys; in a separate config
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700200
201}