コード例 #1
0
        /**
         * Build a BindingPrefix for the given InetAddress and Link.
         *
         * @param inetAddr the inet addr
         * @param clientLink the client link
         * @param requestMsg the request msg
         *
         * @return the binding address
         */
        protected override BindingObject BuildBindingObject(IPAddress inetAddr,
                                                            DhcpLink clientLink, DhcpMessage requestMsg)
        {
            V6PrefixBindingPool bp =
                (V6PrefixBindingPool)FindBindingPool(clientLink.GetLink(), inetAddr, requestMsg);

            if (bp != null)
            {
                bp.SetUsed(inetAddr);   // TODO check if this is necessary
                IaPrefix iaPrefix = new IaPrefix();
                iaPrefix.SetIpAddress(inetAddr);
                iaPrefix.SetPrefixLength((short)bp.GetAllocPrefixLen());
                V6BindingPrefix bindingPrefix = new V6BindingPrefix(iaPrefix, bp);
                SetBindingObjectTimes(bindingPrefix,
                                      bp.GetPreferredLifetimeMs(), bp.GetPreferredLifetimeMs());
                // TODO store the configured options in the persisted binding?
                // bindingPrefix.setDhcpOptions(bp.getDhcpOptions());
                return(bindingPrefix);
            }
            else
            {
                log.Error("Failed to create BindingPrefix: No BindingPool found for IP=" +
                          inetAddr.ToString());
            }
            // MUST have a BindingPool, otherwise something's broke
            return(null);
        }
コード例 #2
0
        /**
         * Builds a binding pool from an PrefixPool using the given link and filter.
         *
         * @param pool the AddressPool to wrap as an PrefixBindingPool
         * @param link the link
         * @param linkFilter the link filter
         *
         * @return the binding pool
         *
         * @throws DhcpServerConfigException if there is a problem parsing the configured range
         */
        protected V6PrefixBindingPool BuildV6BindingPool(v6PrefixPool pool, link link,
                                                         linkFilter linkFilter)
        {
            V6PrefixBindingPool bp = new V6PrefixBindingPool(pool);
            long pLifetime         =
                DhcpServerPolicies.EffectivePolicyAsLong(bp, link, Property.PREFERRED_LIFETIME);

            bp.SetPreferredLifetime(pLifetime);
            long vLifetime =
                DhcpServerPolicies.EffectivePolicyAsLong(bp, link, Property.VALID_LIFETIME);

            bp.SetValidLifetime(vLifetime);
            bp.SetLinkFilter(linkFilter);

            List <IPAddress> usedIps = iaMgr.FindExistingIPs(bp.GetStartAddress(), bp.GetEndAddress());

            if ((usedIps != null) && usedIps.Count > 0)
            {
                foreach (IPAddress ip in usedIps)
                {
                    //TODO: for the quickest startup?...
                    // set IP as used without checking if the binding has expired
                    // let the reaper thread deal with all binding cleanup activity
                    bp.SetUsed(ip);
                }
            }
            log.Info("Built prefix binding pool: " + bp.GetStartAddress().ToString() + "-" +
                     bp.GetEndAddress().ToString() + ", size=" + bp.GetSize());
            return(bp);
        }
コード例 #3
0
        /**
         * Build the list of PrefixBindingPools from the list of configured PrefixPools
         * for the given configuration Link container object. The list of PrefixBindingPools
         * starts with the filtered PrefixPools followed by non-filtered PrefixPools.
         *
         * @param link the configuration Link object
         *
         * @return the list of PrefixBindingPools (<? extends BindingPool>)
         *
         * @throws DhcpServerConfigException if there is a problem parsing a configured range
         */
        protected override List <BindingPool> BuildBindingPools(link link)
        {
            List <BindingPool> bindingPools = new List <BindingPool>();
            // Put the filtered pools first in the list of pools on this link
            List <linkFilter> linkFilters = link.linkFilters;

            foreach (linkFilter linkFilter in linkFilters)
            {
                List <v6PrefixPool> poolsType = linkFilter.v6PrefixPools;
                if (poolsType != null)
                {
                    // add the filtered pools to the mapped list
                    List <v6PrefixPool> pools = poolsType;
                    if ((pools != null) && pools.Count > 0)
                    {
                        foreach (v6PrefixPool pool in pools)
                        {
                            V6PrefixBindingPool abp = BuildV6BindingPool(pool, link, linkFilter);
                            bindingPools.Add(abp);
                        }
                    }
                    else
                    {
                        log.Error("PoolList is null for PoolsType: " + poolsType);
                    }
                }
                else
                {
                    log.Info("PoolsType is null for LinkFilter: " + linkFilter.name);
                }
            }

            // add the unfiltered pools to the mapped list
            List <v6PrefixPool> unpools = link.v6PrefixPools;

            if ((unpools != null) && unpools.Count > 0)
            {
                foreach (v6PrefixPool pool in unpools)
                {
                    V6PrefixBindingPool abp = BuildV6BindingPool(pool, link);
                    bindingPools.Add(abp);
                }
            }
            else
            {
                log.Error("PoolList is null for PoolsType");
            }

            ReconcilePools(bindingPools);

            return(bindingPools);
        }