Browse Source

[2949] Remaining unit-tests implemented.

Tomek Mrugalski 10 years ago
parent
commit
f1c1a3d47d
2 changed files with 99 additions and 3 deletions
  1. 22 2
      src/bin/dhcp6/tests/dhcp6_client.h
  2. 77 1
      src/bin/dhcp6/tests/infrequest_unittest.cc

+ 22 - 2
src/bin/dhcp6/tests/dhcp6_client.h

@@ -384,6 +384,28 @@ public:
     /// @brief Link address of the relay to be used for relayed messages.
     asiolink::IOAddress relay_link_addr_;
 
+    /// @brief Controls whether client will send ORO
+    ///
+    /// The actual content of the ORO is specified in oro_.
+    /// It is useful to split the actual content and the ORO sending
+    /// decision, so we could test cases of sending empty ORO.
+    void sendORO(bool send) {
+        send_oro_ = send;
+    }
+
+    /// @brief Instructs client to request specified option in ORO
+    ///
+    /// @param option_code client will request this option code
+    void requestOption(uint16_t option_code) {
+        send_oro_ = true;
+        oro_.push_back(option_code);
+    }
+
+    /// @brief List of options to be requested
+    ///
+    /// Content of this vector will be sent as ORO if send_oro_ is set
+    /// to true. See @ref sendORO for details.
+    std::vector<uint16_t> oro_;
 private:
 
     /// @brief Applies the new leases for the client.
@@ -489,8 +511,6 @@ private:
     /// @brief Pointer to the option holding a prefix hint.
     Option6IAPrefixPtr prefix_hint_;
 
-    // @brief List of options to be requested
-    std::vector<uint16_t> oro_;
 };
 
 } // end of namespace isc::dhcp::test

+ 77 - 1
src/bin/dhcp6/tests/infrequest_unittest.cc

@@ -64,6 +64,7 @@ const char* CONFIGS[] = {
         "    \"interface\": \"eth0\""
         " } ],"
         "\"valid-lifetime\": 4000 }",
+
     // Configuration 1
     "{ \"interfaces\": [ \"*\" ],"
         "\"preferred-lifetime\": 3000,"
@@ -78,6 +79,7 @@ const char* CONFIGS[] = {
         "    \"interface\": \"eth0\""
         " } ],"
         "\"valid-lifetime\": 4000 }",
+
     // Configuration 2
     "{ \"interfaces\": [ \"*\" ],"
         "\"preferred-lifetime\": 3000,"
@@ -96,7 +98,8 @@ const char* CONFIGS[] = {
         "    } ]"
         " } ],"
         "\"valid-lifetime\": 4000 }",
-    // Configuration 2
+
+    // Configuration 3
     "{ \"interfaces\": [ \"*\" ],"
         "\"option-data\": [ {"
         "    \"name\": \"nis-servers\","
@@ -135,6 +138,7 @@ TEST_F(InfRequestTest, infRequestBasic) {
     ASSERT_EQ(1, subnets->size());
 
     // Perform 2-way exchange (Inf-request/reply)
+    client.requestOption(D6O_NAME_SERVERS);
     ASSERT_NO_THROW(client.doInfRequest());
 
     // Confirm that there's a response
@@ -164,6 +168,7 @@ TEST_F(InfRequestTest, infRequestAnonymous) {
     ASSERT_EQ(1, subnets->size());
 
     // Perform 2-way exchange (Inf-request/reply)
+    client.requestOption(D6O_NAME_SERVERS);
     client.sendClientId(false);
     ASSERT_NO_THROW(client.doInfRequest());
 
@@ -193,6 +198,7 @@ TEST_F(InfRequestTest, infRequestStateless) {
     ASSERT_EQ(1, subnets->size());
 
     // Perform 2-way exchange (Inf-request/reply)
+    client.requestOption(D6O_SIP_SERVERS_ADDR);
     ASSERT_NO_THROW(client.doInfRequest());
 
     // Confirm that there's a response
@@ -207,5 +213,75 @@ TEST_F(InfRequestTest, infRequestStateless) {
     EXPECT_EQ("2001:db8::abcd", addrs[0].toText());
 }
 
+/// Check that server processes correctly an incoming inf-request
+/// if there are options defined at both global and subnet scope.
+TEST_F(InfRequestTest, infRequestSubnetAndGlobal) {
+    Dhcp6Client client;
+
+    // Configure client to request IA_PD.
+    configure(CONFIGS[2], *client.getServer());
+    // Make sure we ended-up having expected number of subnets configured.
+    const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
+        getCfgSubnets6()->getAll();
+    ASSERT_EQ(1, subnets->size());
+
+    // Perform 2-way exchange (Inf-request/reply)
+    client.requestOption(D6O_SIP_SERVERS_ADDR);
+    client.requestOption(D6O_NAME_SERVERS);
+    ASSERT_NO_THROW(client.doInfRequest());
+
+    // Confirm that there's a response
+    Pkt6Ptr response = client.getContext().response_;
+    ASSERT_TRUE(response);
+
+    // Check sip servers
+    Option6AddrLstPtr sip = boost::dynamic_pointer_cast<Option6AddrLst>
+                            (response->getOption(D6O_SIP_SERVERS_ADDR));
+    ASSERT_TRUE(sip);
+    Option6AddrLst::AddressContainer addrs = sip->getAddresses();
+    ASSERT_EQ(1, addrs.size());
+    EXPECT_EQ("2001:db8::1", addrs[0].toText());
+
+    // Check dns servers
+    Option6AddrLstPtr dns = boost::dynamic_pointer_cast<Option6AddrLst>
+                            (response->getOption(D6O_NAME_SERVERS));
+    ASSERT_TRUE(dns);
+    addrs = sip->getAddresses();
+    ASSERT_EQ(1, addrs.size());
+    EXPECT_EQ("2001:db8::2", addrs[0].toText());
+}
+
+/// Check that server processes correctly an incoming inf-request
+/// if there are options defined at global scope only (no subnets).
+TEST_F(InfRequestTest, infRequestNoSubnets) {
+    Dhcp6Client client;
+
+    // Configure client to request IA_PD.
+    configure(CONFIGS[3], *client.getServer());
+    // Make sure we ended-up having expected number of subnets configured.
+    const Subnet6Collection* subnets = CfgMgr::instance().getCurrentCfg()->
+        getCfgSubnets6()->getAll();
+    ASSERT_EQ(1, subnets->size());
+
+    // Perform 2-way exchange (Inf-request/reply)
+    client.requestOption(D6O_NIS_SERVERS);
+    ASSERT_NO_THROW(client.doInfRequest());
+
+    // Confirm that there's a response
+    Pkt6Ptr response = client.getContext().response_;
+    ASSERT_TRUE(response);
+
+    // Check sip servers
+    Option6AddrLstPtr nis = boost::dynamic_pointer_cast<Option6AddrLst>
+                            (response->getOption(D6O_NIS_SERVERS));
+    ASSERT_TRUE(nis);
+    Option6AddrLst::AddressContainer addrs = nis->getAddresses();
+    ASSERT_EQ(2, addrs.size());
+    EXPECT_EQ("2001:db8::1", addrs[0].toText());
+    EXPECT_EQ("2001:db8::2", addrs[0].toText());
+}
+
+
+
 
 } // end of anonymous namespace