Squid Programmer Guide

Bob Gisiger ()

Xiuduan Fang ()

Squid information can be obtained from their website

We have modified squid to dynamically control circuit connections on the CHEEAH network. After observing the sequence of functions called during a web request, we determined that the function peerGetSomeNeighbor[x1] would be a good place to insert the circuit testing and setup functionality, since this function is called for every web request that does not result in a cache hit.

Using a program such as Source Insight to view the squid code is highly recommended since you can trace the function call sequence and search in multiple files among other helpful features.

The latest version of modified Squid code is on losa-pc1 /home/mv/squid-2.6.STABLE7.cheetah.tar.gz

The following command to create a .tar.gz file: tar cvzf squid-2.6.STABLE7.cheetah.tar.gz squid-2.6.STABLE7.cheetah

Configuration and Make:

To build the modified package, we changed

configure.inlines 679-692[x2](located in squid-2.6.STABLE7.cheetah)

Makefile.amlines 33-37, and 249

We modified configure.in to include a new feature --enable-circuit and to define two new options USE_CIRCUIT and ENABLE_CIRCUIT. If the configure script is run with the parameter --enable-circuit, then USE_CIRCUIT and ENABLE_CIRCUIT will be defined. ENABLE_CIRCUIT is used in Makefile.am to enable the compilation of cheetah.c. USE_CIRCUIT is used within the original squid files to activate certain sections we have added in main.c and peer_select.c.

We also changed src/Makefile.am to include the new source file cheetah.c. Then we ran autoconf to generate the new configure file and ran automake to generate the new Makefile.in

Installation guide for the modified package:

1. Run ./configure --enable-circuit to generate Makefiles that include the modified feature.

2. Run make

Addedsource header and code:

cheetah.h

The file cheetah.h includes the declaration of the circuit_status struct that is used to keep track of circuit information such as the interface name, whether the circuit is in use, the session ID, the owner of the circuit, the bandwidth, the destination and the expiration time. It also contains the prototypes for three functions used within the original squid files. The function attemptCircuit is called in peer_select.c to handle circuit setup.

The function attemptCTCP function is called in comm..c to set the congestion-control algorithm of a socket to CTCP. Another function monitorCircuitInterface[x3] is called in main.c every cheetahMonitorPeriod (default is 60 seconds) to check whether the circuit is being utilized.

cheetah.c

The file cheetah.c implements the functions defined in cheetah.h.

Modified Squid code:

All files modified are location in squid-2.6.STABLE7.cheetah/src unless otherwise noted.

main.clines 812-816

The main() function in the file main.c is modified to add a signal on the function monitorCircuitInterface, and then set an alarm for the cheetahMonitorPeriod (default period is 60 seconds). This means that the function monitorCircuitInterface is run every 60 seconds to check if the circuit is still in use. This function observes the number of packets that were received and transmitted by the circuit interface over the last period. If this number is under a certain threshold (10 packets by default) then the circuit is considered to no longer be in use and is released.

peer_select.clines 364-376

The file peer_select.c is modified in the function peerGetSomeNeighbor to handle the circuit setup upon receiving a web request. It checks if the peer object p is the proper parent cache for the given request using the function peerAllowedToUse. If it is then it calls the attemptCircuit function. If there is a circuit, then the web request will be served the circuit by calling the function peerAddFwdServer to add the circuit IP address of the remote proxy into the parent list. This parent will then be used to forward the web request to and the circuit will be used for the resulting file transfer.Otherwise, the request will trigger a circuit setup attempt but to avoid the call setup delay, the request will be served by the Internet. peerAddFwdServer.

comm.c

This file is modified to call the attemptCTCP function. Two functions in comm.c comm_connect_addr and comm_accept have been touched.

Future work:

  1. In squid.conf or a separate configuration file, use a directive circuit_rate to specify circuit-rate. (Will do)

[x1]This function may not be the best place to insert the CHEETAH code. The problem is that when netdb is enabled, this function will be called periodically even there is no web request.

[x2]The line numbers may change as the code is updated. Search “modified by …” for a confirmation.

[x3]Currently this function is not working.