From a2d15ef6554b04ec58ac64a88a898e83f2fe959c Mon Sep 17 00:00:00 2001 From: Mandeep Shetty Date: Mon, 13 Apr 2015 14:31:43 -0700 Subject: [PATCH] Added check for stale observe notifications. When observe type is OC_REST_OBSERVE, the client should not receive stale notifications. Added clarification to usage message to occlient.cpp. Increased number of notifcations to allow more notfications and to test observe in DELETE case. Change-Id: If1c7fbcf5bcdf67f5ed813178fbe5bf9902d2e3a Signed-off-by: Mandeep Shetty Reviewed-on: https://gerrit.iotivity.org/gerrit/709 Tested-by: jenkins-iotivity Reviewed-by: Sakthivel Samidurai Reviewed-by: Erich Keane --- .../samples/linux/SimpleClientServer/occlient.cpp | 7 ++++--- resource/csdk/stack/src/ocstack.c | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index 4b78752..ec5f88b 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -86,7 +86,8 @@ static void PrintUsage() OC_LOG(INFO, TAG, "-t 8 : Discover Resources and Initiate Confirmable Get Request"); OC_LOG(INFO, TAG, "-t 9 : Discover Resources and Initiate Confirmable Post Request"); OC_LOG(INFO, TAG, "-t 10 : Discover Resources and Initiate Confirmable Delete Requests"); - OC_LOG(INFO, TAG, "-t 11 : Discover Resources and Initiate Confirmable Observe Requests"); + OC_LOG(INFO, TAG, "-t 11 : Discover Resources and Initiate Confirmable Observe Requests"\ + " and cancel with Low QoS"); #ifdef WITH_PRESENCE OC_LOG(INFO, TAG, "-t 12 : Discover Resources and Initiate Nonconfirmable presence"); @@ -97,7 +98,7 @@ static void PrintUsage() #endif OC_LOG(INFO, TAG, "-t 15 : Discover Resources and Initiate Nonconfirmable Observe Requests "\ - "then cancel immediately"); + "then cancel immediately with High QOS"); OC_LOG(INFO, TAG, "-t 16 : Discover Resources and Initiate Nonconfirmable Get Request and "\ "add vendor specific header options"); OC_LOG(INFO, TAG, "-t 17 : Discover Devices"); @@ -255,7 +256,7 @@ OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse OC_LOG_V(INFO, TAG, "JSON = %s =============> Obs Response", clientResponse->resJSONPayload); gNumObserveNotifies++; - if (gNumObserveNotifies == 3) //large number to test observing in DELETE case. + if (gNumObserveNotifies == 15) //large number to test observing in DELETE case. { if(TEST_CASE == TEST_OBS_REQ_NON || TEST_CASE == TEST_OBS_REQ_CON) { diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 15c48ac..08cd487 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -1143,10 +1143,25 @@ void HandleCAResponses(const CARemoteEndpoint_t* endPoint, const CAResponseInfo_ &(responseInfo->info.options[i]), sizeof(OCHeaderOption)); } } - if (cbNode->callBack(cbNode->context, - cbNode->handle, &response) == OC_STACK_DELETE_TRANSACTION) + + if (cbNode->method == OC_REST_OBSERVE && + response.sequenceNumber > OC_OFFSET_SEQUENCE_NUMBER && + response.sequenceNumber <= cbNode->sequenceNumber) + { + OC_LOG_V(INFO, TAG, PCF("Received stale notification. Number :%d"), + response.sequenceNumber); + } + else { - FindAndDeleteClientCB(cbNode); + OCStackApplicationResult appFeedback = cbNode->callBack(cbNode->context, + cbNode->handle, + &response); + cbNode->sequenceNumber = response.sequenceNumber; + + if (appFeedback == OC_STACK_DELETE_TRANSACTION) + { + FindAndDeleteClientCB(cbNode); + } } //Need to send ACK when the response is CON -- 2.7.4