Commit 02141f25 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[2994] selectSubnet(), hooks tests for subnet4_select fixes.

parent 07074c52
...@@ -885,7 +885,7 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) { ...@@ -885,7 +885,7 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) {
Subnet4Ptr subnet; Subnet4Ptr subnet;
// Is this relayed message? // Is this relayed message?
IOAddress relay = question->getGiaddr(); IOAddress relay = question->getGiaddr();
if (relay.toText() == "0.0.0.0") { if (relay.toText() != "0.0.0.0") {
// Yes: Use relay address to select subnet // Yes: Use relay address to select subnet
subnet = CfgMgr::instance().getSubnet4(relay); subnet = CfgMgr::instance().getSubnet4(relay);
...@@ -895,6 +895,8 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) { ...@@ -895,6 +895,8 @@ Dhcpv4Srv::selectSubnet(const Pkt4Ptr& question) {
subnet = CfgMgr::instance().getSubnet4(question->getRemoteAddr()); subnet = CfgMgr::instance().getSubnet4(question->getRemoteAddr());
} }
/// @todo Implement getSubnet4(interface-name)
// Let's execute all callouts registered for packet_received // Let's execute all callouts registered for packet_received
if (HooksManager::getHooksManager().calloutsPresent(hook_index_subnet4_select_)) { if (HooksManager::getHooksManager().calloutsPresent(hook_index_subnet4_select_)) {
CalloutHandlePtr callout_handle = getCalloutHandle(question); CalloutHandlePtr callout_handle = getCalloutHandle(question);
......
...@@ -1622,6 +1622,11 @@ TEST_F(Dhcpv4SrvTest, ServerID) { ...@@ -1622,6 +1622,11 @@ TEST_F(Dhcpv4SrvTest, ServerID) {
EXPECT_EQ(srvid_text, text); EXPECT_EQ(srvid_text, text);
} }
/// @todo Implement tests for subnetSelect See tests in dhcp6_srv_unittest.cc:
/// selectSubnetAddr, selectSubnetIface, selectSubnetRelayLinkaddr,
/// selectSubnetRelayInterfaceId. Note that the concept of interface-id is not
/// present in the DHCPv4, so not everything is applicable directly.
// Checks if hooks are registered properly. // Checks if hooks are registered properly.
TEST_F(Dhcpv4SrvTest, Hooks) { TEST_F(Dhcpv4SrvTest, Hooks) {
NakedDhcpv4Srv srv(0); NakedDhcpv4Srv srv(0);
...@@ -1909,14 +1914,14 @@ public: ...@@ -1909,14 +1914,14 @@ public:
// Call the basic calllout to record all passed values // Call the basic calllout to record all passed values
subnet4_select_callout(callout_handle); subnet4_select_callout(callout_handle);
Subnet4Collection subnets; const Subnet4Collection* subnets;
Subnet4Ptr subnet; Subnet4Ptr subnet;
callout_handle.getArgument("subnet4", subnet); callout_handle.getArgument("subnet4", subnet);
callout_handle.getArgument("subnet4collection", subnets); callout_handle.getArgument("subnet4collection", subnets);
// Let's change to a different subnet // Let's change to a different subnet
if (subnets.size() > 1) { if (subnets->size() > 1) {
subnet = subnets[1]; // Let's pick the other subnet subnet = (*subnets)[1]; // Let's pick the other subnet
callout_handle.setArgument("subnet4", subnet); callout_handle.setArgument("subnet4", subnet);
} }
...@@ -2222,16 +2227,15 @@ TEST_F(HooksDhcpv4SrvTest, subnet4_select) { ...@@ -2222,16 +2227,15 @@ TEST_F(HooksDhcpv4SrvTest, subnet4_select) {
// Configure 2 subnets, both directly reachable over local interface // Configure 2 subnets, both directly reachable over local interface
// (let's not complicate the matter with relays) // (let's not complicate the matter with relays)
string config = "{ \"interface\": [ \"all\" ]," string config = "{ \"interface\": [ \"all\" ],"
"\"preferred-lifetime\": 3000,"
"\"rebind-timer\": 2000, " "\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, " "\"renew-timer\": 1000, "
"\"subnet4\": [ { " "\"subnet4\": [ { "
" \"pool\": [ \"2001:db8:1::/44\" ]," " \"pool\": [ \"192.0.2.0/25\" ],"
" \"subnet\": \"2001:db8:1::/48\", " " \"subnet\": \"192.0.2.0/24\", "
" \"interface\": \"" + valid_iface_ + "\" " " \"interface\": \"" + valid_iface_ + "\" "
" }, {" " }, {"
" \"pool\": [ \"2001:db8:2::/44\" ]," " \"pool\": [ \"192.0.3.0/25\" ],"
" \"subnet\": \"2001:db8:2::/48\" " " \"subnet\": \"192.0.3.0/24\" "
" } ]," " } ],"
"\"valid-lifetime\": 4000 }"; "\"valid-lifetime\": 4000 }";
...@@ -2246,7 +2250,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet4_select) { ...@@ -2246,7 +2250,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet4_select) {
// Prepare discover packet. Server should select first subnet for it // Prepare discover packet. Server should select first subnet for it
Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
sol->setRemoteAddr(IOAddress("fe80::abcd")); sol->setRemoteAddr(IOAddress("192.0.2.1"));
sol->setIface(valid_iface_); sol->setIface(valid_iface_);
OptionPtr clientid = generateClientId(); OptionPtr clientid = generateClientId();
sol->addOption(clientid); sol->addOption(clientid);
...@@ -2289,16 +2293,15 @@ TEST_F(HooksDhcpv4SrvTest, subnet_select_change) { ...@@ -2289,16 +2293,15 @@ TEST_F(HooksDhcpv4SrvTest, subnet_select_change) {
// Configure 2 subnets, both directly reachable over local interface // Configure 2 subnets, both directly reachable over local interface
// (let's not complicate the matter with relays) // (let's not complicate the matter with relays)
string config = "{ \"interface\": [ \"all\" ]," string config = "{ \"interface\": [ \"all\" ],"
"\"preferred-lifetime\": 3000,"
"\"rebind-timer\": 2000, " "\"rebind-timer\": 2000, "
"\"renew-timer\": 1000, " "\"renew-timer\": 1000, "
"\"subnet4\": [ { " "\"subnet4\": [ { "
" \"pool\": [ \"2001:db8:1::/44\" ]," " \"pool\": [ \"192.0.2.0/25\" ],"
" \"subnet\": \"2001:db8:1::/48\", " " \"subnet\": \"192.0.2.0/24\", "
" \"interface\": \"" + valid_iface_ + "\" " " \"interface\": \"" + valid_iface_ + "\" "
" }, {" " }, {"
" \"pool\": [ \"2001:db8:2::/44\" ]," " \"pool\": [ \"192.0.3.0/25\" ],"
" \"subnet\": \"2001:db8:2::/48\" " " \"subnet\": \"192.0.3.0/24\" "
" } ]," " } ],"
"\"valid-lifetime\": 4000 }"; "\"valid-lifetime\": 4000 }";
...@@ -2313,7 +2316,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet_select_change) { ...@@ -2313,7 +2316,7 @@ TEST_F(HooksDhcpv4SrvTest, subnet_select_change) {
// Prepare discover packet. Server should select first subnet for it // Prepare discover packet. Server should select first subnet for it
Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234)); Pkt4Ptr sol = Pkt4Ptr(new Pkt4(DHCPDISCOVER, 1234));
sol->setRemoteAddr(IOAddress("fe80::abcd")); sol->setRemoteAddr(IOAddress("192.0.2.1"));
sol->setIface(valid_iface_); sol->setIface(valid_iface_);
OptionPtr clientid = generateClientId(); OptionPtr clientid = generateClientId();
sol->addOption(clientid); sol->addOption(clientid);
......
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