Browse Source

[4271] Logging checks added for TokenVendor and TokenVendorClass

Tomek Mrugalski 8 years ago
parent
commit
d7f927a155
3 changed files with 272 additions and 25 deletions
  1. 15 9
      src/lib/eval/eval_messages.mes
  2. 249 13
      src/lib/eval/tests/token_unittest.cc
  3. 8 3
      src/lib/eval/token.cc

+ 15 - 9
src/lib/eval/eval_messages.mes

@@ -112,49 +112,55 @@ This debug message indicates that the expression has been evaluated
 to said value. This message is mostly useful during debugging of the
 client classification expressions.
 
-% EVAL_DEBUG_VENDOR_NO_OPTION Option with code %1 missing, pushing result %2
+% EVAL_DEBUG_VENDOR_NO_OPTION Option with code %1 missing, pushing result '%2'
 This debug message indicates that the expression has been evaluated
 and vendor option was not found. This message is mostly useful during
 debugging of the client classification expressions.
 
-% EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for %1, option had %2, pushing result %3
+% EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for %1, option had %2, pushing result '%3'
 This debug message indicates that the expression has been evaluated
 and vendor option was found, but has different enterprise-id than specified
 in the expression. This message is mostly useful during debugging of the
 client classification expressions.
 
-% EVAL_DEBUG_VENDOR_ENTERPRISE_ID Pushing enterprise-id %1 as result %2
+% EVAL_DEBUG_VENDOR_ENTERPRISE_ID Pushing enterprise-id %1 as result '%2'
 This debug message indicates that the expression has been evaluated and vendor
 option was found and its enterprise-id is being reported. This message is mostly
 useful during debugging of the client classification expressions.
 
-% EVAL_DEBUG_VENDOR_EXISTS Option with enterprise-id %1 found, pushing result %2
+% EVAL_DEBUG_VENDOR_EXISTS Option with enterprise-id %1 found, pushing result '%2'
 This debug message indicates that the expression has been evaluated and vendor
 option was found. This message is mostly useful during debugging of the client
 classification expressions.
 
-% EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code %1 missing, pushing result %2
+% EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code %1 missing, pushing result '%2'
 This debug message indicates that the expression has been evaluated
 and vendor class option was not found. This message is mostly useful during
 debugging of the client classification expressions.
 
-% EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for %1, option had %2, pushing result %3
+% EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for %1, option had %2, pushing result '%3'
 This debug message indicates that the expression has been evaluated
 and vendor class option was found, but has different enterprise-id than specified
 in the expression. This message is mostly useful during debugging of the
 client classification expressions.
 
-% EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID Pushing enterprise-id %1 as result %2
+% EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID Pushing enterprise-id %1 as result '%2'
 This debug message indicates that the expression has been evaluated and vendor
 class option was found and its enterprise-id is being reported. This message is mostly
 useful during debugging of the client classification expressions.
 
-% EVAL_DEBUG_VENDOR_CLASS_EXISTS Option with enterprise-id %1 found, pushing result %2
+% EVAL_DEBUG_VENDOR_CLASS_EXISTS Option with enterprise-id %1 found, pushing result '%2'
 This debug message indicates that the expression has been evaluated and vendor
 class option was found. This message is mostly useful during debugging of the
 client classification expressions.
 
-% EVAL_DEBUG_VENDOR_CLASS_DATA Data %1 (out of %2 received) in vendor class found pushing as %3
+% EVAL_DEBUG_VENDOR_CLASS_DATA Data %1 (out of %2 received) in vendor class found, pushing result '%3'
 This debug message indicates that vendor class option was found and passed
 enterprise-id checks and has sufficient number of data chunks. Total numer
 of chunks and value pushed are reported as debugging aid.
+
+% EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND Requested data index %1, but option with enterprise-id %2 has only %3 data tuple(s), pushing result '%4'
+This debug message indicates that vendor class option was found and passed
+enterprise-id checks, but does not have sufficient number of data chunks.
+Note that the index starts at 0, so there has to be at least (index + 1)
+data chunks.

+ 249 - 13
src/lib/eval/tests/token_unittest.cc

@@ -53,6 +53,10 @@ public:
 
         pkt4_->addOption(option_str4_);
         pkt6_->addOption(option_str6_);
+
+        // Change this to true if you need extra information about logging
+        // checks to be printed.
+        logCheckVerbose(false);
     }
 
     /// @brief Inserts RAI option with several suboptions
