Compare commits

..

267 Commits

Author SHA1 Message Date
Weston Schmidt
85a0d9b71d Merge pull request #425 from shilpa24balaji/memFreeMetadata
Free memory in Parodus during exit/shutdown
2023-07-19 17:48:29 -07:00
Shilpa Seshadri
03a5b96e0c To fix security warnings 2023-07-14 12:02:29 +05:30
Mohamed Shaikh
066bdc180d "Memory hardening in Parodus in exit scenarios"
Signed-off-by: Mohamed Shaikh <mohamed.shaikh@t-systems.com>
2023-07-12 17:34:22 +05:30
sadhyama
118e8ee32f Merge pull request #413 from shilpa24balaji/xmidt_send_loop
Xmidt send loop
2023-04-11 12:26:39 +05:30
Shilpa Seshadri
f7c9f483f9 Merge branch 'master' of https://github.com/xmidt-org/parodus into xmidt_send_loop 2023-04-05 19:04:56 +05:30
shilpa24balaji
502f56400e Merge pull request #418 from sadhyama/lowqos_retry
XmidtSendData to handle higher priority low qos
2023-03-30 20:24:10 +05:30
Sadhyama Vengilat
3e557ae4b0 To skip max queue size delete for higher priority low qos 2023-03-30 18:34:55 +05:30
Sadhyama Vengilat
0602fb243b XmidtSendData to handle higher priority low qos msgs to confirm send success 2023-03-28 18:45:31 +05:30
shilpa24balaji
1a7ae0b785 Merge pull request #417 from sadhyama/rbus_log
Enable rbus logs in parodus
2023-03-23 11:53:46 +05:30
Sadhyama Vengilat
bc655cf9ba Parodus to enable rbus ERROR level logging 2023-03-17 17:28:40 +05:30
Sadhyama Vengilat
ad0491179d Remove threadId from rbus log 2023-03-16 18:31:02 +05:30
Sadhyama Vengilat
fa49a52a94 Register rbus logger to enable more debug logs from rbus 2023-03-16 11:19:11 +05:30
shilpa24balaji
25baef78a8 Merge pull request #416 from sadhyama/max_queue
Fix parodus crash when xmidtSend reaches max queue size during WFO
2023-03-13 23:41:07 +05:30
Sadhyama Vengilat
9034ef9d10 To fix low qos msgs immediate delete during max queue size 2023-03-03 21:03:51 +05:30
Sadhyama Vengilat
9020089016 To skip max queue size callback for already processed msgs 2023-02-28 17:39:33 +05:30
sadhyama
664690e6a6 Merge pull request #415 from sadhyama/wfo_subscribe
Subscribe to CurrentActiveInterfaceEvent before initial cloud connection
2023-02-22 09:57:42 +05:30
shilpa24balaji
4aed47b730 Merge pull request #414 from Mike0893/master
RDKC-13073 : Remove camera specific patch from parodus
2023-02-21 13:22:16 +05:30
Sadhyama Vengilat
2f3f1424b4 Subscribe to CurrentActiveInterfaceEvent before initial cloud connection 2023-02-17 19:11:03 +05:30
mmikhi643
91ae0e82e2 RDKC-13073 : Remove camera specific patch from parodus 2023-02-15 16:20:20 +00:00
mmikhi643
bfc2659bbb RDKC-13073 : Remove camera specific patch from parodus 2023-02-14 14:43:29 +00:00
shilpa24balaji
f9c2878cbf Merge pull request #412 from vasuki01/null_check
"Added null check as fix for parodus crash"
2023-01-17 19:56:53 +05:30
Vasuki
c84a1bdfad "Added null check as fix for parodus crash" 2023-01-11 22:42:23 +05:30
Shilpa Seshadri
0b0ba77bd6 Wait until close retry is in progress for xmidtEventSendToServer 2023-01-06 00:16:27 +05:30
shilpa24balaji
0b0309c3dd Merge pull request #410 from Thanusha-D/traceContext_api
Log traceParent & traceState value in upstream request & event messages
2022-12-22 08:57:51 +05:30
Thanusha D
f4e358c179 Log traceParent & traceState value in upstream request & event messages 2022-12-21 16:04:32 +05:30
Shilpa Seshadri
0561c67e5c To avoid continuous xmidtEventSendToServer retry loop 2022-12-15 20:42:34 +05:30
shilpa24balaji
c1fc8d877b Merge pull request #409 from shilpa24balaji/rbus
Use rdkcentral RBUS repo & resolve dependencies
2022-12-06 23:10:36 +05:30
Shilpa Seshadri
581d7fc966 Unit test fixes 2022-11-18 18:28:40 +05:30
Shilpa Seshadri
0673d2624e Use rdkcentral RBUS repo & resolve dependencies 2022-11-11 21:08:03 +05:30
shilpa24balaji
0f82e7c2d9 Merge pull request #408 from vasuki01/seriallog
Serial-number configuration incorrect in parodus log
2022-11-03 16:51:10 +05:30
Vasuki
4acf7f63ba Serial-number configuration incorrect in parodus log 2022-11-02 15:10:57 +05:30
shilpa24balaji
df67b95244 Merge pull request #406 from shilpa24balaji/webcfg_signal11
To fix webconfig upstream event crash
2022-10-22 22:18:55 +05:30
Shilpa Seshadri
e6e37053d3 To fix webconfig upstream event crash 2022-10-21 20:06:32 +05:30
shilpa24balaji
d5a9ff36f6 Merge pull request #403 from guruchandru/retry_stuck
Moving from Realtime clock to monotonic clock in backoff delay
2022-09-28 23:09:16 +05:30
Guru Chandru
f4536b778e Fix for updating parconnhealth file 2022-09-28 18:41:20 +05:30
shilpa24balaji
b65b3ab3b0 Merge pull request #404 from sadhyama/xmidt_src
Modify outparams source based on status and handle cloud failure
2022-09-26 17:16:12 +05:30
Sadhyama Vengilat
954080bbd1 Modify outparams source based on status and handle cloud failure 2022-09-23 20:56:12 +05:30
Guru Chandru
c8a2c95ae4 Switch to use the sonarcloud installer action 2022-09-22 12:30:57 +05:30
shilpa24balaji
59bba50bee Merge pull request #402 from sadhyama/exp_callback
send rbus callback on xmidt msg expiry and queue optimize
2022-09-21 20:07:02 +05:30
Sadhyama Vengilat
3090e50b02 Msg optimized callback when low qos deletion on max queue 2022-09-21 19:35:02 +05:30
Guru Chandru
af4eeb9199 Merge remote-tracking branch 'upstream/master' into retry_stuck 2022-09-21 18:53:42 +05:30
Guru Chandru
2dd392dac6 Adding cond attribute for MONOTONIC wait 2022-09-21 18:02:05 +05:30
Sadhyama Vengilat
7eae3da3f2 send rbus callback when queue optimized 2022-09-20 17:54:07 +05:30
Sadhyama Vengilat
6e5ecc87f9 send rbus callback to caller during msg expiry 2022-09-20 17:14:26 +05:30
shilpa24balaji
893c1c7547 Merge pull request #401 from sadhyama/cloudack_serv
Implement cloud ack for provider of Device.X_RDK_Xmidt.SendData
2022-09-19 20:12:57 +05:30
Sadhyama Vengilat
3e30328738 Update latest wrp-c git tag 2022-09-19 20:03:18 +05:30
Thanusha D
f7412f9710 Changed Realtime clock to monotonic clock in backoff delay 2022-09-19 19:41:48 +05:30
Sadhyama Vengilat
2e11d7e3ba To skip DELETE state and logging multiple times during expiry 2022-09-19 16:49:16 +05:30
Sadhyama Vengilat
5ddac7dc47 Reduce debug log 2022-09-16 20:18:42 +05:30
Sadhyama Vengilat
79d8a84c2e Add sleep 1s to avoid cpu load 2022-09-15 20:03:01 +05:30
Sadhyama Vengilat
6f7332d054 To add 200ms sleep to process ack and handle partnerid mismatch case 2022-09-15 16:51:04 +05:30
Sadhyama Vengilat
26d409d884 To fix local pc build failure in tests 2022-09-13 16:48:39 +05:30
Sadhyama Vengilat
d3e758ccb4 Remove test simulation and addional debug logs 2022-09-12 21:06:33 +05:30
Sadhyama Vengilat
4af1aaf418 To fix crash when partner id mismatch and fix msg processing before init 2022-09-09 20:29:18 +05:30
Sadhyama Vengilat
8e00ec8e5e Fix unknown dest error during downstream cloud ack processing 2022-08-29 20:33:00 +05:30
Sadhyama Vengilat
43f55f9a99 Reduce cloud ack processing time delay 2022-08-25 19:53:48 +05:30
Sadhyama Vengilat
bf3ee65360 Enable debug logs 2022-08-25 18:01:24 +05:30
Sadhyama Vengilat
9ebe011cb0 Reduce xmidt send consumer sleep on processing msgs 2022-08-25 16:07:09 +05:30
Sadhyama Vengilat
2bfc0a3c32 Merge remote-tracking branch 'upstream/master' into cloudack_serv 2022-08-03 14:08:38 +05:30
Sadhyama Vengilat
37bb19eeaa Remove test simulation for sendresponse 2022-08-03 14:05:41 +05:30
Sadhyama Vengilat
2c4980cf9e Enable more debug logs in validate partner id 2022-08-02 18:09:12 +05:30
Sadhyama Vengilat
2248f31658 Remove test simulation for cloud ack to test with cd server 2022-08-02 16:22:19 +05:30
Sadhyama Vengilat
b97643ec42 Optimize xmidtQ when connection down and reset to head 2022-07-21 18:38:28 +05:30
Sadhyama Vengilat
66b16aa58f Modify xmidt state flow based on next node 2022-07-18 20:37:44 +05:30
Sadhyama Vengilat
d3a56df184 Handle enqueued msg expiry when cloud connection is down 2022-07-14 20:09:04 +05:30
Sadhyama Vengilat
8b5346e69b To test high qos wan down scenarios locally 2022-07-11 19:58:31 +05:30
Sadhyama Vengilat
2a28e5d3e8 Log qos , transaction id during expiry and delete 2022-07-07 18:34:50 +05:30
Sadhyama Vengilat
33af3f3eec Modify xmidtQsize logs and test simulation transid 2022-07-06 18:19:43 +05:30
Sadhyama Vengilat
c9b34d3c3f Reduce debug logs 2022-07-06 13:07:04 +05:30
Sadhyama Vengilat
4add1c07ca Test simulation to generate cloud acks for each transid 2022-07-05 16:33:34 +05:30
Sadhyama Vengilat
75c833e3a8 To handle max queue size 0 and qos disabled 2022-07-04 18:09:33 +05:30
Sadhyama Vengilat
5359fc79cf Remove transaction id checks from delete func 2022-07-04 17:33:55 +05:30
Sadhyama Vengilat
623192e301 Fix ping received time logging 2022-07-04 14:05:52 +05:30
Sadhyama Vengilat
b6490ba5b3 Check xmidt state as DELETE along with transid when deleting a node 2022-07-01 20:16:10 +05:30
shilpa24balaji
20ccd81086 Merge pull request #400 from vasuki01/serial_fix
"Parodus crash due to invalid serial number"
2022-07-01 17:15:58 +05:30
Vasuki
f9ac95642c "Parodus crash due to invalid serial number" 2022-07-01 16:54:29 +05:30
Sadhyama Vengilat
ae5d027612 Fix time value logging 2022-06-30 20:07:58 +05:30
Sadhyama Vengilat
e139a2d6b6 Fix delete node traversal and debug enqueueTime 2022-06-30 18:45:56 +05:30
Sadhyama Vengilat
f655d6382b Fix lock stuck issue during delete and enqueuetime logging 2022-06-30 14:14:30 +05:30
Sadhyama Vengilat
267e0eb796 Merge remote-tracking branch 'upstream/master' into cloudack_xmdQ 2022-06-29 20:45:49 +05:30
Sadhyama Vengilat
00251153a4 Handle xmidt size when max queue size argument is not available 2022-06-29 20:40:38 +05:30
Sadhyama Vengilat
d328a56e1a Fix build error on max queue size argument 2022-06-29 17:30:53 +05:30
Sadhyama Vengilat
1a169561e4 Merge remote-tracking branch 'upstream/cmd_queSize' into cloudack_xmdQ 2022-06-29 15:56:18 +05:30
Sadhyama Vengilat
8019489b86 Handle xmidt event validation failures and delete from queue 2022-06-29 14:13:37 +05:30
Sadhyama Vengilat
ee3e006908 Xmidt rdr status to error message mapping to send callback 2022-06-28 20:18:38 +05:30
Sadhyama Vengilat
797c9de17f Add mutex locks for xmidtQsize 2022-06-28 17:18:46 +05:30
Sadhyama Vengilat
0bf4d754e5 DELETE state to delete processed xmidt msgs 2022-06-24 20:42:59 +05:30
Sadhyama Vengilat
3d98b4a80b Traverse xmidtQ locally and reset to headnode 2022-06-24 20:18:33 +05:30
Sadhyama Vengilat
80a50dead6 check expiry based on qos and handle maxQueue 2022-06-24 20:09:03 +05:30
Sadhyama Vengilat
dd69d5ec5d Use existing getCurrentTime func to set time values 2022-06-23 20:20:20 +05:30
Sadhyama Vengilat
1b23de5a12 SENT state cloud ack timeout retry handling and ping detection 2022-06-22 20:25:58 +05:30
Sadhyama Vengilat
8ea342b537 Xmidt SENT state to process cloud ACK 2022-06-21 20:29:36 +05:30
Sadhyama Vengilat
124fc11232 Add xmidt states and process PENDING messages 2022-06-20 20:29:04 +05:30
shilpa24balaji
9abb37a005 Merge pull request #398 from Thanusha-D/log_change
Added NULL checks in value change event & Logging transaction_uuid in msg send
2022-06-17 12:17:47 +05:30
Thanusha D
c0edaaf31c Added logs for debugging 2022-06-16 21:16:00 +05:30
Thanusha D
32138613bb To get max-queue-size from startparodus 2022-06-16 12:02:07 +05:30
Sadhyama Vengilat
4cb167e8dd Fix xmidtQ head node NULL issue while cloud ack processing 2022-06-03 20:50:14 +05:30
Sadhyama Vengilat
454ec26065 Xmidt msg status update based on cloud ack 2022-06-03 13:04:02 +05:30
Sadhyama Vengilat
47af275929 Xmidt cloud ack handling with xmidtMsgQ 2022-06-01 20:40:22 +05:30
shilpa24balaji
34802d329d Merge pull request #394 from sadhyama/xmd_content
Add content_type validation for Xmidt method profiles
2022-05-27 23:07:53 +05:30
Sadhyama Vengilat
0297d994b5 Reduce debug log 2022-05-27 19:47:39 +05:30
Sadhyama Vengilat
ee7033c36c Add contentType list and validate 2022-05-27 12:59:38 +05:30
Sadhyama Vengilat
e35221efd2 Add content_type validation for Xmidt method profiles 2022-05-26 20:36:11 +05:30
sadhyama
c898fe6d0e Merge pull request #393 from sadhyama/def_profile
Handle Xmidt default profile events received before connection
2022-05-13 18:55:25 +05:30
Sadhyama Vengilat
0017e48f7d Remove content_type modification 2022-05-13 18:48:30 +05:30
Sadhyama Vengilat
285a461f42 Disable debug logs 2022-05-11 18:16:25 +05:30
Sadhyama Vengilat
bb0f49a8b3 Added delay on parodus init 2022-05-10 19:26:33 +05:30
Sadhyama Vengilat
ee20e1fcb8 Handle xmidt default profiles received before initial cloud connection 2022-05-09 20:31:07 +05:30
sadhyama
becacd8990 Merge pull request #392 from sadhyama/parodus_highqos
set cloud_status online after close_retry reset to fix Xmidt sendMsg failure
2022-04-20 16:13:53 +05:30
Sadhyama Vengilat
b05bfbe1fa Merge remote-tracking branch 'upstream/master' into parodus_highqos 2022-04-20 16:13:10 +05:30
sadhyama
9fb3f118b7 Merge pull request #391 from guruchandru/xmd_send
Error Number value change
2022-04-20 16:11:22 +05:30
Sadhyama Vengilat
a124aafc5f set cloud_status online after close_retry reset to fix sendMsg failure 2022-04-20 13:09:57 +05:30
Guru Chandru
0c4a2f407a Error Number value change 2022-04-18 12:25:20 +05:30
shilpa24balaji
523c9cc0d2 Merge pull request #390 from guruchandru/xmd_send
Changes to Send Success and Error ACK
2022-04-13 18:51:33 +05:30
Guru Chandru
58492950d6 Review comment changes 2022-04-13 13:18:21 +05:30
Guru Chandru
29906511b8 Changes to Send ACK for Success and Error Case 2022-04-12 17:56:34 +05:30
shilpa24balaji
c6fa4b2ce8 Merge pull request #388 from shilpa24balaji/wan_failover
Reconnect to cloud on every wan failover event
2022-04-12 16:43:59 +05:30
sadhyama
0640f3516f Merge pull request #386 from xmidt-org/xmidt_send
Xmidt send RBUS method to send events upstream
2022-04-08 20:35:23 +05:30
Sadhyama Vengilat
60c37daa18 Wrp-c git tag update 2022-04-08 20:30:03 +05:30
Sadhyama Vengilat
f51b4ef9c2 Fix valgrind leaks 2022-04-08 18:14:40 +05:30
Sadhyama Vengilat
254c9f6763 Start xmidt consumer only when method register is success 2022-04-08 13:31:24 +05:30
sadhyama
8876fa9239 Merge pull request #387 from guruchandru/xmd_send
Transaction uuid Crash Fix
2022-04-08 13:03:42 +05:30
Guru Chandru
42fc9eb26e Transaction uuid Crash Fix 2022-04-08 12:37:58 +05:30
sadhyama
e8e652b076 Merge pull request #385 from sadhyama/xmd_new
Log reduction and format
2022-04-07 21:09:05 +05:30
Sadhyama Vengilat
dc935f9a09 Debug log reduction and formatting 2022-04-07 21:04:55 +05:30
Sadhyama Vengilat
d1462de56a Convert device mac to lowercase 2022-04-07 15:03:00 +05:30
Shilpa Seshadri
13309a737e Reconnect to cloud on every wan failover event 2022-04-07 12:40:21 +05:30
Guru Chandru
223e7db81c Valgrind leak fix for cloud status and device_id 2022-04-05 20:00:19 +05:30
sadhyama
cd763823fc Merge pull request #383 from guruchandru/xmd_send
High QOS and ACK
2022-04-05 14:08:38 +05:30
Guru Chandru
8537f27ece Review comment changes 2022-04-05 14:04:21 +05:30
Guru Chandru
6381d9c55f Local PC Unit Test Build Failure Fix 2022-04-04 15:15:18 +05:30
Guru Chandru
980b7a88db Review comment Changes on ACK and Cloud status Cond signal 2022-04-04 15:05:24 +05:30
Guru Chandru
e3c37b6764 Review comment Changes 2022-04-04 12:10:30 +05:30
Guru Chandru
67d58441ef Revised changes 2022-04-04 11:02:21 +05:30
Guru Chandru
f6ffda05ad Merge remote-tracking branch 'upstream/xmidt_send' into xmd_send 2022-04-01 17:54:33 +05:30
Guru Chandru
6aee851944 Removing tempAsyncHandle 2022-04-01 14:59:29 +05:30
Sadhyama Vengilat
aaa93e137d Merge remote-tracking branch 'upstream/master' into xmidt_send 2022-04-01 14:17:36 +05:30
Sadhyama Vengilat
21e8c74f23 Add transaction id in outParams & fix PC build issues 2022-04-01 14:07:57 +05:30
Guru Chandru
0248e7b241 removed LTE distro in mutex 2022-03-31 17:10:28 +05:30
Guru Chandru
da019382c6 Async response 2022-03-31 14:01:55 +05:30
Guru Chandru
aecbd885d5 Remove wrp_free in Dequeue 2022-03-30 12:08:52 +05:30
Guru Chandru
0443c45924 Merge remote-tracking branch 'upstream/master' into xmd_send 2022-03-30 10:38:20 +05:30
sadhyama
314c840755 Merge pull request #382 from Thanusha-D/lte_wanfail
Support Wan failover/restore events for LTE backup
2022-03-29 18:54:44 +05:30
Guru Chandru
69f7e3eba0 Adding NULL checks for wrp struct free 2022-03-29 18:41:11 +05:30
Thanusha D
e643f9e2fc Support Wan failover/restore events for LTE backup 2022-03-29 18:14:29 +05:30
Guru Chandru
7d2e9733d0 Debug logs 2022-03-29 15:23:20 +05:30
Guru Chandru
23c18da03e Fix for Crash due to frequent ACK response trigger 2022-03-29 13:30:01 +05:30
Guru Chandru
2218637f2c Added ACK and Cond wait signal for connection not OK 2022-03-28 21:41:42 +05:30
Guru Chandru
54f9983eff High Qos Event ACK and Enqueue changes 2022-03-28 15:39:30 +05:30
Guru Chandru
a577854172 Merge remote-tracking branch 'upstream/parodusUS' into xmd_send 2022-03-28 13:11:40 +05:30
Guru Chandru
e054ef580f Merge remote-tracking branch 'upstream/xmd_send' into xmd_send 2022-03-28 13:04:05 +05:30
Sadhyama Vengilat
79eb7ba6ef To fix send ack crash due to OutParams NULL issue 2022-03-28 12:49:18 +05:30
Guru Chandru
a291b047b6 Enqueue option to add High Qos Events after Failure 2022-03-28 12:27:38 +05:30
Sadhyama Vengilat
656b1b0b58 To fix send ack crash due to OutParams NULL issue 2022-03-28 12:10:19 +05:30
vasuki01
22ecf0ef76 Review comments updated for wan fail over support 2022-03-25 19:40:00 +05:30
Sadhyama Vengilat
c97a3a3a20 Rbus async ack handling for xmidt send requests 2022-03-25 14:36:38 +05:30
Vasuki
46273d9766 Add cloud status mutex locks for Parodus send data US subtask 2022-03-23 14:57:39 +05:30
Sadhyama Vengilat
7efed14c20 Enable WAN_FAILOVER_SUPPORTED and fix build issues 2022-03-18 14:01:40 +05:30
Vasuki
6d39163d47 Parodus changes for Wanifailover support-2 2022-03-17 11:46:13 +05:30
sadhyama
5b0d3e19f3 Merge pull request #381 from sadhyama/xmd_send
Xmidt sendData method provider to send upstream events
2022-03-17 11:41:30 +05:30
Sadhyama Vengilat
0d8bb960f6 Merge remote-tracking branch 'upstream/master' into xmd_send 2022-03-17 11:13:23 +05:30
Sadhyama Vengilat
5d537fb139 Disabled async ack inParams release 2022-03-16 20:18:37 +05:30
Sadhyama Vengilat
47fcd6bdae Add rbusObject in xmidt queue 2022-03-16 17:29:11 +05:30
Sadhyama Vengilat
24e1790ccb Rbus inParams check method validation 2022-03-16 16:44:23 +05:30
Sadhyama Vengilat
89fdd97d44 Add more debug logs 2022-03-16 16:13:17 +05:30
Sadhyama Vengilat
5ae2325fb6 Parse rbus inParams into wrp event and send to server 2022-03-15 20:50:30 +05:30
Sadhyama Vengilat
9bad1142ab Xmidt Upstream queue to receive events from components 2022-03-08 19:58:05 +05:30
Vasuki
339b93cfd3 Merge remote-tracking branch 'upstream/master' into wanfailsupport 2022-03-03 14:30:51 +05:30
Vasuki
a34db44c90 Parodus changes for Wanifailover support-2 2022-03-02 19:13:44 +05:30
shilpa24balaji
bdec80dd07 Merge pull request #379 from Thanusha-D/time_diff
ConnectTime value in parodus in terms of device uptime
2022-02-28 19:23:17 +05:30
Vasuki
1833c30e83 Parodus changes for Wanifailover support 2022-02-28 15:57:02 +05:30
Thanusha D
5b26fe38f5 Time value in parodus is higher 2022-02-28 15:16:53 +05:30
Sadhyama Vengilat
f3a4daeb74 To extract inParams received from consumer 2022-02-23 19:49:38 +05:30
Sadhyama Vengilat
aaeb1f6612 To send parodus ack response back to caller 2022-02-11 17:52:16 +05:30
Sadhyama Vengilat
0fb6288255 Parodus to support rbus xmidtSendData provider 2022-01-21 17:10:55 +05:30
shilpa24balaji
0fd3b76f27 Merge pull request #375 from sadhyama/webcfg_binON
Fix parodus PC build issues when webconfig bin is ON
2021-12-07 10:22:13 +05:30
Sadhyama Vengilat
48722ffa7c Fix parodus PC build issues when webconfig bin is ON 2021-12-06 19:57:29 +05:30
shilpa24balaji
bf5d555d96 Merge pull request #374 from xmidt-org/webcfg_bin
Changes to support webconfig as separate binary in RBUS mode
2021-11-30 20:09:56 +05:30
Shilpa Seshadri
c02b141f7c Fixed license in new c file 2021-11-30 19:59:42 +05:30
shilpa24balaji
9f40b7efe5 Merge pull request #371 from krishnangnair/monotonic_clock
Use monotonic clock for heartBeat timer calculation.
2021-11-26 12:13:50 +05:30
shilpa24balaji
2a184e24c9 Merge pull request #372 from shilpa24balaji/webcfg_bin
Use rbus subscribe API instead of addListener API
2021-11-25 23:26:19 +05:30
Shilpa Seshadri
233a167cb4 Use rbus subscribe API instead of addListener API 2021-11-23 22:47:28 +05:30
knair410
5562d7ec48 Use monotonic clock for heartBeat timer calculation. 2021-11-10 23:15:07 +05:30
sadhyama
49513df8f8 Merge pull request #370 from Sreedevi29/bin_flag
Move webcfgbin distro flage to outside of BUILD_YOCTO check.
2021-09-29 10:58:18 +05:30
Sreedevi V
d0e6c5bd75 Move webcfgbin distro flage to outside of BUILD_YOCTO check. 2021-09-29 16:18:38 +05:30
sadhyama
66f1f4d4fb Merge pull request #368 from Sreedevi29/distro_check
Listener for webconfig upstream events when bin distro is on
2021-09-28 14:17:20 +05:30
sadhyama
19b4f56913 Merge pull request #367 from shilpa24balaji/notify_upstream
Listener for webconfig upstream events
2021-09-27 20:16:30 +05:30
Sreedevi V
c30d5a3362 Listener for webconfig upstream events when bin distro is on 2021-09-23 22:08:19 +05:30
Shilpa Seshadri
c98e2e2fb8 Listener for webconfig upstream events 2021-09-23 00:00:32 +05:30
Shilpa Seshadri
c78625f35a Update to use nopoll version 1.0.3 2021-09-22 12:53:53 +05:30
shilpa24balaji
aeea6fbb03 Merge pull request #366 from sadhyama/conn_retry
Fix Parodus connection stuck on interface up down received together
2021-09-02 12:40:16 +05:30
Sadhyama Vengilat
d2d1590329 Fix unit tests on conn_interface 2021-09-01 22:58:17 +05:30
Sadhyama Vengilat
e693c09ca3 Fix Parodus connection stuck on interface up down received together 2021-08-30 20:02:14 +05:30
shilpa24balaji
0b9f739323 Merge pull request #365 from shilpa24balaji/conn_event
Invoke conn status change event only one time on failure
2021-08-25 22:28:17 +05:30
Shilpa Seshadri
d901efd10c Invoke conn status change event only one time on failure 2021-08-25 15:02:19 +05:30
shilpa24balaji
824bcb81cf Merge pull request #364 from shilpa24balaji/conn_event
To fix brackets in conn event check
2021-08-19 22:31:33 +05:30
Shilpa Seshadri
671fc5be59 To fix brackets in conn event check 2021-08-17 23:38:58 +05:30
shilpa24balaji
4bf8683192 Merge pull request #363 from shilpa24balaji/conn_event
Add callback handler for initial connection status change event
2021-08-09 23:46:50 +05:30
Shilpa Seshadri
9300d76a8e Add callback handler for initial connection status change event 2021-07-27 20:06:26 +05:30
Weston Schmidt
dee98922a6 Update the readme links. 2021-06-02 18:28:37 -07:00
Weston Schmidt
b9fa918c15 Merge pull request #362 from xmidt-org/update-ci
Update the CI pipeline.
2021-06-02 18:25:04 -07:00
Weston Schmidt
a278a7017d Update the CI pipeline. 2021-06-02 18:17:54 -07:00
Weston Schmidt
69cf210a34 Merge pull request #359 from xmidt-org/whitesource/configure
Configure WhiteSource Bolt for GitHub
2021-06-02 18:06:27 -07:00
Weston Schmidt
77b587aa9d Merge pull request #361 from xmidt-org/proposed-add-auth-headers
Add additional headers to auth request
2021-06-02 16:44:07 -07:00
Weston Schmidt
441ecf702f Add additional headers to auth request
This adds the set of headers from the convey header into the auth
request in a way that doesn't require a change to Themis.
2021-06-02 00:57:51 -07:00
sadhyama
bdc2733d8e Merge pull request #360 from sadhyama/reb_reason
To increase reboot reason size
2021-02-03 19:35:33 +05:30
Sadhyama Vengilat
1f24671c0f To increase reboot reason size 2021-02-03 16:51:18 +05:30
whitesource-bolt-for-github[bot]
3de4ec59c1 Add .whitesource configuration file 2020-12-07 17:30:48 +00:00
sadhyama
a01ad8f15c Merge pull request #357 from sadhyama/part_id
Add partnerID header in auth token request
2020-11-16 14:42:18 +05:30
Sadhyama Vengilat
1d2e51e31e Add partnerID header in auth token request 2020-11-10 15:51:35 +05:30
Weston Schmidt
9e808acf7d Use the old default branch name for now. 2020-09-18 13:40:50 -07:00
Weston Schmidt
19f2fe1419 Merge pull request #356 from xmidt-org/add-sonar
Add sonar, travis and friends.
2020-09-15 18:55:34 -07:00
Weston Schmidt
b99c06a67b Disable the clang build for now. 2020-09-15 18:45:42 -07:00
Weston Schmidt
f57ebc1cd7 Disable string_helpers test for now since it fails... 2020-09-15 18:31:08 -07:00
Weston Schmidt
1df770a91b Remove the spin thread test due to what appear to be issues with travis-ci. 2020-09-15 18:23:09 -07:00
Weston Schmidt
a582bb3252 Fix several compilation errors (multiple definitions of global variables, remove overlapping strncpy() strings which cause latent bugs) to allow for code coverage to work. 2020-09-15 18:04:41 -07:00
Weston Schmidt
42dd20263b Ignore a test generated file. 2020-09-15 18:03:05 -07:00
Weston Schmidt
ac100c0f4e Disable valgrind for now to get updated builds working. 2020-09-15 12:06:22 -07:00
Weston Schmidt
290289f2f1 Remove the duplicate cmake line. 2020-09-15 12:00:00 -07:00
Weston Schmidt
8e9b98b697 Disable coverity since it makes the build always fail. 2020-09-15 11:52:04 -07:00
Weston Schmidt
b148d40c53 Disable valgrind for now to get updated builds working. 2020-09-15 11:51:18 -07:00
Weston Schmidt
dc6486f200 Add sonar, travis and friends. 2020-09-15 11:32:52 -07:00
shilpa24balaji
ad2d43b4f6 Merge pull request #354 from sadhyama/aker_blob
Webconfig communication to aker via parodus
2020-08-07 16:37:29 +05:30
Sadhyama Vengilat
54cfdd9c52 Support Retrieve with dest as mac:xxxxxxxxxxxx/parodus/service-status/service 2020-07-27 18:30:15 +05:30
Sadhyama Vengilat
19056ddfec Webconfig communication to aker via parodus 2020-07-17 01:11:35 +05:30
shilpa24balaji
1d85742497 Merge pull request #351 from krish-1/master
Code changes to drop root privilege
2020-04-01 20:57:12 -07:00
kjothi774
e29dd26d2b To drop root privilege for parodus process 2020-04-02 03:37:44 +00:00
kjothi774
5aae91763a To drop root privilege for parodus process 2020-04-02 03:03:12 +00:00
shilpa24balaji
9afa49140a Merge pull request #349 from bill1600/siglog
fix shutdown close msg to agree with splunk log
2020-03-27 18:25:40 -07:00
Bill Williams
4305dc8eef fix shutdown close msg to agree with splunk log 2020-03-26 09:30:26 -07:00
shilpa24balaji
f44fc2c8d9 Merge pull request #346 from bill1600/sigterm2
Parodus shutdown with SIGTERM to read close_reason file
2020-03-05 12:37:55 -08:00
Weston Schmidt
16543800d2 Merge pull request #344 from bill1600/jitter2
Jitter2
2020-03-03 11:04:18 -08:00
Bill Williams
bcb4840a41 update with requested changes 2020-02-27 16:54:51 -08:00
Bill Williams
b173828777 merge master 2020-02-13 10:50:21 -08:00
Bill Williams
2df8cdfeb5 change jitter calculation 2020-02-12 09:42:15 -08:00
shilpa24balaji
eba1309169 Merge pull request #342 from bill1600/cloudstat
check cloud status for sendMessage
2020-02-06 16:21:48 -08:00
Bill Williams
70c1c64550 fix/add unit tests for backoff delay 2020-02-04 13:41:27 -08:00
Bill Williams
e825c19ef3 use jitter in backoff delay 2020-02-04 10:22:17 -08:00
Bill Williams
95170d95c7 add unit test for cloud status offline 2020-02-03 13:13:31 -08:00
Bill Williams
33142a6ce7 add mock_event_handler for testing 2020-01-30 15:33:45 -08:00
Bill Williams
7b3ee1dd5a remove nopoll_conn_is_ok from sendMessage 2020-01-16 14:25:01 -08:00
Bill Williams
f2308e2966 remove nopoll_conn_is_ready test from sendMessage 2020-01-16 12:49:11 -08:00
Bill Williams
9c55157da7 fix test_nopoll_helpers 2020-01-15 13:41:57 -08:00
Bill Williams
1c254e28fe check cloud status for sendMessage 2020-01-15 12:06:09 -08:00
shilpa24balaji
8955787640 Merge pull request #340 from xmidt-org/revert-339-nopoll_timeout
Revert "To add Nopoll default connect timeout value"
2020-01-09 11:40:38 -08:00
shilpa24balaji
b633938bc7 Revert "To add Nopoll default connect timeout value" 2020-01-09 11:33:13 -08:00
shilpa24balaji
b0aeaf1fb2 Merge pull request #339 from guruchandru/nopoll_timeout
To add Nopoll default connect timeout value
2020-01-03 10:48:14 -08:00
Guru Chandru
ea726e0c10 To add Nopoll default connect timeout value 2020-01-03 14:14:51 +05:30
shilpa24balaji
cbdf5d2be9 Merge pull request #337 from bill1600/norequery
remerged noretrydns and two_times
2019-12-27 13:40:52 -08:00
shilpa24balaji
3d369cafb2 Merge pull request #338 from sadhyama/master
Unit tests for non 200 auth token response codes
2019-12-26 17:05:02 -08:00
Sadhyama Vengilat
c0dbdb5028 Unit tests for non 200 auth token response codes 2019-12-26 18:20:44 +05:30
shilpa24balaji
12a7765f98 Update event_handler.h 2019-12-25 22:09:05 -08:00
shilpa24balaji
88c87917a4 Update event_handler.c 2019-12-25 22:08:35 -08:00
shilpa24balaji
0905387d49 Free redirect server url during reconnect 2019-12-23 17:35:52 -08:00
Bill Williams
a8167fa417 change health file update interval to 240s 2019-12-20 14:30:01 -08:00
Bill Williams
6ab601e758 retrigger travis tests 2019-12-19 13:33:59 -08:00
Bill Williams
45536eb4e1 remerged noretrydns and two_times 2019-12-19 11:12:59 -08:00
shilpa24balaji
8208d3bfd0 Merge pull request #335 from sadhyama/auth_token
Fix Report failure on non-200 response code from auth token server
2019-12-17 12:35:04 -08:00
shilpa24balaji
4fc60b6b3c Merge pull request #330 from bill1600/idownunit
add unit tests for interface down
2019-12-17 12:33:51 -08:00
Sadhyama Vengilat
990d9df7e2 Fix Report failure on non-200 response code from auth token server 2019-12-12 21:17:02 +05:30
Weston Schmidt
fe52d9a55e Update README.md 2019-12-06 12:54:30 -08:00
shilpa24balaji
9cfc734c51 Merge pull request #331 from rajnishdey/errMsgUpdate
Change Info log level from error log level for "received temporary re…
2019-11-18 10:51:06 -08:00
Rajnish
153add9bec Change Info log level from error log level for "received temporary redirection response". 2019-11-18 11:28:43 -05:00
Bill Williams
8b553f8a29 add unit tests for interface down 2019-11-17 16:45:33 -08:00
shilpa24balaji
7679fdaf4a Merge pull request #327 from bill1600/ifcdown
update backoff delay and interface down logic
2019-11-15 12:27:41 -08:00
Bill Williams
1c09a80493 fix condition test in wait_while_interface_down 2019-11-14 15:31:28 -08:00
Bill Williams
bfad8ed44b fix deadlock in wait_while_interface_down 2019-11-14 10:56:47 -08:00
66 changed files with 4065 additions and 526 deletions

