The PingER Topology Service supports the XPath query language. Many XPath tutorials can be found on the web including ones at W3schools and Zvon.

Query wrapper

All queries must be wrapped in the necessary XML to create a PerfSONAR message.

<nmwg:message type="SetupDataRequest"
        xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"
                xmlns:xquery="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/">

        <nmwg:metadata id="meta1">
                <nmwg:eventType>http://ggf.org/ns/nmwg/topology/query/xquery/20070809</nmwg:eventType>
                <xquery:subject id="sub1" xmlns:xquery="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/">

                <!-- Query goes here, not in comments -->

        </xquery:subject>
    </nmwg:metadata>
    <nmwg:data id="data1" metadataIdRef="meta1"/>
</nmwg:message>

Query anatomy

/*:entity[predicate]

XPath queries start with / or //. A single slash means that the query will be selecting elements from the root of the XML hierarchy; // indicates that the following node selection can be found anywhere inside the hierarchy.

An entity selector follows the slash. Entity names are prefixed with *: to ensure that the entity will be matched regardless of what namespace it is in.

The [predicate] section is optional and is a typical infix (entity/attribute operator value) expression for the criteria used to narrow down which instances of an entity are selected. Attributes of an entity can be referred to with @attributeName and child entities' values can be referred to by their entity names directly. A test can be performed on the current entity's value by using . (period). Typical Java operators can be used with = working for string comparison. String literals should be contained in single or double quotes.

Sample Queries

Querying for a specific node by hostname:

//*:node[*:hostName="ping.slac.stanford.edu"]

Wrapped, the complete XML message would look like:

<nmwg:message type="SetupDataRequest"
        xmlns:nmwg="http://ggf.org/ns/nmwg/base/2.0/"
                xmlns:xquery="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/">

        <nmwg:metadata id="meta1">
                <nmwg:eventType>http://ggf.org/ns/nmwg/topology/query/xquery/20070809</nmwg:eventType>
                <xquery:subject id="sub1" xmlns:xquery="http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/">

                //*:node[*:hostName="ping.slac.stanford.edu"]

        </xquery:subject>
    </nmwg:metadata>
    <nmwg:data id="data1" metadataIdRef="meta1"/>
</nmwg:message>

Querying for nodes based on part of their host name

//*:node[contains(*:hostName,"stanford")]

Querying for a specific node by IP address

//*:port/*:ipAddress[@type="IPv4" and .='193.227.1.191']/parent::*/parent::*

Since the XPath query is looking at the ipAddress sub-entiy of port (which is in turn a sub-entity or child of node), the suffix of the query /parent::/parent:: is necessary to return the "grandparent" of the ipAddress element, which is the entire node entity.

It is not strictly necessary to start with the port entity; this query should return the same results:

//*:ipAddress[@type="IPv4" and .='193.227.1.191']/parent::*/parent::*

Querying for nodes from a country

//*:location[*:country="Germany"]/parent::*:node

Querying for nodes from a continent

//*:location[*:country="Europe]/parent::*:node
  • No labels