You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/08/05 19:53:20 UTC

svn commit: r801338 [2/3] - in /directory/apacheds/trunk: protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/messages/ protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/options/ protocol-dhcp/src/main/java/org/apache/directory/serv...

Modified: directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/service/StoreBasedDhcpService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/service/StoreBasedDhcpService.java?rev=801338&r1=801337&r2=801338&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/service/StoreBasedDhcpService.java (original)
+++ directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/service/StoreBasedDhcpService.java Wed Aug  5 17:53:19 2009
@@ -1,290 +1,290 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.directory.server.dhcp.service;
-
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-
-import org.apache.directory.server.dhcp.DhcpException;
-import org.apache.directory.server.dhcp.messages.DhcpMessage;
-import org.apache.directory.server.dhcp.messages.MessageType;
-import org.apache.directory.server.dhcp.options.AddressOption;
-import org.apache.directory.server.dhcp.options.OptionsField;
-import org.apache.directory.server.dhcp.options.dhcp.ClientIdentifier;
-import org.apache.directory.server.dhcp.options.dhcp.IpAddressLeaseTime;
-import org.apache.directory.server.dhcp.options.dhcp.MaximumDhcpMessageSize;
-import org.apache.directory.server.dhcp.options.dhcp.ParameterRequestList;
-import org.apache.directory.server.dhcp.options.dhcp.RequestedIpAddress;
-import org.apache.directory.server.dhcp.options.dhcp.ServerIdentifier;
-import org.apache.directory.server.dhcp.store.DhcpStore;
-
-
-/**
- * A default implementation of the DHCP service. Does the tedious low-level
- * chores of handling DHCP messages, but delegates the lease-handling to a
- * supplied DhcpStore.
- * 
- * @see org.apache.directory.server.dhcp.store.DhcpStore
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
- */
-public class StoreBasedDhcpService extends AbstractDhcpService
-{
-    private final DhcpStore dhcpStore;
-
-
-    public StoreBasedDhcpService(DhcpStore dhcpStore)
-    {
-        this.dhcpStore = dhcpStore;
-    }
-
-
-    /**
-     * Try to get an existing lease. The lease may have been created during
-     * earlier DHCP negotiations or a recent DHCPDISCOVER.
-     * 
-     * @param clientAddress
-     * @param request
-     * @return
-     * @throws DhcpException
-     */
-    private Lease getExistingLease( InetSocketAddress clientAddress, DhcpMessage request ) throws DhcpException
-    {
-        // determine requested lease time
-        IpAddressLeaseTime requestedLeaseTimeOption = ( IpAddressLeaseTime ) request.getOptions().get(
-            IpAddressLeaseTime.class );
-        long requestedLeaseTime = null != requestedLeaseTimeOption ? requestedLeaseTimeOption.getIntValue() * 1000
-            : -1L;
-
-        // try to get the lease (address) requested by the client
-        InetAddress requestedAddress = null;
-        AddressOption requestedAddressOption = ( AddressOption ) request.getOptions().get( RequestedIpAddress.class );
-        if ( null != requestedAddressOption )
-            requestedAddress = requestedAddressOption.getAddress();
-        if ( null == requestedAddress )
-            requestedAddress = request.getCurrentClientAddress();
-
-        InetAddress selectionBase = determineSelectionBase( clientAddress, request );
-
-        Lease lease = dhcpStore.getExistingLease( request.getHardwareAddress(), requestedAddress, selectionBase,
-            requestedLeaseTime, request.getOptions() );
-
-        if ( null == lease )
-            return null;
-
-        return lease;
-    }
-
-
-    /**
-     * Determine a lease to offer in response to a DHCPDISCOVER message.
-     * <p>
-     * When a server receives a DHCPDISCOVER message from a client, the server
-     * chooses a network address for the requesting client. If no address is
-     * available, the server may choose to report the problem to the system
-     * administrator. If an address is available, the new address SHOULD be
-     * chosen as follows:
-     * <ul>
-     * <li> The client's current address as recorded in the client's current
-     * binding, ELSE
-     * <li> The client's previous address as recorded in the client's (now
-     * expired or released) binding, if that address is in the server's pool of
-     * available addresses and not already allocated, ELSE
-     * <li> The address requested in the 'Requested IP Address' option, if that
-     * address is valid and not already allocated, ELSE
-     * <li> A new address allocated from the server's pool of available
-     * addresses; the address is selected based on the subnet from which the
-     * message was received (if 'giaddr' is 0) or on the address of the relay
-     * agent that forwarded the message ('giaddr' when not 0).
-     * </ul>
-     * 
-     * @param clientAddress
-     * @param request
-     * @return
-     */
-    private Lease getLeaseOffer( InetSocketAddress clientAddress, DhcpMessage request ) throws DhcpException
-    {
-        // determine requested lease time
-        IpAddressLeaseTime requestedLeaseTimeOption = ( IpAddressLeaseTime ) request.getOptions().get(
-            IpAddressLeaseTime.class );
-        long requestedLeaseTime = null != requestedLeaseTimeOption ? requestedLeaseTimeOption.getIntValue() * 1000
-            : -1L;
-
-        // try to get the lease (address) requested by the client
-        InetAddress requestedAddress = null;
-        AddressOption requestedAddressOption = ( AddressOption ) request.getOptions().get( RequestedIpAddress.class );
-        if ( null != requestedAddressOption )
-            requestedAddress = requestedAddressOption.getAddress();
-
-        InetAddress selectionBase = determineSelectionBase( clientAddress, request );
-
-        Lease lease = dhcpStore.getLeaseOffer( request.getHardwareAddress(), requestedAddress, selectionBase,
-            requestedLeaseTime, request.getOptions() );
-
-        return lease;
-    }
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.service.AbstractDhcpService#handleRELEASE(java.net.InetSocketAddress,
-     *      java.net.InetSocketAddress,
-     *      org.apache.directory.server.dhcp.messages.DhcpMessage)
-     */
-    protected DhcpMessage handleRELEASE( InetSocketAddress localAddress, InetSocketAddress clientAddress,
-        DhcpMessage request ) throws DhcpException
-    {
-        // check server ident
-        AddressOption serverIdentOption = ( AddressOption ) request.getOptions().get( ServerIdentifier.class );
-        if ( null != serverIdentOption && serverIdentOption.getAddress().isAnyLocalAddress() )
-            return null; // not me?! FIXME: handle authoritative server case
-
-        Lease lease = getExistingLease( clientAddress, request );
-
-        DhcpMessage reply = initGeneralReply( localAddress, request );
-
-        if ( null == lease )
-        {
-            // null lease? send NAK
-            // FIXME...
-            reply.setMessageType( MessageType.DHCPNAK );
-            reply.setCurrentClientAddress( null );
-            reply.setAssignedClientAddress( null );
-            reply.setNextServerAddress( null );
-        }
-        else
-        {
-            dhcpStore.releaseLease( lease );
-
-            // lease Ok, send ACK
-            // FIXME...
-            reply.getOptions().merge( lease.getOptions() );
-
-            reply.setAssignedClientAddress( lease.getClientAddress() );
-            reply.setNextServerAddress( lease.getNextServerAddress() );
-
-            // fix options
-            OptionsField options = reply.getOptions();
-
-            // these options must not be present
-            options.remove( RequestedIpAddress.class );
-            options.remove( ParameterRequestList.class );
-            options.remove( ClientIdentifier.class );
-            options.remove( MaximumDhcpMessageSize.class );
-
-            // these options must be present
-            options.add( new IpAddressLeaseTime( ( lease.getExpires() - System.currentTimeMillis() ) / 1000L ) );
-
-            stripUnwantedOptions( request, options );
-        }
-        return reply;
-
-    }
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.service.AbstractDhcpService#handleDISCOVER(java.net.InetSocketAddress,
-     *      org.apache.directory.server.dhcp.messages.DhcpMessage)
-     */
-    protected DhcpMessage handleDISCOVER( InetSocketAddress localAddress, InetSocketAddress clientAddress,
-        DhcpMessage request ) throws DhcpException
-    {
-        Lease lease = getLeaseOffer( clientAddress, request );
-
-        // null lease? don't offer one.
-        if ( null == lease )
-            return null;
-
-        DhcpMessage reply = initGeneralReply( localAddress, request );
-
-        reply.getOptions().merge( lease.getOptions() );
-
-        reply.setMessageType( MessageType.DHCPOFFER );
-
-        reply.setAssignedClientAddress( lease.getClientAddress() );
-        reply.setNextServerAddress( lease.getNextServerAddress() );
-
-        // fix options
-        OptionsField options = reply.getOptions();
-
-        // these options must not be present
-        options.remove( RequestedIpAddress.class );
-        options.remove( ParameterRequestList.class );
-        options.remove( ClientIdentifier.class );
-        options.remove( MaximumDhcpMessageSize.class );
-
-        // these options must be present
-        options.add( new IpAddressLeaseTime( ( lease.getExpires() - System.currentTimeMillis() ) / 1000L ) );
-
-        stripUnwantedOptions( request, options );
-
-        return reply;
-    }
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.service.AbstractDhcpService#handleREQUEST(java.net.InetSocketAddress,
-     *      org.apache.directory.server.dhcp.messages.DhcpMessage)
-     */
-    protected DhcpMessage handleREQUEST( InetSocketAddress localAddress, InetSocketAddress clientAddress,
-        DhcpMessage request ) throws DhcpException
-    {
-        // check server ident
-        AddressOption serverIdentOption = ( AddressOption ) request.getOptions().get( ServerIdentifier.class );
-        if ( null != serverIdentOption && serverIdentOption.getAddress().isAnyLocalAddress() )
-            return null; // not me?! FIXME: handle authoritative server case
-
-        Lease lease = getExistingLease( clientAddress, request );
-
-        DhcpMessage reply = initGeneralReply( localAddress, request );
-
-        if ( null == lease )
-        {
-            // null lease? send NAK
-            reply.setMessageType( MessageType.DHCPNAK );
-            reply.setCurrentClientAddress( null );
-            reply.setAssignedClientAddress( null );
-            reply.setNextServerAddress( null );
-        }
-        else
-        {
-            // lease Ok, send ACK
-            reply.getOptions().merge( lease.getOptions() );
-
-            reply.setAssignedClientAddress( lease.getClientAddress() );
-            reply.setNextServerAddress( lease.getNextServerAddress() );
-
-            // fix options
-            OptionsField options = reply.getOptions();
-
-            // these options must not be present
-            options.remove( RequestedIpAddress.class );
-            options.remove( ParameterRequestList.class );
-            options.remove( ClientIdentifier.class );
-            options.remove( MaximumDhcpMessageSize.class );
-
-            // these options must be present
-            options.add( new IpAddressLeaseTime( ( lease.getExpires() - System.currentTimeMillis() ) / 1000L ) );
-
-            stripUnwantedOptions( request, options );
-        }
-        return reply;
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.dhcp.service;
+
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import org.apache.directory.server.dhcp.DhcpException;
+import org.apache.directory.server.dhcp.messages.DhcpMessage;
+import org.apache.directory.server.dhcp.messages.MessageType;
+import org.apache.directory.server.dhcp.options.AddressOption;
+import org.apache.directory.server.dhcp.options.OptionsField;
+import org.apache.directory.server.dhcp.options.dhcp.ClientIdentifier;
+import org.apache.directory.server.dhcp.options.dhcp.IpAddressLeaseTime;
+import org.apache.directory.server.dhcp.options.dhcp.MaximumDhcpMessageSize;
+import org.apache.directory.server.dhcp.options.dhcp.ParameterRequestList;
+import org.apache.directory.server.dhcp.options.dhcp.RequestedIpAddress;
+import org.apache.directory.server.dhcp.options.dhcp.ServerIdentifier;
+import org.apache.directory.server.dhcp.store.DhcpStore;
+
+
+/**
+ * A default implementation of the DHCP service. Does the tedious low-level
+ * chores of handling DHCP messages, but delegates the lease-handling to a
+ * supplied DhcpStore.
+ * 
+ * @see org.apache.directory.server.dhcp.store.DhcpStore
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
+ */
+public class StoreBasedDhcpService extends AbstractDhcpService
+{
+    private final DhcpStore dhcpStore;
+
+
+    public StoreBasedDhcpService(DhcpStore dhcpStore)
+    {
+        this.dhcpStore = dhcpStore;
+    }
+
+
+    /**
+     * Try to get an existing lease. The lease may have been created during
+     * earlier DHCP negotiations or a recent DHCPDISCOVER.
+     * 
+     * @param clientAddress
+     * @param request
+     * @return
+     * @throws DhcpException
+     */
+    private Lease getExistingLease( InetSocketAddress clientAddress, DhcpMessage request ) throws DhcpException
+    {
+        // determine requested lease time
+        IpAddressLeaseTime requestedLeaseTimeOption = ( IpAddressLeaseTime ) request.getOptions().get(
+            IpAddressLeaseTime.class );
+        long requestedLeaseTime = null != requestedLeaseTimeOption ? requestedLeaseTimeOption.getIntValue() * 1000
+            : -1L;
+
+        // try to get the lease (address) requested by the client
+        InetAddress requestedAddress = null;
+        AddressOption requestedAddressOption = ( AddressOption ) request.getOptions().get( RequestedIpAddress.class );
+        if ( null != requestedAddressOption )
+            requestedAddress = requestedAddressOption.getAddress();
+        if ( null == requestedAddress )
+            requestedAddress = request.getCurrentClientAddress();
+
+        InetAddress selectionBase = determineSelectionBase( clientAddress, request );
+
+        Lease lease = dhcpStore.getExistingLease( request.getHardwareAddress(), requestedAddress, selectionBase,
+            requestedLeaseTime, request.getOptions() );
+
+        if ( null == lease )
+            return null;
+
+        return lease;
+    }
+
+
+    /**
+     * Determine a lease to offer in response to a DHCPDISCOVER message.
+     * <p>
+     * When a server receives a DHCPDISCOVER message from a client, the server
+     * chooses a network address for the requesting client. If no address is
+     * available, the server may choose to report the problem to the system
+     * administrator. If an address is available, the new address SHOULD be
+     * chosen as follows:
+     * <ul>
+     * <li> The client's current address as recorded in the client's current
+     * binding, ELSE
+     * <li> The client's previous address as recorded in the client's (now
+     * expired or released) binding, if that address is in the server's pool of
+     * available addresses and not already allocated, ELSE
+     * <li> The address requested in the 'Requested IP Address' option, if that
+     * address is valid and not already allocated, ELSE
+     * <li> A new address allocated from the server's pool of available
+     * addresses; the address is selected based on the subnet from which the
+     * message was received (if 'giaddr' is 0) or on the address of the relay
+     * agent that forwarded the message ('giaddr' when not 0).
+     * </ul>
+     * 
+     * @param clientAddress
+     * @param request
+     * @return
+     */
+    private Lease getLeaseOffer( InetSocketAddress clientAddress, DhcpMessage request ) throws DhcpException
+    {
+        // determine requested lease time
+        IpAddressLeaseTime requestedLeaseTimeOption = ( IpAddressLeaseTime ) request.getOptions().get(
+            IpAddressLeaseTime.class );
+        long requestedLeaseTime = null != requestedLeaseTimeOption ? requestedLeaseTimeOption.getIntValue() * 1000
+            : -1L;
+
+        // try to get the lease (address) requested by the client
+        InetAddress requestedAddress = null;
+        AddressOption requestedAddressOption = ( AddressOption ) request.getOptions().get( RequestedIpAddress.class );
+        if ( null != requestedAddressOption )
+            requestedAddress = requestedAddressOption.getAddress();
+
+        InetAddress selectionBase = determineSelectionBase( clientAddress, request );
+
+        Lease lease = dhcpStore.getLeaseOffer( request.getHardwareAddress(), requestedAddress, selectionBase,
+            requestedLeaseTime, request.getOptions() );
+
+        return lease;
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.service.AbstractDhcpService#handleRELEASE(java.net.InetSocketAddress,
+     *      java.net.InetSocketAddress,
+     *      org.apache.directory.server.dhcp.messages.DhcpMessage)
+     */
+    protected DhcpMessage handleRELEASE( InetSocketAddress localAddress, InetSocketAddress clientAddress,
+        DhcpMessage request ) throws DhcpException
+    {
+        // check server ident
+        AddressOption serverIdentOption = ( AddressOption ) request.getOptions().get( ServerIdentifier.class );
+        if ( null != serverIdentOption && serverIdentOption.getAddress().isAnyLocalAddress() )
+            return null; // not me?! FIXME: handle authoritative server case
+
+        Lease lease = getExistingLease( clientAddress, request );
+
+        DhcpMessage reply = initGeneralReply( localAddress, request );
+
+        if ( null == lease )
+        {
+            // null lease? send NAK
+            // FIXME...
+            reply.setMessageType( MessageType.DHCPNAK );
+            reply.setCurrentClientAddress( null );
+            reply.setAssignedClientAddress( null );
+            reply.setNextServerAddress( null );
+        }
+        else
+        {
+            dhcpStore.releaseLease( lease );
+
+            // lease Ok, send ACK
+            // FIXME...
+            reply.getOptions().merge( lease.getOptions() );
+
+            reply.setAssignedClientAddress( lease.getClientAddress() );
+            reply.setNextServerAddress( lease.getNextServerAddress() );
+
+            // fix options
+            OptionsField options = reply.getOptions();
+
+            // these options must not be present
+            options.remove( RequestedIpAddress.class );
+            options.remove( ParameterRequestList.class );
+            options.remove( ClientIdentifier.class );
+            options.remove( MaximumDhcpMessageSize.class );
+
+            // these options must be present
+            options.add( new IpAddressLeaseTime( ( lease.getExpires() - System.currentTimeMillis() ) / 1000L ) );
+
+            stripUnwantedOptions( request, options );
+        }
+        return reply;
+
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.service.AbstractDhcpService#handleDISCOVER(java.net.InetSocketAddress,
+     *      org.apache.directory.server.dhcp.messages.DhcpMessage)
+     */
+    protected DhcpMessage handleDISCOVER( InetSocketAddress localAddress, InetSocketAddress clientAddress,
+        DhcpMessage request ) throws DhcpException
+    {
+        Lease lease = getLeaseOffer( clientAddress, request );
+
+        // null lease? don't offer one.
+        if ( null == lease )
+            return null;
+
+        DhcpMessage reply = initGeneralReply( localAddress, request );
+
+        reply.getOptions().merge( lease.getOptions() );
+
+        reply.setMessageType( MessageType.DHCPOFFER );
+
+        reply.setAssignedClientAddress( lease.getClientAddress() );
+        reply.setNextServerAddress( lease.getNextServerAddress() );
+
+        // fix options
+        OptionsField options = reply.getOptions();
+
+        // these options must not be present
+        options.remove( RequestedIpAddress.class );
+        options.remove( ParameterRequestList.class );
+        options.remove( ClientIdentifier.class );
+        options.remove( MaximumDhcpMessageSize.class );
+
+        // these options must be present
+        options.add( new IpAddressLeaseTime( ( lease.getExpires() - System.currentTimeMillis() ) / 1000L ) );
+
+        stripUnwantedOptions( request, options );
+
+        return reply;
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.service.AbstractDhcpService#handleREQUEST(java.net.InetSocketAddress,
+     *      org.apache.directory.server.dhcp.messages.DhcpMessage)
+     */
+    protected DhcpMessage handleREQUEST( InetSocketAddress localAddress, InetSocketAddress clientAddress,
+        DhcpMessage request ) throws DhcpException
+    {
+        // check server ident
+        AddressOption serverIdentOption = ( AddressOption ) request.getOptions().get( ServerIdentifier.class );
+        if ( null != serverIdentOption && serverIdentOption.getAddress().isAnyLocalAddress() )
+            return null; // not me?! FIXME: handle authoritative server case
+
+        Lease lease = getExistingLease( clientAddress, request );
+
+        DhcpMessage reply = initGeneralReply( localAddress, request );
+
+        if ( null == lease )
+        {
+            // null lease? send NAK
+            reply.setMessageType( MessageType.DHCPNAK );
+            reply.setCurrentClientAddress( null );
+            reply.setAssignedClientAddress( null );
+            reply.setNextServerAddress( null );
+        }
+        else
+        {
+            // lease Ok, send ACK
+            reply.getOptions().merge( lease.getOptions() );
+
+            reply.setAssignedClientAddress( lease.getClientAddress() );
+            reply.setNextServerAddress( lease.getNextServerAddress() );
+
+            // fix options
+            OptionsField options = reply.getOptions();
+
+            // these options must not be present
+            options.remove( RequestedIpAddress.class );
+            options.remove( ParameterRequestList.class );
+            options.remove( ClientIdentifier.class );
+            options.remove( MaximumDhcpMessageSize.class );
+
+            // these options must be present
+            options.add( new IpAddressLeaseTime( ( lease.getExpires() - System.currentTimeMillis() ) / 1000L ) );
+
+            stripUnwantedOptions( request, options );
+        }
+        return reply;
+    }
+}

Modified: directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/AbstractDhcpStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/AbstractDhcpStore.java?rev=801338&r1=801337&r2=801338&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/AbstractDhcpStore.java (original)
+++ directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/AbstractDhcpStore.java Wed Aug  5 17:53:19 2009
@@ -1,316 +1,316 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.directory.server.dhcp.store;
-
-
-import java.net.InetAddress;
-import java.util.Map;
-
-import org.apache.directory.server.dhcp.DhcpException;
-import org.apache.directory.server.dhcp.messages.HardwareAddress;
-import org.apache.directory.server.dhcp.options.OptionsField;
-import org.apache.directory.server.dhcp.options.vendor.HostName;
-import org.apache.directory.server.dhcp.options.vendor.SubnetMask;
-import org.apache.directory.server.dhcp.service.Lease;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Abstract base implementation of a {@link DhcpStore}.
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
- */
-public abstract class AbstractDhcpStore implements DhcpStore
-{
-    private static final Logger logger = LoggerFactory.getLogger( AbstractDhcpStore.class );
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.service.DhcpStore#getLeaseOffer(org.apache.directory.server.dhcp.messages.HardwareAddress,
-     *      java.net.InetAddress, java.net.InetAddress, long,
-     *      org.apache.directory.server.dhcp.options.OptionsField)
-     */
-    public Lease getLeaseOffer( HardwareAddress hardwareAddress, InetAddress requestedAddress,
-        InetAddress selectionBase, long requestedLeaseTime, OptionsField options ) throws DhcpException
-    {
-        Subnet subnet = findSubnet( selectionBase );
-        if ( null == subnet )
-        {
-            logger.warn( "Don't know anything about the sbnet containing " + selectionBase );
-            return null;
-        }
-
-        // try to find existing lease
-        Lease lease = null;
-        lease = findExistingLease( hardwareAddress, lease );
-        if ( null != lease )
-            return lease;
-
-        Host host = null;
-        host = findDesignatedHost( hardwareAddress );
-        if ( null != host )
-        {
-            // make sure that the host is actually within the subnet. Depending
-            // on the way the DhcpStore configuration is implemented, it is not
-            // possible to violate this condition, but we can't be sure.
-            if ( !subnet.contains( host.getAddress() ) )
-            {
-                logger.warn( "Host " + host + " is not within the subnet for which an address is requested" );
-            }
-            else
-            {
-                // build properties map
-                Map properties = getProperties( subnet );
-                properties.putAll( getProperties( host ) );
-
-                // build lease
-                lease = new Lease();
-                lease.setAcquired( System.currentTimeMillis() );
-
-                long leaseTime = determineLeaseTime( requestedLeaseTime, properties );
-
-                lease.setExpires( System.currentTimeMillis() + leaseTime );
-
-                lease.setHardwareAddress( hardwareAddress );
-                lease.setState( Lease.STATE_NEW );
-                lease.setClientAddress( host.getAddress() );
-
-                // set lease options
-                OptionsField o = lease.getOptions();
-
-                // set (client) host name
-                o.add( new HostName( host.getName() ) );
-
-                // add subnet settings
-                o.add( new SubnetMask( subnet.getNetmask() ) );
-                o.merge( subnet.getOptions() );
-
-                // add the host's options. they override existing
-                // subnet options as they take the precedence.
-                o.merge( host.getOptions() );
-            }
-        }
-
-        if ( null == lease )
-        {
-            // FIXME: use selection base to find a lease in a pool.
-        }
-
-        // update the lease state
-        if ( null != lease && lease.getState() != Lease.STATE_ACTIVE )
-        {
-            lease.setState( Lease.STATE_OFFERED );
-            updateLease( lease );
-        }
-
-        return lease;
-    }
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.store.DhcpStore#getExistingLease(org.apache.directory.server.dhcp.messages.HardwareAddress,
-     *      java.net.InetAddress, java.net.InetAddress, long,
-     *      org.apache.directory.server.dhcp.options.OptionsField)
-     */
-    public Lease getExistingLease( HardwareAddress hardwareAddress, InetAddress requestedAddress,
-        InetAddress selectionBase, long requestedLeaseTime, OptionsField options ) throws DhcpException
-    {
-        // try to find existing lease. if we don't find a lease based on the
-        // client's
-        // hardware address, we send a NAK.
-        Lease lease = null;
-        lease = findExistingLease( hardwareAddress, lease );
-        if ( null == lease )
-            return null;
-
-        // check whether the notions of the client address match
-        if ( !lease.getClientAddress().equals( requestedAddress ) )
-        {
-            logger.warn( "Requested address " + requestedAddress + " for " + hardwareAddress
-                + " doesn't match existing lease " + lease );
-            return null;
-        }
-
-        // check whether addresses and subnet match
-        Subnet subnet = findSubnet( selectionBase );
-        if ( null == subnet )
-        {
-            logger.warn( "No subnet found for existing lease " + lease );
-            return null;
-        }
-        if ( !subnet.contains( lease.getClientAddress() ) )
-        {
-            logger.warn( "Client with existing lease " + lease + " is on wrong subnet " + subnet );
-            return null;
-        }
-        if ( !subnet.isInRange( lease.getClientAddress() ) )
-        {
-            logger.warn( "Client with existing lease " + lease + " is out of valid range for subnet " + subnet );
-            return null;
-        }
-
-        // build properties map
-        Map properties = getProperties( subnet );
-
-        // update lease options
-        OptionsField o = lease.getOptions();
-        o.clear();
-
-        // add subnet settings
-        o.add( new SubnetMask( subnet.getNetmask() ) );
-        o.merge( subnet.getOptions() );
-
-        // check whether there is a designated host.
-        Host host = findDesignatedHost( hardwareAddress );
-        if ( null != host )
-        {
-            // check whether the host matches the address (using a fixed
-            // host address is mandatory).
-            if ( host.getAddress() != null && !host.getAddress().equals( lease.getClientAddress() ) )
-            {
-                logger.warn( "Existing fixed address for " + hardwareAddress + " conflicts with existing lease "
-                    + lease );
-                return null;
-            }
-
-            properties.putAll( getProperties( host ) );
-
-            // set (client) host name
-            o.add( new HostName( host.getName() ) );
-
-            // add the host's options
-            o.merge( host.getOptions() );
-        }
-
-        // update other lease fields
-        long leaseTime = determineLeaseTime( requestedLeaseTime, properties );
-        lease.setExpires( System.currentTimeMillis() + leaseTime );
-        lease.setHardwareAddress( hardwareAddress );
-
-        // update the lease state
-        if ( lease.getState() != Lease.STATE_ACTIVE )
-        {
-            lease.setState( Lease.STATE_ACTIVE );
-            updateLease( lease );
-        }
-
-        // store information about the lease
-        updateLease( lease );
-
-        return lease;
-    }
-
-
-    /**
-     * Determine the lease time based on the time requested by the client, the
-     * properties and a global default.
-     * 
-     * @param requestedLeaseTime
-     * @param properties
-     * @return long
-     */
-    private long determineLeaseTime( long requestedLeaseTime, Map properties )
-    {
-        // built-in default
-        long leaseTime = 1000L * 3600;
-        Integer propMaxLeaseTime = ( Integer ) properties.get( DhcpConfigElement.PROPERTY_MAX_LEASE_TIME );
-        if ( null != propMaxLeaseTime )
-            if ( requestedLeaseTime > 0 )
-                leaseTime = Math.min( propMaxLeaseTime.intValue() * 1000L, requestedLeaseTime );
-            else
-                leaseTime = propMaxLeaseTime.intValue() * 1000L;
-        return leaseTime;
-    }
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.store.DhcpStore#releaseLease(org.apache.directory.server.dhcp.service.Lease)
-     */
-    public void releaseLease( Lease lease )
-    {
-        lease.setState( Lease.STATE_RELEASED );
-        updateLease( lease );
-    }
-
-
-    /**
-     * Update the (possibly changed) lease in the store.
-     * 
-     * @param lease
-     */
-    protected abstract void updateLease( Lease lease );
-
-
-    /**
-     * Return a list of all options applicable to the given config element. List
-     * list must contain the options specified for the element and all parent
-     * elements in an aggregated fashion. For instance, the options for a host
-     * must include the global default options, the options of classes the host
-     * is a member of, the host's group options and the host's options.
-     * 
-     * @param element
-     * @return OptionsField
-     */
-    protected abstract OptionsField getOptions( DhcpConfigElement element );
-
-
-    /**
-     * Return a list of all options applicable to the given config element. List
-     * list must contain the options specified for the element and all parent
-     * elements in an aggregated fashion. For instance, the options for a host
-     * must include the global default options, the options of classes the host
-     * is a member of, the host's group options and the host's options.
-     * 
-     * @param element
-     * @return Map
-     */
-    protected abstract Map getProperties( DhcpConfigElement element );
-
-
-    /**
-     * Find an existing lease in the store.
-     * 
-     * @param hardwareAddress
-     * @param existingLease
-     * @return Map
-     */
-    protected abstract Lease findExistingLease( HardwareAddress hardwareAddress, Lease existingLease );
-
-
-    /**
-     * Find a host to with the explicitely designated hardware address.
-     * 
-     * @param hardwareAddress
-     * @return Host
-     * @throws DhcpException
-     */
-    protected abstract Host findDesignatedHost( HardwareAddress hardwareAddress ) throws DhcpException;
-
-
-    /**
-     * Find the subnet definition matching the given address.
-     * 
-     * @param clientAddress
-     * @return Subnet
-     */
-    protected abstract Subnet findSubnet( InetAddress clientAddress );
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.dhcp.store;
+
+
+import java.net.InetAddress;
+import java.util.Map;
+
+import org.apache.directory.server.dhcp.DhcpException;
+import org.apache.directory.server.dhcp.messages.HardwareAddress;
+import org.apache.directory.server.dhcp.options.OptionsField;
+import org.apache.directory.server.dhcp.options.vendor.HostName;
+import org.apache.directory.server.dhcp.options.vendor.SubnetMask;
+import org.apache.directory.server.dhcp.service.Lease;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Abstract base implementation of a {@link DhcpStore}.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
+ */
+public abstract class AbstractDhcpStore implements DhcpStore
+{
+    private static final Logger logger = LoggerFactory.getLogger( AbstractDhcpStore.class );
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.service.DhcpStore#getLeaseOffer(org.apache.directory.server.dhcp.messages.HardwareAddress,
+     *      java.net.InetAddress, java.net.InetAddress, long,
+     *      org.apache.directory.server.dhcp.options.OptionsField)
+     */
+    public Lease getLeaseOffer( HardwareAddress hardwareAddress, InetAddress requestedAddress,
+        InetAddress selectionBase, long requestedLeaseTime, OptionsField options ) throws DhcpException
+    {
+        Subnet subnet = findSubnet( selectionBase );
+        if ( null == subnet )
+        {
+            logger.warn( "Don't know anything about the sbnet containing " + selectionBase );
+            return null;
+        }
+
+        // try to find existing lease
+        Lease lease = null;
+        lease = findExistingLease( hardwareAddress, lease );
+        if ( null != lease )
+            return lease;
+
+        Host host = null;
+        host = findDesignatedHost( hardwareAddress );
+        if ( null != host )
+        {
+            // make sure that the host is actually within the subnet. Depending
+            // on the way the DhcpStore configuration is implemented, it is not
+            // possible to violate this condition, but we can't be sure.
+            if ( !subnet.contains( host.getAddress() ) )
+            {
+                logger.warn( "Host " + host + " is not within the subnet for which an address is requested" );
+            }
+            else
+            {
+                // build properties map
+                Map properties = getProperties( subnet );
+                properties.putAll( getProperties( host ) );
+
+                // build lease
+                lease = new Lease();
+                lease.setAcquired( System.currentTimeMillis() );
+
+                long leaseTime = determineLeaseTime( requestedLeaseTime, properties );
+
+                lease.setExpires( System.currentTimeMillis() + leaseTime );
+
+                lease.setHardwareAddress( hardwareAddress );
+                lease.setState( Lease.STATE_NEW );
+                lease.setClientAddress( host.getAddress() );
+
+                // set lease options
+                OptionsField o = lease.getOptions();
+
+                // set (client) host name
+                o.add( new HostName( host.getName() ) );
+
+                // add subnet settings
+                o.add( new SubnetMask( subnet.getNetmask() ) );
+                o.merge( subnet.getOptions() );
+
+                // add the host's options. they override existing
+                // subnet options as they take the precedence.
+                o.merge( host.getOptions() );
+            }
+        }
+
+        if ( null == lease )
+        {
+            // FIXME: use selection base to find a lease in a pool.
+        }
+
+        // update the lease state
+        if ( null != lease && lease.getState() != Lease.STATE_ACTIVE )
+        {
+            lease.setState( Lease.STATE_OFFERED );
+            updateLease( lease );
+        }
+
+        return lease;
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.store.DhcpStore#getExistingLease(org.apache.directory.server.dhcp.messages.HardwareAddress,
+     *      java.net.InetAddress, java.net.InetAddress, long,
+     *      org.apache.directory.server.dhcp.options.OptionsField)
+     */
+    public Lease getExistingLease( HardwareAddress hardwareAddress, InetAddress requestedAddress,
+        InetAddress selectionBase, long requestedLeaseTime, OptionsField options ) throws DhcpException
+    {
+        // try to find existing lease. if we don't find a lease based on the
+        // client's
+        // hardware address, we send a NAK.
+        Lease lease = null;
+        lease = findExistingLease( hardwareAddress, lease );
+        if ( null == lease )
+            return null;
+
+        // check whether the notions of the client address match
+        if ( !lease.getClientAddress().equals( requestedAddress ) )
+        {
+            logger.warn( "Requested address " + requestedAddress + " for " + hardwareAddress
+                + " doesn't match existing lease " + lease );
+            return null;
+        }
+
+        // check whether addresses and subnet match
+        Subnet subnet = findSubnet( selectionBase );
+        if ( null == subnet )
+        {
+            logger.warn( "No subnet found for existing lease " + lease );
+            return null;
+        }
+        if ( !subnet.contains( lease.getClientAddress() ) )
+        {
+            logger.warn( "Client with existing lease " + lease + " is on wrong subnet " + subnet );
+            return null;
+        }
+        if ( !subnet.isInRange( lease.getClientAddress() ) )
+        {
+            logger.warn( "Client with existing lease " + lease + " is out of valid range for subnet " + subnet );
+            return null;
+        }
+
+        // build properties map
+        Map properties = getProperties( subnet );
+
+        // update lease options
+        OptionsField o = lease.getOptions();
+        o.clear();
+
+        // add subnet settings
+        o.add( new SubnetMask( subnet.getNetmask() ) );
+        o.merge( subnet.getOptions() );
+
+        // check whether there is a designated host.
+        Host host = findDesignatedHost( hardwareAddress );
+        if ( null != host )
+        {
+            // check whether the host matches the address (using a fixed
+            // host address is mandatory).
+            if ( host.getAddress() != null && !host.getAddress().equals( lease.getClientAddress() ) )
+            {
+                logger.warn( "Existing fixed address for " + hardwareAddress + " conflicts with existing lease "
+                    + lease );
+                return null;
+            }
+
+            properties.putAll( getProperties( host ) );
+
+            // set (client) host name
+            o.add( new HostName( host.getName() ) );
+
+            // add the host's options
+            o.merge( host.getOptions() );
+        }
+
+        // update other lease fields
+        long leaseTime = determineLeaseTime( requestedLeaseTime, properties );
+        lease.setExpires( System.currentTimeMillis() + leaseTime );
+        lease.setHardwareAddress( hardwareAddress );
+
+        // update the lease state
+        if ( lease.getState() != Lease.STATE_ACTIVE )
+        {
+            lease.setState( Lease.STATE_ACTIVE );
+            updateLease( lease );
+        }
+
+        // store information about the lease
+        updateLease( lease );
+
+        return lease;
+    }
+
+
+    /**
+     * Determine the lease time based on the time requested by the client, the
+     * properties and a global default.
+     * 
+     * @param requestedLeaseTime
+     * @param properties
+     * @return long
+     */
+    private long determineLeaseTime( long requestedLeaseTime, Map properties )
+    {
+        // built-in default
+        long leaseTime = 1000L * 3600;
+        Integer propMaxLeaseTime = ( Integer ) properties.get( DhcpConfigElement.PROPERTY_MAX_LEASE_TIME );
+        if ( null != propMaxLeaseTime )
+            if ( requestedLeaseTime > 0 )
+                leaseTime = Math.min( propMaxLeaseTime.intValue() * 1000L, requestedLeaseTime );
+            else
+                leaseTime = propMaxLeaseTime.intValue() * 1000L;
+        return leaseTime;
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.store.DhcpStore#releaseLease(org.apache.directory.server.dhcp.service.Lease)
+     */
+    public void releaseLease( Lease lease )
+    {
+        lease.setState( Lease.STATE_RELEASED );
+        updateLease( lease );
+    }
+
+
+    /**
+     * Update the (possibly changed) lease in the store.
+     * 
+     * @param lease
+     */
+    protected abstract void updateLease( Lease lease );
+
+
+    /**
+     * Return a list of all options applicable to the given config element. List
+     * list must contain the options specified for the element and all parent
+     * elements in an aggregated fashion. For instance, the options for a host
+     * must include the global default options, the options of classes the host
+     * is a member of, the host's group options and the host's options.
+     * 
+     * @param element
+     * @return OptionsField
+     */
+    protected abstract OptionsField getOptions( DhcpConfigElement element );
+
+
+    /**
+     * Return a list of all options applicable to the given config element. List
+     * list must contain the options specified for the element and all parent
+     * elements in an aggregated fashion. For instance, the options for a host
+     * must include the global default options, the options of classes the host
+     * is a member of, the host's group options and the host's options.
+     * 
+     * @param element
+     * @return Map
+     */
+    protected abstract Map getProperties( DhcpConfigElement element );
+
+
+    /**
+     * Find an existing lease in the store.
+     * 
+     * @param hardwareAddress
+     * @param existingLease
+     * @return Map
+     */
+    protected abstract Lease findExistingLease( HardwareAddress hardwareAddress, Lease existingLease );
+
+
+    /**
+     * Find a host to with the explicitely designated hardware address.
+     * 
+     * @param hardwareAddress
+     * @return Host
+     * @throws DhcpException
+     */
+    protected abstract Host findDesignatedHost( HardwareAddress hardwareAddress ) throws DhcpException;
+
+
+    /**
+     * Find the subnet definition matching the given address.
+     * 
+     * @param clientAddress
+     * @return Subnet
+     */
+    protected abstract Subnet findSubnet( InetAddress clientAddress );
+}

