Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » Octetstring Manipulation
Octetstring Manipulation [message #1744345] Mon, 26 September 2016 08:34 Go to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Hi All,

I would like to add values to a variable of type octetstring in a loop.

    var octetstring payload;
    for(var integer v_ct :=1; v_ct<8; v_ct:=v_ct+1 ){
        //TODO payload := '11'   and in next loop  payload := '1122'  and so on ...
}



Unfortunately I couldn't find out to do this in TTCN3, can somebody help me ?

Thanks !
Re: Octetstring Manipulation [message #1744350 is a reply to message #1744345] Mon, 26 September 2016 09:10 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Johannes,
module test
{




control{


var octetstring payload:=''O;

    for(var integer v_ct :=1; v_ct<8; v_ct:=v_ct+1 ) {
         payload := payload& hex2oct(int2hex(v_ct,1)&int2hex(v_ct,1));
        log(payload)
}

}

}



11:11:34.141011 Execution of control part in module test started.
11:11:34.141097 '11'O
11:11:34.142409 '1122'O
11:11:34.142428 '112233'O
11:11:34.142445 '11223344'O
11:11:34.142461 '1122334455'O
11:11:34.142479 '112233445566'O
11:11:34.142497 '11223344556677'O
11:11:34.142519 Execution of control part in module test finished.



BR Elemer
Re: Octetstring Manipulation [message #1744396 is a reply to message #1744350] Mon, 26 September 2016 13:17 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Thank you Elemer !
Re: Octetstring Manipulation [message #1744450 is a reply to message #1744396] Tue, 27 September 2016 07:36 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
One test case is failing for me because the expected octetstring is
payload:=''O
and the received is
payload:=omit
.
Is there really a difference between omit and a empty octetstring ? How to deal with it ?
Re: Octetstring Manipulation [message #1744454 is a reply to message #1744450] Tue, 27 September 2016 07:56 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Johannes,

yes there is; omit should be considered as a special value.

In receiving templates, you can use wildcards: '?' has the significance of any value (including the zero length value -empty string- in case of strings) and "*" represents any value or omit.

In structures, only optional fields can be given a value of omit.


I hope this makes it clearer

BR
Elemer
Re: Octetstring Manipulation [message #1744574 is a reply to message #1744454] Wed, 28 September 2016 13:23 Go to previous messageGo to next message
Gyorgy Rethy is currently offline Gyorgy RethyFriend
Messages: 31
Registered: April 2015
Member
You can also look at this from an other angle, i.e. what signal is sent over the line. For example, in a TLV encoded message payload := ''O will result the T part encoded as appropriate, the L part containing 0 and no V part; payload := omit will simply result the whole TLV construct is missing in the message. Depending of the protocol specification these two cases may have different semantic meanings (or one of them may be testing a potential vulnerability if the case is not covered by the protocol spec).
Re: Octetstring Manipulation [message #1744675 is a reply to message #1744574] Thu, 29 September 2016 12:35 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
One further question:

Is there a possibility to compare only for example 10 last bytes of a octetstring ?
template Frame frame1 (octetstring p_payload ) := {
            octetstring  payload =  '?'O &p_payload  // Some bytes are doesn't matter but the last have to be equal p_payload
}
 

[Updated on: Thu, 29 September 2016 12:48]

Report message to a moderator

Re: Octetstring Manipulation [message #1744801 is a reply to message #1744675] Fri, 30 September 2016 10:00 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Johannes,

in this context "?" denotes one element of a string , so '?'O is an octetstring of length one ( this is two hex characters , e.g. '1F'O) ;
for any length (including length zero ) , a "*" should be used, so '*'O denotes an octetstring of an arbitrary length (including ''O) .

So the correct expression would be

template Frame frame1 (octetstring p_payload ) := {
             payload :=  '*'O &p_payload  // Some bytes are doesn't matter but the last have to be equal p_payload
}



But , unfortunately concatenation of wildcards has not been implemented; we will look into it.

However, "?" and "*" can be used inside the octetstring , so
something like:

template Frame frame2  := {
              payload :=  '*1234567ABC'O 
}

or

template Frame frame3  := {
              payload :=  '*12345F??'O 
}

will be working.





Best regards

Elemer




Re: Octetstring Manipulation [message #1746397 is a reply to message #1744801] Fri, 28 October 2016 07:03 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Hi All,

first thanks for the detailed description. But I have to come back to this topic. As you already mentioned your example is only working when you type explicit the value of the octetstring. In my case I need to check partly a octetstring variable. Therefore I had a look to the TTCN standard and there is a function to create a substring of a string.
See
substr
at chapter string Manipulation at http://www.blukaktus.com/TTCN3QRC_viewme.pdf. I tried it out with titan but it seems not to be supported, isn't it ?
As approach I created my own "substr" function for octetstrings, see below. Concerning this function, I would like to know what is the best practice to create a error in case of index/counter is less than zero or index+count is creater as the length of the input octeststring:

module test {

function f_suboctstr ( in octetstring octstr, in integer index, in integer count ) return octetstring {
    var octetstring retOctstr := ''O;
    if((lengthof(octstr)>=count+index) and (index >= 0) and (index >= 0)){
        for( var integer i :=0;  i<count; i:=i+1){
            retOctstr := retOctstr& octstr[index+i];        
        }    
    }
    else{
     setverdict(fail, "Disallowed ussage of f_suboctstr");
    }
    return retOctstr;
}


control{
  var octetstring test:='AABBCC'O;
  
  test := f_suboctstr (test,1,2);
  log(test)
  
}

}

[Updated on: Fri, 28 October 2016 07:06]

Report message to a moderator

Re: Octetstring Manipulation [message #1746421 is a reply to message #1746397] Fri, 28 October 2016 13:12 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Johannes,

substr is fully supported as specified in the standard.


As for your question, I guess the best practice is to use an out parameter for the resulting octetstring
and an integer return to specify the result:

var octetstring v_res
var integer v_ret

function f_suboctstr ( in octetstring octstr, in integer index, in integer count, out octetstring p_res) 
return integer { //returns 0 if everything is OK

p_res:=...
} 

v_ret:=f_suboctstr('AABBCC'O,1,2,v_res)

v_ret=0 indicates successful execution
if v_ret == 0, v_res will store the result




Best regards
Elemer
Re: Octetstring Manipulation [message #1746438 is a reply to message #1746421] Fri, 28 October 2016 17:36 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Johannes,

could you pls send me the code where you tried substr? maybe I could figure out what went wrong.

Thanks

Elemer
Re: Octetstring Manipulation [message #1746748 is a reply to message #1744345] Fri, 04 November 2016 07:10 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Hi Elemer,

I don't have my first tries anymore. I think it was just a typo and I was to hasty with the conclusion. Sorry for raising a question for that. Finally I replaced the calls with "substr(..)" and it is working.

Concerning my question, I though there is maybe a possibility to create a TTCN_ERROR like for implementing test ports.

Regards Johannes
Re: Octetstring Manipulation [message #1746750 is a reply to message #1746748] Fri, 04 November 2016 07:56 Go to previous messageGo to next message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Hi Johannes,

the-recommended by standard -way of dealing with errors is to set the verdict to error;
substr itself will throw an error in certain situations will result in the verdict being set to error.


Best regards

Elemer







Re: Octetstring Manipulation [message #1746872 is a reply to message #1746750] Mon, 07 November 2016 07:01 Go to previous messageGo to next message
Johannes Bro is currently offline Johannes BroFriend
Messages: 56
Registered: June 2015
Member
Hi Elemer,

I tried to set it to error, just replace the line from my example above:
     setverdict(fail, "Disallowed ussage of f_suboctstr");

to
 setverdict(error)

But you can't build it, the code interpreter says: "Error verdict cannot be set by the setverdict operation"

Thanks,

Johannes


Re: Octetstring Manipulation [message #1746876 is a reply to message #1746872] Mon, 07 November 2016 08:12 Go to previous message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 1120
Registered: January 2015
Senior Member
Sorry , Johannes,

I have misled you here;

I have checked the standard and it explicitly says that:
"The setverdict operation shall only be used with the values pass, fail, inconc and none. It shall not
be used to assign the value error, this is set by the test system only to indicate runtime errors. "

so I remembered wrongly.

Technically, there is the option of writing an external function that triggers an error.
However, I would not recommend that; dynamic test case error is quite a dramatic way to end;

Situations like you mentioned can be treated nicely in the code without a recourse to error.


Best regards

Elemer








Previous Topic:CoAP Conformance example test cases in titan.misc
Next Topic:Titan Architecture internals: On why index operators in the generated code have signed parameter
Goto Forum:
  


Current Time: Thu Apr 18 03:26:47 GMT 2024

Powered by FUDForum. Page generated in 0.02629 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top