MLopezJ / LwM2M-device-simulator

A LwM2M Client to perform operations on a LwM2M Server
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Send Operation #6

Open MLopezJ opened 1 year ago

MLopezJ commented 1 year ago

It is desired to implement the Send Operation from Dev Mang & Serv Enab in the Device Simulator. The request must be accepted for the LwM2M Server (Coiote in this case).

MLopezJ commented 1 year ago

Analyzing Send Operation

I think I am using the proper requirements to execute the "send" operation request, but when I perform the operation, it does not affect the server. I am not sure if the request was received by the server or ignored because it had a mistake.

However, when the action is performed by Anjay (LwM2M client from AVSystem) or a Thingy:91, it works.

How to check that the request I am sending is equal to the request sent by Thingy:91?

Actors

  1. Anjay (LwM2M Client)
  2. Thingy 91 (LwM2M Client)
  3. Device Simulator (LwM2M Client)
  4. Coiote (LwM2M Server)

Interfaces

  1. Send Operation from LwM2M
  2. Senml+cbor

Tools

  1. WireShark

Options

Option 1

Trace the request with WireShark and observe the payload sent.

I tried this Tuesday 11 July (check week # 28 for more details), but "I was not able to ‘translate’ the payload". It was because the payload was in CBOR format and it printed with some ASCII codes which makes it difficult to transform back to text. It is also because of my lack of knowledge of WireShark. Stig could help me with this but he is on vacation until August 21.

I also told this to AVSystems 12 of July through the help center:

Trace from Anjay request

I used WireShark to inspect the send request from Anjay. However, because of lack of knowledge about the tool, I am not able to translate the payload properly from cbor to human redable text. Can you help me with that? I would like to know how the payload looks, just to confirm I am setting it correctly here: https://github.com/MLopezJ/minimalist-lwm2m-client/blob/saga/src/send.ts#L61

** help center: https://helpcenter.avsystem.com/plugins/servlet/desk/portal/17/CDM-410

but no answer received since then.

Option 2

Use the same payload as the one in the LwM2M documentation.

** This option does not answer the question formulated.

Option 3

Map the documentation with the lines of code, this way it would be easier to understand the decisions made in the code and check if there are any misunderstood

** This option does not answer the question formulated. It only confirms that the documentation steps are followed

Option 4

Print payload from Anjay. Check the C code and print out the payload of the request.

Option 5

Create a node.js LwM2M server and send a "send" request with Anjay to this server to check how the request is received. Then, send the "send" request using the device simulator and check for the differences.

Option 6

Trace the "send" request from the Device Simulator with WireShark and compare it with the request from Thingy 91 and Anjay.

Option 7

Test send operation request to have the confidence that it is as the documentation establishes.

MLopezJ commented 1 year ago

Execution

The option number 6 is going to be executed first. It is desired to see the differences between requests.

Then, option number 7 is going to be implemented. It is desired to use the outside-in approach of TDD in order to have confidence that the documentation is followed in the code. The device simulator relies on node-coap and another lib is used for the cbor transformation. It is not tested. The goal of this step is to have the confidence that the implementation is correct.

Option number 1 would be ideal but there is a blocker related to not being able to translate the payload

MLopezJ commented 1 year ago

A minimalist version of the device simulator is going to be used as the LwM2M Client in the tests. This is because the minimalist version contains aspects only related to the standard, excluding logic that is not necessary to check if the LwM2M operation is executed correctly.

Minimalist LwM2M Client

MLopezJ commented 1 year ago

Trace "Send" operation with different clients

It is desired to trace the operation with the following clients: Thingy:91 and Device Simulator. However, there is an already existing trace for Anjay, which is another client from AVSystems.

Set up Thingy:91 in a new environment will take some time and with anjay is possible to examine how a request accepted by Coiote looks like. Because of those 2 reasons;

  1. save time by no need to set up an environment from scratch
  2. Check struct of a request accepted by Coiote

is that as first step the trace from Anjay and the trace from Minimalist device simulator are going to be compared. Having say that, is important to clarify that this do not remove the need of compare result of the traces of Thingy:91 and the minimalist device simulator.

Main objective with this is to check if there are big differences between requests structs.

Result

Both trace looks really similar. The only difference found is in the struct of the payload. Both follow senml+cbor format but the minimalist device simulator uses the object implementation and Anjay uses resource description.

Minimalist device simulator payload

Screenshot 2023-08-01 at 13 05 11
// [{ 0: '/3/0/0', 3: 'newManufacturer' }]
// name: /3/0/0, string value: newManufacturer

Anjay payload

Screenshot 2023-08-01 at 13 14 00
// [ { -2: /3303/0, 0: /5700, -3: ...., 2: 14},
//   {                       0: /5701,              3: cel}                  
// ]

// [
//  base name: /3303/0, name: /5700, base time: ..., value: 14,
//   name: /5701,       string value: cel
// ]
MLopezJ commented 1 year ago

Implementation of observation

In order with the result of last comparation, the payload from minimalist device simulator is going to be changed for the resource specification as first try.

from:

[{ 0: '/3/0/0', 3: 'newManufacturer' }]

to

[{ -2: '/3/0/' , 0: /0', -3: 1688129143.99978, 3: 'newManufacturer' }]
// ... getCborValue method
const map = new Map()
        .set(-2, '/3/0') // base name
        .set(0, '/0') // name
        .set(-3, 1688129143.99978) // base time
        .set(3, newManufacturer) // string value

If that doesnt work, the object 3303 is going to be added in the minimalist device simulator and the payload will be the same as the one in Anjay:

// [ { -2: /3303/0, 0: 5700, -3: ...., 2: 14},
//   {                0: 5701,              3: cel}                  
// ]
// ... getCborValue method
const element1 = new Map()
        .set(-2, '/3303/0') // base name
        .set(0, '/5700') // name
        .set(-3, 1688129143.99978) // base time
        .set(2, 14.0) // string value
const element2 = new Map()
    .set(0, '/5701') // name
    .set(3, 'Cel') // string value

Result

For both cases, the result was not stable. Sometimes the response is 403 (forbidden) and sometimes the request has no answer from the server (retransmissioning). Even when the answer is from error code, is the first time that there is an answer from the server for the send operation request made with a simulated device.

Comparing the trace result from the last example and Anjay, in which both payloads suppose to be the same, there is one important difference that is important to mention. It is that even when the Concise Binary Object Representation suggest the payload is the same, there is a difference of 4 bytes between the accepted request and the request from a simulated device.

Screenshot 2023-08-01 at 15 08 31

One possible reason why this is happening is because the value 14 from the update of resource 5700 is integer in the device simulator and float in Anjay. However I havent dig into it to see if that is why it is happening or not.

Screenshot 2023-08-01 at 15 11 13
MLopezJ commented 1 year ago

Ensure that the documentation is been following

MLopezJ commented 1 year ago

Payload from successful send operation was used in the device simulator, but request was not accepted.