24
.github/scripts/get_sonarcloud.sh vendored Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0
curl -s -L -O https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
unzip -q -o build-wrapper-linux-x86.zip
SONAR_VERSION=`curl -s https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/ |grep -o "sonar-scanner-cli-[0-9.]*-linux.zip"|sort -r|uniq|head -n 1`
curl -s -L -O https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/$SONAR_VERSION
curl -s -L -O https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/$SONAR_VERSION.sha256
echo " $SONAR_VERSION" >> $SONAR_VERSION.sha256
sha256sum -c $SONAR_VERSION.sha256
if [[ $? -ne 0 ]]
then
exit 1
fi
unzip -q $SONAR_VERSION
output=`ls | grep -o "sonar-scanner-[0-9.]*-linux"`
echo "Using $output"
mv $output sonar-scanner

50
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0
name: LGTM Analysis
on:
create:
pull_request:
push:
branches:
- main
schedule:
- cron: '12 9 * * 3'
jobs:
codeql:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Install the dependent packages
- name: Install packages
run: |
sudo apt update
sudo apt-get -y install valgrind libcunit1 libcunit1-doc libcunit1-dev libmsgpack-dev gcovr libtool
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: cpp
queries: security-extended
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

72
.github/workflows/push.yml vendored Normal file
View File

