Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net; |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * Collection of keys for annotation. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 20 | * <p> |
| 21 | * Number of the annotation keys have been deprecated as the use of annotations |
| 22 | * is being phased out and instead network configuration subsystem is being |
| 23 | * phased-in for majority of model meta-data. |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 24 | */ |
| 25 | public final class AnnotationKeys { |
| 26 | |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 27 | private static final double DEFAULT_VALUE = 1.0; |
| 28 | |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 29 | // Prohibit instantiation |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 30 | private AnnotationKeys() { |
| 31 | } |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 32 | |
| 33 | /** |
Sho SHIMIZU | f5c3a2e | 2014-12-02 14:49:39 -0800 | [diff] [blame] | 34 | * Annotation key for instance name. |
| 35 | */ |
| 36 | public static final String NAME = "name"; |
| 37 | |
| 38 | /** |
| 39 | * Annotation key for instance type (e.g. host type). |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 40 | * |
| 41 | * @deprecated since Cardinal |
Sho SHIMIZU | f5c3a2e | 2014-12-02 14:49:39 -0800 | [diff] [blame] | 42 | */ |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 43 | @Deprecated |
Sho SHIMIZU | f5c3a2e | 2014-12-02 14:49:39 -0800 | [diff] [blame] | 44 | public static final String TYPE = "type"; |
| 45 | |
| 46 | /** |
Simon Hunt | 1e20dae | 2016-10-28 11:26:26 -0700 | [diff] [blame] | 47 | * Annotation key for UI type (the glyph ID for rendering). |
| 48 | */ |
| 49 | public static final String UI_TYPE = "uiType"; |
| 50 | |
| 51 | /** |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 52 | * Annotation key for UI location type of device/host |
| 53 | * (either 'geo' or 'grid'). |
| 54 | */ |
| 55 | public static final String LOC_TYPE = "locType"; |
| 56 | |
| 57 | /** |
| 58 | * Annotation key for latitude (e.g. latitude of device/host |
| 59 | * in a geo-layout). |
Sho SHIMIZU | f5c3a2e | 2014-12-02 14:49:39 -0800 | [diff] [blame] | 60 | */ |
| 61 | public static final String LATITUDE = "latitude"; |
| 62 | |
| 63 | /** |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 64 | * Annotation key for longitude (e.g. longitude of device/host |
| 65 | * in a geo-layout). |
Sho SHIMIZU | f5c3a2e | 2014-12-02 14:49:39 -0800 | [diff] [blame] | 66 | */ |
| 67 | public static final String LONGITUDE = "longitude"; |
| 68 | |
| 69 | /** |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 70 | * Annotation key for grid-Y (e.g. y-coordinate of device/host |
| 71 | * in a grid-layout). |
| 72 | */ |
| 73 | public static final String GRID_Y = "gridY"; |
| 74 | |
| 75 | /** |
| 76 | * Annotation key for grid-X (e.g. x-coordinate of device/host |
| 77 | * in a grid-layout). |
| 78 | */ |
| 79 | public static final String GRID_X = "gridX"; |
| 80 | |
| 81 | /** |
Sho SHIMIZU | f5c3a2e | 2014-12-02 14:49:39 -0800 | [diff] [blame] | 82 | * Annotation key for southbound protocol. |
| 83 | */ |
| 84 | public static final String PROTOCOL = "protocol"; |
| 85 | |
| 86 | /** |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 87 | * Annotation key for the device driver name. |
| 88 | */ |
| 89 | public static final String DRIVER = "driver"; |
| 90 | |
| 91 | /** |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 92 | * Annotation key for durable links. |
| 93 | */ |
| 94 | public static final String DURABLE = "durable"; |
| 95 | |
| 96 | /** |
Thomas Vachuska | 41fe1ec | 2015-12-03 23:17:02 -0800 | [diff] [blame] | 97 | * Annotation key for link metric; used by |
| 98 | * {@link org.onosproject.net.topology.MetricLinkWeight} function. |
| 99 | */ |
| 100 | public static final String METRIC = "metric"; |
| 101 | |
| 102 | /** |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 103 | * Annotation key for latency. |
Yuta HIGUCHI | 5f3f3c4 | 2017-02-02 20:49:35 -0800 | [diff] [blame] | 104 | * The value of this key is expected to be latency in microsecond. |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 105 | */ |
| 106 | public static final String LATENCY = "latency"; |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 107 | |
| 108 | /** |
Toshio Koide | 4b6562b | 2014-11-13 17:20:47 -0800 | [diff] [blame] | 109 | * Annotation key for bandwidth. |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 110 | * The value for this key is interpreted as Mbps. |
Toshio Koide | 4b6562b | 2014-11-13 17:20:47 -0800 | [diff] [blame] | 111 | */ |
| 112 | public static final String BANDWIDTH = "bandwidth"; |
| 113 | |
| 114 | /** |
| 115 | * Annotation key for the number of optical waves. |
| 116 | */ |
| 117 | public static final String OPTICAL_WAVES = "optical.waves"; |
| 118 | |
| 119 | /** |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 120 | * Annotation key for the port name. |
| 121 | */ |
| 122 | public static final String PORT_NAME = "portName"; |
| 123 | |
Simon Hunt | ab130524 | 2015-05-06 18:07:13 -0700 | [diff] [blame] | 124 | /** |
lishuai | 4ee4204 | 2015-11-30 17:19:21 +0800 | [diff] [blame] | 125 | * Annotation key for the port mac. |
| 126 | */ |
| 127 | public static final String PORT_MAC = "portMac"; |
| 128 | |
| 129 | /** |
Simon Hunt | ab130524 | 2015-05-06 18:07:13 -0700 | [diff] [blame] | 130 | * Annotation key for the router ID. |
| 131 | */ |
| 132 | public static final String ROUTER_ID = "routerId"; |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 133 | |
Thomas Vachuska | 41fe1ec | 2015-12-03 23:17:02 -0800 | [diff] [blame] | 134 | /** |
| 135 | * Annotation key for the static lambda. |
| 136 | */ |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 137 | public static final String STATIC_LAMBDA = "staticLambda"; |
| 138 | |
Thomas Vachuska | 41fe1ec | 2015-12-03 23:17:02 -0800 | [diff] [blame] | 139 | /** |
| 140 | * Annotation key for the static port. |
| 141 | */ |
Marc De Leenheer | 723f553 | 2015-06-03 20:16:17 -0700 | [diff] [blame] | 142 | public static final String STATIC_PORT = "staticPort"; |
| 143 | |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 144 | /** |
Ayaka Koshibe | 0891129 | 2015-08-05 15:07:08 -0700 | [diff] [blame] | 145 | * Annotation key for device location. |
| 146 | */ |
| 147 | public static final String RACK_ADDRESS = "rackAddress"; |
| 148 | |
| 149 | /** |
| 150 | * Annotation key for device owner. |
| 151 | */ |
| 152 | public static final String OWNER = "owner"; |
| 153 | |
| 154 | /** |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 155 | * Annotation key for the channel id. |
| 156 | */ |
| 157 | public static final String CHANNEL_ID = "channelId"; |
| 158 | |
| 159 | /** |
| 160 | * Annotation key for the management address. |
| 161 | */ |
| 162 | public static final String MANAGEMENT_ADDRESS = "managementAddress"; |
| 163 | |
| 164 | /** |
Brian Stanke | 9bf8d7c | 2016-02-11 10:17:23 -0500 | [diff] [blame] | 165 | * Annotation key for the username. |
| 166 | */ |
| 167 | public static final String USERNAME = "username"; |
| 168 | |
| 169 | /** |
| 170 | * Annotation key for the password. |
| 171 | */ |
| 172 | public static final String PASSWORD = "password"; |
| 173 | |
| 174 | /** |
Yuta HIGUCHI | 76609cd | 2016-09-16 15:25:13 -0700 | [diff] [blame] | 175 | * Link annotation key to express that a Link |
| 176 | * is backed by underlying protection mechanism. |
| 177 | */ |
| 178 | // value is undefined at the moment, only using key existence |
| 179 | public static final String PROTECTED = "protected"; |
| 180 | |
| 181 | /** |
Michele Santuari | c372c22 | 2017-01-12 09:41:25 +0100 | [diff] [blame] | 182 | * Annotation key for REST server identifier. |
| 183 | */ |
| 184 | public static final String REST_SERVER = "restServer"; |
| 185 | |
| 186 | /** |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 187 | * Annotation key for the sshkey. |
| 188 | */ |
| 189 | public static final String SSHKEY = "sshkey"; |
| 190 | |
| 191 | /** |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 192 | * Returns the value annotated object for the specified annotation key. |
| 193 | * The annotated value is expected to be String that can be parsed as double. |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 194 | * If parsing fails, the returned value will be {@value DEFAULT_VALUE}. |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 195 | * |
| 196 | * @param annotated annotated object whose annotated value is obtained |
andrea | fe3308f | 2015-10-06 15:51:25 -0700 | [diff] [blame] | 197 | * @param key key of annotation |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 198 | * @return double value of annotated object for the specified key |
| 199 | */ |
| 200 | public static double getAnnotatedValue(Annotated annotated, String key) { |
| 201 | double value; |
| 202 | try { |
| 203 | value = Double.parseDouble(annotated.annotations().value(key)); |
| 204 | } catch (NumberFormatException e) { |
Simon Hunt | bc30e68 | 2017-02-15 18:39:23 -0800 | [diff] [blame] | 205 | value = DEFAULT_VALUE; |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 206 | } |
| 207 | return value; |
| 208 | } |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 209 | } |