iRules, URL Routing and Cookie Persistance

Hi Everyone,

We have a BigIP 1500, configured with several virtual servers and pools. We use an iRule to make routing decisions to direct traffic to the correct pool based on request URL, since the site is distributed across several pools.

The iRule for one of the virtual servers is as follows. It has a default pool of webnode3_pool.

when CLIENT_ACCEPTED {

set defpool [LB::server pool]

}

when HTTP_REQUEST {

set request_uri [string tolower [HTTP::uri]]

set request_host [string tolower [HTTP::host]]

if { $request_uri contains “/aspnet_client/” } {

pool webnode_pool

}

elseif { $request_uri contains “/ig_common/” } {

pool webnode_pool

}

elseif { $request_uri contains “/cpm/” } {

pool cpmweb_pool

}

elseif { $request_uri contains “/agentrequest/” } {

pool webnode_pool

}

elseif { $request_uri contains “/agents/” } {

pool webnode_pool

}

elseif { $request_uri contains “/home/” } {

pool webnode_pool

}

else {

pool $defpool

}

}

The URL routing works fine. The virtual server is configured to use cookie-insert persistance. If I look at my cookies when I browse the site, I can see BigIP cookies. My concern is that in the administration webpage, under persistance records, every record is showing SOURCE ADDRESS AFFINITY. We recently tried to run a load balancing test, (one machine that makes multiple connections to the site to generate a load), and the BigIP failed to load balance any of the requests.

Does using the iRule not allow the default persistance method defined on the virtual server to take effect? Is there something else I’m missing here -- why isn’t cookie-insert persistance working?

Thanks in advance,

Ian

Could you please post the configuration for this virtual?

Thanks,

Brian

P.S. - Log in via the CLI as root (ssh/telnet) and type ‘more bigip.conf’

Gladly.

virtual www.mywebsite.com_HTTPS {

destination 63.104.68.144:https

snat automap

fallback persist source_addr

ip protocol tcp

profile http_features oneconnect tcp www.mywebsite.com

persist cookie_persistant_services

pool webnode3_pool

rule URL_Routing

vlans external enable

}

profile persist cookie_persistant_services {

defaults from cookie

mode cookie

across services enable

}

profile http http_features {

defaults from http

oneconnect transformations disable

compress selective

compress content type include none

compress content type exclude none

compress vary header disable

compress http 1.0 enable

compress gzip level 4

}

I don’t think the LB::server is available in the CLIENT_ACCEPTED event, so nothing is getting set, and thus, no default persistence.

To test your idea, I put a log line just after the set defpool command.

My local traffic log filled with lines like:

Rule URL_Routing : Default pool is: webnode3_pool

So it would seem that the default pool was being set correctly.

I was thinking:

What I want to happen is that should someone request http://www.mywebsite.com/cpm/, I want them to be processed by this rule, and then persisted to whatever node in the CPM_Pool that they get load balanced on to. We want our website to appear as one site, even though different URL paths are serviced by different web applications, running on different pools.

The way this is written though, I’m wondering if it’s possible that for each request, this iRule runs again, and they have the danger of being re-load balanced. If they were, the site would be quite broken though, we’d know right away. Perhaps the F5 detected this and is using Source Address Affinity? Does any of that sound reasonable? If so, what alternative solution might you suggest?

-Ian

If this is in testing, can you remove the fallback persistence profile? (Source IP)

Thanks,

Brian

P.S. - We’ll put it back once it is working correctly…

I can’t remove the fallback persistance profile right now -- this is a production enviornment. Possibly I could do it late tonight -- what were you looking to see? If it would stop persisting at all after that was turned off?

Right. I’ve never used a fallback persistence profile, and I wanted to take it out of the equation.

-Brian

One other thing, I think you need the following in your persistence profile… “cookie mode insert”

-Brian

P.S. - I think this is the missing piece. (It should work now).

P.S.S. - If you need verification, you will need to open a support case.

