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"; |
| 29 | |
| 30 | @Override |
| 31 | public boolean isValid() { |
| 32 | return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER, |
| 33 | TYPE, DRIVER, MANAGEMENT_ADDRESS); |
| 34 | } |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Returns the device type. |
| 38 | * |
| 39 | * @return device type override |
| 40 | */ |
| 41 | public Device.Type type() { |
| 42 | return get(TYPE, Device.Type.SWITCH, Device.Type.class); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Sets the device type. |
| 47 | * |
| 48 | * @param type device type override |
| 49 | * @return self |
| 50 | */ |
| 51 | public BasicDeviceConfig type(Device.Type type) { |
| 52 | return (BasicDeviceConfig) setOrClear(TYPE, type); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the device driver name. |
| 57 | * |
| 58 | * @return driver name of null if not set |
| 59 | */ |
| 60 | public String driver() { |
Thomas Vachuska | 138de8b | 2016-01-11 21:31:38 -0800 | [diff] [blame] | 61 | return get(DRIVER, null); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Sets the driver name. |
| 66 | * |
| 67 | * @param driverName new driver name; null to clear |
| 68 | * @return self |
| 69 | */ |
| 70 | public BasicElementConfig driver(String driverName) { |
| 71 | return (BasicElementConfig) setOrClear(DRIVER, driverName); |
| 72 | } |
| 73 | |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 74 | /** |
| 75 | * Returns the device management ip (ip:port). |
| 76 | * |
| 77 | * @return device management address (ip:port) or null if not set |
| 78 | */ |
| 79 | public String managementAddress() { |
| 80 | return get(MANAGEMENT_ADDRESS, null); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Sets the driver name. |
| 85 | * |
| 86 | * @param managementAddress new device management address (ip:port); null to clear |
| 87 | * @return self |
| 88 | */ |
| 89 | public BasicElementConfig managementAddress(String managementAddress) { |
| 90 | return (BasicElementConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress); |
| 91 | } |
| 92 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 93 | // TODO: device port meta-data to be configured via BasicPortsConfig |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 94 | // TODO: device credentials/keys; in a separate config |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 95 | |
| 96 | } |