ComboAddress remote;
try {
for(counter = 0; counter < 100000; ++counter) {
- DNSName a=DNSName("hello ")+DNSName(std::to_string(counter));
+ DNSName a=DNSName(std::to_string(counter))+DNSName(" hello");
BOOST_CHECK_EQUAL(DNSName(a.toString()), a);
vector<uint8_t> query;
size_t deleted=0;
size_t delcounter=0;
for(delcounter=0; delcounter < counter/1000; ++delcounter) {
- DNSName a=DNSName("hello ")+DNSName(std::to_string(delcounter));
+ DNSName a=DNSName(std::to_string(delcounter))+DNSName(" hello");
vector<uint8_t> query;
DNSPacketWriter pwQ(query, a, QType::A, QClass::IN, 0);
pwQ.getHeader()->rd = 1;
}
BOOST_CHECK_EQUAL(PC.getSize(), counter - skipped - deleted);
+
size_t matches=0;
vector<DNSResourceRecord> entry;
size_t expected=counter-skipped-deleted;
for(; delcounter < counter; ++delcounter) {
- DNSName a(DNSName("hello ")+DNSName(std::to_string(delcounter)));
+ DNSName a(DNSName(std::to_string(delcounter))+DNSName(" hello"));
vector<uint8_t> query;
DNSPacketWriter pwQ(query, a, QType::A, QClass::IN, 0);
pwQ.getHeader()->rd = 1;
uint16_t responseSize = sizeof(response);
DNSQuestion dq(&a, QType::A, QClass::IN, &remote, &remote, (struct dnsheader*) query.data(), len, query.size(), false);
if(PC.get(dq, a.wirelength(), pwQ.getHeader()->id, response, &responseSize, &key)) {
- matches++;
+ matches++;
}
}
BOOST_CHECK_EQUAL(matches, expected);
+
+ PC.expungeByName(DNSName(" hello"), QType::ANY, true);
+ BOOST_CHECK_EQUAL(PC.getSize(), 0);
}
catch(PDNSException& e) {
cerr<<"Had error: "<<e.reason<<endl;
total += self._responsesCounter[key]
self.assertEquals(total, misses)
+ def testCacheExpungeByNameAndSuffix(self):
+ """
+ Cache: Expunge by name
+
+ """
+ misses = 0
+ ttl = 600
+ name = 'expungebyname.suffix.cache.tests.powerdns.com.'
+ query = dns.message.make_query(name, 'A', 'IN')
+ response = dns.message.make_response(query)
+ rrset = dns.rrset.from_text(name,
+ ttl,
+ dns.rdataclass.IN,
+ dns.rdatatype.A,
+ '127.0.0.1')
+ response.answer.append(rrset)
+
+ name2 = 'expungebyname.suffixother.cache.tests.powerdns.com.'
+ query2 = dns.message.make_query(name2, 'A', 'IN')
+ response2 = dns.message.make_response(query2)
+ rrset2 = dns.rrset.from_text(name2,
+ ttl,
+ dns.rdataclass.IN,
+ dns.rdatatype.A,
+ '127.0.0.1')
+ response2.answer.append(rrset2)
+
+ # Miss
+ (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+ self.assertTrue(receivedQuery)
+ self.assertTrue(receivedResponse)
+ receivedQuery.id = query.id
+ self.assertEquals(query, receivedQuery)
+ self.assertEquals(response, receivedResponse)
+ misses += 1
+
+ # next queries should hit the cache
+ (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response)
+
+ # cache another entry
+ (receivedQuery, receivedResponse) = self.sendUDPQuery(query2, response2)
+ self.assertTrue(receivedQuery)
+ self.assertTrue(receivedResponse)
+ receivedQuery.id = query2.id
+ self.assertEquals(query2, receivedQuery)
+ self.assertEquals(response2, receivedResponse)
+ misses += 1
+
+ # queries for name and name 2 should hit the cache
+ (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response)
+
+ (_, receivedResponse) = self.sendUDPQuery(query2, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response2)
+
+ # remove cached entries from name
+ self.sendConsoleCommand("getPool(\"\"):getCache():expungeByName(newDNSName(\"suffix.cache.tests.powerdns.com.\"), dnsdist.ANY, true)")
+
+ # Miss for name
+ (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+ self.assertTrue(receivedQuery)
+ self.assertTrue(receivedResponse)
+ receivedQuery.id = query.id
+ self.assertEquals(query, receivedQuery)
+ self.assertEquals(response, receivedResponse)
+ misses += 1
+
+ # next queries for name should hit the cache again
+ (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response)
+
+ # queries for name2 should still hit the cache
+ (_, receivedResponse) = self.sendUDPQuery(query2, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response2)
+
+ total = 0
+ for key in self._responsesCounter:
+ total += self._responsesCounter[key]
+
+ self.assertEquals(total, misses)
+
+ def testCacheExpungeByNameAndTypeAndSuffix(self):
+ """
+ Cache: Expunge by name and type
+
+ """
+ misses = 0
+ ttl = 600
+ name = 'expungebynameandtype.suffixtype.cache.tests.powerdns.com.'
+ query = dns.message.make_query(name, 'A', 'IN')
+ response = dns.message.make_response(query)
+ rrset = dns.rrset.from_text(name,
+ ttl,
+ dns.rdataclass.IN,
+ dns.rdatatype.A,
+ '127.0.0.1')
+ response.answer.append(rrset)
+
+ query2 = dns.message.make_query(name, 'AAAA', 'IN')
+ response2 = dns.message.make_response(query2)
+ rrset2 = dns.rrset.from_text(name,
+ ttl,
+ dns.rdataclass.IN,
+ dns.rdatatype.AAAA,
+ '::1')
+ response2.answer.append(rrset2)
+
+ # Miss
+ (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+ self.assertTrue(receivedQuery)
+ self.assertTrue(receivedResponse)
+ receivedQuery.id = query.id
+ self.assertEquals(query, receivedQuery)
+ self.assertEquals(response, receivedResponse)
+ misses += 1
+
+ # next queries should hit the cache
+ (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response)
+
+ # cache another entry
+ (receivedQuery, receivedResponse) = self.sendUDPQuery(query2, response2)
+ self.assertTrue(receivedQuery)
+ self.assertTrue(receivedResponse)
+ receivedQuery.id = query2.id
+ self.assertEquals(query2, receivedQuery)
+ self.assertEquals(response2, receivedResponse)
+ misses += 1
+
+ # queries for name A and AAAA should hit the cache
+ (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response)
+
+ (_, receivedResponse) = self.sendUDPQuery(query2, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response2)
+
+ # remove cached entries from name A
+ self.sendConsoleCommand("getPool(\"\"):getCache():expungeByName(newDNSName(\"suffixtype.cache.tests.powerdns.com.\"), dnsdist.A, true)")
+
+ # Miss for name A
+ (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response)
+ self.assertTrue(receivedQuery)
+ self.assertTrue(receivedResponse)
+ receivedQuery.id = query.id
+ self.assertEquals(query, receivedQuery)
+ self.assertEquals(response, receivedResponse)
+ misses += 1
+
+ # next queries for name A should hit the cache again
+ (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response)
+
+ # queries for name AAAA should still hit the cache
+ (_, receivedResponse) = self.sendUDPQuery(query2, response=None, useQueue=False)
+ self.assertEquals(receivedResponse, response2)
+
+ total = 0
+ for key in self._responsesCounter:
+ total += self._responsesCounter[key]
+ self.assertEquals(total, misses)
+
class TestCachingTTL(DNSDistTest):
_maxCacheTTL = 86400