Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 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. |
| 20 | * Definitions of annotation keys needs to be here to avoid scattering. |
| 21 | */ |
| 22 | public final class AnnotationKeys { |
| 23 | |
| 24 | // Prohibit instantiation |
| 25 | private AnnotationKeys() {} |
| 26 | |
| 27 | /** |
Sho SHIMIZU | f5c3a2e | 2014-12-02 14:49:39 -0800 | [diff] [blame] | 28 | * Annotation key for instance name. |
| 29 | */ |
| 30 | public static final String NAME = "name"; |
| 31 | |
| 32 | /** |
| 33 | * Annotation key for instance type (e.g. host type). |
| 34 | */ |
| 35 | public static final String TYPE = "type"; |
| 36 | |
| 37 | /** |
| 38 | * Annotation key for latitude (e.g. latitude of device). |
| 39 | */ |
| 40 | public static final String LATITUDE = "latitude"; |
| 41 | |
| 42 | /** |
| 43 | * Annotation key for longitute (e.g. longitude of device). |
| 44 | */ |
| 45 | public static final String LONGITUDE = "longitude"; |
| 46 | |
| 47 | /** |
| 48 | * Annotation key for southbound protocol. |
| 49 | */ |
| 50 | public static final String PROTOCOL = "protocol"; |
| 51 | |
| 52 | /** |
Thomas Vachuska | ca88bb7 | 2015-04-08 19:38:02 -0700 | [diff] [blame] | 53 | * Annotation key for the device driver name. |
| 54 | */ |
| 55 | public static final String DRIVER = "driver"; |
| 56 | |
| 57 | /** |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 58 | * Annotation key for durable links. |
| 59 | */ |
| 60 | public static final String DURABLE = "durable"; |
| 61 | |
| 62 | /** |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 63 | * Annotation key for latency. |
| 64 | */ |
| 65 | public static final String LATENCY = "latency"; |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 66 | |
| 67 | /** |
Toshio Koide | 4b6562b | 2014-11-13 17:20:47 -0800 | [diff] [blame] | 68 | * Annotation key for bandwidth. |
Sho SHIMIZU | 0ce220a | 2015-01-23 15:54:47 -0800 | [diff] [blame] | 69 | * The value for this key is interpreted as Mbps. |
Toshio Koide | 4b6562b | 2014-11-13 17:20:47 -0800 | [diff] [blame] | 70 | */ |
| 71 | public static final String BANDWIDTH = "bandwidth"; |
| 72 | |
| 73 | /** |
| 74 | * Annotation key for the number of optical waves. |
| 75 | */ |
| 76 | public static final String OPTICAL_WAVES = "optical.waves"; |
| 77 | |
| 78 | /** |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 79 | * Annotation key for the port name. |
| 80 | */ |
| 81 | public static final String PORT_NAME = "portName"; |
| 82 | |
Simon Hunt | ab130524 | 2015-05-06 18:07:13 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Annotation key for the router ID. |
| 85 | */ |
| 86 | public static final String ROUTER_ID = "routerId"; |
Thomas Vachuska | b52a014 | 2015-04-21 17:48:15 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
Sho SHIMIZU | 97a64cd | 2014-11-11 16:31:21 -0800 | [diff] [blame] | 89 | * Returns the value annotated object for the specified annotation key. |
| 90 | * The annotated value is expected to be String that can be parsed as double. |
| 91 | * If parsing fails, the returned value will be 1.0. |
| 92 | * |
| 93 | * @param annotated annotated object whose annotated value is obtained |
| 94 | * @param key key of annotation |
| 95 | * @return double value of annotated object for the specified key |
| 96 | */ |
| 97 | public static double getAnnotatedValue(Annotated annotated, String key) { |
| 98 | double value; |
| 99 | try { |
| 100 | value = Double.parseDouble(annotated.annotations().value(key)); |
| 101 | } catch (NumberFormatException e) { |
| 102 | value = 1.0; |
| 103 | } |
| 104 | return value; |
| 105 | } |
Sho SHIMIZU | fe129db | 2014-11-11 14:24:51 -0800 | [diff] [blame] | 106 | } |