Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
23d08556
Commit
23d08556
authored
Oct 30, 2012
by
Tomek Mrugalski
🛰
Browse files
[2414] toText() and get() implemented in Subnet
parent
fdcffb79
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dhcp/subnet.cc
View file @
23d08556
...
...
@@ -15,6 +15,7 @@
#include
<dhcp/addr_utilities.h>
#include
<asiolink/io_address.h>
#include
<dhcp/subnet.h>
#include
<sstream>
using
namespace
isc
::
asiolink
;
...
...
@@ -52,6 +53,12 @@ Subnet::delOptions() {
options_
.
clear
();
}
std
::
string
Subnet
::
toText
()
{
std
::
stringstream
tmp
;
tmp
<<
prefix_
.
toText
()
<<
"/"
<<
static_cast
<
unsigned
int
>
(
prefix_len_
);
return
(
tmp
.
str
());
}
Subnet4
::
Subnet4
(
const
isc
::
asiolink
::
IOAddress
&
prefix
,
uint8_t
length
,
const
Triplet
<
uint32_t
>&
t1
,
const
Triplet
<
uint32_t
>&
t2
,
...
...
src/lib/dhcp/subnet.h
View file @
23d08556
...
...
@@ -279,6 +279,12 @@ public:
/// @return unique ID for that subnet
SubnetID
getID
()
const
{
return
(
id_
);
}
std
::
pair
<
isc
::
asiolink
::
IOAddress
,
uint8_t
>
get
()
{
return
(
std
::
pair
<
isc
::
asiolink
::
IOAddress
,
uint8_t
>
(
prefix_
,
prefix_len_
));
}
virtual
std
::
string
toText
();
protected:
/// @brief protected constructor
//
...
...
src/lib/dhcp/tests/subnet_unittest.cc
View file @
23d08556
...
...
@@ -158,6 +158,19 @@ TEST(Subnet4Test, inRangeinPool) {
EXPECT_FALSE
(
subnet
->
inPool
(
IOAddress
(
"192.3.0.0"
)));
}
// This test checks if the toText() method returns text representation
TEST
(
Subnet4Test
,
toText
)
{
Subnet4Ptr
subnet
(
new
Subnet4
(
IOAddress
(
"192.0.2.0"
),
24
,
1
,
2
,
3
));
EXPECT_EQ
(
"192.0.2.0/24"
,
subnet
->
toText
());
}
// This test checks if the get() method returns proper parameters
TEST
(
Subnet4Test
,
get
)
{
Subnet4Ptr
subnet
(
new
Subnet4
(
IOAddress
(
"192.0.2.0"
),
28
,
1
,
2
,
3
));
EXPECT_EQ
(
"192.0.2.0"
,
subnet
->
get
().
first
.
toText
());
EXPECT_EQ
(
28
,
subnet
->
get
().
second
);
}
// Tests for Subnet6
TEST
(
Subnet6Test
,
constructor
)
{
...
...
@@ -418,4 +431,17 @@ TEST(Subnet6Test, inRangeinPool) {
EXPECT_FALSE
(
subnet
->
inPool
(
IOAddress
(
"2001:db8::21"
)));
}
// This test checks if the toText() method returns text representation
TEST
(
Subnet6Test
,
toText
)
{
Subnet6Ptr
subnet
(
new
Subnet6
(
IOAddress
(
"2001:db8::"
),
32
,
1
,
2
,
3
,
4
));
EXPECT_EQ
(
"2001:db8::/32"
,
subnet
->
toText
());
}
// This test checks if the get() method returns proper parameters
TEST
(
Subnet6Test
,
get
)
{
Subnet6Ptr
subnet
(
new
Subnet6
(
IOAddress
(
"2001:db8::"
),
32
,
1
,
2
,
3
,
4
));
EXPECT_EQ
(
"2001:db8::"
,
subnet
->
get
().
first
.
toText
());
EXPECT_EQ
(
32
,
subnet
->
get
().
second
);
}
};
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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