Commit 59410c49 authored by Francis Dupont's avatar Francis Dupont
Browse files

[5241] Added PRL vs always-true requested unit tests

parent 66730342
......@@ -2170,6 +2170,87 @@ TEST_F(Dhcpv4SrvTest, clientClassify) {
EXPECT_TRUE(srv_.selectSubnet(dis));
}
// Checks effect of persistency (aka always-true) flag on the PRL
TEST_F(Dhcpv4SrvTest, prlPersistency) {
IfaceMgrTestConfig test_config(true);
IfaceMgr::instance().openSockets4();
NakedDhcpv4Srv srv(0);
string config = "{ \"interfaces-config\": {"
" \"interfaces\": [ \"*\" ] }, "
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
"\"valid-lifetime\": 4000, "
"\"subnet4\": [ "
"{ \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], "
" \"subnet\": \"192.0.2.0/24\" } ], "
"\"option-data\": ["
" { \"name\": \"default-ip-ttl\", "
" \"data\": \"FF\", "
" \"csv-format\": false }, "
" { \"name\": \"ip-forwarding\", "
" \"data\": \"false\", "
" \"always-send\": true } ] }";
ConstElementPtr json;
ASSERT_NO_THROW(json = parseDHCP4(config));
ConstElementPtr status;
// Configure the server and make sure the config is accepted
EXPECT_NO_THROW(status = configureDhcp4Server(srv, json));
ASSERT_TRUE(status);
comment_ = config::parseAnswer(rcode_, status);
ASSERT_EQ(0, rcode_);
CfgMgr::instance().commit();
// Create a packet with enough to select the subnet and go through
// the DISCOVER processing
Pkt4Ptr query(new Pkt4(DHCPDISCOVER, 1234));
query->setRemoteAddr(IOAddress("192.0.2.1"));
OptionPtr clientid = generateClientId();
query->addOption(clientid);
query->setIface("eth1");
// Create and add a PRL option for another option
OptionUint8ArrayPtr prl(new OptionUint8Array(Option::V4,
DHO_DHCP_PARAMETER_REQUEST_LIST));
ASSERT_TRUE(prl);
prl->addValue(DHO_ARP_CACHE_TIMEOUT);
query->addOption(prl);
// Create and add a host-name option to the query
OptionStringPtr hostname(new OptionString(Option::V4, 12, "foo"));
ASSERT_TRUE(hostname);
query->addOption(hostname);
// Process the query
Pkt4Ptr response = srv.processDiscover(query);
// Processing should add an ip-forwarding option
ASSERT_TRUE(response->getOption(DHO_IP_FORWARDING));
// But no default-ip-ttl
ASSERT_FALSE(response->getOption(DHO_DEFAULT_IP_TTL));
// Nor an arp-cache-timeout
ASSERT_FALSE(response->getOption(DHO_ARP_CACHE_TIMEOUT));
// Reset PRL adding default-ip-ttl
query->delOption(DHO_DHCP_PARAMETER_REQUEST_LIST);
prl->addValue(DHO_DEFAULT_IP_TTL);
query->addOption(prl);
// Process query
response = srv.processDiscover(query);
// Processing should add an ip-forwarding option
ASSERT_TRUE(response->getOption(DHO_IP_FORWARDING));
// and now a default-ip-ttl
ASSERT_TRUE(response->getOption(DHO_DEFAULT_IP_TTL));
// and still no arp-cache-timeout
ASSERT_FALSE(response->getOption(DHO_ARP_CACHE_TIMEOUT));
}
// Checks if relay IP address specified in the relay-info structure in
// subnet4 is being used properly.
TEST_F(Dhcpv4SrvTest, relayOverride) {
......
......@@ -1502,6 +1502,81 @@ TEST_F(Dhcpv6SrvTest, portsRelayedTraffic) {
EXPECT_EQ(DHCP6_SERVER_PORT, adv->getRemotePort());
}
// Checks effect of persistency (aka always-true) flag on the ORO
TEST_F(Dhcpv6SrvTest, prlPersistency) {
IfaceMgrTestConfig test_config(true);
NakedDhcpv6Srv srv(0);
string config = "{ \"interfaces-config\": {"
" \"interfaces\": [ \"*\" ] }, "
"\"preferred-lifetime\": 3000, "
"\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, "
"\"valid-lifetime\": 4000, "
"\"subnet6\": [ "
"{ \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ], "
" \"subnet\": \"2001:db8:1::/48\" } ], "
"\"option-data\": ["
" { \"name\": \"dns-servers\", "
" \"data\": \"2001:db8:1234:FFFF::1\" }, "
" { \"name\": \"subscriber-id\", "
" \"data\": \"1234\", "
" \"always-send\": true } ] }";
ConstElementPtr json;
ASSERT_NO_THROW(json = parseDHCP6(config));
ConstElementPtr status;
// Configure the server and make sure the config is accepted
EXPECT_NO_THROW(status = configureDhcp6Server(srv, json));
ASSERT_TRUE(status);
comment_ = config::parseAnswer(rcode_, status);
ASSERT_EQ(0, rcode_);
CfgMgr::instance().commit();
// Create a packet with enough to select the subnet and go through
// the SOLICIT processing
Pkt6Ptr sol(new Pkt6(DHCPV6_SOLICIT, 1234));
sol->setRemoteAddr(IOAddress("fe80::abcd"));
sol->setIface("eth0");
sol->addOption(generateIA(D6O_IA_NA, 234, 1500, 3000));
OptionPtr clientid = generateClientId();
sol->addOption(clientid);
// Create and add an ORO for another option
OptionUint16ArrayPtr oro(new OptionUint16Array(Option::V6, D6O_ORO));
ASSERT_TRUE(oro);
oro->addValue(D6O_SNTP_SERVERS);
sol->addOption(oro);
// Process the solicit
Pkt6Ptr response = srv.processSolicit(sol);
// Processing should add a subscriber-id option
ASSERT_TRUE(response->getOption(D6O_SUBSCRIBER_ID));
// But no dns-servers
ASSERT_FALSE(response->getOption(D6O_NAME_SERVERS));
// Nor a sntp-servers
ASSERT_FALSE(response->getOption(D6O_SNTP_SERVERS));
// Reset ORO adding dns-servers
sol->delOption(D6O_ORO);
oro->addValue(D6O_NAME_SERVERS);
sol->addOption(oro);
// Process solicit
response = srv.processSolicit(sol);
// Processing should add a subscriber-id option
ASSERT_TRUE(response->getOption(D6O_SUBSCRIBER_ID));
// and now a dns-servers
ASSERT_TRUE(response->getOption(D6O_NAME_SERVERS));
// and still no sntp-servers
ASSERT_FALSE(response->getOption(D6O_SNTP_SERVERS));
}
// Checks if server is able to handle a relayed traffic from DOCSIS3.0 modems
// @todo Uncomment this test as part of #3180 work.
// Kea code currently fails to handle docsis traffic.
......
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