Service Logic Expressions

Introduction

Instead of providing a literal or  a single variable an expression can be provided. These can prove to be useful in switch statements.

This tutorial assumes you are familiar with escaping xml if this is a new concept please visit Escaping Xml.

The valid operators are specified in the grammar which can be found in gerrit.

All expressions begin and end with backticks. They may contain literals, variables and operators.

Logical Operators

operators

and or

example code

<switch test="`'PIZZA' == 'NOTPIZZA' or $a != $b`"> <switch test="`'PIZZA' == 'PIZZA' and $a != $b`"> <switch test="`'PIZZA' == 'NOTPIZZA' or $a &gt;= $b`"> <switch test="`'PIZZA' == 'PIZZA' and $b &lt; $a`">

log statements

2017-03-16T19:28:54.011Z|d1910234-d180-44c9-a33e-5b7095d272b9|qtp768791817-241|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute b to 3 2017-03-16T19:28:54.011Z|d1910234-d180-44c9-a33e-5b7095d272b9|qtp768791817-241|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute a to 5 2017-03-16T19:29:27.320Z|d1910234-d180-44c9-a33e-5b7095d272b9|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (PIZZA == NOTPIZZA or $a != $b) evaluates to true 2017-03-16T19:29:27.320Z|d1910234-d180-44c9-a33e-5b7095d272b9|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (PIZZA == PIZZA and $a != $b) evaluates to true 2017-03-16T19:47:34.510Z|d1910234-d180-44c9-a33e-5b7095d272b9|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (PIZZA == NOTPIZZA or $a >= $b) evaluates to true 2017-03-16T19:47:34.510Z|d1910234-d180-44c9-a33e-5b7095d272b9|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (PIZZA == PIZZA and $b < $a) evaluates to true

Comparison Operators

operators

== != > < >= <=

example code

<switch test="`'PIZZA' == 'PIZZA'`"> <switch test="`$a == $b`"> <switch test="`'PIZZA' == 'NOTPIZZA'`"> <switch test="`'PIZZA' != 'PIZZA'`"> <switch test="`'PIZZA' != 'NOTPIZZA'`"> <switch test='`$a != $b`'> <switch test='`1 &lt; 2`'> <switch test='`2 &lt;= 2`'> <switch test='`3 &gt; 2`'> <switch test='`2 &gt;= 2`'>

log statements

2017-03-16T19:28:54.011Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute b to 3 2017-03-16T19:28:54.011Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute a to 5 2017-03-16T19:29:27.318Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (PIZZA == PIZZA) evaluates to true 2017-03-16T19:29:27.319Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression ($a == $b) evaluates to false 2017-03-16T19:29:27.319Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (PIZZA == NOTPIZZA) evaluates to false 2017-03-16T19:29:27.319Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (PIZZA != PIZZA) evaluates to false 2017-03-16T19:29:27.320Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (PIZZA != NOTPIZZA) evaluates to true 2017-03-16T19:29:27.320Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression ($a != $b) evaluates to true 2017-03-16T19:29:27.321Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (1 < 2) evaluates to true 2017-03-16T19:29:27.321Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (2 <= 2) evaluates to true 2017-03-16T19:29:27.321Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (3 > 2) evaluates to true 2017-03-16T19:29:27.322Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SwitchNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|test expression (2 >= 2) evaluates to true

Arithmetic Operators

operators

+ - / *

example code

<set> <parameter name='add' value='`1 + 1`' /> <parameter name='sub' value='`2 - 1`' /> <parameter name='div' value='`6 / 2`' /> <parameter name='multi' value='`2 * 2`' />

log statements

2017-03-16T19:29:27.322Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SvcLogicServiceImpl |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node executor for node type set - com.att.sdnctl.sli.provider.SetNodeExecutor 2017-03-16T19:29:27.322Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute div to 3 2017-03-16T19:29:27.322Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute multi to 4 2017-03-16T19:29:27.323Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute sub to 1 2017-03-16T19:29:27.323Z|9602570e-6c56-493c-9f9a-32b9911d27db|qtp768791817-241|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute add to 2

Concatentation

operators

+

sample code

<set> <parameter name='varA' value='`$a + $b`' /> <parameter name='varB' value="`$a +'literal' `" /> <parameter name='varC' value="`'literal' + $b `" /> <parameter name='varD' value="`'too' + 'literal'`" />

log statements

2017-03-16T20:01:25.399Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute b to dog 2017-03-16T20:01:25.399Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute a to cat 2017-03-16T20:01:25.399Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|BlockNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Block - executing outcome 2 2017-03-16T20:01:25.399Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|SvcLogicServiceImpl |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node 3 2017-03-16T20:01:25.399Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|SvcLogicServiceImpl |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node executor for node type set - com.att.sdnctl.sli.provider.SetNodeExecutor 2017-03-16T20:01:25.400Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute varD to tooliteral 2017-03-16T20:01:25.400Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute varC to literaldog 2017-03-16T20:01:25.400Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute varB to catliteral 2017-03-16T20:01:25.401Z|6564cfee-98ad-460a-af08-c3987c7d1afa|qtp768791817-238|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute varA to catdog

Notes

If the + operator is used against numeric operands they are added. If the + operator is used against string operands they are concatenated.

If you need to concatenate strings which are numbers use StringUtils concat.

<parameter name='numbers' value='`1 + 1`' /> <parameter name='strings' value="`'1' +'1'`"/> <parameter name='portNumber' value='2' /> <parameter name='slot' value="3" /> <parameter name='shelf' value="1" /> <parameter name='pssh' value='`$portNumber + $slot + $shelf`' />

log statements

2017-03-16T20:10:02.911Z|b8501d87-d470-464f-99a1-74e4174f1825|qtp768791817-242|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute strings to 2 2017-03-16T20:10:02.912Z|b8501d87-d470-464f-99a1-74e4174f1825|qtp768791817-242|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute numbers to 2 2017-03-16T20:15:15.909Z|4918a17d-057a-46a1-b45d-cc884fe79f87|qtp768791817-239|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute slot to 3 2017-03-16T20:15:15.910Z|4918a17d-057a-46a1-b45d-cc884fe79f87|qtp768791817-239|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute portNumber to 2 2017-03-16T20:15:15.910Z|4918a17d-057a-46a1-b45d-cc884fe79f87|qtp768791817-239|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute shelf to 1 2017-03-16T20:15:15.910Z|4918a17d-057a-46a1-b45d-cc884fe79f87|qtp768791817-239|DEBUG|BlockNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Block - executing outcome 2 2017-03-16T20:15:15.910Z|4918a17d-057a-46a1-b45d-cc884fe79f87|qtp768791817-239|DEBUG|SvcLogicServiceImpl |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node 3 2017-03-16T20:15:15.910Z|4918a17d-057a-46a1-b45d-cc884fe79f87|qtp768791817-239|DEBUG|SvcLogicServiceImpl |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Executing node executor for node type set - com.att.sdnctl.sli.provider.SetNodeExecutor 2017-03-16T20:15:15.910Z|4918a17d-057a-46a1-b45d-cc884fe79f87|qtp768791817-239|DEBUG|SetNodeExecutor |144 - com.att.sdnctl.sli-provider - 11.0.7.SNAPSHOT|Setting context attribute pssh to 6