28 #ifndef __ONLP_OID_H__ 29 #define __ONLP_OID_H__ 34 #include <AIM/aim_pvs.h> 36 #include <BigList/biglist.h> 37 #include <cjson/cJSON.h> 60 ONLP_OID_JSON_FLAG_RECURSIVE = (1 << 0),
61 ONLP_OID_JSON_FLAG_UNSUPPORTED_FIELDS = (1 << 1),
62 ONLP_OID_JSON_FLAG_TO_USER_JSON = (1 << 2),
67 ONLP_OID_STATUS_FLAG_PRESENT = (1 << 0),
68 ONLP_OID_STATUS_FLAG_FAILED = (1 << 1),
69 ONLP_OID_STATUS_FLAG_OPERATIONAL = (1 << 2),
70 ONLP_OID_STATUS_FLAG_UNPLUGGED = (1 << 3),
75 ONLP_OID_TYPE_CHASSIS = 1,
76 ONLP_OID_TYPE_MODULE = 2,
77 ONLP_OID_TYPE_THERMAL = 3,
78 ONLP_OID_TYPE_FAN = 4,
79 ONLP_OID_TYPE_PSU = 5,
80 ONLP_OID_TYPE_LED = 6,
81 ONLP_OID_TYPE_SFP = 7,
82 ONLP_OID_TYPE_GENERIC = 8,
87 ONLP_OID_TYPE_FLAG_CHASSIS = (1 << 1),
88 ONLP_OID_TYPE_FLAG_MODULE = (1 << 2),
89 ONLP_OID_TYPE_FLAG_THERMAL = (1 << 3),
90 ONLP_OID_TYPE_FLAG_FAN = (1 << 4),
91 ONLP_OID_TYPE_FLAG_PSU = (1 << 5),
92 ONLP_OID_TYPE_FLAG_LED = (1 << 6),
93 ONLP_OID_TYPE_FLAG_SFP = (1 << 7),
94 ONLP_OID_TYPE_FLAG_GENERIC = (1 << 8),
109 #define ONLP_OID_TYPE_GET(_id) ( ( (_id) >> 24) ) 111 #define ONLP_OID_TYPE_CREATE(_type, _id) ( ( (_type) << 24) | (_id)) 113 #define ONLP_OID_IS_TYPE(_type,_id) (ONLP_OID_TYPE_GET((_id)) == _type) 115 #define ONLP_OID_ID_GET(_id) (_id & 0xFFFFFF) 117 #define ONLP_OID_TYPE_VALIDATE(_type, _oid) \ 119 if(!ONLP_OID_IS_TYPE(_type, _oid)) { \ 120 return ONLP_STATUS_E_PARAM; \ 124 #define ONLP_OID_TYPE_VALIDATE_NR(_type, _oid) \ 126 if(!ONLP_OID_IS_TYPE(_type, _oid)) { \ 132 #define ONLP_OID_TYPE_VALIDATE_GET_ID(_type, _oid, _id) \ 134 ONLP_OID_TYPE_VALIDATE(_type, _oid); \ 135 _id = ONLP_OID_ID_GET(_oid); \ 138 #define ONLP_OID_TYPE_VALIDATE_GET_ID_NR(_type, _oid, _id) \ 140 ONLP_OID_TYPE_VALIDATE_NR(_type, _oid); \ 141 _id = ONLP_OID_ID_GET(_oid); \ 145 #define ONLP_OID_IS_TYPE_FLAGS(_flags, _id) ((_flags & (1 << ONLP_OID_TYPE_GET(_id)))) 148 #define ONLP_OID_IS_TYPE_FLAGSZ(_flags, _id) ((_flags == 0) || ONLP_OID_IS_TYPE_FLAGS(_flags, _id)) 151 #define ONLP_CHASSIS_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_CHASSIS, _id) 153 #define ONLP_THERMAL_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_THERMAL, _id) 155 #define ONLP_FAN_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_FAN, _id) 157 #define ONLP_PSU_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_PSU, _id) 159 #define ONLP_LED_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_LED, _id) 161 #define ONLP_SFP_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_SFP, _id) 163 #define ONLP_MODULE_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_MODULE, _id) 165 #define ONLP_GENERIC_ID_CREATE(_id) ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_GENERIC, _id) 168 #define ONLP_OID_IS_CHASSIS(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_CHASSIS, _id) 170 #define ONLP_OID_CHASSIS_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_CHASSIS, _id) 172 #define ONLP_OID_CHASSIS_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_CHASSIS, _id) 175 #define ONLP_OID_IS_THERMAL(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_THERMAL, _id) 177 #define ONLP_OID_THERMAL_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_THERMAL, _id) 179 #define ONLP_OID_THERMAL_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_THERMAL, _id) 181 #define ONLP_OID_THERMAL_VALIDATE_GET_ID(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID(ONLP_OID_TYPE_THERMAL, _oid, _id) 183 #define ONLP_OID_THERMAL_VALIDATE_GET_ID_NR(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID_NR(ONLP_OID_TYPE_THERMAL, _oid, _id) 186 #define ONLP_OID_IS_FAN(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_FAN, _id) 188 #define ONLP_OID_FAN_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_FAN, _id) 190 #define ONLP_OID_FAN_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_FAN, _id) 192 #define ONLP_OID_FAN_VALIDATE_GET_ID(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID(ONLP_OID_TYPE_FAN, _oid, _id) 194 #define ONLP_OID_FAN_VALIDATE_GET_ID_NR(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID_NR(ONLP_OID_TYPE_FAN, _oid, _id) 197 #define ONLP_OID_IS_PSU(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_PSU, _id) 199 #define ONLP_OID_PSU_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_PSU, _id) 201 #define ONLP_OID_PSU_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_PSU, _id) 203 #define ONLP_OID_PSU_VALIDATE_GET_ID(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID(ONLP_OID_TYPE_PSU, _oid, _id) 205 #define ONLP_OID_PSU_VALIDATE_GET_ID_NR(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID_NR(ONLP_OID_TYPE_PSU, _oid, _id) 208 #define ONLP_OID_IS_LED(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_LED, _id) 210 #define ONLP_OID_LED_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_LED, _id) 212 #define ONLP_OID_LED_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_LED, _id) 214 #define ONLP_OID_LED_VALIDATE_GET_ID(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID(ONLP_OID_TYPE_LED, _oid, _id) 216 #define ONLP_OID_LED_VALIDATE_GET_ID_NR(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID_NR(ONLP_OID_TYPE_LED, _oid, _id) 220 #define ONLP_OID_IS_SFP(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_SFP, _id) 222 #define ONLP_OID_SFP_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_SFP, _id) 224 #define ONLP_OID_SFP_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_SFP, _id) 226 #define ONLP_OID_SFP_VALIDATE_GET_ID(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID(ONLP_OID_TYPE_SFP, _oid, _id) 228 #define ONLP_OID_SFP_VALIDATE_GET_ID_NR(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID_NR(ONLP_OID_TYPE_SFP, _oid, _id) 231 #define ONLP_OID_IS_MODULE(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_MODULE, _id) 233 #define ONLP_OID_MODULE_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_MODULE, _id) 235 #define ONLP_OID_MODULE_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_MODULE, _id) 237 #define ONLP_OID_MODULE_VALIDATE_GET_ID(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID(ONLP_OID_TYPE_MODULE, _oid, _id) 239 #define ONLP_OID_MODULE_VALIDATE_GET_ID_NR(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID_NR(ONLP_OID_TYPE_MODULE, _oid, _id) 242 #define ONLP_OID_IS_GENERIC(_id) ONLP_OID_IS_TYPE(ONLP_OID_TYPE_GENERIC, _id) 244 #define ONLP_OID_GENERIC_VALIDATE(_id) ONLP_OID_TYPE_VALIDATE(ONLP_OID_TYPE_GENERIC, _id) 246 #define ONLP_OID_GENERIC_VALIDATE_NR(_id) ONLP_OID_TYPE_VALIDATE_NR(ONLP_OID_TYPE_GENERIC, _id) 248 #define ONLP_OID_GENERIC_VALIDATE_GET_ID(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID(ONLP_OID_TYPE_GENERIC, _oid, _id) 250 #define ONLP_OID_GENERIC_VALIDATE_GET_ID_NR(_oid, _id) ONLP_OID_TYPE_VALIDATE_GET_ID_NR(ONLP_OID_TYPE_GENERIC, _oid, _id) 254 #define ONLP_OID_ID_VALIDATE_RANGE(_id, _min, _max) \ 255 ( (_id) >= (_min) && (_id) <= (_max)) ? ONLP_STATUS_OK : ONLP_STATUS_E_INVALID 260 #define ONLP_OID_CHASSIS ONLP_OID_TYPE_CREATE(ONLP_OID_TYPE_CHASSIS, 1) 265 #define ONLP_OID_DESC_SIZE 128 271 #define ONLP_OID_TABLE_SIZE 256 277 #define ONLP_OID_TABLE_SIZE_BYTES (sizeof(onlp_oid_t)*ONLP_OID_TABLE_SIZE) 280 #define ONLP_OID_TABLE_COPY(_dst, _src) memcpy(_dst, _src, ONLP_OID_TABLE_SIZE_BYTES) 283 #define ONLP_OID_TABLE_CLEAR(_table) memset(_table, 0, ONLP_OID_TABLE_SIZE_BYTES) 289 #define ONLP_OID_THERMAL_ENTRY(_id, _desc, _parent_type, _parent_id) \ 290 { ONLP_THERMAL_ID_CREATE(_id), _desc, ONLP_OID_TYPE_CREATE(_parent_type, _parent_id) } 351 uint32_t flags, biglist_t** list);
361 uint32_t flags, biglist_t** list);
372 #define ONLP_OID_STATUS_FLAGS_GET(_ptr) \ 373 (((onlp_oid_hdr_t*)_ptr)->status) 376 #define ONLP_OID_STATUS_FLAGS_CLR(_ptr) \ 377 ONLP_OID_STATUS_FLAGS_GET(_ptr) = 0 380 #define ONLP_OID_STATUS_FLAG_GET_VALUE(_ptr, _name) \ 381 AIM_FLAG_GET_VALUE(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name) 384 #define ONLP_OID_STATUS_FLAG_SET_VALUE(_ptr, _name, _value) \ 385 AIM_FLAG_SET_VALUE(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name, _value) 388 #define ONLP_OID_STATUS_FLAG_SET(_ptr, _name) \ 389 AIM_FLAG_SET(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name) 392 #define ONLP_OID_STATUS_FLAG_CLR(_ptr, _name) \ 393 AIM_FLAG_CLR(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name) 396 #define ONLP_OID_STATUS_FLAG_IS_SET(_ptr, _name) \ 397 AIM_FLAG_IS_SET(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name) 400 #define ONLP_OID_STATUS_FLAG_NOT_SET(_ptr, _name) \ 401 AIM_FLAG_NOT_SET(ONLP_OID_STATUS_FLAGS_GET(_ptr), ONLP_OID_STATUS_FLAG_##_name) 404 #define ONLP_OID_PRESENT(_ptr) \ 405 ONLP_OID_STATUS_FLAG_IS_SET(_ptr, PRESENT) 408 #define ONLP_OID_FAILED(_ptr) \ 409 ONLP_OID_STATUS_FLAG_IS_SET(_ptr, FAILED) 417 #define ONLP_OID_TABLE_ITER_EXPR(_table, _oidp, _expr) \ 418 for(_oidp = _table; _oidp < (_table+ONLP_OID_TABLE_SIZE); _oidp++) \ 419 if( (*_oidp) && (_expr) ) 426 #define ONLP_OID_TABLE_ITER(_table, _oidp) ONLP_OID_TABLE_ITER_EXPR(_table, _oidp, 1) 435 #define ONLP_OID_TABLE_ITER_TYPE(_table, _oidp, _type) \ 436 ONLP_OID_TABLE_ITER_EXPR(_table, _oidp, ONLP_OID_IS_TYPE(ONLP_OID_TYPE_##_type, *_oidp)) 545 #define ONLP_OID_JSON_FLAG_VALID(_e) \ 546 (onlp_oid_json_flag_valid((_e))) 566 #define ONLP_OID_STATUS_FLAG_VALID(_e) \ 567 (onlp_oid_status_flag_valid((_e))) 587 #define ONLP_OID_TYPE_VALID(_e) \ 588 (onlp_oid_type_valid((_e))) 608 #define ONLP_OID_TYPE_FLAG_VALID(_e) \ 609 (onlp_oid_type_flag_valid((_e))) onlp Configuration Header
int(* onlp_oid_iterate_f)(onlp_oid_t oid, void *cookie)
Definition: oids.h:330
const char * onlp_oid_json_flag_name(onlp_oid_json_flag_t e)
struct onlp_oid_hdr_s onlp_oid_hdr_t
int onlp_oid_status_flag_value(const char *str, onlp_oid_status_flag_t *e, int substr)
onlp_oid_status_flags_t status
Definition: oids.h:307
int onlp_oid_info_get(onlp_oid_t oid, onlp_oid_hdr_t **info)
Get the information structure for a given OID.
aim_map_si_t onlp_oid_json_flag_desc_map[]
onlp_oid_t onlp_oid_table_t[ONLP_OID_TABLE_SIZE]
Definition: oids.h:274
int onlp_oid_info_to_json(onlp_oid_hdr_t *info, cJSON **cj, uint32_t flags)
OID Info Structure -> JSON.
int onlp_oid_type_flag_value(const char *str, onlp_oid_type_flag_t *e, int substr)
const char * onlp_oid_status_flag_desc(onlp_oid_status_flag_t e)
aim_map_si_t onlp_oid_status_flag_map[]
const char * onlp_oid_type_desc(onlp_oid_type_t e)
int onlp_oid_iterate(onlp_oid_t root, onlp_oid_type_flags_t types, onlp_oid_iterate_f itf, void *cookie)
Iterate over all platform OIDs.
enum onlp_oid_type_flag_e onlp_oid_type_flag_t
aim_map_si_t onlp_oid_json_flag_map[]
int onlp_oid_from_json(cJSON *cj, onlp_oid_hdr_t **hdr, biglist_t **all, uint32_t flags)
JSON -> OID Information structures.
enum onlp_oid_type_e onlp_oid_type_t
uint32_t onlp_oid_t
Definition: oids.h:52
onlp_oid_status_flag_e
Definition: oids.h:66
int onlp_oid_to_user_json(onlp_oid_t oid, cJSON **rv, uint32_t flags)
OID -> JSON.
int onlp_oid_hdr_get(onlp_oid_t oid, onlp_oid_hdr_t *hdr)
Get the OID header for a given OID.
char onlp_oid_desc_t[ONLP_OID_DESC_SIZE]
Definition: oids.h:268
int onlp_oid_hdr_from_json(cJSON *cj, onlp_oid_hdr_t *hdr)
JSON -> OID Header.
int onlp_oid_hdr_get_all(onlp_oid_t root, onlp_oid_type_flags_t types, uint32_t flags, biglist_t **list)
Iterate over all given OID types and return their hdr structures.
int onlp_oid_type_value(const char *str, onlp_oid_type_t *e, int substr)
int onlp_oid_type_valid(onlp_oid_type_t e)
onlp_oid_type_flag_e
Definition: oids.h:86
aim_map_si_t onlp_oid_type_flag_desc_map[]
int onlp_oid_hdr_to_json(onlp_oid_hdr_t *hdr, cJSON **cj, uint32_t flags)
OID Header -> JSON.
int onlp_oid_info_get_all(onlp_oid_t root, onlp_oid_type_flags_t types, uint32_t flags, biglist_t **list)
Iterate over all given OID types and return their info structures.
int onlp_oid_from_str(char *str, onlp_oid_t *roid)
String Represenation -> OID.
aim_map_si_t onlp_oid_type_map[]
int onlp_oid_to_str(onlp_oid_t oid, char *rstr)
aim_map_si_t onlp_oid_status_flag_desc_map[]
int onlp_oid_table_from_json(cJSON *cj, onlp_oid_table_t table)
JSON -> OID Table.
uint32_t onlp_oid_id_t
Definition: oids.h:55
onlp_oid_table_t coids
Definition: oids.h:304
int onlp_oid_to_json(onlp_oid_t oid, cJSON **rv, uint32_t flags)
OID -> User JSON.
aim_map_si_t onlp_oid_type_flag_map[]
aim_map_si_t onlp_oid_type_desc_map[]
enum onlp_oid_status_flag_e onlp_oid_status_flag_t
onlp_oid_t id
Definition: oids.h:298
onlp_oid_json_flag_e
Definition: oids.h:59
int onlp_oid_table_to_json(onlp_oid_table_t table, cJSON **cjp)
OID Table -> JSON.
#define ONLP_OID_TABLE_SIZE
Definition: oids.h:271
const char * onlp_oid_json_flag_desc(onlp_oid_json_flag_t e)
const char * onlp_oid_status_flag_name(onlp_oid_status_flag_t e)
const char * onlp_oid_type_flag_name(onlp_oid_type_flag_t e)
uint32_t onlp_oid_status_flags_t
Definition: oids.h:106
int onlp_oid_json_flag_valid(onlp_oid_json_flag_t e)
onlp_oid_type_e
Definition: oids.h:74
#define ONLP_OID_DESC_SIZE
Definition: oids.h:265
int onlp_oid_json_flag_value(const char *str, onlp_oid_json_flag_t *e, int substr)
onlp_oid_desc_t description
Definition: oids.h:300
onlp_oid_t poid
Definition: oids.h:302
int onlp_oid_json_verify(onlp_oid_t oid)
int onlp_oid_type_flag_valid(onlp_oid_type_flag_t e)
uint32_t onlp_oid_type_flags_t
Definition: oids.h:101
int onlp_oid_status_flag_valid(onlp_oid_status_flag_t e)
int onlp_oid_get_all_free(biglist_t *list)
Free a list returned by onlp_oid_info_get_all() or onlp_oid_hdr_get_all()
int onlp_oid_to_user_str(onlp_oid_t oid, char *rstr)
enum onlp_oid_json_flag_e onlp_oid_json_flag_t
const char * onlp_oid_type_name(onlp_oid_type_t e)
int onlp_oid_is_present(onlp_oid_t *oid)
Return whether an OID is present or not.
const char * onlp_oid_type_flag_desc(onlp_oid_type_flag_t e)