TR181-XPON  1.4.0
TR-181 PON manager.
data_model.c File Reference
#include "data_model.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <amxc/amxc.h>
#include <amxp/amxp.h>
#include <amxd/amxd_object.h>
#include <amxd/amxd_transaction.h>
#include "ani.h"
#include "dm_actions.h"
#include "dm_info.h"
#include "dm_xpon_mngr.h"
#include "onu_priv.h"
#include "persistency.h"
#include "password.h"
#include "restore_to_hal.h"
#include "xpon_trace.h"

Go to the source code of this file.

Data Structures

struct  _dm_action_info
 

Macros

#define ADD_INST_N_ARGS_REQUIRED   3
 
#define REMOVE_INST_N_ARGS_REQUIRED   2
 
#define CHANGE_OBJ_N_ARGS_REQUIRED   2
 
#define ADD_OR_CHANGE_INST_N_ARGS_REQUIRED   2
 

Typedefs

typedef struct _dm_action_info dm_action_info_t
 

Functions

static void init_dm_action_info (dm_action_info_t *const info)
 
static amxd_object_t * dm_get_xpon_object (void)
 
void dm_set_vendor_module (const char *name)
 
void dm_set_module_error (void)
 
static bool get_ref_to_params (const amxc_var_t *const args, const amxc_var_t **params)
 
static bool process_args_common (const amxc_var_t *const args, dm_action_info_t *info, const char **keys_required, int n_keys_required)
 
static bool process_add_instance_args (const amxc_var_t *const args, dm_action_info_t *info)
 
static bool prepare_adding_instance (const char *const path, uint32_t index, amxd_object_t **templ)
 
static bool add_params_to_transaction (amxd_trans_t *transaction, const amxc_var_t *const params, object_id_t id)
 
static void update_enable (amxd_trans_t *transaction, const char *const path, uint32_t index)
 
static void add_private_data_to_onu (const char *const path, uint32_t index)
 
static bool add_instance (const dm_action_info_t *const info)
 
static bool process_remove_instance_args (const amxc_var_t *const args, dm_action_info_t *info)
 
static bool remove_instance (const dm_action_info_t *const info)
 
int dm_add_instance (const amxc_var_t *const args)
 
int dm_remove_instance (const amxc_var_t *const args)
 
int dm_change_object (const amxc_var_t *const args)
 
int dm_add_or_change_instance_impl (const amxc_var_t *const args)
 
static bool remove_all_instances (amxd_object_t *templ)
 
static void set_ethernet_uni_status_to_down (const amxd_object_t *const onu_instance, const char *const path)
 
int dm_omci_reset_mib (const amxc_var_t *const args)
 
int dm_set_xpon_parameter_impl (const amxc_var_t *const args)
 
bool dm_does_instance_exist (const char *const path, uint32_t index)
 
static uint32_t get_nr_of_instances (const char *const path)
 
uint32_t dm_get_nr_of_ethernet_uni_instances (const char *const onu_path)
 
uint32_t dm_get_nr_of_ani_instances (const char *const onu_path)
 
bool dm_get_param (const char *path, const char *name, amxc_var_t *resp)
 
bool dm_is_hex_password (const char *const ani_path, bool *is_hex)
 
bool dm_get_ani_pon_mode (const char *const ani_path, pon_mode_t *pon_mode)
 

Variables

static const char * ADD_INST_PARAMS_REQUIRED [3]
 
static const char * REMOVE_INST_ARGS_REQUIRED [2]
 
static const char * CHANGE_OBJ_ARGS_REQUIRED [2]
 
static const char * ADD_OR_CHANGE_INST_ARGS_REQUIRED [2]
 

Macro Definition Documentation

◆ ADD_INST_N_ARGS_REQUIRED

#define ADD_INST_N_ARGS_REQUIRED   3

Include amxp.h to include amxp_signal.h, which defines amxp_signal_mngr_t. amxd_object.h and amxd_transaction.h need it: they include amxd_types.h, which uses amxp_signal_mngr_t.

Definition at line 94 of file data_model.c.

◆ ADD_OR_CHANGE_INST_N_ARGS_REQUIRED

#define ADD_OR_CHANGE_INST_N_ARGS_REQUIRED   2

Definition at line 109 of file data_model.c.

◆ CHANGE_OBJ_N_ARGS_REQUIRED

#define CHANGE_OBJ_N_ARGS_REQUIRED   2

Definition at line 104 of file data_model.c.

◆ REMOVE_INST_N_ARGS_REQUIRED

#define REMOVE_INST_N_ARGS_REQUIRED   2

Definition at line 99 of file data_model.c.

Typedef Documentation

◆ dm_action_info_t

Info related to actions done on the DM.

The actions are:

  • add an instance
  • remove an instance
  • update/change an object

Meaning of the fields:

  • path: object path of a singleton or template object
  • index: instance index for the instance of a template object. 0 if not applicable.
  • obj_id: object ID (derived from 'path' with dm_get_object_id())
  • key_value: for an instance of a template object, it is the value of the unique key for that instance. The variant normally has a string or an uint32_t.
  • params: values for the params of the object

Function Documentation

◆ add_instance()

static bool add_instance ( const dm_action_info_t *const  info)
static

Add an instance to the XPON DM.

Parameters
[in]infoall the info needed to create the instance

If the instance to be created has a read-write Enable parameter, and if that instance is enabled according to the persistent data, create the instance with that Enable parameter set to true, and schedule a timer to let this know to the vendor module in 100 ms.

If the instance created is an ONU instance, create and attach private data to the instance to indicate the persistency of the RW Enable parameter has been handled. The ANI also a has RW Enable parameter. The approach with the private data is only done for an ONU because the PON vendor modules create an ONU instance in 2 different ways:

  • via this add_instance() call: then this add_instance() call attaches the private data to the ONU instance. If dm_change_object() is called afterwards, it notices the private data is already present, and then it knows this process already checked if it should enable the ONU according to the persistent data.
  • via defaults.odl file: then add_instance() is not triggered, but dm_change_object() is. dm_change_object() will see that there is no private data attached to the ONU. Then that function will attach the private data and check if it should enable the ONU.

If the instance created is an ANI instance, restore its PON password if there is one.

Returns
true on success, else false

Definition at line 589 of file data_model.c.

