Commit 068ecfa5 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2098] copy getAbsoluteLabels() from rbtree with trivial modifications.

we need to it for TreeNodeRRset::toWire() (actually this method was
introduced exactly for that purpose).
parent 2c34181a
......@@ -226,6 +226,26 @@ public:
return (dns::LabelSequence(getLabelsData()));
}
/// \brief Return the absolute label sequence of the node.
///
/// This method returns the label sequence corresponding to the full
/// name of the node; i.e. the entire name as it appears in the zone.
///
/// It takes the (partial) name of the node itself, and extends it
/// with all upper nodes.
///
/// \note Care must be taken with the buffer that is used here; this
/// method overwrites its data, so it should not be associated with
/// any other LabelSequence during the lifetime of the LabelSequence
/// returned by this method. See LabelSequence::extend(), which is used
/// by this method.
///
/// \param buf A data buffer where the label sequence will be built.
/// The data in this buffer will be overwritten by this call.
/// \return A LabelSequence with the absolute name of this node.
isc::dns::LabelSequence getAbsoluteLabels(
uint8_t buf[isc::dns::LabelSequence::MAX_SERIALIZED_LENGTH]) const;
/// \brief Return the data stored in this node.
///
/// You should not delete the data, it is deleted when the tree is
......@@ -530,6 +550,21 @@ DomainTreeNode<T>::getUpperNode() const {
return (current->getParent());
}
template <typename T, typename DT>
isc::dns::LabelSequence
DomainTreeNode<T, DT>::getAbsoluteLabels(
uint8_t buf[isc::dns::LabelSequence::MAX_SERIALIZED_LENGTH]) const
{
isc::dns::LabelSequence result(getLabels(), buf);
const DomainTreeNode<T, DT>* upper = getUpperNode();
while (upper != NULL) {
result.extend(upper->getLabels(), buf);
upper = upper->getUpperNode();
}
return (result);
}
template <typename T>
const DomainTreeNode<T>*
DomainTreeNode<T>::abstractSuccessor(
......
......@@ -114,6 +114,7 @@ protected:
TestDomainTree& dtree_expose_empty_node;
TestDomainTreeNode* dtnode;
const TestDomainTreeNode* cdtnode;
uint8_t buf[LabelSequence::MAX_SERIALIZED_LENGTH];
};
TEST_F(DomainTreeTest, nodeCount) {
......@@ -470,6 +471,11 @@ TEST_F(DomainTreeTest, chainLevel) {
tree.find(node_name, &cdtnode, chain));
EXPECT_EQ(1, chain.getLevelCount());
// Check the name of the found node (should have '.' as both non-absolute
// and absolute name
EXPECT_EQ(".", cdtnode->getLabels().toText());
EXPECT_EQ(".", cdtnode->getAbsoluteLabels(buf).toText());
/*
* Now creating a possibly deepest tree with MAX_LABELS levels.
* it should look like:
......@@ -493,6 +499,12 @@ TEST_F(DomainTreeTest, chainLevel) {
EXPECT_EQ(TestDomainTree::EXACTMATCH,
tree.find(node_name, &cdtnode, found_chain));
EXPECT_EQ(i, found_chain.getLevelCount());
// The non-absolute name should only have the first label
EXPECT_EQ("a", cdtnode->getLabels().toText());
// But the absolute name should have all labels
EXPECT_EQ(node_name.toText(),
cdtnode->getAbsoluteLabels(buf).toText());
}
// Confirm the last inserted name has the possible maximum length with
......@@ -1039,4 +1051,44 @@ TEST_F(DomainTreeTest, root) {
root.find(Name("example.com"), &cdtnode));
EXPECT_EQ(dtnode, cdtnode);
}
TEST_F(DomainTreeTest, getAbsoluteLabels) {
// The full absolute names of the nodes in the tree
// with the addition of the explicit root node
const char* const domain_names[] = {
"c", "b", "a", "x.d.e.f", "z.d.e.f", "g.h", "i.g.h", "o.w.y.d.e.f",
"j.z.d.e.f", "p.w.y.d.e.f", "q.w.y.d.e.f", "k.g.h"};
// The names of the nodes themselves, as they end up in the tree
const char* const first_labels[] = {
"c", "b", "a", "x", "z", "g.h", "i", "o",
"j", "p", "q", "k"};
const int name_count = sizeof(domain_names) / sizeof(domain_names[0]);
for (int i = 0; i < name_count; ++i) {
EXPECT_EQ(TestDomainTree::EXACTMATCH, dtree.find(Name(domain_names[i]),
&cdtnode));
// First make sure the names themselves are not absolute
const LabelSequence ls(cdtnode->getLabels());
EXPECT_EQ(first_labels[i], ls.toText());
EXPECT_FALSE(ls.isAbsolute());
// Now check the absolute names
const LabelSequence abs_ls(cdtnode->getAbsoluteLabels(buf));
EXPECT_EQ(Name(domain_names[i]).toText(), abs_ls.toText());
EXPECT_TRUE(abs_ls.isAbsolute());
}
// Explicitly add and find a root node, to see that getAbsoluteLabels
// also works when getLabels() already returns an absolute LabelSequence
dtree.insert(mem_sgmt_, Name("."), &dtnode);
dtnode->setData(mem_sgmt_, new int(1));
EXPECT_EQ(TestDomainTree::EXACTMATCH, dtree.find(Name("."), &cdtnode));
EXPECT_TRUE(cdtnode->getLabels().isAbsolute());
EXPECT_EQ(".", cdtnode->getLabels().toText());
EXPECT_TRUE(cdtnode->getAbsoluteLabels(buf).isAbsolute());
EXPECT_EQ(".", cdtnode->getAbsoluteLabels(buf).toText());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment