Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 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 | */ |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 16 | package org.onosproject.net.config.basics; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.net.Device; |
| 19 | import org.onosproject.net.DeviceId; |
Claudine Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 20 | import org.onosproject.net.key.DeviceKeyId; |
Simon Hunt | 1e20dae | 2016-10-28 11:26:26 -0700 | [diff] [blame] | 21 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Basic configuration for network infrastructure devices. |
| 24 | */ |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 25 | public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 26 | |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 27 | private static final String TYPE = "type"; |
| 28 | private static final String DRIVER = "driver"; |
| 29 | private static final String MANAGEMENT_ADDRESS = "managementAddress"; |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 30 | 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 Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 34 | private static final String DEVICE_KEY_ID = "deviceKeyId"; |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 35 | |
| 36 | @Override |
| 37 | public boolean isValid() { |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 38 | 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 Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 42 | } |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Returns the device type. |
| 46 | * |
| 47 | * @return device type override |
| 48 | */ |
| 49 | public Device.Type type() { |
Thomas Vachuska | 2d6c599 | 2016-07-01 12:42:26 +0200 | [diff] [blame] | 50 | return get(TYPE, null, Device.Type.class); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 51 | } |
| 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 Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 66 | * @return driver name or null if not set |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 67 | */ |
| 68 | public String driver() { |
Thomas Vachuska | 138de8b | 2016-01-11 21:31:38 -0800 | [diff] [blame] | 69 | return get(DRIVER, null); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Sets the driver name. |
| 74 | * |
| 75 | * @param driverName new driver name; null to clear |
| 76 | * @return self |
| 77 | */ |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 78 | 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 Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 156 | } |
| 157 | |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 158 | /** |
| 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 Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 168 | * Sets the device management ip (ip:port). |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 169 | * |
| 170 | * @param managementAddress new device management address (ip:port); null to clear |
| 171 | * @return self |
| 172 | */ |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 173 | public BasicDeviceConfig managementAddress(String managementAddress) { |
| 174 | return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress); |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Claudine Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 177 | /** |
| 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 Hunt | 1e20dae | 2016-10-28 11:26:26 -0700 | [diff] [blame] | 190 | * @param deviceKeyId the new device key id; null to clear |
Claudine Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 191 | * @return self |
| 192 | */ |
| 193 | public BasicDeviceConfig deviceKeyId(DeviceKeyId deviceKeyId) { |
| 194 | return (BasicDeviceConfig) setOrClear(DEVICE_KEY_ID, |
Simon Hunt | 1e20dae | 2016-10-28 11:26:26 -0700 | [diff] [blame] | 195 | deviceKeyId != null ? deviceKeyId.id() : null); |
Claudine Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 196 | } |
| 197 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 198 | // TODO: device port meta-data to be configured via BasicPortsConfig |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 199 | // TODO: device credentials/keys; in a separate config |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 200 | |
| 201 | } |