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; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 21 | /** |
| 22 | * Basic configuration for network infrastructure devices. |
| 23 | */ |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 24 | public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 25 | |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 26 | private static final String TYPE = "type"; |
| 27 | private static final String DRIVER = "driver"; |
| 28 | private static final String MANAGEMENT_ADDRESS = "managementAddress"; |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 29 | private static final String MANUFACTURER = "manufacturer"; |
| 30 | private static final String HW_VERSION = "hwVersion"; |
| 31 | private static final String SW_VERSION = "swVersion"; |
| 32 | private static final String SERIAL = "serial"; |
Claudine Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 33 | private static final String DEVICE_KEY_ID = "deviceKeyId"; |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 34 | |
| 35 | @Override |
| 36 | public boolean isValid() { |
| 37 | return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER, |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 38 | TYPE, DRIVER, MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL, |
Claudine Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 39 | MANAGEMENT_ADDRESS, DEVICE_KEY_ID); |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 40 | } |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Returns the device type. |
| 44 | * |
| 45 | * @return device type override |
| 46 | */ |
| 47 | public Device.Type type() { |
Thomas Vachuska | 2d6c599 | 2016-07-01 12:42:26 +0200 | [diff] [blame] | 48 | return get(TYPE, null, Device.Type.class); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Sets the device type. |
| 53 | * |
| 54 | * @param type device type override |
| 55 | * @return self |
| 56 | */ |
| 57 | public BasicDeviceConfig type(Device.Type type) { |
| 58 | return (BasicDeviceConfig) setOrClear(TYPE, type); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the device driver name. |
| 63 | * |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 64 | * @return driver name or null if not set |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 65 | */ |
| 66 | public String driver() { |
Thomas Vachuska | 138de8b | 2016-01-11 21:31:38 -0800 | [diff] [blame] | 67 | return get(DRIVER, null); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Sets the driver name. |
| 72 | * |
| 73 | * @param driverName new driver name; null to clear |
| 74 | * @return self |
| 75 | */ |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 76 | public BasicDeviceConfig driver(String driverName) { |
| 77 | return (BasicDeviceConfig) setOrClear(DRIVER, driverName); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns the device manufacturer. |
| 82 | * |
| 83 | * @return manufacturer or null if not set |
| 84 | */ |
| 85 | public String manufacturer() { |
| 86 | return get(MANUFACTURER, null); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Sets the device manufacturer. |
| 91 | * |
| 92 | * @param manufacturerName new manufacturer; null to clear |
| 93 | * @return self |
| 94 | */ |
| 95 | public BasicDeviceConfig manufacturer(String manufacturerName) { |
| 96 | return (BasicDeviceConfig) setOrClear(MANUFACTURER, manufacturerName); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Returns the device hardware version. |
| 101 | * |
| 102 | * @return hardware version or null if not set |
| 103 | */ |
| 104 | public String hwVersion() { |
| 105 | return get(HW_VERSION, null); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Sets the device hardware version. |
| 110 | * |
| 111 | * @param hwVersion new hardware version; null to clear |
| 112 | * @return self |
| 113 | */ |
| 114 | public BasicDeviceConfig hwVersion(String hwVersion) { |
| 115 | return (BasicDeviceConfig) setOrClear(HW_VERSION, hwVersion); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Returns the device software version. |
| 120 | * |
| 121 | * @return software version or null if not set |
| 122 | */ |
| 123 | public String swVersion() { |
| 124 | return get(SW_VERSION, null); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Sets the device software version. |
| 129 | * |
| 130 | * @param swVersion new software version; null to clear |
| 131 | * @return self |
| 132 | */ |
| 133 | public BasicDeviceConfig swVersion(String swVersion) { |
| 134 | return (BasicDeviceConfig) setOrClear(SW_VERSION, swVersion); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Returns the device serial number. |
| 139 | * |
| 140 | * @return serial number or null if not set |
| 141 | */ |
| 142 | public String serial() { |
| 143 | return get(SERIAL, null); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Sets the device serial number. |
| 148 | * |
| 149 | * @param serial new serial number; null to clear |
| 150 | * @return self |
| 151 | */ |
| 152 | public BasicDeviceConfig serial(String serial) { |
| 153 | return (BasicDeviceConfig) setOrClear(SERIAL, serial); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 154 | } |
| 155 | |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 156 | /** |
| 157 | * Returns the device management ip (ip:port). |
| 158 | * |
| 159 | * @return device management address (ip:port) or null if not set |
| 160 | */ |
| 161 | public String managementAddress() { |
| 162 | return get(MANAGEMENT_ADDRESS, null); |
| 163 | } |
| 164 | |
| 165 | /** |
Claudine Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 166 | * Sets the device management ip (ip:port). |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 167 | * |
| 168 | * @param managementAddress new device management address (ip:port); null to clear |
| 169 | * @return self |
| 170 | */ |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 171 | public BasicDeviceConfig managementAddress(String managementAddress) { |
| 172 | return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress); |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Claudine Chiu | 5951bda | 2016-02-19 04:04:52 +0000 | [diff] [blame] | 175 | /** |
| 176 | * Returns the device key id. |
| 177 | * |
| 178 | * @return device key id or null if not set |
| 179 | */ |
| 180 | public DeviceKeyId deviceKeyId() { |
| 181 | String s = get(DEVICE_KEY_ID, null); |
| 182 | return s == null ? null : DeviceKeyId.deviceKeyId(s); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Sets the device key id. |
| 187 | * |
| 188 | * @param deviceKeyId new device key id; null to clear |
| 189 | * @return self |
| 190 | */ |
| 191 | public BasicDeviceConfig deviceKeyId(DeviceKeyId deviceKeyId) { |
| 192 | return (BasicDeviceConfig) setOrClear(DEVICE_KEY_ID, |
| 193 | deviceKeyId != null ? deviceKeyId.id() : null); |
| 194 | } |
| 195 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 196 | // TODO: device port meta-data to be configured via BasicPortsConfig |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 197 | // TODO: device credentials/keys; in a separate config |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 198 | |
| 199 | } |