From: Thomas Markwalder Date: Thu, 8 May 2014 10:42:09 +0000 (-0400) Subject: [3268] Modify D2Process to use D2Params X-Git-Tag: trac3434_base~26^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eecc258336e4c196475fd81eb874e81e41bd3f13;p=thirdparty%2Fkea.git [3268] Modify D2Process to use D2Params Changed D2Process to get queue manager configuration values from D2Params. This makes NCR protocol and format configurable. --- diff --git a/src/bin/d2/d2_process.cc b/src/bin/d2/d2_process.cc index cca71e21d3..e9ce245616 100644 --- a/src/bin/d2/d2_process.cc +++ b/src/bin/d2/d2_process.cc @@ -207,7 +207,7 @@ D2Process::configure(isc::data::ConstElementPtr config_set) { if (rcode) { // Non-zero means we got an invalid configuration, take no further - // action. In integrated mode, this will send a failed response back + // action. In integrated mode, this will send a failed response back // to BIND10. reconf_queue_flag_ = false; return (answer); @@ -248,7 +248,7 @@ D2Process::checkQueueStatus() { queue_mgr_->stopListening(); } catch (const isc::Exception& ex) { // It is very unlikey that we would experience an error - // here, but theoretically possible. + // here, but theoretically possible. LOG_ERROR(dctl_logger, DHCP_DDNS_QUEUE_MGR_STOP_ERROR) .arg(ex.what()); } @@ -325,37 +325,42 @@ D2Process::reconfigureQueueMgr() { queue_mgr_->removeListener(); // Get the configuration parameters that affect Queue Manager. - // @todo Need to add parameters for listener TYPE, FORMAT, address reuse - std::string ip_address; - uint32_t port; - getCfgMgr()->getContext()->getParam("ip_address", ip_address); + const D2ParamsPtr& d2_params = getD2CfgMgr()->getD2Params(); // Warn the user if the server address is not the loopback. /// @todo Remove this once we provide a secure mechanism. + std::string ip_address = d2_params->getIpAddress().toText(); if (ip_address != "127.0.0.1" && ip_address != "::1") { LOG_WARN(dctl_logger, DHCP_DDNS_NOT_ON_LOOPBACK).arg(ip_address); } - getCfgMgr()->getContext()->getParam("port", port); - isc::asiolink::IOAddress addr(ip_address); - // Instantiate the listener. - queue_mgr_->initUDPListener(addr, port, dhcp_ddns::FMT_JSON, true); + if (d2_params->getNcrProtocol() == dhcp_ddns::NCR_UDP) { + queue_mgr_->initUDPListener(d2_params->getIpAddress(), + d2_params->getPort(), + d2_params->getNcrFormat(), true); + } else { + /// @todo Add TCP/IP once it's supported + // We should never get this far but if we do deal with it. + isc_throw(DProcessBaseError, "Unsupported NCR listener protocol:" + << dhcp_ddns::ncrProtocolToString(d2_params-> + getNcrProtocol())); + } // Now start it. This assumes that starting is a synchronous, // blocking call that executes quickly. @todo Should that change then // we will have to expand the state model to accommodate this. queue_mgr_->startListening(); } catch (const isc::Exception& ex) { - // Queue manager failed to initialize and therefore not listening. - // This is most likely due to an unavailable IP address or port, + // Queue manager failed to initialize and therefore not listening. + // This is most likely due to an unavailable IP address or port, // which is a configuration issue. LOG_ERROR(dctl_logger, DHCP_DDNS_QUEUE_MGR_START_ERROR).arg(ex.what()); } } isc::data::ConstElementPtr -D2Process::command(const std::string& command, +D2Process::command(const std::string& command, isc::data::ConstElementPtr args) { // @todo This is the initial implementation. If and when D2 is extended // to support its own commands, this implementation must change. Otherwise diff --git a/src/bin/d2/tests/d2_process_unittests.cc b/src/bin/d2/tests/d2_process_unittests.cc index bd6f77042a..025d501c7e 100644 --- a/src/bin/d2/tests/d2_process_unittests.cc +++ b/src/bin/d2/tests/d2_process_unittests.cc @@ -35,7 +35,6 @@ namespace { /// @brief Valid configuration containing an unavailable IP address. const char* bad_ip_d2_config = "{ " - "\"interface\" : \"eth1\" , " "\"ip_address\" : \"1.1.1.1\" , " "\"port\" : 5031, " "\"tsig_keys\": [" @@ -607,7 +606,6 @@ TEST_F(D2ProcessTest, fatalErrorShutdown) { /// loopback. TEST_F(D2ProcessTest, notLoopbackTest) { const char* config = "{ " - "\"interface\" : \"\" , " "\"ip_address\" : \"0.0.0.0\" , " "\"port\" : 53001, " "\"tsig_keys\": []," @@ -626,7 +624,6 @@ TEST_F(D2ProcessTest, notLoopbackTest) { /// DHCP_DDNS_NOT_ON_LOOPBACK is not issued. TEST_F(D2ProcessTest, v4LoopbackTest) { const char* config = "{ " - "\"interface\" : \"\" , " "\"ip_address\" : \"127.0.0.1\" , " "\"port\" : 53001, " "\"tsig_keys\": []," @@ -640,7 +637,6 @@ TEST_F(D2ProcessTest, v4LoopbackTest) { /// DHCP_DDNS_NOT_ON_LOOPBACK is not issued. TEST_F(D2ProcessTest, v6LoopbackTest) { const char* config = "{ " - "\"interface\" : \"\" , " "\"ip_address\" : \"::1\" , " "\"port\" : 53001, " "\"tsig_keys\": []," diff --git a/src/bin/d2/tests/d2_update_mgr_unittests.cc b/src/bin/d2/tests/d2_update_mgr_unittests.cc index f669aeb970..4b17575b70 100644 --- a/src/bin/d2/tests/d2_update_mgr_unittests.cc +++ b/src/bin/d2/tests/d2_update_mgr_unittests.cc @@ -120,7 +120,6 @@ public: void makeCannedConfig() { std::string canned_config_ = "{ " - "\"interface\" : \"eth1\" , " "\"ip_address\" : \"192.168.1.33\" , " "\"port\" : 88 , " "\"tsig_keys\": [] ,"