TR181-XPON  1.4.0
TR-181 PON manager.
restore_to_hal.c File Reference
#include "restore_to_hal.h"
#include <stdlib.h>
#include <string.h>
#include <amxc/amxc_macros.h>
#include <amxc/amxc.h>
#include <amxp/amxp_timer.h>
#include "data_model.h"
#include "dm_info.h"
#include "pon_ctrl.h"
#include "xpon_mgr_constants.h"
#include "xpon_trace.h"

Go to the source code of this file.

Data Structures

struct  _rth_task
 

Typedefs

typedef struct _rth_task rth_task_t
 

Functions

static void rth_task_clean (rth_task_t *const task)
 
static rth_task_trth_task_create (const char *const path)
 
static void rth_task_delete (amxc_llist_it_t *hit)
 
static void handle_rth_tasks (amxp_timer_t *timer, UNUSED void *priv)
 
void rth_init (void)
 
void rth_cleanup (void)
 
void rth_schedule_enable (const char *const object)
 
void rth_disable (const char *const object)
 

Variables

static amxc_llist_t s_rth_tasks
 
static amxp_timer_t * s_timer_handle_rth_tasks = NULL
 
static const uint8_t MAX_CHECKS_ON_NR_OF_UNIS_AND_ANIS = 4
 

Typedef Documentation

◆ rth_task_t

typedef struct _rth_task rth_task_t

Task to enable an object in the HAL.

  • path: path of object to be enabled, e.g. "XPON.ONU.1"
  • cntr: when enabling an XPON.ONU instance, tr181-xpon waits for a few seconds until the XPON.ONU instance has at least one EthernetUNI instance and one ANI instance. Enabling the XPON.ONU instance before tr181-xpon has discovered its EthernetUNI or ANI instance(s) might cause errors. E.g. the vendor module might already try to update the Status field of the EthernetUNI instance. This counter keeps track of how many times tr181-xpon checked the number of EthernetUNIs and ANIs of the XPON.ONU instance given by 'path'. If the counter goes above MAX_CHECKS_ON_NR_OF_UNIS_AND_ANIS, tr181-xpon enables the XPON.UNI instance even if its number of EthernetUNIs or ANIs is still 0. The field 'cntr' tracks more or less a number of seconds. By setting the MAX_CHECKS value to 4, tr181-xpon waits max about 4 to 5 seconds for both an EthernetUNI and ANI to appear. If 'path' refers to something else than an XPON.ONU instance, this counter is don't care.
  • it: iterator to put it in s_rth_tasks

Function Documentation

◆ handle_rth_tasks()

static void handle_rth_tasks ( amxp_timer_t *  timer,
UNUSED void *  priv 
)
static

Handle all tasks in the list s_rth_tasks to restore their Enable=1 setting.

For each task in the list, do the following:

  • If the path in the task does not refer to an XPON.ONU instance, call pon_ctrl_set_enable(), remove the task from the list and delete it.
  • If the path in the task refers to an XPON.ONU instance, check its number of EthernetUNIs and ANIs. If they are both non zero, or if the 'cntr' field of the task is larger than MAX_CHECKS_ON_NR_OF_UNIS_AND_ANIS, call pon_ctrl_set_enable(), remove the task from the list and delete it. Else increment the field 'cntr' and keep the task in the list. See doc of field 'cntr' of 'struct _rth_task' above for more info on this behavior.

Restart timer with timeout of 1 s if there are still tasks in the list.

Definition at line 177 of file restore_to_hal.c.

