This is the default back-end for DHCP Cluster. It is based on “Hypersonic DB” which is a simple and very fast database in pure Java, suitable for small to medium size deployments.
This back-end allows for fast deployment of end-to-end DHCP solutions without installing or managing a separate database (MySQL, Oracle…).
This back-end offers high brute performance, but is not suitable for high-availability cluster solutions or highly scalable services.
The Hsqldb back-end is kept as small and simple as possible.
It is currently only used to keep track of client leases. All other configuration parameters are stored in a single XML file.
There is basically only one persistant table: T_LEASE, which stores usage of IP addresses.
Other non-persistent table are created in-memory for lease calculation and OFFER tracking:
During debug and development, it is interesting to run the db in “Server” mode, which opens a server socket. The front-end connects via this socket despite the fact that the db runs in the same VM as the front-end. This allows for external client connection for manual data inspection. For maximum performance, you can swith to in-process mode where communication goes directly without going through network layers; this however prevents external client connection.
TODO : howto and performance gain
The table T_LEASE is kept entirely in-memory by default for simpliest and maximum performance. Data commited is however immediately written to disk into a SQL script. This SQL script is completely reloaded at next startup.
If the lease volume increases widely, it can be interesting to switch this table to cached mode, where the data is kept on disk and only partially cached in memory. Performance will be slightly reduced but server restart will be faster.
TODO
| Table T_LEASE | ||
|---|---|---|
| IP | BIGINT PK | binary (long) representation of the IPv4 address of the lease |
| CREATE_DATE | TIMESTAMP | time when the lease was initially created for this client (mac) |
| UPDATE_DATE | TIMESTAMP | time when the lease was last updated |
| EXPIRE_DATE | TIMESTAMP | end of lease time |
| RECYCLE_DATE | TIMESTAMP | time when the IP can be reallocated (including a secure margin to take into account clock drifts) |
| MAC | VARCHAR | MAC address of the client |
| STATUS | INTEGER | current status of the lease -1: ABANDONED (address not usable) 0:FREE 1:OFFERED 2:USED |
| Table T_POOL_SET | ||
|---|---|---|
| SET_ID | BIGINT PK | id (long) of the pool set |
| Table T_POOL | ||
|---|---|---|
| START_IP | BIGINT PK | start address of the pool as binary (long) IPv4 address |
| END_IP | BIGINT | end address of the pool as binary (long) IPv4 address |
| CLASSES | INTEGER | [reserved for future use] |
| SET_ID | BIGINT | foreign key to T_POOL_SET entity |
| T_BUBBLE | ||
|---|---|---|
| BUBBLE_ID | INTEGER PK | auto-increment identifier |
| POOL_ID | BIGINT | foreign key to T_POOL entity |
| START_IP | BIGINT | start address of the free address bubble |
| END_IP | BIGINT | end address of the free address bubble |
The first sequence in IP address allocation is the client sending a DHCPDiscover request and the server sending back a DHCPOffer with a (hopefully) proposed IP address.
The internal sequence when receiving a DHCPDiscover is as follows:
This stored procedure is responsible for finding a suitable IP address for the client.
T_POOL_SET, T_POOL and T_BUBBLE are populated and consistentT_POOL rangesT_BUBBLE rangesOFFERED or USED address in any T_BUBBLE rangeT_BUBBLE range (start address > end address)poolId id of the POOL_SET, hence the address rangesmacHex hex representation of the client's MAC address (must not be null)iccQuota maximum number of addresses allowed of this icc, or 0 to ignore iccicc icc identifier of the client, must not be null if iccQuota is > 0offerTime number of seconds to reserve OFFER before reallocating addressT_LEASE table with client's Mac address and Status is not FREE or ABANDONED,T_LEASE table with the client's ICC, then count active leasesT_BUBBLE to find the first free bubble, retrieve the first address then update the bubble: increase its start address or delete it if it becomes emptyT_LEASE row is created withIP = offered addressUPDATE_DATE = nowCREATION_DATE ⇐ UPDATE_DATEEXPIRATION_DATE >= now+offerTimeRECYCLE_DATE >= EXPIRATION_DATEMAC = client's mac addressICC = client's ICC identifier (if present)STATUS = OFFERED or USEDThis stored procedure is responsible for allocating the final IP address for the client.
poolId id of the POOL_SET, hence the address rangesrequestedIp IP address requested by clientleaseTime number of seconds to reserve the lease in DBmargin percentage of margin for the lease time before reallocated, this is necessary for potential clock drifts between client and server (e.g. 30 means allocated 30% more time)macHex hex representation of the client's MAC address (must not be null)optimisticAllocation whether we allow a client to request a free address even if there was no previous OFFERThe first step is to analyze both the client request and the database state. This lets us determine what actions should be done on the db, and which kind of response to send back to the client.
| updateLease | boolean | true= lease already exists in db, we should update it false=we need to create a fresh new lease in db |
|---|---|---|
| updateBubble | boolean | true= we need to adjust bubbles because the address lies within a free bubble (only in optimistic mode) false=bubbles are untouched |
| renewal | boolean | true= this is a lease renewal (we don't touch the CREATE_DATE) false= fresh new lease, this address was not owned by this client |
Return code if successful >= 0 (bit array)
When leases RECYCLE_DATE is past, they are eligible for garbage collection. The garbage collector is called every 5 minutes to reclaim free leases.
Design issue: there can be a significant delay between the time a lease has expired and the time when the address is free to be allocated to another client. The trade-off is in favor of runtime performance causing potentially some address starving in extreme conditions. However, a specific “urgent” clean-up may be introduced in case of an free address starvation.