예제 #1
0
        // Conversion methods

        /**
         * To identity assoc.
         *
         * @param leases the leases
         * @return the identity assoc
         */
        protected IdentityAssoc ToIdentityAssoc(List <DhcpLease> leases)
        {
            IdentityAssoc ia = null;

            if ((leases != null) && leases.Count > 0)
            {
                var  enumerator = leases.GetEnumerator();
                bool hasNext    = enumerator.MoveNext();

                DhcpLease lease = enumerator.Current;
                ia = new IdentityAssoc();
                ia.SetDuid(lease.GetDuid());
                ia.SetIatype(lease.GetIatype());
                ia.SetIaid(lease.GetIaid());
                ia.SetState(lease.GetState());
                ia.SetDhcpOptions(lease.GetIaDhcpOptions());
                if (lease.GetIatype() == IdentityAssoc.PD_TYPE)
                {
                    List <IaAddress> iaPrefixes = new List <IaAddress>();
                    iaPrefixes.Add(ToIaPrefix(lease));
                    while (enumerator.MoveNext())
                    {
                        //TODO: should confirm that the duid/iatype/iaid/state still match
                        iaPrefixes.Add(ToIaPrefix(lease));
                    }
                    ia.SetIaAddresses(iaPrefixes);
                }
                else
                {
                    List <IaAddress> iaAddrs = new List <IaAddress>();
                    iaAddrs.Add(ToIaAddress(lease));
                    while (enumerator.MoveNext())
                    {
                        //TODO: should confirm that the duid/iatype/iaid/state still match
                        iaAddrs.Add(ToIaAddress(lease));
                    }
                    ia.SetIaAddresses(iaAddrs);
                }
            }
            return(ia);
        }
예제 #2
0
        /**
         * Find ia.
         *
         * @param inetAddr the inet addr
         * @param allBindings the all bindings
         * @return the identity assoc
         */
        public IdentityAssoc FindIA(IPAddress inetAddr, bool allBindings)
        {
            IdentityAssoc ia    = null;
            DhcpLease     lease = FindDhcpLeaseForInetAddr(inetAddr);

            if (lease != null)
            {
                // use a set here, so that if we are getting all bindings, then we don't
                // include the lease found above again in the returned collection
                List <DhcpLease> leases = new List <DhcpLease>();
                leases.Add(lease);
                if (allBindings)
                {
                    leases.AddRange(FindDhcpLeasesForIA(lease.GetDuid(), lease.GetIatype(), lease.GetIaid()));
                    //leases = leases.Concat(FindDhcpLeasesForIA(lease.GetDuid(), lease.GetIatype(), lease.GetIaid())).ToList();
                }
                ia = ToIdentityAssoc(leases);
            }
            return(ia);
        }