177  {
178 
179  if(amxc_llist_is_empty(&s_rth_tasks)) {
180  SAH_TRACEZ_WARNING(ME, "No tasks");
181  return;
182  }
183 
184  rth_task_t* task;
185  const char* path;
186  object_id_t id;
187  bool delete_item;
188  uint32_t n_ethernet_unis;
189  uint32_t n_anis;
190  amxc_llist_for_each(it, &s_rth_tasks) {
191  delete_item = true;
192  task = amxc_llist_it_get_data(it, rth_task_t, it);
193  path = amxc_string_get(&task->path, 0);
194  id = dm_get_object_id(path);
195  SAH_TRACEZ_DEBUG(ME, "path='%s'", path);
196  if(obj_id_onu == id) {
197  n_ethernet_unis = dm_get_nr_of_ethernet_uni_instances(path);
198  n_anis = dm_get_nr_of_ani_instances(path);
199  SAH_TRACEZ_DEBUG(ME, "path='%s' n_ethernet_unis=%d n_anis=%d cntr=%d",
200  path, n_ethernet_unis, n_anis, task->cntr);
201  if((n_ethernet_unis != 0) && (n_anis != 0)) {
202  pon_ctrl_set_enable(path, /*enable=*/ true);
203  } else if(task->cntr > MAX_CHECKS_ON_NR_OF_UNIS_AND_ANIS) {
204  SAH_TRACEZ_WARNING(ME, "Enable %s despite n_ethernet_unis=%d n_anis=%d",
205  path, n_ethernet_unis, n_anis);
206  pon_ctrl_set_enable(path, /*enable=*/ true);
207  } else {
208  ++task->cntr;
209  delete_item = false;
210  }
211  } else {
212  pon_ctrl_set_enable(path, /*enable=*/ true);
213  }
214  if(delete_item) {
215  amxc_llist_it_take(it);
216  rth_task_clean(task);
217  free(task);
218  }
219  }
220  if(!amxc_llist_is_empty(&s_rth_tasks)) {
221  amxp_timer_start(timer, /*timeout_msec=*/ 1000);
222  }
223 }
uint32_t dm_get_nr_of_ani_instances(const char *const onu_path)
Definition: data_model.c:1198
uint32_t dm_get_nr_of_ethernet_uni_instances(const char *const onu_path)
Definition: data_model.c:1187
object_id_t dm_get_object_id(const char *path)
Definition: dm_info.c:380
enum _xpon_object_id object_id_t
@ obj_id_onu
Definition: dm_info.h:80
void pon_ctrl_set_enable(const char *const path, bool enable)
Definition: pon_ctrl.c:153
static const uint8_t MAX_CHECKS_ON_NR_OF_UNIS_AND_ANIS
static amxc_llist_t s_rth_tasks
static void rth_task_clean(rth_task_t *const task)
amxc_string_t path
uint8_t cntr
#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:

◆ rth_cleanup()

void rth_cleanup ( void  )

Definition at line 234 of file restore_to_hal.c.

234  {
235  if(!amxc_llist_is_empty(&s_rth_tasks)) {
236  /* Normally s_rth_tasks should be empty upon stopping */
237  SAH_TRACEZ_WARNING(ME, "size(s_rth_tasks)=%zd != 0",
238  amxc_llist_size(&s_rth_tasks));
239  amxc_llist_clean(&s_rth_tasks, rth_task_delete);
240  }
241  amxp_timer_delete(&s_timer_handle_rth_tasks);
242 }
static void rth_task_delete(amxc_llist_it_t *hit)
static amxp_timer_t * s_timer_handle_rth_tasks
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rth_disable()

void rth_disable ( const char *const  object)

Remove task to enable an object in the HAL if such task exists.

Parameters
[in]objectobject path, e.g. "XPON.ONU.1"

Definition at line 286 of file restore_to_hal.c.

