Manual Chapter : Routing Based on XML Content

Applies To:

Show Versions Show Versions

BIG-IP AAM

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1

BIG-IP APM

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1

BIG-IP GTM

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1

BIG-IP Link Controller

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1

BIG-IP Analytics

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1

BIG-IP LTM

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1

BIG-IP AFM

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1

BIG-IP PEM

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1

BIG-IP ASM

  • 11.5.10, 11.5.9, 11.5.8, 11.5.7, 11.5.6, 11.5.5, 11.5.4, 11.5.3, 11.5.2, 11.5.1
Manual Chapter

Routing Based on XML Content

Overview: XML content-based routing

You can use the BIG-IP® system to perform XML content-based routing whereby the system routes requests to an appropriate pool, pool member, or virtual server based on specific content in an XML document. For example, if your company transfers information in XML format, you could use this feature to examine the XML content with the intent to route the information to the appropriate department.

You configure content-based routing by creating an XML profile and associating it with a virtual server. In the XML profile, define the matching content to look for in the XML document. Next, specify how to route the traffic to a pool by writing simple iRules®. When the system discovers a match, it triggers an iRule event, and then you can configure the system to route traffic to a virtual server, a pool, or a node. You can allow multiple query matches, if needed.

This example shows a simple XML document that the system could use to perform content-based routing. It includes an element called FinanceObject used in this implementation.

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:eai="http://192.168.149.250/eai_enu/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
     <eai:SiebelEmployeeDelete
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
             <FinanceObject xsi:type="xsd:string">Route to Financing</FinanceObject>
             <SiebelMessage xsi:type="ns:ListOfEmployeeInterfaceTopElmt"
xmlns:ns="http://www.siebel.com/xml">
                   <ListOfEmployeeInterface xsi:type="ns:ListOfEmployeeInterface">
                         <SecretKey>123456789</SecretKey>
                                  <Employee>John</Employee>
                                  <Title>CEO</Title>
                   </ListOfEmployeeInterface>
             </SiebelMessage>
     </eai:SiebelEmployeeDelete>
   </soapenv:Body>
</soapenv:Envelope> 
  

Task summary

You can perform tasks to enable XML content-based routing whereby the system routes requests to an appropriate pool, pool member, or virtual server based on specific content in an XML document.

Task list

Creating a custom XML profile

To implement content-based routing, you first need to create an XML profile. XML profiles specify the content to look for in XML documents. In the XML profile, you define XPath queries to locate items in an XML document.
  1. On the Main tab, click Local Traffic > Profiles > Services > XML .
    The XML screen opens.
  2. Click Create.
    The New XML screen opens.
  3. In the Name field, type a unique name for the XML profile, such as cbr_xml_profile.
  4. In the Settings area, select the Custom check box at right.
    The settings become available.
  5. If you want to reference XML elements with namespaces in XPath queries, from Namespace Mappings, select Specify.
    The screen displays the Namespace Mappings List settings.
  6. Add namespaces to the list to specify how to map XML namespaces (as defined by the xmlns attribute) for the system to use when routing XML traffic to the correct pool, pool member, or virtual server:
    1. In the Prefix field, type the namespace prefix.
    2. In the Namespace field, type the URL that the prefix maps to.
    3. Click Add to add the namespace to the Namespace Mappings List.
  7. To define the matching criteria in the XML document, from XPath Queries, select Specify.
    The screen displays the XPath Queries settings.
  8. Add XPath queries to the list to define matching criteria in XML payloads so the system can route the traffic to the correct pool, pool member, or virtual server:
    1. In the XPath field, type an XPath expression.
      For example, to look for an element called FinanceObject, type //FinanceObject.
    2. Click Add to add the XPath expression to the XPath Queries list.
      You can define up to three XPath queries.
      The expression is added to the list.
  9. To allow each query to have multiple matches, select Multiple Query Matches.
  10. Click Finished.
    The system creates an XML profile.
You can use the XML profile to route XML traffic. Note that XML profiles do not support use of the Expect header field. This is because the header of a transaction could direct it to one pool, and the payload could invoke an iRule to direct the transaction to a different pool.

Writing XPath queries

You can write up to three XPath queries to define the content that you are looking for in XML documents. When writing XPath queries, you use a subset of the XPath syntax described in the XML Path Language (XPath) standard at http://www.w3.org/TR/xpath.

These are the rules for writing XPath queries for XML content-based routing.

  1. Express the queries in abbreviated form.
  2. Map all prefixes to namespaces.
  3. Use only ASCII characters in queries.
  4. Write queries to match elements and attributes.
  5. Use wildcards as needed for elements and namespaces; for example, //emp:employee/*.
  6. Do not use predicates in queries.

Syntax for XPath expressions

This table shows the syntax to use for XPath expressions.

Expression Description
Nodename Selects all child nodes of the named node.
@Attname Selects all attribute nodes of the named node.
/ Indicates XPath step.
// Selects nodes that match the selection no matter where they are in the document.

