Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Adam Osuchowski
Kea
Commits
7793f98f
Commit
7793f98f
authored
Nov 29, 2012
by
Tomek Mrugalski
🛰
Browse files
[2325] Dhcpv6Srv::serverReceivedPacketName() -> Pkt6::getName()
parent
fa4d217e
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp6/dhcp6_srv.cc
View file @
7793f98f
...
...
@@ -126,7 +126,7 @@ bool Dhcpv6Srv::run() {
continue
;
}
LOG_DEBUG
(
dhcp6_logger
,
DBG_DHCP6_DETAIL
,
DHCP6_PACKET_RECEIVED
)
.
arg
(
serverReceivedPacketName
(
query
->
get
Typ
e
())
)
;
.
arg
(
query
->
get
Nam
e
());
LOG_DEBUG
(
dhcp6_logger
,
DBG_DHCP6_DETAIL_DATA
,
DHCP6_QUERY_DATA
)
.
arg
(
static_cast
<
int
>
(
query
->
getType
()))
.
arg
(
query
->
getBuffer
().
getLength
())
...
...
@@ -573,48 +573,5 @@ Pkt6Ptr Dhcpv6Srv::processInfRequest(const Pkt6Ptr& infRequest) {
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
);
}
};
};
src/bin/dhcp6/dhcp6_srv.h
View file @
7793f98f
...
...
@@ -83,23 +83,6 @@ public:
/// @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.
///
...
...
src/bin/dhcp6/tests/dhcp6_srv_unittest.cc
View file @
7793f98f
...
...
@@ -749,52 +749,6 @@ TEST_F(Dhcpv6SrvTest, ManyRequests) {
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
;
...
...
src/lib/dhcp/pkt6.cc
View file @
7793f98f
...
...
@@ -205,6 +205,52 @@ Pkt6::updateTimestamp() {
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
src/lib/dhcp/pkt6.h
View file @
7793f98f
...
...
@@ -127,7 +127,7 @@ public:
/// 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)
///
...
...
@@ -266,6 +266,34 @@ public:
/// @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.
///
...
...
src/lib/dhcp/tests/pkt6_unittest.cc
View file @
7793f98f
...
...
@@ -234,4 +234,52 @@ TEST_F(Pkt6Test, Timestamp) {
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
));
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment