TR181-XPON  1.4.0
TR-181 PON manager.
dm_info.c
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2022 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or
8 ** without modification, are permitted provided that the following
9 ** conditions are met:
10 **
11 ** 1. Redistributions of source code must retain the above copyright
12 ** notice, this list of conditions and the following disclaimer.
13 **
14 ** 2. Redistributions in binary form must reproduce the above
15 ** copyright notice, this list of conditions and the following
16 ** disclaimer in the documentation and/or other materials provided
17 ** with the distribution.
18 **
19 ** Subject to the terms and conditions of this license, each
20 ** copyright holder and contributor hereby grants to those receiving
21 ** rights under this license a perpetual, worldwide, non-exclusive,
22 ** no-charge, royalty-free, irrevocable (except for failure to
23 ** satisfy the conditions of this license) patent license to make,
24 ** have made, use, offer to sell, sell, import, and otherwise
25 ** transfer this software, where such license applies only to those
26 ** patent claims, already acquired or hereafter acquired, licensable
27 ** by such copyright holder or contributor that are necessarily
28 ** infringed by:
29 **
30 ** (a) their Contribution(s) (the licensed copyrights of copyright
31 ** holders and non-copyrightable additions of contributors, in
32 ** source or binary form) alone; or
33 **
34 ** (b) combination of their Contribution(s) with the work of
35 ** authorship to which such Contribution(s) was added by such
36 ** copyright holder or contributor, if, at the time the Contribution
37 ** is added, such addition causes such combination to be necessarily
38 ** infringed. The patent license shall not apply to any other
39 ** combinations which include the Contribution.
40 **
41 ** Except as expressly stated above, no rights or licenses from any
42 ** copyright holder or contributor is granted under this license,
43 ** whether expressly, by implication, estoppel or otherwise.
44 **
45 ** DISCLAIMER
46 **
47 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
48 ** CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
49 ** INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
50 ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
51 ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
52 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
55 ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
56 ** AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58 ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 ** POSSIBILITY OF SUCH DAMAGE.
60 **
61 ****************************************************************************/
62 
63 /* Related header */
64 #include "dm_info.h"
65 
66 /* System headers */
67 #include <string.h> /* strncmp() */
68 
69 /* Other libraries' headers */
70 #include <amxc/amxc.h>
71 #include <amxc/amxc_macros.h>
72 
73 /* Own headers */
74 #include "xpon_trace.h"
75 
76 #ifndef ARRAY_SIZE
77 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
78 #endif
79 
80 static const param_info_t ONU_PARAMS[] = {
81  { .name = ENABLE_PARAM, .type = AMXC_VAR_ID_BOOL },
82  { .name = "Version", .type = AMXC_VAR_ID_CSTRING },
83  { .name = "EquipmentID", .type = AMXC_VAR_ID_CSTRING },
84  { .name = "UsePPTPEthernetUNIasIFtoNonOmciDomain", .type = AMXC_VAR_ID_BOOL }
85 };
86 
88  { .name = "Version", .type = AMXC_VAR_ID_CSTRING },
89  { .name = "IsCommitted", .type = AMXC_VAR_ID_BOOL },
90  { .name = "IsActive", .type = AMXC_VAR_ID_BOOL },
91  { .name = "IsValid", .type = AMXC_VAR_ID_BOOL }
92 };
93 
95  { .name = "Enable", .type = AMXC_VAR_ID_BOOL },
96  { .name = "Status", .type = AMXC_VAR_ID_CSTRING },
97  { .name = "LastChange", .type = AMXC_VAR_ID_UINT32 },
98  { .name = "ANIs", .type = AMXC_VAR_ID_CSV_STRING },
99  { .name = "InterdomainID", .type = AMXC_VAR_ID_CSTRING },
100  { .name = "InterdomainName", .type = AMXC_VAR_ID_CSTRING },
101 };
102 
103 static const param_info_t ANI_PARAMS[] = {
104  { .name = ENABLE_PARAM, .type = AMXC_VAR_ID_BOOL },
105  { .name = "Status", .type = AMXC_VAR_ID_CSTRING },
106  { .name = "LastChange", .type = AMXC_VAR_ID_UINT32 },
107  { .name = "PONMode", .type = AMXC_VAR_ID_CSTRING }
108 };
109 
110 static const param_info_t GEM_PORT_PARAMS[] = {
111  { .name = "Direction", .type = AMXC_VAR_ID_CSTRING },
112  { .name = "PortType", .type = AMXC_VAR_ID_CSTRING }
113 };
114 
116  { .name = "Identifier", .type = AMXC_VAR_ID_UINT32 },
117  { .name = "VendorName", .type = AMXC_VAR_ID_CSTRING },
118  { .name = "VendorPartNumber", .type = AMXC_VAR_ID_CSTRING },
119  { .name = "VendorRevision", .type = AMXC_VAR_ID_CSTRING },
120  { .name = "PONMode", .type = AMXC_VAR_ID_CSTRING },
121  { .name = "Connector", .type = AMXC_VAR_ID_CSTRING },
122  { .name = "NominalBitRateDownstream", .type = AMXC_VAR_ID_UINT32 },
123  { .name = "NominalBitRateUpstream", .type = AMXC_VAR_ID_UINT32 },
124  { .name = "RxPower", .type = AMXC_VAR_ID_INT32 },
125  { .name = "TxPower", .type = AMXC_VAR_ID_INT32 },
126  { .name = "Voltage", .type = AMXC_VAR_ID_UINT32 },
127  { .name = "Bias", .type = AMXC_VAR_ID_UINT32 },
128  { .name = "Temperature", .type = AMXC_VAR_ID_INT32 }
129 };
130 
132  { .name = "ONUState", .type = AMXC_VAR_ID_CSTRING },
133  { .name = "VendorID", .type = AMXC_VAR_ID_CSTRING },
134  { .name = "SerialNumber", .type = AMXC_VAR_ID_CSTRING },
135  { .name = "ONUID", .type = AMXC_VAR_ID_UINT32 }
136 };
137 
139  { .name = "Password", .type = AMXC_VAR_ID_CSTRING },
140  { .name = "HexadecimalPassword", .type = AMXC_VAR_ID_BOOL }
141 };
142 
144  { .name = "SignalFail", .type = AMXC_VAR_ID_UINT32 },
145  { .name = "SignalDegrade", .type = AMXC_VAR_ID_UINT32 }
146 };
147 
148 static const param_info_t TC_ALARMS_PARAMS[] = {
149  { .name = "LOS", .type = AMXC_VAR_ID_BOOL },
150  { .name = "LOF", .type = AMXC_VAR_ID_BOOL },
151  { .name = "SF", .type = AMXC_VAR_ID_BOOL },
152  { .name = "SD", .type = AMXC_VAR_ID_BOOL },
153  { .name = "LCDG", .type = AMXC_VAR_ID_BOOL },
154  { .name = "TF", .type = AMXC_VAR_ID_BOOL },
155  { .name = "SUF", .type = AMXC_VAR_ID_BOOL },
156  { .name = "MEM", .type = AMXC_VAR_ID_BOOL },
157  { .name = "DACT", .type = AMXC_VAR_ID_BOOL },
158  { .name = "DIS", .type = AMXC_VAR_ID_BOOL },
159  { .name = "MIS", .type = AMXC_VAR_ID_BOOL },
160  { .name = "PEE", .type = AMXC_VAR_ID_BOOL },
161  { .name = "RDI", .type = AMXC_VAR_ID_BOOL },
162  { .name = "LODS", .type = AMXC_VAR_ID_BOOL },
163  { .name = "ROGUE", .type = AMXC_VAR_ID_BOOL }
164 };
165 
172  {
173  .id = obj_id_onu,
174  .name = "ONU",
175  .generic_path = "XPON.ONU",
176  .key_name = NAME_PARAM,
177  .singletons = NULL,
178  .templates = "SoftwareImage,EthernetUNI,ANI",
179  .params = ONU_PARAMS,
180  .n_params = ARRAY_SIZE(ONU_PARAMS),
181  .has_rw_enable = true
182  },
183  {
184  .id = obj_id_software_image,
185  .name = "SoftwareImage",
186  .generic_path = "XPON.ONU.x.SoftwareImage",
187  .key_name = "ID",
188  .key_max_value = 1,
189  .singletons = NULL,
190  .templates = NULL,
191  .params = SOFTWARE_IMAGE_PARAMS,
192  .n_params = ARRAY_SIZE(SOFTWARE_IMAGE_PARAMS),
193  .has_rw_enable = false
194  },
195  {
196  .id = obj_id_ethernet_uni,
197  .name = "EthernetUNI",
198  .generic_path = "XPON.ONU.x.EthernetUNI",
199  .key_name = NAME_PARAM,
200  .singletons = NULL,
201  .templates = NULL,
202  .params = ETHERNET_UNI_PARAMS,
203  .n_params = ARRAY_SIZE(ETHERNET_UNI_PARAMS),
204  .has_rw_enable = false
205  },
206  {
207  .id = obj_id_ani,
208  .name = "ANI",
209  .generic_path = "XPON.ONU.x.ANI",
210  .key_name = NAME_PARAM,
211  .singletons = "TC.ONUActivation,TC.PerformanceThresholds,TC.Alarms",
212  .templates = "TC.GEM.Port,Transceiver",
213  .params = ANI_PARAMS,
214  .n_params = ARRAY_SIZE(ANI_PARAMS),
215  .has_rw_enable = true
216  },
217  {
218  .id = obj_id_gem_port,
219  .name = "GEMPort",
220  .generic_path = "XPON.ONU.x.ANI.x.TC.GEM.Port",
221  .key_name = "PortID",
222  .key_max_value = 65534,
223  .singletons = NULL,
224  .templates = NULL,
225  .params = GEM_PORT_PARAMS,
226  .n_params = ARRAY_SIZE(GEM_PORT_PARAMS),
227  .has_rw_enable = false
228  },
229  {
230  .id = obj_id_transceiver,
231  .name = "Transceiver",
232  .generic_path = "XPON.ONU.x.ANI.x.Transceiver",
233  .key_name = "ID",
234  .key_max_value = 1,
235  .singletons = NULL,
236  .templates = NULL,
237  .params = TRANSCEIVER_PARAMS,
238  .n_params = ARRAY_SIZE(TRANSCEIVER_PARAMS),
239  .has_rw_enable = false
240  },
241  {
243  .name = "ONUActivation",
244  .generic_path = "XPON.ONU.x.ANI.x.TC.ONUActivation",
245  .key_name = NULL,
246  .singletons = NULL,
247  .templates = NULL,
248  .params = ONU_ACTIVATION_PARAMS,
249  .n_params = ARRAY_SIZE(ONU_ACTIVATION_PARAMS),
250  .has_rw_enable = false
251  },
252  {
254  .name = "Authentication",
255  .generic_path = "XPON.ONU.x.ANI.x.TC.Authentication",
256  .key_name = NULL,
257  .singletons = NULL,
258  .templates = NULL,
259  .params = AUTHENTICATION_PARAMS,
260  .n_params = ARRAY_SIZE(AUTHENTICATION_PARAMS),
261  .has_rw_enable = false
262  },
263  {
265  .name = "PerformanceThresholds",
266  .generic_path = "XPON.ONU.x.ANI.x.TC.PerformanceThresholds",
267  .key_name = NULL,
268  .singletons = NULL,
269  .templates = NULL,
272  .has_rw_enable = false
273  },
274  {
275  .id = obj_id_ani_tc_alarms,
276  .name = "TC.Alarms",
277  .generic_path = "XPON.ONU.x.ANI.x.TC.Alarms",
278  .key_name = NULL,
279  .singletons = NULL,
280  .templates = NULL,
281  .params = TC_ALARMS_PARAMS,
282  .n_params = ARRAY_SIZE(TC_ALARMS_PARAMS),
283  .has_rw_enable = false
284  }
285 };
286 
287 
297 bool dm_info_init(void) {
298  uint32_t i;
299  for(i = 0; i < obj_id_nbr; ++i) {
300  if(OBJECT_INFO[i].id != i) {
301  SAH_TRACEZ_ERROR(ME, "OBJECT_INFO[%d].id=%d != %d",
302  i, OBJECT_INFO[i].id, i);
303  return false;
304  }
305  }
306  return true;
307 }
308 
320 static bool dm_convert_to_generic_path(const char* path, amxc_string_t* generic_path) {
321 
322  bool rv = false;
323  when_null(path, exit_no_cleanup);
324  when_null(generic_path, exit_no_cleanup);
325 
326  amxc_llist_t list;
327  amxc_llist_init(&list);
328 
329  amxc_string_t input;
330  amxc_string_init(&input, 0);
331  amxc_string_set(&input, path);
332 
333  if(AMXC_STRING_SPLIT_OK != amxc_string_split_to_llist(&input, &list, '.')) {
334  SAH_TRACEZ_ERROR(ME, "Failed to split '%s'", path);
335  goto exit;
336  }
337 
338  /* Remove the last elem from 'list' if it's numeric */
339  amxc_llist_it_t* last_it = amxc_llist_get_last(&list);
340  when_null(last_it, exit);
341  amxc_string_t* const last_elem = amxc_string_from_llist_it(last_it);
342  if(amxc_string_is_numeric(last_elem)) {
343  amxc_llist_take_last(&list);
344  amxc_string_list_it_free(last_it);
345  }
346 
347  amxc_llist_iterate(it, &list) {
348  amxc_string_t* part = amxc_string_from_llist_it(it);
349  if(amxc_string_is_numeric(part)) {
350  amxc_string_set(part, "x");
351  }
352  }
353 
354  if(amxc_string_join_llist(generic_path, &list, '.') != 0) {
355  SAH_TRACEZ_ERROR(ME, "Failed to generate generic path from '%s'", path);
356  goto exit;
357  }
358  rv = true;
359 
360 exit:
361  amxc_llist_clean(&list, amxc_string_list_it_free);
362  amxc_string_clean(&input);
363 
364 exit_no_cleanup:
365  return rv;
366 }
367 
368 
380 object_id_t dm_get_object_id(const char* path) {
381 
383 
384  amxc_string_t generic_path_str;
385  amxc_string_init(&generic_path_str, 0);
386 
387  if(!dm_convert_to_generic_path(path, &generic_path_str)) {
388  goto exit;
389  }
390 
391  const char* const generic_path = amxc_string_get(&generic_path_str, 0);
392  const size_t generic_path_len = strlen(generic_path);
393 
394  uint32_t i;
395  size_t len;
396  for(i = 0; i < obj_id_nbr; ++i) {
397  len = strlen(OBJECT_INFO[i].generic_path);
398  if((generic_path_len == len) &&
399  (strncmp(generic_path, OBJECT_INFO[i].generic_path, len) == 0)) {
400  id = OBJECT_INFO[i].id;
401  break;
402  }
403  }
404 
405 exit:
406  amxc_string_clean(&generic_path_str);
407  return id;
408 }
409 
411  if(id < obj_id_nbr) {
412  return &OBJECT_INFO[id];
413  }
414 
415  SAH_TRACEZ_ERROR(ME, "Invalid id [%d]", id);
416  return NULL;
417 }
418 
430  const param_info_t** param_info,
431  uint32_t* size) {
432  if(id < obj_id_nbr) {
433  *param_info = OBJECT_INFO[id].params;
434  *size = OBJECT_INFO[id].n_params;
435  return true;
436  }
437  SAH_TRACEZ_ERROR(ME, "Invalid id [%d]", id);
438  return false;
439 }
static const param_info_t SOFTWARE_IMAGE_PARAMS[]
Definition: dm_info.c:87
static const param_info_t TC_ALARMS_PARAMS[]
Definition: dm_info.c:148
bool dm_info_init(void)
Definition: dm_info.c:297
#define ARRAY_SIZE(arr)
Definition: dm_info.c:77
static bool dm_convert_to_generic_path(const char *path, amxc_string_t *generic_path)
Definition: dm_info.c:320
bool dm_get_object_param_info(object_id_t id, const param_info_t **param_info, uint32_t *size)
Definition: dm_info.c:429
static const param_info_t AUTHENTICATION_PARAMS[]
Definition: dm_info.c:138
static const param_info_t ANI_PARAMS[]
Definition: dm_info.c:103
static const param_info_t TRANSCEIVER_PARAMS[]
Definition: dm_info.c:115
static const param_info_t ETHERNET_UNI_PARAMS[]
Definition: dm_info.c:94
object_id_t dm_get_object_id(const char *path)
Definition: dm_info.c:380
static const param_info_t PERFORMANCE_THRESHOLDS_PARAMS[]
Definition: dm_info.c:143
static const param_info_t GEM_PORT_PARAMS[]
Definition: dm_info.c:110
static const param_info_t ONU_ACTIVATION_PARAMS[]
Definition: dm_info.c:131
const object_info_t OBJECT_INFO[obj_id_nbr]
Definition: dm_info.c:171
static const param_info_t ONU_PARAMS[]
Definition: dm_info.c:80
const object_info_t * dm_get_object_info(object_id_t id)
Definition: dm_info.c:410
#define ENABLE_PARAM
Definition: dm_info.h:74
enum _xpon_object_id object_id_t
#define NAME_PARAM
Definition: dm_info.h:76
@ obj_id_ani
Definition: dm_info.h:83
@ obj_id_nbr
Definition: dm_info.h:90
@ obj_id_gem_port
Definition: dm_info.h:84
@ obj_id_onu
Definition: dm_info.h:80
@ obj_id_ani_tc_authentication
Definition: dm_info.h:87
@ obj_id_ethernet_uni
Definition: dm_info.h:82
@ obj_id_ani_tc_alarms
Definition: dm_info.h:89
@ obj_id_software_image
Definition: dm_info.h:81
@ obj_id_unknown
Definition: dm_info.h:91
@ obj_id_ani_tc_performance_thresholds
Definition: dm_info.h:88
@ obj_id_transceiver
Definition: dm_info.h:85
@ obj_id_ani_tc_onu_activation
Definition: dm_info.h:86
const param_info_t * params
Definition: dm_info.h:130
uint32_t n_params
Definition: dm_info.h:131
object_id_t id
Definition: dm_info.h:123
const char * name
Definition: dm_info.h:95
#define ME
Definition: xpon_trace.h:78