diff --git a/README.md b/README.md index 52ba96f6e33ea44cf5d9a13d676cffe2e94b39e8..c4160a5a77a8de8c5e6388d26549c1c74179e3b8 100644 --- a/README.md +++ b/README.md @@ -82,17 +82,29 @@ root@iopsys:~$ ubus call topology dump } #To show the topology changelogs - -root@iopsys:~$ ubus call topology changelog +root@iopsys:~# ubus call topology changelog { - "changelog": [ - { - <TODO> - }, - { - <TODO> - } - ] + "num_changelog": 2, + "changelog": [ + { + "reporter": "00:22:07:6d:3d:8e", + "reporter_interface": "00:22:07:70:f5:6c", + "neighbor": "00:22:07:6d:3d:8e", + "is1905_neighbor": "true", + "event_type": "add", + "timestamp": "2020-07-06T11:51:54" + }, + { + "reporter": "00:22:07:ae:ed:fd", + "reporter_interface": "00:22:07:70:f5:6c", + "neighbor": "00:22:07:ae:ed:fd", + "is1905_neighbor": "true", + "event_type": "add", + "timestamp": "2020-07-06T11:56:01" + } + ] } + ```` ### Testing diff --git a/src/topologyd.c b/src/topologyd.c index e326041683c5d4d6690f11b32c1a2e71b22388ae..0a6e2f0dc936e84c62015fdeea4ede7d845326e5 100644 --- a/src/topologyd.c +++ b/src/topologyd.c @@ -25,6 +25,7 @@ static int signal_pending; extern int refresh_int; extern const char *ubus_socket; +uint32_t topology_log_max; static void topologyd_sighandler(int sig) { @@ -296,13 +297,16 @@ void topologyd_print_changelog(struct blob_buf *bb, struct topologyd_private *pr char rpt_ifmacstr[18] = { 0 }; char rpt_macstr[18] = { 0 }; char nbr_macstr[18] = { 0 }; - char *timestring; void *t; int i; struct tm *info; time_t tmp_t; + char str_tm[20]; dbg("changelog start value is [%d] end value is [%d]", start, end); + if (bb == NULL || priv == NULL) + return; + for (i = start ; i <= end ; i++) { log = &priv->topo.changelog[i]; t = blobmsg_open_table(bb, NULL); @@ -324,8 +328,8 @@ void topologyd_print_changelog(struct blob_buf *bb, struct topologyd_private *pr tmp_t = log->timestamp; info = localtime(&tmp_t); - timestring = asctime(info); - blobmsg_add_string(bb, "timestamp", timestring); + strftime(str_tm, sizeof str_tm, "%Y-%m-%dT%H:%M:%S", info); + blobmsg_add_string(bb, "timestamp", str_tm); blobmsg_close_table(bb, t); } } @@ -340,7 +344,7 @@ void topologyd_dump_changelog(struct topologyd_private *priv, struct blob_buf *b return; } if(priv->topo.changelog_front > priv->topo.changelog_rear) { - topologyd_print_changelog(bb, priv, priv->topo.changelog_front, TOPOLOGY_LOG_MAX-1); + topologyd_print_changelog(bb, priv, priv->topo.changelog_front, topology_log_max-1); topologyd_print_changelog(bb, priv, 0, priv->topo.changelog_rear); } else { @@ -406,6 +410,17 @@ static void topologyd_periodic_refresh(struct uloop_timeout *t) uloop_timeout_set(&priv->refresh_timer, priv->refresh_int * 1000); } +static void topologyd_change_status(struct uloop_timeout *t) +{ + struct topologyd_private *priv = + container_of(t, struct topologyd_private, status_timer); + + dbg("Change the status of topology...\n"); + priv->status = 1; + +} + + static void topologyd_start_heartbeat(struct uloop_timeout *t) { struct topologyd_private *priv = @@ -441,9 +456,10 @@ static int topologyd_run(struct topologyd_private *priv) if(priv->refresh_int == 0) priv->refresh_int = TOPOLOGY_REFRESH_INT; - + topologyd_start_heartbeat(&priv->heartbeat); topologyd_periodic_refresh(&priv->refresh_timer); + uloop_timeout_set(&priv->status_timer, 90*1000); //initalize the changelog values priv->topo.changelog_front = priv->topo.changelog_rear = -1; @@ -558,6 +574,13 @@ int topologyd_start(void) priv->refresh_timer.cb = topologyd_periodic_refresh; priv->heartbeat.cb = topologyd_start_heartbeat; + priv->topo.changelog = (struct topology_changelog*) malloc + ((priv->config.maxlog)*sizeof(struct topology_changelog)); + topology_log_max = priv->config.maxlog; + dbg("Dynamic array size %d",priv->config.maxlog); + + priv->status = 0; + priv->status_timer.cb = topologyd_change_status; if (!priv->config.enabled) { info("topologyd not enabled.\n"); @@ -593,7 +616,7 @@ void topologyd_stop(struct topologyd_private *priv) // Check if the changelog queue is full int is_full(struct topology *t) { - if ((t->changelog_front == t->changelog_rear + 1) || (t->changelog_front == 0 && t->changelog_rear == TOPOLOGY_LOG_MAX - 1)) + if ((t->changelog_front == t->changelog_rear + 1) || (t->changelog_front == 0 && t->changelog_rear == topology_log_max - 1)) return 1; return 0; } @@ -605,13 +628,13 @@ void enqueue_changelog(struct topology *t, struct topology_changelog *c) struct topology_changelog *elem; if (is_full(t)) { dbg("Changelog queue is full deleting the front node \n"); - t->changelog_front = (t->changelog_front + 1) % TOPOLOGY_LOG_MAX; + t->changelog_front = (t->changelog_front + 1) % topology_log_max; t->num_changelog--; } if (t->changelog_front == -1) t->changelog_front = 0; - t->changelog_rear = (t->changelog_rear + 1) % TOPOLOGY_LOG_MAX; + t->changelog_rear = (t->changelog_rear + 1) % topology_log_max; elem =&(t->changelog[t->changelog_rear]); memset(elem, 0, sizeof(struct topology_changelog )); memcpy(elem->rpt_macaddr, c->rpt_macaddr, 6); @@ -629,6 +652,9 @@ void changelog_copy_node_info(struct topologyd_private *t, struct node *p, int32 dbg("Inside changelog_copy_node_info \n"); struct topology_changelog elem; + if( t == NULL || p == NULL) + return; + if(event == 0) memcpy(elem.rpt_macaddr, p->hwaddr, 6); else diff --git a/src/topologyd.h b/src/topologyd.h index 200fc0d8869a5c93ac861eb2620e9c9e08e735b2..293918acbc73d2b8743bef73c3b11e264abb9193 100644 --- a/src/topologyd.h +++ b/src/topologyd.h @@ -62,7 +62,7 @@ struct topology { uint32_t state; int32_t num_nodes; uint32_t num_changelog; - struct topology_changelog changelog[TOPOLOGY_LOG_MAX]; + struct topology_changelog *changelog; int32_t changelog_front; int32_t changelog_rear; struct hlist_head node_htable[NODE_HTABLE_SIZE]; @@ -84,6 +84,7 @@ struct topologyd_private { struct ubus_event_handler ev; struct uloop_timeout heartbeat; struct uloop_timeout refresh_timer; + struct uloop_timeout status_timer; struct ubus_object obj; struct topologyd_config config; ieee1905_object_t ieee1905;