Commit 4119b60c authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[3554] Unit-tests implemented.

parent f643dc9f
......@@ -3627,4 +3627,29 @@ TEST_F(Dhcp6ParserTest, reservationBogus) {
}
/// The goal of this test is to verify that configuration can include
/// MAC/Hardware sources.
TEST_F(Dhcp6ParserTest, macSources) {
ConstElementPtr status;
EXPECT_NO_THROW(status = configureDhcp6Server(srv_,
Element::fromJSON("{ \"interfaces\": [ \"*\" ],"
"\"mac-sources\": [ \"rfc6939\", \"rfc4649\", \"rfc4580\" ],"
"\"preferred-lifetime\": 3000,"
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
"\"subnet6\": [ ], "
"\"valid-lifetime\": 4000 }")));
// returned value should be 0 (success)
checkResult(status, 0);
vector<uint32_t> mac_sources = CfgMgr::instance().getStagingCfg()->getMACSources();
ASSERT_EQ(3, mac_sources.size());
EXPECT_EQ(Pkt::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION, mac_sources[0]);
EXPECT_EQ(Pkt::HWADDR_SOURCE_REMOTE_ID, mac_sources[1]);
EXPECT_EQ(Pkt::HWADDR_SOURCE_SUBSCRIBER_ID, mac_sources[2]);
}
};
......@@ -1130,4 +1130,34 @@ TEST_F(Pkt6Test, getMACFromIPv6RelayOpt_multipleRelay) {
tmp << "hwtype=1 fa:30:0b:fa:c0:fe";
EXPECT_EQ(tmp.str(), found->toText(true));
}
// Checks whether Pkt::MACSourceFromText is working correctly.
// Technically, this is a Pkt, not Pkt6 test, but since there is no separate
// unit-tests for Pkt and it is abstract, so it would be tricky to test it
// directly. Hence test is being run in Pkt6.
TEST_F(Pkt6Test, MACSourceFromText) {
EXPECT_THROW(Pkt::MACSourceFromText("unknown"), BadValue);
EXPECT_EQ(Pkt::HWADDR_SOURCE_ANY, Pkt::MACSourceFromText("any"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_RAW, Pkt::MACSourceFromText("raw"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_DUID, Pkt::MACSourceFromText("duid"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_IPV6_LINK_LOCAL,
Pkt::MACSourceFromText("ipv6-link-local"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION,
Pkt::MACSourceFromText("client-link-addr-option"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_CLIENT_ADDR_RELAY_OPTION,
Pkt::MACSourceFromText("rfc6939"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_REMOTE_ID,
Pkt::MACSourceFromText("remote-id"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_REMOTE_ID,
Pkt::MACSourceFromText("rfc4649"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_SUBSCRIBER_ID,
Pkt::MACSourceFromText("subscriber-id"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_SUBSCRIBER_ID,
Pkt::MACSourceFromText("rfc4580"));
EXPECT_EQ(Pkt::HWADDR_SOURCE_DOCSIS,
Pkt::MACSourceFromText("docsis"));
}
}
......@@ -212,7 +212,7 @@ TEST_F(DhcpParserTest, uint32ParserTest) {
EXPECT_EQ(test_value, actual_value);
}
/// @brief Check InterfaceListParser basic functionality
/// @brief Check InterfaceListConfigParser basic functionality
///
/// Verifies that the parser:
/// 1. Does not allow empty for storage.
......@@ -270,6 +270,49 @@ TEST_F(DhcpParserTest, interfaceListParserTest) {
EXPECT_TRUE(test_config.socketOpen("eth1", AF_INET));
}
/// @brief Check MACSourcesListConfigParser basic functionality
///
/// Verifies that the parser:
/// 1. Does not allow empty for storage.
/// 2. Does not allow name other than "mac-sources"
/// 3. Parses list of mac sources and adds them to CfgMgr
TEST_F(DhcpParserTest, MacSourcesListConfigParserTest) {
const std::string valid_name = "mac-sources";
const std::string bogus_name = "bogus-name";
ParserContextPtr parser_context(new ParserContext(Option::V6));
// Verify that parser constructor fails if parameter name isn't "mac-sources"
EXPECT_THROW(MACSourcesListConfigParser(bogus_name, parser_context),
isc::BadValue);
// That's an equivalent of the following snippet:
// "mac-sources: [ \"duid\", \"ipv6\" ]";
ElementPtr config = Element::createList();
config->add(Element::create("duid"));
config->add(Element::create("ipv6-link-local"));
boost::scoped_ptr<MACSourcesListConfigParser>
parser(new MACSourcesListConfigParser(valid_name, parser_context));
// This should parse the configuration and add eth0 and eth1 to the list
// of interfaces that server should listen on.
EXPECT_NO_THROW(parser->build(config));
EXPECT_NO_THROW(parser->commit());
// Use CfgMgr instance to check if eth0 and eth1 was added, and that
// eth2 was not added.
SrvConfigPtr cfg = CfgMgr::instance().getStagingCfg();
ASSERT_TRUE(cfg);
vector<uint32_t> configured_sources = cfg->getMACSources();
ASSERT_EQ(2, configured_sources.size());
EXPECT_EQ(Pkt::HWADDR_SOURCE_DUID, configured_sources[0]);
EXPECT_EQ(Pkt::HWADDR_SOURCE_IPV6_LINK_LOCAL, configured_sources[1]);
}
/// @brief Test Fixture class which provides basic structure for testing
/// configuration parsing. This is essentially the same structure provided
/// by dhcp servers.
......
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