Commit c71f3d38 authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[5535] kea-dhcp4 parsing now supports relay "ip-addresses"

src/bin/dhcp4/dhcp4_lexer.ll
src/bin/dhcp4/dhcp4_parser.yy
    Modified to support "ip-address" and
    "ip-addresses" under "relay"

src/bin/dhcp4/tests/get_config_unittest.cc
    Updated per process.

src/bin/dhcp4/tests/config_parser_unittest.cc
    void checkResult() - modified to output parsing error text

    TEST_F(Dhcp4ParserTest, subnetRelayInfo)
    TEST_F(Dhcp4ParserTest, classifySubnets)
    - updated to use new Network methods

    TEST_F(Dhcp4ParserTest, subnetRelayInfoList) - new test
    to verify a list of addresses in relay
parent 0e5e017d
This diff is collapsed.
......@@ -1052,6 +1052,15 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
}
}
\"ip-addresses\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::RELAY:
return isc::dhcp::Dhcp4Parser::make_IP_ADDRESSES(driver.loc_);
default:
return isc::dhcp::Dhcp4Parser::make_STRING("ip-addresses", driver.loc_);
}
}
\"hooks-libraries\" {
switch(driver.ctx_) {
case isc::dhcp::Parser4Context::DHCP4:
......
This diff is collapsed.
This diff is collapsed.
......@@ -145,6 +145,7 @@ using namespace std;
RELAY "relay"
IP_ADDRESS "ip-address"
IP_ADDRESSES "ip-addresses"
HOOKS_LIBRARIES "hooks-libraries"
LIBRARY "library"
......@@ -1586,6 +1587,16 @@ ip_address: IP_ADDRESS {
ctx.leave();
};
ip_addresses: IP_ADDRESSES {
ElementPtr l(new ListElement(ctx.loc2pos(@1)));
ctx.stack_.back()->set("ip-addresses", l);
ctx.stack_.push_back(l);
ctx.enter(ctx.NO_KEYWORD);
} COLON list_strings {
ctx.stack_.pop_back();
ctx.leave();
};
duid: DUID {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
......@@ -1657,13 +1668,9 @@ relay: RELAY {
ctx.leave();
};
relay_map: IP_ADDRESS {
ctx.enter(ctx.NO_KEYWORD);
} COLON STRING {
ElementPtr ip(new StringElement($4, ctx.loc2pos(@4)));
ctx.stack_.back()->set("ip-address", ip);
ctx.leave();
};
relay_map: ip_address
| ip_addresses
;
// --- end of relay definitions ------------------------------
......
// Generated 201804111443
// A Bison parser, made by GNU Bison 3.0.4.
// Locations for Bison parsers in C++
......
// Generated 201804111443
// A Bison parser, made by GNU Bison 3.0.4.
// Positions for Bison parsers in C++
......
// Generated 201804111443
// A Bison parser, made by GNU Bison 3.0.4.
// Stack handling for Bison parsers in C++
......
......@@ -260,7 +260,7 @@ public:
void checkResult(ConstElementPtr status, int expected_code) {
ASSERT_TRUE(status);
comment_ = parseAnswer(rcode_, status);
EXPECT_EQ(expected_code, rcode_);
EXPECT_EQ(expected_code, rcode_) << "error text:" << comment_->stringValue();
}
/// @brief Convenience method for running configuration
......@@ -1377,7 +1377,7 @@ TEST_F(Dhcp4ParserTest, nextServerOverride) {
"\"renew-timer\": 1000, "
"\"next-server\": \"192.0.0.1\", "
"\"server-hostname\": \"nohost\","
"\"boot-file-name\": \"nofile\","
"\"boot-file-name\": \"nofile\","
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
" \"next-server\": \"1.2.3.4\", "
......@@ -4089,9 +4089,50 @@ TEST_F(Dhcp4ParserTest, subnetRelayInfo) {
Subnet4Ptr subnet = CfgMgr::instance().getStagingCfg()->
getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"));
ASSERT_TRUE(subnet);
EXPECT_EQ("192.0.2.123", subnet->getRelayInfo().addr_.toText());
EXPECT_TRUE(subnet->hasRelays());
EXPECT_TRUE(subnet->hasRelayAddress(IOAddress("192.0.2.123")));
}
// This test checks if it is possible to specify a list of relays
TEST_F(Dhcp4ParserTest, subnetRelayInfoList) {
ConstElementPtr status;
// A config with relay information.
string config = "{ " + genIfaceConfig() + "," +
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
"\"subnet4\": [ { "
" \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
" \"renew-timer\": 1, "
" \"rebind-timer\": 2, "
" \"valid-lifetime\": 4,"
" \"relay\": { "
" \"ip-addresses\": [ \"192.0.2.123\", \"192.0.2.124\" ]"
" },"
" \"subnet\": \"192.0.2.0/24\" } ],"
"\"valid-lifetime\": 4000 }";
ConstElementPtr json;
ASSERT_NO_THROW(json = parseDHCP4(config));
extractConfig(config);
EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, json));
// returned value should be 0 (configuration success)
checkResult(status, 0);
Subnet4Ptr subnet = CfgMgr::instance().getStagingCfg()->
getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"));
ASSERT_TRUE(subnet);
EXPECT_TRUE(subnet->hasRelays());
EXPECT_TRUE(subnet->hasRelayAddress(IOAddress("192.0.2.123")));
EXPECT_TRUE(subnet->hasRelayAddress(IOAddress("192.0.2.124")));
}
// Goal of this test is to verify that multiple subnets can be configured
// with defined client classes.
TEST_F(Dhcp4ParserTest, classifySubnets) {
......@@ -5652,7 +5693,7 @@ TEST_F(Dhcp4ParserTest, sharedNetworksDerive) {
EXPECT_EQ(IOAddress("1.2.3.4"), s->getSiaddr());
EXPECT_EQ("foo", s->getSname());
EXPECT_EQ("bar", s->getFilename());
EXPECT_EQ(IOAddress("5.6.7.8"), s->getRelayInfo().addr_);
EXPECT_TRUE(s->hasRelayAddress(IOAddress("5.6.7.8")));
EXPECT_EQ(Network::HR_OUT_OF_POOL, s->getHostReservationMode());
// For the second subnet, the renew-timer should be 100, because it
......@@ -5667,7 +5708,7 @@ TEST_F(Dhcp4ParserTest, sharedNetworksDerive) {
EXPECT_EQ(IOAddress("11.22.33.44"), s->getSiaddr());
EXPECT_EQ("some-name.example.org", s->getSname());
EXPECT_EQ("bootfile.efi", s->getFilename());
EXPECT_EQ(IOAddress("55.66.77.88"), s->getRelayInfo().addr_);
EXPECT_TRUE(s->hasRelayAddress(IOAddress("55.66.77.88")));
EXPECT_EQ(Network::HR_DISABLED, s->getHostReservationMode());
// Ok, now check the second shared subnet.
......@@ -5686,7 +5727,7 @@ TEST_F(Dhcp4ParserTest, sharedNetworksDerive) {
EXPECT_EQ(IOAddress("0.0.0.0"), s->getSiaddr());
EXPECT_TRUE(s->getSname().empty());
EXPECT_TRUE(s->getFilename().empty());
EXPECT_EQ(IOAddress("0.0.0.0"), s->getRelayInfo().addr_);
EXPECT_FALSE(s->hasRelays());
EXPECT_EQ(Network::HR_ALL, s->getHostReservationMode());
}
......
This diff is collapsed.
// Generated 201804111443
// A Bison parser, made by GNU Bison 3.0.4.
// Locations for Bison parsers in C++
......
// Generated 201804111443
// A Bison parser, made by GNU Bison 3.0.4.
// Positions for Bison parsers in C++
......
// Generated 201804111443
// A Bison parser, made by GNU Bison 3.0.4.
// Stack handling for Bison parsers in C++
......
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