@@ -0,0 +1,72 @@
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0
name: CI
on:
pull_request:
push:
paths-ignore:
- 'AUTHORS'
- 'LICENSE'
- 'NOTICE'
- '**.md'
- '.gitignore'
tags-ignore:
- 'v[0-9]+.[0-9]+.[0-9]+'
branches:
- main
- master
jobs:
test:
name: Unit Tests
runs-on: [ ubuntu-latest ]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
fetch-depth: 0
# Install the dependent packages
- name: Install packages
run: |
sudo apt update
sudo apt-get -y install valgrind libcunit1 libcunit1-doc libcunit1-dev libmsgpack-dev gcovr libtool
pip install codecov
- name: Make Build Directory
run: mkdir build
- name: Get Sonarcloud Binaries
uses: xmidt-org/sonarcloud-installer-action@v1
with:
working-directory: build
- name: CMake
working-directory: build
run: |
cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=${DISABLE_VALGRIND} -DENABLE_SESHAT:BOOL=true -DFEATURE_DNS_QUERY:BOOL=true
- name: Build
working-directory: build
run: |
build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make all test
- name: Merge GCOV Reports for Sonarcloud
working-directory: build
run: |
gcovr --sonarqube coverage.xml -r ..
- name: Upload SonarCloud
run: |
build/sonar-scanner/bin/sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dproject.settings=.sonar-project.properties -Dsonar.login=${{ secrets.SONAR_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Codecov.io
uses: codecov/codecov-action@v1
with:
directory: .
fail_ci_if_error: true

49
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,49 @@
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0
name: release
on:
push:
tags:
# Push events to matching v#.#.#*, ex: v1.2.3, v.2.4.6-beta
- 'v[0-9]+.[0-9]+.[0-9]+*'
jobs:
release:
runs-on: [ ubuntu-latest ]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Determine repo name
run: |
echo "repo_name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "release_slug=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')-${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
shell: bash
- name: Create tarball and sha256
run: |
git archive --format=tar.gz -o ${release_slug}.tar.gz --prefix=${release_slug}/ ${version}
git archive --format=zip -o ${release_slug}.zip --prefix=${release_slug}/ ${version}
sha256sum ${release_slug}.tar.gz ${release_slug}.zip > ${release_slug}-sha256sums.txt
mkdir artifacts
cp ${release_slug}* artifacts/.
- name: Prepare Release Body
id: prep
run: |
export version=${GITHUB_REF#refs/tags/}
export NOTES=$(cat CHANGELOG.md | perl -0777 -ne 'print "$1\n" if /.*## \[${version}\]\s(.*?)\s+## \[(v\d+.\d+.\d+)\].*/s')
export TODAY=`date +'%m/%d/%Y'`
echo ::set-output name=rname::$(echo ${version} ${TODAY})
echo ::set-output name=body::${NOTES}
- name: create release
id: create_release
uses: ncipollo/release-action@v1
with:
name: ${{ steps.prep.outputs.rname }}
draft: false
prerelease: false
bodyFile: ${{ steps.prep.outputs.body }}
artifacts: "artifacts/*"
token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token

33
.github/workflows/tag.yml vendored Normal file
View File

@@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0
name: tag
on:
push:
paths:
- "CHANGELOG.md" # only try to tag if the CHANGELOG has been updated.
branches:
- main
jobs:
build:
runs-on: [ ubuntu-latest ]
steps:
- uses: actions/checkout@v2
with:
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
fetch-depth: 0
- name: set up bot
run: |
git config --global user.name "xmidt-bot"
git config --global user.email "$BOT_EMAIL"
- name: export variables and tag commit
run: |
export OLD_VERSION=$(git describe --tags `git rev-list --tags --max-count=1` | tail -1)
export TAG=$(cat CHANGELOG.md | perl -0777 -ne 'print "$1" if /.*## \[Unreleased\]\s+## \[(v\d+.\d+.\d+)\].*/s')
export BINVER=$(cat CMakeLists.txt | perl -0777 -ne 'print "v$1" if /.*project\s*\(.*\s*VERSION\s*(\d+.\d+.\d+).*\s*\)/s')
export TODAY=`date +'%m/%d/%Y'`
export NOTES=$(cat CHANGELOG.md | perl -0777 -ne 'print "$ENV{TODAY}\n\n$1\n" if /.*## \[$ENV{TAG}\]\s(.*?)\s+## \[(v\d+.\d+.\d+)\].*/s')
if [[ "$TAG" != "" && "$TAG" != "$BINVER" ]]; then echo "CHANGELOG.md($TAG) and CMakeLists.txt VERSION($BINVER) do not match"; fi
if [[ "$TAG" != "" && "$TAG" != "$OLD_VERSION" && "$TAG" == "$BINVER" ]]; then git tag -a "$TAG" -m "$NOTES"; git push origin --tags; echo $?; fi

2
.gitignore vendored
View File

@@ -34,3 +34,5 @@
tags tags
build/ build/
tests/jwt_key.tst

34
.sonar-project.properties Normal file
View File

@@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0
# Reference:
# https://github.com/SonarSource/sonarcloud_example_go-sqscanner-travis/blob/master/sonar-project.properties
# =====================================================
# Standard properties
# =====================================================
sonar.organization=xmidt-org
sonar.projectKey=xmidt-org_parodus
sonar.projectName=parodus
sonar.sources=src
# =====================================================
# Meta-data for the project
# =====================================================
sonar.links.homepage=https://github.com/xmidt-org/parodus
sonar.links.ci=https://github.com/xmidt-org/parodus/actions
sonar.links.scm=https://github.com/xmidt-org/parodus
sonar.links.issue=https://github.com/xmidt-org/parodus/issues
# =====================================================
# Properties specific to C
# =====================================================
sonar.cfamily.build-wrapper-output=build/bw-output
sonar.cfamily.threads=2
sonar.cfamily.cache.enabled=false
sonar.coverageReportPaths=build/coverage.xml

View File

@@ -1,43 +0,0 @@
dist: trusty
sudo: required
language: c
compiler:
- gcc
addons:
coverity_scan:
project:
name: "Comcast/parodus"
description: "C implementation of the WebPA client coordinator"
notification_email: weston_schmidt@alumni.purdue.edu
build_command_prepend: "mkdir coverity_build && cd coverity_build && cmake .."
build_command: "make"
branch_pattern: ignore
before_install:
- sudo pip install codecov
- echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-
install:
- sudo apt-get update -qq
- sudo apt-get install -y -qq check libcunit1 libcunit1-dev uuid-dev valgrind
script:
- mkdir build
- cd build
- cmake .. -DINTEGRATION_TESTING:BOOL=false -DDISABLE_VALGRIND:BOOL=false -DENABLE_SESHAT:BOOL=true -DFEATURE_DNS_QUERY:BOOL=true
- make
- export ARGS="-V"
- make test
after_success:
- codecov
env:
global:
- secure: EwQu1WDUgIF5qM5tnKj/+NCPz9t15y289bbqFo0wDhyfTlJGS9buQeJNeVLtNJBEOngpo+AkaPGvh/d9NZ0vLdxu+K/e+HhA6kOTxUrCHD8+4oX9XpVs/XvQmD1COlJYeeqd8bJMKtlFtonGdMJogxpEFQzv4fQjmoARvL2ciV4OB0MBcD5Lsb72L3a0aJT69F6WFuDpgGj2eIQyCDSTPNIi2X7EA8R33lxnntFDn8Vj6qSBbVOI2S5R5S+JUCMp1Q1ZbEqmh6j+wKtszWj8wGqfz8Ol5+GYl511bExb+hwvV5zen0Ol0+2LQmSpYhbQZ7prfI8AclLLwhDUrP+WDOv34vwd4EWQ1OoLqG23HbBygCxPSBIB6ZxPtVkzjVlOK8qqIB5QXqCyq8sPKlrXfntOQ+Ha938cIA+A0ag+26MLbhDGj8k3Os7BdY/oqNTKADZQdxfGKhCiA9qO2clpMyRXoE0q6hv9dYoG/2c4sxH8DKsT8XY/QbGmiBsk0DWHcpxkObCsHUxVKi+gIBGSL/tSjz2IJfQVZkdl2hhcyStGuPKbiwAlW3HydMk0VgRhVmHBIc41Cv7vPdMEVf/XiFhr2utRX468M/LR8vkhhokKl1xkVIiquwCPYPzZVAFARHTlaBMhz9kQVtTAHf2JkHuM9XcLWKW996FiSeswKyI=
- secure: LQK36EsQdIJw7eSW1yz+yh3+yJdp8cznynBjE3whOEVI2KHZimr+vtK5hxE6TH0QjYyrb/BFgRql6CtLprpaABSEC9gpqpahu50jiAkjKC8DtfSloAbH5jj+ZllaPjURocerllNLVZxiRM/WCuJAy0nzBpAyx62YmVlEYi+zYD67d3wG6gLwso6l2DWuPPze6t5NmbUmH9hNk52++TZalwMtZFdibQoYm64vCTT5gycujw6ZDa8GD0m+Yryvc20kLlWPOVS9lN1iEGo98/gj8Ops8w0iw6k7SfEkvvFsKEUDr77wAN5Tk4tGq7odVrD/y3W9AsHkkSb1B6RqVWkcW3SjCAQc03jhdaBxXwcoJZcYahY21CB12EP7p0HSjEbvIzNpk0D9MulsGaMPlOudnKdG0/kmD7oIAiXjfC7PiPBBFIc/cVF5VAKNTUInEVfcKvlLpqDatwjB+qgb7pld24dUPuJw+yOgglk7J7xckJYHFTHhk0PWI5oN66dndj3yyJp4dz1v64ViFFTG4PO4YPJydZxRxolg1eGMuG0UIYJK6RWcSQ+ZPBm4p78J8xfHtgUkvWvrHJoXC1qAzqx1XRzbHEeTJgbKgLrWY+B6nbNotw1RDX4lNDirp5EI6GqezoFJToZkqe3MRs8DrqhaFjUbbEzAxznRWmxnWNN3Ujc=
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- secure: "V/W4Z9/3uXpS83CvlZ1XfDAbHPIA2ID5G5s9GPcsUqoOASQdc6Y/DPejUlot+DgtiHOEdTr9n5iWDOuxqjcVnjVd6ag9i2m0PMqDhPj3fnUJM6dAeXIBda/qSuTsJTX4cIwb371R77cLcIUm35IEOSIAQOBCjh7RCf3ivGPUp+wobTonkNzDw6xqO90hx7NLnxwGSCcaNBFKOcLL0e7DXspp18lTWCSSaHELzXOyLlhZnWhC5tiFUIZk1ixm/cO1YEQH9AzgPJ5OYs+On0j8VT8XWMsxHu0zfkZkdZMAEOQbO6u4HBDePIfp+PoF1LwtX/UXfaEkUHZ0kNVXHfsN/KP7NHgTbASe9EXp+R4pcKEy4ZEbx+xpp7FlMQSJYiYiQbJ2FBrjwRPreXiHyCqn8htd0YNOTH4UykvO3NYxlTaMf9aE041lnLjUY18TuXrILz6SzMsGV+nYqfIci/NPuj/57k7nw127a93S4Mr/phXts9ZL8I7kagd8wKv3m5+7rmIfuSfS2kg2pTa0hk5uMqFWLG8AilUQ5t1ChylzPcl/Gdgi9OP0pG2WyUmkqOiSqhwwdg2ZCwptodwuonfbdKMSBuHOS8lLU1bGyCRdWsMoscSv/xn4t3ikzBsSDiKgI8xq2+aqQyHDeVneqAk1BbxiNIwoJeyVXq2EKU6MlgI="

12
.whitesource Normal file
View File

@@ -0,0 +1,12 @@
{
"scanSettings": {
"baseBranches": []
},
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure",
"displayMode": "diff"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}

View File

@@ -5,18 +5,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
- Security: Added support to use auth token during initial connect to cloud - Add additional HTTP headers for call to Themis from Convey
- Fix re-registration fails that lose a socket - Add callback handler for initial cloud connection status change event
- Fix mutex error in service alive - Fix Parodus connection stuck on interface up down received together
- Security: Mutual Authentication (mTLS or two way TLS) - Update to use nopoll version 1.0.3
- Rename command line options for MTLS cert and Key
- Update to use nanomsg v. 1.1.4 ## [1.1.4]
- requestNewAuthToken will clear the token if it fails. - on connect retry, requery jwt only if it failed before
- request auth token on every retry, not just after 403 - put two timestamps in connection health file; start conn and current
- update to use nopoll v 1.0.2 - change health file update interval to 240sec
- Add pause/resume heartBeatTimer - use jitter in backoff delay
- parodus event handler to listen to interface_down and interface_up event - sendMessage to check cloud status == ONLINE before sending
- Pause connection retry during interface_down event - when killed with SIGTERM, close will use msg in close reason file.
## [1.1.3]
- Add callback handler for ping status change event - Add callback handler for ping status change event
- Fixed nopoll_conn_unref crash - Fixed nopoll_conn_unref crash
- Update retry timestamp in connection-health-file - Update retry timestamp in connection-health-file
@@ -25,6 +27,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- send status code and reason in websocket close message - send status code and reason in websocket close message
- dont try to install handler for signal 9 - dont try to install handler for signal 9
## [1.1.2]
- Add pause/resume heartBeatTimer
- parodus event handler to listen to interface_down and interface_up event
- Pause connection retry during interface_down event
## [1.1.1]
- Update to use nanomsg v. 1.1.4
- requestNewAuthToken will clear the token if it fails.
- request auth token on every retry, not just after 403
- update to use nopoll v 1.0.2
## [1.0.4]
- Fix re-registration fails that lose a socket
- Fix mutex error in service alive
- Security: Mutual Authentication (mTLS or two way TLS)
- Rename command line options for MTLS cert and Key
## [1.0.3]
- Security: Added support to use auth token during initial connect to cloud
## [1.0.2] - 2019-02-08 ## [1.0.2] - 2019-02-08
- Refactored connection.c and updated corresponding unit tests - Refactored connection.c and updated corresponding unit tests
- Additional `/cloud-status` and `/cloud-disconnect` fields. - Additional `/cloud-status` and `/cloud-disconnect` fields.
@@ -73,6 +95,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Security ### Security
- Added command line arguments for secure token read and acquire. Token presented to cloud for authentication verification. - Added command line arguments for secure token read and acquire. Token presented to cloud for authentication verification.
- Added support for override functions to support drop root capabilities for parodus process
## [1.0.0] - 2017-11-17 ## [1.0.0] - 2017-11-17
### Added ### Added
@@ -82,7 +105,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added ### Added
- Initial creation - Initial creation
[Unreleased]: https://github.com/Comcast/parodus/compare/1.0.1...HEAD [Unreleased]: https://github.com/Comcast/parodus/compare/1.1.4...HEAD
[1.1.4]: https://github.com/Comcast/parodus/compare/1.1.3...1.1.4
[1.1.3]: https://github.com/Comcast/parodus/compare/1.1.2...1.1.3
[1.1.2]: https://github.com/Comcast/parodus/compare/1.1.1...1.1.2
[1.1.1]: https://github.com/Comcast/parodus/compare/1.0.4...1.1.1
[1.0.4]: https://github.com/Comcast/parodus/compare/1.0.3...1.0.4
[1.0.3]: https://github.com/Comcast/parodus/compare/1.0.2...1.0.3
[1.0.2]: https://github.com/Comcast/parodus/compare/1.0.1...1.0.2 [1.0.2]: https://github.com/Comcast/parodus/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/Comcast/parodus/compare/1.0.0...1.0.1 [1.0.1]: https://github.com/Comcast/parodus/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/Comcast/parodus/compare/79fa7438de2b14ae64f869d52f5c127497bf9c3f...1.0.0 [1.0.0]: https://github.com/Comcast/parodus/compare/79fa7438de2b14ae64f869d52f5c127497bf9c3f...1.0.0

View File

@@ -14,6 +14,7 @@
cmake_minimum_required(VERSION 2.8.7) cmake_minimum_required(VERSION 2.8.7)
#project(parodus VERSION 1.1.15)
project(parodus) project(parodus)
include(ExternalProject) include(ExternalProject)
@@ -42,6 +43,11 @@ include_directories(${INCLUDE_DIR}
${INCLUDE_DIR}/cjwt ${INCLUDE_DIR}/cjwt
) )
if (ENABLE_WEBCFGBIN)
include_directories(${INCLUDE_DIR}/rbus)
endif (ENABLE_WEBCFGBIN)
# Get git commit hash # Get git commit hash
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
execute_process( execute_process(
@@ -58,9 +64,18 @@ add_definitions("-DGIT_COMMIT_TAG=\"${GIT_COMMIT_TAG}\"")
add_definitions(-std=c99) add_definitions(-std=c99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DNOPOLL_LOGGER ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DNOPOLL_LOGGER ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Wall -Wno-missing-field-initializers") if (DEVICE_CAMERA)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=all -Wno-missing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=all")
add_definitions(-DDEVICE_CAMERA)
else ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=all -Wno-missing-field-initializers")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=all")
endif (DEVICE_CAMERA)
if (INCLUDE_BREAKPAD)
add_definitions(-DINCLUDE_BREAKPAD)
endif (INCLUDE_BREAKPAD)
# pthread external dependency # pthread external dependency
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -85,7 +100,7 @@ add_dependencies(libtrower-base64 trower-base64)
ExternalProject_Add(nopoll ExternalProject_Add(nopoll
PREFIX ${PREFIX_DIR}/nopoll PREFIX ${PREFIX_DIR}/nopoll
GIT_REPOSITORY https://github.com/Comcast/nopoll.git GIT_REPOSITORY https://github.com/Comcast/nopoll.git
GIT_TAG "1.0.2" GIT_TAG "1.0.3"
CONFIGURE_COMMAND COMMAND <SOURCE_DIR>/autogen.sh --prefix=${PREFIX} CONFIGURE_COMMAND COMMAND <SOURCE_DIR>/autogen.sh --prefix=${PREFIX}
--includedir=${INCLUDE_DIR} --includedir=${INCLUDE_DIR}
--libdir=${LIBRARY_DIR} --libdir=${LIBRARY_DIR}
@@ -164,8 +179,8 @@ add_dependencies(libcimplog cimplog)
ExternalProject_Add(wrp-c ExternalProject_Add(wrp-c
DEPENDS trower-base64 msgpack cimplog DEPENDS trower-base64 msgpack cimplog
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/wrp-c PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/wrp-c
GIT_REPOSITORY https://github.com/Comcast/wrp-c.git GIT_REPOSITORY https://github.com/xmidt-org/wrp-c.git
GIT_TAG "1.0.1" GIT_TAG "b5ef4d10cb39905908788bc89ab3e4dab201db8a"
CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} CMAKE_ARGS += -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}
-DMSGPACK_ENABLE_CXX=OFF -DMSGPACK_ENABLE_CXX=OFF
-DMSGPACK_BUILD_EXAMPLES=OFF -DMSGPACK_BUILD_EXAMPLES=OFF
@@ -228,6 +243,26 @@ include_directories(${INCLUDE_DIR}
endif (FEATURE_DNS_QUERY) endif (FEATURE_DNS_QUERY)
if (ENABLE_WEBCFGBIN)
# rbus external dependency
#-------------------------------------------------------------------------------
ExternalProject_Add(rbus
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_prefix/rbus
GIT_REPOSITORY https://github.com/rdkcentral/rbus.git
GIT_TAG main
CMAKE_ARGS += -DBUILD_FOR_DESKTOP=ON -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} -DBUILD_TESTING=OFF
)
add_library(librbuscore STATIC SHARED IMPORTED)
add_dependencies(librbuscore rbuscore)
add_library(librtMessage STATIC SHARED IMPORTED)
add_dependencies(librtMessage rtMessage)
add_library(librbus STATIC SHARED IMPORTED)
add_dependencies(librbus rbus)
endif (ENABLE_WEBCFGBIN)
if (BUILD_TESTING) if (BUILD_TESTING)
# cmocka external dependency # cmocka external dependency
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -252,6 +287,14 @@ if (FEATURE_DNS_QUERY)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFEATURE_DNS_QUERY ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFEATURE_DNS_QUERY ")
endif (FEATURE_DNS_QUERY) endif (FEATURE_DNS_QUERY)
if (ENABLE_WEBCFGBIN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_WEBCFGBIN ")
endif (ENABLE_WEBCFGBIN)
if (WAN_FAILOVER_SUPPORTED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWAN_FAILOVER_SUPPORTED ")
endif (WAN_FAILOVER_SUPPORTED)
link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} ) link_directories ( ${LIBRARY_DIR} ${COMMON_LIBRARY_DIR} ${LIBRARY_DIR64} )
add_subdirectory(src) add_subdirectory(src)
if (BUILD_TESTING) if (BUILD_TESTING)

View File

@@ -1,10 +1,16 @@
<!--
SPDX-FileCopyrightText: 2016-2021 Comcast Cable Communications Management, LLC
SPDX-License-Identifier: Apache-2.0
-->
# parodus # parodus
[![Build Status](https://travis-ci.org/xmidt-org/parodus.svg?branch=master)](https://travis-ci.org/xmidt-org/parodus) [![Build Status](https://github.com/xmidt-org/parodus/workflows/CI/badge.svg)](https://github.com/xmidt-org/parodus/actions)
[![codecov.io](http://codecov.io/github/Comcast/parodus/coverage.svg?branch=master)](http://codecov.io/github/Comcast/parodus?branch=master) [![codecov.io](http://codecov.io/github/xmidt-org/parodus/coverage.svg?branch=master)](http://codecov.io/github/xmidt-org/parodus?branch=master)
[![Coverity](https://img.shields.io/coverity/scan/11192.svg)](https://scan.coverity.com/projects/comcast-parodus) [![Coverity](https://img.shields.io/coverity/scan/11192.svg)](https://scan.coverity.com/projects/comcast-parodus)
[![Apache V2 License](http://img.shields.io/badge/license-Apache%20V2-blue.svg)](https://github.com/Comcast/parodus/blob/master/LICENSE) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xmidt-org_parodus&metric=alert_status)](https://sonarcloud.io/dashboard?id=xmidt-org_parodus)
[![GitHub release](https://img.shields.io/github/release/Comcast/parodus.svg)](CHANGELOG.md) [![Language Grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/xmidt-org/parodus.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/xmidt-org/parodus/context:cpp)
[![Apache V2 License](http://img.shields.io/badge/license-Apache%20V2-blue.svg)](https://github.com/xmidt-org/parodus/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/xmidt-org/parodus.svg)](CHANGELOG.md)
C implementation of the XMiDT client coordinator C implementation of the XMiDT client coordinator

View File

@@ -14,8 +14,8 @@
set(SOURCES main.c mutex.c networking.c nopoll_helpers.c heartBeat.c nopoll_handlers.c set(SOURCES main.c mutex.c networking.c nopoll_helpers.c heartBeat.c nopoll_handlers.c
ParodusInternal.c string_helpers.c time.c config.c conn_interface.c ParodusInternal.c string_helpers.c time.c config.c conn_interface.c
connection.c spin_thread.c client_list.c service_alive.c connection.c spin_thread.c client_list.c service_alive.c
upstream.c downstream.c thread_tasks.c partners_check.c token.c upstream.c downstream.c thread_tasks.c partners_check.c token.c event_handler.c
crud_interface.c crud_tasks.c crud_internal.c close_retry.c auth_token.c) crud_interface.c crud_tasks.c crud_internal.c close_retry.c auth_token.c privilege.c)
if (ENABLE_SESHAT) if (ENABLE_SESHAT)
set(SOURCES ${SOURCES} seshat_interface.c) set(SOURCES ${SOURCES} seshat_interface.c)
@@ -23,6 +23,15 @@ else()
set(SOURCES ${SOURCES} seshat_interface_stub.c) set(SOURCES ${SOURCES} seshat_interface_stub.c)
endif (ENABLE_SESHAT) endif (ENABLE_SESHAT)
if (ENABLE_WEBCFGBIN)
set(SOURCES ${SOURCES} upstream_rbus.c xmidtsend_rbus.c)
endif (ENABLE_WEBCFGBIN)
if (WAN_FAILOVER_SUPPORTED)
message(STATUS "WAN_FAILOVER_SUPPORTED is supported")
else()
message(STATUS "WAN_FAILOVER_SUPPORTED is not supported")
endif (WAN_FAILOVER_SUPPORTED)
add_executable(parodus ${SOURCES}) add_executable(parodus ${SOURCES})
@@ -53,5 +62,7 @@ if (ENABLE_SESHAT)
target_link_libraries (parodus -llibseshat) target_link_libraries (parodus -llibseshat)
endif (ENABLE_SESHAT) endif (ENABLE_SESHAT)
if (ENABLE_WEBCFGBIN)
target_link_libraries (parodus -lrbus)
endif (ENABLE_WEBCFGBIN)
install (TARGETS parodus DESTINATION bin) install (TARGETS parodus DESTINATION bin)

View File

@@ -69,9 +69,9 @@ char* getWebpaConveyHeader()
cJSON_AddStringToObject(response, WEBPA_PROTOCOL, get_parodus_cfg()->webpa_protocol); cJSON_AddStringToObject(response, WEBPA_PROTOCOL, get_parodus_cfg()->webpa_protocol);
} }
if(strlen(get_parodus_cfg()->webpa_interface_used)!=0) if(strlen(getWebpaInterface())!=0)
{ {
cJSON_AddStringToObject(response, WEBPA_INTERFACE, get_parodus_cfg()->webpa_interface_used); cJSON_AddStringToObject(response, WEBPA_INTERFACE, getWebpaInterface());
} }
if(strlen(get_parodus_cfg()->hw_last_reboot_reason)!=0) if(strlen(get_parodus_cfg()->hw_last_reboot_reason)!=0)
@@ -131,6 +131,27 @@ char* getWebpaConveyHeader()
return NULL; return NULL;
} }
int readFromFile(const char *file_name, char **data)
{
FILE *fp;
int ch_count = 0;
fp = fopen(file_name, "r+");
if (fp == NULL)
{
ParodusError("Failed to open file %s (errno %d)\n", file_name, errno);
return 0;
}
fseek(fp, 0, SEEK_END);
ch_count = ftell(fp);
fseek(fp, 0, SEEK_SET);
*data = (char *) malloc(sizeof(char) * (ch_count + 1));
fread(*data, 1, ch_count,fp);
(*data)[ch_count] ='\0';
fclose(fp);
return 1;
}
void timespec_diff(struct timespec *start, struct timespec *stop, void timespec_diff(struct timespec *start, struct timespec *stop,
struct timespec *diff) struct timespec *diff)
{ {

View File

@@ -108,6 +108,7 @@ typedef struct {
//--- Used in connection.c for backoff delay timer //--- Used in connection.c for backoff delay timer
typedef struct { typedef struct {
unsigned long start_time;
struct timespec ts; struct timespec ts;
int count; int count;
int max_count; int max_count;
@@ -126,7 +127,7 @@ typedef struct {
// wait_connection_ready, and nopoll_connect // wait_connection_ready, and nopoll_connect
typedef struct { typedef struct {
noPollCtx *nopoll_ctx; noPollCtx *nopoll_ctx;
server_list_t server_list; server_list_t *server_list;
server_t *current_server; server_t *current_server;
header_info_t header_info; header_info_t header_info;
char *extra_headers; // need to be freed char *extra_headers; // need to be freed
@@ -138,7 +139,6 @@ typedef struct {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
extern bool g_shutdown; extern bool g_shutdown;
extern ParodusMsg *ParodusMsgQ; extern ParodusMsg *ParodusMsgQ;
int numLoops;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Function Prototypes */ /* Function Prototypes */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -156,10 +156,19 @@ char* getWebpaConveyHeader();
void *CRUDHandlerTask(); void *CRUDHandlerTask();
void addCRUDmsgToQueue(wrp_msg_t *crudMsg); void addCRUDmsgToQueue(wrp_msg_t *crudMsg);
int readFromFile(const char *file_name, char **data);
void timespec_diff(struct timespec *start, struct timespec *stop, void timespec_diff(struct timespec *start, struct timespec *stop,
struct timespec *result); struct timespec *result);
#ifdef ENABLE_WEBCFGBIN
void subscribeRBUSevent();
int regXmidtSendDataMethod();
void registerRbusLogger();
#endif
#ifdef WAN_FAILOVER_SUPPORTED
void setWebpaInterface(char *value);
#endif
/*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/
/* For interface_down_event Flag */ /* For interface_down_event Flag */
/*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/
@@ -177,6 +186,11 @@ pthread_cond_t *get_interface_down_con();
pthread_mutex_t *get_interface_down_mut(); pthread_mutex_t *get_interface_down_mut();
pthread_cond_t *get_global_cloud_status_cond(void);
pthread_mutex_t *get_global_cloud_status_mut(void);
int cloud_status_is_online (void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -24,6 +24,7 @@
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include "config.h" #include "config.h"
#include "connection.h"
#include "auth_token.h" #include "auth_token.h"
#include "ParodusInternal.h" #include "ParodusInternal.h"
#include <cjwt/cjwt.h> #include <cjwt/cjwt.h>
@@ -31,16 +32,22 @@
#include <curl/curl.h> #include <curl/curl.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#define MAX_BUF_SIZE 128 #define MAX_BUF_SIZE 256
#define CURL_TIMEOUT_SEC 25L #define CURL_TIMEOUT_SEC 25L
#define MAX_CURL_RETRY_COUNT 3 #define MAX_CURL_RETRY_COUNT 3
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* File Scoped Variables */ /* File Scoped Variables */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
void createCurlheader(char *mac_header, char *serial_header, char *uuid_header, char *transaction_uuid, struct curl_slist *list, struct curl_slist **header_list); void createCurlheader(struct curl_slist *list, struct curl_slist **header_list);
long g_response_code;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* External Functions */ /* External Functions */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
int getGlobalResponseCode()
{
return g_response_code;
}
/* /*
* @brief Initialize curl object with required options. create newToken using libcurl. * @brief Initialize curl object with required options. create newToken using libcurl.
* @param[out] newToken auth token string obtained from JWT curl response * @param[out] newToken auth token string obtained from JWT curl response
@@ -57,12 +64,8 @@ int requestNewAuthToken(char *newToken, size_t len, int r_count)
struct curl_slist *list = NULL; struct curl_slist *list = NULL;
struct curl_slist *headers_list = NULL; struct curl_slist *headers_list = NULL;
char *mac_header = NULL; char webpa_interface[64]={'\0'};
char *serial_header = NULL;
char *uuid_header = NULL;
char *transaction_uuid = NULL;
double total; double total;
long response_code;
struct token_data data; struct token_data data;
data.size = 0; data.size = 0;
@@ -73,14 +76,15 @@ int requestNewAuthToken(char *newToken, size_t len, int r_count)
{ {
data.data[0] = '\0'; data.data[0] = '\0';
createCurlheader(mac_header, serial_header, uuid_header, transaction_uuid, list, &headers_list); createCurlheader(list, &headers_list);
curl_easy_setopt(curl, CURLOPT_URL, get_parodus_cfg()->token_server_url); curl_easy_setopt(curl, CURLOPT_URL, get_parodus_cfg()->token_server_url);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT_SEC); curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT_SEC);
if(get_parodus_cfg()->webpa_interface_used !=NULL && strlen(get_parodus_cfg()->webpa_interface_used) >0) parStrncpy(webpa_interface, getWebpaInterface(), sizeof(webpa_interface));
if(webpa_interface !=NULL && strlen(webpa_interface) >0)
{ {
curl_easy_setopt(curl, CURLOPT_INTERFACE, get_parodus_cfg()->webpa_interface_used); curl_easy_setopt(curl, CURLOPT_INTERFACE, webpa_interface);
} }
/* set callback for writing received data */ /* set callback for writing received data */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback_fn); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback_fn);
@@ -118,8 +122,8 @@ int requestNewAuthToken(char *newToken, size_t len, int r_count)
/* Perform the request, res will get the return code */ /* Perform the request, res will get the return code */
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &g_response_code);
ParodusInfo("themis curl response %d http_code %d\n", res, response_code); ParodusInfo("themis curl response %d http_code %d\n", res, g_response_code);
time_res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total); time_res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total);
if(time_res == 0) if(time_res == 0)
@@ -137,10 +141,18 @@ int requestNewAuthToken(char *newToken, size_t len, int r_count)
} }
else else
{ {
if(response_code == 200) if(getGlobalResponseCode() == 200)
{ {
ParodusInfo("cURL success\n"); ParodusInfo("cURL success\n");
} }
else
{
ParodusError("Failed response from auth token server %s\n", data.data);
curl_easy_cleanup(curl);
data.size = 0;
memset (data.data, 0, len);
return -1;
}
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }
@@ -211,8 +223,14 @@ void getAuthToken(ParodusCfg *cfg)
* @param[in] nmemb size of delivered data * @param[in] nmemb size of delivered data
* @param[out] data curl response data saved. * @param[out] data curl response data saved.
*/ */
#ifndef DEVICE_CAMERA
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, struct token_data *data) size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, struct token_data *data)
{ {
#else
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, void *datain)
{
struct token_data *data = (struct token_data*) datain;
#endif //DEVICE_CAMERA
ParodusCfg *cfg; ParodusCfg *cfg;
size_t max_data_size = sizeof (cfg->webpa_auth_token); size_t max_data_size = sizeof (cfg->webpa_auth_token);
size_t index = data->size; size_t index = data->size;
@@ -251,52 +269,60 @@ char* generate_trans_uuid()
} }
/* @brief function to create curl header contains mac, serial number and uuid. /* @brief function to create curl header contains mac, serial number and uuid.
* @param[in] mac_header mac address header key value pair * @param[in] h the auth headers to populate
* @param[in] serial_header serial number key value pair
* @param[in] uuid_header transaction uuid key value pair
* @param[in] list temp curl header list * @param[in] list temp curl header list
* @param[out] header_list output curl header list * @param[out] header_list output curl header list
*/ */
void createCurlheader(char *mac_header, char *serial_header, char *uuid_header, char *transaction_uuid, struct curl_slist *list, struct curl_slist **header_list) void createCurlheader(struct curl_slist *list, struct curl_slist **header_list)
{ {
mac_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE); char buf[MAX_BUF_SIZE];
if(mac_header !=NULL) char *uuid = NULL;
{
snprintf(mac_header, MAX_BUF_SIZE, "X-Midt-Mac-Address: %s", get_parodus_cfg()->hw_mac);
ParodusPrint("mac_header formed %s\n", mac_header);
list = curl_slist_append(list, mac_header);
free(mac_header);
mac_header = NULL;
}
serial_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE); snprintf(buf, MAX_BUF_SIZE, "X-Midt-Mac-Address: %s", get_parodus_cfg()->hw_mac);
if(serial_header !=NULL) ParodusPrint("mac_header formed %s\n", buf);
{ list = curl_slist_append(list, buf);
snprintf(serial_header, MAX_BUF_SIZE, "X-Midt-Serial-Number: %s", get_parodus_cfg()->hw_serial_number);
ParodusPrint("serial_header formed %s\n", serial_header);
list = curl_slist_append(list, serial_header);
free(serial_header);
serial_header = NULL;
}
transaction_uuid = generate_trans_uuid(); snprintf(buf, MAX_BUF_SIZE, "X-Midt-Serial-Number: %s", get_parodus_cfg()->hw_serial_number);
if(transaction_uuid !=NULL) ParodusPrint("serial_header formed %s\n", buf);
{ list = curl_slist_append(list, buf);
uuid_header = (char *) malloc(sizeof(char)*MAX_BUF_SIZE);
if(uuid_header !=NULL) uuid = generate_trans_uuid();
{ if(uuid !=NULL) {
snprintf(uuid_header, MAX_BUF_SIZE, "X-Midt-Uuid: %s", transaction_uuid); snprintf(buf, MAX_BUF_SIZE, "X-Midt-Uuid: %s", uuid);
ParodusInfo("uuid_header formed %s\n", uuid_header); ParodusInfo("uuid_header formed %s\n", buf);
list = curl_slist_append(list, uuid_header); list = curl_slist_append(list, buf);
free(transaction_uuid); free(uuid);
transaction_uuid = NULL; } else {
free(uuid_header); ParodusError("Failed to generate transaction_uuid\n");
uuid_header = NULL; }
}
} snprintf(buf, MAX_BUF_SIZE, "X-Midt-Partner-Id: %s", get_parodus_cfg()->partner_id);
else ParodusInfo("partnerid_header formed %s\n", buf);
{ list = curl_slist_append(list, buf);
ParodusError("Failed to generate transaction_uuid\n");
} snprintf(buf, MAX_BUF_SIZE, "X-Midt-Hardware-Model: %s", get_parodus_cfg()->hw_model);
*header_list = list; list = curl_slist_append(list, buf);
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Hardware-Manufacturer: %s", get_parodus_cfg()->hw_manufacturer);
list = curl_slist_append(list, buf);
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Firmware-Name: %s", get_parodus_cfg()->fw_name);
list = curl_slist_append(list, buf);
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Protocol: %s", get_parodus_cfg()->webpa_protocol);
list = curl_slist_append(list, buf);
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Interface-Used: %s", getWebpaInterface());
list = curl_slist_append(list, buf);
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Last-Reboot-Reason: %s", get_parodus_cfg()->hw_last_reboot_reason);
list = curl_slist_append(list, buf);
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Last-Reconnect-Reason: %s", get_global_reconnect_reason());
list = curl_slist_append(list, buf);
snprintf(buf, MAX_BUF_SIZE, "X-Midt-Boot-Retry-Wait: %d", get_parodus_cfg()->boot_retry_wait);
list = curl_slist_append(list, buf);
*header_list = list;
} }

View File

@@ -47,7 +47,11 @@ struct token_data {
int requestNewAuthToken(char *newToken, size_t len, int r_count); int requestNewAuthToken(char *newToken, size_t len, int r_count);
void getAuthToken(ParodusCfg *cfg); void getAuthToken(ParodusCfg *cfg);
#ifndef DEVICE_CAMERA
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, struct token_data *data); size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, struct token_data *data);
#else
size_t write_callback_fn(void *buffer, size_t size, size_t nmemb, void *data);
#endif
char* generate_trans_uuid(); char* generate_trans_uuid();
#ifdef __cplusplus #ifdef __cplusplus

View File

@@ -294,3 +294,24 @@ int sendMsgtoRegisteredClients(char *dest,const char **Msg,size_t msgSize)
release_global_node (); release_global_node ();
return 0; return 0;
} }
//To check client registration status with parodus.
int checkClientStatus(char *serviceName)
{
reg_list_item_t *temp = NULL;
temp = get_global_node();
while (NULL != temp)
{
ParodusPrint("node is pointing to temp->service_name %s \n",temp->service_name);
// Sending message to registered clients
if( strcmp(serviceName, temp->service_name) == 0)
{
release_global_node ();
return 1;
}
ParodusPrint("checking the next item in the list\n");
temp= temp->next;
}
release_global_node ();
return 0;
}

View File

@@ -56,7 +56,7 @@ int sendMsgtoRegisteredClients(char *dest,const char **Msg,size_t msgSize);
reg_list_item_t * get_global_node(void); reg_list_item_t * get_global_node(void);
void release_global_node (void); void release_global_node (void);
int checkClientStatus();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -33,6 +33,13 @@
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* File Scoped Variables */ /* File Scoped Variables */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
pthread_mutex_t config_mut=PTHREAD_MUTEX_INITIALIZER;
//For sending cond signal when cloud status is ONLINE
pthread_mutex_t cloud_status_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cloud_status_cond=PTHREAD_COND_INITIALIZER;
char webpa_interface[64]={'\0'};
static ParodusCfg parodusCfg; static ParodusCfg parodusCfg;
static unsigned int rsa_algorithms = static unsigned int rsa_algorithms =
@@ -40,6 +47,15 @@ static unsigned int rsa_algorithms =
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* External Functions */ /* External Functions */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
pthread_cond_t *get_global_cloud_status_cond(void)
{
return &cloud_status_cond;
}
pthread_mutex_t *get_global_cloud_status_mut(void)
{
return &cloud_status_mut;
}
ParodusCfg *get_parodus_cfg(void) ParodusCfg *get_parodus_cfg(void)
{ {
@@ -61,6 +77,31 @@ void reset_cloud_disconnect_reason(ParodusCfg *cfg)
cfg->cloud_disconnect = NULL; cfg->cloud_disconnect = NULL;
} }
void set_cloud_status(char *status)
{
if(status != NULL)
{
pthread_mutex_lock(&config_mut);
get_parodus_cfg()->cloud_status = status;
if(strcmp (status, CLOUD_STATUS_ONLINE) == 0)
{
pthread_cond_signal(&cloud_status_cond);
}
pthread_mutex_unlock(&config_mut);
}
}
char *get_cloud_status(void)
{
char *status = NULL;
pthread_mutex_lock(&config_mut);
if(NULL != get_parodus_cfg()->cloud_status)
{
status = get_parodus_cfg()->cloud_status;
}
pthread_mutex_unlock(&config_mut);
return status;
}
const char *get_tok (const char *src, int delim, char *result, int resultsize) const char *get_tok (const char *src, int delim, char *result, int resultsize)
{ {
@@ -146,9 +187,9 @@ void read_key_from_file (const char *fname, char *buf, size_t buflen)
int parse_mac_address (char *target, const char *arg) int parse_mac_address (char *target, const char *arg)
{ {
int count = 0; int count = 0;
int i; int i, j;
char c; char c;
char *mac = target;
for (i=0; (c=arg[i]) != 0; i++) { for (i=0; (c=arg[i]) != 0; i++) {
if (c !=':') if (c !=':')
count++; count++;
@@ -160,9 +201,48 @@ int parse_mac_address (char *target, const char *arg)
*(target++) = c; *(target++) = c;
} }
*target = 0; // terminating null *target = 0; // terminating null
//convert mac to lowercase
for(j = 0; mac[j]; j++)
{
mac[j] = tolower(mac[j]);
}
ParodusPrint("mac in lowercase is %s\n", mac);
return 0; return 0;
} }
int parse_serial_num(char *target, const char *arg)
{
char ch;
if(arg != NULL)
{
if(strlen(arg) == 0)
{
ParodusError("Empty serial number, setting to default unknown\n");
strcpy(target,"unknown");
}
for(int i=0; (ch = arg[i]) != '\0'; i++)
{
// check if character is ascii, a-z --> 97 to 122, A-Z --> 65 to 90, digits(0 to 9) --> 48 to 57
if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90) || (ch >=48 && ch <= 57))
{
target[i] = ch;
}
else
{
ParodusError("Invalid serial number, setting to default unknown\n");
strcpy(target,"unknown");
break;
}
}
}
else
{
ParodusError("serial number argument is NULL\n");
}
return 0;
}
int server_is_http (const char *full_url, int server_is_http (const char *full_url,
const char **server_ptr) const char **server_ptr)
{ {
@@ -214,8 +294,13 @@ int parse_webpa_url__ (const char *full_url,
if(openBracket != NULL){ if(openBracket != NULL){
//Remove [ from server address //Remove [ from server address
char *remove = server_addr; char *remove = server_addr;
int i;
// Strings can overlap, so don't use strncpy()
remove++; remove++;
parStrncpy (server_addr, remove, server_addr_buflen); for( i = 0; i < server_addr_buflen; i++ ) {
server_addr[i] = remove[i];
}
closeBracket = strchr(server_addr,']'); closeBracket = strchr(server_addr,']');
if(closeBracket != NULL){ if(closeBracket != NULL){
//Remove ] by making it as null //Remove ] by making it as null
@@ -350,6 +435,9 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
{"webpa-backoff-max", required_argument, 0, 'o'}, {"webpa-backoff-max", required_argument, 0, 'o'},
{"webpa-interface-used", required_argument, 0, 'i'}, {"webpa-interface-used", required_argument, 0, 'i'},
{"parodus-local-url", required_argument, 0, 'l'}, {"parodus-local-url", required_argument, 0, 'l'},
#ifdef ENABLE_WEBCFGBIN
{"max-queue-size", required_argument, 0, 'q'},
#endif
{"partner-id", required_argument, 0, 'p'}, {"partner-id", required_argument, 0, 'p'},
#ifdef ENABLE_SESHAT #ifdef ENABLE_SESHAT
{"seshat-url", required_argument, 0, 'e'}, {"seshat-url", required_argument, 0, 'e'},
@@ -366,6 +454,7 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
{"token-server-url", required_argument, 0, 'U'}, {"token-server-url", required_argument, 0, 'U'},
{"crud-config-file", required_argument, 0, 'C'}, {"crud-config-file", required_argument, 0, 'C'},
{"connection-health-file", required_argument, 0, 'S'}, {"connection-health-file", required_argument, 0, 'S'},
{"close-reason-file", required_argument, 0, 'R'},
{"mtls-client-key-path", required_argument, 0, 'K'}, {"mtls-client-key-path", required_argument, 0, 'K'},
{"mtls-client-cert-path", required_argument, 0,'M'}, {"mtls-client-cert-path", required_argument, 0,'M'},
{0, 0, 0, 0} {0, 0, 0, 0}
@@ -384,6 +473,7 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
parStrncpy (cfg->jwt_key, "", sizeof(cfg->jwt_key)); parStrncpy (cfg->jwt_key, "", sizeof(cfg->jwt_key));
cfg->crud_config_file = NULL; cfg->crud_config_file = NULL;
cfg->connection_health_file = NULL; cfg->connection_health_file = NULL;
cfg->close_reason_file = NULL;
cfg->client_cert_path = NULL; cfg->client_cert_path = NULL;
cfg->token_server_url = NULL; cfg->token_server_url = NULL;
cfg->cloud_status = NULL; cfg->cloud_status = NULL;
@@ -394,8 +484,9 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
/* getopt_long stores the option index here. */ /* getopt_long stores the option index here. */
int option_index = 0; int option_index = 0;
c = getopt_long (argc, argv, "m:s:f:d:r:n:b:u:t:o:i:l:p:e:D:j:a:k:c:T:w:J:46:C:S:K:M", c = getopt_long (argc, argv,
long_options, &option_index); "m:s:f:d:r:n:b:u:t:o:i:l:q:p:e:D:j:a:k:c:T:w:J:46:C:S:R:K:M",
long_options, &option_index);
/* Detect the end of the options. */ /* Detect the end of the options. */
if (c == -1) if (c == -1)
@@ -409,8 +500,8 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
break; break;
case 's': case 's':
parStrncpy(cfg->hw_serial_number,optarg,sizeof(cfg->hw_serial_number)); if(parse_serial_num(cfg->hw_serial_number, optarg) == 0)
ParodusInfo("hw_serial_number is %s\n",cfg->hw_serial_number); ParodusInfo ("hw_serial_number is %s\n",cfg->hw_serial_number);
break; break;
case 'f': case 'f':
@@ -480,6 +571,16 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
parStrncpy(cfg->local_url, optarg,sizeof(cfg->local_url)); parStrncpy(cfg->local_url, optarg,sizeof(cfg->local_url));
ParodusInfo("parodus local_url is %s\n",cfg->local_url); ParodusInfo("parodus local_url is %s\n",cfg->local_url);
break; break;
#ifdef ENABLE_WEBCFGBIN
case 'q':
cfg->max_queue_size = parse_num_arg (optarg, "max-queue-size");
if (cfg->max_queue_size == (unsigned int) -1)
return -1;
ParodusInfo("max_queue_size is %d\n",cfg->max_queue_size);
break;
#endif
case 'D': case 'D':
// like 'fabric' or 'test' // like 'fabric' or 'test'
// this parameter is used, along with the hw_mac parameter // this parameter is used, along with the hw_mac parameter
@@ -538,17 +639,22 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
ParodusInfo("connection_health_file is %s\n", cfg->connection_health_file); ParodusInfo("connection_health_file is %s\n", cfg->connection_health_file);
break; break;
case 'R':
cfg->close_reason_file = strdup(optarg);
ParodusInfo("sigterm_close_reason_file is %s\n", cfg->close_reason_file);
break;
case 'C': case 'C':
cfg->crud_config_file = strdup(optarg); cfg->crud_config_file = strdup(optarg);
ParodusInfo("crud_config_file is %s\n", cfg->crud_config_file); ParodusInfo("crud_config_file is %s\n", cfg->crud_config_file);
break; break;
case 'P': case 'P':
cfg->client_cert_path = strdup(optarg); cfg->client_cert_path = strdup(optarg);
ParodusInfo("client_cert_path is %s\n", cfg->client_cert_path); ParodusInfo("client_cert_path is %s\n", cfg->client_cert_path);
break; break;
case 'U': case 'U':
cfg->token_server_url = strdup(optarg); cfg->token_server_url = strdup(optarg);
ParodusInfo("token_server_url is %s\n", cfg->token_server_url); ParodusInfo("token_server_url is %s\n", cfg->token_server_url);
break; break;
@@ -605,6 +711,53 @@ int parseCommandLine(int argc,char **argv,ParodusCfg * cfg)
return 0; return 0;
} }
void free_cfg(ParodusCfg *cfg)
{
if(cfg != NULL)
{
if (cfg->mtls_client_cert_path != NULL )
{
free(cfg->mtls_client_cert_path);
cfg->mtls_client_cert_path = NULL;
}
if(cfg->connection_health_file != NULL)
{
free(cfg->connection_health_file);
cfg->connection_health_file = NULL;
}
if(cfg->token_server_url != NULL)
{
free(cfg->token_server_url );
cfg->token_server_url = NULL;
}
if(cfg->mtls_client_key_path != NULL)
{
free(cfg->mtls_client_key_path);
cfg->mtls_client_key_path = NULL;
}
if(cfg->client_cert_path != NULL)
{
free(cfg->client_cert_path);
cfg->client_cert_path = NULL;
}
if(cfg->crud_config_file != NULL)
{
free(cfg->crud_config_file);
cfg->crud_config_file = NULL;
}
if(cfg->close_reason_file != NULL)
{
free(cfg->close_reason_file);
cfg->close_reason_file = NULL;
}
if(cfg->cloud_disconnect != NULL)
{
free(cfg->cloud_disconnect);
cfg->cloud_disconnect = NULL;
}
}
}
void setDefaultValuesToCfg(ParodusCfg *cfg) void setDefaultValuesToCfg(ParodusCfg *cfg)
{ {
if(cfg == NULL) if(cfg == NULL)
@@ -637,6 +790,7 @@ void setDefaultValuesToCfg(ParodusCfg *cfg)
ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid); ParodusPrint("cfg->webpa_uuid is :%s\n", cfg->webpa_uuid);
cfg->crud_config_file = NULL; cfg->crud_config_file = NULL;
cfg->connection_health_file = NULL; cfg->connection_health_file = NULL;
cfg->close_reason_file = NULL;
cfg->client_cert_path = NULL; cfg->client_cert_path = NULL;
cfg->token_server_url = NULL; cfg->token_server_url = NULL;
@@ -710,7 +864,7 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
} }
if(strlen(config->webpa_interface_used )!=0) if(strlen(config->webpa_interface_used )!=0)
{ {
parStrncpy(cfg->webpa_interface_used, config->webpa_interface_used,sizeof(cfg->webpa_interface_used)); parStrncpy(getWebpaInterface(), config->webpa_interface_used,sizeof(getWebpaInterface()));
} }
else else
{ {
@@ -778,7 +932,9 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
parStrncpy(cfg->cert_path, "\0", sizeof(cfg->cert_path)); parStrncpy(cfg->cert_path, "\0", sizeof(cfg->cert_path));
ParodusPrint("cert_path is NULL. set to empty\n"); ParodusPrint("cert_path is NULL. set to empty\n");
} }
#ifdef ENABLE_WEBCFGBIN
cfg->max_queue_size = config->max_queue_size;
#endif
cfg->boot_time = config->boot_time; cfg->boot_time = config->boot_time;
cfg->webpa_ping_timeout = config->webpa_ping_timeout; cfg->webpa_ping_timeout = config->webpa_ping_timeout;
cfg->webpa_backoff_max = config->webpa_backoff_max; cfg->webpa_backoff_max = config->webpa_backoff_max;
@@ -797,6 +953,15 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
ParodusPrint("connection_health_file is NULL. set to empty\n"); ParodusPrint("connection_health_file is NULL. set to empty\n");
} }
if(config->close_reason_file != NULL)
{
cfg->close_reason_file = strdup(config->close_reason_file);
}
else
{
ParodusPrint("close_reason_file is NULL. set to empty\n");
}
if(config->crud_config_file != NULL) if(config->crud_config_file != NULL)
{ {
cfg->crud_config_file = strdup(config->crud_config_file); cfg->crud_config_file = strdup(config->crud_config_file);
@@ -825,4 +990,26 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg)
} }
} }
#ifdef WAN_FAILOVER_SUPPORTED
void setWebpaInterface(char *value)
{
pthread_mutex_lock (&config_mut);
parStrncpy(get_parodus_cfg()->webpa_interface_used, value, sizeof(get_parodus_cfg()->webpa_interface_used));
pthread_mutex_unlock (&config_mut);
}
#endif
char *getWebpaInterface(void)
{
#ifdef WAN_FAILOVER_SUPPORTED
ParodusPrint("WAN_FAILOVER_SUPPORTED mode \n");
pthread_mutex_lock (&config_mut);
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
pthread_mutex_unlock (&config_mut);
#else
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
#endif
ParodusPrint("webpa_interface:%s\n", webpa_interface);
return webpa_interface;
}

View File

@@ -24,6 +24,7 @@
#ifndef _CONFIG_H_ #ifndef _CONFIG_H_
#define _CONFIG_H_ #define _CONFIG_H_
#include <pthread.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@@ -75,7 +76,7 @@ typedef struct
char hw_serial_number[64]; char hw_serial_number[64];
char hw_manufacturer[64]; char hw_manufacturer[64];
char hw_mac[64]; char hw_mac[64];
char hw_last_reboot_reason[64]; char hw_last_reboot_reason[128];
char fw_name[64]; char fw_name[64];
unsigned int boot_time; unsigned int boot_time;
unsigned int webpa_ping_timeout; unsigned int webpa_ping_timeout;
@@ -87,6 +88,9 @@ typedef struct
char webpa_uuid[64]; char webpa_uuid[64];
unsigned int flags; unsigned int flags;
char local_url[124]; char local_url[124];
#ifdef ENABLE_WEBCFGBIN
unsigned int max_queue_size;
#endif
char partner_id[64]; char partner_id[64];
#ifdef ENABLE_SESHAT #ifdef ENABLE_SESHAT
char seshat_url[128]; char seshat_url[128];
@@ -102,6 +106,7 @@ typedef struct
char *client_cert_path; char *client_cert_path;
char *token_server_url; char *token_server_url;
char *connection_health_file; char *connection_health_file;
char *close_reason_file;
char *mtls_client_key_path; char *mtls_client_key_path;
char *mtls_client_cert_path; char *mtls_client_cert_path;
char *crud_config_file; char *crud_config_file;
@@ -130,7 +135,7 @@ void loadParodusCfg(ParodusCfg * config,ParodusCfg *cfg);
* or -1 if error * or -1 if error
*/ */
int parseCommandLine(int argc,char **argv,ParodusCfg * cfg); int parseCommandLine(int argc,char **argv,ParodusCfg * cfg);
void free_cfg(ParodusCfg *cfg);
void setDefaultValuesToCfg(ParodusCfg *cfg); void setDefaultValuesToCfg(ParodusCfg *cfg);
// Accessor for the global config structure. // Accessor for the global config structure.
ParodusCfg *get_parodus_cfg(void); ParodusCfg *get_parodus_cfg(void);
@@ -138,6 +143,10 @@ void set_parodus_cfg(ParodusCfg *);
char *get_token_application(void) ; char *get_token_application(void) ;
void set_cloud_disconnect_reason(ParodusCfg *cfg, char *disconn_reason); void set_cloud_disconnect_reason(ParodusCfg *cfg, char *disconn_reason);
void reset_cloud_disconnect_reason(ParodusCfg *cfg); void reset_cloud_disconnect_reason(ParodusCfg *cfg);
char *getWebpaInterface(void);
void set_cloud_status(char *status);
char *get_cloud_status(void);
int get_parodus_init();
/** /**
* parse a webpa url. Extract the server address, the port * parse a webpa url. Extract the server address, the port
* and return whether it's secure or not * and return whether it's secure or not

View File

@@ -33,6 +33,7 @@
#include "spin_thread.h" #include "spin_thread.h"
#include "service_alive.h" #include "service_alive.h"
#include "seshat_interface.h" #include "seshat_interface.h"
#include "event_handler.h"
#include "crud_interface.h" #include "crud_interface.h"
#include "heartBeat.h" #include "heartBeat.h"
#include "close_retry.h" #include "close_retry.h"
@@ -73,8 +74,10 @@ void createSocketConnection(void (* initKeypress)())
{ {
//ParodusCfg *tmpCfg = (ParodusCfg*)config_in; //ParodusCfg *tmpCfg = (ParodusCfg*)config_in;
noPollCtx *ctx; noPollCtx *ctx;
server_list_t server_list;
bool seshat_registered = false; bool seshat_registered = false;
int create_conn_rtn = 0; int create_conn_rtn = 0;
int nopoll_returnvalue = 0;
unsigned int webpa_ping_timeout_ms = 1000 * get_parodus_cfg()->webpa_ping_timeout; unsigned int webpa_ping_timeout_ms = 1000 * get_parodus_cfg()->webpa_ping_timeout;
unsigned int heartBeatTimer = 0; unsigned int heartBeatTimer = 0;
struct timespec start_svc_alive_timer; struct timespec start_svc_alive_timer;
@@ -95,9 +98,12 @@ void createSocketConnection(void (* initKeypress)())
nopoll_log_set_handler (ctx, __report_log, NULL); nopoll_log_set_handler (ctx, __report_log, NULL);
#endif #endif
start_conn_in_progress (); EventHandler();
create_conn_rtn = createNopollConnection(ctx); #ifdef WAN_FAILOVER_SUPPORTED
stop_conn_in_progress (); subscribeCurrentActiveInterfaceEvent();
#endif
set_server_list_null (&server_list);
create_conn_rtn = createNopollConnection(ctx, &server_list);
if(!create_conn_rtn) if(!create_conn_rtn)
{ {
ParodusError("Unrecovered error, terminating the process\n"); ParodusError("Unrecovered error, terminating the process\n");
@@ -128,14 +134,17 @@ void createSocketConnection(void (* initKeypress)())
struct timespec start, stop, diff; struct timespec start, stop, diff;
int time_taken_ms; int time_taken_ms;
clock_gettime(CLOCK_REALTIME, &start); clock_gettime(CLOCK_MONOTONIC, &start);
nopoll_loop_wait(ctx, 5000000); nopoll_returnvalue = nopoll_loop_wait(ctx, 5000000);
clock_gettime(CLOCK_REALTIME, &stop); clock_gettime(CLOCK_MONOTONIC, &stop);
timespec_diff(&start, &stop, &diff); timespec_diff(&start, &stop, &diff);
time_taken_ms = diff.tv_sec * 1000 + (diff.tv_nsec / 1000000); time_taken_ms = diff.tv_sec * 1000 + (diff.tv_nsec / 1000000);
if(time_taken_ms/1000 != 5)
// ParodusInfo("nopoll_loop_wait() time %d msec\n", time_taken_ms); {
ParodusInfo("nopoll_loop_wait value %d,nopoll_loop_wait() time %d msec\n",nopoll_returnvalue, time_taken_ms);
}
ParodusPrint("webpa_ping_timeout_ms %d msec\n", webpa_ping_timeout_ms);
heartBeatTimer = get_heartBeatTimer(); heartBeatTimer = get_heartBeatTimer();
if(heartBeatTimer >= webpa_ping_timeout_ms) if(heartBeatTimer >= webpa_ping_timeout_ms)
{ {
@@ -169,7 +178,6 @@ void createSocketConnection(void (* initKeypress)())
seshat_registered = __registerWithSeshat(); seshat_registered = __registerWithSeshat();
} }
// If interface down event is set, wait till interface is up again.
if (get_interface_down_event ()) if (get_interface_down_event ())
if (0 != wait_while_interface_down ()) if (0 != wait_while_interface_down ())
break; break;
@@ -177,7 +185,7 @@ void createSocketConnection(void (* initKeypress)())
if(get_close_retry()) if(get_close_retry())
{ {
ParodusInfo("close_retry is %d, hence closing the connection and retrying\n", get_close_retry()); ParodusInfo("close_retry is %d, hence closing the connection and retrying\n", get_close_retry());
close_and_unref_connection(get_global_conn()); close_and_unref_connection(get_global_conn(), false);
set_global_conn(NULL); set_global_conn(NULL);
if(get_parodus_cfg()->cloud_disconnect !=NULL) if(get_parodus_cfg()->cloud_disconnect !=NULL)
@@ -191,11 +199,10 @@ void createSocketConnection(void (* initKeypress)())
free(get_parodus_cfg()->cloud_disconnect); free(get_parodus_cfg()->cloud_disconnect);
reset_cloud_disconnect_reason(get_parodus_cfg()); reset_cloud_disconnect_reason(get_parodus_cfg());
} }
start_conn_in_progress (); createNopollConnection(ctx, &server_list);
createNopollConnection(ctx);
stop_conn_in_progress ();
} }
} while(!get_close_retry() && !g_shutdown); //process exit only when g_shutdown is true.
} while(FOREVER() && !g_shutdown);
pthread_mutex_lock (get_global_svc_mut()); pthread_mutex_lock (get_global_svc_mut());
pthread_cond_signal (get_global_svc_con()); pthread_cond_signal (get_global_svc_con());
@@ -220,11 +227,13 @@ void createSocketConnection(void (* initKeypress)())
deleteAllClients (); deleteAllClients ();
ParodusInfo ("reconnect reason at close %s\n", get_global_reconnect_reason()); ParodusInfo ("reconnect reason at close %s\n", get_global_reconnect_reason());
ParodusInfo ("shutdown reason at close %s\n", get_global_shutdown_reason()); close_and_unref_connection(get_global_conn(), true);
close_and_unref_connection(get_global_conn());
nopoll_ctx_unref(ctx); nopoll_ctx_unref(ctx);
nopoll_cleanup_library(); nopoll_cleanup_library();
curl_global_cleanup(); curl_global_cleanup();
clear_metadata();
rdk_logger_deinit();
free_server_list(&server_list);
} }
void shutdownSocketConnection(char *reason) { void shutdownSocketConnection(char *reason) {

View File

@@ -38,7 +38,7 @@
#define HTTP_CUSTOM_HEADER_COUNT 5 #define HTTP_CUSTOM_HEADER_COUNT 5
#define INITIAL_CJWT_RETRY -2 #define INITIAL_CJWT_RETRY -2
#define UPDATE_HEALTH_FILE_INTERVAL_SECS 450 #define UPDATE_HEALTH_FILE_INTERVAL_SECS 240
/* Close codes defined in RFC 6455, section 11.7. */ /* Close codes defined in RFC 6455, section 11.7. */
enum { enum {
@@ -62,6 +62,10 @@ enum {
/* File Scoped Variables */ /* File Scoped Variables */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
parodusOnConnStatusChangeHandler on_conn_status_change;
parodusOnPingStatusChangeHandler on_ping_status_change;
pthread_mutex_t backoff_delay_mut=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t backoff_delay_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t backoff_delay_con=PTHREAD_COND_INITIALIZER; pthread_cond_t backoff_delay_con=PTHREAD_COND_INITIALIZER;
@@ -128,7 +132,10 @@ void set_cloud_disconnect_time(int disconnTime)
cloud_disconnect_max_time = disconnTime; cloud_disconnect_max_time = disconnTime;
} }
int get_parodus_init()
{
return init;
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// createNopollConnection_logic: // createNopollConnection_logic:
@@ -232,7 +239,63 @@ void init_backoff_timer (backoff_timer_t *timer, int max_count)
timer->count = 1; timer->count = 1;
timer->max_count = max_count; timer->max_count = max_count;
timer->delay = 1; timer->delay = 1;
clock_gettime (CLOCK_REALTIME, &timer->ts); clock_gettime (CLOCK_MONOTONIC, &timer->ts);
timer->start_time = time(NULL);
}
unsigned update_backoff_delay (backoff_timer_t *timer)
{
if (timer->count < timer->max_count) {
timer->count += 1;
timer->delay = timer->delay + timer->delay + 1;
// 3,7,15,31 ..
}
return (unsigned) timer->delay;
}
void add_timespec (struct timespec *t1, struct timespec *t2)
{
t2->tv_sec += t1->tv_sec;
t2->tv_nsec += t1->tv_nsec;
if (t2->tv_nsec >= 1000000000) {
t2->tv_sec += 1;
t2->tv_nsec -= 1000000000;
}
}
unsigned calc_random_secs (int random_num, unsigned max_secs)
{
unsigned delay_secs = (unsigned) random_num & max_secs;
if (delay_secs < 3)
return delay_secs + 3;
else
return delay_secs;
}
unsigned calc_random_nsecs (int random_num)
{
/* random _num is in range 0..2147483648 */
unsigned n = (unsigned) random_num >> 1;
/* n is in range 0..1073741824 */
if (n < 1000000000)
return n;
return n - 1000000000;
}
void calc_random_expiration (int random_num1, int random_num2, backoff_timer_t *timer, struct timespec *ts)
{
unsigned max_secs = update_backoff_delay (timer); // 3,7,15,31
struct timespec ts_delay = {3, 0};
if (max_secs > 3) {
ts_delay.tv_sec = calc_random_secs (random_num1, max_secs);
ts_delay.tv_nsec = calc_random_nsecs (random_num2);
}
ParodusInfo("Waiting max delay %u backoffRetryTime %ld secs %ld usecs\n",
max_secs, ts_delay.tv_sec, ts_delay.tv_nsec/1000);
/* Add delay to expire time */
add_timespec (&ts_delay, ts);
} }
void terminate_backoff_delay (void) void terminate_backoff_delay (void)
@@ -242,21 +305,11 @@ void terminate_backoff_delay (void)
pthread_mutex_unlock (&backoff_delay_mut); pthread_mutex_unlock (&backoff_delay_mut);
} }
int update_backoff_delay (backoff_timer_t *timer)
{
if (timer->count < timer->max_count) {
timer->count += 1;
timer->delay = timer->delay + timer->delay + 1;
// 3,7,15,31 ..
}
return timer->delay;
}
#define BACKOFF_ERR -1 #define BACKOFF_ERR -1
#define BACKOFF_SHUTDOWN 1 #define BACKOFF_SHUTDOWN 1
#define BACKOFF_DELAY_TAKEN 0 #define BACKOFF_DELAY_TAKEN 0
void start_conn_in_progress (void); void start_conn_in_progress (unsigned long start_time);
/* backoff_delay /* backoff_delay
* *
@@ -272,22 +325,28 @@ static int backoff_delay (backoff_timer_t *timer)
struct timespec ts; struct timespec ts;
int rtn; int rtn;
pthread_condattr_t backoff_delay_cond_attr;
pthread_condattr_init (&backoff_delay_cond_attr);
pthread_condattr_setclock (&backoff_delay_cond_attr, CLOCK_MONOTONIC);
pthread_cond_init (&backoff_delay_con, &backoff_delay_cond_attr);
// periodically update the health file. // periodically update the health file.
clock_gettime (CLOCK_REALTIME, &ts); clock_gettime (CLOCK_MONOTONIC, &ts);
if ((ts.tv_sec - timer->ts.tv_sec) >= UPDATE_HEALTH_FILE_INTERVAL_SECS) { if ((ts.tv_sec - timer->ts.tv_sec) >= UPDATE_HEALTH_FILE_INTERVAL_SECS) {
start_conn_in_progress (); start_conn_in_progress (timer->start_time);
timer->ts.tv_sec += UPDATE_HEALTH_FILE_INTERVAL_SECS; timer->ts.tv_sec += UPDATE_HEALTH_FILE_INTERVAL_SECS;
} }
update_backoff_delay (timer); calc_random_expiration (random(), random(), timer, &ts);
ParodusInfo("Waiting with backoffRetryTime %d seconds\n", timer->delay);
ts.tv_sec += timer->delay;
pthread_mutex_lock (&backoff_delay_mut); pthread_mutex_lock (&backoff_delay_mut);
// The condition variable will only be set if we shut down. // The condition variable will only be set if we shut down.
rtn = pthread_cond_timedwait (&backoff_delay_con, &backoff_delay_mut, &ts); rtn = pthread_cond_timedwait (&backoff_delay_con, &backoff_delay_mut, &ts);
pthread_mutex_unlock (&backoff_delay_mut); pthread_mutex_unlock (&backoff_delay_mut);
pthread_condattr_destroy(&backoff_delay_cond_attr);
if (g_shutdown) if (g_shutdown)
return BACKOFF_SHUTDOWN; return BACKOFF_SHUTDOWN;
if ((rtn != 0) && (rtn != ETIMEDOUT)) { if ((rtn != 0) && (rtn != ETIMEDOUT)) {
@@ -373,7 +432,7 @@ char *build_extra_hdrs (header_info_t *header_info)
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void set_current_server (create_connection_ctx_t *ctx) void set_current_server (create_connection_ctx_t *ctx)
{ {
ctx->current_server = get_current_server (&ctx->server_list); ctx->current_server = get_current_server (ctx->server_list);
} }
void free_extra_headers (create_connection_ctx_t *ctx) void free_extra_headers (create_connection_ctx_t *ctx)
@@ -399,7 +458,8 @@ void free_connection_ctx (create_connection_ctx_t *ctx)
{ {
free_extra_headers (ctx); free_extra_headers (ctx);
free_header_info (&ctx->header_info); free_header_info (&ctx->header_info);
free_server_list (&ctx->server_list); if (NULL != ctx->server_list)
free_server_list (ctx->server_list);
} }
@@ -416,8 +476,10 @@ int find_servers (server_list_t *server_list)
free_server_list (server_list); free_server_list (server_list);
// parse default server URL // parse default server URL
if (parse_server_url (get_parodus_cfg()->webpa_url, default_server) < 0) if (parse_server_url (get_parodus_cfg()->webpa_url, default_server) < 0) {
return FIND_INVALID_DEFAULT; // must have valid default url ParodusError ("Invalid Default URL\n");
return FIND_INVALID_DEFAULT;
}
ParodusInfo("default server_Address %s\n", default_server->server_addr); ParodusInfo("default server_Address %s\n", default_server->server_addr);
ParodusInfo("default port %u\n", default_server->port); ParodusInfo("default port %u\n", default_server->port);
#ifdef FEATURE_DNS_QUERY #ifdef FEATURE_DNS_QUERY
@@ -435,7 +497,6 @@ int find_servers (server_list_t *server_list)
return FIND_SUCCESS; return FIND_SUCCESS;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// connect to current server // connect to current server
int nopoll_connect (create_connection_ctx_t *ctx, int is_ipv6) int nopoll_connect (create_connection_ctx_t *ctx, int is_ipv6)
@@ -509,12 +570,12 @@ int wait_connection_ready (create_connection_ctx_t *ctx)
if(wait_status == 307 || wait_status == 302 || wait_status == 303) // only when there is a http redirect if(wait_status == 307 || wait_status == 302 || wait_status == 303) // only when there is a http redirect
{ {
char *redirect_ptr = redirectURL; char *redirect_ptr = redirectURL;
ParodusError("Received temporary redirection response message %s\n", redirectURL); ParodusInfo("Received temporary redirection response message %s\n", redirectURL);
// Extract server Address and port from the redirectURL // Extract server Address and port from the redirectURL
if (strncmp (redirect_ptr, "Redirect:", 9) == 0) if (strncmp (redirect_ptr, "Redirect:", 9) == 0)
redirect_ptr += 9; redirect_ptr += 9;
free_server (&ctx->server_list.redirect); free_server (&ctx->server_list->redirect);
if (parse_server_url (redirect_ptr, &ctx->server_list.redirect) < 0) { if (parse_server_url (redirect_ptr, &ctx->server_list->redirect) < 0) {
ParodusError ("Redirect url error %s\n", redirectURL); ParodusError ("Redirect url error %s\n", redirectURL);
free (redirectURL); free (redirectURL);
return WAIT_FAIL; return WAIT_FAIL;
@@ -543,7 +604,7 @@ int wait_connection_ready (create_connection_ctx_t *ctx)
// Return codes for connect_and_wait // Return codes for connect_and_wait
#define CONN_WAIT_SUCCESS 0 #define CONN_WAIT_SUCCESS 0
#define CONN_WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303, or 403 #define CONN_WAIT_ACTION_RETRY 1 // if wait_status is 307, 302, 303, or 403
#define CONN_WAIT_RETRY_DNS 2 #define CONN_WAIT_FAIL 2
int connect_and_wait (create_connection_ctx_t *ctx) int connect_and_wait (create_connection_ctx_t *ctx)
{ {
@@ -574,7 +635,7 @@ int connect_and_wait (create_connection_ctx_t *ctx)
} // nopoll_connected } // nopoll_connected
if (nopoll_connected) { if (nopoll_connected) {
close_and_unref_connection(get_global_conn()); close_and_unref_connection(get_global_conn(), false);
set_global_conn(NULL); set_global_conn(NULL);
} }
@@ -587,7 +648,7 @@ int connect_and_wait (create_connection_ctx_t *ctx)
continue; continue;
} }
return CONN_WAIT_RETRY_DNS; return CONN_WAIT_FAIL;
} }
} }
@@ -610,13 +671,12 @@ int keep_trying_to_connect (create_connection_ctx_t *ctx,
if (rtn == CONN_WAIT_ACTION_RETRY) // if redirected or build_headers if (rtn == CONN_WAIT_ACTION_RETRY) // if redirected or build_headers
continue; continue;
// If interface down event is set, stop retry // If interface down event is set, stop retry
// and wait till interface is up again. // and wait till interface is up again.
if(get_interface_down_event()) { if(get_interface_down_event()) {
if (0 != wait_while_interface_down()) if (0 != wait_while_interface_down())
return false; return false;
start_conn_in_progress(); start_conn_in_progress(backoff_timer->start_time);
ParodusInfo("Interface is back up, re-initializing the convey header\n"); ParodusInfo("Interface is back up, re-initializing the convey header\n");
// Reset the reconnect reason by initializing the convey header again // Reset the reconnect reason by initializing the convey header again
((header_info_t *)(&ctx->header_info))->conveyHeader = getWebpaConveyHeader(); ((header_info_t *)(&ctx->header_info))->conveyHeader = getWebpaConveyHeader();
@@ -626,9 +686,9 @@ int keep_trying_to_connect (create_connection_ctx_t *ctx,
!= BACKOFF_DELAY_TAKEN) // shutdown or cond wait error != BACKOFF_DELAY_TAKEN) // shutdown or cond wait error
return false; return false;
} }
if (rtn == CONN_WAIT_FAIL) {
if (rtn == CONN_WAIT_RETRY_DNS) return false;
return false; //find_server again }
// else retry // else retry
} }
return false; return false;
@@ -640,21 +700,20 @@ int wait_while_interface_down()
int rtn; int rtn;
ParodusError("Interface is down, hence waiting until its up\n"); ParodusError("Interface is down, hence waiting until its up\n");
close_and_unref_connection (get_global_conn()); close_and_unref_connection (get_global_conn(), false);
set_global_conn(NULL); set_global_conn(NULL);
while (get_interface_down_event ()) { while (get_interface_down_event ()) {
pthread_mutex_lock(get_interface_down_mut()); pthread_mutex_lock(get_interface_down_mut());
rtn = pthread_cond_wait(get_interface_down_con(), get_interface_down_mut()); rtn = pthread_cond_wait(get_interface_down_con(), get_interface_down_mut());
pthread_mutex_unlock (get_interface_down_mut()); pthread_mutex_unlock (get_interface_down_mut());
if (rtn != 0) if (rtn != 0)
ParodusError("Error on pthread_cond_wait (%d) in wait_while_interface_down\n", rtn); ParodusError
("Error on pthread_cond_wait (%d) in wait_while_interface_down\n", rtn);
if ((rtn != 0) || g_shutdown) if (g_shutdown) {
ParodusInfo("Received g_shutdown during interface down wait, returning\n");
return -1; return -1;
}
} }
return 0; return 0;
} }
@@ -665,14 +724,13 @@ int wait_while_interface_down()
* @brief createNopollConnection interface to create WebSocket client connections. * @brief createNopollConnection interface to create WebSocket client connections.
*Loads the WebPA config file and creates the intial connection and manages the connection wait, close mechanisms. *Loads the WebPA config file and creates the intial connection and manages the connection wait, close mechanisms.
*/ */
int createNopollConnection(noPollCtx *ctx) int createNopollConnection(noPollCtx *ctx, server_list_t *server_list)
{ {
create_connection_ctx_t conn_ctx; create_connection_ctx_t conn_ctx;
int max_retry_count; int max_retry_count;
int query_dns_status;
struct timespec connect_time,*connectTimePtr;
connectTimePtr = &connect_time;
backoff_timer_t backoff_timer; backoff_timer_t backoff_timer;
static int init_conn_failure=1;
struct sysinfo l_sSysInfo;
if(ctx == NULL) { if(ctx == NULL) {
return nopoll_false; return nopoll_false;
@@ -689,22 +747,43 @@ int createNopollConnection(noPollCtx *ctx)
conn_ctx.nopoll_ctx = ctx; conn_ctx.nopoll_ctx = ctx;
init_expire_timer (&conn_ctx.connect_timer); init_expire_timer (&conn_ctx.connect_timer);
init_header_info (&conn_ctx.header_info); init_header_info (&conn_ctx.header_info);
set_server_list_null (&conn_ctx.server_list); /* look up server information if we don't already have it */
init_backoff_timer (&backoff_timer, max_retry_count); if (server_is_null (&server_list->defaults))
if (find_servers (server_list) == FIND_INVALID_DEFAULT) {
return nopoll_false;
}
conn_ctx.server_list = server_list;
init_backoff_timer (&backoff_timer, max_retry_count);
start_conn_in_progress (backoff_timer.start_time);
while (!g_shutdown) while (!g_shutdown)
{ {
query_dns_status = find_servers (&conn_ctx.server_list);
if (query_dns_status == FIND_INVALID_DEFAULT)
return nopoll_false;
set_current_server (&conn_ctx); set_current_server (&conn_ctx);
if (keep_trying_to_connect (&conn_ctx, &backoff_timer)) if (keep_trying_to_connect (&conn_ctx, &backoff_timer)) {
// Don't reuse the redirect server during reconnect
free_server (&conn_ctx.server_list->redirect);
break; break;
}
/* if we failed to connect, don't reuse the redirect server */
free_server (&conn_ctx.server_list->redirect);
// retry dns query /* On initial connect failure, invoke conn status change event as "failed" only 1 time*/
if((NULL != on_conn_status_change) && init && init_conn_failure)
{
on_conn_status_change("failed");
init_conn_failure=0;
}
#ifdef FEATURE_DNS_QUERY
/* if we don't already have a valid jwt, look up server information */
if (server_is_null (&conn_ctx.server_list->jwt))
if (find_servers (conn_ctx.server_list) == FIND_INVALID_DEFAULT) {
/* since we already found a default server, we don't expect FIND_INVALID_DEFAULT */
g_shutdown = true;
}
#endif
} }
if(conn_ctx.current_server != NULL && conn_ctx.current_server->allow_insecure <= 0)
if(conn_ctx.current_server->allow_insecure <= 0)
{ {
ParodusInfo("Connected to server over SSL\n"); ParodusInfo("Connected to server over SSL\n");
OnboardLog("Connected to server over SSL\n"); OnboardLog("Connected to server over SSL\n");
@@ -715,8 +794,11 @@ int createNopollConnection(noPollCtx *ctx)
OnboardLog("Connected to server\n"); OnboardLog("Connected to server\n");
} }
get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE; /* On initial connect success, invoke conn status change event as "success" */
ParodusInfo("cloud_status set as %s after successful connection\n", get_parodus_cfg()->cloud_status); if((NULL != on_conn_status_change) && init)
{
on_conn_status_change("success");
}
// Invoke the ping status change event callback as "received" ping // Invoke the ping status change event callback as "received" ping
if(NULL != on_ping_status_change) if(NULL != on_ping_status_change)
@@ -724,15 +806,14 @@ int createNopollConnection(noPollCtx *ctx)
on_ping_status_change("received"); on_ping_status_change("received");
} }
if((get_parodus_cfg()->boot_time != 0) && init) { if(init) {
getCurrentTime(connectTimePtr); sysinfo(&l_sSysInfo);
ParodusInfo("connect_time-diff-boot_time=%d\n", connectTimePtr->tv_sec - get_parodus_cfg()->boot_time); ParodusInfo("connect_time-diff-boot_time=%ld\n", l_sSysInfo.uptime);
init = 0; //set init to 0 so that this is logged only during process start up and not during reconnect init = 0; //set init to 0 so that this is logged only during process start up and not during reconnect
} }
free_extra_headers (&conn_ctx); free_extra_headers (&conn_ctx);
free_header_info (&conn_ctx.header_info); free_header_info (&conn_ctx.header_info);
free_server_list (&conn_ctx.server_list);
// Reset close_retry flag and heartbeatTimer once the connection retry is successful // Reset close_retry flag and heartbeatTimer once the connection retry is successful
ParodusPrint("createNopollConnection(): reset_close_retry\n"); ParodusPrint("createNopollConnection(): reset_close_retry\n");
@@ -742,7 +823,10 @@ int createNopollConnection(noPollCtx *ctx)
set_global_reconnect_status(false); set_global_reconnect_status(false);
ParodusPrint("LastReasonStatus reset after successful connection\n"); ParodusPrint("LastReasonStatus reset after successful connection\n");
setMessageHandlers(); setMessageHandlers();
stop_conn_in_progress ();
ParodusPrint("set cloud_status\n");
set_cloud_status(CLOUD_STATUS_ONLINE);
ParodusInfo("cloud_status set as %s after successful connection\n", get_cloud_status());
return nopoll_true; return nopoll_true;
} }
@@ -787,29 +871,52 @@ static noPollConnOpts * createConnOpts (char * extra_headers, bool secure)
nopoll_conn_opts_ssl_peer_verify (opts, nopoll_true); nopoll_conn_opts_ssl_peer_verify (opts, nopoll_true);
nopoll_conn_opts_set_ssl_protocol (opts, NOPOLL_METHOD_TLSV1_2); nopoll_conn_opts_set_ssl_protocol (opts, NOPOLL_METHOD_TLSV1_2);
} }
nopoll_conn_opts_set_interface (opts,get_parodus_cfg()->webpa_interface_used); nopoll_conn_opts_set_interface (opts,getWebpaInterface());
nopoll_conn_opts_set_extra_headers (opts,extra_headers); nopoll_conn_opts_set_extra_headers (opts,extra_headers);
return opts; return opts;
} }
static void close_conn ( noPollConn *conn, bool is_shutting_down)
{
const char *effective_reason = get_global_shutdown_reason();
void close_and_unref_connection(noPollConn *conn) if (NULL == effective_reason) {
effective_reason = SHUTDOWN_REASON_SYSTEM_RESTART;
}
else if (strcmp (effective_reason, SHUTDOWN_REASON_SIGTERM) == 0) {
char *sigterm_reason;
char *reason_file = get_parodus_cfg()->close_reason_file;
if ((NULL != reason_file) && readFromFile (reason_file, &sigterm_reason) &&
(strlen(sigterm_reason) != 0))
{
nopoll_conn_close_ext(conn, CloseNormalClosure, sigterm_reason,
strlen (sigterm_reason));
ParodusInfo ("Closed by SIGTERM, reason: %s\n", sigterm_reason);
if (is_shutting_down)
ParodusInfo ("shutdown reason at close %s\n", sigterm_reason);
free (sigterm_reason);
return;
}
/* file could not be read. use canned message. */
effective_reason = SHUTDOWN_REASON_SYSTEM_RESTART;
ParodusError ("Closed by SIGTERM, but no reason file\n");
}
nopoll_conn_close_ext(conn, CloseNormalClosure, effective_reason,
strlen (effective_reason));
if (is_shutting_down)
ParodusInfo ("shutdown reason at close %s\n", effective_reason);
}
void close_and_unref_connection(noPollConn *conn, bool is_shutting_down)
{ {
if (conn) { if (conn) {
const char *reason = get_global_shutdown_reason(); close_conn (conn, is_shutting_down);
int reason_len = 0; set_cloud_status(CLOUD_STATUS_OFFLINE);
int status = CloseNoStatus; ParodusInfo("cloud_status set as %s after connection close\n", get_cloud_status());
if (NULL != reason) {
reason_len = (int) strlen (reason);
status = CloseNormalClosure;
}
nopoll_conn_close_ext(conn, status, reason, reason_len);
get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE;
ParodusInfo("cloud_status set as %s after connection close\n", get_parodus_cfg()->cloud_status);
} }
} }
void write_conn_in_prog_file (const char *msg) void write_conn_in_prog_file (bool is_starting, unsigned long start_time)
{ {
int fd; int fd;
FILE *fp; FILE *fp;
@@ -830,18 +937,22 @@ void write_conn_in_prog_file (const char *msg)
return; return;
} }
timestamp = (unsigned long) time(NULL); timestamp = (unsigned long) time(NULL);
fprintf (fp, "{%s=%lu}\n", msg, timestamp); if (is_starting)
fprintf (fp, "{START=%lu,%lu}\n", start_time, timestamp);
else
fprintf (fp, "{STOP=%lu}\n", timestamp);
fclose (fp); fclose (fp);
} }
void start_conn_in_progress (void) void start_conn_in_progress (unsigned long start_time)
{ {
write_conn_in_prog_file ("START"); write_conn_in_prog_file (true, start_time);
} }
void stop_conn_in_progress (void) void stop_conn_in_progress (void)
{ {
write_conn_in_prog_file ("STOP"); write_conn_in_prog_file (false, 0);
} }
@@ -850,3 +961,8 @@ void registerParodusOnPingStatusChangeHandler(parodusOnPingStatusChangeHandler c
on_ping_status_change = callback_func; on_ping_status_change = callback_func;
} }
void registerParodusOnConnStatusChangeHandler(parodusOnConnStatusChangeHandler callback_func)
{
on_conn_status_change = callback_func;
}

