blob: 93ca16efe5bfb1c7e1e012bc0ae2d9de55280c13 [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;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070021/**
22 * Basic configuration for network infrastructure devices.
23 */
Thomas Vachuska36008462016-01-07 15:38:20 -080024public final class BasicDeviceConfig extends BasicElementConfig<DeviceId> {
Thomas Vachuska96d55b12015-05-11 08:52:03 -070025
Thomas Vachuska36008462016-01-07 15:38:20 -080026 private static final String TYPE = "type";
27 private static final String DRIVER = "driver";
28 private static final String MANAGEMENT_ADDRESS = "managementAddress";
Andrea Campanellab75b4882016-01-15 15:15:09 -080029 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 Chiu5951bda2016-02-19 04:04:52 +000033 private static final String DEVICE_KEY_ID = "deviceKeyId";
Thomas Vachuska36008462016-01-07 15:38:20 -080034
35 @Override
36 public boolean isValid() {
37 return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER,
Andrea Campanellab75b4882016-01-15 15:15:09 -080038 TYPE, DRIVER, MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL,
Claudine Chiu5951bda2016-02-19 04:04:52 +000039 MANAGEMENT_ADDRESS, DEVICE_KEY_ID);
Thomas Vachuska36008462016-01-07 15:38:20 -080040 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -070041
42 /**
43 * Returns the device type.
44 *
45 * @return device type override
46 */
47 public Device.Type type() {
48 return get(TYPE, Device.Type.SWITCH, Device.Type.class);
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 Campanellab75b4882016-01-15 15:15:09 -080064 * @return driver name or null if not set
Thomas Vachuska96d55b12015-05-11 08:52:03 -070065 */
66 public String driver() {
Thomas Vachuska138de8b2016-01-11 21:31:38 -080067 return get(DRIVER, null);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070068 }
69
70 /**
71 * Sets the driver name.
72 *
73 * @param driverName new driver name; null to clear
74 * @return self
75 */
Andrea Campanellab75b4882016-01-15 15:15:09 -080076 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 Vachuska96d55b12015-05-11 08:52:03 -0700154 }
155
andreafe3308f2015-10-06 15:51:25 -0700156 /**
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 Chiu5951bda2016-02-19 04:04:52 +0000166 * Sets the device management ip (ip:port).
andreafe3308f2015-10-06 15:51:25 -0700167 *
168 * @param managementAddress new device management address (ip:port); null to clear
169 * @return self
170 */
Andrea Campanellab75b4882016-01-15 15:15:09 -0800171 public BasicDeviceConfig managementAddress(String managementAddress) {
172 return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress);
andreafe3308f2015-10-06 15:51:25 -0700173 }
174
Claudine Chiu5951bda2016-02-19 04:04:52 +0000175 /**
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 Vachuska96d55b12015-05-11 08:52:03 -0700196 // TODO: device port meta-data to be configured via BasicPortsConfig
Thomas Vachuska36008462016-01-07 15:38:20 -0800197 // TODO: device credentials/keys; in a separate config
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700198
199}