]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
implemented getPage4 and getPage6 using getAll4 and getAll6, sorting and filtering
authorRazvan Becheriu <ravan@isc.org>
Tue, 12 Mar 2019 14:30:50 +0000 (16:30 +0200)
committerTomek Mrugalski <tomek@isc.org>
Fri, 19 Apr 2019 07:55:02 +0000 (03:55 -0400)
src/lib/dhcpsrv/cql_host_data_source.cc

index 7e5c974c7a2aeab87d030eb2c8b26b96af275852..42e7b916628a5f2f7f3ef62d38c5265cf509c021 100644 (file)
@@ -1985,19 +1985,47 @@ CqlHostDataSourceImpl::getAll6(const SubnetID& subnet_id) const {
 // paging at the API level.
 
 ConstHostCollection
-CqlHostDataSourceImpl::getPage4(const SubnetID& /*subnet_id*/,
-                                uint64_t /*lower_host_id*/,
-                                const HostPageSize& /*page_size*/) const {
-    isc_throw(NotImplemented,
-              "reservation-get-page is not supported by Cassandra");
+CqlHostDataSourceImpl::getPage4(const SubnetID& subnet_id,
+                                uint64_t lower_host_id,
+                                const HostPageSize& page_size) const {
+    ConstHostCollection hosts = getAll4(subnet_id);
+    std::sort(hosts.begin(), hosts.end(), [](ConstHostPtr a, ConstHostPtr b) {
+        return a->getHostId() > b->getHostId();
+    });
+    ConstHostCollection result;
+    size_t count = 0;
+    for (auto host : hosts) {
+        if (host->getHostId() > lower_host_id) {
+            result.push_back(host);
+            count++;
+            if (count == page_size.page_size_) {
+                break;
+            }
+        }
+    }
+    return (result);
 }
 
 ConstHostCollection
-CqlHostDataSourceImpl::getPage6(const SubnetID& /*subnet_id*/,
-                                uint64_t /*lower_host_id*/,
-                                const HostPageSize& /*page_size*/) const {
-    isc_throw(NotImplemented,
-              "reservation-get-page is not supported by Cassandra");
+CqlHostDataSourceImpl::getPage6(const SubnetID& subnet_id,
+                                uint64_t lower_host_id,
+                                const HostPageSize& page_size) const {
+    ConstHostCollection hosts = getAll6(subnet_id);
+    std::sort(hosts.begin(), hosts.end(), [](ConstHostPtr a, ConstHostPtr b) {
+        return a->getHostId() > b->getHostId();
+    });
+    ConstHostCollection result;
+    size_t count = 0;
+    for (auto host : hosts) {
+        if (host->getHostId() > lower_host_id) {
+            result.push_back(host);
+            count++;
+            if (count == page_size.page_size_) {
+                break;
+            }
+        }
+    }
+    return (result);
 }
 
 ConstHostCollection