/// <summary> /// Sets the lifetimes of the given binding object. /// </summary> /// <param name="bindingObj">binding object</param> /// <param name="preferred">preferred lifetime in ms</param> /// <param name="valid">valid lifetime in ms</param> protected void SetBindingObjectTimes(BindingObject bindingObj, long preferred, long valid) { if (_log.IsDebugEnabled) { _log.Debug("Updating binding times for address: " + bindingObj.GetIpAddress().ToString() + " preferred=" + preferred + ", valid=" + valid); } DateTime now = DateTime.Now; bindingObj.SetStartTime(now); if (preferred < 0) { // infinite lease bindingObj.SetPreferredEndTime(new DateTime(-1)); } else { bindingObj.SetPreferredEndTime(now.AddMilliseconds(preferred)); } if (valid < 0) { // infinite lease bindingObj.SetValidEndTime(now.AddDays(-1)); } else { bindingObj.SetValidEndTime(now.AddMilliseconds(valid)); } }
/** * Adds the v4 binding to reply. * * @param clientLink the client link * @param binding the binding */ protected void AddBindingToReply(DhcpLink clientLink, Binding binding) { HashSet <BindingObject> bindingObjs = binding.GetBindingObjects(); if ((bindingObjs != null) && bindingObjs.Count > 0) { if (bindingObjs.Count == 1) { BindingObject bindingObj = bindingObjs.First(); IPAddress inetAddr = bindingObj.GetIpAddress(); if (inetAddr != null) { _replyMsg.SetYiAddr(inetAddr); // must be an DhcpV4OptionConfigObject for v4 binding DhcpV4OptionConfigObject configObj = (DhcpV4OptionConfigObject)bindingObj.GetConfigObj(); if (configObj != null) { long preferred = configObj.GetPreferredLifetime(); DhcpV4LeaseTimeOption dhcpV4LeaseTimeOption = new DhcpV4LeaseTimeOption(); dhcpV4LeaseTimeOption.SetUnsignedInt(preferred); _replyMsg.PutDhcpOption(dhcpV4LeaseTimeOption); PopulateV4Reply(clientLink, configObj); //TODO when do actually start the timer? currently, two get // created - one during advertise, one during reply // policy to allow real-time expiration? // bp.startExpireTimerTask(bindingAddr, iaAddrOption.getValidLifetime()); } else { log.Error("Null binding pool in binding: " + binding.ToString()); } } else { log.Error("Null address in binding: " + binding.ToString()); } } else { log.Error("Expected only one bindingObject in v4 Binding, but found " + bindingObjs.Count + "bindingObjects"); } } else { log.Error("No V4 bindings in binding object!"); } }