@@ -1924,15 +1928,13 @@ TEST_F(TokenTest, vendor4SpecificVendorExists) {
     // Case 3: option present and has matchin enterprise-id, should suceed
     testVendorExists(Option::V4, 4491, 4491, "true");
 
-
+    // Check if the logged messages are correct.
     addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 125 missing, "
-              "pushing result false");
+              "pushing result 'false'");
     addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
-              "option had 1234, pushing result false");
+              "option had 1234, pushing result 'false'");
     addString("EVAL_DEBUG_VENDOR_EXISTS Option with enterprise-id 4491 "
-              "found, pushing result true");
-
-    logCheckVerbose(true);
+              "found, pushing result 'true'");
     EXPECT_TRUE(checkFile());
 }
 
@@ -1946,6 +1948,15 @@ TEST_F(TokenTest, vendor6SpecificVendorExists) {
 
     // Case 3: option present and has matchin enterprise-id, should suceed
     testVendorExists(Option::V6, 4491, 4491, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 17 missing, "
+              "pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_EXISTS Option with enterprise-id 4491 "
+              "found, pushing result 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 /// Test if expression vendor[*].exists works properly for DHCPv4.
@@ -1958,6 +1969,15 @@ TEST_F(TokenTest, vendor4AnyVendorExists) {
 
     // Case 3: option present with vendor-id 4491, should succeed
     testVendorExists(Option::V4, 0, 4491, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 125 missing, "
+              "pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_EXISTS Option with enterprise-id 1234 "
+              "found, pushing result 'true'");
+    addString("EVAL_DEBUG_VENDOR_EXISTS Option with enterprise-id 4491 "
+              "found, pushing result 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test if expression vendor[*].exists works properly for DHCPv6.
@@ -1970,6 +1990,15 @@ TEST_F(TokenTest, vendor6AnyVendorExists) {
 
     // Case 3: option present with vendor-id 4491, should succeed
     testVendorExists(Option::V6, 0, 4491, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 17 missing, "
+              "pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_EXISTS Option with enterprise-id 1234 "
+              "found, pushing result 'true'");
+    addString("EVAL_DEBUG_VENDOR_EXISTS Option with enterprise-id 4491 "
+              "found, pushing result 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test if expression vendor[*].enterprise works properly for DHCPv4.
@@ -1983,6 +2012,15 @@ TEST_F(TokenTest, vendor4enterprise) {
     // Case 3: Option with vendor-id set to maximum value, should still
     // be able to handle it
     testVendorEnterprise(Option::V4, 4294967295, encode(4294967295));
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 125 missing, pushing"
+              " result ''");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID Pushing enterprise-id 1234 as "
+              "result '000004D2'");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID Pushing enterprise-id 4294967295"
+              " as result 'FFFFFFFF'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test if expression vendor[*].enterprise works properly for DHCPv6.
@@ -1996,6 +2034,15 @@ TEST_F(TokenTest, vendor6enterprise) {
     // Case 3: Option with vendor-id set to maximum value, should still
     // be able to handle it
     testVendorEnterprise(Option::V6, 4294967295, encode(4294967295));
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 17 missing, pushing"
+              " result ''");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID Pushing enterprise-id 1234 as "
+              "result '000004D2'");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID Pushing enterprise-id 4294967295 "
+              "as result 'FFFFFFFF'");
+    EXPECT_TRUE(checkFile());
 }
 
 // This one tests "vendor[4491].option[1].exists" expression. There are so many
@@ -2021,6 +2068,17 @@ TEST_F(TokenTest, vendor4SuboptionExists) {
     // Case 5: expression vendor[4491].option[1].exists, option with vendor-id = 4491,
     // suboption 1, expected result "true"
     testVendorSuboption(Option::V4, 4491, 1, 4491, 1, TokenOption::EXISTS, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 125 missing, pushing "
+              "result 'false'");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result 'false'");
+    addString("EVAL_DEBUG_OPTION Pushing option 1 with value 'false'");
+    addString("EVAL_DEBUG_OPTION Pushing option 1 with value 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 // This is similar to the previous one, but tests vendor[4491].option[1].exists
@@ -2044,6 +2102,17 @@ TEST_F(TokenTest, vendor6SuboptionExists) {
     // Case 5: expression vendor[4491].option[1].exists, option with vendor-id = 4491,
     // suboption 1, expected result "true"
     testVendorSuboption(Option::V6, 4491, 1, 4491, 1, TokenOption::EXISTS, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 17 missing, pushing "
+              "result 'false'");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result 'false'");
+    addString("EVAL_DEBUG_OPTION Pushing option 1 with value 'false'");
+    addString("EVAL_DEBUG_OPTION Pushing option 1 with value 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 // This test verifies if vendor[4491].option[1].hex expression properly returns
@@ -2065,6 +2134,17 @@ TEST_F(TokenTest, vendor4SuboptionHex) {
     // Case 5: option with vendor-id = 4491, suboption 1, expected result content
     // of the option
     testVendorSuboption(Option::V4, 4491, 1, 4491, 1, TokenOption::HEXADECIMAL, "alpha");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 125 missing, pushing "
+              "result ''");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_OPTION Pushing option 1 with value 0x");
+    addString("EVAL_DEBUG_OPTION Pushing option 1 with value 0x616C706861");
+    EXPECT_TRUE(checkFile());
 }
 
 // This test verifies if vendor[4491].option[1].hex expression properly returns
@@ -2086,6 +2166,17 @@ TEST_F(TokenTest, vendor6SuboptionHex) {
     // Case 5: option with vendor-id = 4491, suboption 1, expected result content
     // of the option
     testVendorSuboption(Option::V6, 4491, 1, 4491, 1, TokenOption::HEXADECIMAL, "alpha");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_NO_OPTION Option with code 17 missing, pushing "
+              "result ''");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_ENTERPRISE_ID_MISMATCH Was looking for 4491, "
+              "option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_OPTION Pushing option 1 with value 0x");
+    addString("EVAL_DEBUG_OPTION Pushing option 1 with value 0x616C706861");
+    EXPECT_TRUE(checkFile());
 }
 
 // This test verifies that "vendor-class[4491].exists" expression can be used
@@ -2099,6 +2190,15 @@ TEST_F(TokenTest, vendorClass4SpecificVendorExists) {
 
     // Case 3: option exists and has matching vendor-id, should succeed
     testVendorClassExists(Option::V4, 4491, 4491, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 124 missing, "
+              "pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_EXISTS Option with enterprise-id 4491 "
+              "found, pushing result 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 // This test verifies that "vendor-class[4491].exists" expression can be used
@@ -2112,6 +2212,15 @@ TEST_F(TokenTest, vendorClass6SpecificVendorExists) {
 
     // Case 3: option exists and has matching vendor-id, should succeed
     testVendorClassExists(Option::V6, 4491, 4491, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 16 missing, pushing "
+              "result 'false'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_EXISTS Option with enterprise-id 4491 "
+              "found, pushing result 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 // This test verifies that "vendor-class[*].exists" can be used in DHCPv4
@@ -2125,6 +2234,15 @@ TEST_F(TokenTest, vendorClass4AnyVendorExists) {
 
     // Case 3: option exists, should succeed, regardless of the vendor-id
     testVendorClassExists(Option::V4, 0, 4491, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 124 missing, "
+              "pushing result 'false'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_EXISTS Option with enterprise-id 1234 "
+              "found, pushing result 'true'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_EXISTS Option with enterprise-id 4491 "
+              "found, pushing result 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 // This test verifies that "vendor-class[*].exists" can be used in DHCPv6
@@ -2138,6 +2256,15 @@ TEST_F(TokenTest, vendorClass6AnyVendorExists) {
 
     // Case 3: option exists, should succeed, regardless of the vendor-id
     testVendorClassExists(Option::V6, 0, 4491, "true");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 16 missing, pushing "
+              "result 'false'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_EXISTS Option with enterprise-id 1234 "
+              "found, pushing result 'true'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_EXISTS Option with enterprise-id 4491 "
+              "found, pushing result 'true'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test if expression "vendor-class.enterprise" works properly for DHCPv4.
@@ -2151,6 +2278,15 @@ TEST_F(TokenTest, vendorClass4enterprise) {
     // Case 3: Option with vendor-id set to maximum value, should still
     // be able to handle it
     testVendorClassEnterprise(Option::V4, 4294967295, encode(4294967295));
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 124 missing, pushing "
+              "result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID Pushing enterprise-id "
+              "1234 as result '000004D2'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID Pushing enterprise-id "
+              "4294967295 as result 'FFFFFFFF'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test if expression "vendor-class.enterprise" works properly for DHCPv6.
@@ -2164,6 +2300,15 @@ TEST_F(TokenTest, vendorClass6enterprise) {
     // Case 3: Option with vendor-id set to maximum value, should still
     // be able to handle it.
     testVendorClassEnterprise(Option::V6, 4294967295, encode(4294967295));
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 16 missing, pushing "
+              "result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID Pushing enterprise-id "
+              "1234 as result '000004D2'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID Pushing enterprise-id "
+              "4294967295 as result 'FFFFFFFF'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test that expression "vendor-class[4491].data" is able to retrieve content
@@ -2189,6 +2334,19 @@ TEST_F(TokenTest, vendorClass4SpecificVendorData) {
     // vendor-class with vendor-id 4491 and 1 data tuple, expected result is
     // content of that data ("alpha")
     testVendorClassData(Option::V4, 4491, 0, 4491, 1, "alpha");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 124 missing, "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in vendor "
+              "class found, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in vendor "
+              "class found, pushing result 'alpha'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test that expression "vendor-class[4491].data" is able to retrieve content
@@ -2214,6 +2372,20 @@ TEST_F(TokenTest, vendorClass6SpecificVendorData) {
     // vendor-class with vendor-id 4491 and 1 data tuple, expected result is
     // content of that data ("alpha")
     testVendorClassData(Option::V6, 4491, 0, 4491, 1, "alpha");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 16 missing, "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND Requested data index 0, "
+              "but option with enterprise-id 4491 has only 0 data tuple(s), "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in vendor "
+              "class found, pushing result 'alpha'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test that expression "vendor-class[*].data" is able to retrieve content
@@ -2224,11 +2396,13 @@ TEST_F(TokenTest, vendorClass4AnyVendorData) {
     testVendorClassData(Option::V4, 0, 0, 0, 0, "");
 
     // Case 2: Expression looks for any vendor-id (0), data[0], there is
-    // vendor-class with vendor-id 1234 and no data, expected result is empty string.
+    // vendor-class with vendor-id 1234 and no data (one empty tuple), expected
+    // result is empty string.
     testVendorClassData(Option::V4, 0, 0, 1234, 0, "");
 
     // Case 3: Expression looks for any vendor-id (0), data[0], there is
-    // vendor-class with vendor-id 4491 and no data, expected result is empty string
+    // vendor-class with vendor-id 4491 and no data (one empty tuple), expected
+    // result is empty string.
     testVendorClassData(Option::V4, 0, 0, 4491, 0, "");
 
     // Case 4: Expression looks for any vendor-id (0), data[0], there is
@@ -2239,6 +2413,19 @@ TEST_F(TokenTest, vendorClass4AnyVendorData) {
     // vendor-class with vendor-id 4491 and 1 data tuple, expected result is
     // content of that data ("alpha")
     testVendorClassData(Option::V4, 0, 0, 4491, 1, "alpha");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 124 missing, "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in "
+              "vendor class found, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in "
+              "vendor class found, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in "
+              "vendor class found, pushing result 'alpha'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in "
+              "vendor class found, pushing result 'alpha'");
+    EXPECT_TRUE(checkFile());
 }
 
 // Test that expression "vendor-class[*].data" is able to retrieve content
@@ -2264,6 +2451,21 @@ TEST_F(TokenTest, vendorClass6AnyVendorData) {
     // vendor-class with vendor-id 4491 and 1 data tuple, expected result is
     // content of that data ("alpha")
     testVendorClassData(Option::V6, 0, 0, 4491, 1, "alpha");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 16 missing, "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND Requested data index 0, "
+              "but option with enterprise-id 1234 has only 0 data tuple(s), "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND Requested data index 0, "
+              "but option with enterprise-id 4491 has only 0 data tuple(s), "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in vendor "
+              "class found, pushing result 'alpha'");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 0 (out of 1 received) in vendor "
+              "class found, pushing result 'alpha'");
+    EXPECT_TRUE(checkFile());
 }
 
 // This test verifies if expression vendor-class[4491].data[3] is able to access
@@ -2288,12 +2490,29 @@ TEST_F(TokenTest, vendorClass4DataIndex) {
     // Case 5: Expression looks for vendor-id 4491, data[3], there is
     // vendor-class with vendor-id 4491, but has only 2 data tuples, expected
     // result is empty string.
-    testVendorClassData(Option::V4, 4491, 3, 1234, 1, "");
+    testVendorClassData(Option::V4, 4491, 3, 4491, 3, "");
 
     // Case 6: Expression looks for vendor-id 4491, data[3], there is
     // vendor-class with vendor-id 4491 and 5 data tuples, expected result is
     // content of that tuple ("gamma")
     testVendorClassData(Option::V4, 4491, 3, 4491, 5, "gamma");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 124 missing, "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND Requested data index 3, "
+              "but option with enterprise-id 4491 has only 1 data tuple(s), "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND Requested data index 3, "
+              "but option with enterprise-id 4491 has only 3 data tuple(s), "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 3 (out of 5 received) in vendor "
+              "class found, pushing result 'gamma'");
+    EXPECT_TRUE(checkFile());
 }
 
 // This test verifies if expression vendor-class[4491].data[3] is able to access
@@ -2312,18 +2531,35 @@ TEST_F(TokenTest, vendorClass6DataIndex) {
     testVendorClassData(Option::V6, 4491, 3, 4491, 0, "");
 
     // Case 4: Expression looks for vendor-id 4491, data[3], there is
-    // vendor-class with vendor-id 1234 and 2 data tuples, expected result is empty string.
-    testVendorClassData(Option::V6, 4491, 3, 1234, 1, "");
+    // vendor-class with vendor-id 1234 and 5 data tuples, expected result is empty string.
+    testVendorClassData(Option::V6, 4491, 3, 1234, 5, "");
 
     // Case 5: Expression looks for vendor-id 4491, data[3], there is
-    // vendor-class with vendor-id 4491, but has only 2 data tuples, expected
+    // vendor-class with vendor-id 4491, but has only 3 data tuples, expected
     // result is empty string.
-    testVendorClassData(Option::V6, 4491, 3, 1234, 1, "");
+    testVendorClassData(Option::V6, 4491, 3, 4491, 3, "");
 
     // Case 6: Expression looks for vendor-id 4491, data[3], there is
     // vendor-class with vendor-id 4491 and 5 data tuples, expected result is
     // content of that tuple ("gamma")
     testVendorClassData(Option::V6, 4491, 3, 4491, 5, "gamma");
+
+    // Check if the logged messages are correct.
+    addString("EVAL_DEBUG_VENDOR_CLASS_NO_OPTION Option with code 16 missing, "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND Requested data index 3, "
+              "but option with enterprise-id 4491 has only 0 data tuple(s), "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID_MISMATCH Was looking for "
+              "4491, option had 1234, pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND Requested data index 3, "
+              "but option with enterprise-id 4491 has only 3 data tuple(s), "
+              "pushing result ''");
+    addString("EVAL_DEBUG_VENDOR_CLASS_DATA Data 3 (out of 5 received) in vendor"
+              " class found, pushing result 'gamma'");
+    EXPECT_TRUE(checkFile());
 }
 
 };

+ 8 - 3
src/lib/eval/token.cc

@@ -682,7 +682,7 @@ void TokenVendor::evaluate(Pkt& pkt, ValueStack& values) {
         memcpy(&txt[0], &value, sizeof(uint32_t));
         values.push(txt);
         LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_ENTERPRISE_ID)
-            .arg(vendor_id_)
+            .arg(vendor->getVendorId())
             .arg(util::encode::encodeHex(std::vector<uint8_t>(txt.begin(),
                                                               txt.end())));
         return;
@@ -789,7 +789,7 @@ void TokenVendorClass::evaluate(Pkt& pkt, ValueStack& values) {
         memcpy(&txt[0], &value, sizeof(uint32_t));
         values.push(txt);
         LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_ENTERPRISE_ID)
-            .arg(vendor_id_)
+            .arg(vendor->getVendorId())
             .arg(util::encode::encodeHex(std::vector<uint8_t>(txt.begin(),
                                                               txt.end())));
         return;
@@ -812,6 +812,11 @@ void TokenVendorClass::evaluate(Pkt& pkt, ValueStack& values) {
         if (index_ + 1 > max) {
             // The index specified if out of bound, e.g. there are only
             // 2 tuples and index specified is 5.
+            LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND)
+                .arg(index_)
+                .arg(vendor->getVendorId())
+                .arg(max)
+                .arg("");
             values.push("");
             return;
         }
@@ -823,7 +828,7 @@ void TokenVendorClass::evaluate(Pkt& pkt, ValueStack& values) {
         LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_DATA)
             .arg(index_)
             .arg(max)
-            .arg(util::encode::encodeHex(buf));
+            .arg(txt);
 
         values.push(txt);
         return;