Menu

#197 Incorrect Marshalling/Unmarshalling for nested datasets

1.4.0.0
closed
None
2018-06-25
2018-04-27
No

Have a small test case wherein I am sending a simulated 'Mn' Notification message to a device(64-bit Raspberry Pi) running a test application accessing the TRDP stack (TRDP Light 1.3.3.0).
There seems to be an issue in marshalling/unmarshalling (done via inbuilt trdp marshalling functions, not user-defined) of a dataset containing nested dataset. Presenting a very simple example:

The entry in the config.xml is as follows..

<data-set name="Test_dataset2000" id="2000">        
    <element name="a_CHAR8"     type="2"/>
    <element name="b_INT32"     type="10"/>
</data-set>

<data-set name="Test_dataset2001" id="2001">
    <element name="a_CHAR8"         type="2"/>
    <element name="b_DATASET2000"   type="2000"/>
</data-set> 

The structure of dataset - 2000

typedef struct {
    CHAR8 a;
    INT32 b;
} DS2000;

The structure of dataset - 2001

typedef struct{
    CHAR8 a;
    DS2000 ds;  
} DS2001;

The device under test receives the Mn as follows:
Received Databytes (raw): (Size = 6)
[ 01 02 00 00 00 03 ]
(a = 1, ds.a = 2, ds.b = 3)

After unmarshalling:
Actual Unmarshalled Databytes (raw): (Size = 8)
[ 01 02 $$ $$ 03 00 00 00 ]

Ideally, the DS2000 being a struct inside DS2001, should be aligned on struct boundary, here 4 bytes.
Expected Unmarshalled Databytes : (Size = 12)
[ 01 $$ $$ $$ 02 $$ $$ $$ 03 00 00 00 ]

The test case is supposed to increment a, ds.a and ds.b by 1. It does that based on incorrectly placed bytes after unmarshalling.

Marshalling again before sending :
Actual Marshalled Databytes (raw): (Size = 6)
[ 02 02 00 00 00 04 ]

Expected Marshalled Databytes (raw): (Size = 6)
[ 02 03 00 00 00 04 ]

**Conclusion: Seems that TRDP aligns nested dataset based on the alignment convention of the first element of the struct and not as per complete struct alignment. **
Even though tau_marshall.c:379 does align based on STRUCT_T boundary. Will update after some more analysis of code.

Discussion

  • Bernd Löhr

    Bernd Löhr - 2018-04-27
     
  • Bernd Löhr

    Bernd Löhr - 2018-04-27

    Hi Chirag, I cannot reproduce this directly.
    Seems to depend on your target OS/compiler. What is your target? You might check the ALIGNOF makro on your compiler.
    Also you may add some more alignment tests at vos_utils.c:293. If DEBUG is defined, vos_initRuntimeConsts() checks some compiler & architecture related settings (endianess and alignment).

     
  • Siddhi Wadgaonkar

    Hello Bernd,

    Me and Chirag have this tested on 2 different targets with OS -Linux-64 bit and Windows 32-bit.

    The test2() from test_marshalling.c [r1722] works correctly in both the targets we have tested on. But if we try to modify the datasets to be exactly as per ticket #197 , it fails. ( There should be a CHAR8 or INT16 before the nested dataset. Keeping INT32 before the nested dataset indirectly removes the reproducibility of the mentioned scenario.)

    We propose a small change in the dataset gDataSet2003 for the ** test_marshalling.c:706** and request you to check if it still works correctly on your system.

    struct myDataSet2003 {
    UINT32 a;
    INT32 b; CHAR8 b;
    struct DS2 c;
    } gMyDataSet2003 =
    {
    0x12345678, -1, {0,0,0}
    };

     

    Related

    Commit: [r1722]

  • Bernd Löhr

    Bernd Löhr - 2018-05-17
    • status: open --> pending
    • assigned_to: Bernd Löhr
     
  • Bernd Löhr

    Bernd Löhr - 2018-05-17

    Finally, because alignment of structs was fixed on first instead of largest member, marshalling would not work correctly on nested datasets without natural alignment.
    Now we analyse each dataset before proceeding with marshalling/demarshalling...

     
  • Bernd Löhr

    Bernd Löhr - 2018-06-25
    • Status: pending --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB