blob: 77073cbc819b45b3cce2e0c2d942982bb0b89133 [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
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 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;
20
21/**
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";
Thomas Vachuska36008462016-01-07 15:38:20 -080033
34 @Override
35 public boolean isValid() {
36 return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER,
Andrea Campanellab75b4882016-01-15 15:15:09 -080037 TYPE, DRIVER, MANUFACTURER, HW_VERSION, SW_VERSION, SERIAL,
38 MANAGEMENT_ADDRESS);
Thomas Vachuska36008462016-01-07 15:38:20 -080039 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -070040
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 Campanellab75b4882016-01-15 15:15:09 -080063 * @return driver name or null if not set
Thomas Vachuska96d55b12015-05-11 08:52:03 -070064 */
65 public String driver() {
Thomas Vachuska138de8b2016-01-11 21:31:38 -080066 return get(DRIVER, null);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070067 }
68
69 /**
70 * Sets the driver name.
71 *
72 * @param driverName new driver name; null to clear
73 * @return self
74 */
Andrea Campanellab75b4882016-01-15 15:15:09 -080075 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 Vachuska96d55b12015-05-11 08:52:03 -0700153 }
154
andreafe3308f2015-10-06 15:51:25 -0700155 /**
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 Campanellab75b4882016-01-15 15:15:09 -0800170 public BasicDeviceConfig managementAddress(String managementAddress) {
171 return (BasicDeviceConfig) setOrClear(MANAGEMENT_ADDRESS, managementAddress);
andreafe3308f2015-10-06 15:51:25 -0700172 }
173
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700174 // TODO: device port meta-data to be configured via BasicPortsConfig
Thomas Vachuska36008462016-01-07 15:38:20 -0800175 // TODO: device credentials/keys; in a separate config
Thomas Vachuska96d55b12015-05-11 08:52:03 -0700176
177}