Beispiel #1
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);
         }
     }
 }
        /* (non-Javadoc)
         * @see java.lang.Object#equals(java.lang.Object)
         */
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if ((this.GetType() != obj.GetType()))
            {
                return(false);
            }
            if (!(obj is IdentityAssoc))
            {
                return(false);
            }

            IdentityAssoc other = (IdentityAssoc)obj;

            if (!Array.Equals(duid, other.duid))
            {
                return(false);
            }
            if (iaid != other.iaid)
            {
                return(false);
            }
            if (iatype != other.iatype)
            {
                return(false);
            }
            if (id == 0)
            {
                if (other.id != 0)
                {
                    return(false);
                }
            }
            else if (!id.Equals(other.id))
            {
                return(false);
            }
            if (state != other.state)
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
 /* (non-Javadoc)
  * @see com.jagornet.dhcpv6.db.IaManager#deleteIA(com.jagornet.dhcpv6.db.IdentityAssoc)
  */
 public void DeleteIA(IdentityAssoc ia)
 {
     if (ia != null)
     {
         List <DhcpLease> leases = ToDhcpLeases(ia);
         if ((leases != null) && leases.Count > 0)
         {
             foreach (DhcpLease lease in leases)
             {
                 DeleteDhcpLease(lease);
             }
         }
     }
 }
Beispiel #4
0
        protected List <IdentityAssoc> ToIdentityAssocs(List <DhcpLease> leases)
        {
            List <IdentityAssoc> ias = null;

            if ((leases != null) && leases.Count > 0)
            {
                ias = new List <IdentityAssoc>();
                // for each lease, create a separate IdentityAssoc
                foreach (DhcpLease lease in leases)
                {
                    List <DhcpLease> _leases = new List <DhcpLease>();
                    _leases.Add(lease);
                    IdentityAssoc ia = ToIdentityAssoc(_leases);
                    ias.Add(ia);
                }
            }
            return(ias);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
 }
 public void DeleteIA(IdentityAssoc ia)
 {
 }
 public void UpdateIA(IdentityAssoc ia, List <IaAddress> addAddrs, List <IaAddress> updateAddrs, List <IaAddress> delAddrs)
 {
 }
 public void CreateIA(IdentityAssoc ia)
 {
 }