]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3074] added some comments
authorPiotrek Zadroga <piotrek@isc.org>
Wed, 11 Oct 2023 11:25:28 +0000 (13:25 +0200)
committerPiotrek Zadroga <piotrek@isc.org>
Tue, 9 Jan 2024 10:38:08 +0000 (11:38 +0100)
src/lib/dhcp/option_classless_static_route.h
src/lib/dhcp/tests/option_classless_static_route_unittest.cc

index 6bd1da03002ca535dfbef9f7e768d2a87d313c85..e39347fd41b7c1be9c24adff952b637af55e906a 100644 (file)
@@ -48,7 +48,8 @@ public:
     /// @param check flag which indicates if checking the option length is
     /// required (used only in V4)
     ///
-    /// @throw
+    /// @throw OutOfRange Thrown when @c check param set to @c true and
+    /// @c Option::packHeader(buf,check) throws due to option len>255 octets.
     void pack(util::OutputBuffer& buf, bool check = true) const override;
 
     /// @brief Parses received wire data buffer.
index 32a28eb1cfe1b257c6b1327ad3419fd3f6de7f66..ef0d615e12960f9ed41c34bfcb5f650aaafc9c77 100644 (file)
@@ -27,6 +27,7 @@ TEST(OptionClasslessStaticRouteTest, emptyCtor) {
     EXPECT_EQ(DHO_CLASSLESS_STATIC_ROUTE, option->getType());
 }
 
+// This test verifies adding one route to OptionClasslessStaticRoute class.
 TEST(OptionClasslessStaticRouteTest, emptyCtorAddOneRoute) {
     // Create option instance. Check that constructor doesn't throw.
     OptionClasslessStaticRoutePtr option;
@@ -44,23 +45,21 @@ TEST(OptionClasslessStaticRouteTest, emptyCtorAddOneRoute) {
     EXPECT_EQ("type=121(CLASSLESS_STATIC_ROUTE), len=5, Route 1 (subnet 0.0.0.0/0,"
               " router IP 10.198.122.1)",
               option->toText());
-
-    // Check if member variables were correctly set by ctor.
-    EXPECT_EQ(Option::V4, option->getUniverse());
-    EXPECT_EQ(DHO_CLASSLESS_STATIC_ROUTE, option->getType());
 }
 
+// This test verifies constructor of the OptionClasslessStaticRoute class from config data.
+// Only one static route is defined.
 TEST(OptionClasslessStaticRouteTest, bufferCtorWithOneRoute) {
-    // Prepare data to decode - one route with 0 mask width
+    // Prepare data to decode - one route with mask width = 8.
     const uint8_t buf_data[] = {
-        10, 0, 0, 0,    // subnet nr
-        255, 0, 0, 0,   // mask
-        10, 198, 122, 1 // router IP
+        10,  0,   0,   0,  // subnet nr
+        255, 0,   0,   0,  // mask
+        10,  198, 122, 1   // router IP
     };
 
     OptionBuffer buf(buf_data, buf_data + sizeof(buf_data));
 
-    // Create option instance. Check that constructor doesn't throw.
+    // Create option instance. Check that constructor doesn't throw. Unpack is also tested here.
     OptionClasslessStaticRoutePtr option;
     EXPECT_NO_THROW(option.reset(new OptionClasslessStaticRoute(buf.begin(), buf.end())));
     ASSERT_TRUE(option);
@@ -72,10 +71,41 @@ TEST(OptionClasslessStaticRouteTest, bufferCtorWithOneRoute) {
     EXPECT_EQ("type=121(CLASSLESS_STATIC_ROUTE), len=6, Route 1 (subnet 10.0.0.0/8,"
               " router IP 10.198.122.1)",
               option->toText());
+}
 
-    // Check if member variables were correctly set by ctor.
-    EXPECT_EQ(Option::V4, option->getUniverse());
-    EXPECT_EQ(DHO_CLASSLESS_STATIC_ROUTE, option->getType());
+// This test verifies constructor of the OptionClasslessStaticRoute class from config data.
+// 3 static routes are defined.
+TEST(OptionClasslessStaticRouteTest, bufferCtorWithMoreRoutes) {
+    // Prepare data to decode - 3 static routes
+    const uint8_t buf_data[] = {
+        0,   0,   0,   0,    // subnet nr
+        0,   0,   0,   0,    // mask
+        10,  17,  0,   1,    // router IP
+        10,  229, 0,   128,  // subnet nr
+        255, 255, 255, 128,  // mask
+        10,  229, 0,   1,    // router IP
+        10,  27,  129, 0,    // subnet nr
+        255, 255, 255, 0,    // mask
+        10,  27,  129, 1     // router IP
+    };
+
+    OptionBuffer buf(buf_data, buf_data + sizeof(buf_data));
+
+    // Create option instance. Check that constructor doesn't throw. Unpack is also tested here.
+    OptionClasslessStaticRoutePtr option;
+    EXPECT_NO_THROW(option.reset(new OptionClasslessStaticRoute(buf.begin(), buf.end())));
+    ASSERT_TRUE(option);
+
+    // Expected len: 2 (option code + option len headers) + 5 (1 dest descriptor + 4 router addr)
+    // + 9 (5 dest descriptor + 4 router addr) + 8 (4 dest descriptor + 4 router addr).
+    EXPECT_EQ(24, option->len());
+
+    // Verify toText() is working fine.
+    EXPECT_EQ("type=121(CLASSLESS_STATIC_ROUTE), len=22, "
+              "Route 1 (subnet 0.0.0.0/0, router IP 10.17.0.1), "
+              "Route 2 (subnet 10.229.0.128/25, router IP 10.229.0.1), "
+              "Route 3 (subnet 10.27.129.0/24, router IP 10.27.129.1)",
+              option->toText());
 }
 
 }
\ No newline at end of file