View File

@@ -35,6 +35,16 @@ extern "C" {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
#define SHUTDOWN_REASON_PARODUS_STOP "parodus_stopping" #define SHUTDOWN_REASON_PARODUS_STOP "parodus_stopping"
#define SHUTDOWN_REASON_SYSTEM_RESTART "system_restarting" #define SHUTDOWN_REASON_SYSTEM_RESTART "system_restarting"
#define SHUTDOWN_REASON_SIGTERM "SIGTERM"
/**
* parodusOnConnStatusChangeHandler - Function pointer
* Used to define callback function to do additional processing
* when websocket cloud connection status change event
* i.e. "cloud-conn-status" as "fail" or "success"
*/
typedef void (*parodusOnConnStatusChangeHandler) (char * status);
extern parodusOnConnStatusChangeHandler on_conn_status_change;
/** /**
* parodusOnPingStatusChangeHandler - Function pointer * parodusOnPingStatusChangeHandler - Function pointer
@@ -43,18 +53,19 @@ extern "C" {
* i.e. ping_miss or ping receive after miss * i.e. ping_miss or ping receive after miss
*/ */
typedef void (*parodusOnPingStatusChangeHandler) (char * status); typedef void (*parodusOnPingStatusChangeHandler) (char * status);
parodusOnPingStatusChangeHandler on_ping_status_change; extern parodusOnPingStatusChangeHandler on_ping_status_change;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Function Prototypes */ /* Function Prototypes */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
int createNopollConnection(noPollCtx *); void set_server_list_null (server_list_t *server_list);
int createNopollConnection(noPollCtx *, server_list_t *);
/** /**
* @brief Interface to terminate WebSocket client connections and clean up resources. * @brief Interface to terminate WebSocket client connections and clean up resources.
*/ */
void close_and_unref_connection(noPollConn *); void close_and_unref_connection(noPollConn *conn, bool is_shutting_down);
noPollConn *get_global_conn(void); noPollConn *get_global_conn(void);
void set_global_conn(noPollConn *); void set_global_conn(noPollConn *);
@@ -74,9 +85,12 @@ void set_cloud_disconnect_time(int disconnTime);
/** /**
* @brief Interface to self heal connection in progress getting stuck * @brief Interface to self heal connection in progress getting stuck
*/ */
void start_conn_in_progress (void); void start_conn_in_progress (unsigned long start_time);
void stop_conn_in_progress (void); void stop_conn_in_progress (void);
// To Register parodusOnConnStatusChangeHandler Callback function
void registerParodusOnConnStatusChangeHandler(parodusOnConnStatusChangeHandler on_conn_status_change);
// To Register parodusOnPingStatusChangeHandler Callback function // To Register parodusOnPingStatusChangeHandler Callback function
void registerParodusOnPingStatusChangeHandler(parodusOnPingStatusChangeHandler on_ping_status_change); void registerParodusOnPingStatusChangeHandler(parodusOnPingStatusChangeHandler on_ping_status_change);

View File

@@ -26,6 +26,9 @@
#include "config.h" #include "config.h"
#include "connection.h" #include "connection.h"
#include "close_retry.h" #include "close_retry.h"
#include "client_list.h"
#define SERVICE_STATUS "service-status"
static void freeObjArray(char *(*obj)[], int size); static void freeObjArray(char *(*obj)[], int size);
static int writeIntoCrudJson(cJSON *res_obj, char * object, cJSON *objValue, int freeFlag); static int writeIntoCrudJson(cJSON *res_obj, char * object, cJSON *objValue, int freeFlag);
@@ -33,6 +36,7 @@ static int parse_dest_elements_to_string(wrp_msg_t *reqMsg, char *(*obj)[]);
static char* strdupptr( const char *s, const char *e ); static char* strdupptr( const char *s, const char *e );
static int ConnDisconnectFromCloud(char *reason); static int ConnDisconnectFromCloud(char *reason);
static int validateDisconnectString(char *reason); static int validateDisconnectString(char *reason);
static int getClientStatus(char *service, cJSON **jsonresponse);
int writeToJSON(char *data) int writeToJSON(char *data)
{ {
@@ -58,22 +62,7 @@ int writeToJSON(char *data)
int readFromJSON(char **data) int readFromJSON(char **data)
{ {
FILE *fp; return readFromFile (get_parodus_cfg()->crud_config_file, data);
int ch_count = 0;
fp = fopen(get_parodus_cfg()->crud_config_file, "r+");
if (fp == NULL)
{
ParodusError("Failed to open file %s\n", get_parodus_cfg()->crud_config_file);
return 0;
}
fseek(fp, 0, SEEK_END);
ch_count = ftell(fp);
fseek(fp, 0, SEEK_SET);
*data = (char *) malloc(sizeof(char) * (ch_count + 1));
fread(*data, 1, ch_count,fp);
(*data)[ch_count] ='\0';
fclose(fp);
return 1;
} }
/* /*
* @res_obj json object to add it in crud config json file * @res_obj json object to add it in crud config json file
@@ -548,13 +537,13 @@ int retrieveFromMemory(char *keyName, cJSON **jsonresponse)
} }
else if(strcmp(WEBPA_INTERFACE, keyName)==0) else if(strcmp(WEBPA_INTERFACE, keyName)==0)
{ {
if((get_parodus_cfg()->webpa_interface_used !=NULL)&& (strlen(get_parodus_cfg()->fw_name)==0)) if((getWebpaInterface() !=NULL)&& (strlen(get_parodus_cfg()->fw_name)==0))
{ {
ParodusError("retrieveFromMemory: webpa_interface_used value is NULL\n"); ParodusError("retrieveFromMemory: webpa_interface_used value is NULL\n");
return -1; return -1;
} }
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n",keyName,get_parodus_cfg()->webpa_interface_used); ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n",keyName,getWebpaInterface());
cJSON_AddItemToObject( *jsonresponse, WEBPA_INTERFACE , cJSON_CreateString(get_parodus_cfg()->webpa_interface_used)); cJSON_AddItemToObject( *jsonresponse, WEBPA_INTERFACE , cJSON_CreateString(getWebpaInterface()));
} }
else if(strcmp(WEBPA_URL, keyName)==0) else if(strcmp(WEBPA_URL, keyName)==0)
{ {
@@ -588,20 +577,20 @@ int retrieveFromMemory(char *keyName, cJSON **jsonresponse)
} }
else if(strcmp(CLOUD_STATUS, keyName)==0) else if(strcmp(CLOUD_STATUS, keyName)==0)
{ {
if(get_parodus_cfg()->cloud_status ==NULL) if(get_cloud_status() ==NULL)
{ {
ParodusError("retrieveFromMemory: cloud_status value is NULL\n"); ParodusError("retrieveFromMemory: cloud_status value is NULL\n");
return -1; return -1;
} }
else if((get_parodus_cfg()->cloud_status !=NULL) && (strlen(get_parodus_cfg()->cloud_status)==0)) else if((get_cloud_status() !=NULL) && (strlen(get_cloud_status())==0))
{ {
ParodusError("retrieveFromMemory: cloud_status value is empty\n"); ParodusError("retrieveFromMemory: cloud_status value is empty\n");
return -1; return -1;
} }
else else
{ {
ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n", keyName, get_parodus_cfg()->cloud_status); ParodusInfo("retrieveFromMemory: keyName:%s value:%s\n", keyName, get_cloud_status());
cJSON_AddItemToObject( *jsonresponse, CLOUD_STATUS , cJSON_CreateString(get_parodus_cfg()->cloud_status)); cJSON_AddItemToObject( *jsonresponse, CLOUD_STATUS , cJSON_CreateString(get_cloud_status()));
} }
} }
else if(strcmp(BOOT_TIME, keyName)==0) else if(strcmp(BOOT_TIME, keyName)==0)
@@ -654,10 +643,17 @@ int retrieveObject( wrp_msg_t *reqMsg, wrp_msg_t **response )
} }
ParodusInfo( "Number of object level %d\n", objlevel ); ParodusInfo( "Number of object level %d\n", objlevel );
if((objlevel == 3 && ((obj[3] !=NULL) && strstr(obj[3] ,"tags") == NULL)) || (objlevel == 4 && ((obj[3] !=NULL) && strstr(obj[3] ,"service-status") != NULL)))
if(objlevel == 3 && ((obj[3] !=NULL) && strstr(obj[3] ,"tags") == NULL))
{ {
inMemStatus = retrieveFromMemory(obj[3], &inMemResponse ); //To support dest "mac:14xxxxxxxxxx/parodus/service-status/service" to retrieve online/offline status of registered clients.
if(strstr(obj[3] ,"service-status") !=NULL)
{
inMemStatus = getClientStatus(obj[4], &inMemResponse );
}
else
{
inMemStatus = retrieveFromMemory(obj[3], &inMemResponse );
}
if(inMemStatus == 0) if(inMemStatus == 0)
{ {
@@ -1628,3 +1624,27 @@ static int validateDisconnectString(char *reason)
} }
return rv; return rv;
} }
static int getClientStatus(char *service, cJSON **jsonresponse)
{
char regstatus[16] ={0};
*jsonresponse = cJSON_CreateObject();
if(service == NULL)
{
ParodusError("service is NULL\n");
return -1;
}
if(checkClientStatus(service))
{
strncpy(regstatus, "online", sizeof(regstatus)-1);
}
else
{
strncpy(regstatus, "offline", sizeof(regstatus)-1);
}
ParodusPrint("getClientStatus: service:%s value:%s\n", service, regstatus);
cJSON_AddItemToObject( *jsonresponse, SERVICE_STATUS , cJSON_CreateString(regstatus));
return 0;
}

View File

@@ -27,6 +27,9 @@
#include "partners_check.h" #include "partners_check.h"
#include "ParodusInternal.h" #include "ParodusInternal.h"
#include "crud_interface.h" #include "crud_interface.h"
#ifdef ENABLE_WEBCFGBIN
#include "xmidtsend_rbus.h"
#endif
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Function Prototypes */ /* Function Prototypes */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -91,6 +94,7 @@ void listenerOnMessage(void * msg, size_t msgSize)
{ {
ParodusPrint("numOfClients registered is %d\n", get_numOfClients()); ParodusPrint("numOfClients registered is %d\n", get_numOfClients());
int ret = validate_partner_id(message, NULL); int ret = validate_partner_id(message, NULL);
ParodusPrint("validate_partner_id returns %d\n", ret);
if(ret < 0) if(ret < 0)
{ {
response = cJSON_CreateObject(); response = cJSON_CreateObject();
@@ -98,7 +102,6 @@ void listenerOnMessage(void * msg, size_t msgSize)
cJSON_AddStringToObject(response, "message", "Invalid partner_id"); cJSON_AddStringToObject(response, "message", "Invalid partner_id");
} }
destVal = strdup(((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.dest : destVal = strdup(((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.dest :
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.dest : message->u.crud.dest))); ((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.dest : message->u.crud.dest)));
@@ -120,10 +123,10 @@ void listenerOnMessage(void * msg, size_t msgSize)
} }
ParodusInfo("Received downstream dest as :%s and transaction_uuid :%s\n", dest, ParodusInfo("Received downstream dest as :%s and transaction_uuid :%s\n", dest,
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.transaction_uuid : ((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.transaction_uuid :
((WRP_MSG_TYPE__EVENT == msgType) ? "NA" : message->u.crud.transaction_uuid))); ((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.transaction_uuid : message->u.crud.transaction_uuid)));
OnboardLog("%s\n", OnboardLog("%s\n",
((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.transaction_uuid : ((WRP_MSG_TYPE__REQ == msgType) ? message->u.req.transaction_uuid :
((WRP_MSG_TYPE__EVENT == msgType) ? "NA" : message->u.crud.transaction_uuid))); ((WRP_MSG_TYPE__EVENT == msgType) ? message->u.event.transaction_uuid : message->u.crud.transaction_uuid)));
free(destVal); free(destVal);
@@ -168,13 +171,16 @@ void listenerOnMessage(void * msg, size_t msgSize)
destFlag =1; destFlag =1;
} }
//if any unknown dest received sending error response to server //if any unknown dest received sending error response to server
if(destFlag ==0) if (WRP_MSG_TYPE__EVENT != msgType)
{ {
ParodusError("Unknown dest:%s\n", dest); if(destFlag ==0)
response = cJSON_CreateObject(); {
cJSON_AddNumberToObject(response, "statusCode", 531); ParodusError("Unknown dest:%s\n", dest);
cJSON_AddStringToObject(response, "message", "Service Unavailable"); response = cJSON_CreateObject();
} cJSON_AddNumberToObject(response, "statusCode", 531);
cJSON_AddStringToObject(response, "message", "Service Unavailable");
}
}
} }
if( (WRP_MSG_TYPE__EVENT != msgType) && if( (WRP_MSG_TYPE__EVENT != msgType) &&
@@ -235,6 +241,37 @@ void listenerOnMessage(void * msg, size_t msgSize)
} }
free(resp_msg); free(resp_msg);
} }
#ifdef ENABLE_WEBCFGBIN
//To handle cloud ack events received from server for the xmidt sent messages.
if((WRP_MSG_TYPE__EVENT == msgType) && (ret >= 0))
{
if(get_parodus_cfg()->max_queue_size > 0)
{
//Process cloud ack only when qos > 24
if(highQosValueCheck(message->u.event.qos))
{
if(message->u.event.transaction_uuid !=NULL)
{
ParodusInfo("Received cloud ack from server: transaction_uuid %s qos %d, rdr %d source %s\n", message->u.event.transaction_uuid, message->u.event.qos, message->u.event.rdr, message->u.event.source);
addToCloudAckQ(message->u.event.transaction_uuid, message->u.event.qos, message->u.event.rdr, message->u.event.source);
ParodusPrint("Added to cloud ack Q\n");
}
else
{
ParodusError("cloud ack transaction id is NULL\n");
}
}
else
{
ParodusInfo("cloud ack received with low qos %d, ignoring it\n", message->u.event.qos);
}
}
else
{
ParodusInfo("cloud ack is ignored as max queue size is %d\n", get_parodus_cfg()->max_queue_size );
}
}
#endif
break; break;
} }

