Commit 73f048fe authored by Francis Dupont's avatar Francis Dupont
Browse files

[4204fd] Reverted to original token.{h,cc}

parent efb9dab9
......@@ -14,9 +14,6 @@
#include <config.h>
#include <eval/token.h>
#include <dhcp/libdhcp++.h>
#include <dhcp/option.h>
#include <dhcp/option_definition.h>
#include <dhcp/pkt4.h>
#include <dhcp/pkt6.h>
#include <dhcp/dhcp4.h>
......@@ -55,13 +52,6 @@ public:
pkt6_->addOption(option_str6_);
}
/// @brief Destructor.
///
/// Removes any option definitions registered in runtime.
virtual ~TokenTest() {
LibDHCP::clearRuntimeOptionDefs();
}
TokenPtr t_; ///< Just a convenience pointer
ValueStack values_; ///< evaluated values will be stored here
......@@ -72,23 +62,6 @@ public:
OptionPtr option_str4_; ///< A string option for DHCPv4
OptionPtr option_str6_; ///< A string option for DHCPv6
/// @brief Create definitions of DHCPv4 options used by unit tests.
void createOptionDefinitions4() {
OptionDefSpaceContainer defs;
OptionDefinitionPtr opt_def4(new OptionDefinition("name-hundred4",
100, "string"));
defs.addItem(opt_def4, "dhcp4");
LibDHCP::setRuntimeOptionDefs(defs);
}
/// @brief Create definitions of DHCPv6 options used by unit tests.
void createOptionDefinitions6() {
OptionDefSpaceContainer defs;
OptionDefinitionPtr opt_def6(new OptionDefinition("name-hundred6",
100, "string"));
defs.addItem(opt_def6, "dhcp6");
LibDHCP::setRuntimeOptionDefs(defs);
}
/// @brief Verify that the substring eval works properly
///
......@@ -301,28 +274,6 @@ TEST_F(TokenTest, optionString4) {
EXPECT_EQ("hundred4", values_.top());
}
// This test checks if a token representing an option identified by name is
// able to extract this option from an IPv4 packet and properly store the
// option's value.
TEST_F(TokenTest, optionWithNameString4) {
// Create definition of option 100 to provide a mapping between option
// code and option name.
ASSERT_NO_THROW(createOptionDefinitions4());
// Create token for option referenced by name. The constructor should
// map the option name to its code.
TokenPtr token;
ASSERT_NO_THROW(token.reset(new TokenOption("name-hundred4", Option::V4,
TokenOption::TEXTUAL)));
// Evaluate option in the packet.
ASSERT_NO_THROW(token->evaluate(*pkt4_, values_));
ASSERT_EQ(1, values_.size());
// Then the content of the option.
EXPECT_EQ("hundred4", values_.top());
}
// This test checks if a token representing option value is able to extract
// the option from an IPv4 packet and properly store its value in a
// hexadecimal format.
......@@ -352,28 +303,6 @@ TEST_F(TokenTest, optionHexString4) {
EXPECT_EQ("hundred4", values_.top());
}
// This test checks if a token representing an option identified by name is
// able to extract this option from an IPv4 packet and properly store its
// value in the hexadecimal format.
TEST_F(TokenTest, optionWithNameHexString4) {
// Create definition of option 100 to provide a mapping between option
// code and option name.
ASSERT_NO_THROW(createOptionDefinitions4());
// Create token for option referenced by name. The constructor should
// map the option name to its code.
TokenPtr token;
ASSERT_NO_THROW(token.reset(new TokenOption("name-hundred4", Option::V4,
TokenOption::HEXADECIMAL)));
// Evaluate option in the packet.
ASSERT_NO_THROW(token->evaluate(*pkt4_, values_));
ASSERT_EQ(1, values_.size());
// Then the content of the option.
EXPECT_EQ("hundred4", values_.top());
}
// This test checks if a token representing an option value is able to extract
// the option from an IPv6 packet and properly store the option's value.
TEST_F(TokenTest, optionString6) {
......@@ -402,29 +331,6 @@ TEST_F(TokenTest, optionString6) {
EXPECT_EQ("hundred6", values_.top());
}
// This test checks if a token representing an option identified by name is
// able to extract this option from an IPv6 packet and properly store the
// option's value.
TEST_F(TokenTest, optionWithNameString6) {
// Create definition of option 100 to provide a mapping between option
// code and option name.
ASSERT_NO_THROW(createOptionDefinitions6());
// Create token for option referenced by name. The constructor should
// map the option name to its code.
TokenPtr token;
ASSERT_NO_THROW(token.reset(new TokenOption("name-hundred6", Option::V6,
TokenOption::TEXTUAL)));
// Evaluate option in the packet.
ASSERT_NO_THROW(token->evaluate(*pkt6_, values_));
ASSERT_EQ(1, values_.size());
// Then the content of the option.
EXPECT_EQ("hundred6", values_.top());
}
// This test checks if a token representing an option value is able to extract
// the option from an IPv6 packet and properly store its value in hexadecimal
// format.
......@@ -454,28 +360,6 @@ TEST_F(TokenTest, optionHexString6) {
EXPECT_EQ("hundred6", values_.top());
}
// This test checks if a token representing an option identified by name is
// able to extract this option from an IPv6 packet and properly store its
// value in the hexadecimal format.
TEST_F(TokenTest, optionWithNameHexString6) {
// Create definition of option 100 to provide a mapping between option
// code and option name.
ASSERT_NO_THROW(createOptionDefinitions6());
// Create token for option referenced by name. The constructor should
// map the option name to its code.
TokenPtr token;
ASSERT_NO_THROW(token.reset(new TokenOption("name-hundred6", Option::V6,
TokenOption::HEXADECIMAL)));
// Evaluate option in the packet.
ASSERT_NO_THROW(token->evaluate(*pkt6_, values_));
ASSERT_EQ(1, values_.size());
// Then the content of the option.
EXPECT_EQ("hundred6", values_.top());
}
// This test checks if a token representing an == operator is able to
// compare two values (with incorrectly built stack).
TEST_F(TokenTest, optionEqualInvalid) {
......
......@@ -14,8 +14,6 @@
#include <eval/token.h>
#include <eval/eval_log.h>
#include <dhcp/option_definition.h>
#include <dhcp/libdhcp++.h>
#include <util/encode/hex.h>
#include <boost/lexical_cast.hpp>
#include <cstring>
......@@ -64,26 +62,6 @@ TokenHexString::evaluate(const Pkt& /*pkt*/, ValueStack& values) {
values.push(value_);
}
TokenOption::TokenOption(const std::string& option_name,
const Option::Universe& option_universe,
const RepresentationType& rep_type)
: option_code_(0), representation_type_(rep_type) {
OptionDefinitionPtr option_def = LibDHCP::getOptionDef(option_universe,
option_name);
if (!option_def) {
const std::string global_space =
(option_universe == Option::V4) ? "dhcp4" : "dhcp6";
option_def = LibDHCP::getRuntimeOptionDef(global_space, option_name);
}
if (!option_def) {
isc_throw(BadValue, "option '" << option_name << "' is not defined");
}
option_code_ = option_def->getCode();
}
void
TokenOption::evaluate(const Pkt& pkt, ValueStack& values) {
OptionPtr opt = pkt.getOption(option_code_);
......
......@@ -16,10 +16,8 @@
#define TOKEN_H
#include <exceptions/exceptions.h>
#include <dhcp/option.h>
#include <dhcp/pkt.h>
#include <stack>
#include <string>
namespace isc {
namespace dhcp {
......@@ -163,25 +161,16 @@ public:
};
/// @brief Constructor that takes an option code as a parameter
/// @param option_code code of the option
///
/// @param option_code Code of the option to be represented.
/// Note: There is no constructor that takes option_name, as it would
/// introduce complex dependency of the libkea-eval on libdhcpsrv.
///
/// @param option_code code of the option to be represented.
/// @param rep_type Token representation type.
TokenOption(const uint16_t option_code, const RepresentationType& rep_type)
: option_code_(option_code), representation_type_(rep_type) {}
/// @brief Constructor that takes option name as a parameter.
///
/// This constructor will throw exception if there is no definition using
/// specified option name in libdhcp++.
///
/// @param option_name Name of the option to be represented.
/// @param option_universe Option universe: DHCPv4 or DHCPv6.
/// @param rep_type Token representation type.
/// @throw BadValue when the option_name cannot be resolved
TokenOption(const std::string& option_name,
const Option::Universe& option_universe,
const RepresentationType& rep_type);
/// @brief Evaluates the values of the option
///
/// This token represents a value of the option, so this method attempts
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment