memfile_lease_mgr.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (C) 2012 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/memfile_lease_mgr.h>
  15. #include <iostream>
  16. using namespace isc::dhcp;
  17. Memfile_LeaseMgr::Memfile_LeaseMgr(const ParameterMap& parameters)
  18. : LeaseMgr(parameters) {
  19. std::cout << "Warning: Using memfile database backend. It is usable for limited"
  20. << " testing only. Leases will be lost after restart." << std::endl;
  21. }
  22. Memfile_LeaseMgr::~Memfile_LeaseMgr() {
  23. }
  24. bool Memfile_LeaseMgr::addLease(const Lease4Ptr&) {
  25. return (false);
  26. }
  27. bool Memfile_LeaseMgr::addLease(const Lease6Ptr& lease) {
  28. if (getLease6(lease->addr_)) {
  29. // there is a lease with specified address already
  30. return (false);
  31. }
  32. storage6_.insert(lease);
  33. return (true);
  34. }
  35. Lease4Ptr Memfile_LeaseMgr::getLease4(const isc::asiolink::IOAddress&) const {
  36. return (Lease4Ptr());
  37. }
  38. Lease4Collection Memfile_LeaseMgr::getLease4(const HWAddr& ) const {
  39. return (Lease4Collection());
  40. }
  41. Lease4Ptr Memfile_LeaseMgr::getLease4(const HWAddr&,
  42. SubnetID) const {
  43. return (Lease4Ptr());
  44. }
  45. Lease4Ptr Memfile_LeaseMgr::getLease4(const ClientId&,
  46. SubnetID) const {
  47. return (Lease4Ptr());
  48. }
  49. Lease4Collection Memfile_LeaseMgr::getLease4(const ClientId& ) const {
  50. return (Lease4Collection());
  51. }
  52. Lease6Ptr Memfile_LeaseMgr::getLease6(const isc::asiolink::IOAddress& addr) const {
  53. Lease6Storage::iterator l = storage6_.find(addr);
  54. if (l == storage6_.end()) {
  55. return (Lease6Ptr());
  56. } else {
  57. return (*l);
  58. }
  59. }
  60. Lease6Collection Memfile_LeaseMgr::getLease6(const DUID& , uint32_t ) const {
  61. return (Lease6Collection());
  62. }
  63. Lease6Ptr Memfile_LeaseMgr::getLease6(const DUID& duid, uint32_t iaid,
  64. SubnetID subnet_id) const {
  65. /// @todo: Slow, naive implementation. Write it using additional indexes
  66. for (Lease6Storage::iterator l = storage6_.begin(); l != storage6_.end(); ++l) {
  67. if ( (*((*l)->duid_) == duid) &&
  68. ( (*l)->iaid_ == iaid) &&
  69. ( (*l)->subnet_id_ == subnet_id)) {
  70. return (*l);
  71. }
  72. }
  73. return (Lease6Ptr());
  74. }
  75. void Memfile_LeaseMgr::updateLease4(const Lease4Ptr& ) {
  76. }
  77. void Memfile_LeaseMgr::updateLease6(const Lease6Ptr& ) {
  78. }
  79. bool Memfile_LeaseMgr::deleteLease(const isc::asiolink::IOAddress& addr) {
  80. if (addr.isV4()) {
  81. // V4 not implemented yet
  82. return (false);
  83. } else {
  84. // V6 lease
  85. Lease6Storage::iterator l = storage6_.find(addr);
  86. if (l == storage6_.end()) {
  87. // No such lease
  88. return (false);
  89. } else {
  90. storage6_.erase(l);
  91. return (true);
  92. }
  93. }
  94. }
  95. std::string Memfile_LeaseMgr::getDescription() const {
  96. return (std::string("This is a dummy memfile backend implementation.\n"
  97. "It does not offer any useful lease management and its only\n"
  98. "purpose is to test abstract lease manager API."));
  99. }
  100. void
  101. Memfile_LeaseMgr::commit() {
  102. }
  103. void
  104. Memfile_LeaseMgr::rollback() {
  105. }