Hi Dojo,
I noticed an interesting behavior in DataMiner's byte unstuffing that caught my attention. Consider the following action:
<Action id="4">
<Name>Response Unstuffing</Name>
<On>response</On>
<Type options="0x10ef-0x10fd-0x10fc;0x10-0x02-0x03" startoffset="1" endoffset="1">replace data</Type>
</Action>
Example raw device response:
02 30 0E 00 D1 10 EF FD 03
After unstuffing, the protocol produces:
02 30 0E 00 D1 02 03
Even though the original response contained 10 EF FD, the sequential greedy replacement turns it into just 02.
Step-by-step explanation:
-
The protocol scans the stream and finds
10 EF. It replaces it with10.-
Stream becomes:
... <strong>D1 10 FD 03</strong>
-
-
Next, it finds
10 FDin the remaining stream and replaces it with02.-
Stream becomes:
... <strong>D1 02 03</strong>
-
-
No more matches are found, so unstuffing ends.
-
Final unstuffed stream:
... <strong>D1 02 03</strong>
-
The protocol processes the buffer sequentially and greedily, which is why 10 EF FD becomes 02.
I am curious why the protocol was designed to apply replacements sequentially over the entire response instead of treating the original response sequence as a single unit. Also, is there a scenario where reordering the replacements to prevent this behavior is not possible, and could that potentially cause issues with some responses?
Hi,
Indeed, the logic is done sequentially:
-First the response data is iterated to replace 0x10ef with 0x10
-Then that modified result is iterated to replace 0x10fd with 0x02
-Lastly that second modified result is iterated to replace 0x10fc with 0x03
This means if you have 0x10effd that it will be replaced with 0x02 instead of 0x1002.
As the 0x10 is the 'special' indicator byte, the advice would be to change the order in the options to only replace the 0x10fd as last: options="0x10fd-0x10fc-0x10ef;0x02-0x03-0x10"
I do not know the reason why it was implemented sequentially. This logic was introduced in DataMiner version 2.5.0.1 in 2003, which is already more than two decades ago.
Regards,