Commit 13a8becc authored by Francis Dupont's avatar Francis Dupont
Browse files

[5425] Added final (?) tests

parent 43410fdf
......@@ -4112,11 +4112,13 @@ TEST_F(Dhcp4ParserTest, classifyPools) {
" },"
" {"
" \"pool\": \"192.0.3.101 - 192.0.3.150\", "
" \"client-class\": \"beta\" "
" \"client-class\": \"beta\", "
" \"known-clients\": \"never\" "
" },"
" {"
" \"pool\": \"192.0.4.101 - 192.0.4.150\", "
" \"client-class\": \"gamma\" "
" \"client-class\": \"gamma\", "
" \"known-clients\": \"only\" "
" },"
" {"
" \"pool\": \"192.0.5.101 - 192.0.5.150\" "
......@@ -4145,9 +4147,13 @@ TEST_F(Dhcp4ParserTest, classifyPools) {
ClientClasses classes;
classes.insert("alpha");
EXPECT_TRUE(pools.at(0)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to beta class is supported in pool[1]
// and not supported in any other pool (except pools[3], which allows
......@@ -4155,9 +4161,13 @@ TEST_F(Dhcp4ParserTest, classifyPools) {
classes.clear();
classes.insert("beta");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to gamma class is supported in pool[2]
// and not supported in any other pool (except pool[3], which allows
......@@ -4165,26 +4175,38 @@ TEST_F(Dhcp4ParserTest, classifyPools) {
classes.clear();
classes.insert("gamma");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(2)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to some other class (not mentioned in
// the config) is supported only in pool[3], which allows everyone.
classes.clear();
classes.insert("delta");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Finally, let's check class-less client. He should be allowed only in
// the last pool, which does not have any class restrictions.
classes.clear();
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
}
// This test verifies that the host reservations can be specified for
......
......@@ -2387,6 +2387,57 @@ TEST_F(Dhcpv4SrvTest, clientPoolClassify) {
EXPECT_FALSE(offer->getYiaddr().isV4Zero());
}
// Checks if the known-clients field is indeed used for pool selection.
TEST_F(Dhcpv4SrvTest, clientPoolKnown) {
IfaceMgrTestConfig test_config(true);
IfaceMgr::instance().openSockets4();
NakedDhcpv4Srv srv(0);
// This test configures 2 pools.
string config = "{ \"interfaces-config\": {"
" \"interfaces\": [ \"*\" ]"
"},"
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
"\"subnet4\": [ "
"{ \"pools\": [ { "
" \"pool\": \"192.0.2.1 - 192.0.2.100\", "
" \"known-clients\": \"only\" }, "
" { \"pool\": \"192.0.3.1 - 192.0.3.100\", "
" \"known-clients\": \"never\" } ], "
" \"subnet\": \"192.0.0.0/16\" } "
"],"
"\"valid-lifetime\": 4000 }";
ConstElementPtr json;
ASSERT_NO_THROW(json = parseDHCP4(config, true));
ConstElementPtr status;
EXPECT_NO_THROW(status = configureDhcp4Server(srv, json));
CfgMgr::instance().commit();
// check if returned status is OK
ASSERT_TRUE(status);
comment_ = config::parseAnswer(rcode_, status);
ASSERT_EQ(0, rcode_);
// Create a simple packet
Pkt4Ptr dis = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
dis->setRemoteAddr(IOAddress("192.0.2.1"));
dis->setCiaddr(IOAddress("192.0.2.1"));
dis->setIface("eth0");
OptionPtr clientid = generateClientId();
dis->addOption(clientid);
// First pool requires reservation so the second will be used
Pkt4Ptr offer = srv.processDiscover(dis);
ASSERT_TRUE(offer);
EXPECT_EQ(DHCPOFFER, offer->getType());
EXPECT_EQ("192.0.3.1", offer->getYiaddr().toText());
}
// Verifies last resort option 43 is backward compatible
TEST_F(Dhcpv4SrvTest, option43LastResort) {
IfaceMgrTestConfig test_config(true);
......
This diff is collapsed.
......@@ -3014,6 +3014,7 @@ YY_RULE_SETUP
{
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::POOLS:
case isc::dhcp::Parser6Context::PD_POOLS:
return isc::dhcp::Dhcp6Parser::make_KNOWN_CLIENTS(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("known-clients", driver.loc_);
......
......@@ -830,6 +830,7 @@ ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
\"known-clients\" {
switch(driver.ctx_) {
case isc::dhcp::Parser6Context::POOLS:
case isc::dhcp::Parser6Context::PD_POOLS:
return isc::dhcp::Dhcp6Parser::make_KNOWN_CLIENTS(driver.loc_);
default:
return isc::dhcp::Dhcp6Parser::make_STRING("known-clients", driver.loc_);
......
......@@ -735,6 +735,93 @@ TEST_F(ClassifyTest, clientClassifyPool) {
EXPECT_TRUE(ia_na3->getOption(D6O_IAADDR));
}
// Checks if the known-clients field is indeed used for pool selection.
TEST_F(ClassifyTest, clientKnownPool) {
IfaceMgrTestConfig test_config(true);
NakedDhcpv6Srv srv(0);
// This test configures 2 pools.
std::string config = "{ \"interfaces-config\": {"
" \"interfaces\": [ \"*\" ]"
"},"
"\"preferred-lifetime\": 3000,"
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
"\"client-classes\": [ "
" { "
" \"name\": \"foo\" "
" }, "
" { "
" \"name\": \"bar\" "
" } "
"], "
"\"subnet6\": [ "
" { \"pools\": [ "
" { "
" \"pool\": \"2001:db8:1::/64\", "
" \"known-clients\": \"only\" "
" }, "
" { "
" \"pool\": \"2001:db8:2::/64\", "
" \"known-clients\": \"never\" "
" } "
" ], "
" \"subnet\": \"2001:db8:2::/40\", "
" \"reservations\": [ "
" { \"duid\": \"01:02:03:04\", \"hostname\": \"foo\" } ] "
" } "
"], "
"\"valid-lifetime\": 4000 }";
ASSERT_NO_THROW(configure(config));
OptionPtr clientid1 = generateClientId();
Pkt6Ptr query1 = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 1234));
query1->setRemoteAddr(IOAddress("2001:db8:1::3"));
query1->addOption(generateIA(D6O_IA_NA, 234, 1500, 3000));
query1->addOption(clientid1);
query1->setIface("eth1");
// First pool requires reservation so the second will be used
srv.classifyPacket(query1);
Pkt6Ptr response1 = srv.processSolicit(query1);
ASSERT_TRUE(response1);
OptionPtr ia_na1 = response1->getOption(D6O_IA_NA);
ASSERT_TRUE(ia_na1);
EXPECT_FALSE(ia_na1->getOption(D6O_STATUS_CODE));
OptionPtr iaaddr1 = ia_na1->getOption(D6O_IAADDR);
ASSERT_TRUE(iaaddr1);
boost::shared_ptr<Option6IAAddr> addr1 =
boost::dynamic_pointer_cast<Option6IAAddr>(iaaddr1);
ASSERT_TRUE(addr1);
EXPECT_EQ("2001:db8:2::", addr1->getAddress().toText());
// Try with DUID 01:02:03:04
uint8_t duid[] = { 0x01, 0x02, 0x03, 0x04 };
OptionBuffer buf(duid, duid + sizeof(duid));
OptionPtr clientid2(new Option(Option::V6, D6O_CLIENTID, buf));
Pkt6Ptr query2 = Pkt6Ptr(new Pkt6(DHCPV6_SOLICIT, 2345));
query2->setRemoteAddr(IOAddress("2001:db8:1::3"));
query2->addOption(generateIA(D6O_IA_NA, 234, 1500, 3000));
query2->addOption(clientid2);
query2->setIface("eth1");
// Now the first pool will be used
srv.classifyPacket(query2);
Pkt6Ptr response2 = srv.processSolicit(query2);
ASSERT_TRUE(response2);
OptionPtr ia_na2 = response2->getOption(D6O_IA_NA);
ASSERT_TRUE(ia_na2);
EXPECT_FALSE(ia_na2->getOption(D6O_STATUS_CODE));
OptionPtr iaaddr2 = ia_na2->getOption(D6O_IAADDR);
ASSERT_TRUE(iaaddr2);
boost::shared_ptr<Option6IAAddr> addr2 =
boost::dynamic_pointer_cast<Option6IAAddr>(iaaddr2);
ASSERT_TRUE(addr2);
EXPECT_EQ("2001:db8:1::", addr2->getAddress().toText());
}
// Tests whether a packet with custom vendor-class (not erouter or docsis)
// is classified properly.
TEST_F(ClassifyTest, vendorClientClassification2) {
......
......@@ -4149,11 +4149,13 @@ TEST_F(Dhcp6ParserTest, classifyPools) {
" },"
" {"
" \"pool\": \"2001:db8:2::/80\", "
" \"client-class\": \"beta\" "
" \"client-class\": \"beta\", "
" \"known-clients\": \"never\" "
" },"
" {"
" \"pool\": \"2001:db8:3::/80\", "
" \"client-class\": \"gamma\" "
" \"client-class\": \"gamma\", "
" \"known-clients\": \"only\" "
" },"
" {"
" \"pool\": \"2001:db8:4::/80\" "
......@@ -4181,10 +4183,14 @@ TEST_F(Dhcp6ParserTest, classifyPools) {
// everyone).
ClientClasses classes;
classes.insert("alpha");
EXPECT_TRUE (pools.at(0)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(0)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to beta class is supported in pool[1]
// and not supported in any other pool (except pool[3], which allows
......@@ -4192,9 +4198,13 @@ TEST_F(Dhcp6ParserTest, classifyPools) {
classes.clear();
classes.insert("beta");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to gamma class is supported in pool[2]
// and not supported in any other pool (except pool[3], which allows
......@@ -4202,26 +4212,38 @@ TEST_F(Dhcp6ParserTest, classifyPools) {
classes.clear();
classes.insert("gamma");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to some other class (not mentioned in
// the config) is supported only in pool[3], which allows everyone.
classes.clear();
classes.insert("delta");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Finally, let's check class-less client. He should be allowed only in
// the last pool, which does not have any class restrictions.
classes.clear();
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
}
// Goal of this test is to verify that multiple pdpools can be configured
......@@ -4243,13 +4265,15 @@ TEST_F(Dhcp6ParserTest, classifyPdPools) {
" \"prefix-len\": 48, "
" \"delegated-len\": 64, "
" \"prefix\": \"2001:db8:2::\", "
" \"client-class\": \"beta\" "
" \"client-class\": \"beta\", "
" \"known-clients\": \"never\" "
" },"
" {"
" \"prefix-len\": 48, "
" \"delegated-len\": 64, "
" \"prefix\": \"2001:db8:3::\", "
" \"client-class\": \"gamma\" "
" \"client-class\": \"gamma\", "
" \"known-clients\": \"only\" "
" },"
" {"
" \"prefix-len\": 48, "
......@@ -4279,10 +4303,14 @@ TEST_F(Dhcp6ParserTest, classifyPdPools) {
// everyone).
ClientClasses classes;
classes.insert("alpha");
EXPECT_TRUE (pools.at(0)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(0)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to beta class is supported in pool[1]
// and not supported in any other pool (except pool[3], which allows
......@@ -4290,9 +4318,13 @@ TEST_F(Dhcp6ParserTest, classifyPdPools) {
classes.clear();
classes.insert("beta");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to gamma class is supported in pool[2]
// and not supported in any other pool (except pool[3], which allows
......@@ -4300,26 +4332,38 @@ TEST_F(Dhcp6ParserTest, classifyPdPools) {
classes.clear();
classes.insert("gamma");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Let's check if client belonging to some other class (not mentioned in
// the config) is supported only in pool[3], which allows everyone.
classes.clear();
classes.insert("delta");
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
// Finally, let's check class-less client. He should be allowed only in
// the last pool, which does not have any class restrictions.
classes.clear();
EXPECT_FALSE(pools.at(0)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(0)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(1)->clientSupported(classes, true));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, false));
EXPECT_TRUE (pools.at(3)->clientSupported(classes, false));
EXPECT_FALSE(pools.at(2)->clientSupported(classes, true));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, false));
EXPECT_TRUE(pools.at(3)->clientSupported(classes, true));
}
// This test checks the ability of the server to parse a configuration
......
......@@ -1002,10 +1002,12 @@ const char* EXTRACTED_CONFIGS[] = {
" },\n"
" {\n"
" \"client-class\": \"beta\",\n"
" \"known-clients\": \"never\",\n"
" \"pool\": \"2001:db8:2::/80\"\n"
" },\n"
" {\n"
" \"client-class\": \"gamma\",\n"
" \"known-clients\": \"only\",\n"
" \"pool\": \"2001:db8:3::/80\"\n"
" },\n"
" {\n"
......@@ -1037,12 +1039,14 @@ const char* EXTRACTED_CONFIGS[] = {
" {\n"
" \"client-class\": \"beta\",\n"
" \"delegated-len\": 64,\n"
" \"known-clients\": \"never\",\n"
" \"prefix\": \"2001:db8:2::\",\n"
" \"prefix-len\": 48\n"
" },\n"
" {\n"
" \"client-class\": \"gamma\",\n"
" \"delegated-len\": 64,\n"
" \"known-clients\": \"only\",\n"
" \"prefix\": \"2001:db8:3::\",\n"
" \"prefix-len\": 48\n"
" },\n"
......@@ -4454,11 +4458,13 @@ const char* UNPARSED_CONFIGS[] = {
" },\n"
" {\n"
" \"client-class\": \"beta\",\n"
" \"known-clients\": \"never\",\n"
" \"option-data\": [ ],\n"
" \"pool\": \"2001:db8:2::/80\"\n"
" },\n"
" {\n"
" \"client-class\": \"gamma\",\n"
" \"known-clients\": \"only\",\n"
" \"option-data\": [ ],\n"
" \"pool\": \"2001:db8:3::/80\"\n"
" },\n"
......@@ -4546,6 +4552,7 @@ const char* UNPARSED_CONFIGS[] = {
" {\n"
" \"client-class\": \"beta\",\n"
" \"delegated-len\": 64,\n"
" \"known-clients\": \"never\",\n"
" \"option-data\": [ ],\n"
" \"prefix\": \"2001:db8:2::\",\n"
" \"prefix-len\": 48\n"
......@@ -4553,6 +4560,7 @@ const char* UNPARSED_CONFIGS[] = {
" {\n"
" \"client-class\": \"gamma\",\n"
" \"delegated-len\": 64,\n"
" \"known-clients\": \"only\",\n"
" \"option-data\": [ ],\n"
" \"prefix\": \"2001:db8:3::\",\n"
" \"prefix-len\": 48\n"
......
......@@ -265,6 +265,44 @@ TEST(Subnet4Test, pool4InSubnet4) {
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, three_classes, false,
IOAddress("192.1.2.195")));
EXPECT_EQ(mypool, pool3);
// And now known clients
EXPECT_EQ(Pool::SERVE_BOTH, pool1->getKnownClients());
pool2->setKnownClients(Pool::SERVE_KNOWN);
pool3->setKnownClients(Pool::SERVE_UNKNOWN);
pool4->setKnownClients(Pool::SERVE_UNKNOWN);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, false,
IOAddress("192.1.2.64")));
EXPECT_EQ(mypool, pool1);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, true,
IOAddress("192.1.2.64")));
EXPECT_EQ(mypool, pool1);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, false,
IOAddress("192.1.2.129")));
EXPECT_FALSE(mypool);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, true,
IOAddress("192.1.2.129")));
EXPECT_EQ(mypool, pool2);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, false,
IOAddress("192.1.2.195")));
EXPECT_FALSE(mypool);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, true,
IOAddress("192.1.2.195")));
EXPECT_FALSE(mypool);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, bar_class, false,
IOAddress("192.1.2.195")));
EXPECT_EQ(mypool, pool3);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, bar_class, true,
IOAddress("192.1.2.195")));
EXPECT_FALSE(mypool);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, false,
IOAddress("192.1.2.201")));
EXPECT_EQ(mypool, pool4);
ASSERT_NO_THROW(mypool = subnet->getPool(Lease::TYPE_V4, no_class, true,
IOAddress("192.1.2.201")));
EXPECT_FALSE(mypool);
}
// Check if it's possible to get specified number of possible leases for
......@@ -323,6 +361,16 @@ TEST(Subnet4Test, getCapacity) {
EXPECT_EQ(196, subnet->getPoolCapacity(Lease::TYPE_V4, foo_class, false));
EXPECT_EQ(200, subnet->getPoolCapacity(Lease::TYPE_V4, bar_class, false));
EXPECT_EQ(200, subnet->getPoolCapacity(Lease::TYPE_V4, three_classes, false));
// And now known clients
EXPECT_EQ(Pool::SERVE_BOTH, pool1->getKnownClients());
pool2->setKnownClients(Pool::SERVE_KNOWN);
pool3->setKnownClients(Pool::SERVE_UNKNOWN);
EXPECT_EQ(132, subnet->getPoolCapacity(Lease::TYPE_V4, no_class, false));
EXPECT_EQ(196, subnet->getPoolCapacity(Lease::TYPE_V4, no_class, true));
EXPECT_EQ(136, subnet->getPoolCapacity(Lease::TYPE_V4, bar_class, false));
EXPECT_EQ(196, subnet->getPoolCapacity(Lease::TYPE_V4, bar_class, true));
}
// Checks that it is not allowed to add invalid pools.
......@@ -559,6 +607,11 @@ TEST(Subnet4Test, inRangeinPool) {
three_classes.insert("bar");
three_classes.insert("baz");
EXPECT_TRUE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), three_classes, false));
// Add known clients
pool1->setKnownClients(Pool::SERVE_UNKNOWN);
EXPECT_TRUE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), three_classes, false));
EXPECT_FALSE(subnet->inPool(Lease::TYPE_V4, IOAddress("192.2.3.4"), three_classes, true));
}
// This test checks if the toText() method returns text representation
......@@ -789,6 +842,13 @@ TEST(Subnet6Test, Pool6getCapacity) {
EXPECT_EQ(uint64_t(4294967296ull + 4294967296ull + 65536),
subnet->getPoolCapacity(Lease::TYPE_NA, three_classes, false));