예제 #1
0
        public void DeleteDhcpOption(IaAddress iaAddr, BaseDhcpOption baseOption)
        {
            DhcpLease lease = FindDhcpLeaseForInetAddr(iaAddr.GetIpAddress());

            if (lease != null)
            {
                List <DhcpOption> iaAddrOptions = lease.GetIaAddrDhcpOptions();
                if (iaAddrOptions != null)
                {
                    bool deleted = false;
                    foreach (DhcpOption iaAddrOption in iaAddrOptions)
                    {
                        if (iaAddrOption.GetCode() == baseOption.GetCode())
                        {
                            iaAddrOptions.Remove(iaAddrOption);
                            deleted = true;
                            break;
                        }
                    }
                    if (deleted)
                    {
                        UpdateIpAddrOptions(iaAddr.GetIpAddress(), iaAddrOptions);
                    }
                }
            }
        }
예제 #2
0
 /* (non-Javadoc)
  * @see com.jagornet.dhcpv6.db.IaManager#updateIA(com.jagornet.dhcpv6.db.IdentityAssoc, java.util.List, java.util.List, java.util.List)
  */
 public void UpdateIA(IdentityAssoc ia, List <IaAddress> addAddrs, List <IaAddress> updateAddrs, List <IaAddress> delAddrs)
 {
     if ((addAddrs != null) && addAddrs.Count > 0)
     {
         foreach (IaAddress addAddr in addAddrs)
         {
             DhcpLease lease = ToDhcpLease(ia, addAddr);
             InsertDhcpLease(lease);
         }
     }
     if ((updateAddrs != null) && updateAddrs.Count > 0)
     {
         foreach (IaAddress updateAddr in updateAddrs)
         {
             DhcpLease lease = ToDhcpLease(ia, updateAddr);
             UpdateDhcpLease(lease);
         }
     }
     if ((delAddrs != null) && delAddrs.Count > 0)
     {
         foreach (IaAddress delAddr in delAddrs)
         {
             DhcpLease lease = ToDhcpLease(ia, delAddr);
             DeleteDhcpLease(lease);
         }
     }
 }
예제 #3
0
 /**
  * Update dhcp lease.
  *
  * @param lease the lease
  */
 protected void UpdateDhcpLease(DhcpLease lease)
 {
     foreach (var item in _DhcpLeaseData.Where(p => p.GetIpAddress() == lease.GetIpAddress()))
     {
         item.SetState(lease.GetState());
         item.SetStartTime(lease.GetStartTime());
         item.SetPreferredEndTime(lease.GetPreferredEndTime());
         item.SetValidEndTime(lease.GetValidEndTime());
         item.SetIaDhcpOptions(lease.GetIaDhcpOptions());
         item.SetIaAddrDhcpOptions(lease.GetIaAddrDhcpOptions());
     }
 }
예제 #4
0
        /**
         * To ia address.
         *
         * @param lease the lease
         * @return the ia address
         */
        protected IaAddress ToIaAddress(DhcpLease lease)
        {
            IaAddress iaAddr = new IaAddress();

            iaAddr.SetIpAddress(lease.GetIpAddress());
            iaAddr.SetState(lease.GetState());
            iaAddr.SetStartTime(lease.GetStartTime());
            iaAddr.SetPreferredEndTime(lease.GetPreferredEndTime());
            iaAddr.SetValidEndTime(lease.GetValidEndTime());
            iaAddr.SetDhcpOptions(lease.GetIaAddrDhcpOptions());
            return(iaAddr);
        }
예제 #5
0
        /**
         * To ia prefix.
         *
         * @param lease the lease
         * @return the ia prefix
         */
        protected IaPrefix ToIaPrefix(DhcpLease lease)
        {
            IaPrefix iaPrefix = new IaPrefix();

            iaPrefix.SetIpAddress(lease.GetIpAddress());
            iaPrefix.SetPrefixLength(lease.GetPrefixLength());
            iaPrefix.SetState(lease.GetState());
            iaPrefix.SetStartTime(lease.GetStartTime());
            iaPrefix.SetPreferredEndTime(lease.GetPreferredEndTime());
            iaPrefix.SetValidEndTime(lease.GetValidEndTime());
            iaPrefix.SetDhcpOptions(lease.GetIaAddrDhcpOptions());
            return(iaPrefix);
        }
예제 #6
0
        /**
         * To dhcp lease.
         *
         * @param ia the ia
         * @param iaAddr the ia addr
         * @return the dhcp lease
         */
        protected DhcpLease ToDhcpLease(IdentityAssoc ia, IaAddress iaAddr)
        {
            DhcpLease lease = new DhcpLease();

            lease.SetDuid(ia.GetDuid());
            lease.SetIaid(ia.GetIaid());
            lease.SetIatype(ia.GetIatype());
            lease.SetIpAddress(iaAddr.GetIpAddress());
            if (iaAddr is IaPrefix)
            {
                lease.SetPrefixLength(((IaPrefix)iaAddr).GetPrefixLength());
            }
            lease.SetState(iaAddr.GetState());
            lease.SetStartTime(iaAddr.GetStartTime());
            lease.SetPreferredEndTime(iaAddr.GetPreferredEndTime());
            lease.SetValidEndTime(iaAddr.GetValidEndTime());
            lease.SetIaAddrDhcpOptions(iaAddr.GetDhcpOptions());
            lease.SetIaDhcpOptions(ia.GetDhcpOptions());
            return(lease);
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
0
 /**
  * To dhcp leases.
  *
  * @param ia the ia
  * @return the list
  */
 protected List <DhcpLease> ToDhcpLeases(IdentityAssoc ia)
 {
     if (ia != null)
     {
         List <IaAddress> iaAddrs = ia.GetIaAddresses();
         if ((iaAddrs != null) && iaAddrs.Count > 0)
         {
             List <DhcpLease> leases = new List <DhcpLease>();
             foreach (IaAddress iaAddr in iaAddrs)
             {
                 DhcpLease lease = ToDhcpLease(ia, iaAddr);
                 leases.Add(lease);
             }
             return(leases);
         }
         else
         {
             log.Warn("No addresses in lease");
         }
     }
     return(null);
 }
예제 #10
0
        protected DhcpOption FindIaAddressOption(IaAddress iaAddr, BaseDhcpOption baseOption)
        {
            DhcpOption dbOption = null;
            DhcpLease  lease    = FindDhcpLeaseForInetAddr(iaAddr.GetIpAddress());

            if (lease != null)
            {
                List <DhcpOption> iaAddrOptions = lease.GetIaAddrDhcpOptions();
                if (iaAddrOptions != null)
                {
                    foreach (DhcpOption iaAddrOption in iaAddrOptions)
                    {
                        if (iaAddrOption.GetCode() == baseOption.GetCode())
                        {
                            dbOption = iaAddrOption;
                            break;
                        }
                    }
                }
            }
            return(dbOption);
        }
예제 #11
0
 /**
  * Delete dhcp lease.
  *
  * @param lease the lease
  */
 protected void DeleteDhcpLease(DhcpLease lease)
 {
     _DhcpLeaseData.RemoveAll(d => d.GetIpAddress().ToString() == lease.GetIpAddress().ToString());
 }
예제 #12
0
 protected void InsertDhcpLease(DhcpLease lease)
 {
     _DhcpLeaseData.Add(lease);
 }