589  {
590 
591  bool rv = false;
592  amxd_object_t* templ = NULL;
593 
594  SAH_TRACEZ_INFO(ME, "Create %s.%d", info->path, info->index);
595 
596  const object_info_t* const obj_info = dm_get_object_info(info->obj_id);
597  when_null_trace(obj_info, exit_no_cleanup, ERROR,
598  "obj_info is NULL for obj_id=%d", info->obj_id);
599 
600  if(!prepare_adding_instance(info->path, info->index, &templ)) {
601  return false;
602  }
603 
604  amxd_dm_t* const dm = xpon_mngr_get_dm();
605  when_null(dm, exit_no_cleanup);
606 
607  amxd_trans_t transaction;
608  amxd_trans_init(&transaction);
609  amxd_trans_set_attr(&transaction, amxd_tattr_change_ro, true);
610 
611  const char* const key_name = obj_info->key_name; /* alias */
612 
613  amxd_status_t rc = amxd_trans_select_object(&transaction, templ);
614  when_failed_trace(rc, exit, ERROR, "Failed to select %s for transaction (rc=%d)",
615  info->path, rc);
616 
617  rc = amxd_trans_add_inst(&transaction, info->index, NULL);
618  when_failed_trace(rc, exit, ERROR,
619  "Failed to add creation of %s.%d to transaction (rc=%d)",
620  info->path, info->index, rc);
621 
622  rc = amxd_trans_set_param(&transaction, key_name, info->key_value);
623  when_failed_trace(rc, exit, ERROR,
624  "Failed to add value for key to transaction (rc=%d)", rc);
625 
626  if(info->params) {
627  add_params_to_transaction(&transaction, info->params, info->obj_id);
628  }
629 
630  if(obj_info->has_rw_enable) {
631  update_enable(&transaction, info->path, info->index);
632  }
633 
634  rc = amxd_trans_apply(&transaction, dm);
635  when_failed_trace(rc, exit, ERROR, "Failed to create %s.%d (rc=%d)",
636  info->path, info->index, rc);
637 
638  SAH_TRACEZ_DEBUG(ME, "Created %s.%d", info->path, info->index);
639 
640  if(obj_info->id == obj_id_onu) {
641  add_private_data_to_onu(info->path, info->index);
642  } else if(obj_info->id == obj_id_ani) {
643  amxc_string_t ani_instance;
644  amxc_string_init(&ani_instance, 0);
645  amxc_string_setf(&ani_instance, "%s.%d", info->path, info->index);
646  passwd_restore_password(amxc_string_get(&ani_instance, 0));
647  amxc_string_clean(&ani_instance);
648  }
649 
650  rv = true;
651 
652 exit:
653  amxd_trans_clean(&transaction);
654 
655 exit_no_cleanup:
656  return rv;
657 }
static bool prepare_adding_instance(const char *const path, uint32_t index, amxd_object_t **templ)
Definition: data_model.c:389
static void update_enable(amxd_trans_t *transaction, const char *const path, uint32_t index)
Definition: data_model.c:505
static bool add_params_to_transaction(amxd_trans_t *transaction, const amxc_var_t *const params, object_id_t id)
Definition: data_model.c:430
static void add_private_data_to_onu(const char *const path, uint32_t index)
Definition: data_model.c:538
@ obj_id_ani
Definition: dm_info.h:83
@ obj_id_onu
Definition: dm_info.h:80
const object_info_t * dm_get_object_info(object_id_t id)
Definition: dm_info.c:410
amxd_dm_t *PRIVATE xpon_mngr_get_dm(void)
void passwd_restore_password(const char *const ani_path)
Definition: password.c:237
object_id_t obj_id
Definition: data_model.c:136
const char * path
Definition: data_model.c:134
uint32_t index
Definition: data_model.c:135
const amxc_var_t * params
Definition: data_model.c:138
amxc_var_t * key_value
Definition: data_model.c:137
object_id_t id
Definition: dm_info.h:123
bool has_rw_enable
Definition: dm_info.h:132
const char * key_name
Definition: dm_info.h:126
on event dm
#define SAH_TRACEZ_DEBUG(zone, format,...)
Definition: xpon_trace.h:115
#define ME
Definition: xpon_trace.h:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_params_to_transaction()

static bool add_params_to_transaction ( amxd_trans_t *  transaction,
const amxc_var_t *const  params,
object_id_t  id 
)
static

Add set value actions to a transaction to set params of an object.

Parameters
[in,out]transactiontransaction to add set value actions to
[in]paramshtable with values for one or more params of an object
[in]idobject ID

The function iterates over all elements in params. It adds a set value action to transaction for each known element.

Returns
true on success, else false

Definition at line 430 of file data_model.c.

432  {
433  bool rv = false;
434 
435  const amxc_htable_t* const params_table = amxc_var_constcast(amxc_htable_t, params);
436  when_null(params_table, exit);
437 
438  const object_info_t* const obj_info = dm_get_object_info(id);
439  when_null(obj_info, exit);
440 
441  const param_info_t* param_info;
442  const param_info_t* single_param;
443  uint32_t n_params;
444 
445  if(!dm_get_object_param_info(id, &param_info, &n_params)) {
446  SAH_TRACEZ_ERROR(ME, "%s: failed to get info about its params", obj_info->name);
447  goto exit;
448  }
449 
450  amxc_var_t* param_value = NULL;
451  uint32_t i;
452  const char* key;
453 
454  amxc_htable_for_each(it, params_table) {
455  single_param = NULL;
456  key = amxc_htable_it_get_key(it);
457  if(!key) {
458  continue;
459  }
460  for(i = 0; i < n_params; ++i) {
461  if((strncmp(key, param_info[i].name, strlen(key)) == 0) &&
462  (strlen(key) == strlen(param_info[i].name))) {
463  single_param = &param_info[i];
464  break; /* out of for loop */
465  }
466  }
467  if(NULL == single_param) {
468  SAH_TRACEZ_WARNING(ME, "%s: unknown param name: %s", obj_info->name, key);
469  continue;
470  }
471  param_value = GET_ARG(params, key);
472  if(NULL == param_value) {
473  SAH_TRACEZ_ERROR(ME, "%s: failed to get value for %s", obj_info->name, key);
474  continue;
475  }
476  if(amxc_var_type_of(param_value) != single_param->type) {
477  SAH_TRACEZ_ERROR(ME, "%s: type of parameter %s: %d != expected=%d",
478  obj_info->name, key, amxc_var_type_of(param_value),
479  single_param->type);
480  continue;
481  }
482  if(amxd_trans_set_param(transaction, key, param_value)) {
483  SAH_TRACEZ_ERROR(ME, "%s: failed to add value for %s to transaction",
484  obj_info->name, key);
485  } else {
486  SAH_TRACEZ_DEBUG(ME, "%s: added value for %s to transaction",
487  obj_info->name, key);
488  }
489  }
490  rv = true;
491 
492 exit:
493  return rv;
494 }
bool dm_get_object_param_info(object_id_t id, const param_info_t **param_info, uint32_t *size)
Definition: dm_info.c:429
const char * name
Definition: dm_info.h:124
uint32_t type
Definition: dm_info.h:96
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_private_data_to_onu()

static void add_private_data_to_onu ( const char *const  path,
uint32_t  index 
)
static

Create and attach private data to the ONU instance.

Parameters
[in]pathpath of the XPON.ONU template. This must be "XPON.ONU".
[in]indexindex of the ONU instance

Definition at line 538 of file data_model.c.

