Package org.apache.directory.server.dhcp.service

Examples of org.apache.directory.server.dhcp.service.Lease


            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;
    }
View Full Code Here


        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 );
View Full Code Here

            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;
    }
View Full Code Here

        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 );
View Full Code Here

            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;
    }
View Full Code Here

        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 );
View Full Code Here

TOP

Related Classes of org.apache.directory.server.dhcp.service.Lease

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.