26
src/event_handler.c Normal file
View File

@@ -0,0 +1,26 @@
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2016 RDK Management
* Copyright [2014] [Cisco Systems, Inc.]
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* This is a stub file that will be overridden in a patch */
#include "event_handler.h"
void EventHandler()
{
}

21
src/event_handler.h Normal file
View File

@@ -0,0 +1,21 @@
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2016 RDK Management
* Copyright [2014] [Cisco Systems, Inc.]
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
void EventHandler();
#define LOGGING_INTERVAL_SECS ( 60 * 60 )

View File

@@ -22,12 +22,15 @@
*/ */
#include "heartBeat.h" #include "heartBeat.h"
#include "time.h"
#include <stdbool.h> #include <stdbool.h>
volatile unsigned int heartBeatTimer = 0; volatile unsigned int heartBeatTimer = 0;
volatile bool paused = false; volatile bool paused = false;
volatile long long pingTimeStamp = 0;
pthread_mutex_t heartBeat_mut=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t heartBeat_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t ping_mut=PTHREAD_MUTEX_INITIALIZER;
// Get value of heartBeatTimer // Get value of heartBeatTimer
unsigned int get_heartBeatTimer() unsigned int get_heartBeatTimer()
@@ -73,5 +76,22 @@ void resume_heartBeatTimer()
pthread_mutex_unlock (&heartBeat_mut); pthread_mutex_unlock (&heartBeat_mut);
} }
// Set ping received timeStamp
void set_pingTimeStamp()
{
struct timespec ts;
getCurrentTime(&ts);
pthread_mutex_lock (&ping_mut);
pingTimeStamp = (long long)ts.tv_sec;
pthread_mutex_unlock (&ping_mut);
}
// Get ping received timeStamp
long long get_pingTimeStamp()
{
long long tmp = 0;
pthread_mutex_lock (&ping_mut);
tmp = pingTimeStamp;
pthread_mutex_unlock (&ping_mut);
return tmp;
}

View File

@@ -45,6 +45,10 @@ void pause_heartBeatTimer();
// Resume heartBeatTimer, i.e. resume incrementing // Resume heartBeatTimer, i.e. resume incrementing
void resume_heartBeatTimer(); void resume_heartBeatTimer();
void set_pingTimeStamp();
long long get_pingTimeStamp();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -24,9 +24,14 @@
#include "parodus_log.h" #include "parodus_log.h"
#include <curl/curl.h> #include <curl/curl.h>
#ifdef INCLUDE_BREAKPAD #ifdef INCLUDE_BREAKPAD
#ifndef DEVICE_CAMERA
#include "breakpad_wrapper.h" #include "breakpad_wrapper.h"
#else
#include "breakpadwrap.h"
#endif //DEVICE_CAMERA
#endif #endif
#include "signal.h" #include "signal.h"
#include "privilege.h"
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Macros */ /* Macros */
@@ -41,7 +46,7 @@ typedef void Sigfunc(int);
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* File Scoped Variables */ /* File Scoped Variables */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* none */ int numLoops;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Function Prototypes */ /* Function Prototypes */
@@ -86,8 +91,17 @@ int main( int argc, char **argv)
signal(SIGHUP, sig_handler); signal(SIGHUP, sig_handler);
signal(SIGALRM, sig_handler); signal(SIGALRM, sig_handler);
#ifdef INCLUDE_BREAKPAD #ifdef INCLUDE_BREAKPAD
#ifndef DEVICE_CAMERA
/* breakpad handles the signals SIGSEGV, SIGBUS, SIGFPE, and SIGILL */ /* breakpad handles the signals SIGSEGV, SIGBUS, SIGFPE, and SIGILL */
breakpad_ExceptionHandler(); breakpad_ExceptionHandler();
#else
/* breakpad handles the signals SIGSEGV, SIGBUS, SIGFPE, and SIGILL */
BreakPadWrapExceptionHandler eh;
eh = newBreakPadWrapExceptionHandler();
if(NULL != eh) {
ParodusInfo("Breakpad Initialized\n");
}
#endif //DEVICE_CAMERA
#else #else
signal(SIGSEGV, sig_handler); signal(SIGSEGV, sig_handler);
signal(SIGBUS, sig_handler); signal(SIGBUS, sig_handler);
@@ -96,11 +110,20 @@ int main( int argc, char **argv)
#endif #endif
ParodusCfg *cfg; ParodusCfg *cfg;
ParodusInfo ("RAND_MAX is %ld (0x%lx)\n", RAND_MAX, RAND_MAX);
srandom (getpid());
/* TODO not ideal, but it fixes a more major problem for now. */ /* TODO not ideal, but it fixes a more major problem for now. */
cfg = get_parodus_cfg(); cfg = get_parodus_cfg();
memset(cfg,0,sizeof(ParodusCfg)); memset(cfg,0,sizeof(ParodusCfg));
ParodusInfo("********** Starting component: Parodus **********\n "); ParodusInfo("********** Starting component: Parodus **********\n ");
drop_root_privilege();
#ifdef ENABLE_WEBCFGBIN
registerRbusLogger();
subscribeRBUSevent();
regXmidtSendDataMethod();
#endif
setDefaultValuesToCfg(cfg); setDefaultValuesToCfg(cfg);
if (0 != parseCommandLine(argc,argv,cfg)) { if (0 != parseCommandLine(argc,argv,cfg)) {
abort(); abort();
@@ -108,7 +131,7 @@ int main( int argc, char **argv)
curl_global_init(CURL_GLOBAL_DEFAULT); curl_global_init(CURL_GLOBAL_DEFAULT);
createSocketConnection( NULL); createSocketConnection( NULL);
free_cfg(cfg);
return 0; return 0;
} }
@@ -137,8 +160,15 @@ static void sig_handler(int sig)
} }
else if ( sig == SIGUSR2 ) else if ( sig == SIGUSR2 )
{ {
signal(SIGUSR2, sig_handler); /* reset it to this function */
ParodusInfo("SIGUSR2 received!\n"); ParodusInfo("SIGUSR2 received!\n");
} }
else if ( sig == SIGTERM )
{
signal(SIGTERM, sig_handler); /* reset it to this function */
ParodusInfo("SIGTERM received!\n");
shutdownSocketConnection(SHUTDOWN_REASON_SIGTERM);
}
else if ( sig == SIGCHLD ) else if ( sig == SIGCHLD )
{ {
signal(SIGCHLD, sig_handler); /* reset it to this function */ signal(SIGCHLD, sig_handler); /* reset it to this function */

View File

@@ -149,6 +149,7 @@ void listenerOnPingMessage (noPollCtx * ctx, noPollConn * conn, noPollMsg * msg,
if (nopoll_msg_opcode(msg) == NOPOLL_PING_FRAME) if (nopoll_msg_opcode(msg) == NOPOLL_PING_FRAME)
{ {
reset_heartBeatTimer(); reset_heartBeatTimer();
set_pingTimeStamp();
} }
} }
} }

View File

@@ -26,6 +26,7 @@
#include "nopoll_helpers.h" #include "nopoll_helpers.h"
#include "nopoll_handlers.h" #include "nopoll_handlers.h"
#include "time.h" #include "time.h"
#include "config.h"
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Macros */ /* Macros */
@@ -49,60 +50,36 @@ void setMessageHandlers()
nopoll_conn_set_on_close(get_global_conn(), (noPollOnCloseHandler)listenerOnCloseMessage, NULL); nopoll_conn_set_on_close(get_global_conn(), (noPollOnCloseHandler)listenerOnCloseMessage, NULL);
} }
int cloud_status_is_online (void)
{
const char *status = get_cloud_status();
if (NULL == status)
return false;
return (strcmp (status, CLOUD_STATUS_ONLINE) == 0);
}
/** To send upstream msgs to server ***/ /** To send upstream msgs to server ***/
void sendMessage(noPollConn *conn, void *msg, size_t len) int sendMessage(noPollConn *conn, void *msg, size_t len)
{ {
int bytesWritten = 0; int bytesWritten = 0;
static int connErr=0;
long timeDiff = 0; if (!cloud_status_is_online ()) {
ParodusError("Failed to send msg upstream as connection is not OK\n");
OnboardLog("Failed to send msg upstream as connection is not OK\n");
return 1;
}
ParodusInfo("sendMessage length %zu\n", len); ParodusInfo("sendMessage length %zu\n", len);
if(nopoll_conn_is_ok(conn) && nopoll_conn_is_ready(conn)) bytesWritten = sendResponse(conn, msg, len);
ParodusPrint("Number of bytes written: %d\n", bytesWritten);
if (bytesWritten != (int) len)
{ {
//bytesWritten = nopoll_conn_send_binary(conn, msg, len); ParodusError("Failed to send bytes %zu, bytes written were=%d (errno=%d, %s)..\n", len, bytesWritten, errno, strerror(errno));
bytesWritten = sendResponse(conn, msg, len); return 1;
ParodusPrint("Number of bytes written: %d\n", bytesWritten);
if (bytesWritten != (int) len)
{
ParodusError("Failed to send bytes %zu, bytes written were=%d (errno=%d, %s)..\n", len, bytesWritten, errno, strerror(errno));
}
connErr = 0;
}
else
{
ParodusError("Failed to send msg upstream as connection is not OK\n");
OnboardLog("Failed to send msg upstream as connection is not OK\n");
if(get_interface_down_event())
{
ParodusError("Unable to connect to server since interface is down\n");
}
else
{
if (connErr == 0)
{
getCurrentTime(connStuck_startPtr);
ParodusInfo("Conn got stuck, initialized the first timer\n");
connErr = 1;
}
else
{
getCurrentTime(connStuck_endPtr);
timeDiff = timeValDiff(connStuck_startPtr, connStuck_endPtr);
ParodusPrint("checking timeout difference:%ld\n", timeDiff);
if( timeDiff >= (10*60*1000))
{
ParodusError("conn got stuck for over 10 minutes; crashing service.\n");
OnboardLog("conn got stuck for over 10 minutes; crashing service.\n");
kill(getpid(),SIGTERM);
}
}
}
} }
return 0;
} }
int sendResponse(noPollConn * conn, void * buffer, size_t length) int sendResponse(noPollConn * conn, void * buffer, size_t length)

View File

@@ -41,7 +41,7 @@ extern "C" {
*/ */
int sendResponse(noPollConn * conn,void *str, size_t bufferSize); int sendResponse(noPollConn * conn,void *str, size_t bufferSize);
void setMessageHandlers(); void setMessageHandlers();
void sendMessage(noPollConn *conn, void *msg, size_t len); int sendMessage(noPollConn *conn, void *msg, size_t len);
/** /**
* @brief __report_log Nopoll log handler * @brief __report_log Nopoll log handler

View File

@@ -114,7 +114,7 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
} }
/* Commandline input partner_ids not matching with partner_ids from request, appending to request partner_ids*/ /* Commandline input partner_ids not matching with partner_ids from request, appending to request partner_ids*/
if(matchFlag != 1) if(matchFlag != 1 && partnerIds !=NULL)
{ {
(*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * (count+partnersList->count))); (*partnerIds) = (partners_t *) malloc(sizeof(partners_t) + (sizeof(char *) * (count+partnersList->count)));
(*partnerIds)->count = count+partnersList->count; (*partnerIds)->count = count+partnersList->count;
@@ -132,6 +132,23 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
i++; i++;
} }
} }
else if (matchFlag != 1 && partnerIds == NULL)
{
ParodusError("partner_id match not found: command line input %s , msg partner_id %s\n", temp, msg->u.event.partner_ids->partner_ids[0]);
if(partnersList != NULL)
{
for(j=0; j<partnersList->count; j++)
{
if(NULL != partnersList->partner_ids[j])
{
free(partnersList->partner_ids[j]);
}
}
free(partnersList);
}
free(partnerId);
return 1;
}
} }
else else
{ {

6
src/privilege.c Normal file
View File

@@ -0,0 +1,6 @@
#include "privilege.h"
void drop_root_privilege()
{
}

2
src/privilege.h Normal file
View File

@@ -0,0 +1,2 @@
/* This is a stub function that will be overridden in a patch */
void drop_root_privilege();

View File

@@ -17,6 +17,7 @@
#include "time.h" #include "time.h"
#include "parodus_log.h" #include "parodus_log.h"
#include <errno.h>
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* External Functions */ /* External Functions */
@@ -24,7 +25,10 @@
void getCurrentTime(struct timespec *timer) void getCurrentTime(struct timespec *timer)
{ {
clock_gettime(CLOCK_REALTIME, timer); if( clock_gettime(CLOCK_REALTIME, timer) == -1 )
{
ParodusError("clock gettime returns errno %d\n", errno );
}
} }
uint64_t getCurrentTimeInMicroSeconds(struct timespec *timer) uint64_t getCurrentTimeInMicroSeconds(struct timespec *timer)

View File

@@ -40,7 +40,7 @@
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
void *metadataPack; void *metadataPack;
size_t metaPackSize=-1; size_t metaPackSize=0;
UpStreamMsg *UpStreamMsgQ = NULL; UpStreamMsg *UpStreamMsgQ = NULL;
@@ -83,7 +83,6 @@ void packMetaData()
//Pack the metadata initially to reuse for every upstream msg sending to server //Pack the metadata initially to reuse for every upstream msg sending to server
ParodusPrint("-------------- Packing metadata ----------------\n"); ParodusPrint("-------------- Packing metadata ----------------\n");
sprintf(boot_time, "%d", get_parodus_cfg()->boot_time); sprintf(boot_time, "%d", get_parodus_cfg()->boot_time);
struct data meta_pack[METADATA_COUNT] = { struct data meta_pack[METADATA_COUNT] = {
{HW_MODELNAME, get_parodus_cfg()->hw_model}, {HW_MODELNAME, get_parodus_cfg()->hw_model},
{HW_SERIALNUMBER, get_parodus_cfg()->hw_serial_number}, {HW_SERIALNUMBER, get_parodus_cfg()->hw_serial_number},
@@ -95,10 +94,9 @@ void packMetaData()
{LAST_RECONNECT_REASON, get_global_reconnect_reason()}, {LAST_RECONNECT_REASON, get_global_reconnect_reason()},
{WEBPA_PROTOCOL, get_parodus_cfg()->webpa_protocol}, {WEBPA_PROTOCOL, get_parodus_cfg()->webpa_protocol},
{WEBPA_UUID,get_parodus_cfg()->webpa_uuid}, {WEBPA_UUID,get_parodus_cfg()->webpa_uuid},
{WEBPA_INTERFACE, get_parodus_cfg()->webpa_interface_used}, {WEBPA_INTERFACE, getWebpaInterface()},
{PARTNER_ID, get_parodus_cfg()->partner_id} {PARTNER_ID, get_parodus_cfg()->partner_id}
}; };
const data_t metapack = {METADATA_COUNT, meta_pack}; const data_t metapack = {METADATA_COUNT, meta_pack};
metaPackSize = wrp_pack_metadata( &metapack , &metadataPack ); metaPackSize = wrp_pack_metadata( &metapack , &metadataPack );
@@ -113,6 +111,11 @@ void packMetaData()
} }
} }
void clear_metadata(){
if(metadataPack != NULL)
free(metadataPack);
}
/* /*
* @brief To handle UpStream messages which is received from nanomsg server socket * @brief To handle UpStream messages which is received from nanomsg server socket
*/ */
@@ -322,7 +325,10 @@ void *processUpstreamMessage()
} }
else if(msgType == WRP_MSG_TYPE__EVENT) else if(msgType == WRP_MSG_TYPE__EVENT)
{ {
ParodusInfo(" Received upstream event data: dest '%s'\n", msg->u.event.dest); (msg->u.event.headers != NULL && msg->u.event.headers->headers[0] != NULL && msg->u.event.headers->headers[1] != NULL) ? ParodusInfo(" Received upstream event data: dest '%s' traceParent: %s traceState: %s\n", msg->u.event.dest, msg->u.event.headers->headers[0], msg->u.event.headers->headers[1]) : ParodusInfo(" Received upstream event data: dest '%s'\n", msg->u.event.dest);
if(msg->u.event.transaction_uuid != NULL) {
ParodusInfo("transaction_uuid in event: %s\n", msg->u.event.transaction_uuid);
}
partners_t *partnersList = NULL; partners_t *partnersList = NULL;
int j = 0; int j = 0;
@@ -330,6 +336,7 @@ void *processUpstreamMessage()
if(ret == 1) if(ret == 1)
{ {
wrp_msg_t *eventMsg = (wrp_msg_t *) malloc(sizeof(wrp_msg_t)); wrp_msg_t *eventMsg = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
memset( eventMsg, 0, sizeof( wrp_msg_t ) );
eventMsg->msg_type = msgType; eventMsg->msg_type = msgType;
eventMsg->u.event.content_type=msg->u.event.content_type; eventMsg->u.event.content_type=msg->u.event.content_type;
eventMsg->u.event.source=msg->u.event.source; eventMsg->u.event.source=msg->u.event.source;
@@ -339,6 +346,15 @@ void *processUpstreamMessage()
eventMsg->u.event.headers=msg->u.event.headers; eventMsg->u.event.headers=msg->u.event.headers;
eventMsg->u.event.metadata=msg->u.event.metadata; eventMsg->u.event.metadata=msg->u.event.metadata;
eventMsg->u.event.partner_ids = partnersList; eventMsg->u.event.partner_ids = partnersList;
if(msg->u.event.transaction_uuid)
{
ParodusPrint("Inside Trans id in PARODUS\n");
}
else
{
ParodusPrint("Assigning NULL to trans id\n");
eventMsg->u.event.transaction_uuid = NULL;
}
int size = wrp_struct_to( eventMsg, WRP_BYTES, &bytes ); int size = wrp_struct_to( eventMsg, WRP_BYTES, &bytes );
if(size > 0) if(size > 0)
@@ -371,7 +387,7 @@ void *processUpstreamMessage()
//Sending to server for msgTypes 3, 5, 6, 7, 8. //Sending to server for msgTypes 3, 5, 6, 7, 8.
if( WRP_MSG_TYPE__REQ == msgType ) if( WRP_MSG_TYPE__REQ == msgType )
{ {
ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s\n", msgType, msg->u.req.dest, msg->u.req.transaction_uuid ); (msg->u.req.headers != NULL && msg->u.req.headers->headers[0] != NULL && msg->u.req.headers->headers[1] != NULL) ? ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s traceParent: %s traceState: %s\n", msgType, msg->u.req.dest, msg->u.req.transaction_uuid, msg->u.req.headers->headers[0], msg->u.req.headers->headers[1]) : ParodusInfo(" Received upstream data with MsgType: %d dest: '%s' transaction_uuid: %s\n", msgType, msg->u.req.dest, msg->u.req.transaction_uuid);
sendUpstreamMsgToServer(&message->msg, message->len); sendUpstreamMsgToServer(&message->msg, message->len);
} }
else else
@@ -417,12 +433,43 @@ void *processUpstreamMessage()
{ {
ParodusError("Failed to get device_id\n"); ParodusError("Failed to get device_id\n");
} }
} else if (WRP_MSG_TYPE__SVC_ALIVE != msgType) { }
else if((WRP_MSG_TYPE__UPDATE == msgType) || (WRP_MSG_TYPE__DELETE == msgType))
{
ParodusPrint("UPDATE/DELETE request\n");
ret = getDeviceId(&device_id, &device_id_len);
if(ret == 0)
{
ParodusPrint("device_id %s device_id_len %lu\n", device_id, device_id_len);
/* Match dest based on device_id. Check dest start with: "mac:112233445xxx" ? */
if( 0 == strncasecmp(device_id, msg->u.crud.dest, device_id_len-1) )
{
/* For this device. For nanomsg clients.*/
getServiceNameAndSendResponse(msg, &message->msg, message->len);
}
else
{
/* Not for this device. Send upstream */
ParodusInfo("sendUpstreamMsgToServer \n");
sendUpstreamMsgToServer(&message->msg, message->len);
}
if(device_id != NULL)
{
free(device_id);
device_id = NULL;
}
}
else
{
ParodusError("Failed to get device_id\n");
}
}
else if (WRP_MSG_TYPE__SVC_ALIVE != msgType) {
/* Don't reply to service alive message */ /* Don't reply to service alive message */
sendUpstreamMsgToServer(&message->msg, message->len); sendUpstreamMsgToServer(&message->msg, message->len);
}
} }
} }
}
} }
else else
{ {
@@ -565,11 +612,12 @@ void getServiceNameAndSendResponse(wrp_msg_t *msg, void **msg_bytes, size_t msg_
} }
} }
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size) int sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
{ {
void *appendData; void *appendData;
size_t encodedSize; size_t encodedSize;
bool close_retry = false; bool close_retry = false;
int sendRetStatus = 1;
//appending response with metadata //appending response with metadata
if(metaPackSize > 0) if(metaPackSize > 0)
{ {
@@ -584,12 +632,13 @@ void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
//TODO: Upstream and downstream messages in queue should be handled and queue should be empty before parodus forcefully disconnect from cloud. //TODO: Upstream and downstream messages in queue should be handled and queue should be empty before parodus forcefully disconnect from cloud.
if(!close_retry || (get_parodus_cfg()->cloud_disconnect !=NULL)) if(!close_retry || (get_parodus_cfg()->cloud_disconnect !=NULL))
{ {
sendMessage(get_global_conn(),appendData, encodedSize); sendRetStatus = sendMessage(get_global_conn(),appendData, encodedSize);
} }
else else
{ {
ParodusInfo("close_retry is %d, unable to send response as connection retry is in progress\n", close_retry); ParodusInfo("close_retry is %d, unable to send response as connection retry is in progress\n", close_retry);
OnboardLog("close_retry is %d, unable to send response as connection retry is in progress\n", close_retry); OnboardLog("close_retry is %d, unable to send response as connection retry is in progress\n", close_retry);
sendRetStatus = 1;
} }
free(appendData); free(appendData);
appendData =NULL; appendData =NULL;
@@ -597,6 +646,9 @@ void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
else else
{ {
ParodusError("Failed to send upstream as metadata packing is not successful\n"); ParodusError("Failed to send upstream as metadata packing is not successful\n");
sendRetStatus = 1;
} }
ParodusPrint("sendRetStatus is %d\n", sendRetStatus);
return sendRetStatus;
} }

View File

@@ -47,14 +47,19 @@ typedef struct UpStreamMsg__
void packMetaData(); void packMetaData();
void *handle_upstream(); void *handle_upstream();
void *processUpstreamMessage(); void *processUpstreamMessage();
void registerRBUSlistener();
int getDeviceId(char **device_id, size_t *device_id_len); int getDeviceId(char **device_id, size_t *device_id_len);
void sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size); int sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size);
void getServiceNameAndSendResponse(wrp_msg_t *msg, void **msg_bytes, size_t msg_size); void getServiceNameAndSendResponse(wrp_msg_t *msg, void **msg_bytes, size_t msg_size);
void createUpstreamRetrieveMsg(wrp_msg_t *message, wrp_msg_t **retrieve_msg); void createUpstreamRetrieveMsg(wrp_msg_t *message, wrp_msg_t **retrieve_msg);
void set_global_UpStreamMsgQ(UpStreamMsg * UpStreamQ); void set_global_UpStreamMsgQ(UpStreamMsg * UpStreamQ);
#ifdef WAN_FAILOVER_SUPPORTED
int subscribeCurrentActiveInterfaceEvent();
#endif
UpStreamMsg * get_global_UpStreamMsgQ(void); UpStreamMsg * get_global_UpStreamMsgQ(void);
pthread_cond_t *get_global_nano_con(void); pthread_cond_t *get_global_nano_con(void);
pthread_mutex_t *get_global_nano_mut(void); pthread_mutex_t *get_global_nano_mut(void);
void clear_metadata();
#ifdef __cplusplus #ifdef __cplusplus
} }

