blob: 3033b3cb0cdc1b4f06f89f70f39a7ca55fcca239 [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
18/**
19 * Basic configuration for network elements, e.g. devices, hosts. Such elements
20 * can have a friendly name, geo-coordinates, logical rack coordinates and
21 * an owner entity.
22 */
23public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> {
24
Thomas Vachuska36008462016-01-07 15:38:20 -080025 protected static final String NAME = "name";
Thomas Vachuska96d55b12015-05-11 08:52:03 -070026
Thomas Vachuska36008462016-01-07 15:38:20 -080027 protected static final String LATITUDE = "latitude";
28 protected static final String LONGITUDE = "longitude";
Thomas Vachuska96d55b12015-05-11 08:52:03 -070029
Thomas Vachuska36008462016-01-07 15:38:20 -080030 protected static final String RACK_ADDRESS = "rackAddress";
31 protected static final String OWNER = "owner";
Thomas Vachuska96d55b12015-05-11 08:52:03 -070032
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070033 protected static final double DEFAULT_COORD = -1.0;
34
Thomas Vachuska96d55b12015-05-11 08:52:03 -070035 /**
36 * Returns friendly label for the element.
37 *
38 * @return friendly label or element id itself if not set
39 */
40 public String name() {
41 return get(NAME, subject.toString());
42 }
43
44 /**
45 * Sets friendly label for the element.
46 *
47 * @param name new friendly label; null to clear
48 * @return self
49 */
50 public BasicElementConfig name(String name) {
51 return (BasicElementConfig) setOrClear(NAME, name);
52 }
53
54 /**
55 * Returns element latitude.
56 *
57 * @return element latitude; -1 if not set
58 */
59 public double latitude() {
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070060 return get(LATITUDE, DEFAULT_COORD);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070061 }
62
63 /**
64 * Sets the element latitude.
65 *
66 * @param latitude new latitude; null to clear
67 * @return self
68 */
69 public BasicElementConfig latitude(Double latitude) {
70 return (BasicElementConfig) setOrClear(LATITUDE, latitude);
71 }
72
73 /**
74 * Returns element latitude.
75 *
76 * @return element latitude; -1 if not set
77 */
78 public double longitude() {
Ayaka Koshibeb1ffb002015-08-04 15:10:03 -070079 return get(LONGITUDE, DEFAULT_COORD);
Thomas Vachuska96d55b12015-05-11 08:52:03 -070080 }
81
82 /**
83 * Sets the element longitude.
84 *
85 * @param longitude new longitude; null to clear
86 * @return self
87 */
88 public BasicElementConfig longitude(Double longitude) {
89 return (BasicElementConfig) setOrClear(LONGITUDE, longitude);
90 }
91
92 /**
93 * Returns the element rack address.
94 *
95 * @return rack address; null if not set
96 */
97 public String rackAddress() {
98 return get(RACK_ADDRESS, null);
99 }
100
101 /**
102 * Sets element rack address.
103 *
104 * @param address new rack address; null to clear
105 * @return self
106 */
107 public BasicElementConfig rackAddress(String address) {
108 return (BasicElementConfig) setOrClear(RACK_ADDRESS, address);
109 }
110
111 /**
112 * Returns owner of the element.
113 *
114 * @return owner or null if not set
115 */
116 public String owner() {
117 return get(OWNER, null);
118 }
119
120 /**
121 * Sets the owner of the element.
122 *
123 * @param owner new owner; null to clear
124 * @return self
125 */
126 public BasicElementConfig owner(String owner) {
127 return (BasicElementConfig) setOrClear(OWNER, owner);
128 }
129
130}