]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
added get4 and get4subnetid for cql
authorRazvan Becheriu <razvan.becheriu@qualitance.com>
Mon, 19 Feb 2018 16:16:21 +0000 (18:16 +0200)
committerRazvan Becheriu <razvan.becheriu@qualitance.com>
Mon, 19 Feb 2018 16:16:21 +0000 (18:16 +0200)
src/lib/dhcpsrv/cql_lease_mgr.cc
src/lib/dhcpsrv/dhcpsrv_messages.mes

index 8f3c351b7ffd33a99857a559187cd6f927b93f0e..5b43200c319e5fa1911d6d0c0ff594eb009ef00e 100644 (file)
@@ -205,18 +205,20 @@ public:
     static constexpr StatementTag DELETE_LEASE4 = "DELETE_LEASE4";
     // Delete expired lease4s in certain state
     static constexpr StatementTag GET_LEASE4_EXPIRE = "GET_LEASE4_EXPIRE";
+    // Get lease4
+    static constexpr StatementTag GET_LEASE4 = "GET_LEASE4";
     // Get lease4 by address
     static constexpr StatementTag GET_LEASE4_ADDR = "GET_LEASE4_ADDR";
     // Get lease4 by client ID
     static constexpr StatementTag GET_LEASE4_CLIENTID = "GET_LEASE4_CLIENTID";
     // Get lease4 by client ID & subnet ID
-    static constexpr StatementTag GET_LEASE4_CLIENTID_SUBID =
-        "GET_LEASE4_CLIENTID_SUBID";
+    static constexpr StatementTag GET_LEASE4_CLIENTID_SUBID = "GET_LEASE4_CLIENTID_SUBID";
     // Get lease4 by HW address
     static constexpr StatementTag GET_LEASE4_HWADDR = "GET_LEASE4_HWADDR";
     // Get lease4 by HW address & subnet ID
-    static constexpr StatementTag GET_LEASE4_HWADDR_SUBID =
-        "GET_LEASE4_HWADDR_SUBID";
+    static constexpr StatementTag GET_LEASE4_HWADDR_SUBID = "GET_LEASE4_HWADDR_SUBID";
+    // Get lease4 by subnet ID
+    static constexpr StatementTag GET_LEASE4_SUBID = "GET_LEASE4_SUBID";
     /// @}
 
 private:
@@ -232,11 +234,13 @@ constexpr StatementTag CqlLease4Exchange::INSERT_LEASE4;
 constexpr StatementTag CqlLease4Exchange::UPDATE_LEASE4;
 constexpr StatementTag CqlLease4Exchange::DELETE_LEASE4;
 constexpr StatementTag CqlLease4Exchange::GET_LEASE4_EXPIRE;
+constexpr StatementTag CqlLease4Exchange::GET_LEASE4;
 constexpr StatementTag CqlLease4Exchange::GET_LEASE4_ADDR;
 constexpr StatementTag CqlLease4Exchange::GET_LEASE4_CLIENTID;
 constexpr StatementTag CqlLease4Exchange::GET_LEASE4_CLIENTID_SUBID;
 constexpr StatementTag CqlLease4Exchange::GET_LEASE4_HWADDR;
 constexpr StatementTag CqlLease4Exchange::GET_LEASE4_HWADDR_SUBID;
+constexpr StatementTag CqlLease4Exchange::GET_LEASE4_SUBID;
 
 StatementMap CqlLease4Exchange::tagged_statements_{
 
@@ -286,6 +290,14 @@ StatementMap CqlLease4Exchange::tagged_statements_{
       "LIMIT ? "
       "ALLOW FILTERING "}},
 
+     // Gets an IPv4 lease(s)
+     {GET_LEASE4,
+      {GET_LEASE4,
+       "SELECT "
+       "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
+       "fqdn_fwd, fqdn_rev, hostname, state "
+       "FROM lease4 "}},
+
     // Gets an IPv4 lease with specified IPv4 address
     {GET_LEASE4_ADDR,
      {GET_LEASE4_ADDR,
@@ -337,6 +349,15 @@ StatementMap CqlLease4Exchange::tagged_statements_{
       "AND subnet_id = ? "
       "ALLOW FILTERING "}},
 
+     // Gets an IPv4 lease(s) with specified subnet-id
+     {GET_LEASE4_SUBID,
+      {GET_LEASE4_SUBID,
+       "SELECT "
+       "address, hwaddr, client_id, valid_lifetime, expire, subnet_id, "
+       "fqdn_fwd, fqdn_rev, hostname, state "
+       "FROM lease4 "
+       "WHERE subnet_id = ? "
+       "ALLOW FILTERING "}}
 };
 
 CqlLease4Exchange::CqlLease4Exchange(const CqlConnection &connection)