Modified: directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/DhcpConfigElement.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/DhcpConfigElement.java?rev=801338&r1=801337&r2=801338&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/DhcpConfigElement.java (original)
+++ directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/DhcpConfigElement.java Wed Aug  5 17:53:19 2009
@@ -1,55 +1,55 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.directory.server.dhcp.store;
-
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.directory.server.dhcp.options.OptionsField;
-
-
-/**
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
- */
-public abstract class DhcpConfigElement
-{
-    public static final String PROPERTY_MAX_LEASE_TIME = "max-lease-time";
-        
-    /** List of DhcpOptions for ths subnet */
-    private OptionsField options = new OptionsField();
-
-    /** Map of properties for this element */
-    private Map properties = new HashMap();
-
-
-    public OptionsField getOptions()
-    {
-        return options;
-    }
-
-
-    public Map getProperties()
-    {
-        return properties;
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.dhcp.store;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.directory.server.dhcp.options.OptionsField;
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
+ */
+public abstract class DhcpConfigElement
+{
+    public static final String PROPERTY_MAX_LEASE_TIME = "max-lease-time";
+        
+    /** List of DhcpOptions for ths subnet */
+    private OptionsField options = new OptionsField();
+
+    /** Map of properties for this element */
+    private Map properties = new HashMap();
+
+
+    public OptionsField getOptions()
+    {
+        return options;
+    }
+
+
+    public Map getProperties()
+    {
+        return properties;
+    }
+}

Modified: directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/DhcpStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/DhcpStore.java?rev=801338&r1=801337&r2=801338&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/DhcpStore.java (original)
+++ directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/DhcpStore.java Wed Aug  5 17:53:19 2009
@@ -1,103 +1,103 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.directory.server.dhcp.store;
-
-
-import java.net.InetAddress;
-
-import org.apache.directory.server.dhcp.DhcpException;
-import org.apache.directory.server.dhcp.messages.HardwareAddress;
-import org.apache.directory.server.dhcp.options.OptionsField;
-import org.apache.directory.server.dhcp.service.Lease;
-
-
-/**
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
- */
-public interface DhcpStore
-{
-    /**
-     * Find a lease to offer in response to a DHCPDISCOVER request.
-     * <p>
-     * The lease to offer should be determined by an algorithme like the
-     * following:
-     * <ul>
-     * <li> Try to find an existing lease for the given hardware address. The
-     * lease may be either ACTIVE or EXPIRED.
-     * <li>Try to find a lease which has been explicitely dedicated to the
-     * given hardware address.
-     * <li>Try to get a lease from a pool of leases. If the client requested a
-     * specific address, the request should be honored, if possible. Otherwise
-     * the selection of an address should be based on the selection base address
-     * and may be refined using the supplied options.
-     * </ul>
-     * <p>
-     * If the requestedLeaseTime is >= 0, the validity duration of the returned
-     * lease must be updated, so that the lease is valid for at least the
-     * specified time. The duration may, however, be constrained by a configured
-     * maximum lease time.
-     * 
-     * @param hardwareAddress
-     *            hardwareAddress the hardware address of the client requesting
-     *            the lease.
-     * @param requestedAddress
-     *            the address requested by the client or <code>null</code> if
-     *            the client did not request a specific address.
-     * @param selectionBase
-     *            the address on which to base the selection of a lease from a
-     *            pool, i.e. either the address of the interface on which the
-     *            request was received or the address of a DHCP relay agent.
-     * @param requestedLeaseTime
-     *            the lease time in milliseconds as requested by the client, or
-     *            -1 if the client did not request a specific lease time.
-     * @param options
-     *            the supplied DHCP options. Lease selection may be refined by
-     *            using those options
-     * @return a lease or <code>null</code> if no matching lease was found.
-     * @throws DhcpException
-     */
-    Lease getLeaseOffer( HardwareAddress hardwareAddress, InetAddress requestedAddress, InetAddress selectionBase,
-        long requestedLeaseTime, OptionsField options ) throws DhcpException;
-
-
-    /**
-     * Retrieve an existing lease from the dhcp store.
-     * 
-     * @param hardwareAddress
-     * @param requestedAddress
-     * @param selectionBase
-     * @param requestedLeaseTime
-     * @param options
-     * @return Lease
-     * @throws DhcpException 
-     */
-    Lease getExistingLease( HardwareAddress hardwareAddress, InetAddress requestedAddress, InetAddress selectionBase,
-        long requestedLeaseTime, OptionsField options ) throws DhcpException;
-
-
-    /**
-     * Release the specified lease. 
-     * 
-     * @param lease
-     */
-    void releaseLease( Lease lease );
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.dhcp.store;
+
+
+import java.net.InetAddress;
+
+import org.apache.directory.server.dhcp.DhcpException;
+import org.apache.directory.server.dhcp.messages.HardwareAddress;
+import org.apache.directory.server.dhcp.options.OptionsField;
+import org.apache.directory.server.dhcp.service.Lease;
+
+
+/**
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
+ */
+public interface DhcpStore
+{
+    /**
+     * Find a lease to offer in response to a DHCPDISCOVER request.
+     * <p>
+     * The lease to offer should be determined by an algorithme like the
+     * following:
+     * <ul>
+     * <li> Try to find an existing lease for the given hardware address. The
+     * lease may be either ACTIVE or EXPIRED.
+     * <li>Try to find a lease which has been explicitely dedicated to the
+     * given hardware address.
+     * <li>Try to get a lease from a pool of leases. If the client requested a
+     * specific address, the request should be honored, if possible. Otherwise
+     * the selection of an address should be based on the selection base address
+     * and may be refined using the supplied options.
+     * </ul>
+     * <p>
+     * If the requestedLeaseTime is >= 0, the validity duration of the returned
+     * lease must be updated, so that the lease is valid for at least the
+     * specified time. The duration may, however, be constrained by a configured
+     * maximum lease time.
+     * 
+     * @param hardwareAddress
+     *            hardwareAddress the hardware address of the client requesting
+     *            the lease.
+     * @param requestedAddress
+     *            the address requested by the client or <code>null</code> if
+     *            the client did not request a specific address.
+     * @param selectionBase
+     *            the address on which to base the selection of a lease from a
+     *            pool, i.e. either the address of the interface on which the
+     *            request was received or the address of a DHCP relay agent.
+     * @param requestedLeaseTime
+     *            the lease time in milliseconds as requested by the client, or
+     *            -1 if the client did not request a specific lease time.
+     * @param options
+     *            the supplied DHCP options. Lease selection may be refined by
+     *            using those options
+     * @return a lease or <code>null</code> if no matching lease was found.
+     * @throws DhcpException
+     */
+    Lease getLeaseOffer( HardwareAddress hardwareAddress, InetAddress requestedAddress, InetAddress selectionBase,
+        long requestedLeaseTime, OptionsField options ) throws DhcpException;
+
+
+    /**
+     * Retrieve an existing lease from the dhcp store.
+     * 
+     * @param hardwareAddress
+     * @param requestedAddress
+     * @param selectionBase
+     * @param requestedLeaseTime
+     * @param options
+     * @return Lease
+     * @throws DhcpException 
+     */
+    Lease getExistingLease( HardwareAddress hardwareAddress, InetAddress requestedAddress, InetAddress selectionBase,
+        long requestedLeaseTime, OptionsField options ) throws DhcpException;
+
+
+    /**
+     * Release the specified lease. 
+     * 
+     * @param lease
+     */
+    void releaseLease( Lease lease );
+}

Modified: directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/Host.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/Host.java?rev=801338&r1=801337&r2=801338&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/Host.java (original)
+++ directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/Host.java Wed Aug  5 17:53:19 2009
@@ -1,70 +1,70 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.directory.server.dhcp.store;
-
-
-import java.net.InetAddress;
-
-import org.apache.directory.server.dhcp.messages.HardwareAddress;
-
-
-/**
- * The definition of a host.
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
- */
-public class Host extends DhcpConfigElement
-{
-    private final String name;
-
-    private HardwareAddress hardwareAddress;
-
-    /**
-     * The host's fixed address. May be <code>null</code>.
-     */
-    private InetAddress address;
-
-
-    public Host(String name, InetAddress address, HardwareAddress hardwareAddress)
-    {
-        this.name = name;
-        this.address = address;
-        this.hardwareAddress = hardwareAddress;
-    }
-
-
-    public HardwareAddress getHardwareAddress()
-    {
-        return hardwareAddress;
-    }
-
-
-    public String getName()
-    {
-        return name;
-    }
-
-
-    public InetAddress getAddress()
-    {
-        return address;
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.dhcp.store;
+
+
+import java.net.InetAddress;
+
+import org.apache.directory.server.dhcp.messages.HardwareAddress;
+
+
+/**
+ * The definition of a host.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
+ */
+public class Host extends DhcpConfigElement
+{
+    private final String name;
+
+    private HardwareAddress hardwareAddress;
+
+    /**
+     * The host's fixed address. May be <code>null</code>.
+     */
+    private InetAddress address;
+
+
+    public Host(String name, InetAddress address, HardwareAddress hardwareAddress)
+    {
+        this.name = name;
+        this.address = address;
+        this.hardwareAddress = hardwareAddress;
+    }
+
+
+    public HardwareAddress getHardwareAddress()
+    {
+        return hardwareAddress;
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+
+
+    public InetAddress getAddress()
+    {
+        return address;
+    }
+}

Modified: directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/SimpleDhcpStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/SimpleDhcpStore.java?rev=801338&r1=801337&r2=801338&view=diff
==============================================================================
--- directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/SimpleDhcpStore.java (original)
+++ directory/apacheds/trunk/protocol-dhcp/src/main/java/org/apache/directory/server/dhcp/store/SimpleDhcpStore.java Wed Aug  5 17:53:19 2009
@@ -1,201 +1,201 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *  
- *    http://www.apache.org/licenses/LICENSE-2.0
- *  
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License. 
- *  
- */
-package org.apache.directory.server.dhcp.store;
-
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.InitialDirContext;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-
-import org.apache.directory.server.dhcp.DhcpException;
-import org.apache.directory.server.dhcp.messages.HardwareAddress;
-import org.apache.directory.server.dhcp.options.OptionsField;
-import org.apache.directory.server.dhcp.service.Lease;
-
-
-/**
- * Very simple dummy/proof-of-concept implementation of a DhcpStore.
- * 
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
- */
-public class SimpleDhcpStore extends AbstractDhcpStore
-{
-    // private static final String DEFAULT_INITIAL_CONTEXT_FACTORY =
-    // "org.apache.directory.server.core.jndi.CoreContextFactory";
-
-    // a map of current leases
-    private Map leases = new HashMap();
-
-    private List subnets = new ArrayList();
-
-
-    public SimpleDhcpStore()
-    {
-        try
-        {
-            subnets.add( new Subnet( InetAddress.getByName( "192.168.168.0" ),
-                InetAddress.getByName( "255.255.255.0" ), InetAddress.getByName( "192.168.168.159" ), InetAddress
-                    .getByName( "192.168.168.179" ) ) );
-        }
-        catch ( UnknownHostException e )
-        {
-            throw new RuntimeException( "Can't init", e );
-        }
-    }
-
-
-    protected DirContext getContext() throws NamingException
-    {
-        Hashtable env = new Hashtable();
-        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
-        // env.put( Context.INITIAL_CONTEXT_FACTORY,
-        // DEFAULT_INITIAL_CONTEXT_FACTORY );
-        env.put( Context.PROVIDER_URL, "ldap://localhost:389/dc=tcat,dc=test" );
-
-        return new InitialDirContext( env );
-    }
-
-
-    /**
-     * @param hardwareAddress
-     * @param existingLease
-     * @return Lease
-     */
-    protected Lease findExistingLease( HardwareAddress hardwareAddress, Lease existingLease )
-    {
-        if ( leases.containsKey( hardwareAddress ) )
-            existingLease = ( Lease ) leases.get( hardwareAddress );
-        return existingLease;
-    }
-
-
-    /**
-     * @param hardwareAddress
-     * @return Host
-     * @throws DhcpException
-     */
-    protected Host findDesignatedHost( HardwareAddress hardwareAddress ) throws DhcpException
-    {
-        try
-        {
-            DirContext ctx = getContext();
-            try
-            {
-                String filter = "(&(objectclass=ipHost)(objectclass=ieee802Device)(macaddress={0}))";
-                SearchControls sc = new SearchControls();
-                sc.setCountLimit( 1 );
-                sc.setSearchScope( SearchControls.SUBTREE_SCOPE );
-                NamingEnumeration ne = ctx.search( "", filter, new Object[]
-                    { hardwareAddress.toString() }, sc );
-
-                if ( ne.hasMoreElements() )
-                {
-                    SearchResult sr = ( SearchResult ) ne.next();
-                    Attributes att = sr.getAttributes();
-                    Attribute ipHostNumberAttribute = att.get( "iphostnumber" );
-                    if ( ipHostNumberAttribute != null )
-                    {
-                        InetAddress clientAddress = InetAddress.getByName( ( String ) ipHostNumberAttribute.get() );
-                        Attribute cnAttribute = att.get( "cn" );
-                        return new Host( cnAttribute != null ? ( String ) cnAttribute.get() : "unknown", clientAddress,
-                            hardwareAddress );
-                    }
-                }
-            }
-            catch ( Exception e )
-            {
-                throw new DhcpException( "Can't lookup lease", e );
-            }
-            finally
-            {
-                ctx.close();
-            }
-        }
-        catch ( NamingException e )
-        {
-            throw new DhcpException( "Can't lookup lease", e );
-        }
-
-        return null;
-    }
-
-
-    /**
-     * Find the subnet for the given client address.
-     * 
-     * @param clientAddress
-     * @return Subnet
-     */
-    protected Subnet findSubnet( InetAddress clientAddress )
-    {
-        for ( Iterator i = subnets.iterator(); i.hasNext(); )
-        {
-            Subnet subnet = ( Subnet ) i.next();
-            if ( subnet.contains( clientAddress ) )
-                return subnet;
-        }
-        return null;
-    }
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.store.AbstractDhcpStore#updateLease(org.apache.directory.server.dhcp.service.Lease)
-     */
-    public void updateLease( Lease lease )
-    {
-        leases.put( lease.getHardwareAddress(), lease );
-    }
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.store.AbstractDhcpStore#getOptions(org.apache.directory.server.dhcp.store.DhcpConfigElement)
-     */
-    protected OptionsField getOptions( DhcpConfigElement element )
-    {
-        // we don't have groups, classes, etc. yet.
-        return element.getOptions();
-    }
-
-
-    /*
-     * @see org.apache.directory.server.dhcp.store.AbstractDhcpStore#getProperties(org.apache.directory.server.dhcp.store.DhcpConfigElement)
-     */
-    protected Map getProperties( DhcpConfigElement element )
-    {
-        // we don't have groups, classes, etc. yet.
-        return element.getProperties();
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.dhcp.store;
+
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+
+import org.apache.directory.server.dhcp.DhcpException;
+import org.apache.directory.server.dhcp.messages.HardwareAddress;
+import org.apache.directory.server.dhcp.options.OptionsField;
+import org.apache.directory.server.dhcp.service.Lease;
+
+
+/**
+ * Very simple dummy/proof-of-concept implementation of a DhcpStore.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 545042 $, $Date: 2007-06-06 22:32:01 -0500 (Mi, 06 Jun 2007) $
+ */
+public class SimpleDhcpStore extends AbstractDhcpStore
+{
+    // private static final String DEFAULT_INITIAL_CONTEXT_FACTORY =
+    // "org.apache.directory.server.core.jndi.CoreContextFactory";
+
+    // a map of current leases
+    private Map leases = new HashMap();
+
+    private List subnets = new ArrayList();
+
+
+    public SimpleDhcpStore()
+    {
+        try
+        {
+            subnets.add( new Subnet( InetAddress.getByName( "192.168.168.0" ),
+                InetAddress.getByName( "255.255.255.0" ), InetAddress.getByName( "192.168.168.159" ), InetAddress
+                    .getByName( "192.168.168.179" ) ) );
+        }
+        catch ( UnknownHostException e )
+        {
+            throw new RuntimeException( "Can't init", e );
+        }
+    }
+
+
+    protected DirContext getContext() throws NamingException
+    {
+        Hashtable env = new Hashtable();
+        env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
+        // env.put( Context.INITIAL_CONTEXT_FACTORY,
+        // DEFAULT_INITIAL_CONTEXT_FACTORY );
+        env.put( Context.PROVIDER_URL, "ldap://localhost:389/dc=tcat,dc=test" );
+
+        return new InitialDirContext( env );
+    }
+
+
+    /**
+     * @param hardwareAddress
+     * @param existingLease
+     * @return Lease
+     */
+    protected Lease findExistingLease( HardwareAddress hardwareAddress, Lease existingLease )
+    {
+        if ( leases.containsKey( hardwareAddress ) )
+            existingLease = ( Lease ) leases.get( hardwareAddress );
+        return existingLease;
+    }
+
+
+    /**
+     * @param hardwareAddress
+     * @return Host
+     * @throws DhcpException
+     */
+    protected Host findDesignatedHost( HardwareAddress hardwareAddress ) throws DhcpException
+    {
+        try
+        {
+            DirContext ctx = getContext();
+            try
+            {
+                String filter = "(&(objectclass=ipHost)(objectclass=ieee802Device)(macaddress={0}))";
+                SearchControls sc = new SearchControls();
+                sc.setCountLimit( 1 );
+                sc.setSearchScope( SearchControls.SUBTREE_SCOPE );
+                NamingEnumeration ne = ctx.search( "", filter, new Object[]
+                    { hardwareAddress.toString() }, sc );
+
+                if ( ne.hasMoreElements() )
+                {
+                    SearchResult sr = ( SearchResult ) ne.next();
+                    Attributes att = sr.getAttributes();
+                    Attribute ipHostNumberAttribute = att.get( "iphostnumber" );
+                    if ( ipHostNumberAttribute != null )
+                    {
+                        InetAddress clientAddress = InetAddress.getByName( ( String ) ipHostNumberAttribute.get() );
+                        Attribute cnAttribute = att.get( "cn" );
+                        return new Host( cnAttribute != null ? ( String ) cnAttribute.get() : "unknown", clientAddress,
+                            hardwareAddress );
+                    }
+                }
+            }
+            catch ( Exception e )
+            {
+                throw new DhcpException( "Can't lookup lease", e );
+            }
+            finally
+            {
+                ctx.close();
+            }
+        }
+        catch ( NamingException e )
+        {
+            throw new DhcpException( "Can't lookup lease", e );
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Find the subnet for the given client address.
+     * 
+     * @param clientAddress
+     * @return Subnet
+     */
+    protected Subnet findSubnet( InetAddress clientAddress )
+    {
+        for ( Iterator i = subnets.iterator(); i.hasNext(); )
+        {
+            Subnet subnet = ( Subnet ) i.next();
+            if ( subnet.contains( clientAddress ) )
+                return subnet;
+        }
+        return null;
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.store.AbstractDhcpStore#updateLease(org.apache.directory.server.dhcp.service.Lease)
+     */
+    public void updateLease( Lease lease )
+    {
+        leases.put( lease.getHardwareAddress(), lease );
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.store.AbstractDhcpStore#getOptions(org.apache.directory.server.dhcp.store.DhcpConfigElement)
+     */
+    protected OptionsField getOptions( DhcpConfigElement element )
+    {
+        // we don't have groups, classes, etc. yet.
+        return element.getOptions();
+    }
+
+
+    /*
+     * @see org.apache.directory.server.dhcp.store.AbstractDhcpStore#getProperties(org.apache.directory.server.dhcp.store.DhcpConfigElement)
+     */
+    protected Map getProperties( DhcpConfigElement element )
+    {
+        // we don't have groups, classes, etc. yet.
+        return element.getProperties();
+    }
+}