continue;
}
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL, DHCP6_PACKET_RECEIVED)
- .arg(serverReceivedPacketName(query->getType()));
+ .arg(query->getName());
LOG_DEBUG(dhcp6_logger, DBG_DHCP6_DETAIL_DATA, DHCP6_QUERY_DATA)
.arg(static_cast<int>(query->getType()))
.arg(query->getBuffer().getLength())
return reply;
}
-const char*
-Dhcpv6Srv::serverReceivedPacketName(uint8_t type) {
- static const char* CONFIRM = "CONFIRM";
- static const char* DECLINE = "DECLINE";
- static const char* INFORMATION_REQUEST = "INFORMATION_REQUEST";
- static const char* REBIND = "REBIND";
- static const char* RELEASE = "RELEASE";
- static const char* RENEW = "RENEW";
- static const char* REQUEST = "REQUEST";
- static const char* SOLICIT = "SOLICIT";
- static const char* UNKNOWN = "UNKNOWN";
-
- switch (type) {
- case DHCPV6_CONFIRM:
- return (CONFIRM);
-
- case DHCPV6_DECLINE:
- return (DECLINE);
-
- case DHCPV6_INFORMATION_REQUEST:
- return (INFORMATION_REQUEST);
-
- case DHCPV6_REBIND:
- return (REBIND);
-
- case DHCPV6_RELEASE:
- return (RELEASE);
-
- case DHCPV6_RENEW:
- return (RENEW);
-
- case DHCPV6_REQUEST:
- return (REQUEST);
-
- case DHCPV6_SOLICIT:
- return (SOLICIT);
-
- default:
- ;
- }
- return (UNKNOWN);
-}
-
};
};
/// @brief Instructs the server to shut down.
void shutdown();
- /// @brief Return textual type of packet received by server.
- ///
- /// Returns the name of valid packet received by the server (e.g. SOLICIT).
- /// If the packet is unknown - or if it is a valid DHCP packet but not one
- /// expected to be received by the server (such as an ADVERTISE), the string
- /// "UNKNOWN" is returned. This method is used in debug messages.
- ///
- /// As the operation of the method does not depend on any server state, it
- /// is declared static.
- ///
- /// @param type DHCPv4 packet type
- ///
- /// @return Pointer to "const" string containing the packet name.
- /// Note that this string is statically allocated and MUST NOT
- /// be freed by the caller.
- static const char* serverReceivedPacketName(uint8_t type);
-
protected:
/// @brief Processes incoming SOLICIT and returns response.
///
cout << "Assigned address to client3=" << addr3->getAddress().toText() << endl;
}
-
-TEST_F(Dhcpv6SrvTest, serverReceivedPacketName) {
- // Check all possible packet types
- for (int itype = 0; itype < 256; ++itype) {
- uint8_t type = itype;
-
- switch (type) {
- case DHCPV6_CONFIRM:
- EXPECT_STREQ("CONFIRM", Dhcpv6Srv::serverReceivedPacketName(type));
- break;
-
- case DHCPV6_DECLINE:
- EXPECT_STREQ("DECLINE", Dhcpv6Srv::serverReceivedPacketName(type));
- break;
-
- case DHCPV6_INFORMATION_REQUEST:
- EXPECT_STREQ("INFORMATION_REQUEST",
- Dhcpv6Srv::serverReceivedPacketName(type));
- break;
-
- case DHCPV6_REBIND:
- EXPECT_STREQ("REBIND", Dhcpv6Srv::serverReceivedPacketName(type));
- break;
-
- case DHCPV6_RELEASE:
- EXPECT_STREQ("RELEASE", Dhcpv6Srv::serverReceivedPacketName(type));
- break;
-
- case DHCPV6_RENEW:
- EXPECT_STREQ("RENEW", Dhcpv6Srv::serverReceivedPacketName(type));
- break;
-
- case DHCPV6_REQUEST:
- EXPECT_STREQ("REQUEST", Dhcpv6Srv::serverReceivedPacketName(type));
- break;
-
- case DHCPV6_SOLICIT:
- EXPECT_STREQ("SOLICIT", Dhcpv6Srv::serverReceivedPacketName(type));
- break;
-
- default:
- EXPECT_STREQ("UNKNOWN", Dhcpv6Srv::serverReceivedPacketName(type));
- }
- }
-}
-
// This test verifies if the status code option is generated properly.
TEST_F(Dhcpv6SrvTest, StatusCode) {
boost::scoped_ptr<NakedDhcpv6Srv> srv;
timestamp_ = boost::posix_time::microsec_clock::universal_time();
}
+const char*
+Pkt6::getName(uint8_t type) {
+ static const char* CONFIRM = "CONFIRM";
+ static const char* DECLINE = "DECLINE";
+ static const char* INFORMATION_REQUEST = "INFORMATION_REQUEST";
+ static const char* REBIND = "REBIND";
+ static const char* RELEASE = "RELEASE";
+ static const char* RENEW = "RENEW";
+ static const char* REQUEST = "REQUEST";
+ static const char* SOLICIT = "SOLICIT";
+ static const char* UNKNOWN = "UNKNOWN";
+
+ switch (type) {
+ case DHCPV6_CONFIRM:
+ return (CONFIRM);
+
+ case DHCPV6_DECLINE:
+ return (DECLINE);
+
+ case DHCPV6_INFORMATION_REQUEST:
+ return (INFORMATION_REQUEST);
+
+ case DHCPV6_REBIND:
+ return (REBIND);
+
+ case DHCPV6_RELEASE:
+ return (RELEASE);
+
+ case DHCPV6_RENEW:
+ return (RENEW);
+
+ case DHCPV6_REQUEST:
+ return (REQUEST);
+
+ case DHCPV6_SOLICIT:
+ return (SOLICIT);
+
+ default:
+ ;
+ }
+ return (UNKNOWN);
+}
+
+const char* Pkt6::getName() const {
+ return (getName(getType()));
+}
} // end of isc::dhcp namespace
} // end of isc namespace
/// Returns message type (e.g. 1 = SOLICIT)
///
/// @return message type
- uint8_t getType() { return (msg_type_); }
+ uint8_t getType() const { return (msg_type_); }
/// Sets message type (e.g. 1 = SOLICIT)
///
/// @throw isc::Unexpected if timestamp update failed
void updateTimestamp();
+ /// @brief Return textual type of packet.
+ ///
+ /// Returns the name of valid packet received by the server (e.g. SOLICIT).
+ /// If the packet is unknown - or if it is a valid DHCP packet but not one
+ /// expected to be received by the server (such as an ADVERTISE), the string
+ /// "UNKNOWN" is returned. This method is used in debug messages.
+ ///
+ /// As the operation of the method does not depend on any server state, it
+ /// is declared static. There is also non-static getName() method that
+ /// works on Pkt6 objects.
+ ///
+ /// @param type DHCPv6 packet type
+ ///
+ /// @return Pointer to "const" string containing the packet name.
+ /// Note that this string is statically allocated and MUST NOT
+ /// be freed by the caller.
+ static const char* getName(uint8_t type);
+
+ /// @brief returns textual representation of packet type.
+ ///
+ /// This method requires an object. There is also static version, which
+ /// requires one parameter (type).
+ ///
+ /// @return Pointer to "const" string containing packet name.
+ /// Note that this string is statically allocated and MUST NOT
+ /// be freed by the caller.
+ const char* getName() const;
+
protected:
/// Builds on wire packet for TCP transmission.
///
EXPECT_TRUE(ts_period.length().total_microseconds() >= 0);
}
+// This test verifies that getName() method returns proper
+// packet type names.
+TEST_F(Pkt6Test, getName) {
+ // Check all possible packet types
+ for (int itype = 0; itype < 256; ++itype) {
+ uint8_t type = itype;
+
+ switch (type) {
+ case DHCPV6_CONFIRM:
+ EXPECT_STREQ("CONFIRM", Pkt6::getName(type));
+ break;
+
+ case DHCPV6_DECLINE:
+ EXPECT_STREQ("DECLINE", Pkt6::getName(type));
+ break;
+
+ case DHCPV6_INFORMATION_REQUEST:
+ EXPECT_STREQ("INFORMATION_REQUEST",
+ Pkt6::getName(type));
+ break;
+
+ case DHCPV6_REBIND:
+ EXPECT_STREQ("REBIND", Pkt6::getName(type));
+ break;
+
+ case DHCPV6_RELEASE:
+ EXPECT_STREQ("RELEASE", Pkt6::getName(type));
+ break;
+
+ case DHCPV6_RENEW:
+ EXPECT_STREQ("RENEW", Pkt6::getName(type));
+ break;
+
+ case DHCPV6_REQUEST:
+ EXPECT_STREQ("REQUEST", Pkt6::getName(type));
+ break;
+
+ case DHCPV6_SOLICIT:
+ EXPECT_STREQ("SOLICIT", Pkt6::getName(type));
+ break;
+
+ default:
+ EXPECT_STREQ("UNKNOWN", Pkt6::getName(type));
+ }
+ }
+}
+
+
}