package com.theorem.radserver3.examples.server; import com.theorem.radserver3.*; import com.theorem.radserver3.radutil.*; import com.theorem.misc.*; import java.util.*; /** * Proxy implementation example of using the ProxyInfo methods to check round trip * times. * This simple example adds one to the maximum allowable packets if the server * is handling the load, drops the number of packets by 2/3rds if the time limit is exceeded. * This example works as a drop in replacement for the existing 'Proxy.java' class. *

* This example takes a fairly simple approach that if the round trip time is very good * the number of packets should be increased. This could result in never increasing * to full potential, but then this is a simple example. */ public class ProxyThrottle extends ProxyImpl { // Lower limit on packets. static final int MINSESSIONS = 10; // Incremental number of packets when increasing. static final int INCRSESSIONS = 10; // Upper limit on round trip time - preferably set to the maximum time the client // will wait for a response. This is milliseconds. static final long MAXTIME = 6000; // Lower limit on round trip time - if a packet returns within this time we can increase // the maximum number of packets. This is milliseconds. static final long MINTIME = 3000; // Maximum number of packets, we can never exceed this. int maxLimit = 100; // Logs. LogImpl dbg, svr; // Once round trip timing is enabled we don't perform the enabling method again. // Assume it has been disabled (never called) boolean roundTripDisabled = true; /** * Constructor. * @param conf Configuration object. */ public ProxyThrottle(Configure conf) { super(); // Get the maximum limit from the configured value. maxLimit = conf.maxSessions; } /** * Intialize the logs for this class. * * @param svrLog Server log object. * @param dbgLog Debug log object. */ public void logs(LogImpl svrLog, LogImpl dbgLog) { dbg = dbgLog; svr = svrLog; } /** * Change a request's proxy information. * * @param prx ProxyInfo object from server. */ public void changeRequest(ProxyInfo prx) throws AccessDropException, AccessRejectException { if (roundTripDisabled) { // Enable round trip timing. prx.setRoundTripTiming(true); roundTripDisabled = false; } } /** * Change proxy response routing. * * @param prx ProxyInfo object from server. */ public void changeResponse(ProxyInfo prx) throws AccessDropException, AccessRejectException { long t = prx.getRoundTripTiming(); String ts = prx.getRoundTripTimingString(); svr.write("Round trip timing: " + t + " or " + ts); if (t > MAXTIME) { // Timeout is too long, throttle back. RADIUSServer server = prx.getRADIUSServer(); int currentMax = server.getMaximumPackets(); int newMax = currentMax / 2; newMax = newMax < MINSESSIONS ? MINSESSIONS : newMax; server.setMaximumPackets(newMax); } else if (t < MINTIME) { // If the condition has improved after a throttle down restore things somewhat. RADIUSServer server = prx.getRADIUSServer(); int currentMax = server.getMaximumPackets(); int newMax = currentMax + INCRSESSIONS; newMax = newMax > maxLimit ? maxLimit : newMax; server.setMaximumPackets(newMax); } } }