The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article we will look at the variables. There are 2 main types of variables, local and global.
Local
Local variables represent data within your local namespace, and are assigned the same scope as the iRule that created it. This also means that local variables are shared across all iRules for a Virtual Server. In addition to this local variables are also session based.
Below shows you how you would assign, output and unassign a local variable.
set uri “picture.jpg” <- assign var
log local0. “uri is $uri” <- output var
unset uri <- unassign var
Global
Unlike local variables, global variables exist outside of the local namespace, meaning that they aren’t bound to a single session but instead a TMM instance. An example of when a global variable may be required would be the assignment of an IP address to a variable that you would want available to every session across the F5 system.
Unfortunately global variables are not shared across TMM instances and are only available globally within the local TMM instances. Because of this using a global variable within an iRule demotes CMP (Clustered Multi-Processing) from the associated virtual server.
set ::uri “picture.jpg” <- assign var
log local0. “uri is $::uri” <- output var
unset ::uri <- unassign var
Static Global
Static global variables overcome the CMP demotion problem by sharing the data across each TMM instance. However as the name suggests the variable is static, and is only defined each time the iRule is initialized.
when RULE_INIT {
set static::debug 0
}
when HTTP_REQUEST {
if { $static::debug } {
log local0. “debug equals $static::debug”
}
References
https://devcentral.f5.com/tech-tips/articles/irules-101-03-variables
https://devcentral.f5.com/tech-tips/articles/-the101-irules-101-variables
http://support.f5.com/kb/en-us/solutions/public/13000/000/sol13033.html
https://devcentral.f5.com/wiki/irules.static.ashx
- How to Configure a BIND Server on Ubuntu - March 15, 2018
- What is a BGP Confederation? - March 6, 2018
- Cisco – What is BGP ORF (Outbound Route Filtering)? - March 5, 2018
Want to become an F5 Loadbalancers expert?
Here is our hand-picked selection of the best courses you can find online:
F5 BIG-IP 101 Certification Exam – Complete Course
F5 BIG-IP 201 Certification Exam – Complete Course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial