4#include <asiolink/io_address.h>
5#include <dhcp/hwaddr.h>
7#include <hiredis/hiredis.h>
15inline std::string get_ip2mac_key(std::string_view suffix)
17 return "ip2mac-" + std::string{suffix};
20inline std::string sanitize_ip_address_string(
const std::string& ip_str)
22 const isc::asiolink::IOAddress ip_addr{ip_str};
23 return ip_addr.toText();
26inline std::string sanitize_mac_address_string(
const std::string& mac_str)
28 const auto mac = isc::dhcp::HWAddr::fromText(mac_str);
29 return mac.toText(
false);
44 const std::string redis_key = get_ip2mac_key(sanitize_ip_address_string(std::string{ip}));
45 const auto redis_reply = redis.
get(redis_key);
48 if (redis_reply->type == REDIS_REPLY_NIL) {
51 if (redis_reply->type != REDIS_REPLY_STRING) {
52 throw std::runtime_error(
"Unexpected Redis reply type");
55 assert(redis_reply->str);
56 return {redis_reply->str};
virtual get_reply_t get(const std::string &key)
void register_method_handlers(XmlRpcServer &rpc_server)
Register this instance's method handlers in the aai::XmlRpcServer.
std::optional< std::string > resolve_ip_to_mac(std::string_view ip)
Abstraction for an XML-RPC server.
void register_method_handler(std::string_view name, std::function< std::optional< std::string >(const std::string &)> handler)
Register a method handler.
static constexpr const char * RESOLVE_IP_TO_MAC