Forum Discussion
sre_81614
Nimbostratus
May 06, 2009My iRule Impressions & Optimiziation-Request-"Contest" (IP to STOREID)
Hello community,
first of all I have to say two 4 words: I love our BIGIPs! :-)
But when it comes to "iRule-Scripting", I see some disadvantages not regarding tcl itself, but the...
sre_81614
Nimbostratus
May 14, 2009Hey Nat,
here is the whole iRule I use including the "ip to storeid" function. It takes an average of 400.000cpu cycles/request. Putting some of the IP convert functions into the RULE_INIT doesn't work on my BIGIP1600 running V10 HFA2, because [IP::client_addr] isn't known while init. I'm looking forward to see if you can get this rule to burn less cpucycles 😉
Thanks in advance!
- SR
timing on
when RULE_INIT {
}
when HTTP_REQUEST {
Set default publication and pool
set publication vkstintranet
pool vkstintranet
Set publications
Syntax: publicpath internalpath pool
set publications {
publicpath1internalpath1appsrv1-8020
publicpath2internalpath2appsrv2-8020
publicpath3internalpath3appsrv3-8020
publicpath4internalpath4appsrv4-8020
publicpath5internalpath5appsrv5-8020
publicpath6internalpath6appsrv6-8020
publicpath7internalpath7appsrv7-8020
publicpath8internalpath8appsrv8-8020
publicpath9internalpath9appsrv9-8020
publicpath10internalpath10appsrv10-8020
publicpath11internalpath11appsrv11-8020
publicpath12internalpath12appsrv12-8020
}
Always set X-Forwarded-For for transparency...
if {[HTTP::header exists X-Forwarded-For]} {
HTTP::header replace X-Forwarded-For [IP::client_addr]
} else {
HTTP::header insert X-Forwarded-For [IP::client_addr]
}
Set X-Store-Id
set STOREID Non-Store
set ip [IP::client_addr]
Setting the ip for testing purposes because dev workstation does not belong to store-network 😉
set ip 172.20.15.32
set net_start 172.20.0.0
set net_maskbit 14
set net_mask 0.3.255.224
set net_segment_bit 5
if { [IP::addr $ip/$net_maskbit equals $net_start] }{
scan [IP::addr $ip mask $net_mask] "%d.%d.%d.%d" a b c d
set STOREID [expr ( {$a} << 24 | {$b} << 16 | {$c} << 8 | {$d} ) >> {$net_segment_bit} ]
if {[HTTP::header exists X-Store-id]} {
HTTP::header replace X-Store-Id $STOREID
} else {
HTTP::header insert X-Store-Id $STOREID
}
}
set net_start 10.192.0.0
set net_maskbit 10
set net_mask 0.63.254.0
set net_segment_bit 9
if { [IP::addr $ip/$net_maskbit equals $net_start] }{
scan [IP::addr $ip mask $net_mask] "%d.%d.%d.%d" a b c d
set STOREID [expr ( {$a} << 24 | {$b} << 16 | {$c} << 8 | {$d} ) >> {$net_segment_bit} ]
if {[HTTP::header exists X-Store-id]} {
HTTP::header replace X-Store-Id $STOREID
} else {
HTTP::header insert X-Store-Id $STOREID
}
}
We're going to balance (otherwisethe request will be balanced to the default pool of the virtual server)...
set requesteduri [HTTP::uri]
foreach { publicpath publicpath srvpool } $publications {
if { ([HTTP::uri] starts_with "/$publicpath\/") or ([HTTP::uri] equals "/$publicpath") } {
set internalUri [regsub -nocase "/$publicpath/*" [HTTP::uri] ""]
HTTP::uri "/$publicpath/$internalUri"
set publication $publicpath
pool $srvpool
}
}
}
when HTTP_REQUEST_SEND {
log local0. "Source-IP: [IP::client_addr], Source-Port: [client_port], URI: $requesteduri, Publication: $publication, VKST: $STOREID, SelectedPoolAndNode: [LB::server]"
}
when LB_FAILED {
HTTP::respond 200 content {
Apology Page
We are sorry, but the site you are looking for is temporarily out of service
If you feel you have reached this page in error, please try again.
}
log local0. "Balancing failed. Publication: $publication"
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects