cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
383
Views
1
Helpful
6
Replies
khgrant
Cisco Employee

Variable within XPATH in XML file

I´m trying evaluate an XPATH in an XML template but inside the XPATH I need to call a variable, e.g.

<address>{/../../ncs:devices/ncs:device[name='PE1']/ncs:config/cisco-ios-xr:interface/cisco-ios-xr:Loopback[cisco-ios-xr:id='0']/cisco-ios-xr:ipv4/cisco-ios-xr:address/cisco-ios-xr:ip}</address>

I need to be able to change the PE1 name with something that is dynamic /SiteA/DeviceA

Is this doable? If so what would be the correct syntax for that?

BTW, I know that it can be done with Java, but is there an option with just template-based ?

1 ACCEPTED SOLUTION

Accepted Solutions
khgrant
Cisco Employee

Thanks for you example, but the idea is that we don´t ask the user for the pw-peer-address because it can be obtained from the config of the device. And also we do not want the end-user to specify if device is IOS or XR, for our example we want that to be identified by our package (and avoid using java)

We found some ways of doing it:

1) get the value in the YANG, this option requires a different variable because the tail:link is different for IOS than for IOS-XR.

2) we get the value in the template xml file, but requires when statements to identify if neighbor device is IOS or IOS-XR and query the loopback address differently.

Attaching the way we did it, by the way the expression was completed with the help of Sujeeth Kanuganti.

here is the statement that was used in XML.

{/../../ncs:devices/ncs:device[ncs:name=current()/../AttachmentCircuit2/device-name]/ncs:config/ios:interface/ios:Loopback[ios:name='0']/ios:ip/ios:address/ios:primary/ios:address}

View solution in original post

6 REPLIES 6
khgrant
Cisco Employee

I'm not sure I follow you - Why not just {/device} - say device is the direct descendant of the service in your yang module ?

khgrant
Cisco Employee

The thing is I am referencing a different device than the one I actually working on, so it cannot simply be /device.

To ilustrate I have

PE1 —— PE2

When pasting the config for PE1 I need to lookup PE2´s loopback address and vice versa.

khgrant
Cisco Employee

First look at the question which merely says:

I want a service Y to be dependent on some data X which is not part of that service model.

Normally this is not a favourable model of a service. If the data X is changed then the service Y might be out of sync and has to be explicitly redeployed. On the other hand if X is part of Y then the FASTMAP algorithm will take care of this automatically and the service will be redeployed when X changes.

However you can code like this with Java but not with services implemented purely by a template.

Back to the question if you can access other devices from within an XPATH expression:

Short answer: no.

Little longer answer:

All XPATH expressions in a template are evaluated with a root context and a current context. The root context is set to the path of the current service. This means a path beginning with ‘/‘, forward slash, starts at the top of the service. In other word you can say the template is ‘chrooted’ or ‘sandboxed’ to the service instance data. The current context changes, but is always within the service, as XPATH expressions are evaluated. When writing paths without a beginning slash these paths are evaluated relative the current context. So there is no way you can access the data of a device. It is a design decision to have it this way.

khgrant
Cisco Employee

I think this re-emphasizes that we need a “golden example” for pseudowire provisioning – it is a problem we encounter everywhere. (…and also VPLS, H-VPLS, ethernet access, etc.)

I have been experimenting in this area myself. First I looked at how far you can go with a templates based approach:

http://iwe.cisco.com/web/view-post/post/-/posts?postId=732100039

Here the problem you point out below is solved in the YANG file by creating a read-only field in the service model which refers to the loopback address used for LDP router ID.

Note that this is just experimentation by an amateur, so not “golden example” (although I did get good assistance from the Tail-f team)

I am also looking at the next step, which is to use Java in order to enable resource allocation of pseudowire id, service instance id, etc.

khgrant
Cisco Employee

A couple of comments:

1 - It is important to go through the exercise to experiment the limits with template-only services as it is the best way to fully understand YANG and Xpath syntaxing.

2- There are a number of examples of customers using template-only services in operation, so their use in operational environment is real.

3- There is a feature request to allow resource allocation via templates.

4- On the issue of L2VPNs using templates, check the example attached. This is a “real POC” fully done with templates that we successfully concluded at Telecom Egypt (currently waiting for the RFP results):

- There is a topology table where the operator sets what should be interface/IP used for its Pseudo wires.

- For each service instance, we need to add that IP because of the reasons Dag mentioned. However, setting this IP is really an auto-completion tab. I have proposed an extension that removes the need to for this set by allowing xpath expressions in the YANG default statement (that would be a ‘vendor-specific’ YANG default implementation). This is currently under evaluation and we also working on other ways to solve this problem.

- The service support UNI-to-UNI or UNI-to-NNI with IOS/XR/JUNOS as UNI and XR as NNI. Each equipment is placed on a device-group specifying if it is a UNI or NNI device.

- The service also allows a “cleaver” BW policy setting where a threshold is configured and the QoS  BW value changes depending on the amount of bytes computed for that PW in a given month. This way, the customer can offer a “booster” service to its customers and monetised. The accounting for consumed bytes is done outside of NCS (we did a python script as demo)

- The service includes a “self-test”. This is done in JAVA and not in template but it is important not to forget. In my case, I would connect to the respective router and perform a “show l2vpn” for the appropriate PW.

All in all, with this example we can solve Luis’ question with a  simple “tab” to setup the loopback address in each instance. We are working on an improvement to even remove this need for template-only services in the future.

khgrant
Cisco Employee

Thanks for you example, but the idea is that we don´t ask the user for the pw-peer-address because it can be obtained from the config of the device. And also we do not want the end-user to specify if device is IOS or XR, for our example we want that to be identified by our package (and avoid using java)

We found some ways of doing it:

1) get the value in the YANG, this option requires a different variable because the tail:link is different for IOS than for IOS-XR.

2) we get the value in the template xml file, but requires when statements to identify if neighbor device is IOS or IOS-XR and query the loopback address differently.

Attaching the way we did it, by the way the expression was completed with the help of Sujeeth Kanuganti.

here is the statement that was used in XML.

{/../../ncs:devices/ncs:device[ncs:name=current()/../AttachmentCircuit2/device-name]/ncs:config/ios:interface/ios:Loopback[ios:name='0']/ios:ip/ios:address/ios:primary/ios:address}

View solution in original post

Content for Community-Ad

This widget could not be displayed.