<refsynopsisdiv>
<cmdsynopsis>
<command>kea-lfc</command>
+ <arg><option>-4|-6</option></arg>
+ <arg><option>-c <replaceable class="parameter">config-file</replaceable></option></arg>
+ <arg><option>-p <replaceable class="parameter">previous-file</replaceable></option></arg>
+ <arg><option>-i <replaceable class="parameter">copy-file</replaceable></option></arg>
+ <arg><option>-o <replaceable class="parameter">output-file</replaceable></option></arg>
+ <arg><option>-f <replaceable class="parameter">finish-file</replaceable></option></arg>
<arg><option>-v</option></arg>
+ <arg><option>-V</option></arg>
+ <arg><option>-d</option></arg>
</cmdsynopsis>
</refsynopsisdiv>
- <refsynopsisdiv>
- <cmdsynopsis>
- <command>kea-lfc</command>
- <arg><option>-s</option></arg>
- </cmdsynopsis>
- </refsynopsisdiv>
-
-
<refsect1>
<title>DESCRIPTION</title>
<para>
<variablelist>
<varlistentry>
- <term><option>-v</option></term>
+ <term><option>-d</option></term>
<listitem><para>
Verbose mode sets the logging level to debug. This is primarily
for development purposes in stand-alone mode.
</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-v</option></term>
+ <listitem><para>
+ version causes the version stamp to be printed.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-V</option></term>
+ <listitem><para>
+ Version causes a longer form of the version stamp to be printed.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-4 | -6</option></term>
+ <listitem><para>
+ The protocol version of the lease files, must be one of 4 or 6.
+ </para></listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-c</option></term>
<listitem><para>
</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-p</option></term>
+ <listitem><para>
+ Previous lease file - When LFC starts this is the result of any previous
+ run of LFC.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-i</option></term>
+ <listitem><para>
+ 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.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-o</option></term>
+ <listitem><para>
+ 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).
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-f</option></term>
+ <listitem><para>
+ 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.
+ </para></listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term><option>-c</option></term>
+ <listitem><para>
+
+ </para></listitem>
+ </varlistentry>
+
</variablelist>
</refsect1>
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-#include <config.h>
#include <lfc/lfc.h>
#include <exceptions/exceptions.h>
#include <log/logger_support.h>
#include <log/logger_manager.h>
+#include <config.h>
#include <iostream>
using namespace std;
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
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 '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 'o':
- // Output file name.
- if (optarg == NULL) {
- isc_throw(InvalidUsage, "Output file name missing");
- }
- output_file_ = optarg;
- break;
-
- case 'f':
- // Output file name.
- if (optarg == NULL) {
- isc_throw(InvalidUsage, "Finish file name missing");
- }
- finish_file_ = optarg;
- break;
-
- case 'c':
- // Previous file name.
- if (optarg == NULL) {
- isc_throw(InvalidUsage, "Configuration file name missing");
- }
- config_file_ = optarg;
- break;
-
- default:
- usage("");
- }
+ 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 'o':
+ // Output file name.
+ if (optarg == NULL) {
+ isc_throw(InvalidUsage, "Output file name missing");
+ }
+ output_file_ = optarg;
+ break;
+
+ case 'f':
+ // Output file name.
+ if (optarg == NULL) {
+ isc_throw(InvalidUsage, "Finish file name missing");
+ }
+ finish_file_ = optarg;
+ break;
+
+ 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.
}
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;
}
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
+#include <lfc/lfc.h>
#include <log/logger_support.h>
#include <gtest/gtest.h>
-#include <lfc/lfc.h>
using namespace isc::lfc;
using namespace std;
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) {
// Verify that standard options can be parsed without error
char* argv[] = { const_cast<char*>("progName"),
- const_cast<char*>("-4"),
- const_cast<char*>("-p"),
- const_cast<char*>("previous"),
- const_cast<char*>("-i"),
- const_cast<char*>("copy"),
- const_cast<char*>("-o"),
- const_cast<char*>("output"),
- const_cast<char*>("-c"),
- const_cast<char*>("config"),
- const_cast<char*>("-f"),
- const_cast<char*>("finish") };
+ const_cast<char*>("-4"),
+ const_cast<char*>("-p"),
+ const_cast<char*>("previous"),
+ const_cast<char*>("-i"),
+ const_cast<char*>("copy"),
+ const_cast<char*>("-o"),
+ const_cast<char*>("output"),
+ const_cast<char*>("-c"),
+ const_cast<char*>("config"),
+ const_cast<char*>("-f"),
+ const_cast<char*>("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) {
// The standard options we shall test what happens
// if we don't include all of them
char* argv[] = { const_cast<char*>("progName"),
- const_cast<char*>("-4"),
- const_cast<char*>("-p"),
- const_cast<char*>("previous"),
- const_cast<char*>("-i"),
- const_cast<char*>("copy"),
- const_cast<char*>("-o"),
- const_cast<char*>("output"),
- const_cast<char*>("-c"),
- const_cast<char*>("config"),
- const_cast<char*>("-f"),
- const_cast<char*>("finish") };
+ const_cast<char*>("-4"),
+ const_cast<char*>("-p"),
+ const_cast<char*>("previous"),
+ const_cast<char*>("-i"),
+ const_cast<char*>("copy"),
+ const_cast<char*>("-o"),
+ const_cast<char*>("output"),
+ const_cast<char*>("-c"),
+ const_cast<char*>("config"),
+ const_cast<char*>("-f"),
+ const_cast<char*>("finish") };
int argc = 1;
EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage);
// The standard options plus some others
char* argv[] = { const_cast<char*>("progName"),
- const_cast<char*>("-4"),
- const_cast<char*>("-p"),
- const_cast<char*>("previous"),
- const_cast<char*>("-i"),
- const_cast<char*>("copy"),
- const_cast<char*>("-o"),
- const_cast<char*>("output"),
- const_cast<char*>("-c"),
- const_cast<char*>("config"),
- const_cast<char*>("-f"),
- const_cast<char*>("finish"),
- const_cast<char*>("some"),
- const_cast<char*>("other"),
- const_cast<char*>("args"),
+ const_cast<char*>("-4"),
+ const_cast<char*>("-p"),
+ const_cast<char*>("previous"),
+ const_cast<char*>("-i"),
+ const_cast<char*>("copy"),
+ const_cast<char*>("-o"),
+ const_cast<char*>("output"),
+ const_cast<char*>("-c"),
+ const_cast<char*>("config"),
+ const_cast<char*>("-f"),
+ const_cast<char*>("finish"),
+ const_cast<char*>("some"),
+ const_cast<char*>("other"),
+ const_cast<char*>("args"),
};
int argc = 15;
// The standard options plus some others
char* argv[] = { const_cast<char*>("progName"),
- const_cast<char*>("some"),
- const_cast<char*>("bad"),
- const_cast<char*>("args"),
+ const_cast<char*>("some"),
+ const_cast<char*>("bad"),
+ const_cast<char*>("args"),
};
int argc = 4;
EXPECT_THROW(lfcController.parseArgs(argc, argv), InvalidUsage);
}
-//-4 -p previous -i copy -o output -c config -f finish -d