cookie mode insert is in the parent profile “cookie”, and I shouldn’t have to respecify it. No harm in doing so though, so I’ve done that. I have not seen any change yet though. =/

-Ian

What does “across services enable” do, and why do you have it set?

-Brian

It enables persistance across virtual servers.

For example, if VS1 puts you on pool1, node2, and then you go to VS2, pool1, you’ll get put back on node2, rather than re-balanced to the most availible node.

Unfortunately I think brandorr’s right here. This looks like a case for product support.

The rule looks to be in order, and sounds like it’s working properly. It sounds like there’s a configuration issue on the system (possibly) and we’re not equipped to troubleshoot all of the possible causes here.

-Colin

P.S. I would recommend, though, moving the “persist” line up above the “fallback persist” line…just for good measure.

Ok. I have sent an email to them. I tried here first because in the past I’ve found the devs and the crowd here pretty sharp. Thanks for the suggestions. =)

-Ian

There’s a detail I’ve left out here, that I’m wondering if it’s a factor.

I’m using the BigIP as a SSL Termination point. So most of the traffic that is hitting the F5 is doing so encrypted, and then it gets decrypted to be sent on to the webserver.

Can I still use the default persistance profiles on the virtual server for that, or do I need to use an iRule to insert my own cookies at that point?

-Ian

Actually, you can’t do cookie insertion on an SSL VIP unless the BigIP is doing the termination. (So it shouldn’t be an issue)

Here’s a thought… If your client already has a sourceIP persistence entry, I wonder if it will bother to do the cookie insert?

Also with “across services enable” if you have another VIP using the same pool that isn’t using cookie persistence, the pool’s persistence table could all get filled with source IP entries.

-Brian

P.S. - I suspect that if an incoming packet matches an existing persistence entry, it’s not going to care whether or not it is from the primary or secondary profile. (So you might need to flush the persistence table, and disable the cross service persistence for this to actual work).

That’s an interesting idea..

I do have all my VIP’s set to use Cookie_Persistant_Services, so that when a client connects to HTTP, and then jumps to HTTPS, he stays with the same node. But if cookie persistance were to fail and it made a source affinity entry, would it try again later?

Then again, it’s not like I have some Source Address Affinity persistance records. They are *all* Source Address Affinity.

-Ian

Disable persistence on the redirect VIP.

-Brian

P.S. - I added some notes to my previous post…

Okay okay. Hold on a sec. There should be no problems with SSL termination and cookie persistence. In fact, I don’t think there are any problems here at all.

You have configured cookie insert persistence with source address persistence as fallback. First, cookie insert persistence does not create a persistence record. The persistence information is stored in the cookie itself.

When a client connects to BIG-IP and makes a request, BIG-IP will look for a session persistence cookie. If one is found, it will direct the request to the same server as was used for previous connections. If no persistence cookie is found, it will fall back to source address persistence. This means that it will consult the session persistence table for an entry matching the source IP address. For the first request from a new client, no entry will be present, so BIG-IP will create one. This is why you see the SOURCE ADDRESS AFFINITY records.

As for the load balancing test, I would expect every request from the same source address to be directed to the same server. That’s source address persistence!

I hope this clears things up…

*OH*

Ok. That makes a lot of sense.

So the first time someone connects, since they have no cookie and no persistance record, they get a cookie, and a Source Address Affinity record. Then, every subsequent time they connect, they use their cookie, and get routed normally.

However, since that persistance record exists now, if someone else from that IP (Like someone else at the same office, behind a corporate firewall, or a test load box) connects to the BigIP, the BigIP will find their Source Address Affinity record (since they have no cookie to present), and will give them a new cookie, and route them to the same server as the first guy from their office.

Thus, everyone from one source address is being directed to the same node, even though cookie persistance is working. If I wanted to load balance requests from the same IP, I just need to turn off the Fallback Persistance Method.

Sound right?

-Ian