Forum Discussion
Chris_Day_10331
Nimbostratus
Oct 04, 2005iRule for Server Testing
Good morning,
Please see attached doc.
Essentially, what we are trying to achieve is to be able to validate that a single server behind a VS is responding correctly. Ideally, we could rewrite both the request and the response to make the client "think" that it is receiving content from the URL to which they connected, when in fact it has been cloaked to the server and back to the client via header rewrite.
I'm assuming this must be possible, but have not seen this done before. Perhaps there are some other alternatives on how this could be done differently?
I could not attach the word document ("Invalid file type or exceeds max size(60kb)" even though the file is 28k) but here is the guts of the content:
RE: BIG-IP 1500
SN: bip071410s / bip071401s
Version: 9.0.5
Environment:
- 4 web servers: web001, web002, web003, web004
- front-ended by single VS on BIG-IP
Requirements:
1) Each web server runs multiple sites via HTTP/1.1 host headers:
companyA.pnimedia.com
companyB.pnimedia.com
companyC.pnimedia.com
2) Sites are accessed via virtual server on BIG-IP from front end and back end (via VPN)
3) We would like to be able to test (connect and verify) each web server independently, ideally through iRules processing.
Desired functionality:
http://companyA.test.pnimedia.com/web001
- use node web001 AND rewrite request/response to companyA.pnimedia.com
http://companyB.test.pnimedia.com/web003
- use node web003 AND rewrite request/response to companyB.pnimedia.com
Ideally, if the above could be specified in some sort of matrix/which statements like this:
web001 = 10.10.10.101
web003 = 10.10.10.113 (etc.)
I appreciate any comments, recommendations and/or sample iRules!
Thanks,
Chris
- Chris, I moved your post over to the iRules forum. Next time, if you could post iRules questions over there that would help you get a better response.
*** String data groups *** class host_mapping { companyA.test.pnimedia.com companyA.pnimedia.com companyB.test.pnimedia.com companyB.pnimedia.com companyC.test.pnimedia.com companyC.pnimedia.com } class node_mapping { web001 10.10.10.1 web002 10.10.10.2 web003 10.10.10.3 } *** Begin iRule *** when HTTP_REQUEST { Search for host mapping in the lookup list set new_host [findclass [HTTP::host] $::host_mapping " "] if { "" ne $new_host } { if mapping is found, replace the Host header log local0. "Replacing host from [HTTP::host] to $new_host" HTTP::header replace "Host" $new_host" Pull out the node name as the first element of the uri ie. /web001/foo/bar -> web001 set node_name [lindex [split [HTTP::uri] "/"] 1] if { "" ne $node_name } { Now look for the node address in the lookup list log local0. "Searching for node: $node_name" set node_addr [findclass $node_name $::node_mapping " "] if { "" ne $node_addr } { log local0. "Routing to node: $node_addr " node $node_addr } else { log local0. "Didn't find node '$node_name' in lookup class" } } else { log local0. "No node name passed in URI" } } else { log local0. "Didn't find [HTTP::host] in lookup class" } }
- Chris_Day_10331
Nimbostratus
Hey Joe, - Colin_Walker_12Historic F5 AccountOh, and about the node name out of the URI, Joe's rule example does that already.
... Pull out the node name as the first element of the uri ie. /web001/foo/bar -> web001 set node_name [lindex [split [HTTP::uri] "/"] 1] if { "" ne $node_name } { Now look for the node address in the lookup list log local0. "Searching for node: $node_name" set node_addr [findclass $node_name $::node_mapping " "] if { "" ne $node_addr } { log local0. "Routing to node: $node_addr " node $node_addr ...
class node_mapping { web001 10.10.10.1 web002 10.10.10.2 web003 10.10.10.3 }
- Chris_Day_10331
Nimbostratus
Hi Guys,telnet blacks.test.pnimedia.com GET / HTTP/1.1 HOST: blacks.pnimedia.com
Rule PNI_TestProcessor : Replacing host from blacks.test.pnimedia.com to blacks.pnimedia.com Rule PNI_TestProcessor : Searching for node: web002 Rule PNI_TestProcessor : Routing to node: 10.10.20.51
tcpdump -w /var/tmp/external.dump -ni external port 80 and host 64.85.47.204
tcpdump -w /var/tmp/internal.dump -ni internal port 80 and host 64.85.47.204
when HTTP_REQUEST { Search for host mapping in the lookup list set new_host [findclass [HTTP::host] $::host_mapping " "] if { "" ne $new_host } { if mapping is found, replace the Host header log local0. "Replacing host from [HTTP::host] to $new_host" HTTP::header replace "Host" $new_host" Pull out the node name as the first element of the uri ie. /web001/foo/bar -> web001 set node_name [lindex [split [HTTP::uri] "/"] 1] if { "" ne $node_name } { Now look for the node address in the lookup list log local0. "Searching for node: $node_name" set node_addr [findclass $node_name $::node_mapping " "] if { "" ne $node_addr } { log local0. "Routing to node: $node_addr " node $node_addr } else { log local0. "Didn't find node '$node_name' in lookup class" } } else { log local0. "No node name passed in URI" } } else { log local0. "Didn't find [HTTP::host] in lookup class" } }
- It doesn't look like your dumps were added. I've just added ".txt" as a valid attachment extension to the forums so if you could repost them with a .txt extension that would be great.
- Chris_Day_10331
Nimbostratus
My bad, the "80" for TCP/80 was on the end of that telnet string. I'll save you the output of that command ;-) I believe that the problem might be that this part: - In looking at your traces, they contain the following:
13:45:35.179821 64-85-47-204.ip.van.radiant.net.46721 > 10.10.10.100.http: P 1:421(420) ack 1 win 5840 (DF) 0x0000 4500 01d8 6996 4000 3906 51fb 4055 2fcc E...i.@.9.Q.@U/. 0x0010 0a0a 0a64 b681 0050 db6d cd96 3ea3 4800 ...d...P.m..>.H. 0x0020 8018 16d0 bf12 0000 0101 080a 01a4 06bc ................ 0x0030 af8c 12ea 4745 5420 2f77 6562 3030 322f ....GET./web002/ 0x0040 6465 6661 756c 742e 6173 7078 2048 5454 default.aspx.HTT 0x0050 502f P/ 13:45:35.180389 10.10.10.100.http > 64-85-47-204.ip.van.radiant.net.46721: P 1:169(168) ack 421 win 4800 (DF) 0x0000 4500 00dc e46b 4000 ff06 1221 0a0a 0a64 E....k@....!...d 0x0010 4055 2fcc 0050 b681 3ea3 4800 db6d cf3a @U/..P..>.H..m.: 0x0020 8018 12c0 60d4 0000 0101 080a af8c 1300 ....`........... 0x0030 01a4 06bc 4854 5450 2f31 2e31 2034 3030 ....HTTP/1.1.400 0x0040 2042 6164 2052 6571 7565 7374 0d0a 436f .Bad.Request..Co 0x0050 6e74 nt
- Chris_Day_10331
Nimbostratus
Hi Joe,telnet blacks.test.pnimedia.com 80 GET /web002/default.aspx HTTP/1.1 Host: blacks.test.pnimedia.com HTTP/1.1 400 Bad Request Content-Type: text/html Date: Wed, 05 Oct 2005 18:49:39 GMT Connection: close Content-Length: 39Bad Request (Invalid Hostname)
telnet blacks.test.pnimedia.com 80 GET /web002/default.aspx HTTP/1.1 Host: blacks.pnimedia.com HTTP/1.1 302 Found Date: Wed, 05 Oct 2005 18:50:34 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 1.1.4322 Transfer-Encoding: chunked Location: /error.aspx Cache-Control: private Content-Type: text/html; charset=utf-8 80Object movedObject moved to .
- My bad, In my original code I posted I had an extra quote at the end of the HTTP::header replace command:
HTTP::header replace "Host" $new_host"
HTTP::header replace "Host" $new_host
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