New tests, passed.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/597c21e2 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/597c21e2 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/597c21e2 Branch: refs/heads/master Commit: 597c21e29535eeb1eaf8057e003c499309f5987e Parents: fcd092c Author: Alan M. Carroll <[email protected]> Authored: Tue Mar 20 12:33:29 2012 -0500 Committer: Alan M. Carroll <[email protected]> Committed: Tue Mar 20 12:33:29 2012 -0500 ---------------------------------------------------------------------- lib/ts/IpMap.cc | 87 ++++++++++++++++++++++------------------------ lib/ts/IpMapTest.cc | 38 ++++++++++++++++---- 2 files changed, 73 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/597c21e2/lib/ts/IpMap.cc ---------------------------------------------------------------------- diff --git a/lib/ts/IpMap.cc b/lib/ts/IpMap.cc index 14ce6ab..cfb0791 100644 --- a/lib/ts/IpMap.cc +++ b/lib/ts/IpMap.cc @@ -514,49 +514,48 @@ inline int cmp(sockaddr_in6 const& lhs, sockaddr_in6 const& rhs) { /// Less than. inline bool operator<(sockaddr_in6 const& lhs, sockaddr_in6 const& rhs) { - return -1 == ts::detail::cmp(lhs, rhs); + return ts::detail::cmp(lhs, rhs) < 0; } inline bool operator<(sockaddr_in6 const* lhs, sockaddr_in6 const& rhs) { - return -1 == ts::detail::cmp(*lhs, rhs); + return ts::detail::cmp(*lhs, rhs) < 0; } /// Less than. inline bool operator<(sockaddr_in6 const& lhs, sockaddr_in6 const* rhs) { - return -1 == ts::detail::cmp(lhs, *rhs); + return ts::detail::cmp(lhs, *rhs) < 0; } /// Equality. inline bool operator==(sockaddr_in6 const& lhs, sockaddr_in6 const* rhs) { - return 0 == ts::detail::cmp(lhs, *rhs); + return ts::detail::cmp(lhs, *rhs) == 0; } /// Equality. inline bool operator==(sockaddr_in6 const* lhs, sockaddr_in6 const& rhs) { - return 0 == ts::detail::cmp(*lhs, rhs); + return ts::detail::cmp(*lhs, rhs) == 0; } /// Equality. inline bool operator==(sockaddr_in6 const& lhs, sockaddr_in6 const& rhs) { - return 0 == ts::detail::cmp(lhs, rhs); + return ts::detail::cmp(lhs, rhs) == 0; } /// Less than or equal. inline bool operator<=(sockaddr_in6 const& lhs, sockaddr_in6 const* rhs) { - return 1 != ts::detail::cmp(lhs, *rhs); + return ts::detail::cmp(lhs, *rhs) <= 0; } /// Less than or equal. inline bool operator<=(sockaddr_in6 const& lhs, sockaddr_in6 const& rhs) { - return 1 != ts::detail::cmp(lhs, rhs); + return ts::detail::cmp(lhs, rhs) <= 0; } /// Greater than or equal. inline bool operator>=(sockaddr_in6 const& lhs, sockaddr_in6 const& rhs) { - return -1 != ts::detail::cmp(lhs, rhs); + return ts::detail::cmp(lhs, rhs) >= 0; } /// Greater than or equal. inline bool operator>=(sockaddr_in6 const& lhs, sockaddr_in6 const* rhs) { - return -1 != ts::detail::cmp(lhs, *rhs); + return ts::detail::cmp(lhs, *rhs) >= 0; } /// Greater than. inline bool operator>(sockaddr_in6 const& lhs, sockaddr_in6 const* rhs) { - return 1 == ts::detail::cmp(lhs, *rhs); + return ts::detail::cmp(lhs, *rhs) > 0; } - template < typename N > N* IpMapBase<N>::lowerBound(ArgType target) { N* n = _root; // current node to test. @@ -598,25 +597,21 @@ IpMapBase<N>::fill(ArgType rmin, ArgType rmax, void* payload) { // Handle cases involving a node of interest to the left of the // range. if (n) { - Metric min_1; - /* Tricky bit here when min is zero and we can't decrement it. If - it's strictly greater than the node min then it's not zero and - we can check against a decremented value. Moreover, if the node - min isn't less than the range min the node max isn't less - than range min - 1. - */ - if (n->_min < min && (min_1 = min, N::dec(min_1), n->_max < min_1)) { - // no overlap, move on to next node. - n = next(n); - } else if (n->_max >= max) { // incoming range is covered, just discard. - return *this; - } else if (n->_data != payload) { // different payload, clip range on left. - min = n->_max; - N::inc(min); - n = next(n); - } else { // skew overlap with same payload, use node and continue. - x = n; - n = next(n); + if (n->_min < min) { + Metric min_1 = min; + N::dec(min_1); // dec is OK because min isn't zero. + if (n->_max < min_1) { // no overlap or adj. + n = next(n); + } else if (n->_max >= max) { // incoming range is covered, just discard. + return *this; + } else if (n->_data != payload) { // different payload, clip range on left. + min = n->_max; + N::inc(min); + n = next(n); + } else { // skew overlap with same payload, use node and continue. + x = n; + n = next(n); + } } } else { n = this->getHead(); @@ -655,7 +650,7 @@ IpMapBase<N>::fill(ArgType rmin, ArgType rmax, void* payload) { } else { // not carrying a span. if (n->_max <= max) { // next range is covered - use it. x = n; - n->setMin(min); + x->setMin(min); n = next(n); } else if (n->_min <= max_plus1) { n->setMin(min); @@ -677,23 +672,25 @@ IpMapBase<N>::fill(ArgType rmin, ArgType rmax, void* payload) { x->setMaxMinusOne(n->_min); x = 0; min = n->_max; - N::inc(min); + N::inc(min); // OK because n->_max maximal => next is null. n = next(n); } - } else { + } else { // no carry node. if (max < n->_min) { // entirely before next span. this->insertBefore(n, new N(min, max, payload)); - return *this; // done - } else if (min < n->_min) { - // overlap on the right, so make a span to take up the slack. - N* y = new N(min, n->_min, payload); - y->decrementMax(); - this->insertBefore(n, y); + return *this; + } else { + if (min < n->_min) { // leading section, need node. + N* y = new N(min, n->_min, payload); + y->decrementMax(); + this->insertBefore(n, y); + } + if (max <= n->_max) // nothing past node + return *this; + min = n->_max; + N::inc(min); + n = next(n); } - if (max <= n->_max) return *this; - min = n->_max; - N::inc(min); - n = next(n); } } } @@ -815,7 +812,7 @@ IpMapBase<N>::mark(ArgType min, ArgType max, void* payload) { this->remove(y); } else if (max_plus < n->_min) { // no overlap, done. break; - } else if (n->_data == payload) { // skew overlap same payload + } else if (n->_data == payload) { // skew overlap or adj., same payload x->setMax(n->_max); y = n; n = next(n); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/597c21e2/lib/ts/IpMapTest.cc ---------------------------------------------------------------------- diff --git a/lib/ts/IpMapTest.cc b/lib/ts/IpMapTest.cc index 34a0bfb..78a25c9 100644 --- a/lib/ts/IpMapTest.cc +++ b/lib/ts/IpMapTest.cc @@ -151,7 +151,6 @@ REGRESSION_TEST(IpMap_Unmark)(RegressionTest* t, int atype, int* pstatus) { tb.check(!map.contains(&a_0), "IpMap Unmark: Range unmark zero address not removed."); tb.check(!map.contains(&a_0_0_0_16), "IpMap Unmark: Range unmark zero bounded range max not removed."); tb.check(map.contains(&a_0_0_0_17), "IpMap Unmark: Range unmark zero bounded range max+1 removed."); - IpMapTestPrint(map); } REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int atype, int* pstatus) { @@ -162,7 +161,7 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int atype, int* pstatus) { void* const deny = reinterpret_cast<void*>(~0); void* const markA = reinterpret_cast<void*>(1); void* const markB = reinterpret_cast<void*>(2); -// void* const markC = reinterpret_cast<void*>(3); + void* const markC = reinterpret_cast<void*>(3); void* mark; // for retrieval IpEndpoint a0,a_10_28_56_0,a_10_28_56_255,a3,a4; @@ -170,7 +169,7 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int atype, int* pstatus) { IpEndpoint a_10_28_55_255, a_10_28_57_0; IpEndpoint a_63_128_1_12; IpEndpoint a_0000_0000, a_0000_0001, a_ffff_ffff; - IpEndpoint a_fe80_9d89, a_fe80_9d90, a_fe80_9d95, a_fe80_9d9d, a_fe80_9d9e; + IpEndpoint a_fe80_9d8f, a_fe80_9d90, a_fe80_9d95, a_fe80_9d9d, a_fe80_9d9e; *pstatus = REGRESSION_TEST_PASSED; @@ -189,7 +188,7 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int atype, int* pstatus) { ats_ip_pton("::", &a_0000_0000); ats_ip_pton("::1", &a_0000_0001); ats_ip_pton("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", &a_ffff_ffff); - ats_ip_pton("fe80::221:9bff:fe10:9d89", &a_fe80_9d89); + ats_ip_pton("fe80::221:9bff:fe10:9d8f", &a_fe80_9d8f); ats_ip_pton("fe80::221:9bff:fe10:9d90", &a_fe80_9d90); ats_ip_pton("fe80::221:9bff:fe10:9d95", &a_fe80_9d95); ats_ip_pton("fe80::221:9bff:fe10:9d9d", &a_fe80_9d9d); @@ -239,8 +238,8 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int atype, int* pstatus) { "IpMap Fill[v6]: Max address has bad mark."); tb.check(map.contains(&a_fe80_9d90, &mark) && mark == markA, "IpMap Fill[v6]: 9d90 address has bad mark."); - tb.check(map.contains(&a_fe80_9d89, &mark) && mark == markB, - "IpMap Fill[v6]: 9d89 address has bad mark."); + tb.check(map.contains(&a_fe80_9d8f, &mark) && mark == markB, + "IpMap Fill[v6]: 9d8f address has bad mark."); tb.check(map.contains(&a_fe80_9d9d, &mark) && mark == markA, "IpMap Fill[v6]: 9d9d address has bad mark."); tb.check(map.contains(&a_fe80_9d9e, &mark) && mark == markB, @@ -248,5 +247,30 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int atype, int* pstatus) { tb.check(map.contains(&a_0000_0001, &mark) && mark == markA, "IpMap Fill[v6]: ::1 has bad mark."); - IpMapTestPrint(map); + tb.check(map.getCount() == 10, "IpMap Fill[pre-refill]: Bad range count."); + // These should be ignored by the map as it is completely covered for IPv6. + map.fill(&a_fe80_9d90, &a_fe80_9d9d, markA); + map.fill(&a_0000_0001, &a_0000_0001, markC); + map.fill(&a_0000_0000, &a_ffff_ffff, markB); + tb.check(map.getCount() == 10, "IpMap Fill[post-refill]: Bad range count."); + + map.clear(); + map.fill(&a_fe80_9d90, &a_fe80_9d9d, markA); + map.fill(&a_0000_0001, &a_0000_0001, markC); + map.fill(&a_0000_0000, &a_ffff_ffff, markB); + tb.check(map.contains(&a_0000_0000, &mark) && mark == markB, + "IpMap Fill[v6-2]: Zero address has bad mark."); + tb.check(map.contains(&a_ffff_ffff, &mark) && mark == markB, + "IpMap Fill[v6-2]: Max address has bad mark."); + tb.check(map.contains(&a_fe80_9d90, &mark) && mark == markA, + "IpMap Fill[v6-2]: 9d90 address has bad mark."); + tb.check(map.contains(&a_fe80_9d8f, &mark) && mark == markB, + "IpMap Fill[v6-2]: 9d8f address has bad mark."); + tb.check(map.contains(&a_fe80_9d9d, &mark) && mark == markA, + "IpMap Fill[v6-2]: 9d9d address has bad mark."); + tb.check(map.contains(&a_fe80_9d9e, &mark) && mark == markB, + "IpMap Fill[v6-2]: 9d9b address has bad mark."); + tb.check(map.contains(&a_0000_0001, &mark) && mark == markC, + "IpMap Fill[v6-2]: ::1 has bad mark."); + }