243
src/upstream_rbus.c Normal file
View File

@@ -0,0 +1,243 @@
/**
* Copyright 2021 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* @file upstream_rbus.c
*
* @description This is used for parodus-RBUS communication
* to send notification events upstream to cloud.
*
*/
#include <stdlib.h>
#include <rbus.h>
#include "upstream.h"
#include "ParodusInternal.h"
#include "partners_check.h"
#include "close_retry.h"
#include "connection.h"
#include "heartBeat.h"
#define WEBCFG_UPSTREAM_EVENT "Webconfig.Upstream"
#ifdef WAN_FAILOVER_SUPPORTED
#define WEBPA_INTERFACE "Device.X_RDK_WanManager.CurrentActiveInterface"
#endif
rbusHandle_t rbus_Handle;
rbusError_t err;
void processWebconfigUpstreamEvent(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription);
void subscribeAsyncHandler( rbusHandle_t handle, rbusEventSubscription_t* subscription, rbusError_t error);
rbusHandle_t get_parodus_rbus_Handle(void)
{
return rbus_Handle;
}
/* Enables rbus ERROR level logs in parodus. Modify RBUS_LOG_ERROR check if more debug logs are needed from rbus. */
void rbus_log_handler(
rbusLogLevel level,
const char* file,
int line,
int threadId,
char* message)
{
ParodusPrint("threadId %d\n", threadId);
const char* slevel = "";
if(level < RBUS_LOG_ERROR)
return;
switch(level)
{
case RBUS_LOG_DEBUG: slevel = "DEBUG"; break;
case RBUS_LOG_INFO: slevel = "INFO"; break;
case RBUS_LOG_WARN: slevel = "WARN"; break;
case RBUS_LOG_ERROR: slevel = "ERROR"; break;
case RBUS_LOG_FATAL: slevel = "FATAL"; break;
}
ParodusInfo("%5s %s:%d -- %s\n", slevel, file, line, message);
}
void registerRbusLogger()
{
rbus_registerLogHandler(rbus_log_handler);
ParodusPrint("Registered rbus log handler\n");
}
#ifdef WAN_FAILOVER_SUPPORTED
void eventReceiveHandler( rbusHandle_t rbus_Handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription );
#endif
/* API to register RBUS listener to receive messages from webconfig */
void subscribeRBUSevent()
{
int rc = RBUS_ERROR_SUCCESS;
err = rbus_open(&rbus_Handle, "parodus");
if (err)
{
ParodusError("rbus_open failed :%s\n", rbusError_ToString(err));
return;
}
rc = rbusEvent_SubscribeAsync(rbus_Handle,WEBCFG_UPSTREAM_EVENT,processWebconfigUpstreamEvent,subscribeAsyncHandler,"parodus",10*60);
if(rc != RBUS_ERROR_SUCCESS)
ParodusError("rbusEvent_Subscribe failed: %d, %s\n", rc, rbusError_ToString(rc));
else
ParodusInfo("rbusEvent_Subscribe was successful\n");
}
#ifdef WAN_FAILOVER_SUPPORTED
/* API to subscribe Active Interface name on value change event*/
int subscribeCurrentActiveInterfaceEvent()
{
int rc = RBUS_ERROR_SUCCESS;
ParodusInfo("Subscribing to Device.X_RDK_WanManager.CurrentActiveInterface Event\n");
rc = rbusEvent_SubscribeAsync(rbus_Handle,WEBPA_INTERFACE,eventReceiveHandler,subscribeAsyncHandler,"parodusInterface",10*20);
if(rc != RBUS_ERROR_SUCCESS)
{
ParodusError("%s subscribe failed : %d - %s\n", WEBPA_INTERFACE, rc, rbusError_ToString(rc));
}
return rc;
}
#endif
void processWebconfigUpstreamEvent(rbusHandle_t handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription)
{
(void)handle;
(void)subscription;
int rv=-1;
wrp_msg_t *event_msg;
void *bytes;
const uint8_t* bytesVal = NULL;
int len;
rbusValue_t value = NULL;
value = rbusObject_GetValue(event->data, "value");
bytesVal = rbusValue_GetBytes(value, &len);
bytes = (void*) bytesVal;
rv = wrp_to_struct( bytes, len, WRP_BYTES, &event_msg );
if(rv > 0)
{
ParodusInfo(" Received upstream event data: dest '%s'\n", event_msg->u.event.dest);
partners_t *partnersList = NULL;
int j = 0;
int ret = validate_partner_id(event_msg, &partnersList);
if(ret == 1)
{
wrp_msg_t *eventMsg = (wrp_msg_t *) malloc(sizeof(wrp_msg_t));
memset( eventMsg, 0, sizeof( wrp_msg_t ) );
eventMsg->msg_type = event_msg->msg_type;
eventMsg->u.event.content_type=event_msg->u.event.content_type;
eventMsg->u.event.source=event_msg->u.event.source;
eventMsg->u.event.dest=event_msg->u.event.dest;
eventMsg->u.event.payload=event_msg->u.event.payload;
eventMsg->u.event.payload_size=event_msg->u.event.payload_size;
eventMsg->u.event.headers=event_msg->u.event.headers;
eventMsg->u.event.metadata=event_msg->u.event.metadata;
eventMsg->u.event.partner_ids = partnersList;
if(event_msg->u.event.transaction_uuid)
{
ParodusPrint("Inside Trans id in PARODUS_rbus\n");
}
else
{
ParodusPrint("Assigning NULL to trans id RBUS\n");
eventMsg->u.event.transaction_uuid = NULL;
}
int size = wrp_struct_to( eventMsg, WRP_BYTES, &bytes );
if(size > 0)
{
sendUpstreamMsgToServer(&bytes, size);
}
free(eventMsg);
free(bytes);
bytes = NULL;
}
else
{
sendUpstreamMsgToServer((void **)(&bytes), len);
}
if(partnersList != NULL)
{
for(j=0; j<(int)partnersList->count; j++)
{
if(NULL != partnersList->partner_ids[j])
{
free(partnersList->partner_ids[j]);
}
}
free(partnersList);
}
partnersList = NULL;
}
}
void subscribeAsyncHandler( rbusHandle_t handle, rbusEventSubscription_t* subscription, rbusError_t error)
{
(void)handle;
ParodusInfo("subscribeAsyncHandler event %s, error %d - %s\n",subscription->eventName, error, rbusError_ToString(error));
}
#ifdef WAN_FAILOVER_SUPPORTED
void eventReceiveHandler( rbusHandle_t rbus_Handle, rbusEvent_t const* event, rbusEventSubscription_t* subscription )
{
(void)subscription;
ParodusPrint("Handling event inside eventReceiveHandler\n");
(void)rbus_Handle;
char * interface = NULL;
rbusValue_t newValue = rbusObject_GetValue(event->data, "value");
rbusValue_t oldValue = rbusObject_GetValue(event->data, "oldValue");
ParodusInfo("Consumer received ValueChange event for param %s\n", event->name);
if(newValue) {
interface = (char *) rbusValue_GetString(newValue, NULL);
setWebpaInterface(interface);
}
else {
ParodusError("newValue is NULL\n");
}
if(newValue !=NULL && oldValue!=NULL && interface!=NULL) {
ParodusInfo("New Value: %s Old Value: %s New Interface Value: %s\n", rbusValue_GetString(newValue, NULL), rbusValue_GetString(oldValue, NULL), interface);
// If interface is already down then reset it and reconnect cloud conn as wan failover event is received
if(get_interface_down_event())
{
reset_interface_down_event();
ParodusInfo("Interface_down_event is reset\n");
resume_heartBeatTimer();
}
// Close cloud conn and reconnect with the new interface as wan failover event is received
set_global_reconnect_reason("WAN_FAILOVER");
set_global_reconnect_status(true);
set_close_retry();
}
else {
if(oldValue == NULL) {
ParodusError("oldValue is NULL\n");
}
if(interface == NULL) {
ParodusError("interface is NULL\n");
}
}
}
#endif

1771
src/xmidtsend_rbus.c Normal file

File diff suppressed because it is too large Load Diff

127
src/xmidtsend_rbus.h Normal file
View File

@@ -0,0 +1,127 @@
/**
* Copyright 2022 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* @file xmidtsend_rbus.h
*
* @description This header defines functions required to manage xmidt send messages via rbus.
*
*/
#ifndef _XMIDTSEND_RBUS_H_
#define _XMIDTSEND_RBUS_H_
#include <rbus.h>
#include "config.h"
#include <uuid/uuid.h>
#ifdef __cplusplus
extern "C" {
#endif
#define XMIDT_SEND_METHOD "Device.X_RDK_Xmidt.SendData"
#define INPARAMS_PATH "/tmp/inparams.txt"
#define CLOUD_ACK_TIMEOUT_SEC 7
#define CRITICAL_QOS_EXPIRE_TIME 30*60
#define HIGH_QOS_EXPIRE_TIME 25*60
#define MEDIUM_QOS_EXPIRE_TIME 20*60
#define LOW_QOS_EXPIRE_TIME 15*60
#define EXPIRY_CHECK_TIME 5*60 //To check expiry in every 5 mins when cloud connection is down.
/*----------------------------------------------------------------------------*/
/* Data Structures */
/*----------------------------------------------------------------------------*/
typedef struct XmidtMsg__
{
wrp_msg_t *msg;
rbusMethodAsyncHandle_t asyncHandle;
int state;
long long enqueueTime;
long long sentTime;
struct XmidtMsg__ *next;
} XmidtMsg;
typedef struct CloudAck__
{
char *transaction_id;
int qos;
int rdr;
char *source;
struct CloudAck__ *next;
} CloudAck;
typedef enum
{
DELIVERED_SUCCESS = 0,
INVALID_MSG_TYPE,
MISSING_SOURCE,
MISSING_DEST,
MISSING_CONTENT_TYPE,
MISSING_PAYLOAD,
MISSING_PAYLOADLEN,
INVALID_CONTENT_TYPE,
ENQUEUE_FAILURE = 100,
CLIENT_DISCONNECT = 101,
QUEUE_SIZE_EXCEEDED = 102,
WRP_ENCODE_FAILURE = 103,
MSG_PROCESSING_FAILED = 104,
QOS_SEMANTICS_DISABLED = 105,
MSG_EXPIRED = 106,
QUEUE_OPTIMIZED = 107
} XMIDT_STATUS;
typedef enum
{
PENDING = 0,
SENT,
DELETE
} MSG_STATUS;
/*----------------------------------------------------------------------------*/
/* Function Prototypes */
/*----------------------------------------------------------------------------*/
rbusHandle_t get_parodus_rbus_Handle(void);
void addToXmidtUpstreamQ(wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle);
void* processXmidtUpstreamMsg();
void processXmidtData();
int processData(XmidtMsg *Datanode, wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle);
int sendXmidtEventToServer(XmidtMsg *msgnode, wrp_msg_t * msg, rbusMethodAsyncHandle_t asyncHandle);
int checkInputParameters(rbusObject_t inParams);
char* generate_transaction_uuid();
void parseRbusInparamsToWrp(rbusObject_t inParams, char *trans_id, wrp_msg_t **eventMsg);
void createOutParamsandSendAck(wrp_msg_t *msg, rbusMethodAsyncHandle_t asyncHandle, char *errorMsg, int statuscode, char *cloudsource, rbusError_t error);
int validateXmidtData(wrp_msg_t * eventMsg, char **errorMsg, int *statusCode);
void printSendMsgData(char* status, int qos, char* dest, char* transaction_uuid);
bool highQosValueCheck(int qos);
void waitTillConnectionIsUp();
void printRBUSParams(rbusObject_t params, char* file_path);
void addToCloudAckQ(char *transaction_id, int qos, int rdr, char *source);
int checkCloudACK(XmidtMsg *xmdnode, rbusMethodAsyncHandle_t asyncHandle);
int updateXmidtState(XmidtMsg * temp, int state);
void print_xmidMsg_list();
int deleteCloudACKNode(char* trans_id);
int deleteFromXmidtQ(XmidtMsg **next_node);
int checkCloudConn();
void checkMaxQandOptimize(XmidtMsg *xmdMsg);
void checkMsgExpiry(XmidtMsg *xmdMsg);
void mapXmidtStatusToStatusMessage(int status, char **message);
int xmidtQOptmize();
#ifdef __cplusplus
}
#endif
#endif /* _XMIDTSEND_RBUS_H_ */

View File

@@ -16,7 +16,9 @@ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST ") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST ")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -g -fprofile-arcs -ftest-coverage -O0")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -O0") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -O0")
set (PARODUS_COMMON_SRC ../src/string_helpers.c ../src/mutex.c ../src/time.c ../src/config.c ../src/spin_thread.c ../src/token.c) set (PARODUS_COMMON_SRC ../src/string_helpers.c ../src/mutex.c
../src/time.c ../src/config.c ../src/spin_thread.c
../src/event_handler.c ../src/token.c)
set (PARODUS_COMMON_LIBS gcov -lcunit -lcimplog -lwrp-c set (PARODUS_COMMON_LIBS gcov -lcunit -lcimplog -lwrp-c
-luuid -lmsgpackc -lnopoll -lnanomsg -lpthread -luuid -lmsgpackc -lnopoll -lnanomsg -lpthread
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64 -Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
@@ -30,6 +32,10 @@ if (FEATURE_DNS_QUERY)
set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lucresolv -lresolv) set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lucresolv -lresolv)
endif (FEATURE_DNS_QUERY) endif (FEATURE_DNS_QUERY)
if (ENABLE_WEBCFGBIN)
set (PARODUS_COMMON_LIBS ${PARODUS_COMMON_LIBS} -lrbus)
endif (ENABLE_WEBCFGBIN)
if(NOT DISABLE_VALGRIND) if(NOT DISABLE_VALGRIND)
set (MEMORY_CHECK valgrind --leak-check=full --show-reachable=yes -v) set (MEMORY_CHECK valgrind --leak-check=full --show-reachable=yes -v)
endif () endif ()
@@ -40,7 +46,7 @@ link_directories ( ${LIBRARY_DIR} )
# test_heartBeatTimer # test_heartBeatTimer
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_heartBeatTimer COMMAND ${MEMORY_CHECK} ./test_heartBeatTimer) add_test(NAME test_heartBeatTimer COMMAND ${MEMORY_CHECK} ./test_heartBeatTimer)
add_executable(test_heartBeatTimer test_heartBeatTimer.c ../src/heartBeat.c) add_executable(test_heartBeatTimer test_heartBeatTimer.c ../src/heartBeat.c ../src/time.c)
target_link_libraries (test_heartBeatTimer ${PARODUS_COMMON_LIBS} -lcmocka) target_link_libraries (test_heartBeatTimer ${PARODUS_COMMON_LIBS} -lcmocka)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -55,7 +61,10 @@ target_link_libraries (test_close_retry ${PARODUS_COMMON_LIBS} -lcmocka)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_mutex COMMAND ${MEMORY_CHECK} ./test_mutex) add_test(NAME test_mutex COMMAND ${MEMORY_CHECK} ./test_mutex)
add_executable(test_mutex test_mutex.c ../src/mutex.c) add_executable(test_mutex test_mutex.c ../src/mutex.c)
target_link_libraries (test_mutex ${PARODUS_COMMON_LIBS} -lcmocka) target_link_libraries (test_mutex gcov -lcunit -lcimplog -lwrp-c
-luuid -lmsgpackc -lnopoll -lnanomsg -lpthread
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
-lssl -lcrypto -lrt -lm -lcmocka)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# test_networking # test_networking
@@ -68,8 +77,8 @@ target_link_libraries (test_networking ${PARODUS_COMMON_LIBS})
# test_nopoll_helpers # test_nopoll_helpers
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_nopoll_helpers COMMAND ${MEMORY_CHECK} ./test_nopoll_helpers) add_test(NAME test_nopoll_helpers COMMAND ${MEMORY_CHECK} ./test_nopoll_helpers)
add_executable(test_nopoll_helpers test_nopoll_helpers.c ../src/nopoll_helpers.c) add_executable(test_nopoll_helpers test_nopoll_helpers.c ../src/nopoll_helpers.c ../src/string_helpers.c ../src/config.c)
target_link_libraries (test_nopoll_helpers -Wl,--no-as-needed -lrt -lcmocka -lcimplog -lnopoll) target_link_libraries (test_nopoll_helpers -Wl,--no-as-needed -lrt -lcmocka -lcimplog -lnopoll ${PARODUS_COMMON_LIBS})
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# test_time # test_time
@@ -88,22 +97,22 @@ target_link_libraries (test_spin_thread_e ${PARODUS_COMMON_LIBS} )
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# test_spin_thread success # test_spin_thread success
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_spin_thread_s COMMAND ${MEMORY_CHECK} ./test_spin_thread_s) # add_test(NAME test_spin_thread_s COMMAND ${MEMORY_CHECK} ./test_spin_thread_s)
add_executable(test_spin_thread_s test_spin_thread_s.c ../src/spin_thread.c) # add_executable(test_spin_thread_s test_spin_thread_s.c ../src/spin_thread.c)
target_link_libraries (test_spin_thread_s ${PARODUS_COMMON_LIBS} ) # target_link_libraries (test_spin_thread_s ${PARODUS_COMMON_LIBS} )
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# test_string_helpers # test_string_helpers
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_string_helpers COMMAND ${MEMORY_CHECK} ./test_string_helpers) # add_test(NAME test_string_helpers COMMAND ${MEMORY_CHECK} ./test_string_helpers)
add_executable(test_string_helpers test_string_helpers.c ../src/string_helpers.c) # add_executable(test_string_helpers test_string_helpers.c ../src/string_helpers.c)
target_link_libraries (test_string_helpers ${PARODUS_COMMON_LIBS} ) # target_link_libraries (test_string_helpers ${PARODUS_COMMON_LIBS} )
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# test_nopoll_handlers # test_nopoll_handlers
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_nopoll_handlers COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers) add_test(NAME test_nopoll_handlers COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers)
add_executable(test_nopoll_handlers test_nopoll_handlers.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c) add_executable(test_nopoll_handlers test_nopoll_handlers.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c ../src/time.c)
target_link_libraries (test_nopoll_handlers -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm) target_link_libraries (test_nopoll_handlers -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm)
@@ -111,7 +120,7 @@ target_link_libraries (test_nopoll_handlers -lnopoll -lcunit -lcimplog -Wl,--no-
# test_nopoll_handlers_fragment # test_nopoll_handlers_fragment
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_nopoll_handlers_fragment COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers_fragment) add_test(NAME test_nopoll_handlers_fragment COMMAND ${MEMORY_CHECK} ./test_nopoll_handlers_fragment)
add_executable(test_nopoll_handlers_fragment test_nopoll_handlers_fragment.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c) add_executable(test_nopoll_handlers_fragment test_nopoll_handlers_fragment.c ../src/nopoll_handlers.c ../src/heartBeat.c ../src/close_retry.c ../src/time.c)
target_link_libraries (test_nopoll_handlers_fragment -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm -lcmocka) target_link_libraries (test_nopoll_handlers_fragment -lnopoll -lcunit -lcimplog -Wl,--no-as-needed -lrt -lpthread -lm -lcmocka)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -153,6 +162,10 @@ else()
set(CLIST_SRC ${CLIST_SRC} ../src/seshat_interface_stub.c) set(CLIST_SRC ${CLIST_SRC} ../src/seshat_interface_stub.c)
endif (ENABLE_SESHAT) endif (ENABLE_SESHAT)
if (ENABLE_WEBCFGBIN)
set(CLIST_SRC ${CLIST_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
endif (ENABLE_WEBCFGBIN)
add_executable(test_client_list ${CLIST_SRC}) add_executable(test_client_list ${CLIST_SRC})
#target_link_libraries (test_client_list ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS}) #target_link_libraries (test_client_list ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS} -lcurl -luuid) target_link_libraries (test_client_list ${PARODUS_COMMON_LIBS} -lcurl -luuid)
@@ -170,6 +183,10 @@ else()
set(SVA_SRC ${SVA_SRC} ../src/seshat_interface_stub.c) set(SVA_SRC ${SVA_SRC} ../src/seshat_interface_stub.c)
endif (ENABLE_SESHAT) endif (ENABLE_SESHAT)
if (ENABLE_WEBCFGBIN)
set(SVA_SRC ${SVA_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
endif (ENABLE_WEBCFGBIN)
add_executable(test_service_alive ${SVA_SRC}) add_executable(test_service_alive ${SVA_SRC})
#target_link_libraries (test_service_alive ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS}) #target_link_libraries (test_service_alive ${PARODUS_CONN_LIBS} ${PARODUS_COMMON_LIBS})
target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS} -lcurl -luuid) target_link_libraries (test_service_alive ${PARODUS_COMMON_LIBS} -lcurl -luuid)
@@ -198,7 +215,7 @@ target_link_libraries (test_auth_token -lcmocka
# test_auth_token_more # test_auth_token_more
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_auth_token_more COMMAND ${MEMORY_CHECK} ./test_auth_token_more) add_test(NAME test_auth_token_more COMMAND ${MEMORY_CHECK} ./test_auth_token_more)
add_executable(test_auth_token_more test_auth_token_more.c ../src/config.c ../src/auth_token.c ../src/string_helpers.c) add_executable(test_auth_token_more test_auth_token_more.c ../src/config.c ../src/auth_token.c ../src/string_helpers.c ../src/config.c)
target_link_libraries (test_auth_token_more -lcmocka target_link_libraries (test_auth_token_more -lcmocka
-Wl,--no-as-needed -lcimplog -Wl,--no-as-needed -lcimplog
-lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm -lcurl -luuid -lcjson -lcjwt -ltrower-base64 -lssl -lcrypto -lrt -lm -lcurl -luuid
@@ -222,7 +239,8 @@ target_link_libraries (test_crud_tasks -lcmocka ${PARODUS_COMMON_LIBS} )
# test_crud_internal # test_crud_internal
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_crud_internal COMMAND ${MEMORY_CHECK} ./test_crud_internal) add_test(NAME test_crud_internal COMMAND ${MEMORY_CHECK} ./test_crud_internal)
add_executable(test_crud_internal test_crud_internal.c ../src/config.c ../src/close_retry.c ../src/string_helpers.c ../src/crud_internal.c ) add_executable(test_crud_internal test_crud_internal.c ../src/config.c ../src/close_retry.c
../src/ParodusInternal.c ../src/string_helpers.c ../src/crud_internal.c ../src/client_list.c)
target_link_libraries (test_crud_internal -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid) target_link_libraries (test_crud_internal -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -233,7 +251,7 @@ add_executable(test_upstream test_upstream.c ../src/upstream.c ../src/close_retr
target_link_libraries (test_upstream -lcmocka gcov -lcunit -lcimplog target_link_libraries (test_upstream -lcmocka gcov -lcunit -lcimplog
-lwrp-c -luuid -lpthread -lmsgpackc -lnopoll -lwrp-c -luuid -lpthread -lmsgpackc -lnopoll
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64 -Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
-lssl -lcrypto -lrt -lm) -lssl -lcrypto -lrt -lm -lnanomsg)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# test_upstream_sock # test_upstream_sock
@@ -250,7 +268,7 @@ target_link_libraries (test_upstream_sock -lcmocka gcov -lcunit -lcimplog
# test_downstream # test_downstream
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_downstream COMMAND ${MEMORY_CHECK} ./test_downstream) add_test(NAME test_downstream COMMAND ${MEMORY_CHECK} ./test_downstream)
add_executable(test_downstream test_downstream.c ../src/downstream.c ../src/string_helpers.c) add_executable(test_downstream test_downstream.c ../src/downstream.c ../src/string_helpers.c ../src/config.c)
target_link_libraries (test_downstream -lcmocka gcov -lcunit -lcimplog target_link_libraries (test_downstream -lcmocka gcov -lcunit -lcimplog
-lwrp-c -luuid -lpthread -lmsgpackc -lnopoll -lwrp-c -luuid -lpthread -lmsgpackc -lnopoll
-Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64 -Wl,--no-as-needed -lcjson -lcjwt -ltrower-base64
@@ -260,7 +278,7 @@ target_link_libraries (test_downstream -lcmocka gcov -lcunit -lcimplog
# test_downstream_more # test_downstream_more
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
add_test(NAME test_downstream_more COMMAND ${MEMORY_CHECK} ./test_downstream_more) add_test(NAME test_downstream_more COMMAND ${MEMORY_CHECK} ./test_downstream_more)
add_executable(test_downstream_more test_downstream_more.c ../src/downstream.c ../src/string_helpers.c) add_executable(test_downstream_more test_downstream_more.c ../src/downstream.c ../src/string_helpers.c ../src/config.c)
target_link_libraries (test_downstream_more -lcmocka ${PARODUS_COMMON_LIBS} ) target_link_libraries (test_downstream_more -lcmocka ${PARODUS_COMMON_LIBS} )
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@@ -281,14 +299,20 @@ set(CONIFC_SRC test_conn_interface.c
../src/token.c ../src/token.c
../src/string_helpers.c ../src/string_helpers.c
../src/mutex.c ../src/mutex.c
../src/time.c
../src/heartBeat.c ../src/heartBeat.c
../src/close_retry.c ../src/close_retry.c
../src/event_handler.c
../src/client_list.c
) )
if (ENABLE_SESHAT) if (ENABLE_SESHAT)
set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface.c) set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface.c)
else() else()
set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface_stub.c) set(CONIFC_SRC ${CONIFC_SRC} ../src/seshat_interface_stub.c)
endif (ENABLE_SESHAT) endif (ENABLE_SESHAT)
if (ENABLE_WEBCFGBIN)
set(CONIFC_SRC ${CONIFC_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
endif (ENABLE_WEBCFGBIN)
add_executable(test_conn_interface ${CONIFC_SRC}) add_executable(test_conn_interface ${CONIFC_SRC})
target_link_libraries (test_conn_interface -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid ) target_link_libraries (test_conn_interface -lcmocka ${PARODUS_COMMON_LIBS} -lcurl -luuid )
@@ -320,7 +344,7 @@ set(TOKEN_SRC ../src/conn_interface.c ../src/config.c
../src/thread_tasks.c ../src/time.c ../src/thread_tasks.c ../src/time.c
../src/string_helpers.c ../src/mutex.c ../src/string_helpers.c ../src/mutex.c
../src/token.c ../src/heartBeat.c ../src/token.c ../src/heartBeat.c
../src/close_retry.c ../src/close_retry.c ../src/event_handler.c
) )
if (ENABLE_SESHAT) if (ENABLE_SESHAT)
@@ -335,6 +359,10 @@ else()
set(TOKEN_SRC test_token_stub.c ${TOKEN_SRC}) set(TOKEN_SRC test_token_stub.c ${TOKEN_SRC})
endif (FEATURE_DNS_QUERY) endif (FEATURE_DNS_QUERY)
if (ENABLE_WEBCFGBIN)
set(TOKEN_SRC ${TOKEN_SRC} ../src/upstream_rbus.c ../src/xmidtsend_rbus.c)
endif (ENABLE_WEBCFGBIN)
add_executable(test_token ${TOKEN_SRC} ) add_executable(test_token ${TOKEN_SRC} )
#target_link_libraries (test_token ${PARODUS_COMMON_LIBS} ${PARODUS_JWT_LIBS} -lcmocka ) #target_link_libraries (test_token ${PARODUS_COMMON_LIBS} ${PARODUS_JWT_LIBS} -lcmocka )
target_link_libraries (test_token ${PARODUS_COMMON_LIBS} -lcmocka -lcurl -luuid) target_link_libraries (test_token ${PARODUS_COMMON_LIBS} -lcmocka -lcurl -luuid)

104
tests/mock_event_handler.c Normal file
View File

@@ -0,0 +1,104 @@
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2016 RDK Management
* Copyright [2014] [Cisco Systems, Inc.]
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* This is a test version of event_handler.c that can be used
* to simulate interface down, interface up event
* You overwrite event_handler.c in the src diectory with this
* version. It will generate interface down / interface up events
* at random intervals between 60 secs and 124 secs
*/
#include "parodus_log.h"
#include "event_handler.h"
#include "connection.h"
#include "config.h"
#include "heartBeat.h"
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include "time.h"
#include "close_retry.h"
extern bool g_shutdown;
static pthread_t sysevent_tid;
static void start_interface_down (void)
{
set_interface_down_event();
ParodusInfo("Interface_down_event is set\n");
pause_heartBeatTimer();
}
static void end_interface_down (void)
{
reset_interface_down_event();
ParodusInfo("Interface_down_event is reset\n");
resume_heartBeatTimer();
set_close_retry();
}
// waits from 60 to 124 secs
int wait_random (const char *msg)
{
#define HALF_SEC 500000l
long delay = (random() >> 5) + 60000000l;
long secs, usecs;
struct timeval timeout;
secs = delay / 1000000;
usecs = delay % 1000000;
ParodusInfo ("Waiting %ld secs %ld usecs for %s\n", secs, usecs, msg);
while (!g_shutdown) {
timeout.tv_sec = 0;
if (delay <= HALF_SEC) {
timeout.tv_usec = delay;
select (0, NULL, NULL, NULL, &timeout);
return 0;
}
timeout.tv_usec = HALF_SEC;
delay -= HALF_SEC;
select (0, NULL, NULL, NULL, &timeout);
}
return -1;
}
static void *parodus_sysevent_handler (void *data)
{
while (!g_shutdown) {
if (wait_random ("interface down") != 0)
break;
start_interface_down ();
wait_random ("interface up");
end_interface_down ();
}
ParodusInfo ("Exiting event handler\n");
return data;
}
void EventHandler()
{
ParodusInfo ("RAND_MAX is %ld (0x%lx)\n", RAND_MAX, RAND_MAX);
srandom (getpid());
pthread_create(&sysevent_tid, NULL, parodus_sysevent_handler, NULL);
}

View File

@@ -92,7 +92,7 @@ void test_set_parodus_cfg()
CU_ASSERT_STRING_EQUAL(cfg.hw_last_reboot_reason,get_parodus_cfg()->hw_last_reboot_reason); CU_ASSERT_STRING_EQUAL(cfg.hw_last_reboot_reason,get_parodus_cfg()->hw_last_reboot_reason);
CU_ASSERT_STRING_EQUAL(cfg.fw_name,get_parodus_cfg()->fw_name); CU_ASSERT_STRING_EQUAL(cfg.fw_name,get_parodus_cfg()->fw_name);
CU_ASSERT_STRING_EQUAL(cfg.webpa_url, get_parodus_cfg()->webpa_url); CU_ASSERT_STRING_EQUAL(cfg.webpa_url, get_parodus_cfg()->webpa_url);
CU_ASSERT_STRING_EQUAL(cfg.webpa_interface_used , get_parodus_cfg()->webpa_interface_used); CU_ASSERT_STRING_EQUAL(cfg.webpa_interface_used , getWebpaInterface());
CU_ASSERT_STRING_EQUAL(cfg.webpa_protocol, get_parodus_cfg()->webpa_protocol); CU_ASSERT_STRING_EQUAL(cfg.webpa_protocol, get_parodus_cfg()->webpa_protocol);
CU_ASSERT_EQUAL(cfg.boot_time, get_parodus_cfg()->boot_time); CU_ASSERT_EQUAL(cfg.boot_time, get_parodus_cfg()->boot_time);
CU_ASSERT_EQUAL(cfg.webpa_ping_timeout, get_parodus_cfg()->webpa_ping_timeout); CU_ASSERT_EQUAL(cfg.webpa_ping_timeout, get_parodus_cfg()->webpa_ping_timeout);
@@ -113,7 +113,7 @@ void test_getWebpaConveyHeader()
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->hw_manufacturer, cJSON_GetObjectItem(payload, HW_MANUFACTURER)->valuestring); CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->hw_manufacturer, cJSON_GetObjectItem(payload, HW_MANUFACTURER)->valuestring);
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->hw_last_reboot_reason, cJSON_GetObjectItem(payload, HW_LAST_REBOOT_REASON)->valuestring); CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->hw_last_reboot_reason, cJSON_GetObjectItem(payload, HW_LAST_REBOOT_REASON)->valuestring);
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->fw_name, cJSON_GetObjectItem(payload, FIRMWARE_NAME)->valuestring); CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->fw_name, cJSON_GetObjectItem(payload, FIRMWARE_NAME)->valuestring);
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->webpa_interface_used, cJSON_GetObjectItem(payload, WEBPA_INTERFACE)->valuestring); CU_ASSERT_STRING_EQUAL(getWebpaInterface(), cJSON_GetObjectItem(payload, WEBPA_INTERFACE)->valuestring);
CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->webpa_protocol, cJSON_GetObjectItem(payload, WEBPA_PROTOCOL)->valuestring); CU_ASSERT_STRING_EQUAL(get_parodus_cfg()->webpa_protocol, cJSON_GetObjectItem(payload, WEBPA_PROTOCOL)->valuestring);
CU_ASSERT_EQUAL((int)get_parodus_cfg()->boot_time, cJSON_GetObjectItem(payload, BOOT_TIME)->valueint); CU_ASSERT_EQUAL((int)get_parodus_cfg()->boot_time, cJSON_GetObjectItem(payload, BOOT_TIME)->valueint);

