lease_mgr.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include <dhcpsrv/lease_mgr.h>
  15. #include <exceptions/exceptions.h>
  16. #include <boost/foreach.hpp>
  17. #include <boost/algorithm/string.hpp>
  18. #include <algorithm>
  19. #include <iostream>
  20. #include <iterator>
  21. #include <map>
  22. #include <sstream>
  23. #include <string>
  24. #include <time.h>
  25. using namespace std;
  26. namespace isc {
  27. namespace dhcp {
  28. std::string LeaseMgr::getParameter(const std::string& name) const {
  29. ParameterMap::const_iterator param = parameters_.find(name);
  30. if (param == parameters_.end()) {
  31. isc_throw(BadValue, "Parameter not found");
  32. }
  33. return (param->second);
  34. }
  35. Lease6Ptr
  36. LeaseMgr::getLease6(Lease::Type type, const DUID& duid,
  37. uint32_t iaid, SubnetID subnet_id) const {
  38. Lease6Collection col = getLeases6(type, duid, iaid, subnet_id);
  39. if (col.size() > 1) {
  40. isc_throw(MultipleRecords, "More than one lease found for type "
  41. << static_cast<int>(type) << ", duid "
  42. << duid.toText() << ", iaid " << iaid
  43. << " and subnet-id " << subnet_id);
  44. }
  45. if (col.empty()) {
  46. return (Lease6Ptr());
  47. }
  48. return (*col.begin());
  49. }
  50. } // namespace isc::dhcp
  51. } // namespace isc