001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.server.dhcp.store;
021
022
023import java.net.InetAddress;
024
025import org.apache.directory.server.dhcp.DhcpException;
026import org.apache.directory.server.dhcp.messages.HardwareAddress;
027import org.apache.directory.server.dhcp.options.OptionsField;
028import org.apache.directory.server.dhcp.service.Lease;
029
030
031/**
032 * 
033 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
034 */
035public interface DhcpStore
036{
037    /**
038     * Find a lease to offer in response to a DHCPDISCOVER request.
039     * <p>
040     * The lease to offer should be determined by an algorithme like the
041     * following:
042     * <ul>
043     * <li> Try to find an existing lease for the given hardware address. The
044     * lease may be either ACTIVE or EXPIRED.
045     * <li>Try to find a lease which has been explicitely dedicated to the
046     * given hardware address.
047     * <li>Try to get a lease from a pool of leases. If the client requested a
048     * specific address, the request should be honored, if possible. Otherwise
049     * the selection of an address should be based on the selection base address
050     * and may be refined using the supplied options.
051     * </ul>
052     * <p>
053     * If the requestedLeaseTime is &gt;= 0, the validity duration of the returned
054     * lease must be updated, so that the lease is valid for at least the
055     * specified time. The duration may, however, be constrained by a configured
056     * maximum lease time.
057     * 
058     * @param hardwareAddress
059     *            hardwareAddress the hardware address of the client requesting
060     *            the lease.
061     * @param requestedAddress
062     *            the address requested by the client or <code>null</code> if
063     *            the client did not request a specific address.
064     * @param selectionBase
065     *            the address on which to base the selection of a lease from a
066     *            pool, i.e. either the address of the interface on which the
067     *            request was received or the address of a DHCP relay agent.
068     * @param requestedLeaseTime
069     *            the lease time in milliseconds as requested by the client, or
070     *            -1 if the client did not request a specific lease time.
071     * @param options
072     *            the supplied DHCP options. Lease selection may be refined by
073     *            using those options
074     * @return a lease or <code>null</code> if no matching lease was found.
075     * @throws DhcpException
076     */
077    Lease getLeaseOffer( HardwareAddress hardwareAddress, InetAddress requestedAddress, InetAddress selectionBase,
078        long requestedLeaseTime, OptionsField options ) throws DhcpException;
079
080
081    /**
082     * Retrieve an existing lease from the dhcp store.
083     * 
084     * @param hardwareAddress
085     * @param requestedAddress
086     * @param selectionBase
087     * @param requestedLeaseTime
088     * @param options
089     * @return Lease
090     * @throws DhcpException 
091     */
092    Lease getExistingLease( HardwareAddress hardwareAddress, InetAddress requestedAddress, InetAddress selectionBase,
093        long requestedLeaseTime, OptionsField options ) throws DhcpException;
094
095
096    /**
097     * Release the specified lease. 
098     * 
099     * @param lease
100     */
101    void releaseLease( Lease lease );
102}