286  {
287  if(amxc_llist_is_empty(&s_rth_tasks)) {
288  return;
289  }
290  rth_task_t* task;
291  const char* path;
292  amxc_llist_for_each(it, &s_rth_tasks) {
293  task = amxc_llist_it_get_data(it, rth_task_t, it);
294  path = amxc_string_get(&task->path, 0);
295  if(strcmp(object, path) == 0) {
296  amxc_llist_it_take(it);
297  rth_task_delete(it);
298  break; /* out of iteration over s_rth_tasks */
299  }
300  }
301 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rth_init()

void rth_init ( void  )

Definition at line 226 of file restore_to_hal.c.

226  {
227  amxc_llist_init(&s_rth_tasks);
228 
229  if(amxp_timer_new(&s_timer_handle_rth_tasks, handle_rth_tasks, NULL)) {
230  SAH_TRACEZ_ERROR(ME, "Failed to create timer to handle tasks");
231  }
232 }
static void handle_rth_tasks(amxp_timer_t *timer, UNUSED void *priv)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rth_schedule_enable()

void rth_schedule_enable ( const char *const  object)

Schedule task to enable an object in the HAL.

Parameters
[in]objectobject path, e.g. "XPON.ONU.1"

The function creates a task to enable the object in the HAL, appends it to the list of tasks managed by this restore_to_hal part, and starts the timer to handle all tasks in that list.

If there is already a task in the list to enable the object, the function immediately returns.

Definition at line 256 of file restore_to_hal.c.

256  {
257 
258  SAH_TRACEZ_DEBUG(ME, "object='%s'", object);
259 
260  when_null_trace(s_timer_handle_rth_tasks, exit, ERROR, "No timer");
261 
262  const rth_task_t* task;
263  const char* path;
264  amxc_llist_iterate(it, &s_rth_tasks) {
265  task = amxc_llist_it_get_data(it, rth_task_t, it);
266  path = amxc_string_get(&task->path, 0);
267  if(strncmp(path, object, strlen(object)) == 0) {
268  SAH_TRACEZ_DEBUG(ME, "%s is already scheduled to be enabled", object);
269  return;
270  }
271  }
272 
273  if(rth_task_create(object) != NULL) {
274  amxp_timer_start(s_timer_handle_rth_tasks, SHORT_TIMEOUT_MS);
275  }
276 
277 exit:
278  return;
279 }
static rth_task_t * rth_task_create(const char *const path)
#define SHORT_TIMEOUT_MS
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rth_task_clean()

static void rth_task_clean ( rth_task_t *const  task)
static

Definition at line 120 of file restore_to_hal.c.

120  {
121  amxc_string_clean(&task->path);
122 }
Here is the caller graph for this function:

◆ rth_task_create()

static rth_task_t* rth_task_create ( const char *const  path)
static

Create task and append it to 's_rth_tasks'.

If it fails to create the task or to append the task to 's_rth_tasks', the function is a no-op.

Returns
task created on success, else NULL

Definition at line 132 of file restore_to_hal.c.

132  {
133 
134  rth_task_t* task = (rth_task_t*) calloc(1, sizeof(rth_task_t));
135  when_null_trace(task, exit, ERROR, "Failed to allocate memory");
136 
137  amxc_string_init(&task->path, 0);
138  amxc_string_set(&task->path, path);
139 
140  if(amxc_llist_append(&s_rth_tasks, &task->it)) {
141  SAH_TRACEZ_ERROR(ME, "Failed to append task to 's_rth_tasks'");
142  SAH_TRACEZ_ERROR(ME, " path='%s'", path);
143  rth_task_clean(task);
144  free(task);
145  task = NULL;
146  }
147 
148 exit:
149  return task;
150 }
amxc_llist_it_t it
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rth_task_delete()

static void rth_task_delete ( amxc_llist_it_t *  hit)
static

Definition at line 152 of file restore_to_hal.c.

152  {
153  rth_task_t* task = amxc_container_of(hit, rth_task_t, it);
154  const char* path = amxc_string_get(&task->path, 0);
155  SAH_TRACEZ_DEBUG(ME, "path='%s'", path);
156  rth_task_clean(task);
157  free(task);
158 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ MAX_CHECKS_ON_NR_OF_UNIS_AND_ANIS

const uint8_t MAX_CHECKS_ON_NR_OF_UNIS_AND_ANIS = 4
static

Definition at line 88 of file restore_to_hal.c.

◆ s_rth_tasks

amxc_llist_t s_rth_tasks
static

Definition at line 83 of file restore_to_hal.c.

◆ s_timer_handle_rth_tasks

amxp_timer_t* s_timer_handle_rth_tasks = NULL
static

Definition at line 86 of file restore_to_hal.c.