cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1174
Views
20
Helpful
7
Replies

Handle Foreach statement in Top Service Template of a Stacked Service

Jerems
Spotlight
Spotlight

Hi All and HNY 2022!

 

I am currently building a stacked-service which aims to create a Routing-Instance from which i can peer with different ISPs

This stacked-Service relies on 3 packages : 1 top service and 2 bottom service (components services)

The first bottom service handles Iface, link, vlan configurations.

The second bottom service handles the creation of the routing-instance a well as the BGP configuration part.

Because i believe that those two bottom components services can be reusable by some other top services i decided to create a top service that would import both bottom services.

This service creates 1 routing-instance, 1 security-zone and its associated security-policy as well as 1 BGP Group and  peer, 1 interface and 1 vlan.

How should i proceed to create 1 routing-instance  which could host multiple BGP Group depending on the CSP chosen from an enumeration list ?

Let's say that i can choose between ISP1, ISP2, ISP3. Each time i choose an ISP in my list, i am then able to navigate through the sub-items for that particular ISP (vlan, ip address, peer ip address, peer asn). At the moment, i use the same leaf which result in bad template outputs because the different values (for ISP1, ISP2...) of each leaf are concatenated :

 

<ip-address>192.168.255.9/30192.168.255.13/30</ip-address>

 

where it should be :

<ip-address(ISP1)>192.168.255.9/30</ip-address>

<ip-address(ISP2)>192.168.255.13/30</ip-address>

...and so on

 

Thanks in advance for your help !

1 Accepted Solution

Accepted Solutions

Jerems
Spotlight
Spotlight

In order to share my experience on creating a stacked service in NSO please find below a summary of the steps achieved to reach this goal.

To build some sort of usable stacked service design, one should consider the following hints or rules :

Capture d’écran 2022-01-13 à 15.37.10.pngMy project aimed to build a stacked service to allow the reuse of bottom packages (aka components) by different top services.

  • Managing complexity in the top service, meaning that all conditions or loops (and all complex stuff) should be introduced in the upper service and not in the bottom one.
  • Control the data types in your top service (you could even imagine of having only "string" types in the bottom services/packages)
  • Consider each requested list in your yang design as a separate package. Imagine for example that you have to create a routing instance with all underlying components (Routing Policies, Routing Protocols, Associated interfaces). Instead of having one full package, you can have a package for each type of components. In my situation, i had for example a specific package to manage all BGP features. This will let me easily reuse the BGP package if i want to add a new peering in an existing service.

Does it mean that you should consider a Top Down approach ? Maybe yes. From my opinion, this is the best way to design your stack service, but it is still my own opinion

 

I will of course ask anyone of you comment, amend or even share his own personal experience on building stacked service.

Thanks again for the help provided by this great community ;-).

View solution in original post

7 Replies 7

vleijon
Cisco Employee
Cisco Employee
I am not quite sure what your problem is, but you may be able to use either a for-loop or an if-statement in your template. Check out the processing instructions part of the manual: https://developer.cisco.com/docs/nso/guides/#!templates/service-and-api-templates-in-multi-ned-environment

Jerems
Spotlight
Spotlight

Hi vleijon,

 

Thanks a lot for your answer. I am currently struggling with loops at the moment.

My routing instance is supposed to be able to host multiple BGP peerings with external ISPs.

Which means that for a particular Routing-instance i should be able to loop the creation of an interface with multiple vlan (list), each vlan could be assigned multiple IPs(list) :

This is what i expect :

routing-instance 1 > csp1 > vlan1 > IP1

                             > csp2 > vlan2 > IP2

 

This is what i obtain at the moment because of a strange loop :

routing-instance 1 > csp1 > vlan1 > IP1&2

                             > csp2 > vlan2 > IP1&2

CSP is a list, VLAN is a list and IP is a list

 

Thanks in advance for your help.

Jerems

Hard to tell just from that, what is the yang type of IP1 and IP2? What is the corresponding fragment of the template? Perhaps you need an additional inner loop?

Hi Vleijon,

 

I found my answer through the addition of loops in my top service. Thanks for your comment that corrobrates my findings !

To build my top service, i had to pick up the service part of my several bottom service templates but i wasn't sure on how to manage loops in my newly created top service. It becomes more & more clear to me

Great to hear, one tip I want to share: You can do commit dry-run | debug template in the ncs_cli to get some extra debug information about your templates.

Correct vleijon,

But honestly, i'm just a little bit confused when trying to understand the output of a "| debug template".

 

For /services/create_l3vpn:create_l3vpn[l3vpn_id='001']/devices[device='device1'], it evaluates to "device1"
Operation 'merge' on existing node: /devices/device[name='device1'] (from file "create_link-template.xml", line 5)
Processing instruction 'foreach': evaluating the node-set (from file "create_link-template.xml", line 9)
Evaluating "/junos/interface" (from file "create_link-template.xml", line 9)
Context node: /services/create_l3vpn:create_l3vpn[l3vpn_id='001']/devices[device='device1']
Result: empty node

 

For example, i often see this "empty node" result without having the ability to understand what is going wrong...

Thanks again !

 

 

Jerems
Spotlight
Spotlight

In order to share my experience on creating a stacked service in NSO please find below a summary of the steps achieved to reach this goal.

To build some sort of usable stacked service design, one should consider the following hints or rules :

Capture d’écran 2022-01-13 à 15.37.10.pngMy project aimed to build a stacked service to allow the reuse of bottom packages (aka components) by different top services.

  • Managing complexity in the top service, meaning that all conditions or loops (and all complex stuff) should be introduced in the upper service and not in the bottom one.
  • Control the data types in your top service (you could even imagine of having only "string" types in the bottom services/packages)
  • Consider each requested list in your yang design as a separate package. Imagine for example that you have to create a routing instance with all underlying components (Routing Policies, Routing Protocols, Associated interfaces). Instead of having one full package, you can have a package for each type of components. In my situation, i had for example a specific package to manage all BGP features. This will let me easily reuse the BGP package if i want to add a new peering in an existing service.

Does it mean that you should consider a Top Down approach ? Maybe yes. From my opinion, this is the best way to design your stack service, but it is still my own opinion

 

I will of course ask anyone of you comment, amend or even share his own personal experience on building stacked service.

Thanks again for the help provided by this great community ;-).