From: Tomek Mrugalski Date: Fri, 24 Feb 2012 18:05:10 +0000 (+0100) Subject: [1651] dhcp4 module now connects to msgq. X-Git-Tag: trac2351_base~241 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=66e868079f7a572809e5030d64de9caa4c550f73;p=thirdparty%2Fkea.git [1651] dhcp4 module now connects to msgq. --- diff --git a/src/bin/dhcp4/Makefile.am b/src/bin/dhcp4/Makefile.am index 513ae1cca2..4390d4c727 100644 --- a/src/bin/dhcp4/Makefile.am +++ b/src/bin/dhcp4/Makefile.am @@ -36,6 +36,9 @@ b10_dhcp4_LDADD = $(top_builddir)/src/lib/dhcp/libdhcp++.la b10_dhcp4_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la b10_dhcp4_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la b10_dhcp4_LDADD += $(top_builddir)/src/lib/log/liblog.la +b10_dhcp4_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la +b10_dhcp4_LDADD += $(top_builddir)/src/lib/cc/libcc.la + # TODO: config.h.in is wrong because doesn't honor pkgdatadir # and can't use @datadir@ because doesn't expand default ${prefix} diff --git a/src/bin/dhcp4/main.cc b/src/bin/dhcp4/main.cc index ee402955ad..bea06ae10f 100644 --- a/src/bin/dhcp4/main.cc +++ b/src/bin/dhcp4/main.cc @@ -25,12 +25,12 @@ #include #include +#include +#include + #include -#if 0 -// TODO cc is not used yet. It should be eventually #include #include -#endif #include #include @@ -38,11 +38,19 @@ #include #include +#include +#include + +const char* const DHCP4_NAME = "b10-dhcp4"; + using namespace std; using namespace isc::util; - -using namespace isc; using namespace isc::dhcp; +using namespace isc::util; +using namespace isc::data; +using namespace isc::cc; +using namespace isc::config; +using namespace isc::asiolink; namespace { @@ -57,6 +65,50 @@ usage() { } } // end of anonymous namespace +ConstElementPtr +dhcp4_config_handler(ConstElementPtr new_config) { + cout << "#### dhcp4: Received new config:" << new_config->str() << endl; + ConstElementPtr answer = isc::config::createAnswer(0, + "All good here. Thanks for sending config."); + return (answer); +} + +ConstElementPtr +dhcp4_command_handler(const string& command, ConstElementPtr args) { + cout << "#### dhcp4: Received new command: [" << command << "], args=" + << args->str() << endl; + ConstElementPtr answer = isc::config::createAnswer(0, + "All good here. Thanks for asking."); + return (answer); +} + + +void establish_session() { + + Session* cc_session = NULL; + ModuleCCSession* config_session = NULL; + + string specfile; + if (getenv("B10_FROM_BUILD")) { + specfile = string(getenv("B10_FROM_BUILD")) + + "/src/bin/auth/dhcp4.spec"; + } else { + specfile = string(DHCP4_SPECFILE_LOCATION); + } + + cout << "#### specfile=" << specfile << endl; + + IOService io_service; + + cc_session = new Session(io_service.get_io_service()); + + config_session = new ModuleCCSession(specfile, *cc_session, + dhcp4_config_handler, + dhcp4_command_handler, false); + + cout << "#### hasQueuedMsgs()=" << config_session->hasQueuedMsgs() << endl; +} + int main(int argc, char* argv[]) { int ch; @@ -73,6 +125,12 @@ main(int argc, char* argv[]) { } } + // Initialize logging. If verbose, we'll use maximum verbosity. + isc::log::initLogger(DHCP4_NAME, + (verbose_mode ? isc::log::DEBUG : isc::log::INFO), + isc::log::MAX_DEBUG_LEVEL, NULL); + + cout << "My pid=" << getpid() << endl; if (argc - optind > 0) { @@ -81,21 +139,9 @@ main(int argc, char* argv[]) { int ret = 0; - // TODO remainder of auth to dhcp4 code copy. We need to enable this in - // dhcp4 eventually -#if 0 - Session* cc_session = NULL; - Session* statistics_session = NULL; - ModuleCCSession* config_session = NULL; -#endif try { - string specfile; - if (getenv("B10_FROM_BUILD")) { - specfile = string(getenv("B10_FROM_BUILD")) + - "/src/bin/auth/dhcp4.spec"; - } else { - specfile = string(DHCP4_SPECFILE_LOCATION); - } + + establish_session(); cout << "[b10-dhcp4] Initiating DHCPv4 server operation." << endl;