72 #include <amxc/amxc.h>
79 #include <amxp/amxp.h>
80 #include <amxd/amxd_object.h>
81 #include <amxd/amxd_transaction.h>
94 #define ADD_INST_N_ARGS_REQUIRED 3
96 "path",
"index",
"keys"
99 #define REMOVE_INST_N_ARGS_REQUIRED 2
104 #define CHANGE_OBJ_N_ARGS_REQUIRED 2
109 #define ADD_OR_CHANGE_INST_N_ARGS_REQUIRED 2
157 SAH_TRACEZ_ERROR(
ME,
"Failed to get DM");
162 amxd_object_t* xpon = amxd_dm_get_object(
dm,
"XPON");
164 SAH_TRACEZ_ERROR(
ME,
"Failed to 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");
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");
204 const amxc_var_t** params) {
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'");
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);
215 *params = params_var;
246 const char** keys_required,
247 int n_keys_required) {
250 const amxc_var_t* params = NULL;
254 when_null_trace(args, exit, ERROR,
"args is NULL");
257 printf(
"tr181-xpon: process_args_common(): dump(args):\n");
258 amxc_var_dump(args, STDOUT_FILENO);
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");
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]);
272 if((index == 0) && (strncmp(keys_required[i],
"index", 5) == 0)) {
273 index = GET_UINT32(args,
"index");
275 SAH_TRACEZ_ERROR(
ME,
"Failed to get valid index");
281 const char*
const path = GET_CHAR(args,
"path");
282 when_null_trace(path, exit, ERROR,
"Failed to get path");
286 "path='%s': failed to get ID", path);
289 if((index == 0) && amxc_htable_contains(htable,
"index")) {
290 index = GET_UINT32(args,
"index");
292 SAH_TRACEZ_ERROR(
ME,
"Failed to get valid index");
300 if(amxc_htable_contains(htable,
"parameters")) {
339 when_null_trace(obj_info, exit, ERROR,
"obj_info is NULL for obj_id=%d", obj_id);
341 const char* key_name = obj_info->
key_name;
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",
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",
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'",
359 const bool key_is_uint32 =
363 const uint32_t key_uint32 = amxc_var_constcast(uint32_t, key_value);
365 SAH_TRACEZ_ERROR(
ME,
"%s.%d: key: %s: value=%d > max=%d",
366 info->
path, info->
index, key_name, key_uint32,
390 amxd_object_t** templ) {
393 when_null(path, exit);
394 when_null(templ, exit);
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);
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);
406 if(amxd_object_get_instance(templ_candidate, NULL, index) != NULL) {
407 SAH_TRACEZ_ERROR(
ME,
"%s.%d already exists", path, index);
411 *templ = templ_candidate;
431 const amxc_var_t*
const params,
435 const amxc_htable_t*
const params_table = amxc_var_constcast(amxc_htable_t, params);
436 when_null(params_table, exit);
439 when_null(obj_info, exit);
446 SAH_TRACEZ_ERROR(
ME,
"%s: failed to get info about its params", obj_info->
name);
450 amxc_var_t* param_value = NULL;
454 amxc_htable_for_each(it, params_table) {
456 key = amxc_htable_it_get_key(it);
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 = ¶m_info[i];
467 if(NULL == single_param) {
468 SAH_TRACEZ_WARNING(
ME,
"%s: unknown param name: %s", obj_info->
name, key);
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);
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),
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);
487 obj_info->
name, key);
506 const char*
const path, uint32_t index) {
508 when_false_trace(index != 0, exit, ERROR,
"index is 0");
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);
515 const char*
const full_path_cstr = amxc_string_get(&full_path, 0);
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);
526 amxc_string_clean(&full_path);
545 amxd_object_t* templ = amxd_dm_findf(
dm,
"%s", path);
546 when_null_trace(templ, exit, ERROR,
"Failed to find %s", path);
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);
592 amxd_object_t* templ = NULL;
594 SAH_TRACEZ_INFO(
ME,
"Create %s.%d", info->
path, info->
index);
597 when_null_trace(obj_info, exit_no_cleanup, ERROR,
598 "obj_info is NULL for obj_id=%d", info->
obj_id);
605 when_null(
dm, exit_no_cleanup);
607 amxd_trans_t transaction;
608 amxd_trans_init(&transaction);
609 amxd_trans_set_attr(&transaction, amxd_tattr_change_ro,
true);
611 const char*
const key_name = obj_info->
key_name;
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)",
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)",
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);
634 rc = amxd_trans_apply(&transaction,
dm);
635 when_failed_trace(rc, exit, ERROR,
"Failed to create %s.%d (rc=%d)",
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);
647 amxc_string_clean(&ani_instance);
653 amxd_trans_clean(&transaction);
700 SAH_TRACEZ_INFO(
ME,
"Delete %s.%d", info->
path, info->
index);
703 when_null(
dm, exit_no_cleanup);
705 amxd_object_t* templ = amxd_dm_findf(
dm,
"%s", info->
path);
707 SAH_TRACEZ_WARNING(
ME,
"Failed to find %s", info->
path);
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);
715 obj = amxd_object_get_instance(templ, NULL, info->
index);
717 SAH_TRACEZ_WARNING(
ME,
"Instance %s.%d does not exist", info->
path,
722 amxd_trans_t transaction;
723 amxd_trans_init(&transaction);
724 amxd_trans_set_attr(&transaction, amxd_tattr_change_ro,
true);
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)",
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)",
736 rc = amxd_trans_apply(&transaction,
dm);
737 when_failed_trace(rc, exit, ERROR,
"Failed to delete %s.%d (rc=%d)",
745 amxd_trans_clean(&transaction);
837 amxc_string_init(&path, 0);
838 amxc_string_set(&path, info.
path);
844 amxc_string_appendf(&path,
".%d", info.
index);
846 const char*
const path_cstr = amxc_string_get(&path, 0);
848 amxd_object_t*
object = amxd_dm_findf(
dm,
"%s", path_cstr);
850 SAH_TRACEZ_WARNING(
ME,
"%s does not exist: ignore object-changed", path_cstr);
851 amxc_string_clean(&path);
856 amxd_trans_t transaction;
857 amxd_trans_init(&transaction);
858 amxd_trans_set_attr(&transaction, amxd_tattr_change_ro,
true);
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)",
868 if(object->priv == NULL) {
877 status = amxd_trans_apply(&transaction,
dm);
878 when_failed_trace(status, exit_cleanup, ERROR,
"Failed to update %s (status=%d)",
884 amxc_string_clean(&path);
885 amxd_trans_clean(&transaction);
962 when_null(templ, exit_no_cleanup);
965 when_null(
dm, exit_no_cleanup);
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;
972 const uint32_t nr_instances = amxd_object_get_instance_count(templ);
973 if(0 == nr_instances) {
976 goto exit_no_cleanup;
979 amxd_trans_t transaction;
980 amxd_trans_init(&transaction);
981 amxd_trans_set_attr(&transaction, amxd_tattr_change_ro,
true);
983 int rc = amxd_trans_select_object(&transaction, templ);
984 when_failed_trace(rc, exit, ERROR,
"Failed to select template object");
987 amxd_object_t* obj_inst = NULL;
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");
996 rc = amxd_trans_apply(&transaction,
dm);
997 when_failed_trace(rc, exit, ERROR,
"Failed to apply transaction (rc=%d)", rc);
1002 amxd_trans_clean(&transaction);
1012 const char*
const path) {
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);
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");
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");
1029 free(current_status_cstr);
1055 when_null_trace(args, exit, ERROR,
"args is NULL");
1058 when_null(
dm, exit);
1060 const uint32_t index = GET_UINT32(args,
"index");
1061 when_false_trace(index != 0, exit, ERROR,
"Failed to extract valid index from args");
1064 snprintf(path, 16,
"XPON.ONU.%d", index);
1065 const amxd_object_t* onu_instance = amxd_dm_findf(
dm,
"%s", path);
1067 SAH_TRACEZ_WARNING(
ME,
"%s does not exist: ignore omci:reset-mib", path);
1075 const amxd_object_t* ani = amxd_object_get_child(onu_instance,
"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");
1081 SAH_TRACEZ_ERROR(
ME,
"%s: failed to find TC.GEM.Port for ANI.%d",
1082 path, amxd_object_get_index(ani_inst));
1086 SAH_TRACEZ_ERROR(
ME,
"%s: failed to delete GEM ports for ANI.%d",
1087 path, amxd_object_get_index(ani_inst));
1091 SAH_TRACEZ_ERROR(
ME,
"%s.ANI does not exist", path);
1109 when_null(xpon, exit);
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");
1114 const char*
const name = GET_CHAR(args,
"name");
1115 when_null_trace(name, exit, ERROR,
"Failed to get name");
1117 if(strncmp(name,
"FsmState", 8) != 0) {
1118 SAH_TRACEZ_WARNING(
ME,
"dm_set_xpon_parameter() only supports XPON.FsmState");
1122 amxc_var_t*
const value = GET_ARG(args,
"value");
1123 when_null_trace(value, exit, ERROR,
"Failed to get value");
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);
1145 when_null(
dm, exit);
1147 const amxd_object_t*
const templ = amxd_dm_findf(
dm,
"%s", path);
1152 if(amxd_object_get_instance(templ, NULL, index)) {
1168 uint32_t result = 0;
1171 when_null(
dm, exit);
1173 const amxd_object_t*
const object = amxd_dm_findf(
dm,
"%s", path);
1174 when_null_trace(
object, exit, ERROR,
"%s not found", path);
1176 result = amxd_object_get_instance_count(
object);
1189 snprintf(path, 64,
"%s.EthernetUNI", onu_path);
1200 snprintf(path, 64,
"%s.ANI", onu_path);
1208 when_null(
dm, exit);
1210 amxd_object_t*
const param_object = amxd_dm_findf(
dm,
"%s", path);
1212 SAH_TRACEZ_WARNING(
ME,
"%s does not exist!", path);
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);
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);
1245 when_null(
dm, exit);
1246 when_null(is_hex, exit);
1249 const char*
const ani_auth_path_cstr = amxc_string_get(&ani_auth_path, 0);
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);
1255 if(amxd_status_ok != amxd_object_get_param(
object,
"HexadecimalPassword",
1257 SAH_TRACEZ_ERROR(
ME,
"Failed to get %s.HexadecimalPassword",
1258 ani_auth_path_cstr);
1262 *is_hex = amxc_var_constcast(
bool, &is_hex_variant);
1266 amxc_var_clean(&is_hex_variant);
1267 amxc_string_clean(&ani_auth_path);
1283 amxc_var_t pon_mode_var;
1284 amxc_var_init(&pon_mode_var);
1287 when_null(
dm, exit);
1288 when_null(pon_mode, exit);
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);
1293 if(amxd_status_ok != amxd_object_get_param(
object,
"PONMode",
1295 SAH_TRACEZ_ERROR(
ME,
"Failed to get %s.PONMode", ani_path);
1299 const char*
const pon_mode_cstr = amxc_var_constcast(cstring_t, &pon_mode_var);
1300 if(strncmp(pon_mode_cstr,
"Unknown", 7) == 0) {
1302 }
else if(strncmp(pon_mode_cstr,
"G-PON", 5) == 0) {
1304 }
else if(strncmp(pon_mode_cstr,
"XG-PON", 6) == 0) {
1306 }
else if(strncmp(pon_mode_cstr,
"NG-PON2", 7) == 0) {
1308 }
else if(strncmp(pon_mode_cstr,
"XGS-PON", 7) == 0) {
1311 SAH_TRACEZ_ERROR(
ME,
"Invalid PON mode: %s", pon_mode_cstr);
1319 amxc_var_clean(&pon_mode_var);
void ani_append_tc_authentication(const char *const ani_path, amxc_string_t *const ani_auth_path)
void dm_set_module_error(void)
static bool prepare_adding_instance(const char *const path, uint32_t index, amxd_object_t **templ)
bool dm_is_hex_password(const char *const ani_path, bool *is_hex)
uint32_t dm_get_nr_of_ani_instances(const char *const onu_path)
int dm_omci_reset_mib(const amxc_var_t *const args)
static amxd_object_t * dm_get_xpon_object(void)
#define CHANGE_OBJ_N_ARGS_REQUIRED
#define ADD_OR_CHANGE_INST_N_ARGS_REQUIRED
static void update_enable(amxd_trans_t *transaction, const char *const path, uint32_t index)
int dm_change_object(const amxc_var_t *const args)
static bool process_add_instance_args(const amxc_var_t *const args, dm_action_info_t *info)
int dm_add_or_change_instance_impl(const amxc_var_t *const args)
static bool process_remove_instance_args(const amxc_var_t *const args, dm_action_info_t *info)
static const char * REMOVE_INST_ARGS_REQUIRED[2]
#define REMOVE_INST_N_ARGS_REQUIRED
static const char * ADD_OR_CHANGE_INST_ARGS_REQUIRED[2]
static void init_dm_action_info(dm_action_info_t *const info)
static bool remove_all_instances(amxd_object_t *templ)
static const char * CHANGE_OBJ_ARGS_REQUIRED[2]
static void set_ethernet_uni_status_to_down(const amxd_object_t *const onu_instance, const char *const path)
int dm_remove_instance(const amxc_var_t *const args)
int dm_set_xpon_parameter_impl(const amxc_var_t *const args)
int dm_add_instance(const amxc_var_t *const args)
static bool add_instance(const dm_action_info_t *const info)
uint32_t dm_get_nr_of_ethernet_uni_instances(const char *const onu_path)
static bool get_ref_to_params(const amxc_var_t *const args, const amxc_var_t **params)
static uint32_t get_nr_of_instances(const char *const path)
#define ADD_INST_N_ARGS_REQUIRED
static const char * ADD_INST_PARAMS_REQUIRED[3]
static bool add_params_to_transaction(amxd_trans_t *transaction, const amxc_var_t *const params, object_id_t id)
bool dm_does_instance_exist(const char *const path, uint32_t index)
static void add_private_data_to_onu(const char *const path, uint32_t index)
static bool process_args_common(const amxc_var_t *const args, dm_action_info_t *info, const char **keys_required, int n_keys_required)
struct _dm_action_info dm_action_info_t
bool dm_get_ani_pon_mode(const char *const ani_path, pon_mode_t *pon_mode)
static bool remove_instance(const dm_action_info_t *const info)
bool dm_get_param(const char *path, const char *name, amxc_var_t *resp)
void dm_set_vendor_module(const char *name)
void dm_actions_set_ignore_param_reads(bool ignore)
bool dm_get_object_param_info(object_id_t id, const param_info_t **param_info, uint32_t *size)
object_id_t dm_get_object_id(const char *path)
enum _xpon_object_id object_id_t
const object_info_t * dm_get_object_info(object_id_t id)
amxd_dm_t *PRIVATE xpon_mngr_get_dm(void)
void onu_priv_attach_private_data(amxd_object_t *const object)
void passwd_restore_password(const char *const ani_path)
bool persistency_is_enabled(const char *const object)
enum _pon_mode pon_mode_t
void rth_schedule_enable(const char *const object)
const amxc_var_t * params
#define SAH_TRACEZ_DEBUG(zone, format,...)
#define SAH_TRACEZ_DEBUG2(zone, format,...)