Browse Source

[trac4265] updates per review comments

Shawn Routhier 9 years ago
parent
commit
b2a5d809ac

+ 0 - 1
src/lib/eval/eval_context.cc

@@ -100,7 +100,6 @@ EvalContext::convertNestLevelNumber(const std::string& nest_level,
     try {
         n  = boost::lexical_cast<int>(nest_level);
     } catch (const boost::bad_lexical_cast &) {
-        // This can't happen...
         error(loc, "Nest level has invalid value in " + nest_level);
     }
     if (option_universe_ == Option::V6) {

+ 4 - 4
src/lib/eval/parser.yy

@@ -68,7 +68,7 @@ using namespace isc::eval;
 
 %type <uint16_t> option_code
 %type <TokenOption::RepresentationType> option_repr_type
-%type <TokenRelay6::FieldType> relay6_field
+%type <TokenRelay6Field::FieldType> relay6_field
 %type <uint8_t> nest_level
 
 %left OR
@@ -210,7 +210,7 @@ string_expr : STRING
                      switch (ctx.getUniverse()) {
                      case Option::V6:
                      {
-                         TokenPtr relay6field(new TokenRelay6($3, $6));
+                         TokenPtr relay6field(new TokenRelay6Field($3, $6));
                          ctx.expression.push_back(relay6field);
                          break;
                      }
@@ -272,8 +272,8 @@ length_expr : INTEGER
                  }
             ;
 
-relay6_field : PEERADDR { $$ = TokenRelay6::PEERADDR; }
-             | LINKADDR { $$ = TokenRelay6::LINKADDR; }
+relay6_field : PEERADDR { $$ = TokenRelay6Field::PEERADDR; }
+             | LINKADDR { $$ = TokenRelay6Field::LINKADDR; }
              ;
 
 nest_level : INTEGER

+ 11 - 11
src/lib/eval/tests/context_unittest.cc

@@ -210,12 +210,12 @@ public:
     /// @param expected_level expected nesting level
     /// @param expected_code expected option code
     /// @param expected_repr expected representation (text, hex, exists)
-    void checkTokenRelay6(const TokenPtr& token,
-                          uint8_t expected_level,
-                          TokenRelay6::FieldType expected_type) {
+    void checkTokenRelay6Field(const TokenPtr& token,
+                               uint8_t expected_level,
+                               TokenRelay6Field::FieldType expected_type) {
         ASSERT_TRUE(token);
-        boost::shared_ptr<TokenRelay6> opt =
-            boost::dynamic_pointer_cast<TokenRelay6>(token);
+        boost::shared_ptr<TokenRelay6Field> opt =
+            boost::dynamic_pointer_cast<TokenRelay6Field>(token);
         ASSERT_TRUE(opt);
 
         EXPECT_EQ(expected_level, opt->getNest());
@@ -223,7 +223,7 @@ public:
     }
 
     /// @brief This tests attempts to parse the expression then checks
-    /// if the number of tokens is correct and the TokenRelay6 is as
+    /// if the number of tokens is correct and the TokenRelay6Field is as
     /// expected.
     ///
     /// @param expr expression to be parsed
@@ -232,7 +232,7 @@ public:
     /// @param exp_tokens expected number of tokens
     void testRelay6Field(std::string expr,
                          uint8_t exp_level,
-                         TokenRelay6::FieldType exp_type,
+                         TokenRelay6Field::FieldType exp_type,
                          int exp_tokens) {
         EvalContext eval(Option::V6);
 
@@ -251,9 +251,9 @@ public:
         // There should be the expected number of tokens.
         ASSERT_EQ(exp_tokens, eval.expression.size());
 
-        // checkt that the first token is TokenRelay6 and that
+        // checkt that the first token is TokenRelay6Field and that
         // is has the correct attributes
-        checkTokenRelay6(eval.expression.at(0), exp_level, exp_type);
+        checkTokenRelay6Field(eval.expression.at(0), exp_level, exp_type);
     }
 
     /// @brief checks if the given expression raises the expected message
@@ -711,13 +711,13 @@ TEST_F(EvalContextTest, relay6OptionHex) {
 // Tests if the linkaddr field in a Relay6 encapsulation can be accessed.
 TEST_F(EvalContextTest, relay6FieldLinkAddr) {
     testRelay6Field("relay6[0].linkaddr == ::",
-                    0, TokenRelay6::LINKADDR, 3);
+                    0, TokenRelay6Field::LINKADDR, 3);
 }
 
 // Tests if the peeraddr field in a Relay6 encapsulation can be accessed.
 TEST_F(EvalContextTest, relay6FieldPeerAddr) {
     testRelay6Field("relay6[1].peeraddr == ::",
-                    1, TokenRelay6::PEERADDR, 3);
+                    1, TokenRelay6Field::PEERADDR, 3);
 }
 
 //

+ 4 - 2
src/lib/eval/token.cc

@@ -311,7 +311,9 @@ OptionPtr TokenRelay6Option::getOption(const Pkt& pkt) {
         }
         catch (const isc::OutOfRange&) {
             // The only exception we expect is OutOfRange if the nest
-            // level is invalid.  We return a NULL in that case.
+            // level is out of range of the encapsulations, for example
+            // if nest_level_ is 4 and there are only 2 encapsulations.
+            // We return a NULL in that case.
            return (OptionPtr());
         }
 
@@ -322,7 +324,7 @@ OptionPtr TokenRelay6Option::getOption(const Pkt& pkt) {
 }
 
 void
-TokenRelay6::evaluate(const Pkt& pkt, ValueStack& values) {
+TokenRelay6Field::evaluate(const Pkt& pkt, ValueStack& values) {
 
     vector<uint8_t> binary;
     try {

+ 4 - 4
src/lib/eval/token.h

@@ -527,7 +527,7 @@ protected:
 /// set the field it may be 0s.
 ///
 /// The nesting level can go from 0 (closest to the server) to 31.
-class TokenRelay6 : public Token {
+class TokenRelay6Field : public Token {
 public:
 
     /// @brief enum value that determines the field.
@@ -541,7 +541,7 @@ public:
     ///
     /// @param nest_level the nesting level for which relay to examine.
     /// @param type which field to extract.
-    TokenRelay6(const uint8_t nest_level, const FieldType type)
+    TokenRelay6Field(const uint8_t nest_level, const FieldType type)
       : nest_level_(nest_level), type_(type) {}
 
     /// @brief Extracts the specified field from the requested relay
@@ -556,7 +556,7 @@ public:
     /// @brief Returns nest-level
     ///
     /// This method is used in testing to determine if the parser has
-    /// instantiated TokenRelay6 with correct parameters.
+    /// instantiated TokenRelay6Field with correct parameters.
     ///
     /// @return nest-level of the relay block this token expects to use
     /// for extraction.
@@ -567,7 +567,7 @@ public:
     /// @brief Returns field type
     ///
     /// This method is used only in testing to determine if the parser has
-    /// instantiated TokenRelay6 with correct parameters.
+    /// instantiated TokenRelay6Field with correct parameters.
     ///
     /// @return type of the field.
     FieldType getType() {