@@ -361,7 +382,7 @@ CqlLease4Exchange::createBindForInsert(const Lease4Ptr &lease, AnyArray &data) {
         address_ = static_cast<cass_int32_t>(lease->addr_.toUint32());
 
         // hwaddr: blob
-        if (lease_->hwaddr_ && lease->hwaddr_->hwaddr_.size() > 0) {
+        if (lease_->hwaddr_ && lease_->hwaddr_->hwaddr_.size() > 0) {
             if (lease_->hwaddr_->hwaddr_.size() > HWAddr::MAX_HWADDR_LEN) {
                 isc_throw(DbOperationError,
                           "hardware address "
@@ -376,7 +397,7 @@ CqlLease4Exchange::createBindForInsert(const Lease4Ptr &lease, AnyArray &data) {
         }
 
         // client_id: blob
-        if (lease_->client_id_ && lease->client_id_->getClientId().size() > 0) {
+        if (lease_->client_id_ && lease_->client_id_->getClientId().size() > 0) {
             client_id_ = lease_->client_id_->getClientId();
         } else {
             client_id_.clear();
@@ -455,7 +476,7 @@ CqlLease4Exchange::createBindForUpdate(const Lease4Ptr &lease, AnyArray &data,
         address_ = static_cast<cass_int32_t>(lease->addr_.toUint32());
 
         // hwaddr: blob
-        if (lease_->hwaddr_ && lease->hwaddr_->hwaddr_.size() > 0) {
+        if (lease_->hwaddr_ && lease_->hwaddr_->hwaddr_.size() > 0) {
             if (lease_->hwaddr_->hwaddr_.size() > HWAddr::MAX_HWADDR_LEN) {
                 isc_throw(DbOperationError,
                           "hardware address "
@@ -470,7 +491,7 @@ CqlLease4Exchange::createBindForUpdate(const Lease4Ptr &lease, AnyArray &data,
         }
 
         // client_id: blob
-        if (lease_->client_id_ && lease->client_id_->getClientId().size() > 0) {
+        if (lease_->client_id_ && lease_->client_id_->getClientId().size() > 0) {
             client_id_ = lease_->client_id_->getClientId();
         } else {
             client_id_.clear();
@@ -1024,7 +1045,7 @@ CqlLease6Exchange::createBindForInsert(const Lease6Ptr &lease, AnyArray &data) {
         hostname_ = lease_->hostname_;
 
         // hwaddr: blob
-        if (lease_->hwaddr_ && lease->hwaddr_->hwaddr_.size() > 0) {
+        if (lease_->hwaddr_ && lease_->hwaddr_->hwaddr_.size() > 0) {
             if (lease_->hwaddr_->hwaddr_.size() > HWAddr::MAX_HWADDR_LEN) {
                 isc_throw(DbOperationError, "hardware address " << lease_->hwaddr_->toText()
                           << " of length " << lease_->hwaddr_->hwaddr_.size()
@@ -1155,7 +1176,7 @@ CqlLease6Exchange::createBindForUpdate(const Lease6Ptr &lease, AnyArray &data,
         hostname_ = lease_->hostname_;
 
         // hwaddr: blob
-        if (lease_->hwaddr_ && lease->hwaddr_->hwaddr_.size() > 0) {
+        if (lease_->hwaddr_ && lease_->hwaddr_->hwaddr_.size() > 0) {
             if (lease_->hwaddr_->hwaddr_.size() > HWAddr::MAX_HWADDR_LEN) {
                 isc_throw(DbOperationError,
                           "hardware address "
@@ -1617,13 +1638,37 @@ CqlLeaseMgr::getLease4(const ClientId &clientid, SubnetID subnet_id) const {
 }
 
 Lease4Collection
-CqlLeaseMgr::getLeases4(SubnetID) const {
-    isc_throw(NotImplemented, "getLeases4(subnet_id) is not implemented");
+CqlLeaseMgr::getLeases4(SubnetID subnet_id) const {
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET_SUBID4)
+        .arg(subnet_id);
+
+    // Set up the WHERE clause value
+    AnyArray data;
+
+    cass_int32_t subnet_id_data = static_cast<cass_int32_t>(subnet_id);
+    data.add(&subnet_id_data);
+
+    // Get the data.
+    Lease4Collection result;
+    std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
+    exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4, data, result);
+
+    return (result);
 }
 
 Lease4Collection
 CqlLeaseMgr::getLeases4() const {
-    isc_throw(NotImplemented, "getLeases4() is not implemented");
+    LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_GET4);
+
+    // Set up the WHERE clause value
+    AnyArray data;
+
+    // Get the data.
+    Lease4Collection result;
+    std::unique_ptr<CqlLease4Exchange> exchange4(new CqlLease4Exchange(dbconn_));
+    exchange4->getLeaseCollection(CqlLease4Exchange::GET_LEASE4_SUBID, data, result);
+
+    return (result);
 }
 
 Lease6Ptr
index ad5a7d40f3ea46a6cbf0fb77475b05c26e5030f3..3e279513c97e5b381a81f60b83ce1d5eec9f7963 100644 (file)
@@ -223,6 +223,10 @@ leases which have expired longer than a specified period of time.
 The argument is the amount of time Kea waits after a reclaimed
 lease expires before considering its removal.
 
+% DHCPSRV_CQL_GET4 obtaining all IPv4 leases
+A debug message issued when the server is attempting to obtain all IPv4
+leases from the Cassandra database.
+
 % DHCPSRV_CQL_GET_ADDR4 obtaining IPv4 lease for address %1
 A debug message issued when the server is attempting to obtain an IPv4
 lease from the Cassandra database for the specified address.
@@ -266,6 +270,10 @@ A debug message issued when the server is attempting to obtain an IPv6
 lease from the Cassandra database for a client with the specified IAID
 (Identity Association ID), Subnet ID and DUID (DHCP Unique Identifier).
 
+% DHCPSRV_CQL_GET_SUBID4 obtaining IPv4 leases for subnet ID %1
+A debug message issued when the server is attempting to obtain all IPv4
+leases for a given subnet identifier from the Cassandra database.
+
 % DHCPSRV_CQL_GET_SUBID_CLIENTID obtaining IPv4 lease for subnet ID %1 and client ID %2
 A debug message issued when the server is attempting to obtain an IPv4
 lease from the Cassandra database for a client with the specified