Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 16 | package org.onosproject.net.config.basics; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 17 | |
| 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 | */ |
| 23 | public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> { |
| 24 | |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 25 | protected static final String NAME = "name"; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 26 | |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 27 | protected static final String LATITUDE = "latitude"; |
| 28 | protected static final String LONGITUDE = "longitude"; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 29 | |
Thomas Vachuska | 3600846 | 2016-01-07 15:38:20 -0800 | [diff] [blame] | 30 | protected static final String RACK_ADDRESS = "rackAddress"; |
| 31 | protected static final String OWNER = "owner"; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 32 | |
Ayaka Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 33 | protected static final double DEFAULT_COORD = -1.0; |
| 34 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 35 | /** |
| 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 Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 60 | return get(LATITUDE, DEFAULT_COORD); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 61 | } |
| 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 Koshibe | b1ffb00 | 2015-08-04 15:10:03 -0700 | [diff] [blame] | 79 | return get(LONGITUDE, DEFAULT_COORD); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 80 | } |
| 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 | } |