From 3822d64d80118da6355d71c03b9a13087c7d1aef Mon Sep 17 00:00:00 2001 From: "jihwan.seo" Date: Mon, 28 Nov 2016 15:04:52 +0900 Subject: [PATCH] modified print log method in CA layer. to make sure of analyze transmission state, all messages related important code point is printed same log method. - print CoAP message. - print send result. - print adapter state callback. Change-Id: Iccd8c8e9351165c7a6feb477e62b3b8814af0955 Signed-off-by: jihwan.seo Reviewed-on: https://gerrit.iotivity.org/gerrit/14829 Tested-by: jenkins-iotivity Reviewed-by: Jaehong Jo Reviewed-by: Dan Mihai Reviewed-by: Ashok Babu Channa --- resource/csdk/connectivity/api/cacommon.h | 5 + resource/csdk/connectivity/inc/caadapterutils.h | 28 ++++ resource/csdk/connectivity/inc/camessagehandler.h | 7 - .../connectivity/src/adapter_util/caadapterutils.c | 62 ++++++++ resource/csdk/connectivity/src/camessagehandler.c | 174 +++++++++++++++++---- .../csdk/connectivity/src/ip_adapter/caipserver.c | 4 + .../src/ip_adapter/linux/caipnwmonitor.c | 1 + .../connectivity/src/tcp_adapter/catcpserver.c | 6 + 8 files changed, 250 insertions(+), 37 deletions(-) diff --git a/resource/csdk/connectivity/api/cacommon.h b/resource/csdk/connectivity/api/cacommon.h index 81d116a..e66e001 100644 --- a/resource/csdk/connectivity/api/cacommon.h +++ b/resource/csdk/connectivity/api/cacommon.h @@ -55,6 +55,11 @@ extern "C" #endif /** + * TAG of Analyzer log. + */ +#define ANALYZER_TAG "Analyzer" + +/** * IP address Length. */ #define CA_IPADDR_SIZE 16 diff --git a/resource/csdk/connectivity/inc/caadapterutils.h b/resource/csdk/connectivity/inc/caadapterutils.h index 1f2d113..ffbaa56 100644 --- a/resource/csdk/connectivity/inc/caadapterutils.h +++ b/resource/csdk/connectivity/inc/caadapterutils.h @@ -284,6 +284,34 @@ void CADeleteGlobalReferences(); #endif +#ifndef WITH_ARDUINO +/** + * print send state in the adapter. + * @param[in] adapter transport adapter type. + * @param[in] addr remote address. + * @param[in] port port. + * @param[in] sentLen sent data length. + * @param[in] isSuccess sent state. + * @param[in] message detailed message. + */ +void CALogSendStateInfo(CATransportAdapter_t adapter, + const char *addr, uint16_t port, ssize_t sentLen, + bool isSuccess, const char* message); + +/** + * print adapter state in the adapter. + * @param[in] adapter transport adapter type. + * @param[in] state adapter state. + */ +void CALogAdapterStateInfo(CATransportAdapter_t adapter, CANetworkStatus_t state); + +/** + * print adapter type name in the adapter. + * @param[in] adapter transport adapter type. + */ +void CALogAdapterTypeInfo(CATransportAdapter_t adapter); +#endif + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/resource/csdk/connectivity/inc/camessagehandler.h b/resource/csdk/connectivity/inc/camessagehandler.h index 5596039..cdd0e8d 100644 --- a/resource/csdk/connectivity/inc/camessagehandler.h +++ b/resource/csdk/connectivity/inc/camessagehandler.h @@ -96,13 +96,6 @@ void CAHandleRequestResponseCallbacks(); */ void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler); -/** - * To log the PDU data. - * @param[in] pdu pdu data. - * @param[in] endpoint endpoint - */ -void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint); - #ifdef WITH_BWT /** * Add the data to the send queue thread. diff --git a/resource/csdk/connectivity/src/adapter_util/caadapterutils.c b/resource/csdk/connectivity/src/adapter_util/caadapterutils.c index 8355886..f4ee9c5 100644 --- a/resource/csdk/connectivity/src/adapter_util/caadapterutils.c +++ b/resource/csdk/connectivity/src/adapter_util/caadapterutils.c @@ -326,3 +326,65 @@ void CADeleteGlobalReferences(JNIEnv *env) } } #endif + +#ifndef WITH_ARDUINO +void CALogAdapterStateInfo(CATransportAdapter_t adapter, CANetworkStatus_t state) +{ + OIC_LOG(DEBUG, CA_ADAPTER_UTILS_TAG, "CALogAdapterStateInfo"); + OIC_LOG(DEBUG, ANALYZER_TAG, "================================================="); + CALogAdapterTypeInfo(adapter); + if (CA_INTERFACE_UP == state) + { + OIC_LOG(DEBUG, ANALYZER_TAG, "adapter status is changed to CA_INTERFACE_UP"); + } + else + { + OIC_LOG(DEBUG, ANALYZER_TAG, "adapter status is changed to CA_INTERFACE_DOWN"); + } + OIC_LOG(DEBUG, ANALYZER_TAG, "================================================="); +} + +void CALogSendStateInfo(CATransportAdapter_t adapter, + const char *addr, uint16_t port, ssize_t sentLen, + bool isSuccess, const char* message) +{ + OIC_LOG(DEBUG, CA_ADAPTER_UTILS_TAG, "CALogSendStateInfo"); + OIC_LOG(DEBUG, ANALYZER_TAG, "================================================="); + + if (true == isSuccess) + { + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Send Success, sent length = [%d]", sentLen); + } + else + { + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Send Failure, error message = [%s]", + message != NULL ? message : "no message"); + } + + CALogAdapterTypeInfo(adapter); + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Address = [%s]:[%d]", addr, port); + OIC_LOG(DEBUG, ANALYZER_TAG, "================================================="); +} + +void CALogAdapterTypeInfo(CATransportAdapter_t adapter) +{ + switch(adapter) + { + case CA_ADAPTER_IP: + OIC_LOG(DEBUG, ANALYZER_TAG, "Transport Type = [OC_ADAPTER_IP]"); + break; + case CA_ADAPTER_TCP: + OIC_LOG(DEBUG, ANALYZER_TAG, "Transport Type = [OC_ADAPTER_TCP]"); + break; + case CA_ADAPTER_GATT_BTLE: + OIC_LOG(DEBUG, ANALYZER_TAG, "Transport Type = [OC_ADAPTER_GATT_BTLE]"); + break; + case CA_ADAPTER_RFCOMM_BTEDR: + OIC_LOG(DEBUG, ANALYZER_TAG, "Transport Type = [OC_ADAPTER_RFCOMM_BTEDR]"); + break; + default: + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Transport Type = [%d]", adapter); + break; + } +} +#endif diff --git a/resource/csdk/connectivity/src/camessagehandler.c b/resource/csdk/connectivity/src/camessagehandler.c index d713075..847b96f 100644 --- a/resource/csdk/connectivity/src/camessagehandler.c +++ b/resource/csdk/connectivity/src/camessagehandler.c @@ -90,6 +90,13 @@ static void CALogPayloadInfo(CAInfo_t *info); static bool CADropSecondMessage(CAHistory_t *history, const CAEndpoint_t *endpoint, uint16_t id, CAToken_t token, uint8_t tokenLength); +/** + * print send / receive message of CoAP. + * @param[in] data CA information which has send/receive message and endpoint. + * @param[in] pdu CoAP pdu low data. + */ +static void CALogPDUInfo(const CAData_t *data, const coap_pdu_t *pdu); + #ifdef WITH_BWT void CAAddDataToSendThread(CAData_t *data) { @@ -467,7 +474,7 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data) } #endif // WITH_BWT - CALogPDUInfo(pdu, data->remoteEndpoint); + CALogPDUInfo(data, pdu); res = CASendMulticastData(data->remoteEndpoint, pdu->transport_hdr, pdu->length, data->dataType); if (CA_STATUS_OK != res) @@ -564,7 +571,7 @@ static CAResult_t CAProcessSendData(const CAData_t *data) } } #endif // WITH_BWT - CALogPDUInfo(pdu, data->remoteEndpoint); + CALogPDUInfo(data, pdu); OIC_LOG_V(INFO, TAG, "CASendUnicastData type : %d", data->dataType); res = CASendUnicastData(data->remoteEndpoint, pdu->transport_hdr, pdu->length, data->dataType); @@ -730,9 +737,6 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, VERIFY_NON_NULL_VOID(sep, TAG, "remoteEndpoint"); VERIFY_NON_NULL_VOID(data, TAG, "data"); - OIC_LOG(DEBUG, TAG, "received pdu data :"); - OIC_LOG_BUFFER(DEBUG, TAG, data, dataLen); - uint32_t code = CA_NOT_FOUND; CAData_t *cadata = NULL; @@ -741,7 +745,7 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, if (NULL == pdu) { OIC_LOG(ERROR, TAG, "Parse PDU failed"); - return; + goto exit; } OIC_LOG_V(DEBUG, TAG, "code = %d", code); @@ -752,7 +756,7 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, { OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, CAGenerateHandlerData failed!"); coap_delete_pdu(pdu); - return; + goto exit; } } else @@ -762,7 +766,7 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, { OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, CAGenerateHandlerData failed!"); coap_delete_pdu(pdu); - return; + goto exit; } #ifdef WITH_TCP @@ -800,6 +804,8 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, cadata->type = SEND_TYPE_UNICAST; + CALogPDUInfo(cadata, pdu); + #ifdef SINGLE_THREAD CAProcessReceivedData(cadata); #else @@ -825,6 +831,10 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep, #endif // SINGLE_THREAD coap_delete_pdu(pdu); + +exit: + OIC_LOG(DEBUG, TAG, "received pdu data :"); + OIC_LOG_BUFFER(DEBUG, TAG, data, dataLen); } void CAHandleRequestResponseCallbacks() @@ -1219,28 +1229,6 @@ void CATerminateMessageHandler() #endif // SINGLE_THREAD } -void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint) -{ - VERIFY_NON_NULL_VOID(pdu, TAG, "pdu"); - VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint"); - -#ifdef WITH_BWT - if (CAIsSupportedBlockwiseTransfer(endpoint->adapter)) - { - OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->transport_hdr->udp.type); - - OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->transport_hdr->udp.code); - } -#endif - - OIC_LOG(DEBUG, TAG, "PDU Maker - token :"); - OIC_LOG_BUFFER(DEBUG, TAG, pdu->transport_hdr->udp.token, - pdu->transport_hdr->udp.token_length); - - OIC_LOG(DEBUG, TAG, "PDU Maker - payload :"); - OIC_LOG_BUFFER(DEBUG, TAG, (const uint8_t *) pdu->transport_hdr, pdu->length); -} - static void CALogPayloadInfo(CAInfo_t *info) { if (info) @@ -1360,3 +1348,129 @@ static void CASendErrorInfo(const CAEndpoint_t *endpoint, const CAInfo_t *info, #endif OIC_LOG(DEBUG, TAG, "CASendErrorInfo OUT"); } + +#ifndef ARDUINO +static void CALogPDUInfo(const CAData_t *data, const coap_pdu_t *pdu) +{ + OIC_LOG(DEBUG, TAG, "CALogPDUInfo"); + + VERIFY_NON_NULL_VOID(data, TAG, "data"); + VERIFY_NON_NULL_VOID(pdu, TAG, "pdu"); + + OIC_LOG(DEBUG, ANALYZER_TAG, "================================================="); + if(SEND_TYPE_MULTICAST == data->type) + { + OIC_LOG(DEBUG, ANALYZER_TAG, "Is Multicast = true"); + } + else + { + OIC_LOG(DEBUG, ANALYZER_TAG, "Is Multicast = false"); + } + + if (NULL != data->remoteEndpoint) + { + CALogAdapterTypeInfo(data->remoteEndpoint->adapter); + OIC_LOG(DEBUG, ANALYZER_TAG, "-------------------------------------------------"); + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Address = [%s]:[%d]", data->remoteEndpoint->addr, + data->remoteEndpoint->port); + OIC_LOG(DEBUG, ANALYZER_TAG, "-------------------------------------------------"); + } + + switch(data->dataType) + { + case CA_REQUEST_DATA: + OIC_LOG(DEBUG, ANALYZER_TAG, "Data Type = [CA_REQUEST_DATA]"); + break; + case CA_RESPONSE_DATA: + OIC_LOG(DEBUG, ANALYZER_TAG, "Data Type = [CA_RESPONSE_DATA]"); + break; + case CA_ERROR_DATA: + OIC_LOG(DEBUG, ANALYZER_TAG, "Data Type = [CA_ERROR_DATA]"); + break; + case CA_RESPONSE_FOR_RES: + OIC_LOG(DEBUG, ANALYZER_TAG, "Data Type = [CA_RESPONSE_FOR_RES]"); + break; + default: + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Data Type = [%d]", data->dataType); + break; + } + OIC_LOG(DEBUG, ANALYZER_TAG, "-------------------------------------------------"); + + const CAInfo_t *info = NULL; + if (NULL != data->requestInfo) + { + switch(data->requestInfo->method) + { + case CA_GET: + OIC_LOG(DEBUG, ANALYZER_TAG, "Method = [GET]"); + break; + case CA_POST: + OIC_LOG(DEBUG, ANALYZER_TAG, "Method = [POST]"); + break; + case CA_PUT: + OIC_LOG(DEBUG, ANALYZER_TAG, "Method = [PUT]"); + break; + case CA_DELETE: + OIC_LOG(DEBUG, ANALYZER_TAG, "Method = [DELETE]"); + break; + default: + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Method = [%d]", data->requestInfo->method); + break; + } + info = &data->requestInfo->info; + } + + if (NULL != data->responseInfo) + { + OIC_LOG_V(DEBUG, ANALYZER_TAG, "result code = [%d]", data->responseInfo->result); + info = &data->responseInfo->info; + } + + if (pdu->transport_hdr) + { + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Msg ID = [%d]", pdu->transport_hdr->udp.id); + } + + if (info) + { + OIC_LOG(DEBUG, ANALYZER_TAG, "Coap Token"); + OIC_LOG_BUFFER(DEBUG, ANALYZER_TAG, (const uint8_t *) info->token, info->tokenLength); + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Res URI = [%s]", info->resourceUri); + OIC_LOG(DEBUG, ANALYZER_TAG, "-------------------------------------------------"); + + if (CA_FORMAT_APPLICATION_CBOR == info->payloadFormat) + { + OIC_LOG(DEBUG, ANALYZER_TAG, "Payload Format = [CA_FORMAT_APPLICATION_CBOR]"); + } + else + { + OIC_LOG_V(DEBUG, ANALYZER_TAG, "Payload Format = [%d]", info->payloadFormat); + } + + OIC_LOG_V(DEBUG, ANALYZER_TAG, "CoAP Message Full Size = [%d]", pdu->length); + OIC_LOG(DEBUG, ANALYZER_TAG, "CoAP Header (+ 0xFF)"); + OIC_LOG_BUFFER(DEBUG, ANALYZER_TAG, (const uint8_t *) pdu->transport_hdr, + pdu->length - info->payloadSize); + OIC_LOG_V(DEBUG, ANALYZER_TAG, "CoAP Header size = [%d]", pdu->length - info->payloadSize); + + OIC_LOG_V(DEBUG, ANALYZER_TAG, "CoAP Payload"); + OIC_LOG_BUFFER(DEBUG, ANALYZER_TAG, info->payload, info->payloadSize); + OIC_LOG_V(DEBUG, ANALYZER_TAG, "CoAP Payload Size = [%d]", info->payloadSize); + } + + OIC_LOG(DEBUG, ANALYZER_TAG, "================================================="); +} +#else +static void CALogPDUInfo(const CAData_t *data, const coap_pdu_t *pdu) +{ + VERIFY_NON_NULL_VOID(pdu, TAG, "pdu"); + (void)data; + + OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data); + OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->transport_hdr->udp.type); + OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->transport_hdr->udp.code); + OIC_LOG(DEBUG, TAG, "PDU Maker - token :"); + OIC_LOG_BUFFER(DEBUG, TAG, pdu->transport_hdr->udp.token, + pdu->transport_hdr->udp.token_length); +} +#endif diff --git a/resource/csdk/connectivity/src/ip_adapter/caipserver.c b/resource/csdk/connectivity/src/ip_adapter/caipserver.c index 200de59..5c2b06e 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipserver.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipserver.c @@ -1317,10 +1317,14 @@ static void sendData(int fd, const CAEndpoint_t *endpoint, g_ipErrorHandler(endpoint, data, dlen, CA_SEND_FAILED); } OIC_LOG_V(ERROR, TAG, "%s%s %s sendTo failed: %s", secure, cast, fam, strerror(errno)); + CALogSendStateInfo(endpoint->adapter, endpoint->addr, endpoint->port, + len, false, strerror(errno)); } else { OIC_LOG_V(INFO, TAG, "%s%s %s sendTo is successful: %zd bytes", secure, cast, fam, len); + CALogSendStateInfo(endpoint->adapter, endpoint->addr, endpoint->port, + len, true, NULL); } #else int err = 0; diff --git a/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c b/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c index 1d8d631..c64b6a0 100644 --- a/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c +++ b/resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c @@ -238,6 +238,7 @@ static void CAIPPassNetworkChangesToAdapter(CANetworkStatus_t status) if (cbitem && cbitem->adapter) { cbitem->callback(cbitem->adapter, status); + CALogAdapterStateInfo(cbitem->adapter, status); } } } diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c index 329a4cd..e0793a9 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c @@ -891,6 +891,8 @@ static int CATCPCreateSocket(int family, CATCPSessionInfo_t *svritem) if (connect(fd, (struct sockaddr *)&sa, socklen) < 0) { OIC_LOG_V(ERROR, TAG, "failed to connect socket, %s", strerror(errno)); + CALogSendStateInfo(svritem->sep.endpoint.adapter, svritem->sep.endpoint.addr, + svritem->sep.endpoint.port, 0, false, strerror(errno)); close(fd); return -1; } @@ -1213,6 +1215,8 @@ static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data, if (EWOULDBLOCK != errno) { OIC_LOG_V(ERROR, TAG, "unicast ipv4tcp sendTo failed: %s", strerror(errno)); + CALogSendStateInfo(endpoint->adapter, endpoint->addr, endpoint->port, + len, false, strerror(errno)); return len; } continue; @@ -1225,6 +1229,8 @@ static ssize_t sendData(const CAEndpoint_t *endpoint, const void *data, (void)fam; #endif OIC_LOG_V(INFO, TAG, "unicast %stcp sendTo is successful: %zu bytes", fam, dlen); + CALogSendStateInfo(endpoint->adapter, endpoint->addr, endpoint->port, + dlen, true, NULL); return dlen; } -- 2.7.4