blob: ebcdd823ca0261224254703d29c4207ceed41abe [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 Hunt1e20dae2016-10-28 11:26:26 -070038 return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, UI_TYPE,
39 RACK_ADDRESS, OWNER, TYPE, DRIVER, MANUFACTURER, HW_VERSION,
40 SW_VERSION, SERIAL, MANAGEMENT_ADDRESS, DEVICE_KEY_ID);
Thomas Vachuska36008462016-01-07 15:38:20 -080041 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -070042
43 /**
44 * Returns the device type.
45 *
46 * @return device type override
47 */
48 public Device.Type type() {
Thomas Vachuska2d6c5992016-07-01 12:42:26 +020049 return get(TYPE, null, Device.Type.class);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070050 }
51
52 /**
53 * Sets the device type.
54 *
55 * @param type device type override
56 * @return self
57 */
58 public BasicDeviceConfig type(Device.Type type) {
59 return (BasicDeviceConfig) setOrClear(TYPE, type);
60 }
61
62 /**
63 * Returns the device driver name.
64 *
Andrea Campanellab75b4882016-01-15 15:15:09 -080065 * @return driver name or null if not set
Thomas Vachuska96d55b12015-05-11 08:52:03 -070066 */
67 public String driver() {
Thomas Vachuska138de8b2016-01-11 21:31:38 -080068 return get(DRIVER, null);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070069 }
70
71 /**
72 * Sets the driver name.
73 *
74 * @param driverName new driver name; null to clear
75 * @return self
76 */
Andrea Campanellab75b4882016-01-15 15:15:09 -080077 public BasicDeviceConfig driver(String driverName) {
78 return (BasicDeviceConfig) setOrClear(DRIVER, driverName);
79 }
80
81 /**
82 * Returns the device manufacturer.
83 *
84 * @return manufacturer or null if not set
85 */
86 public String manufacturer() {
87 return get(MANUFACTURER, null);
88 }
89
90 /**
91 * Sets the device manufacturer.
92 *
93 * @param manufacturerName new manufacturer; null to clear
94 * @return self
95 */
96 public BasicDeviceConfig manufacturer(String manufacturerName) {
97 return (BasicDeviceConfig) setOrClear(MANUFACTURER, manufacturerName);
98 }
99
100 /**
101 * Returns the device hardware version.
102 *
103 * @return hardware version or null if not set
104 */
105 public String hwVersion() {
106 return get(HW_VERSION, null);
107 }
108
109 /**
110 * Sets the device hardware version.
111 *
112 * @param hwVersion new hardware version; null to clear
113 * @return self
114 */
115 public BasicDeviceConfig hwVersion(String hwVersion) {
116 return (BasicDeviceConfig) setOrClear(HW_VERSION, hwVersion);
117 }
118
119 /**
120 * Returns the device software version.
121 *
122 * @return software version or null if not set
123 */
124 public String swVersion() {
125 return get(SW_VERSION, null);
126 }
127
128 /**
129 * Sets the device software version.
130 *
131 * @param swVersion new software version; null to clear
132 * @return self
133 */
134 public BasicDeviceConfig swVersion(String swVersion) {
135 return (BasicDeviceConfig) setOrClear(SW_VERSION, swVersion);
136 }
137
138 /**
139 * Returns the device serial number.
140 *
141 * @return serial number or null if not set
142 */
143 public String serial() {
144 return get(SERIAL, null);
145 }
146
147 /**
148 * Sets the device serial number.
149 *
150 * @param serial new serial number; null to clear
151 * @return self
152 */
153 public BasicDeviceConfig serial(String serial) {
154 return (BasicDeviceConfig) setOrClear(SERIAL, serial);
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700155 }
156
andreafe3308f2015-10-06 15:51:25 -0700157 /**
158 * Returns the device management ip (ip:port).
159 *
160 * @return device management address (ip:port) or null if not set
161 */
162 public String managementAddress() {
163 return get(MANAGEMENT_ADDRESS, null);
164 }
165
166 /**
Claudine Chiu5951bda2016-02-19 04:04:52 +0000167 * Sets the device management ip (ip:port).
andreafe3308f2015-10-06 15:51:25 -0700168 *
169 * @param managementAddress new device management address (ip:port); null to clear
170 * @return self
171 */
Andrea Campanellab75b4882016-01-15 15:15:09 -0800172 public BasicDeviceConfig managementAddress(String managementAddress) {
173 return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress);
andreafe3308f2015-10-06 15:51:25 -0700174 }
175
Claudine Chiu5951bda2016-02-19 04:04:52 +0000176 /**
177 * Returns the device key id.
178 *
179 * @return device key id or null if not set
180 */
181 public DeviceKeyId deviceKeyId() {
182 String s = get(DEVICE_KEY_ID, null);
183 return s == null ? null : DeviceKeyId.deviceKeyId(s);
184 }
185
186 /**
187 * Sets the device key id.
188 *
Simon Hunt1e20dae2016-10-28 11:26:26 -0700189 * @param deviceKeyId the new device key id; null to clear
Claudine Chiu5951bda2016-02-19 04:04:52 +0000190 * @return self
191 */
192 public BasicDeviceConfig deviceKeyId(DeviceKeyId deviceKeyId) {
193 return (BasicDeviceConfig) setOrClear(DEVICE_KEY_ID,
Simon Hunt1e20dae2016-10-28 11:26:26 -0700194 deviceKeyId != null ? deviceKeyId.id() : null);
Claudine Chiu5951bda2016-02-19 04:04:52 +0000195 }
196
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700197 // TODO: device port meta-data to be configured via BasicPortsConfig
Thomas Vachuska36008462016-01-07 15:38:20 -0800198 // TODO: device credentials/keys; in a separate config
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700199
200}