Forum Discussion

Absarkhan_15403's avatar
Absarkhan_15403
Icon for Nimbostratus rankNimbostratus
Aug 04, 2014

Triggering an action based on TCP Connections

Is it possible to trigger an action on the base of how many tcp connection a specific VIP has under a http request? If yes how to use the variable in order to define it?

 

Many Thanks in advance

 

  • Can the sessions be replaced with connectionswith the way you are prescribing?

     

    if you want to track tcp connection, you may increase the counter in CLIENT_ACCEPTED and decrease it in CLIENT_CLOSED.

     

  • Is it possible to trigger an action on the base of how many tcp connection a specific VIP has under a http request?

     

    what action do you want?

     

    you can count number of current tcp connections to virtual server using table sessiondb (table irule command) and take an action when the number reaches threshold.

     

    • Absarkhan_15403's avatar
      Absarkhan_15403
      Icon for Nimbostratus rankNimbostratus
      Hi Nitass, I am trying to run below iRule to display a waiting room page when a certain threshold is reached. Currently the threshold is "number of sessions", however I think it is more logical to track the "number to TCP connections" instead. Can the sessions be replaced with connectionswith the way you are prescribing? Many Thanks for your help.
    • Absarkhan_15403's avatar
      Absarkhan_15403
      Icon for Nimbostratus rankNimbostratus
      when HTTP_REQUEST priority 1 { set static::maxActiveClients "[class search -all -value datagroup_selfridges_waitingroom starts_with "max_active_clients"]" set subtableName "sessionLimit" set sessionCookieName "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_cookie_prefix"]" set holdingPage "[class search -all -value datagroup_selfridges_waitingroom starts_with "holding_page_url"]" set static::sessionTimeout "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_timeout"]" set need_cookie 0 if {[HTTP::cookie exists $sessionCookieName]} { set client_id [HTTP::cookie $sessionCookieName] set sessiondata [table lookup -subtable $subtableName $client_id] if { $sessiondata != "" } { log local0. "Valid session $client_id - continuing" return } } log local0. "No session. Checking for free slot (Max $static::maxActiveClients)" set sessionCount [table keys -subtable $subtableName -count] log local0. "No session. Checking for free slot (Current $sessionCount)" if {$sessionCount < $static::maxActiveClients} { set need_cookie 1 set client_id [format "%08d" [expr { int(1000000000 * rand()) }]] set sessionValue [IP::client_addr] table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout log local0. "New Session ($client_id) added value $sessionValue Timeout $static::sessionTimeout" } else { HTTP::redirect $holdingPage } } when HTTP_RESPONSE priority 1 { if {$need_cookie == 1} { HTTP::cookie insert name $sessionCookieName value $client_id path "/" } }
  • Is it possible to trigger an action on the base of how many tcp connection a specific VIP has under a http request?

     

    what action do you want?

     

    you can count number of current tcp connections to virtual server using table sessiondb (table irule command) and take an action when the number reaches threshold.

     

    • Absarkhan_15403's avatar
      Absarkhan_15403
      Icon for Nimbostratus rankNimbostratus
      Hi Nitass, I am trying to run below iRule to display a waiting room page when a certain threshold is reached. Currently the threshold is "number of sessions", however I think it is more logical to track the "number to TCP connections" instead. Can the sessions be replaced with connectionswith the way you are prescribing? Many Thanks for your help.
    • Absarkhan_15403's avatar
      Absarkhan_15403
      Icon for Nimbostratus rankNimbostratus
      when HTTP_REQUEST priority 1 { set static::maxActiveClients "[class search -all -value datagroup_selfridges_waitingroom starts_with "max_active_clients"]" set subtableName "sessionLimit" set sessionCookieName "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_cookie_prefix"]" set holdingPage "[class search -all -value datagroup_selfridges_waitingroom starts_with "holding_page_url"]" set static::sessionTimeout "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_timeout"]" set need_cookie 0 if {[HTTP::cookie exists $sessionCookieName]} { set client_id [HTTP::cookie $sessionCookieName] set sessiondata [table lookup -subtable $subtableName $client_id] if { $sessiondata != "" } { log local0. "Valid session $client_id - continuing" return } } log local0. "No session. Checking for free slot (Max $static::maxActiveClients)" set sessionCount [table keys -subtable $subtableName -count] log local0. "No session. Checking for free slot (Current $sessionCount)" if {$sessionCount < $static::maxActiveClients} { set need_cookie 1 set client_id [format "%08d" [expr { int(1000000000 * rand()) }]] set sessionValue [IP::client_addr] table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout log local0. "New Session ($client_id) added value $sessionValue Timeout $static::sessionTimeout" } else { HTTP::redirect $holdingPage } } when HTTP_RESPONSE priority 1 { if {$need_cookie == 1} { HTTP::cookie insert name $sessionCookieName value $client_id path "/" } }
  • Hi Nitass,

     

    I am trying to run below iRule to display a waiting room page when a certain threshold is reached. Currently the threshold is "number of sessions", however I think it is more logical to track the "number to TCP connections" instead.

     

    Can the sessions be replaced with connectionswith the way you are prescribing?

     

    Many Thanks for your help.

     

  • when HTTP_REQUEST priority 1 {
    set static::maxActiveClients "[class search -all -value datagroup_selfridges_waitingroom starts_with "max_active_clients"]"
    set subtableName "sessionLimit"
    set sessionCookieName "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_cookie_prefix"]"
    set holdingPage "[class search -all -value datagroup_selfridges_waitingroom starts_with "holding_page_url"]"
    set static::sessionTimeout "[class search -all -value datagroup_selfridges_waitingroom starts_with "session_timeout"]"
    set need_cookie 0
    if {[HTTP::cookie exists $sessionCookieName]} { 
    set client_id [HTTP::cookie $sessionCookieName]
    set sessiondata [table lookup -subtable $subtableName $client_id]
    if { $sessiondata != "" } {
     log local0. "Valid session $client_id - continuing"
    return 
    } 
    }
     log local0. "No session. Checking for free slot (Max $static::maxActiveClients)"
    set sessionCount [table keys -subtable $subtableName -count]
     log local0. "No session. Checking for free slot (Current $sessionCount)"
    if {$sessionCount < $static::maxActiveClients} {
    set need_cookie 1
    set client_id [format "%08d" [expr { int(1000000000 * rand()) }]] 
    set sessionValue [IP::client_addr]
    table add -subtable $subtableName $client_id $sessionValue $static::sessionTimeout
    log local0. "New Session ($client_id) added value $sessionValue Timeout $static::sessionTimeout"
    } else {
    HTTP::redirect $holdingPage
    }
    }
    when HTTP_RESPONSE priority 1 {
    if {$need_cookie == 1} {
    HTTP::cookie insert name $sessionCookieName value $client_id path "/"
    }
    }
    
  • Can the sessions be replaced with connectionswith the way you are prescribing?

     

    if you want to track tcp connection, you may increase the counter in CLIENT_ACCEPTED and decrease it in CLIENT_CLOSED.

     

    • Absarkhan_15403's avatar
      Absarkhan_15403
      Icon for Nimbostratus rankNimbostratus
      There is a data group as you have probably found already where this iRule takes the values from. Such as; set holdingPage "[class search -all -value datagroup_selfridges_waitingroom starts_with "holding_page_url"]" Can you kindly elaborate a little regarding tracking tcp connections in a table? I don't think I have found it so far. Regards
  • Can the sessions be replaced with connectionswith the way you are prescribing?

     

    if you want to track tcp connection, you may increase the counter in CLIENT_ACCEPTED and decrease it in CLIENT_CLOSED.

     

    • Absarkhan_15403's avatar
      Absarkhan_15403
      Icon for Nimbostratus rankNimbostratus
      There is a data group as you have probably found already where this iRule takes the values from. Such as; set holdingPage "[class search -all -value datagroup_selfridges_waitingroom starts_with "holding_page_url"]" Can you kindly elaborate a little regarding tracking tcp connections in a table? I don't think I have found it so far. Regards