TR181-XPON  1.4.0
TR-181 PON manager.
data_model.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <amxc/amxc_variant.h>
#include "pon_mode.h"

Go to the source code of this file.

Functions

void dm_set_vendor_module (const char *name)
 
void dm_set_module_error (void)
 
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)
 
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 *path, uint32_t index)
 
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)
 

Detailed Description

Functionality related to accessing (set/get) the TR-181 XPON DM.

Definition in file data_model.h.

Function Documentation

◆ 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
#define ME
Definition: xpon_trace.h:78
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
amxd_dm_t *PRIVATE xpon_mngr_get_dm(void)
const char * path
Definition: data_model.c:134
uint32_t index
Definition: data_model.c:135
on event dm
#define SAH_TRACEZ_DEBUG(zone, format,...)
Definition: xpon_trace.h:115
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 void update_enable(amxd_trans_t *transaction, const char *const path, uint32_t index)
Definition: data_model.c:505
static const char * CHANGE_OBJ_ARGS_REQUIRED[2]
Definition: data_model.c:105
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
@ obj_id_onu
Definition: dm_info.h:80
void onu_priv_attach_private_data(amxd_object_t *const object)
Definition: onu_priv.c:77
object_id_t obj_id
Definition: data_model.c:136
const amxc_var_t * params
Definition: data_model.c:138
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_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: