-
Notifications
You must be signed in to change notification settings - Fork 21
LAN Latency MQTT Notification #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rirfha948
wants to merge
10
commits into
develop
Choose a base branch
from
topic/LatencyNotify
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fac2539
RDKB-xx000: LAN side latency measurement
rirfha948 a86b729
RDKB-xx000: LAN side latency measurement
rirfha948 9edb221
RDKB-xx000: LAN side latency measurement
rirfha948 5e5613f
Merge branch 'topic/LatencyNotify' of https://github.com/rdkcentral/t…
rirfha948 172199a
RDKB-xx000: LAN side latency measurement
rirfha948 645e5f0
RDKB-xx000: LAN side latency measurement
rirfha948 9d0713f
RDKB-xx000: LAN side latency measurement
rirfha948 47a183b
RDKB-xx000: LAN side latency measurement
rirfha948 261ac86
Merge branch 'topic/LatencyNotify' of https://github.com/rdkcentral/t…
rirfha948 6b0caa2
RDKB-xx000: LAN side latency measurement
rirfha948 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ | |
| #include <errno.h> | ||
| #include <math.h> | ||
| #include <rbus/rbus.h> | ||
| #include <mosquitto.h> | ||
| #include "syscfg/syscfg.h" | ||
| #define ADD_MAX_SAMPLE 10 | ||
| #define MAX_SAMPLE 50 | ||
|
|
@@ -74,6 +75,11 @@ pthread_mutex_t latency_report_lock = PTHREAD_MUTEX_INITIALIZER; | |
| #define TRUE 1 | ||
| #define FALSE 0 | ||
| #define BUF_SIZE 200 | ||
| #define MQTT_LOCAL_MQTT_BROKER_IP_ADDR "192.168.245.254" | ||
| #define MQTT_LOCAL_MQTT_BROKER_PORT_VAL 1883 | ||
| #define TCP_LAN_latency_TOPIC "device/TCP_LAN_latency" | ||
| #define MQTT_KEEPALIVE_TIME 60 | ||
|
|
||
| enum ip_family | ||
| { | ||
| IPV4=0, | ||
|
|
@@ -1049,6 +1055,55 @@ void* LatencyReportThread(void* arg) | |
|
|
||
|
|
||
| #if 1 | ||
|
|
||
| // Function that takes MAC + LAN latency (microseconds) | ||
| int send_latency_message(const char *mac, long long lan_latency_sec, long long lan_latency_usec) { | ||
| struct mosquitto *mosq; | ||
| char payload[256]; | ||
| int rc =0; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. init and connect we need to do just once. only publish api needs to be called while sending the latency data |
||
| // JSON payload: you can format however you need | ||
| snprintf(payload, sizeof(payload), | ||
| "{\"mac\":\"%s\", \"lan_latency_sec\":%lld.%06lld}", mac, lan_latency_sec, lan_latency_usec); | ||
|
|
||
| mosquitto_lib_init(); | ||
| mosq = mosquitto_new("LatencyPublisher", true, NULL); | ||
| if (!mosq) { | ||
| dbg_log("Failed to create Mosquitto client"); | ||
| mosquitto_lib_cleanup(); | ||
| return -1; | ||
| } | ||
|
|
||
| rc = mosquitto_connect(mosq, | ||
| MQTT_LOCAL_MQTT_BROKER_IP_ADDR, | ||
| MQTT_LOCAL_MQTT_BROKER_PORT_VAL, | ||
| MQTT_KEEPALIVE_TIME); | ||
|
|
||
| if (rc != MOSQ_ERR_SUCCESS) { | ||
| dbg_log("Failed to connect to MQTT broker: %s", mosquitto_strerror(rc)); | ||
|
|
||
| mosquitto_destroy(mosq); | ||
| mosquitto_lib_cleanup(); | ||
| return 1; | ||
| } | ||
|
|
||
| // Publish message | ||
| rc = mosquitto_publish(mosq, NULL, TCP_LAN_latency_TOPIC, | ||
| strlen(payload), payload, | ||
| 1, false); | ||
|
|
||
| if (rc == MOSQ_ERR_SUCCESS) { | ||
| dbg_log("Published: %s", payload); | ||
| } else { | ||
| dbg_log("Failed to publish message: %s", mosquitto_strerror(rc)); | ||
| } | ||
|
|
||
| mosquitto_disconnect(mosq); | ||
| mosquitto_destroy(mosq); | ||
| mosquitto_lib_cleanup(); | ||
| return rc; | ||
| } | ||
|
|
||
| void* LatencyReportThreadPerSession(void* arg) | ||
| { | ||
| // detach the current thread | ||
|
|
@@ -1081,6 +1136,15 @@ void* LatencyReportThreadPerSession(void* arg) | |
| if(hashArray[i].bComputed == TRUE) | ||
| { | ||
| tempCount = snprintf(str1,sizeof(str1),"%s,%u,%lld.%lld,%lld.%06lld|",hashArray[i].mac,hashArray[i].TcpInfo[INDEX_SYN].th_seq,hashArray[i].latency_sec,hashArray[i].latency_usec,hashArray[i].Lan_latency_sec,hashArray[i].Lan_latency_usec); | ||
| //Send LAN side Latency Notification to HCM module | ||
| int rc = send_latency_message(hashArray[i].mac, | ||
| hashArray[i].Lan_latency_sec, hashArray[i].Lan_latency_usec); | ||
|
|
||
| if (rc != MOSQ_ERR_SUCCESS) { | ||
| dbg_log("MQTT publish failed for MAC %s: %s", | ||
| hashArray[i].mac, mosquitto_strerror(rc)); | ||
| } | ||
|
|
||
| if(tempCount) | ||
| { | ||
| if((byteCount+tempCount) < MAX_REPORT_SIZE) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep topic as local/tcplatency