View File

@@ -55,14 +55,31 @@ int curl_easy_perform(CURL *curl)
return rtn; return rtn;
} }
extern int g_response_code;
void setGlobalResponseCode (int response_code)
{
g_response_code = response_code;
}
int curl_easy_getinfo(CURL *curl, CURLINFO CURLINFO_RESPONSE_CODE, long response_code) int curl_easy_getinfo(CURL *curl, CURLINFO CURLINFO_RESPONSE_CODE, long response_code)
{ {
UNUSED(curl); UNUSED(curl);
UNUSED(CURLINFO_RESPONSE_CODE); UNUSED(CURLINFO_RESPONSE_CODE);
UNUSED(response_code); if (0 != g_response_code)
{
response_code= g_response_code;
ParodusInfo("response_code is %ld\n", response_code);
}
function_called(); function_called();
return (int) mock(); return (int) mock();
} }
char* get_global_reconnect_reason()
{
return "none";
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Tests */ /* Tests */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -166,6 +183,7 @@ void test_requestNewAuthToken ()
test_data.size = 0; test_data.size = 0;
test_data.data = token; test_data.data = token;
setGlobalResponseCode(200);
will_return (curl_easy_perform, 0); will_return (curl_easy_perform, 0);
expect_function_calls (curl_easy_perform, 1); expect_function_calls (curl_easy_perform, 1);
will_return (curl_easy_getinfo, 0); will_return (curl_easy_getinfo, 0);
@@ -216,6 +234,7 @@ void test_getAuthToken ()
/* To test curl success case */ /* To test curl success case */
test_data.size = 0; test_data.size = 0;
test_data.data = cfg.webpa_auth_token; test_data.data = cfg.webpa_auth_token;
setGlobalResponseCode(200);
will_return (curl_easy_perform, 0); will_return (curl_easy_perform, 0);
expect_function_calls (curl_easy_perform, 1); expect_function_calls (curl_easy_perform, 1);
@@ -313,6 +332,86 @@ void test_write_callback_fn ()
free(data.data); free(data.data);
} }
void test_requestNewAuthToken_non200 ()
{
char token[1024];
ParodusCfg cfg;
int output;
memset(&cfg,0,sizeof(cfg));
cfg.token_server_url = strdup("https://dev.comcast.net/token");
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
set_parodus_cfg(&cfg);
test_data.size = 0;
test_data.data = token;
setGlobalResponseCode(404);
will_return (curl_easy_perform, 0);
expect_function_calls (curl_easy_perform, 1);
will_return (curl_easy_getinfo, 0);
expect_function_calls (curl_easy_getinfo, 1);
will_return (curl_easy_getinfo, 0);
expect_function_calls (curl_easy_getinfo, 1);
output = requestNewAuthToken (token, sizeof(token), 1);
assert_int_equal (output, -1);
assert_string_equal (token, "");
ParodusInfo("requestNewAuthToken output: %d token empty len: %lu\n", output, strlen(token));
free(cfg.token_server_url);
}
void test_getAuthTokenFailure_non200 ()
{
ParodusCfg cfg;
memset(&cfg,0,sizeof(cfg));
cfg.token_server_url = strdup("https://dev.comcast.net/token");
cfg.client_cert_path = strdup("testcert");
parStrncpy(cfg.cert_path , "/etc/ssl/certs/ca-certificates.crt", sizeof(cfg.cert_path));
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
parStrncpy(cfg.hw_serial_number, "Fer23u948590", sizeof(cfg.hw_serial_number));
parStrncpy(cfg.hw_mac , "123567892366", sizeof(cfg.hw_mac));
set_parodus_cfg(&cfg);
will_return (curl_easy_perform, 0);
expect_function_calls (curl_easy_perform, 1);
will_return (curl_easy_getinfo, 0);
expect_function_calls (curl_easy_getinfo, 1);
will_return (curl_easy_getinfo, 0);
expect_function_calls (curl_easy_getinfo, 1);
will_return (curl_easy_perform, 0);
expect_function_calls (curl_easy_perform, 1);
will_return (curl_easy_getinfo, 0);
expect_function_calls (curl_easy_getinfo, 1);
will_return (curl_easy_getinfo, 0);
expect_function_calls (curl_easy_getinfo, 1);
will_return (curl_easy_perform, 0);
expect_function_calls (curl_easy_perform, 1);
will_return (curl_easy_getinfo, 0);
expect_function_calls (curl_easy_getinfo, 1);
will_return (curl_easy_getinfo, 0);
expect_function_calls (curl_easy_getinfo, 1);
setGlobalResponseCode(504);
getAuthToken(&cfg);
assert_string_equal( cfg.webpa_auth_token, "");
free(cfg.client_cert_path);
free(cfg.token_server_url);
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* External Functions */ /* External Functions */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -328,6 +427,8 @@ int main(void)
cmocka_unit_test(getAuthToken_MacNull), cmocka_unit_test(getAuthToken_MacNull),
cmocka_unit_test(test_getAuthToken), cmocka_unit_test(test_getAuthToken),
cmocka_unit_test(test_getAuthTokenFailure), cmocka_unit_test(test_getAuthTokenFailure),
cmocka_unit_test(test_requestNewAuthToken_non200),
cmocka_unit_test(test_getAuthTokenFailure_non200)
}; };
return cmocka_run_group_tests(tests, NULL, NULL); return cmocka_run_group_tests(tests, NULL, NULL);

View File

@@ -69,6 +69,13 @@ int curl_easy_getinfo(CURL *curl, CURLINFO CURLINFO_RESPONSE_CODE, long response
function_called(); function_called();
return (int) mock(); return (int) mock();
} }
char* get_global_reconnect_reason()
{
return "none";
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Tests */ /* Tests */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View File

@@ -32,6 +32,8 @@ pthread_t test_tid2;
static void *client_rcv_task(); static void *client_rcv_task();
static void *client2_rcv_task(); static void *client2_rcv_task();
int numLoops;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Tests */ /* Tests */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View File

@@ -29,6 +29,7 @@
#include "../src/ParodusInternal.h" #include "../src/ParodusInternal.h"
extern int parse_mac_address (char *target, const char *arg); extern int parse_mac_address (char *target, const char *arg);
extern int parse_serial_num(char *target, const char *arg);
extern int server_is_http (const char *full_url, extern int server_is_http (const char *full_url,
const char **server_ptr); const char **server_ptr);
extern int parse_webpa_url__(const char *full_url, extern int parse_webpa_url__(const char *full_url,
@@ -53,6 +54,11 @@ void create_token_script(char *fname)
system(command); system(command);
} }
char* get_global_reconnect_reason()
{
return "none";
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Tests */ /* Tests */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -98,7 +104,7 @@ void test_setParodusConfig()
assert_string_equal(cfg.hw_last_reboot_reason, temp->hw_last_reboot_reason); assert_string_equal(cfg.hw_last_reboot_reason, temp->hw_last_reboot_reason);
assert_string_equal(cfg.webpa_path_url, temp->webpa_path_url); assert_string_equal(cfg.webpa_path_url, temp->webpa_path_url);
assert_string_equal(cfg.webpa_url, temp->webpa_url); assert_string_equal(cfg.webpa_url, temp->webpa_url);
assert_string_equal(cfg.webpa_interface_used, temp->webpa_interface_used); assert_string_equal(cfg.webpa_interface_used, getWebpaInterface());
assert_string_equal(cfg.webpa_protocol, temp->webpa_protocol); assert_string_equal(cfg.webpa_protocol, temp->webpa_protocol);
assert_string_equal(cfg.webpa_uuid, temp->webpa_uuid); assert_string_equal(cfg.webpa_uuid, temp->webpa_uuid);
assert_string_equal(cfg.partner_id, temp->partner_id); assert_string_equal(cfg.partner_id, temp->partner_id);
@@ -116,6 +122,8 @@ void test_setParodusConfig()
assert_string_equal(cfg.jwt_key, temp->jwt_key); assert_string_equal(cfg.jwt_key, temp->jwt_key);
#endif #endif
assert_string_equal(cfg.crud_config_file, temp->crud_config_file); assert_string_equal(cfg.crud_config_file, temp->crud_config_file);
free(cfg.crud_config_file);
} }
void test_getParodusConfig() void test_getParodusConfig()
@@ -201,13 +209,11 @@ void test_parseCommandLine()
ParodusCfg parodusCfg; ParodusCfg parodusCfg;
memset(&parodusCfg,0,sizeof(parodusCfg)); memset(&parodusCfg,0,sizeof(parodusCfg));
#ifdef FEATURE_DNS_QUERY #ifdef FEATURE_DNS_QUERY
write_key_to_file ("../../tests/jwt_key.tst", jwt_key); write_key_to_file ("../../tests/jwt_key.tst", jwt_key);
#endif #endif
create_token_script("/tmp/token.sh"); create_token_script("/tmp/token.sh");
assert_int_equal (parseCommandLine(argc,command,&parodusCfg), 0); assert_int_equal (parseCommandLine(argc,command,&parodusCfg), 0);
assert_string_equal( parodusCfg.hw_model, "TG1682"); assert_string_equal( parodusCfg.hw_model, "TG1682");
assert_string_equal( parodusCfg.hw_serial_number, "Fer23u948590"); assert_string_equal( parodusCfg.hw_serial_number, "Fer23u948590");
assert_string_equal( parodusCfg.hw_manufacturer, "ARRISGroup,Inc."); assert_string_equal( parodusCfg.hw_manufacturer, "ARRISGroup,Inc.");
@@ -299,8 +305,9 @@ void test_loadParodusCfg()
{ {
ParodusCfg tmpcfg; ParodusCfg tmpcfg;
ParodusCfg *Cfg = NULL; ParodusCfg *Cfg = NULL;
Cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
char protocol[32] = {'\0'}; char protocol[32] = {'\0'};
Cfg = (ParodusCfg*)malloc(sizeof(ParodusCfg));
memset(Cfg, 0, sizeof(ParodusCfg));
parStrncpy(Cfg->hw_model, "TG1682", sizeof(Cfg->hw_model)); parStrncpy(Cfg->hw_model, "TG1682", sizeof(Cfg->hw_model));
parStrncpy(Cfg->hw_serial_number, "Fer23u948590", sizeof(Cfg->hw_serial_number)); parStrncpy(Cfg->hw_serial_number, "Fer23u948590", sizeof(Cfg->hw_serial_number));
@@ -351,6 +358,14 @@ void test_loadParodusCfg()
assert_string_equal(tmpcfg.seshat_url, "ipc://tmp/seshat_service.url"); assert_string_equal(tmpcfg.seshat_url, "ipc://tmp/seshat_service.url");
#endif #endif
assert_string_equal(tmpcfg.crud_config_file, "parodus_cfg.json"); assert_string_equal(tmpcfg.crud_config_file, "parodus_cfg.json");
free(tmpcfg.client_cert_path);
free(tmpcfg.token_server_url);
free(tmpcfg.crud_config_file);
free(Cfg->crud_config_file);
free(Cfg->client_cert_path);
free(Cfg->token_server_url);
free(Cfg); free(Cfg);
} }
@@ -422,6 +437,8 @@ void test_setDefaultValuesToCfg()
assert_string_equal(cfg->webpa_path_url, WEBPA_PATH_URL); assert_string_equal(cfg->webpa_path_url, WEBPA_PATH_URL);
assert_string_equal(cfg->webpa_uuid, "1234567-345456546"); assert_string_equal(cfg->webpa_uuid, "1234567-345456546");
assert_string_equal(cfg->cloud_status, CLOUD_STATUS_OFFLINE); assert_string_equal(cfg->cloud_status, CLOUD_STATUS_OFFLINE);
free(cfg);
} }
void err_setDefaultValuesToCfg() void err_setDefaultValuesToCfg()
@@ -451,6 +468,14 @@ void test_parse_mac_address ()
assert_int_equal (parse_mac_address (result, ""), -1); assert_int_equal (parse_mac_address (result, ""), -1);
} }
void test_parse_serial_num()
{
char result[14];
assert_int_equal (parse_serial_num (result, "1234ABC00ab"), 0);
assert_int_equal (parse_serial_num (result, "$@@"), 0);
assert_int_equal (parse_serial_num (result, ""), 0);
}
void test_server_is_http () void test_server_is_http ()
{ {
const char *server_ptr; const char *server_ptr;
@@ -571,6 +596,7 @@ int main(void)
cmocka_unit_test(err_loadParodusCfg), cmocka_unit_test(err_loadParodusCfg),
cmocka_unit_test(test_parse_num_arg), cmocka_unit_test(test_parse_num_arg),
cmocka_unit_test(test_parse_mac_address), cmocka_unit_test(test_parse_mac_address),
cmocka_unit_test(test_parse_serial_num),
cmocka_unit_test(test_get_algo_mask), cmocka_unit_test(test_get_algo_mask),
cmocka_unit_test(test_server_is_http), cmocka_unit_test(test_server_is_http),
cmocka_unit_test(test_parse_webpa_url__), cmocka_unit_test(test_parse_webpa_url__),

View File

@@ -42,14 +42,26 @@ pthread_mutex_t nano_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t nano_con=PTHREAD_COND_INITIALIZER; pthread_cond_t nano_con=PTHREAD_COND_INITIALIZER;
pthread_mutex_t svc_mut=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t svc_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t svc_con=PTHREAD_COND_INITIALIZER; pthread_cond_t svc_con=PTHREAD_COND_INITIALIZER;
int numLoops;
parodusOnPingStatusChangeHandler on_ping_status_change;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Mocks */ /* Mocks */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
int createNopollConnection(noPollCtx *ctx) void set_server_list_null (server_list_t *server_list)
{ {
UNUSED(ctx); UNUSED(server_list);
}
int find_servers (server_list_t *server_list)
{
UNUSED(server_list);
return FIND_SUCCESS;
}
int createNopollConnection(noPollCtx *ctx, server_list_t *server_list)
{
UNUSED(ctx); UNUSED(server_list);
function_called(); function_called();
return (int) mock(); return (int) mock();
} }
@@ -59,7 +71,10 @@ void nopoll_log_set_handler (noPollCtx *ctx, noPollLogHandler handler, noPollPtr
UNUSED(ctx); UNUSED(handler); UNUSED(user_data); UNUSED(ctx); UNUSED(handler); UNUSED(user_data);
function_called(); function_called();
} }
int cloud_status_is_online (void)
{
return 0;
}
void __report_log (noPollCtx * ctx, noPollDebugLevel level, const char * log_msg, noPollPtr user_data) void __report_log (noPollCtx * ctx, noPollDebugLevel level, const char * log_msg, noPollPtr user_data)
{ {
UNUSED(ctx); UNUSED(level); UNUSED(log_msg); UNUSED(user_data); UNUSED(ctx); UNUSED(level); UNUSED(log_msg); UNUSED(user_data);
@@ -91,8 +106,14 @@ void set_global_shutdown_reason(char *reason)
UNUSED(reason); UNUSED(reason);
} }
void start_conn_in_progress (void) int getDeviceId(char **device_id, size_t *device_id_len)
{ {
UNUSED(device_id); UNUSED(device_id_len);
return 0;
}
void start_conn_in_progress (unsigned long start_time)
{
UNUSED(start_time);
} }
void stop_conn_in_progress (void) void stop_conn_in_progress (void)
@@ -108,6 +129,10 @@ bool get_interface_down_event (void)
return false; return false;
} }
void set_interface_down_event (void)
{
}
int wait_while_interface_down (void) int wait_while_interface_down (void)
{ {
return 0; return 0;
@@ -122,6 +147,10 @@ void packMetaData()
function_called(); function_called();
} }
int get_parodus_init()
{
return 0;
}
int get_cloud_disconnect_time(void) int get_cloud_disconnect_time(void)
{ {
@@ -155,6 +184,18 @@ int serviceAliveTask()
return 0; return 0;
} }
int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
{
UNUSED(msg); UNUSED(partnerIds);
return 0;
}
int sendUpstreamMsgToServer(void **resp_bytes, size_t resp_size)
{
UNUSED(resp_bytes); UNUSED(resp_size);
return 0;
}
int nopoll_loop_wait(noPollCtx * ctx,long timeout) int nopoll_loop_wait(noPollCtx * ctx,long timeout)
{ {
UNUSED(ctx); UNUSED(timeout); UNUSED(ctx); UNUSED(timeout);
@@ -174,12 +215,19 @@ void set_global_reconnect_status(bool status)
function_called(); function_called();
} }
void close_and_unref_connection(noPollConn *conn) void close_and_unref_connection(noPollConn *conn, bool is_shutting_down)
{ {
UNUSED(conn); UNUSED(conn); UNUSED(is_shutting_down);
function_called(); function_called();
} }
int readFromFile(const char *file_name, char **data)
{
UNUSED(file_name);
*data = strdup ("parodus_stopping");
return 1;
}
void nopoll_cleanup_library () void nopoll_cleanup_library ()
{ {
function_called(); function_called();
@@ -268,9 +316,6 @@ void timespec_diff(struct timespec *start, struct timespec *stop,
diff->tv_nsec = 1000; diff->tv_nsec = 1000;
} }
void deleteAllClients (void)
{
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Tests */ /* Tests */
@@ -314,6 +359,7 @@ void test_createSocketConnection()
void test_createSocketConnection1() void test_createSocketConnection1()
{ {
numLoops =0;
noPollCtx *ctx; noPollCtx *ctx;
ParodusCfg cfg; ParodusCfg cfg;
memset(&cfg,0, sizeof(ParodusCfg)); memset(&cfg,0, sizeof(ParodusCfg));
@@ -343,11 +389,11 @@ void test_createSocketConnection1()
expect_function_call(nopoll_ctx_unref); expect_function_call(nopoll_ctx_unref);
expect_function_call(nopoll_cleanup_library); expect_function_call(nopoll_cleanup_library);
createSocketConnection(NULL); createSocketConnection(NULL);
} }
void test_PingMissIntervalTime() void test_PingMissIntervalTime()
{ {
numLoops = 6;
noPollCtx *ctx; noPollCtx *ctx;
ParodusCfg cfg; ParodusCfg cfg;
memset(&cfg,0,sizeof(ParodusCfg)); memset(&cfg,0,sizeof(ParodusCfg));
@@ -365,7 +411,6 @@ void test_PingMissIntervalTime()
//Max ping timeout is 6 sec //Max ping timeout is 6 sec
cfg.webpa_ping_timeout = 6; cfg.webpa_ping_timeout = 6;
set_parodus_cfg(&cfg); set_parodus_cfg(&cfg);
reset_close_retry(); reset_close_retry();
expect_function_call(nopoll_thread_handlers); expect_function_call(nopoll_thread_handlers);
@@ -401,11 +446,11 @@ void test_PingMissIntervalTime()
expect_function_call(nopoll_ctx_unref); expect_function_call(nopoll_ctx_unref);
expect_function_call(nopoll_cleanup_library); expect_function_call(nopoll_cleanup_library);
createSocketConnection(NULL); createSocketConnection(NULL);
} }
void err_createSocketConnection() void err_createSocketConnection()
{ {
numLoops =0;
set_close_retry(); set_close_retry();
reset_heartBeatTimer(); reset_heartBeatTimer();
expect_function_call(nopoll_thread_handlers); expect_function_call(nopoll_thread_handlers);
@@ -438,6 +483,7 @@ void err_createSocketConnection()
void test_createSocketConnection_cloud_disconn() void test_createSocketConnection_cloud_disconn()
{ {
numLoops =0;
ParodusCfg cfg; ParodusCfg cfg;
memset(&cfg,0,sizeof(ParodusCfg)); memset(&cfg,0,sizeof(ParodusCfg));
cfg.cloud_disconnect = strdup("XPC"); cfg.cloud_disconnect = strdup("XPC");

View File

@@ -15,14 +15,12 @@
*/ */
#include <stdarg.h> #include <stdarg.h>
#include <CUnit/Basic.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <setjmp.h> #include <setjmp.h>
#include <cmocka.h> #include <cmocka.h>
#include <assert.h> #include <assert.h>
#include <CUnit/Basic.h>
#include <nopoll.h> #include <nopoll.h>
#include <pthread.h> #include <pthread.h>
@@ -39,6 +37,11 @@ extern void init_expire_timer (expire_timer_t *timer);
extern int check_timer_expired (expire_timer_t *timer, long timeout_ms); extern int check_timer_expired (expire_timer_t *timer, long timeout_ms);
extern void init_backoff_timer (backoff_timer_t *timer, int max_count); extern void init_backoff_timer (backoff_timer_t *timer, int max_count);
extern int update_backoff_delay (backoff_timer_t *timer); extern int update_backoff_delay (backoff_timer_t *timer);
extern void add_timespec (struct timespec *t1, struct timespec *t2);
extern unsigned calc_random_secs (int random_num, unsigned max_secs);
extern unsigned calc_random_nsecs (int random_num);
void calc_random_expiration (int random_num1, int random_num2,
backoff_timer_t *timer, struct timespec *ts);
extern int init_header_info (header_info_t *header_info); extern int init_header_info (header_info_t *header_info);
extern void free_header_info (header_info_t *header_info); extern void free_header_info (header_info_t *header_info);
extern char *build_extra_hdrs (header_info_t *header_info); extern char *build_extra_hdrs (header_info_t *header_info);
@@ -59,10 +62,8 @@ extern int keep_trying_to_connect (create_connection_ctx_t *ctx,
/* File Scoped Variables */ /* File Scoped Variables */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
bool close_retry;
bool LastReasonStatus; bool LastReasonStatus;
bool interface_down_event = false; bool interface_down_event = false;
pthread_mutex_t close_mut;
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER; pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
@@ -113,6 +114,13 @@ pthread_mutex_t *get_interface_down_mut(void)
return &interface_down_mut; return &interface_down_mut;
} }
int readFromFile(const char *file_name, char **data)
{
UNUSED(file_name);
*data = strdup ("parodus_stopping");
return 1;
}
noPollConn * nopoll_conn_new_opts (noPollCtx * ctx, noPollConnOpts * opts, const char * host_ip, const char * host_port, const char * host_name,const char * get_url,const char * protocols, const char * origin) noPollConn * nopoll_conn_new_opts (noPollCtx * ctx, noPollConnOpts * opts, const char * host_ip, const char * host_port, const char * host_name,const char * get_url,const char * protocols, const char * origin)
{ {
UNUSED(host_port); UNUSED(host_name); UNUSED(get_url); UNUSED(protocols); UNUSED(host_port); UNUSED(host_name); UNUSED(get_url); UNUSED(protocols);
@@ -258,7 +266,7 @@ void test_set_global_reconnect_reason()
void test_closeConnection() void test_closeConnection()
{ {
close_and_unref_connection(get_global_conn()); close_and_unref_connection(get_global_conn(), false);
} }
void test_server_is_null() void test_server_is_null()
@@ -335,13 +343,67 @@ void test_expire_timer()
void test_backoff_delay_timer() void test_backoff_delay_timer()
{ {
struct timespec t1;
struct timespec t2;
backoff_timer_t btimer; backoff_timer_t btimer;
init_backoff_timer (&btimer, 5); init_backoff_timer (&btimer, 5);
assert_int_equal (3, update_backoff_delay (&btimer)); assert_int_equal (3, update_backoff_delay (&btimer));
assert_int_equal (7, update_backoff_delay (&btimer)); assert_int_equal (7, update_backoff_delay (&btimer));
assert_int_equal (15, update_backoff_delay (&btimer)); assert_int_equal (15, update_backoff_delay (&btimer));
assert_int_equal (31, update_backoff_delay (&btimer)); assert_int_equal (31, update_backoff_delay (&btimer));
assert_int_equal (31, update_backoff_delay (&btimer));
t1.tv_sec = 3; t1.tv_nsec = 0;
t2.tv_sec = 3; t2.tv_nsec = 0;
add_timespec (&t1, &t2);
assert_int_equal (6, t2.tv_sec);
assert_int_equal (0, t2.tv_nsec);
t1.tv_sec = 3; t1.tv_nsec = 500*1000000;
t2.tv_sec = 3; t2.tv_nsec = 499*1000000;
add_timespec (&t1, &t2);
assert_int_equal (6, t2.tv_sec);
assert_int_equal (999*1000000, t2.tv_nsec);
t1.tv_sec = 3; t1.tv_nsec = 500*1000000;
t2.tv_sec = 3; t2.tv_nsec = 501*1000000;
add_timespec (&t1, &t2);
assert_int_equal (7, t2.tv_sec);
assert_int_equal (1000000, t2.tv_nsec);
assert_int_equal (3, calc_random_secs (0, 7));
assert_int_equal (4, calc_random_secs (1, 7));
assert_int_equal (7, calc_random_secs (15, 7));
assert_int_equal (3, calc_random_secs (16, 15));
assert_int_equal (14, calc_random_secs (30,15));
assert_int_equal (250000, calc_random_nsecs (500000));
assert_int_equal (1, calc_random_nsecs (2000000002));
init_backoff_timer (&btimer, 5);
t1.tv_sec = 0; t1.tv_nsec = 0;
/* max delay is 3 */
calc_random_expiration (0, 0, &btimer, &t1);
assert_int_equal (3, t1.tv_sec);
assert_int_equal (0, t1.tv_nsec);
t1.tv_sec = 0; t1.tv_nsec = 0;
/* max delay is 7*/
calc_random_expiration (15, 1073741824, &btimer, &t1);
assert_int_equal (7, t1.tv_sec);
assert_int_equal (536870912, t1.tv_nsec);
t1.tv_sec = 0; t1.tv_nsec = 0;
/* max delay is 15 */
calc_random_expiration (30, 2000000002, &btimer, &t1);
assert_int_equal (14, t1.tv_sec);
assert_int_equal (1, t1.tv_nsec);
t1.tv_sec = 0; t1.tv_nsec = 0;
/* max delay is 31 */
calc_random_expiration (32, 1, &btimer, &t1);
assert_int_equal (3, t1.tv_sec);
assert_int_equal (0, t1.tv_nsec);
} }
@@ -397,16 +459,19 @@ void test_extra_headers ()
void test_set_current_server() void test_set_current_server()
{ {
server_list_t server_list;
create_connection_ctx_t ctx; create_connection_ctx_t ctx;
memset (&ctx, 0xFF, sizeof(ctx)); memset (&server_list, 0xFF, sizeof(server_list));
memset (&ctx, 0, sizeof(ctx));
ctx.server_list = &server_list;
set_current_server (&ctx); set_current_server (&ctx);
assert_ptr_equal (&ctx.server_list.redirect, ctx.current_server); assert_ptr_equal (&ctx.server_list->redirect, ctx.current_server);
set_server_null (&ctx.server_list.redirect); set_server_null (&ctx.server_list->redirect);
set_current_server (&ctx); set_current_server (&ctx);
assert_ptr_equal (&ctx.server_list.jwt, ctx.current_server); assert_ptr_equal (&ctx.server_list->jwt, ctx.current_server);
set_server_null (&ctx.server_list.jwt); set_server_null (&ctx.server_list->jwt);
set_current_server (&ctx); set_current_server (&ctx);
assert_ptr_equal (&ctx.server_list.defaults, ctx.current_server); assert_ptr_equal (&ctx.server_list->defaults, ctx.current_server);
} }
void init_cfg_header_info (ParodusCfg *cfg) void init_cfg_header_info (ParodusCfg *cfg)
@@ -622,10 +687,12 @@ void test_nopoll_connect ()
void test_wait_connection_ready () void test_wait_connection_ready ()
{ {
server_list_t server_list;
create_connection_ctx_t ctx; create_connection_ctx_t ctx;
set_server_list_null (&server_list);
memset(&ctx,0,sizeof(ctx)); memset(&ctx,0,sizeof(ctx));
set_server_list_null (&ctx.server_list); ctx.server_list = &server_list;
mock_wait_status = 0; mock_wait_status = 0;
mock_redirect = NULL; mock_redirect = NULL;
@@ -654,22 +721,22 @@ void test_wait_connection_ready ()
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
assert_int_equal (wait_connection_ready (&ctx), WAIT_ACTION_RETRY); assert_int_equal (wait_connection_ready (&ctx), WAIT_ACTION_RETRY);
assert_string_equal (ctx.server_list.redirect.server_addr, "mydns.mycom.net"); assert_string_equal (ctx.server_list->redirect.server_addr, "mydns.mycom.net");
assert_int_equal (ctx.server_list.redirect.port, 8080); assert_int_equal (ctx.server_list->redirect.port, 8080);
assert_int_equal (0, ctx.server_list.redirect.allow_insecure); assert_int_equal (0, ctx.server_list->redirect.allow_insecure);
assert_ptr_equal (ctx.current_server, &ctx.server_list.redirect); assert_ptr_equal (ctx.current_server, &ctx.server_list->redirect);
free_server (&ctx.server_list.redirect); free_server (&ctx.server_list->redirect);
mock_wait_status = 303; mock_wait_status = 303;
mock_redirect = "http://mydns.mycom.net"; mock_redirect = "http://mydns.mycom.net";
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
assert_int_equal (wait_connection_ready (&ctx), WAIT_ACTION_RETRY); assert_int_equal (wait_connection_ready (&ctx), WAIT_ACTION_RETRY);
assert_string_equal (ctx.server_list.redirect.server_addr, "mydns.mycom.net"); assert_string_equal (ctx.server_list->redirect.server_addr, "mydns.mycom.net");
assert_int_equal (ctx.server_list.redirect.port, 80); assert_int_equal (ctx.server_list->redirect.port, 80);
assert_int_equal (1, ctx.server_list.redirect.allow_insecure); assert_int_equal (1, ctx.server_list->redirect.allow_insecure);
assert_ptr_equal (ctx.current_server, &ctx.server_list.redirect); assert_ptr_equal (ctx.current_server, &ctx.server_list->redirect);
free_server (&ctx.server_list.redirect); free_server (&ctx.server_list->redirect);
mock_wait_status = 403; mock_wait_status = 403;
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
@@ -687,6 +754,7 @@ void test_wait_connection_ready ()
void test_connect_and_wait () void test_connect_and_wait ()
{ {
server_list_t server_list;
create_connection_ctx_t ctx; create_connection_ctx_t ctx;
noPollCtx test_nopoll_ctx; noPollCtx test_nopoll_ctx;
server_t test_server; server_t test_server;
@@ -703,7 +771,9 @@ void test_connect_and_wait ()
mock_wait_status = 0; mock_wait_status = 0;
set_server_list_null (&server_list);
memset(&ctx,0,sizeof(ctx)); memset(&ctx,0,sizeof(ctx));
ctx.server_list = &server_list;
ctx.nopoll_ctx = &test_nopoll_ctx; ctx.nopoll_ctx = &test_nopoll_ctx;
ctx.current_server = &test_server; ctx.current_server = &test_server;
ctx.extra_headers = test_extra_headers; ctx.extra_headers = test_extra_headers;
@@ -818,9 +888,9 @@ void test_connect_and_wait ()
void test_keep_trying () void test_keep_trying ()
{ {
int rtn; int rtn;
server_list_t server_list;
create_connection_ctx_t ctx; create_connection_ctx_t ctx;
noPollCtx test_nopoll_ctx; noPollCtx test_nopoll_ctx;
server_t test_server;
backoff_timer_t backoff_timer; backoff_timer_t backoff_timer;
ParodusCfg Cfg; ParodusCfg Cfg;
@@ -830,13 +900,15 @@ void test_keep_trying ()
mock_wait_status = 0; mock_wait_status = 0;
set_server_list_null (&server_list);
memset(&ctx,0,sizeof(ctx)); memset(&ctx,0,sizeof(ctx));
ctx.server_list = &server_list;
ctx.nopoll_ctx = &test_nopoll_ctx; ctx.nopoll_ctx = &test_nopoll_ctx;
ctx.current_server = &test_server;
test_server.allow_insecure = 1; server_list.defaults.allow_insecure = 1;
test_server.server_addr = "mydns.mycom.net"; server_list.defaults.server_addr = "mydns.mycom.net";
test_server.port = 8080; server_list.defaults.port = 8080;
set_current_server (&ctx);
Cfg.flags = 0; Cfg.flags = 0;
set_parodus_cfg(&Cfg); set_parodus_cfg(&Cfg);
@@ -851,7 +923,7 @@ void test_keep_trying ()
rtn = keep_trying_to_connect (&ctx, &backoff_timer); rtn = keep_trying_to_connect (&ctx, &backoff_timer);
assert_int_equal (rtn, true); assert_int_equal (rtn, true);
test_server.allow_insecure = 0; server_list.defaults.allow_insecure = 0;
Cfg.flags = FLAGS_IPV4_ONLY; Cfg.flags = FLAGS_IPV4_ONLY;
set_parodus_cfg(&Cfg); set_parodus_cfg(&Cfg);
@@ -918,9 +990,12 @@ void test_create_nopoll_connection()
{ {
int rtn; int rtn;
ParodusCfg cfg; ParodusCfg cfg;
server_list_t server_list;
noPollCtx test_nopoll_ctx; noPollCtx test_nopoll_ctx;
set_server_list_null (&server_list);
memset(&cfg,0,sizeof(cfg)); memset(&cfg,0,sizeof(cfg));
cfg.flags = 0; cfg.flags = 0;
parStrncpy (cfg.webpa_url, "mydns.mycom.net:8080", sizeof(cfg.webpa_url)); parStrncpy (cfg.webpa_url, "mydns.mycom.net:8080", sizeof(cfg.webpa_url));
cfg.boot_time = 25; cfg.boot_time = 25;
@@ -933,11 +1008,12 @@ void test_create_nopoll_connection()
parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name)); parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name));
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol)); parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
set_parodus_cfg(&cfg); set_parodus_cfg(&cfg);
rtn = createNopollConnection (&test_nopoll_ctx); rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_false); assert_int_equal (rtn, nopoll_false);
parStrncpy (cfg.webpa_url, "http://mydns.mycom.net:8080", sizeof(cfg.webpa_url)); parStrncpy (cfg.webpa_url, "http://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
set_parodus_cfg(&cfg); set_parodus_cfg(&cfg);
set_server_list_null (&server_list);
mock_wait_status = 0; mock_wait_status = 0;
@@ -947,12 +1023,13 @@ void test_create_nopoll_connection()
expect_function_call (nopoll_conn_is_ok); expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
parStrncpy (cfg.webpa_url, "https://mydns.mycom.net:8080", sizeof(cfg.webpa_url)); parStrncpy (cfg.webpa_url, "https://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
cfg.flags = 0; cfg.flags = 0;
set_parodus_cfg(&cfg); set_parodus_cfg(&cfg);
set_server_list_null (&server_list);
will_return (nopoll_conn_tls_new6, &connection1); will_return (nopoll_conn_tls_new6, &connection1);
expect_function_call (nopoll_conn_tls_new6); expect_function_call (nopoll_conn_tls_new6);
@@ -964,9 +1041,11 @@ void test_create_nopoll_connection()
expect_function_call (nopoll_conn_is_ok); expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
set_server_list_null (&server_list);
will_return (nopoll_conn_tls_new6, &connection1); will_return (nopoll_conn_tls_new6, &connection1);
expect_function_call (nopoll_conn_tls_new6); expect_function_call (nopoll_conn_tls_new6);
will_return (nopoll_conn_is_ok, nopoll_false); will_return (nopoll_conn_is_ok, nopoll_false);
@@ -991,13 +1070,14 @@ void test_create_nopoll_connection()
mock_wait_status = 0; mock_wait_status = 0;
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
#ifdef FEATURE_DNS_QUERY #ifdef FEATURE_DNS_QUERY
cfg.acquire_jwt = 1; cfg.acquire_jwt = 1;
cfg.flags = FLAGS_IPV4_ONLY; cfg.flags = FLAGS_IPV4_ONLY;
set_parodus_cfg(&cfg); set_parodus_cfg(&cfg);
set_server_list_null (&server_list);
will_return (allow_insecure_conn, -1); will_return (allow_insecure_conn, -1);
expect_function_call (allow_insecure_conn); expect_function_call (allow_insecure_conn);
@@ -1015,11 +1095,32 @@ void test_create_nopoll_connection()
expect_function_call (nopoll_conn_is_ok); expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true);
set_server_list_null (&server_list);
mock_server_addr = "mydns.myjwtcom.net";
mock_port = 80;
will_return (allow_insecure_conn, 0);
expect_function_call (allow_insecure_conn);
will_return (nopoll_conn_tls_new, &connection1);
expect_function_call (nopoll_conn_tls_new);
will_return (nopoll_conn_is_ok, nopoll_true);
expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_false);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
will_return (nopoll_conn_tls_new, &connection1);
expect_function_call (nopoll_conn_tls_new);
will_return (nopoll_conn_is_ok, nopoll_true);
expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
cfg.flags = 0; cfg.flags = 0;
set_parodus_cfg(&cfg); set_parodus_cfg(&cfg);
set_server_list_null (&server_list);
will_return (allow_insecure_conn, -1); will_return (allow_insecure_conn, -1);
expect_function_call (allow_insecure_conn); expect_function_call (allow_insecure_conn);
@@ -1034,7 +1135,7 @@ void test_create_nopoll_connection()
expect_function_call (nopoll_conn_is_ok); expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
#endif #endif
@@ -1060,6 +1161,7 @@ void test_interface_down_retry()
int rtn; int rtn;
ParodusCfg cfg; ParodusCfg cfg;
noPollCtx test_nopoll_ctx; noPollCtx test_nopoll_ctx;
server_list_t server_list;
pthread_t thread_a; pthread_t thread_a;
pthread_create(&thread_a, NULL, a, NULL); pthread_create(&thread_a, NULL, a, NULL);
@@ -1077,7 +1179,8 @@ void test_interface_down_retry()
parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name)); parStrncpy(cfg.fw_name , "2.364s2", sizeof(cfg.fw_name));
parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol)); parStrncpy(cfg.webpa_protocol , "WebPA-1.6", sizeof(cfg.webpa_protocol));
set_parodus_cfg(&cfg); set_parodus_cfg(&cfg);
rtn = createNopollConnection (&test_nopoll_ctx); set_server_list_null (&server_list);
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_false); assert_int_equal (rtn, nopoll_false);
parStrncpy (cfg.webpa_url, "http://mydns.mycom.net:8080", sizeof(cfg.webpa_url)); parStrncpy (cfg.webpa_url, "http://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
@@ -1091,7 +1194,8 @@ void test_interface_down_retry()
expect_function_call (nopoll_conn_is_ok); expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); set_server_list_null (&server_list);
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
parStrncpy (cfg.webpa_url, "https://mydns.mycom.net:8080", sizeof(cfg.webpa_url)); parStrncpy (cfg.webpa_url, "https://mydns.mycom.net:8080", sizeof(cfg.webpa_url));
@@ -1108,7 +1212,8 @@ void test_interface_down_retry()
expect_function_call (nopoll_conn_is_ok); expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); set_server_list_null (&server_list);
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
will_return (nopoll_conn_tls_new6, &connection1); will_return (nopoll_conn_tls_new6, &connection1);
@@ -1135,7 +1240,8 @@ void test_interface_down_retry()
mock_wait_status = 0; mock_wait_status = 0;
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); set_server_list_null (&server_list);
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
#ifdef FEATURE_DNS_QUERY #ifdef FEATURE_DNS_QUERY
@@ -1159,7 +1265,8 @@ void test_interface_down_retry()
expect_function_call (nopoll_conn_is_ok); expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); set_server_list_null (&server_list);
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
cfg.flags = 0; cfg.flags = 0;
@@ -1178,7 +1285,8 @@ void test_interface_down_retry()
expect_function_call (nopoll_conn_is_ok); expect_function_call (nopoll_conn_is_ok);
will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true); will_return (nopoll_conn_wait_for_status_until_connection_ready, nopoll_true);
expect_function_call (nopoll_conn_wait_for_status_until_connection_ready); expect_function_call (nopoll_conn_wait_for_status_until_connection_ready);
rtn = createNopollConnection (&test_nopoll_ctx); set_server_list_null (&server_list);
rtn = createNopollConnection (&test_nopoll_ctx, &server_list);
assert_int_equal (rtn, nopoll_true); assert_int_equal (rtn, nopoll_true);
#endif #endif
pthread_join(thread_a, NULL); pthread_join(thread_a, NULL);
@@ -1210,7 +1318,7 @@ int main(void)
cmocka_unit_test(test_wait_connection_ready), cmocka_unit_test(test_wait_connection_ready),
cmocka_unit_test(test_connect_and_wait), cmocka_unit_test(test_connect_and_wait),
cmocka_unit_test(test_keep_trying), cmocka_unit_test(test_keep_trying),
cmocka_unit_test(test_create_nopoll_connection), cmocka_unit_test(test_create_nopoll_connection),
cmocka_unit_test(test_get_interface_down_event), cmocka_unit_test(test_get_interface_down_event),
cmocka_unit_test(test_interface_down_retry) cmocka_unit_test(test_interface_down_retry)
}; };