538  {
539 
540  SAH_TRACEZ_DEBUG(ME, "%s.%d", path, index);
541 
542  amxd_dm_t* const dm = xpon_mngr_get_dm();
543  when_null(dm, exit);
544 
545  amxd_object_t* templ = amxd_dm_findf(dm, "%s", path);
546  when_null_trace(templ, exit, ERROR, "Failed to find %s", path);
547 
548  amxd_object_t* const obj = amxd_object_get_instance(templ, NULL, index);
549  when_null_trace(obj, exit, ERROR, "Instance %s.%d does not exist", path, index);
550 
552 
553 exit:
554  return;
555 }
void onu_priv_attach_private_data(amxd_object_t *const object)
Definition: onu_priv.c:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_add_instance()

int dm_add_instance ( const amxc_var_t *const  args)

Add an instance to the XPON DM.

Parameters
[in]args: must be htable with the keys 'path', 'index' and 'keys'. The htable normally also has an entry with the key 'parameters'.
Returns
0 on success, else -1.

Definition at line 762 of file data_model.c.

762  {
763 
764  int rc = -1;
765  dm_action_info_t info;
766 
767  SAH_TRACEZ_DEBUG2(ME, "called");
768 
769  if(!process_add_instance_args(args, &info)) {
770  goto exit;
771  }
772  if(!add_instance(&info)) {
773  goto exit;
774  }
775 
776  rc = 0;
777 exit:
778  return rc;
779 }
static bool process_add_instance_args(const amxc_var_t *const args, dm_action_info_t *info)
Definition: data_model.c:326
static bool add_instance(const dm_action_info_t *const info)
Definition: data_model.c:589
#define SAH_TRACEZ_DEBUG2(zone, format,...)
Definition: xpon_trace.h:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_add_or_change_instance_impl()

int dm_add_or_change_instance_impl ( const amxc_var_t *const  args)

Add or update an instance in the XPON DM.

Parameters
[in]args: must be htable with the keys 'path' and 'index'. It must also have the key 'keys' if the instance does not yet exist, else it must have the key 'parameters'. It's recommended that 'args' has all those 4 keys. See below for more info.

The function checks if the instance exists. If the instance does not exist, the function calls 'dm_add_instance()', else it calls 'dm_change_object()'.

More info about the parameter args: The path in args must be the template path, e.g. "XPON.ONU.1.SoftwareImage".

If the function finds out the instance does not exist yet, it demands the same from args as dm_instance_added(): it must be an htable with the keys 'path', 'index' and 'keys'.

If the function finds out the instance already exists, it demands the same from args as dm_object_changed(): it must be an htable with the keys 'path' and 'parameters'. If dm_object_changed() sees that args has a value for 'index', it assumes the caller wants to change path.index, not path.

Hence when calling this function, it's recommended args is htable with the keys 'path', 'index', 'keys' and 'parameters'. Then the function finds the required keys, independent from whether the instance already exists or not.

Returns
0 on success, else -1.

Definition at line 922 of file data_model.c.

922  {
923 
924  int rc = -1;
925 
926  SAH_TRACEZ_DEBUG2(ME, "called");
927 
928  amxd_dm_t* const dm = xpon_mngr_get_dm();
929  when_null(dm, exit);
930 
931  dm_action_info_t info;
934  goto exit;
935  }
936 
937  if(dm_does_instance_exist(info.path, info.index)) {
938  SAH_TRACEZ_DEBUG(ME, "Change %s.%d", info.path, info.index);
939  return dm_change_object(args);
940  } else {
941  SAH_TRACEZ_DEBUG(ME, "Add %s.%d", info.path, info.index);
942  return dm_add_instance(args);
943  }
944 
945 exit:
946  return rc;
947 }
#define ADD_OR_CHANGE_INST_N_ARGS_REQUIRED
Definition: data_model.c:109
int dm_change_object(const amxc_var_t *const args)
Definition: data_model.c:821
static const char * ADD_OR_CHANGE_INST_ARGS_REQUIRED[2]
Definition: data_model.c:110
int dm_add_instance(const amxc_var_t *const args)
Definition: data_model.c:762
bool dm_does_instance_exist(const char *const path, uint32_t index)
Definition: data_model.c:1141
static bool process_args_common(const amxc_var_t *const args, dm_action_info_t *info, const char **keys_required, int n_keys_required)
Definition: data_model.c:244
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_change_object()

int dm_change_object ( const amxc_var_t *const  args)

Update one of more params of an object in the XPON DM.

Parameters
[in]args: must be htable with the keys 'path' and 'parameters'. If it has a non-zero value for 'index', the function assumes the caller wants to update the instance 'path'.'index'.

If the object is an ONU instance, check if the instance has private data. If it doesn't, attach private data, and call update_enable() for that instance. If the ONU instance has no private data yet, this process did not check yet the persistent data to find out if the ONU instance should be enabled.

Returns
0 on success, else -1.

Definition at line 821 of file data_model.c.

821  {
822 
823  int rc = -1;
824 
825  SAH_TRACEZ_DEBUG2(ME, "called");
826 
827  amxd_dm_t* const dm = xpon_mngr_get_dm();
828  when_null(dm, exit);
829 
830  dm_action_info_t info;
833  goto exit;
834  }
835 
836  amxc_string_t path;
837  amxc_string_init(&path, 0);
838  amxc_string_set(&path, info.path);
839 
840  SAH_TRACEZ_DEBUG(ME, "path='%s' index=%d", info.path, info.index);
841 
842  if(info.index) {
843  /* Assume caller wants to update 'path'.'index' */
844  amxc_string_appendf(&path, ".%d", info.index);
845  }
846  const char* const path_cstr = amxc_string_get(&path, 0);
847 
848  amxd_object_t* object = amxd_dm_findf(dm, "%s", path_cstr);
849  if(!object) {
850  SAH_TRACEZ_WARNING(ME, "%s does not exist: ignore object-changed", path_cstr);
851  amxc_string_clean(&path);
852  rc = 0;
853  goto exit;
854  }
855 
856  amxd_trans_t transaction;
857  amxd_trans_init(&transaction);
858  amxd_trans_set_attr(&transaction, amxd_tattr_change_ro, true);
859 
860  amxd_status_t status = amxd_trans_select_object(&transaction, object);
861  when_failed_trace(status, exit_cleanup, ERROR,
862  "Failed to select %s for transaction (status=%d)",
863  info.path, status);
864 
865  add_params_to_transaction(&transaction, info.params, info.obj_id);
866 
867  if(info.obj_id == obj_id_onu) {
868  if(object->priv == NULL) {
869  SAH_TRACEZ_DEBUG(ME, "%s has no private data", path_cstr);
871  update_enable(&transaction, info.path, info.index);
872  } else {
873  SAH_TRACEZ_DEBUG(ME, "%s already has private data", path_cstr);
874  }
875  }
876 
877  status = amxd_trans_apply(&transaction, dm);
878  when_failed_trace(status, exit_cleanup, ERROR, "Failed to update %s (status=%d)",
879  info.path, status);
880 
881  rc = 0;
882 
883 exit_cleanup:
884  amxc_string_clean(&path);
885  amxd_trans_clean(&transaction);
886 exit:
887  return rc;
888 }
#define CHANGE_OBJ_N_ARGS_REQUIRED
Definition: data_model.c:104
static const char * CHANGE_OBJ_ARGS_REQUIRED[2]
Definition: data_model.c:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_does_instance_exist()

