blob: ea40829054b1e8d34b7fb4e64a6801c4e4fcc2e8 [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";
29
30 @Override
31 public boolean isValid() {
32 return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, RACK_ADDRESS, OWNER,
33 TYPE, DRIVER, MANAGEMENT_ADDRESS);
34 }
Thomas Vachuska96d55b12015-05-11 08:52:03 -070035
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 Vachuska138de8b2016-01-11 21:31:38 -080061 return get(DRIVER, null);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070062 }
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
andreafe3308f2015-10-06 15:51:25 -070074 /**
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 Vachuska96d55b12015-05-11 08:52:03 -070093 // TODO: device port meta-data to be configured via BasicPortsConfig
Thomas Vachuska36008462016-01-07 15:38:20 -080094 // TODO: device credentials/keys; in a separate config
Thomas Vachuska96d55b12015-05-11 08:52:03 -070095
96}