View File

@@ -341,7 +341,7 @@ void test_createConnection()
int ret = createNopollConnection(ctx); int ret = createNopollConnection(ctx);
assert_int_equal(ret, nopoll_true); assert_int_equal(ret, nopoll_true);
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_ONLINE); assert_string_equal(get_cloud_status(), CLOUD_STATUS_ONLINE);
free(cfg); free(cfg);
if (g_jwt_server_ip !=NULL) if (g_jwt_server_ip !=NULL)
{ {

View File

@@ -125,6 +125,10 @@ int processCrudRequest(wrp_msg_t *reqMsg, wrp_msg_t **responseMsg )
return (int)mock(); return (int)mock();
} }
char* getWebpaInterface(void)
{
return NULL;
}
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Tests */ /* Tests */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View File

@@ -32,8 +32,10 @@
#include "../src/connection.h" #include "../src/connection.h"
#include "../src/close_retry.h" #include "../src/close_retry.h"
bool LastReasonStatus; char *get_global_reconnect_reason()
pthread_mutex_t close_mut; {
return "parodus_stopping";
}
void set_global_reconnect_reason(char *reason) void set_global_reconnect_reason(char *reason)
{ {
@@ -1528,7 +1530,7 @@ void test_retrieveObject_cloud_status()
ret = retrieveObject(reqMsg, &respMsg); ret = retrieveObject(reqMsg, &respMsg);
assert_int_equal (respMsg->u.crud.status, 200); assert_int_equal (respMsg->u.crud.status, 200);
assert_int_equal (ret, 0); assert_int_equal (ret, 0);
assert_string_equal(get_parodus_cfg()->cloud_status, CLOUD_STATUS_ONLINE); assert_string_equal(get_cloud_status(), CLOUD_STATUS_ONLINE);
assert_int_equal (respMsg->u.crud.payload_size, 25); assert_int_equal (respMsg->u.crud.payload_size, 25);
fp = fopen(cfg.crud_config_file, "r"); fp = fopen(cfg.crud_config_file, "r");

View File

@@ -64,7 +64,18 @@ reg_list_item_t * get_global_node(void)
void release_global_node (void) void release_global_node (void)
{ {
} }
void addToCloudAckQ(char *transaction_id, int qos, int rdr)
{
(void)transaction_id;
(void)qos;
(void)rdr;
return;
}
bool highQosValueCheck(int qos)
{
(void)qos;
return false;
}
ssize_t wrp_to_struct( const void *bytes, const size_t length, ssize_t wrp_to_struct( const void *bytes, const size_t length,
const enum wrp_format fmt, wrp_msg_t **msg ) const enum wrp_format fmt, wrp_msg_t **msg )
{ {

View File

@@ -192,6 +192,20 @@ int validate_partner_id(wrp_msg_t *msg, partners_t **partnerIds)
return 1; return 1;
} }
void addToCloudAckQ(char *transaction_id, int qos, int rdr)
{
(void)transaction_id;
(void)qos;
(void)rdr;
return;
}
bool highQosValueCheck(int qos)
{
(void)qos;
return false;
}
ssize_t wrp_to_struct( const void *bytes, const size_t length, const enum wrp_format fmt, ssize_t wrp_to_struct( const void *bytes, const size_t length, const enum wrp_format fmt,
wrp_msg_t **msg ) wrp_msg_t **msg )
{ {

View File

@@ -79,7 +79,6 @@ void test_mutexHeartBeatTimer() {
ParodusInfo("heartBeatTimer reset to: %d\n", heartBeatTimer); ParodusInfo("heartBeatTimer reset to: %d\n", heartBeatTimer);
assert_int_equal(heartBeatTimer, 0); assert_int_equal(heartBeatTimer, 0);
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* External Functions */ /* External Functions */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View File

@@ -28,14 +28,11 @@
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* File Scoped Variables */ /* File Scoped Variables */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
volatile unsigned int heartBeatTimer;
bool LastReasonStatus; bool LastReasonStatus;
bool interface_down_event = false; bool interface_down_event = false;
int closeReason = 0; int closeReason = 0;
pthread_mutex_t close_mut;
pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t interface_down_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER; pthread_cond_t interface_down_con=PTHREAD_COND_INITIALIZER;
bool close_retry;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Mocks */ /* Mocks */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/

View File

@@ -30,10 +30,7 @@
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* File Scoped Variables */ /* File Scoped Variables */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
volatile unsigned int heartBeatTimer;
bool LastReasonStatus; bool LastReasonStatus;
pthread_mutex_t close_mut;
bool close_retry;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Mocks */ /* Mocks */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -71,7 +68,6 @@ nopoll_bool nopoll_msg_is_final(noPollMsg *msg)
function_called(); function_called();
return (nopoll_bool) mock(); return (nopoll_bool) mock();
} }
const unsigned char *nopoll_msg_get_payload(noPollMsg *msg) const unsigned char *nopoll_msg_get_payload(noPollMsg *msg)
{ {
(void)msg; (void)msg;

View File

@@ -23,6 +23,10 @@
#include "../src/parodus_log.h" #include "../src/parodus_log.h"
#include "../src/nopoll_helpers.h" #include "../src/nopoll_helpers.h"
#include "../src/config.h"
#include <cjwt/cjwt.h>
#include "../src/connection.h"
#include "../src/ParodusInternal.h"
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Macros */ /* Macros */
@@ -32,7 +36,8 @@
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* File Scoped Variables */ /* File Scoped Variables */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
static noPollConn *conn; static noPollConn *conn = NULL;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Mocks */ /* Mocks */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -122,6 +127,7 @@ bool get_interface_down_event()
return false; return false;
} }
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Tests */ /* Tests */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -212,13 +218,7 @@ void test_sendMessage()
{ {
int len = strlen("Hello Parodus!"); int len = strlen("Hello Parodus!");
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)conn); get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
will_return(nopoll_conn_is_ok, nopoll_true);
expect_function_call(nopoll_conn_is_ok);
expect_value(nopoll_conn_is_ready, (intptr_t)conn, (intptr_t)conn);
will_return(nopoll_conn_is_ready, nopoll_true);
expect_function_call(nopoll_conn_is_ready);
expect_value(__nopoll_conn_send_common, (intptr_t)conn, (intptr_t)conn); expect_value(__nopoll_conn_send_common, (intptr_t)conn, (intptr_t)conn);
expect_value(__nopoll_conn_send_common, length, len); expect_value(__nopoll_conn_send_common, length, len);
@@ -228,80 +228,20 @@ void test_sendMessage()
sendMessage(conn, "Hello Parodus!", len); sendMessage(conn, "Hello Parodus!", len);
} }
void connStuck_sendMessage() void test_sendMessageOffline()
{ {
int len = strlen("Hello Parodus!"); int len = strlen("Hello Parodus!");
/* Initialize the timer when connection gets stuck */
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
will_return(nopoll_conn_is_ok, nopoll_false);
expect_function_call(nopoll_conn_is_ok);
expect_function_call(getCurrentTime);
sendMessage(NULL, "Hello Parodus!", len);
/* When connection recovers within 10 mins, it should be able to re-connect */
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
will_return(nopoll_conn_is_ok, nopoll_false);
expect_function_call(nopoll_conn_is_ok);
expect_function_call(getCurrentTime);
will_return(timeValDiff, 5*60*1000);
expect_function_call(timeValDiff);
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)conn);
will_return(nopoll_conn_is_ok, nopoll_true);
expect_function_call(nopoll_conn_is_ok);
expect_value(nopoll_conn_is_ready, (intptr_t)conn, (intptr_t)conn);
will_return(nopoll_conn_is_ready, nopoll_true);
expect_function_call(nopoll_conn_is_ready);
expect_value(__nopoll_conn_send_common, (intptr_t)conn, (intptr_t)conn);
expect_value(__nopoll_conn_send_common, length, len);
will_return(__nopoll_conn_send_common, len);
expect_function_calls(__nopoll_conn_send_common, 1);
get_parodus_cfg()->cloud_status = CLOUD_STATUS_OFFLINE;
sendMessage(conn, "Hello Parodus!", len); sendMessage(conn, "Hello Parodus!", len);
/* When timer exceeds more than 10 mins kill the process */
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
will_return(nopoll_conn_is_ok, nopoll_false);
expect_function_call(nopoll_conn_is_ok);
sendMessage(NULL, "Hello Parodus!", len);
expect_function_call(getCurrentTime);
sendMessage(NULL, "Hello Parodus!", len);
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL);
will_return(nopoll_conn_is_ok, nopoll_false);
expect_function_call(nopoll_conn_is_ok);
expect_function_call(getCurrentTime);
will_return(timeValDiff, 10*60*1000);
expect_function_call(timeValDiff);
will_return(kill, 1);
expect_function_call(kill);
sendMessage(NULL, "Hello Parodus!", len);
} }
void err_sendMessage() void err_sendMessage()
{ {
int len = strlen("Hello Parodus!"); int len = strlen("Hello Parodus!");
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)conn); get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
will_return(nopoll_conn_is_ok, nopoll_true);
expect_function_call(nopoll_conn_is_ok);
expect_value(nopoll_conn_is_ready, (intptr_t)conn, (intptr_t)conn);
will_return(nopoll_conn_is_ready, nopoll_true);
expect_function_call(nopoll_conn_is_ready);
expect_value(__nopoll_conn_send_common, (intptr_t)conn,(intptr_t) conn); expect_value(__nopoll_conn_send_common, (intptr_t)conn,(intptr_t) conn);
expect_value(__nopoll_conn_send_common, length, len); expect_value(__nopoll_conn_send_common, length, len);
@@ -320,11 +260,12 @@ void err_sendMessageConnNull()
{ {
int len = strlen("Hello Parodus!"); int len = strlen("Hello Parodus!");
expect_value(nopoll_conn_is_ok, (intptr_t)conn, (intptr_t)NULL); get_parodus_cfg()->cloud_status = CLOUD_STATUS_ONLINE;
will_return(nopoll_conn_is_ok, nopoll_false);
expect_function_call(nopoll_conn_is_ok);
expect_function_call(getCurrentTime); expect_value(__nopoll_conn_send_common, (intptr_t)conn, NULL);
expect_value(__nopoll_conn_send_common, length, len);
will_return(__nopoll_conn_send_common, len);
expect_function_calls(__nopoll_conn_send_common, 1);
sendMessage(NULL, "Hello Parodus!", len); sendMessage(NULL, "Hello Parodus!", len);
} }
@@ -349,7 +290,7 @@ int main(void)
cmocka_unit_test(err_sendResponseFlushWrites), cmocka_unit_test(err_sendResponseFlushWrites),
cmocka_unit_test(err_sendResponseConnNull), cmocka_unit_test(err_sendResponseConnNull),
cmocka_unit_test(test_sendMessage), cmocka_unit_test(test_sendMessage),
cmocka_unit_test(connStuck_sendMessage), cmocka_unit_test(test_sendMessageOffline),
cmocka_unit_test(err_sendMessage), cmocka_unit_test(err_sendMessage),
cmocka_unit_test(err_sendMessageConnNull), cmocka_unit_test(err_sendMessageConnNull),
cmocka_unit_test(test_reportLog), cmocka_unit_test(test_reportLog),

View File

@@ -32,6 +32,7 @@ static void *client_rcv_task();
static void *keep_alive_thread(); static void *keep_alive_thread();
static void add_client(); static void add_client();
int sock1; int sock1;
int numLoops;
pthread_t threadId; pthread_t threadId;
pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER; pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER;

View File

@@ -160,6 +160,7 @@ extern unsigned int get_algo_mask (const char *algo_str);
pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER; pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER;
int numLoops;
pthread_cond_t *get_global_crud_con(void) pthread_cond_t *get_global_crud_con(void)
{ {

View File

@@ -26,12 +26,12 @@
#include <pthread.h> #include <pthread.h>
#include "../src/token.h" #include "../src/token.h"
int numLoops;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Mocks */ /* Mocks */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t crud_mut=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER; pthread_cond_t crud_con=PTHREAD_COND_INITIALIZER;

View File

@@ -44,10 +44,12 @@ extern size_t metaPackSize;
extern UpStreamMsg *UpStreamMsgQ; extern UpStreamMsg *UpStreamMsgQ;
int numLoops = 1; int numLoops = 1;
int deviceIDNull =0; int deviceIDNull =0;
char webpa_interface[64]={'\0'};
wrp_msg_t *temp = NULL; wrp_msg_t *temp = NULL;
extern pthread_mutex_t nano_mut; extern pthread_mutex_t nano_mut;
extern pthread_cond_t nano_con; extern pthread_cond_t nano_con;
static int crud_test = 0; static int crud_test = 0;
pthread_mutex_t config_mut=PTHREAD_MUTEX_INITIALIZER;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Mocks */ /* Mocks */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -116,6 +118,27 @@ ParodusCfg *get_parodus_cfg(void)
return &parodusCfg; return &parodusCfg;
} }
char *getWebpaInterface(void)
{
ParodusCfg cfg;
memset(&cfg,0,sizeof(cfg));
#ifdef WAN_FAILOVER_SUPPORTED
parStrncpy(cfg.webpa_interface_used , "wl0", sizeof(cfg.webpa_interface_used));
#else
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
#endif
set_parodus_cfg(&cfg);
#ifdef WAN_FAILOVER_SUPPORTED
ParodusPrint("WAN_FAILOVER_SUPPORTED mode \n");
pthread_mutex_lock (&config_mut);
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
pthread_mutex_unlock (&config_mut);
#else
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
#endif
return webpa_interface;
}
ssize_t wrp_pack_metadata( const data_t *packData, void **data ) ssize_t wrp_pack_metadata( const data_t *packData, void **data )
{ {
(void) packData; (void) data; (void) packData; (void) data;

View File

@@ -46,10 +46,11 @@ extern size_t metaPackSize;
extern UpStreamMsg *UpStreamMsgQ; extern UpStreamMsg *UpStreamMsgQ;
int numLoops = 1; int numLoops = 1;
int deviceIDNull =0; int deviceIDNull =0;
char webpa_interface[64]={'\0'};
wrp_msg_t *reg_msg = NULL; wrp_msg_t *reg_msg = NULL;
extern pthread_mutex_t nano_mut; extern pthread_mutex_t nano_mut;
extern pthread_cond_t nano_con; extern pthread_cond_t nano_con;
pthread_mutex_t config_mut=PTHREAD_MUTEX_INITIALIZER;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* Mocks */ /* Mocks */
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
@@ -101,6 +102,27 @@ ParodusCfg *get_parodus_cfg(void)
return &parodusCfg; return &parodusCfg;
} }
char *getWebpaInterface(void)
{
ParodusCfg cfg;
memset(&cfg,0,sizeof(cfg));
#ifdef WAN_FAILOVER_SUPPORTED
parStrncpy(cfg.webpa_interface_used , "wl0", sizeof(cfg.webpa_interface_used));
#else
parStrncpy(cfg.webpa_interface_used , "eth0", sizeof(cfg.webpa_interface_used));
#endif
set_parodus_cfg(&cfg);
#ifdef WAN_FAILOVER_SUPPORTED
ParodusPrint("WAN_FAILOVER_SUPPORTED mode \n");
pthread_mutex_lock (&config_mut);
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
pthread_mutex_unlock (&config_mut);
#else
parStrncpy(webpa_interface, get_parodus_cfg()->webpa_interface_used, sizeof(webpa_interface));
#endif
return webpa_interface;
}
/*------------------------------------------- /*-------------------------------------------
int nn_connect (int s, const char *addr) int nn_connect (int s, const char *addr)
{ {