bool dm_does_instance_exist ( const char *const  path,
uint32_t  index 
)

Return true if a certain instance of a template object exists.

Parameters
[in]pathobject path, e.g., "XPON.ONU"
[in]indexthe instance index, e.g., 1
Returns
true if instance exists, else false

Definition at line 1141 of file data_model.c.

1141  {
1142 
1143  bool rv = false;
1144  amxd_dm_t* const dm = xpon_mngr_get_dm();
1145  when_null(dm, exit);
1146 
1147  const amxd_object_t* const templ = amxd_dm_findf(dm, "%s", path);
1148  if(!templ) {
1149  goto exit;
1150  }
1151 
1152  if(amxd_object_get_instance(templ, NULL, index)) {
1153  rv = true;
1154  }
1155 
1156 exit:
1157  return rv;
1158 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_get_ani_pon_mode()

bool dm_get_ani_pon_mode ( const char *const  ani_path,
pon_mode_t pon_mode 
)

Find out the PON Mode of an ANI.

Parameters
[in]ani_pathpath to ANI instance, e.g. "XPON.ONU.1.ANI.1"
[in,out]pon_modefunction sets this to the PON mode of the ANI referred to by ani_path
Returns
true on success, else false

Definition at line 1280 of file data_model.c.

1280  {
1281 
1282  bool rv = false;
1283  amxc_var_t pon_mode_var;
1284  amxc_var_init(&pon_mode_var);
1285 
1286  amxd_dm_t* const dm = xpon_mngr_get_dm();
1287  when_null(dm, exit);
1288  when_null(pon_mode, exit);
1289 
1290  amxd_object_t* const object = amxd_dm_findf(dm, "%s", ani_path);
1291  when_null_trace(object, exit, WARNING, "%s does not exist", ani_path);
1292 
1293  if(amxd_status_ok != amxd_object_get_param(object, "PONMode",
1294  &pon_mode_var)) {
1295  SAH_TRACEZ_ERROR(ME, "Failed to get %s.PONMode", ani_path);
1296  goto exit;
1297  }
1298 
1299  const char* const pon_mode_cstr = amxc_var_constcast(cstring_t, &pon_mode_var);
1300  if(strncmp(pon_mode_cstr, "Unknown", 7) == 0) {
1301  *pon_mode = pon_mode_unknown;
1302  } else if(strncmp(pon_mode_cstr, "G-PON", 5) == 0) {
1303  *pon_mode = pon_mode_gpon;
1304  } else if(strncmp(pon_mode_cstr, "XG-PON", 6) == 0) {
1305  *pon_mode = pon_mode_xg_pon;
1306  } else if(strncmp(pon_mode_cstr, "NG-PON2", 7) == 0) {
1307  *pon_mode = pon_mode_ng_pon2;
1308  } else if(strncmp(pon_mode_cstr, "XGS-PON", 7) == 0) {
1309  *pon_mode = pon_mode_xgs_pon;
1310  } else {
1311  SAH_TRACEZ_ERROR(ME, "Invalid PON mode: %s", pon_mode_cstr);
1312  *pon_mode = pon_mode_unknown;
1313  goto exit;
1314  }
1315 
1316  rv = true;
1317 
1318 exit:
1319  amxc_var_clean(&pon_mode_var);
1320  return rv;
1321 }
@ pon_mode_ng_pon2
Definition: pon_mode.h:70
@ pon_mode_unknown
Definition: pon_mode.h:67
@ pon_mode_gpon
Definition: pon_mode.h:68
@ pon_mode_xgs_pon
Definition: pon_mode.h:71
@ pon_mode_xg_pon
Definition: pon_mode.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_get_nr_of_ani_instances()

uint32_t dm_get_nr_of_ani_instances ( const char *const  onu_path)

Return the number of ANI instances for a certain XPON.ONU instance.

Parameters
[in]pathpath of a certain XPON.ONU instance, e.g. "XPON.ONU.1"

Definition at line 1198 of file data_model.c.

1198  {
1199  char path[64];
1200  snprintf(path, 64, "%s.ANI", onu_path);
1201  return get_nr_of_instances(path);
1202 }
static uint32_t get_nr_of_instances(const char *const path)
Definition: data_model.c:1166
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_get_nr_of_ethernet_uni_instances()

uint32_t dm_get_nr_of_ethernet_uni_instances ( const char *const  onu_path)

Return the number of EthernetUNI instances for a certain XPON.ONU instance.

Parameters
[in]pathpath of a certain XPON.ONU instance, e.g. "XPON.ONU.1"

Definition at line 1187 of file data_model.c.

1187  {
1188  char path[64];
1189  snprintf(path, 64, "%s.EthernetUNI", onu_path);
1190  return get_nr_of_instances(path);
1191 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_get_param()

bool dm_get_param ( const char *  path,
const char *  name,
amxc_var_t *  resp 
)

Definition at line 1204 of file data_model.c.

1204  {
1205  SAH_TRACEZ_DEBUG(ME, "get value of dm parameter path=%s.%s", path, name);
1206 
1207  amxd_dm_t* const dm = xpon_mngr_get_dm();
1208  when_null(dm, exit);
1209 
1210  amxd_object_t* const param_object = amxd_dm_findf(dm, "%s", path);
1211  if(!param_object) {
1212  SAH_TRACEZ_WARNING(ME, "%s does not exist!", path);
1213  goto exit;
1214  }
1215 
1216  if(amxd_status_ok != amxd_object_get_param(param_object, name, resp)) {
1217  SAH_TRACEZ_WARNING(ME, "Failed to get param from object: %s.%s", path, name);
1218  goto exit;
1219  }
1220 
1221  return true;
1222 exit:
1223  return false;
1224 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_get_xpon_object()

static amxd_object_t* dm_get_xpon_object ( void  )
static

Return the "XPON" object from the XPON DM.

Definition at line 153 of file data_model.c.

153  {
154 
155  amxd_dm_t* const dm = xpon_mngr_get_dm();
156  if(!dm) {
157  SAH_TRACEZ_ERROR(ME, "Failed to get DM");
158  return NULL;
159  }
160 
161 
162  amxd_object_t* xpon = amxd_dm_get_object(dm, "XPON");
163  if(!xpon) {
164  SAH_TRACEZ_ERROR(ME, "Failed to get XPON object");
165  return NULL;
166  }
167  return xpon;
168 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_is_hex_password()

bool dm_is_hex_password ( const char *const  ani_path,
bool *  is_hex 
)

Find out if password for an ANI instance is in hex format or not.

Parameters
[in]ani_pathpath to ANI instance, e.g. "XPON.ONU.1.ANI.1"
[in,out]is_hexfunction sets this to true if the parameter 'HexadecimalPassword' of the ANI instance referred to by ani_path is true
Returns
true on success, else false

Definition at line 1236 of file data_model.c.

1236  {
1237 
1238  bool rv = false;
1239  amxc_var_t is_hex_variant;
1240  amxc_string_t ani_auth_path;
1241  amxc_var_init(&is_hex_variant);
1242  amxc_string_init(&ani_auth_path, 0);
1243 
1244  amxd_dm_t* const dm = xpon_mngr_get_dm();
1245  when_null(dm, exit);
1246  when_null(is_hex, exit);
1247 
1248  ani_append_tc_authentication(ani_path, &ani_auth_path);
1249  const char* const ani_auth_path_cstr = amxc_string_get(&ani_auth_path, 0);
1250 
1251  amxd_object_t* const object = amxd_dm_findf(dm, "%s", ani_auth_path_cstr);
1252  when_null_trace(object, exit, WARNING, "%s does not exist",
1253  ani_auth_path_cstr);
1254 
1255  if(amxd_status_ok != amxd_object_get_param(object, "HexadecimalPassword",
1256  &is_hex_variant)) {
1257  SAH_TRACEZ_ERROR(ME, "Failed to get %s.HexadecimalPassword",
1258  ani_auth_path_cstr);
1259  goto exit;
1260  }
1261 
1262  *is_hex = amxc_var_constcast(bool, &is_hex_variant);
1263  rv = true;
1264 
1265 exit:
1266  amxc_var_clean(&is_hex_variant);
1267  amxc_string_clean(&ani_auth_path);
1268  return rv;
1269 }
void ani_append_tc_authentication(const char *const ani_path, amxc_string_t *const ani_auth_path)
Definition: ani.c:113
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_omci_reset_mib()

int dm_omci_reset_mib ( const amxc_var_t *const  args)

Handle an OMCI reset MIB message.

Parameters
[in]args: must be htable with the key 'index'. The 'index' must indicate for which XPON.ONU instance an OMCI reset MIB is received

The function does the following:

  • For all EthernetUNI instances of the ONU, set Status to Down if it is Up now.
  • For all ANI instances of the ONU, remove all TC.GEM.Port instances.
Returns
0 on success, else -1

Definition at line 1049 of file data_model.c.

1049  {
1050 
1051  int rc = -1;
1052 
1053  SAH_TRACEZ_DEBUG2(ME, "called");
1054 
1055  when_null_trace(args, exit, ERROR, "args is NULL");
1056 
1057  amxd_dm_t* const dm = xpon_mngr_get_dm();
1058  when_null(dm, exit);
1059 
1060  const uint32_t index = GET_UINT32(args, "index");
1061  when_false_trace(index != 0, exit, ERROR, "Failed to extract valid index from args");
1062 
1063  char path[16];
1064  snprintf(path, 16, "XPON.ONU.%d", index);
1065  const amxd_object_t* onu_instance = amxd_dm_findf(dm, "%s", path);
1066  if(!onu_instance) {
1067  SAH_TRACEZ_WARNING(ME, "%s does not exist: ignore omci:reset-mib", path);
1068  rc = 0;
1069  goto exit;
1070  }
1071 
1072  set_ethernet_uni_status_to_down(onu_instance, path);
1073 
1074  /* Remove GEM ports */
1075  const amxd_object_t* ani = amxd_object_get_child(onu_instance, "ANI");
1076  if(ani) {
1077  amxd_object_iterate(instance, it, ani) {
1078  amxd_object_t* const ani_inst = amxc_container_of(it, amxd_object_t, it);
1079  amxd_object_t* const port_templ = amxd_object_findf(ani_inst, "TC.GEM.Port");
1080  if(!port_templ) {
1081  SAH_TRACEZ_ERROR(ME, "%s: failed to find TC.GEM.Port for ANI.%d",
1082  path, amxd_object_get_index(ani_inst));
1083  continue;
1084  }
1085  if(!remove_all_instances(port_templ)) {
1086  SAH_TRACEZ_ERROR(ME, "%s: failed to delete GEM ports for ANI.%d",
1087  path, amxd_object_get_index(ani_inst));
1088  }
1089  }
1090  } else {
1091  SAH_TRACEZ_ERROR(ME, "%s.ANI does not exist", path);
1092  }
1093 
1094  rc = 0;
1095 exit:
1096  return rc;
1097 }
static bool remove_all_instances(amxd_object_t *templ)
Definition: data_model.c:958
static void set_ethernet_uni_status_to_down(const amxd_object_t *const onu_instance, const char *const path)
Definition: data_model.c:1011
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_remove_instance()

int dm_remove_instance ( const amxc_var_t *const  args)

Remove an instance from the XPON DM.

Parameters
[in]args: must be htable with the keys 'path' and 'index'
Returns
0 on success, else -1.

Definition at line 788 of file data_model.c.

788  {
789 
790  int rc = -1;
791  dm_action_info_t info;
792 
793  SAH_TRACEZ_DEBUG2(ME, "called");
794 
795  if(!process_remove_instance_args(args, &info)) {
796  goto exit;
797  }
798  if(!remove_instance(&info)) {
799  goto exit;
800  }
801 
802  rc = 0;
803 exit:
804  return rc;
805 }
static bool process_remove_instance_args(const amxc_var_t *const args, dm_action_info_t *info)
Definition: data_model.c:669
static bool remove_instance(const dm_action_info_t *const info)
Definition: data_model.c:695
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_set_module_error()

void dm_set_module_error ( void  )

Set XPON.ModuleError to true.

Definition at line 192 of file data_model.c.

192  {
193 
194  amxd_object_t* xpon = dm_get_xpon_object();
195  when_null(xpon, exit);
196  if(amxd_object_set_value(bool, xpon, "ModuleError", true)) {
197  SAH_TRACEZ_ERROR(ME, "Failed to set XPON.ModuleError to true");
198  }
199 exit:
200  return;
201 }
static amxd_object_t * dm_get_xpon_object(void)
Definition: data_model.c:153
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_set_vendor_module()

void dm_set_vendor_module ( const char *  name)

Set XPON.ModuleName to name.

Parameters
[in]namename of the vendor module, e.g. "mod-xpon-prpl".

The component should call this function once at startup, after determining which vendor module it should load.

Definition at line 178 of file data_model.c.

178  {
179 
180  amxd_object_t* xpon = dm_get_xpon_object();
181  when_null(xpon, exit);
182  if(amxd_object_set_value(cstring_t, xpon, "ModuleName", name)) {
183  SAH_TRACEZ_ERROR(ME, "Failed to update XPON.ModuleName");
184  }
185 exit:
186  return;
187 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dm_set_xpon_parameter_impl()

int dm_set_xpon_parameter_impl ( const amxc_var_t *const  args)

Update a parameter of the XPON object.

Parameters
[in]argsmust be htable with the keys 'name' and 'value'.
Returns
0 on success, else -1

Definition at line 1106 of file data_model.c.

1106  {
1107  int rc = -1;
1108  amxd_object_t* const xpon = dm_get_xpon_object();
1109  when_null(xpon, exit);
1110 
1111  const amxc_htable_t* const htable = amxc_var_constcast(amxc_htable_t, args);
1112  when_null_trace(htable, exit, ERROR, "args is not an htable");
1113 
1114  const char* const name = GET_CHAR(args, "name");
1115  when_null_trace(name, exit, ERROR, "Failed to get name");
1116 
1117  if(strncmp(name, "FsmState", 8) != 0) {
1118  SAH_TRACEZ_WARNING(ME, "dm_set_xpon_parameter() only supports XPON.FsmState");
1119  goto exit;
1120  }
1121 
1122  amxc_var_t* const value = GET_ARG(args, "value");
1123  when_null_trace(value, exit, ERROR, "Failed to get value");
1124 
1125  const amxd_status_t status = amxd_object_set_param(xpon, name, value);
1126  when_true_trace(status != amxd_status_ok, exit, ERROR,
1127  "Failed to update %s: status=%d", name, status);
1128  rc = 0;
1129 exit:
1130  return rc;
1131 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_nr_of_instances()

static uint32_t get_nr_of_instances ( const char *const  path)
static

Return the number of instances of a template object.

Parameters
[in]pathpath of a template object, e.g., "XPON.ONU" or "XPON.ONU.1.ANI"

Definition at line 1166 of file data_model.c.

1166  {
1167 
1168  uint32_t result = 0;
1169 
1170  amxd_dm_t* const dm = xpon_mngr_get_dm();
1171  when_null(dm, exit);
1172 
1173  const amxd_object_t* const object = amxd_dm_findf(dm, "%s", path);
1174  when_null_trace(object, exit, ERROR, "%s not found", path);
1175 
1176  result = amxd_object_get_instance_count(object);
1177 
1178 exit:
1179  return result;
1180 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_ref_to_params()

static bool get_ref_to_params ( const amxc_var_t *const  args,
const amxc_var_t **  params 
)
static

Definition at line 203 of file data_model.c.

204  {
205  bool rv = false;
206 
207  const amxc_var_t* const params_var =
208  amxc_var_get_key(args, "parameters", AMXC_VAR_FLAG_DEFAULT);
209  when_null_trace(params_var, exit, ERROR, "Failed to get 'parameters' from 'args'");
210 
211  const uint32_t params_type = amxc_var_type_of(params_var);
212  when_false_trace(AMXC_VAR_ID_HTABLE == params_type, exit, ERROR,
213  "Type of 'parameters' = %d != htable", params_type);
214 
215  *params = params_var;
216 
217  rv = true;
218 exit:
219  return rv;
220 }
Here is the caller graph for this function:

◆ init_dm_action_info()

static void init_dm_action_info ( dm_action_info_t *const  info)
static

Definition at line 141 of file data_model.c.

141  {
142 
143  info->path = NULL;
144  info->index = 0;
145  info->obj_id = obj_id_unknown;
146  info->key_value = NULL;
147  info->params = NULL;
148 }
@ obj_id_unknown
Definition: dm_info.h:91
Here is the caller graph for this function:

◆ prepare_adding_instance()

static bool prepare_adding_instance ( const char *const  path,
uint32_t  index,
amxd_object_t **  templ 
)
static

Prepare adding an instance to the XPON DM.

Parameters
[in]pathobject path of a template object, e.g. "XPON.ONU"
[in]indexindex of instance to be added
[in,out]templfunction assigns pointer to template object if instance does not yet exist
Returns
true on success and if instance does not yet exist, else false

Definition at line 389 of file data_model.c.

390  {
391 
392  bool rv = false;
393  when_null(path, exit);
394  when_null(templ, exit);
395 
396  amxd_dm_t* const dm = xpon_mngr_get_dm();
397  when_null(dm, exit);
398 
399  amxd_object_t* templ_candidate = amxd_dm_findf(dm, "%s", path);
400  when_null_trace(templ_candidate, exit, ERROR, "%s does not exist", path);
401 
402  const amxd_object_type_t type = amxd_object_get_type(templ_candidate);
403  when_false_trace(amxd_object_template == type, exit, ERROR,
404  "%s is not a template object", path);
405 
406  if(amxd_object_get_instance(templ_candidate, NULL, index) != NULL) {
407  SAH_TRACEZ_ERROR(ME, "%s.%d already exists", path, index);
408  goto exit;
409  }
410 
411  *templ = templ_candidate;
412  rv = true;
413 
414 exit:
415  return rv;
416 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_add_instance_args()

static bool process_add_instance_args ( const amxc_var_t *const  args,
dm_action_info_t info 
)
static

Process the arguments of dm_add_instance() function call.

Parameters
[in]argsmust be htable with keys specified by ADD_INST_PARAMS_REQUIRED. The htable normally also has an entry with the key 'parameters'.
[in,out]infothe function extracts info from args and assigns it to the fields of this parameter

It calls process_args_common() with args = ADD_INST_PARAMS_REQUIRED.

In addition it extracts the key value from args and assigns it info->key_value.

Returns
true on success, else false

Definition at line 326 of file data_model.c.

327  {
328 
329  bool rv = false;
330  SAH_TRACEZ_DEBUG2(ME, "called");
331 
334  goto exit;
335  }
336 
337  const object_id_t obj_id = info->obj_id;
338  const object_info_t* const obj_info = dm_get_object_info(obj_id);
339  when_null_trace(obj_info, exit, ERROR, "obj_info is NULL for obj_id=%d", obj_id);
340 
341  const char* key_name = obj_info->key_name; /* alias */
342 
343  const amxc_var_t* const keys_var = amxc_var_get_key(args, "keys", AMXC_VAR_FLAG_DEFAULT);
344  when_null_trace(keys_var, exit, ERROR, "%s.%d: failed to get 'keys' from args",
345  info->path, info->index);
346 
347  if(amxc_var_type_of(keys_var) != AMXC_VAR_ID_HTABLE) {
348  SAH_TRACEZ_ERROR(ME, "%s.%d: variant 'keys' is not an htable",
349  info->path, info->index);
350  goto exit;
351  }
352  amxc_var_t* key_value =
353  amxc_var_get_key(keys_var, key_name, AMXC_VAR_FLAG_DEFAULT);
354  when_null_trace(key_value, exit, ERROR, "%s.%d: failed to get value for key='%s'",
355  info->path, info->index, key_name);
356 
357  /* If the key name is "Name", its value is of type string, else its value
358  * is of type uint32_t. */
359  const bool key_is_uint32 =
360  strncmp(key_name, NAME_PARAM, NAME_PARAM_LEN) != 0;
361 
362  if(key_is_uint32) {
363  const uint32_t key_uint32 = amxc_var_constcast(uint32_t, key_value);
364  if(key_uint32 > obj_info->key_max_value) {
365  SAH_TRACEZ_ERROR(ME, "%s.%d: key: %s: value=%d > max=%d",
366  info->path, info->index, key_name, key_uint32,
367  obj_info->key_max_value);
368  goto exit;
369  }
370  }
371 
372  info->key_value = key_value;
373 
374  rv = true;
375 exit:
376  return rv;
377 }
#define ADD_INST_N_ARGS_REQUIRED
Definition: data_model.c:94
static const char * ADD_INST_PARAMS_REQUIRED[3]
Definition: data_model.c:95
enum _xpon_object_id object_id_t
#define NAME_PARAM
Definition: dm_info.h:76
#define NAME_PARAM_LEN
Definition: dm_info.h:77
uint32_t key_max_value
Definition: dm_info.h:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_args_common()

static bool process_args_common ( const amxc_var_t *const  args,
dm_action_info_t info,
const char **  keys_required,
int  n_keys_required 
)
static

Process the arguments of a function implemented in this file.

Parameters
[in]argsmust be htable with keys specified by keys_required
[in,out]infothe function extracts info from args and assigns it to the fields of this parameter
[in]keys_requiredlist of keys which must be present in args
[in]n_keys_requirednumber of elements in keys_required

args must always have an entry with key 'path'. The function assigns its value to info->path. It derives the object ID from the path with dm_get_object_id() and assigns it to info->obj_id.

If args contains entries with the key 'index' and/or 'parameters', the function assigns their values to info->index and info->params respectively.

The function returns false if one of the keys specified in keys_required does not occur in args.

Returns
true on success, else false

Definition at line 244 of file data_model.c.

247  {
248  bool rv = false;
249  uint32_t index = 0;
250  const amxc_var_t* params = NULL;
251 
252  SAH_TRACEZ_DEBUG2(ME, "called");
253 
254  when_null_trace(args, exit, ERROR, "args is NULL");
255 
256 #ifdef _DEBUG_
257  printf("tr181-xpon: process_args_common(): dump(args):\n");
258  amxc_var_dump(args, STDOUT_FILENO);
259 #endif
260 
261  init_dm_action_info(info);
262 
263  const amxc_htable_t* const htable = amxc_var_constcast(amxc_htable_t, args);
264  when_null_trace(htable, exit, ERROR, "args is not an htable");
265 
266  int i;
267  for(i = 0; i < n_keys_required; ++i) {
268  if(!amxc_htable_contains(htable, keys_required[i])) {
269  SAH_TRACEZ_ERROR(ME, "args does not contain key '%s'", keys_required[i]);
270  goto exit;
271  }
272  if((index == 0) && (strncmp(keys_required[i], "index", 5) == 0)) {
273  index = GET_UINT32(args, "index");
274  if(0 == index) {
275  SAH_TRACEZ_ERROR(ME, "Failed to get valid index");
276  goto exit;
277  }
278  }
279  }
280 
281  const char* const path = GET_CHAR(args, "path");
282  when_null_trace(path, exit, ERROR, "Failed to get path");
283 
284  const object_id_t obj_id = dm_get_object_id(path);
285  when_false_trace(obj_id_unknown != obj_id, exit, ERROR,
286  "path='%s': failed to get ID", path);
287 
288  /* Get 'index' if it's in 'args' even it's not required */
289  if((index == 0) && amxc_htable_contains(htable, "index")) {
290  index = GET_UINT32(args, "index");
291  if(0 == index) {
292  SAH_TRACEZ_ERROR(ME, "Failed to get valid index");
293  }
294  }
295 
296  info->path = path;
297  info->index = index;
298  info->obj_id = obj_id;
299 
300  if(amxc_htable_contains(htable, "parameters")) {
301  if(get_ref_to_params(args, &params)) {
302  info->params = params;
303  }
304  }
305  rv = true;
306 exit:
307  return rv;
308 }
static void init_dm_action_info(dm_action_info_t *const info)
Definition: data_model.c:141
static bool get_ref_to_params(const amxc_var_t *const args, const amxc_var_t **params)
Definition: data_model.c:203
object_id_t dm_get_object_id(const char *path)
Definition: dm_info.c:380
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_remove_instance_args()

static bool process_remove_instance_args ( const amxc_var_t *const  args,
dm_action_info_t info 
)
static

Process the arguments of dm_remove_instance() function call.

Parameters
[in]argsmust be htable with keys specified by REMOVE_INST_ARGS_REQUIRED
[in,out]infothe function extracts info from args and assigns it to the fields of this parameter
Returns
true on success, else false

Definition at line 669 of file data_model.c.

670  {
671 
672  bool rv = false;
673  SAH_TRACEZ_DEBUG2(ME, "called");
674 
677  goto exit;
678  }
679 
680  rv = true;
681 
682 exit:
683  return rv;
684 }
static const char * REMOVE_INST_ARGS_REQUIRED[2]
Definition: data_model.c:100
#define REMOVE_INST_N_ARGS_REQUIRED
Definition: data_model.c:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_all_instances()

static bool remove_all_instances ( amxd_object_t *  templ)
static

Remove all instances from a template object.

Parameters
[in]templtemplate object to remove all instances from

Example: template can refer to "XPON.ONU.1.ANI.1.TC.GEM.Port".

Returns
true on success, else false

Definition at line 958 of file data_model.c.

958  {
959 
960  bool rv = false;
961 
962  when_null(templ, exit_no_cleanup);
963 
964  amxd_dm_t* const dm = xpon_mngr_get_dm();
965  when_null(dm, exit_no_cleanup);
966 
967  if(amxd_object_get_type(templ) != amxd_object_template) {
968  SAH_TRACEZ_ERROR(ME, "Parameter 'templ' is not a template");
969  goto exit_no_cleanup;
970  }
971 
972  const uint32_t nr_instances = amxd_object_get_instance_count(templ);
973  if(0 == nr_instances) {
974  SAH_TRACEZ_DEBUG(ME, "No instances");
975  rv = true;
976  goto exit_no_cleanup;
977  }
978 
979  amxd_trans_t transaction;
980  amxd_trans_init(&transaction);
981  amxd_trans_set_attr(&transaction, amxd_tattr_change_ro, true);
982 
983  int rc = amxd_trans_select_object(&transaction, templ);
984  when_failed_trace(rc, exit, ERROR, "Failed to select template object");
985 
986  uint32_t index;
987  amxd_object_t* obj_inst = NULL;
988 
989  amxd_object_iterate(instance, it, templ) {
990  obj_inst = amxc_container_of(it, amxd_object_t, it);
991  index = amxd_object_get_index(obj_inst);
992  rc = amxd_trans_del_inst(&transaction, index, NULL);
993  when_failed_trace(rc, exit, ERROR, "Failed to add deletion to transaction");
994  }
995 
996  rc = amxd_trans_apply(&transaction, dm);
997  when_failed_trace(rc, exit, ERROR, "Failed to apply transaction (rc=%d)", rc);
998 
999  rv = true;
1000 
1001 exit:
1002  amxd_trans_clean(&transaction);
1003 
1004 exit_no_cleanup:
1005  return rv;
1006 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_instance()

static bool remove_instance ( const dm_action_info_t *const  info)
static

Remove an from instance from to the XPON DM.

Parameters
[in]infoall the info needed to remove the instance

The function logs a warning and returns true if the instance does not exist.

Returns
true on success, else false

Definition at line 695 of file data_model.c.

695  {
696 
697  bool rv = false;
698  amxd_object_t* obj;
699 
700  SAH_TRACEZ_INFO(ME, "Delete %s.%d", info->path, info->index);
701 
702  amxd_dm_t* const dm = xpon_mngr_get_dm();
703  when_null(dm, exit_no_cleanup);
704 
705  amxd_object_t* templ = amxd_dm_findf(dm, "%s", info->path);
706  if(!templ) {
707  SAH_TRACEZ_WARNING(ME, "Failed to find %s", info->path);
708  return true;
709  }
710 
711  const amxd_object_type_t type = amxd_object_get_type(templ);
712  when_false_trace(amxd_object_template == type, exit_no_cleanup, ERROR,
713  "%s is not a template object", info->path);
714 
715  obj = amxd_object_get_instance(templ, NULL, info->index);
716  if(!obj) {
717  SAH_TRACEZ_WARNING(ME, "Instance %s.%d does not exist", info->path,
718  info->index);
719  return true;
720  }
721 
722  amxd_trans_t transaction;
723  amxd_trans_init(&transaction);
724  amxd_trans_set_attr(&transaction, amxd_tattr_change_ro, true);
725 
726  amxd_status_t rc = amxd_trans_select_object(&transaction, templ);
727  when_failed_trace(rc, exit, ERROR, "Failed to select %s for transaction (rc=%d)",
728  info->path, rc);
729 
730  rc = amxd_trans_del_inst(&transaction, info->index, NULL);
731  when_failed_trace(rc, exit, ERROR,
732  "Failed to add %s.%d for deletion to transaction (rc=%d)",
733  info->path, info->index, rc);
734 
736  rc = amxd_trans_apply(&transaction, dm);
737  when_failed_trace(rc, exit, ERROR, "Failed to delete %s.%d (rc=%d)",
738  info->path, info->index, rc);
739 
740  SAH_TRACEZ_DEBUG(ME, "Deleted %s.%d", info->path, info->index);
741 
742  rv = true;
743 
744 exit:
745  amxd_trans_clean(&transaction);
747 
748 exit_no_cleanup:
749  return rv;
750 }
void dm_actions_set_ignore_param_reads(bool ignore)
Definition: dm_actions.c:124
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_ethernet_uni_status_to_down()

static void set_ethernet_uni_status_to_down ( const amxd_object_t *const  onu_instance,
const char *const  path 
)
static

For all EthernetUNI instances of the ONU, set Status to Down if it is Up now.

Definition at line 1011 of file data_model.c.

1012  {
1013 
1014  const amxd_object_t* ethernet_uni = amxd_object_get_child(onu_instance, "EthernetUNI");
1015  when_null_trace(ethernet_uni, exit, ERROR, "%s.EthernetUNI does not exist", path);
1016 
1017  char* current_status_cstr;
1018  amxd_object_iterate(instance, it, ethernet_uni) {
1019  amxd_object_t* const eth_uni_inst = amxc_container_of(it, amxd_object_t, it);
1020  if(NULL == eth_uni_inst) {
1021  SAH_TRACEZ_ERROR(ME, "Failed to get EthernetUNI object");
1022  continue;
1023  }
1024  current_status_cstr = amxd_object_get_value(cstring_t, eth_uni_inst, "Status", NULL);
1025  if(current_status_cstr) {
1026  if(strncmp(current_status_cstr, "Up", 2) == 0) {
1027  amxd_object_set_value(cstring_t, eth_uni_inst, "Status", "Down");
1028  }
1029  free(current_status_cstr);
1030  }
1031  }
1032 exit:
1033  return;
1034 }
Here is the caller graph for this function:

◆ update_enable()

static void update_enable ( amxd_trans_t *  transaction,
const char *const  path,
uint32_t  index 
)
static

Set the Enable param to true if the object is enabled according to persistency.

Also call rth_schedule_enable().

Parameters
[in]transactiontransaction which is going to add an instance
[in]pathobject path, e.g. "XPON.ONU"
[in]indexthe index of the object instance

Definition at line 505 of file data_model.c.

506  {
507 
508  when_false_trace(index != 0, exit, ERROR, "index is 0");
509 
510  amxc_string_t full_path;
511  amxc_string_init(&full_path, 0);
512  amxc_string_set(&full_path, path);
513  amxc_string_appendf(&full_path, ".%d", index);
514 
515  const char* const full_path_cstr = amxc_string_get(&full_path, 0);
516 
517  if(persistency_is_enabled(full_path_cstr)) {
518  amxc_var_t enabled;
519  amxc_var_init(&enabled);
520  amxc_var_set(bool, &enabled, true);
521  amxd_trans_set_param(transaction, ENABLE_PARAM, &enabled);
522  amxc_var_clean(&enabled);
523 
524  rth_schedule_enable(full_path_cstr);
525  }
526  amxc_string_clean(&full_path);
527 
528 exit:
529  return;
530 }
#define ENABLE_PARAM
Definition: dm_info.h:74
bool persistency_is_enabled(const char *const object)
Definition: persistency.c:280
void rth_schedule_enable(const char *const object)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ADD_INST_PARAMS_REQUIRED

const char* ADD_INST_PARAMS_REQUIRED[3]
static
Initial value:
= {
"path", "index", "keys"
}

Definition at line 95 of file data_model.c.

◆ ADD_OR_CHANGE_INST_ARGS_REQUIRED

const char* ADD_OR_CHANGE_INST_ARGS_REQUIRED[2]
static
Initial value:
= {
"path", "index"
}

Definition at line 110 of file data_model.c.

◆ CHANGE_OBJ_ARGS_REQUIRED

const char* CHANGE_OBJ_ARGS_REQUIRED[2]
static
Initial value:
= {
"path", "parameters"
}

Definition at line 105 of file data_model.c.

◆ REMOVE_INST_ARGS_REQUIRED

const char* REMOVE_INST_ARGS_REQUIRED[2]
static
Initial value:
= {
"path", "index"
}

Definition at line 100 of file data_model.c.