Forum Discussion

dedi_21505's avatar
dedi_21505
Icon for Nimbostratus rankNimbostratus
Nov 30, 2008

How to limin conection by MSISDN

Hi

 

Thank you In advance for your help.

 

 

Today I have This IRule

 

 

when HTTP_REQUEST {

 

if { [HTTP::header exists "MSISDN"] } {

 

persist uie [HTTP::header "MSISDN"]

 

}

 

}

 

 

This Rule figure as Time Out after 300 Sec since the last connection.

 

 

This Command “persist uie [HTTP::header "MSISDN"]” add the MSISDN as string to persist

 

My need is that I want to limit the max for MSISDN connection with IRule.

 

 

I wild like to know how to check if the MSISDN is already in the persistent table ?

 

 

Or to limit the connection In a different way.

 

 

8 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    With the different permutations of the persist command you should be able to perform a lookup as you're describing. The command you'd want to use is persist lookup.

     

     

    You can read more about the persist command options here - Click here

     

     

    HTH,

     

    Colin
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Sure. If you just want to perform a check to see if the info is in the persistence table already, you'd do:

     
     persist lookup uie [HTTP::header "MSISDN"]  
     

    So if you wanted to only perform a certain action if this record didn't exist, for example, you could do:

     
     set pEntry [persist lookup uie [HTTP::header "MSISDN"] ] 
     if { [string length $pEntry] <= 0 ] 
       ... 
     

    Does that help?

    Colin
  • Hi Colin

     

    Yes The Example Is great - Thank you for the Help

     

     

    I succedd to limit the tcp connection on the pool. but I can count only Active TCP connection but I want to know how much Active MSISDN I have Or the TOtal MSISDN in the persistent Table.

     

     

    Is there away tho know How much recorded I have in the persistent Table ?

     

    that how I will be abe to know how much MSISDN I have and I will limit by MSISDN.

     

     

    Here is My Rule

     

     

    when RULE_INIT {

     

     

    Set a global max for number of concurrent TCP connections

     

    set ::max_connections 1

     

     

    Set an HTML response to sent to clients who make a request while the VIP is over the max connection count

     

    set ::html_content_503 "over limit"

     

    set ::html_content_401 "NO MSISDN IN HEADER"

     

     

    Print debug messages to /var/log/ltm? 1=yes, 0=no

     

    set ::debug 1

     

     

    Initialize a counter for active connections (don't modify this)

     

    set ::active_connections 0

     

    }

     

    when HTTP_REQUEST {

     

    if { [HTTP::header exists "MSISDN"] } {

     

    If we're over the limit for this connection, send a response

     

    if {$::active_connections > $::max_connections}{

     

    Check if Hndset persist

     

    set pEntry [persist lookup uie [HTTP::header "MSISDN"] ]

     

    if { [string length $pEntry] >= 1 } {

     

    incr ::active_connections 1

     

    persist uie [HTTP::header "MSISDN"]

     

    if {$::debug}{log local0. "Handset persist - Enter (current: $::active_connections). Sent response to [IP::client_addr] , MSISDN [HTTP::header "MSISDN"]"}

     

    } else {

     

    Send a response

     

    HTTP::respond 503 content $::html_content_503

     

    if {$::debug}{log local0. "HTTP::respond - Service Unavailable content (current: $::active_connections). Sent response to [IP::client_addr] , MSISDN [HTTP::header "MSISDN"]"}

     

    Close the connection since CLIENT_CLOSED will decrease active_connections -1

     

    incr ::active_connections 1

     

    TCP::close

     

    Log a message to /var/log/ltm if debug is enabled

     

    }

     

    } else {

     

    We're not over the limit, so check if this is the first HTTP request on the TCP connection.

     

    persist uie [HTTP::header "MSISDN"]

     

    Increment the TCP connection count.

     

    incr ::active_connections 1

     

    if {$::debug}{log local0. "Add MSISDN (current: $::active_connections). Sent response to [IP::client_addr] , MSISDN [HTTP::header "MSISDN"]"}

     

    }

     

    } else {

     

    HTTP::respond 401 content $::html_content_401

     

    }

     

    }

     

     

     

    when CLIENT_CLOSED {

     

    A connection was closed, so decrement the global counter

     

    incr ::active_connections -1

     

    if {$::debug}{log local0. "CLIENT_CLOSED (current: $::active_connections). Sent response to [IP::client_addr]"}

     

    }

     

     

     

    Again Colin Thank you In Advance
  • Is there away tho know How much recorded I have in the persistent Table ?

     

  • Hi Dedi,

     

     

    There isn't a simple mechanism for counting session table entries from an iRule. Check this post for details on requesting that F5 add this functionality. Please open a support case with F5 if you want this functionality.

     

     

    http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=2517426340

     

     

    And I described a possible workaround in this thread:

     

     

    http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=30234&view=topic30337

     

     

    Aaron
  • Actually Dedi, you'll run into the same issue with your iRule which abeny did in his iRule (Click here). You're incrementing the connection count for every HTTP request and only decrementing the count once when the client to VIP TCP connection is closed. If the client makes multiple HTTP requests on the same TCP connection, your count won't be accurate.

     

     

    Aaron
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    There is a relatively simple fix for that though, detailed in the link that Aaron posted.

     

     

    Colin