modified print log method in CA layer.
authorjihwan.seo <jihwan.seo@samsung.com>
Mon, 28 Nov 2016 06:04:52 +0000 (15:04 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Mon, 5 Dec 2016 07:10:14 +0000 (07:10 +0000)
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 <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14829
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/api/cacommon.h
resource/csdk/connectivity/inc/caadapterutils.h
resource/csdk/connectivity/inc/camessagehandler.h
resource/csdk/connectivity/src/adapter_util/caadapterutils.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/ip_adapter/linux/caipnwmonitor.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c

index 81d116a..e66e001 100644 (file)
@@ -55,6 +55,11 @@ extern "C"
 #endif
 
 /**
+ * TAG of Analyzer log.
+ */
+#define ANALYZER_TAG "Analyzer"
+
+/**
  * IP address Length.
  */
 #define CA_IPADDR_SIZE 16
index 1f2d113..ffbaa56 100644 (file)
@@ -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
index 5596039..cdd0e8d 100644 (file)
@@ -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.
index 8355886..f4ee9c5 100644 (file)
@@ -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
index d713075..847b96f 100644 (file)
@@ -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
index 200de59..5c2b06e 100644 (file)
@@ -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;
index 1d8d631..c64b6a0 100644 (file)
@@ -238,6 +238,7 @@ static void CAIPPassNetworkChangesToAdapter(CANetworkStatus_t status)
         if (cbitem && cbitem->adapter)
         {
             cbitem->callback(cbitem->adapter, status);
+            CALogAdapterStateInfo(cbitem->adapter, status);
         }
     }
 }
index 329a4cd..e0793a9 100644 (file)
@@ -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;
 }