diff --git a/src/bin/lfc/kea-lfc.xml b/src/bin/lfc/kea-lfc.xml
index 97c67fcd67..5473c3cec5 100644
--- a/src/bin/lfc/kea-lfc.xml
+++ b/src/bin/lfc/kea-lfc.xml
@@ -44,18 +44,18 @@
kea-lfc
+
+
+
+
+
+
+
+
-
-
- kea-lfc
-
-
-
-
-
DESCRIPTION
@@ -76,13 +76,34 @@
-
+
Verbose mode sets the logging level to debug. This is primarily
for development purposes in stand-alone mode.
+
+
+
+ version causes the version stamp to be printed.
+
+
+
+
+
+
+ Version causes a longer form of the version stamp to be printed.
+
+
+
+
+
+
+ The protocol version of the lease files, must be one of 4 or 6.
+
+
+
@@ -91,6 +112,47 @@
+
+
+
+ Previous lease file - When LFC starts this is the result of any previous
+ run of LFC.
+
+
+
+
+
+
+ Input or copy of lease file - Before the DHCP serves invokes LFC it will move
+ the current lease file to this file and then call LFC with the new file.
+
+
+
+
+
+
+ Output lease file - The temporary file LFC should use to write the leases.
+ Upon completion this file will be moved to the finish file (see below).
+
+
+
+
+
+
+ Finish or completion file - Another temporary file LFC uses for bookkeeping.
+ When LFC completes writing the output file it moves it to this file name.
+ After LFC finishes deleting the other files (previous and input) it moves
+ this file to previous lease file.
+
+
+
+
+
+
+
+
+
+
diff --git a/src/bin/lfc/lfc.cc b/src/bin/lfc/lfc.cc
index cb031e2154..f8e3b450e4 100644
--- a/src/bin/lfc/lfc.cc
+++ b/src/bin/lfc/lfc.cc
@@ -12,11 +12,11 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-#include
#include
#include
#include
#include
+#include
#include
using namespace std;
@@ -33,12 +33,10 @@ const char* lfcController::lfc_bin_name_ = "kea-lfc";
lfcController::lfcController()
: protocol_version_(0), verbose_(false), config_file_(""), previous_file_(""),
- copy_file_(""), output_file_(""), finish_file_(""), pid_file_("./test_pid") {
- std::cerr << "created lfc" << std::endl;
+ copy_file_(""), output_file_(""), finish_file_(""), pid_file_("") {
}
lfcController::~lfcController() {
- std::cerr << "destroyed lfc" << std::endl;
}
void
@@ -49,85 +47,82 @@ lfcController::launch(int argc, char* argv[], const bool test_mode) {
usage(ex.what());
throw; // rethrow it
}
-
- std::cerr << "launched lfc" << std::endl;
}
void
-lfcController::parseArgs(int argc, char* argv[])
-{
+lfcController::parseArgs(int argc, char* argv[]) {
int ch;
while ((ch = getopt(argc, argv, "46dvVp:i:o:c:f:")) != -1) {
switch (ch) {
- case '4':
+ case '4':
// Process DHCPv4 lease files.
protocol_version_ = 4;
break;
- case '6':
+ case '6':
// Process DHCPv6 lease files.
protocol_version_ = 6;
break;
- case 'v':
+ case 'v':
// Print just Kea vesion and exit.
- std::cout << getVersion(false) << std::endl;
+ std::cout << getVersion(false) << std::endl;
exit(EXIT_SUCCESS);
- case 'V':
+ case 'V':
// Print extended Kea vesion and exit.
- std::cout << getVersion(true) << std::endl;
+ std::cout << getVersion(true) << std::endl;
exit(EXIT_SUCCESS);
- case 'd':
- // Verbose output.
- verbose_ = true;
- break;
+ case 'd':
+ // Verbose output.
+ verbose_ = true;
+ break;
- case 'p':
- // Previous file name.
- if (optarg == NULL) {
- isc_throw(InvalidUsage, "Previous file name missing");
- }
- previous_file_ = optarg;
- break;
-
- case 'i':
- // Copy file name.
- if (optarg == NULL) {
- isc_throw(InvalidUsage, "Copy file name missing");
- }
- copy_file_ = optarg;
- break;
+ case 'p':
+ // Previous file name.
+ if (optarg == NULL) {
+ isc_throw(InvalidUsage, "Previous file name missing");
+ }
+ previous_file_ = optarg;
+ break;
- case 'o':
- // Output file name.
- if (optarg == NULL) {
- isc_throw(InvalidUsage, "Output file name missing");
- }
- output_file_ = optarg;
- break;
+ case 'i':
+ // Copy file name.
+ if (optarg == NULL) {
+ isc_throw(InvalidUsage, "Copy file name missing");
+ }
+ copy_file_ = optarg;
+ break;
- case 'f':
- // Output file name.
- if (optarg == NULL) {
- isc_throw(InvalidUsage, "Finish file name missing");
- }
- finish_file_ = optarg;
- break;
+ case 'o':
+ // Output file name.
+ if (optarg == NULL) {
+ isc_throw(InvalidUsage, "Output file name missing");
+ }
+ output_file_ = optarg;
+ break;
- case 'c':
- // Previous file name.
- if (optarg == NULL) {
- isc_throw(InvalidUsage, "Configuration file name missing");
- }
- config_file_ = optarg;
- break;
+ case 'f':
+ // Output file name.
+ if (optarg == NULL) {
+ isc_throw(InvalidUsage, "Finish file name missing");
+ }
+ finish_file_ = optarg;
+ break;
- default:
- usage("");
- }
+ case 'c':
+ // Previous file name.
+ if (optarg == NULL) {
+ isc_throw(InvalidUsage, "Configuration file name missing");
+ }
+ config_file_ = optarg;
+ break;
+
+ default:
+ usage("");
+ }
}
// Check for extraneous parameters.
@@ -140,57 +135,39 @@ lfcController::parseArgs(int argc, char* argv[])
}
if (previous_file_.empty()) {
- isc_throw(InvalidUsage, "Previous file not specified");
+ isc_throw(InvalidUsage, "Previous file not specified");
}
if (copy_file_.empty()) {
- isc_throw(InvalidUsage, "Copy file not specified");
+ isc_throw(InvalidUsage, "Copy file not specified");
}
if (output_file_.empty()) {
- isc_throw(InvalidUsage, "Output file not specified");
+ isc_throw(InvalidUsage, "Output file not specified");
}
if (finish_file_.empty()) {
- isc_throw(InvalidUsage, "Finish file not specified");
+ isc_throw(InvalidUsage, "Finish file not specified");
}
if (config_file_.empty()) {
- isc_throw(InvalidUsage, "Config file not specified");
+ isc_throw(InvalidUsage, "Config file not specified");
}
// If verbose is set echo the input information
if (verbose_ == true) {
std::cerr << "Protocol version: " << protocol_version_ << std::endl
- << "Previous lease file: " << previous_file_ << std::endl
- << "Copy lease file: " << copy_file_ << std::endl
- << "Output lease file: " << output_file_ << std::endl
- << "Finishn file: " << finish_file_ << std::endl
- << "Config file: " << config_file_ << std::endl
- << "PID file: " << pid_file_ << std::endl;
+ << "Previous lease file: " << previous_file_ << std::endl
+ << "Copy lease file: " << copy_file_ << std::endl
+ << "Output lease file: " << output_file_ << std::endl
+ << "Finishn file: " << finish_file_ << std::endl
+ << "Config file: " << config_file_ << std::endl
+ << "PID file: " << pid_file_ << std::endl;
}
}
-bool
-lfcController::pidCheck(const std::string & pid_file)
-{
- return (false);
-}
-
-bool
-lfcController::pidWrite(const std::string & pid_file)
-{
- return (true);
-}
-
void
-lfcController::pidDelete(const std::string & pid_file)
-{
-}
-
-void
-lfcController::usage(const std::string & text)
-{
+lfcController::usage(const std::string& text) {
if (text != "") {
std::cerr << "Usage error: " << text << std::endl;
}
diff --git a/src/bin/lfc/lfc.h b/src/bin/lfc/lfc.h
index 4c0deb4623..ec79f7a187 100644
--- a/src/bin/lfc/lfc.h
+++ b/src/bin/lfc/lfc.h
@@ -16,7 +16,6 @@
#define LFC_H
#include
-
#include
namespace isc {
@@ -53,9 +52,9 @@ public:
///
/// 1. parse command line arguments
/// 2. verifies that it is the only instance
- /// 3. creates pid file
+ /// 3. creates pid file (TBD)
/// .... TBD
- /// 4. remove pid file
+ /// 4. remove pid file (TBD)
/// 5. exit to the caller
void launch(int argc, char* argv[], const bool test_mode);
@@ -63,21 +62,6 @@ public:
/// step taken after the process has been launched.
void parseArgs(int argc, char* argv[]);
- /// @brief Use the pid file to determine if there is another instance
- ///
- /// @param pid_file is the name of the file which holds the pid to check
- /// returns true if there is a process with that pid
- bool pidCheck(const std::string & pid_file);
-
- /// @brief Extract the pid and Write it out to the pid file
- ///
- /// @param pid_file is the name of the file in which to write the pid
- /// returns true if the write was successful
- bool pidWrite(const std::string & pid_file);
-
- /// @brief Get rid of the pid file we created earlier
- void pidDelete(const std::string & pid_file);
-
/// @brief Prints the program usage text to std error.
///
/// @param text is a string message which will preceded the usage text.
@@ -157,4 +141,3 @@ private:
}; // namespace isc
#endif
-
diff --git a/src/bin/lfc/main.cc b/src/bin/lfc/main.cc
index 7328f945e7..4cc2964bea 100644
--- a/src/bin/lfc/main.cc
+++ b/src/bin/lfc/main.cc
@@ -12,12 +12,11 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-#include
#include
#include
#include
#include
-
+#include
#include
using namespace isc::lfc;
diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc
index 3069a2ac52..76753dbb9c 100644
--- a/src/bin/lfc/tests/lfc_controller_unittests.cc
+++ b/src/bin/lfc/tests/lfc_controller_unittests.cc
@@ -12,9 +12,9 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
+#include
#include
#include
-#include
using namespace isc::lfc;
using namespace std;
@@ -23,14 +23,13 @@ TEST(lfcControllerTest, initialValues) {
lfcController lfcController;
// Verify that we start with everything empty
- EXPECT_TRUE(lfcController.getProtocolVersion() == 0);
- EXPECT_TRUE(lfcController.getConfigFile() == "");
- EXPECT_TRUE(lfcController.getPreviousFile() == "");
- EXPECT_TRUE(lfcController.getCopyFile() == "");
- EXPECT_TRUE(lfcController.getOutputFile() == "");
- EXPECT_TRUE(lfcController.getFinishFile() == "");
- // Currently defaulting pid file for testing
- // EXPECT_TRUE(lfcController.getPidFile() == "");
+ EXPECT_EQ(lfcController.getProtocolVersion(), 0);
+ EXPECT_EQ(lfcController.getConfigFile(), "");
+ EXPECT_EQ(lfcController.getPreviousFile(), "");
+ EXPECT_EQ(lfcController.getCopyFile(), "");
+ EXPECT_EQ(lfcController.getOutputFile(), "");
+ EXPECT_EQ(lfcController.getFinishFile(), "");
+ EXPECT_EQ(lfcController.getPidFile(), "");
}
TEST(lfcControllerTest, fullCommandLine) {
@@ -38,28 +37,28 @@ TEST(lfcControllerTest, fullCommandLine) {
// Verify that standard options can be parsed without error
char* argv[] = { const_cast("progName"),
- const_cast("-4"),
- const_cast("-p"),
- const_cast("previous"),
- const_cast("-i"),
- const_cast("copy"),
- const_cast("-o"),
- const_cast("output"),
- const_cast("-c"),
- const_cast("config"),
- const_cast("-f"),
- const_cast("finish") };
+ const_cast("-4"),
+ const_cast("-p"),
+ const_cast("previous"),
+ const_cast("-i"),
+ const_cast("copy"),
+ const_cast("-o"),
+ const_cast("output"),
+ const_cast("-c"),
+ const_cast("config"),
+ const_cast("-f"),
+ const_cast("finish") };
int argc = 12;
EXPECT_NO_THROW(lfcController.parseArgs(argc, argv));
// The parsed data
- EXPECT_TRUE(lfcController.getProtocolVersion() == 4);
- EXPECT_TRUE(lfcController.getConfigFile() == "config");
- EXPECT_TRUE(lfcController.getPreviousFile() == "previous");
- EXPECT_TRUE(lfcController.getCopyFile() == "copy");
- EXPECT_TRUE(lfcController.getOutputFile() == "output");
- EXPECT_TRUE(lfcController.getFinishFile() == "finish");
+ EXPECT_EQ(lfcController.getProtocolVersion(), 4);
+ EXPECT_EQ(lfcController.getConfigFile(), "config");
+ EXPECT_EQ(lfcController.getPreviousFile(), "previous");
+ EXPECT_EQ(lfcController.getCopyFile(), "copy");
+ EXPECT_EQ(lfcController.getOutputFile(), "output");
+ EXPECT_EQ(lfcController.getFinishFile(), "finish");
}
TEST(lfcControllerTest, notEnoughData) {
@@ -68,17 +67,17 @@ TEST(lfcControllerTest, notEnoughData) {
// The standard options we shall test what happens
// if we don't include all of them
char* argv[] = { const_cast("progName"),
- const_cast("-4"),
- const_cast("-p"),
- const_cast("previous"),
- const_cast("-i"),
- const_cast("copy"),
- const_cast("-o"),
- const_cast("output"),
- const_cast("-c"),
- const_cast("config"),
- const_cast("-f"),
- const_cast("finish") };
+ const_cast("-4"),
+ const_cast("-p"),
+ const_cast("previous"),
+ const_cast("-i"),
+ const_cast("copy"),
+ const_cast("-o"),
+ const_cast("output"),
+ const_cast("-c"),
+ const_cast("config"),
+ const_cast("-f"),
+ const_cast("finish") };
int argc = 1;
EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage);
@@ -121,20 +120,20 @@ TEST(lfcControllerTest, tooMuchData) {
// The standard options plus some others
char* argv[] = { const_cast("progName"),
- const_cast("-4"),
- const_cast("-p"),
- const_cast("previous"),
- const_cast("-i"),
- const_cast("copy"),
- const_cast("-o"),
- const_cast("output"),
- const_cast("-c"),
- const_cast("config"),
- const_cast("-f"),
- const_cast("finish"),
- const_cast("some"),
- const_cast("other"),
- const_cast("args"),
+ const_cast("-4"),
+ const_cast("-p"),
+ const_cast("previous"),
+ const_cast("-i"),
+ const_cast("copy"),
+ const_cast("-o"),
+ const_cast("output"),
+ const_cast("-c"),
+ const_cast("config"),
+ const_cast("-f"),
+ const_cast("finish"),
+ const_cast("some"),
+ const_cast("other"),
+ const_cast("args"),
};
int argc = 15;
@@ -147,12 +146,11 @@ TEST(lfcControllerTest, someBadData) {
// The standard options plus some others
char* argv[] = { const_cast("progName"),
- const_cast("some"),
- const_cast("bad"),
- const_cast("args"),
+ const_cast("some"),
+ const_cast("bad"),
+ const_cast("args"),
};
int argc = 4;
EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage);
}
-//-4 -p previous -i copy -o output -c config -f finish -d