Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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; |
| 20 | |
| 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"; |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 33 | |
| 34 | @Override |
| 35 | public boolean isValid() { |
| 36 | return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER, |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 37 | TYPE, DRIVER, MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL, |
| 38 | MANAGEMENT_ADDRESS); |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 39 | } |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Returns the device type. |
| 43 | * |
| 44 | * @return device type override |
| 45 | */ |
| 46 | public Device.Type type() { |
| 47 | return get(TYPE, Device.Type.SWITCH, Device.Type.class); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Sets the device type. |
| 52 | * |
| 53 | * @param type device type override |
| 54 | * @return self |
| 55 | */ |
| 56 | public BasicDeviceConfig type(Device.Type type) { |
| 57 | return (BasicDeviceConfig) setOrClear(TYPE, type); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the device driver name. |
| 62 | * |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 63 | * @return driver name or null if not set |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 64 | */ |
| 65 | public String driver() { |
Thomas Vachuska | 138de8b | 2016-01-11 21:31:38 -0800 | [diff] [blame] | 66 | return get(DRIVER, null); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Sets the driver name. |
| 71 | * |
| 72 | * @param driverName new driver name; null to clear |
| 73 | * @return self |
| 74 | */ |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 75 | public BasicDeviceConfig driver(String driverName) { |
| 76 | return (BasicDeviceConfig) setOrClear(DRIVER, driverName); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the device manufacturer. |
| 81 | * |
| 82 | * @return manufacturer or null if not set |
| 83 | */ |
| 84 | public String manufacturer() { |
| 85 | return get(MANUFACTURER, null); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Sets the device manufacturer. |
| 90 | * |
| 91 | * @param manufacturerName new manufacturer; null to clear |
| 92 | * @return self |
| 93 | */ |
| 94 | public BasicDeviceConfig manufacturer(String manufacturerName) { |
| 95 | return (BasicDeviceConfig) setOrClear(MANUFACTURER, manufacturerName); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Returns the device hardware version. |
| 100 | * |
| 101 | * @return hardware version or null if not set |
| 102 | */ |
| 103 | public String hwVersion() { |
| 104 | return get(HW_VERSION, null); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Sets the device hardware version. |
| 109 | * |
| 110 | * @param hwVersion new hardware version; null to clear |
| 111 | * @return self |
| 112 | */ |
| 113 | public BasicDeviceConfig hwVersion(String hwVersion) { |
| 114 | return (BasicDeviceConfig) setOrClear(HW_VERSION, hwVersion); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Returns the device software version. |
| 119 | * |
| 120 | * @return software version or null if not set |
| 121 | */ |
| 122 | public String swVersion() { |
| 123 | return get(SW_VERSION, null); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Sets the device software version. |
| 128 | * |
| 129 | * @param swVersion new software version; null to clear |
| 130 | * @return self |
| 131 | */ |
| 132 | public BasicDeviceConfig swVersion(String swVersion) { |
| 133 | return (BasicDeviceConfig) setOrClear(SW_VERSION, swVersion); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Returns the device serial number. |
| 138 | * |
| 139 | * @return serial number or null if not set |
| 140 | */ |
| 141 | public String serial() { |
| 142 | return get(SERIAL, null); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Sets the device serial number. |
| 147 | * |
| 148 | * @param serial new serial number; null to clear |
| 149 | * @return self |
| 150 | */ |
| 151 | public BasicDeviceConfig serial(String serial) { |
| 152 | return (BasicDeviceConfig) setOrClear(SERIAL, serial); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 153 | } |
| 154 | |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Returns the device management ip (ip:port). |
| 157 | * |
| 158 | * @return device management address (ip:port) or null if not set |
| 159 | */ |
| 160 | public String managementAddress() { |
| 161 | return get(MANAGEMENT_ADDRESS, null); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Sets the driver name. |
| 166 | * |
| 167 | * @param managementAddress new device management address (ip:port); null to clear |
| 168 | * @return self |
| 169 | */ |
Andrea Campanella | b75b488 | 2016-01-15 15:15:09 -0800 | [diff] [blame] | 170 | public BasicDeviceConfig managementAddress(String managementAddress) { |
| 171 | return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress); |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 174 | // TODO: device port meta-data to be configured via BasicPortsConfig |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 175 | // TODO: device credentials/keys; in a separate config |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 176 | |
| 177 | } |