Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » 'ifpresent' or ternary operator in parametric send templates
'ifpresent' or ternary operator in parametric send templates [message #1781028] Wed, 31 January 2018 16:26 Go to next message
Harald Welte is currently offline Harald WelteFriend
Messages: 47
Registered: July 2017
Location: Berlin, Germany
Member

I'm often running into use cases where I have TLV type structures in protocols.

Now if I want to have a parametric template that can be used for encoding a message both with and without the TLV, I end up with something like this:

//24.008/ 10.5.1.7
type record MobileStationClassmark3_TLV
{
  OCT1  elementIdentifier,
  LIN1  lengthIndicator,
  OCTN  valuePart
} with {
  variant "PRESENCE (elementIdentifier = '20'O)"
  variant (lengthIndicator) "LENGTHTO (valuePart)"
};


template PDU_ML3_MS_NW ts_RRM_CM_CHG(MobileStationClassmark2_LV cm2,
                                             template MobileStationClassmark3_TLV cm3 := omit) := {
        discriminator := '0110'B,
        tiOrSkip := {
                skipIndicator := '0000'B
        },
        msgs := {
                rrm := {
                        classmarkChange := {
                                messageType := '00010110'B,
                                mobileStationClassmark2 := cm2,
                                mobileStationClassmark3 := cm3
                }
        }
}


This way I can use the template to send a message with CM2 only, or one that also has CM3. fine.

However, from a usability point of view it is "ugly" because it's not user friendly. What the user actually wants to specify is the MobileStationClassmark3_TLV.valuePArt, and not the "TLV wrapper", so the template should look like this:

template MobileStationClassmark3_TLV ts_CM3_TLV(OCTN cm3) := {
        elementIdentifier := '20'O,
        lengthIndicator := 0, /* overwritten */
        valuePart := cm3
}

template PDU_ML3_MS_NW ts_RRM_CM_CHG(MobileStationClassmark2_LV cm2, template OCTN cm3 := omit) := {
       discriminator := '0110'B,
        tiOrSkip := {
                skipIndicator := '0000'B
        },
        msgs := {
                rrm := {
                        classmarkChange := {
                                messageType := '00010110'B,
                                mobileStationClassmark2 := cm2,
                                mobileStationClassmark3 := ts_CM3_TLV(cm3),
                }
        }
}


but now the problem is, that the ts_CM3_TLV() will always return a MobileStationClassmark3_TLV - whether or not the input argument 'cm3' is 'omit' or whether it's an actual value.

So basically, I would like to create templates which return omit if their argument/parameter is omit.

In C, one would be able to use this with the ternary operator in a syntax like "mobileStationClassmark3 = cm3 ? ts_CM3_TLV(cm3) : NULL" and I would love if something like that existed in TTCN3. However, it apparently doesn't.

On the matching / receiving side, I've seen the "ifpresent" qualifier which is very useful in simiar cases. However, for the transmit / send template site I haven't found any solution. Please let me know if I simply haven't studied the language spec sufficiently, or if it really doesn't exist. To me, it's one of the most common patterns in generating send/generate/transmit messages in protocol testing.

One workaround seems to be to define a function which returns a template, and then in that function one can of course use conditional expressions like:

function ts_RRM_CM_CHG(MobileStationClassmark2_LV cm2, template MobileStationClassmark3_TLV cm3 := omit) return template PDU_ML3_MS_NW {
        var template PDU_ML3_MS_NW ret;
        if (not ispresent(cm3)) {
                return omit;
        }
        ret := {
             discriminator := '0110'B,
             tiOrSkip := {
                    skipIndicator := '0000'B
            },
            msgs := {
                    rrm := {
                            classmarkChange := {
                                    messageType := '00010110'B,
                                    mobileStationClassmark2 := cm2,
                                    mobileStationClassmark3 := ts_CM3_TLV(cm3)
                    }
            }
       }
       return ret;
}


but as you can see, it's quite verbose / lengthy, and it is using a very imperative programming approach, whereas I've perceived the strengty of TTCN-3 to be its declarative nature - which allows it to be extremely expressive without having to write lots of code. Declaring separate copy+pasted templates for the CM2-only and the CM2+CM3 case is also not really nice, as it's copy+paste programming.

Another approach is

function ts_CM3_TLV(template OCTN cm3) return template MobileStationClassmark3_TLV {
        if (not isvalue(cm3)) {
                return omit;
        }
        var template MobileStationClassmark3_TLV ret := {
            elementIdentifier := '20'O,
            lengthIndicator := 0, /* overwritten */
            valuePart := cm3
        }
        return ret;
}

template PDU_ML3_MS_NW ts_RRM_CM_CHG(MobileStationClassmark2_LV cm2, template OCTN cm3 := omit) := {
       discriminator := '0110'B,
        tiOrSkip := {
                skipIndicator := '0000'B
        },
        msgs := {
                rrm := {
                        classmarkChange := {
                                messageType := '00010110'B,
                                mobileStationClassmark2 := cm2,
                                mobileStationClassmark3 := ts_CM3_TLV(cm3),
                }
        }
}


But that's still quite verbose and my aesthetics sense says it's just a hack and not an elegant and/or expressive solution.

Any hints from those more experienced?
Re: 'ifpresent' or ternary operator in parametric send templates [message #1781069 is a reply to message #1781028] Thu, 01 February 2018 07:43 Go to previous messageGo to next message
roland gecse is currently offline roland gecseFriend
Messages: 9
Registered: December 2015
Junior Member
I would advise to separate the transport handling from the protocol business logic. It does not extend TTCN-3 templates' capabilities but improves the readability of your test suite.

You could introduce some transport ASPs representing the methods you intend to use the underlying transport. One ASP could have the PDU as its sole content. It could be used when you want the TAG and LENGTH calculated automatically. Another ASP could additionally include TAG and LENGTH for those cases when you want to set TAG and LENGTH explicitly.

You have the option to implement your ASPs in C++ as a Test Port or in TTCN-3 as dual-faced/translation port. (Refer to Elemer's article for hints and examples about the latter!)
An instance of this test port or component would act as a port mapper between your Tester and SUT. It would abstract away lower level transport related functionality. The test cases would then send/receive PDUs by invoking the appropriate ASPs instead of encoding/decoding transport layer data.

Hope this makes sense.
Re: 'ifpresent' or ternary operator in parametric send templates [message #1781081 is a reply to message #1781069] Thu, 01 February 2018 09:18 Go to previous messageGo to next message
Harald Welte is currently offline Harald WelteFriend
Messages: 47
Registered: July 2017
Location: Berlin, Germany
Member

Hi Roland,

I completely agree with your statement - if I want to implement/emulate the entire "transport protocol". Whenever that's the case, I implement PTCs just doing thaty "protocol emulation". Or Whenever I need to encode/decode, I use dual-faced or translation ports.

However, in this particular case, what I want to do is to test the implementation of the same protocol in the IUT. So I need to (very flexibly) construct PDUs and send them to the IUT, and then match on the proper response. Let's say I want to have one test where the PDU contains Classmark3, and another one that doesn't contain Classmark3. And then I end up exactly with the problem outlined above.

Isn't it then the job of the templates to help me to be very expressive in writing such tests, rather than copy+pasting every single template N number of times?

What's the best approach to handle this in TTCN-3/TITAN, using the most expressive/declarative, least verbose/time-consuming/copy-pasting/imperative way?
Re: 'ifpresent' or ternary operator in parametric send templates [message #1781170 is a reply to message #1781081] Fri, 02 February 2018 09:33 Go to previous message
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 760
Registered: January 2015
Senior Member
Hi Harald,

the language does not offer such a feature currently; however if there is a strong use case and you make a proposal, we'll consider
implementing it and and also submitting it as a change request to the standard.

Deviating from the standard, even with extensions, has its downside: it makes your code less portable.
Practically , as there are only a handful of tools, and the test adapter/codec part not being standardized, this is a weak argument as you cannot get away without serious
modding when migrating from one tool to another.

Best regards
Elemer








Previous Topic:concatenating templates of list types
Next Topic:help,help,help,about repgen
Goto Forum:
  


Current Time: Mon Jun 25 17:36:58 GMT 2018

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

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

Back to the top