XPath query examples

This table shows examples of XPath queries.

Query Description
/a Selects the root element a.
//b Selects all b elements wherever they appear in the document.
/a/b:* Selects any element in a namespace bound to prefix b, which is a child of the root element a.
//a/b:c Selects elements in the namespace of element c, which is bound to prefix b, and is a child of element a.

Creating a pool to manage HTTP traffic

For implementing content-based routing, you can create one or more pools that contain the servers where you want the system to send the traffic. You write an iRule to route the traffic to the pool.

If you want to specify a default pool to which to send traffic when it does not match the content you are looking for, repeat the procedure to create a second pool. You specify the default pool in the virtual server. Alternatively, you can create a node or a virtual server to route traffic to instead of creating a pool.

  1. On the Main tab, click Local Traffic > Pools .
    The Pool List screen opens.
  2. Click Create.
    The New Pool screen opens.
  3. In the Name field, type a name for the pool, such as finance_pool.
  4. For the Health Monitors setting, from the Available list, select the http monitor, and click << to move the monitor to the Active list.
  5. From the Load Balancing Method list, select how the system distributes traffic to members of this pool.
    The default is Round Robin.
  6. For the Priority Group Activation setting, specify how to handle priority groups:
    • Select Disabled to disable priority groups. This is the default option.
    • Select Less than, and in the Available Members field type the minimum number of members that must remain available in each priority group in order for traffic to remain confined to that group.
  7. Using the New Members setting, add each resource that you want to include in the pool:
    1. Type an IP address in the Address field.
    2. Type 80 in the Service Port field, or select HTTP from the list.
    3. (Optional) Type a priority number in the Priority field.
    4. Click Add.
  8. Click Finished.
The new pool appears in the Pools list.

Creating an iRule

You create iRules® to automate traffic forwarding for XML content-based routing. When a match occurs, an iRule event is triggered, and the iRule directs the individual request to a pool, a node, or virtual server. This implementation targets a pool.
  1. On the Main tab, click Local Traffic > iRules .
  2. Click Create.
  3. In the Name field, type a 1- to 31-character name, such as XML_CBR_iRule.
  4. In the Definition field, type the syntax for the iRule using Tool Command Language (Tcl) syntax.
    For complete and detailed information iRules syntax, see the F5 Networks DevCentral web site http://devcentral.f5.com.
  5. Click Finished.

Examples of iRules for XML content-based routing

This example shows an iRule that queries for an element called FinanceObject in XML content and if a match is found, an iRule event is triggered. The system populates the values of the Tcl variables ($XML_count, $XML_queries, and $XML_values). Then the system routes traffic to a pool called finance_pool.

when XML_CONTENT_BASED_ROUTING
{ 
  for {set i 0} { $i < $XML_count } {incr i} {
    log local0. $XML_queries($i)
    log local0. $XML_values($i)
    if {($XML_queries($i) contains "FinanceObject")} {
       pool finance_pool
    }
  }
}
   

This is another example of XML content-based routing. It shows routing by bank name and by price.

      when XML_CONTENT_BASED_ROUTING
{    
     for {set i 0} { $i < $XML_count } {incr i} {  
       # routing by BANK_NAME
       if {($XML_queries($i) contains "BANK_NAME")} { 
         if {($XML_values($i) contains "InternationalBank")} {
           pool pool1
         } elseif {($XML_values($i) contains "Hapoalim")} {
           pool pool2
         } else {
           pool pool3
         }
       }
       
       # routing by PRICE
       if {($XML_queries($i) contains "PRICE")} { 
         if {($XML_values($i) > 50)} {
           pool pool1         
         } else {
           pool pool2
         }
       }
     # end for       
     }  
}

    
Note: The XML_CONTENT_BASED_ROUTING event does not trigger when the client's headers contain "Expect: 100-continue" regardless of whether the server sends a 100-continue response. In this case, the request is routed to the default pool.

Tcl variables in iRules for XML routing

This table lists and describes the Tcl variables in the sample iRule.

Tcl variable Description
$XML_count Shows the number of matching queries.
$XML_queries Contains an array of the matching query names.
$XML_values Holds the values of the matching elements.

Viewing statistics about XML content-based routing

You can view statistics about XML content-based routing to make sure that the routing is working.
Note: The system first checks for a match, then checks for malformedness of XML content. So if the system detects a match, it stops checking, and might not detect any subsequent parts of the document that are malformed.
  1. On the Main tab, click Statistics > Module Statistics > Local Traffic .
    The Local Traffic statistics screen opens.
  2. From the Statistics Type list, select Profiles Summary.
  3. In the Global Profile Statistics area, for the Profile Type XML, click View in the Details.
    The system displays information about the number of XML documents that were inspected, the number of documents that had zero to three matches, and the number of XML documents that were found to be malformed.