Added check for stale observe notifications.
authorMandeep Shetty <mandeep.shetty@intel.com>
Mon, 13 Apr 2015 21:31:43 +0000 (14:31 -0700)
committerErich Keane <erich.keane@intel.com>
Tue, 14 Apr 2015 16:44:13 +0000 (16:44 +0000)
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 <mandeep.shetty@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/709
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/src/ocstack.c

index 4b78752a8311c4a411c161a864cc7fee753990a3..ec5f88bcaee583e4e75aa44ee77ebb9bb6a99ed1 100644 (file)
@@ -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)
             {
index 15c48acb22dc96cb5a34063a0cf67267085087e6..08cd48763c3d86c4ee37f230fcb96ab48b8cc73a 100644 (file)
@@ -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