libDwm-0.9.45
DwmIpv4Routes.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 1999-2005, 2016, 2024
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
39//---------------------------------------------------------------------------
40
41#ifndef _DWMIPV4ROUTES_HH_
42#define _DWMIPV4ROUTES_HH_
43
44#include <algorithm>
45#include <cassert>
46#include <future>
47#include <unordered_map>
48
49#include "DwmPortability.hh"
50#include "DwmBZ2IO.hh"
51#include "DwmDescriptorIO.hh"
52#include "DwmFileIO.hh"
53#include "DwmGZIO.hh"
54#include "DwmIOUtils.hh"
55#include "DwmStreamIO.hh"
56#include "DwmIpv4Prefix.hh"
57#include "DwmOperators.hh"
58
59namespace Dwm {
60 struct OurIpv4AddressHash
61 {
62 inline size_t operator () (const Dwm::Ipv4Address & addr) const
63 {
64 return(addr.Raw());
65 }
66 };
67} // namespace Dwm
68
69namespace Dwm {
70
71 //--------------------------------------------------------------------------
124 //--------------------------------------------------------------------------
125 template <typename _valueT>
127 {
128 public:
129 typedef std::unordered_map<Ipv4Address, _valueT,
130 OurIpv4AddressHash> _RepSubType;
131 typedef typename _RepSubType::const_iterator const_iterator;
132
133 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
137 : _hashMaps()
138 {
139 for (uint8_t i = 0; i < 33; ++i) {
140 _hashMaps[i].max_load_factor(.08);
141 }
142 }
143
144 //------------------------------------------------------------------------
146 //------------------------------------------------------------------------
147 void Clear()
148 {
149 for (uint8_t i = 0; i < 33; ++i)
150 _hashMaps[i].clear();
151 return;
152 }
153
154 //------------------------------------------------------------------------
156 //------------------------------------------------------------------------
157 bool Empty() const
158 {
159 bool rc = true;
160 for (uint8_t i = 0; i < 33; ++i) {
161 if (! _hashMaps[i].empty()) {
162 rc = false;
163 break;
164 }
165 }
166 return(rc);
167 }
168
169 //------------------------------------------------------------------------
172 //------------------------------------------------------------------------
173 bool Add(const Ipv4Prefix & prefix, const _valueT & value)
174 {
175 bool rc = false;
176
177 typename _RepSubType::iterator iter =
178 _hashMaps[prefix.MaskLength()].find(prefix.Network());
179 if (iter == _hashMaps[prefix.MaskLength()].end()) {
180 _hashMaps[prefix.MaskLength()][prefix.Network()] = value;
181 rc = true;
182 }
183 return(rc);
184 }
185
186 //------------------------------------------------------------------------
188 //------------------------------------------------------------------------
189 void Add(const Ipv4Routes<_valueT> & routes)
190 {
191 for (uint8_t i = 0; i < 33; ++i) {
192 if (! routes._hashMaps[i].empty()) {
193 for (const auto & entry : routes._hashMaps[i]) {
194 _hashMaps[i][entry.first] = entry.second;
195 }
196 }
197 }
198 return;
199 }
200
201 //------------------------------------------------------------------------
203 //------------------------------------------------------------------------
204 _valueT & operator [] (const Ipv4Prefix & prefix)
205 {
206 return(_hashMaps[prefix.MaskLength()][prefix.Network()]);
207 }
208
209 //------------------------------------------------------------------------
212 //------------------------------------------------------------------------
213 bool Delete(const Ipv4Prefix & prefix)
214 {
215 bool rc = false;
216 typename _RepSubType::iterator iter =
217 _hashMaps[prefix.MaskLength()].find(prefix.Network());
218 if (iter != _hashMaps[prefix.MaskLength()].end()) {
219 _hashMaps[prefix.MaskLength()].erase(iter);
220 rc = true;
221 }
222 return(rc);
223 }
224
225 //------------------------------------------------------------------------
229 //------------------------------------------------------------------------
230 bool Find(const Ipv4Prefix & prefix, _valueT & match) const
231 {
232 bool rc = false;
233 if (! _hashMaps[prefix.MaskLength()].empty()) {
234 typename _RepSubType::const_iterator iter =
235 _hashMaps[prefix.MaskLength()].find(prefix.Network());
236 if (iter != _hashMaps[prefix.MaskLength()].end()) {
237 match = iter->second;
238 rc = true;
239 }
240 }
241 return(rc);
242 }
243
244 //------------------------------------------------------------------------
246 //------------------------------------------------------------------------
247 void FindInSubMap(const _RepSubType & subMap, Ipv4Address ipAddr,
248 std::pair<bool,_valueT> & result) const
249 {
250 auto iter = subMap.find(ipAddr);
251 if (iter != subMap.end()) {
252 result.first = true;
253 result.second = iter->second;
254 }
255 return;
256 }
257
258 //------------------------------------------------------------------------
260 //------------------------------------------------------------------------
261 bool NewFindLongest(const Ipv4Address & ipAddr,
262 std::pair<Ipv4Prefix,_valueT> & match) const
263 {
264 using std::map, std::pair, std::thread;
265 bool rc = false;
266 map<uint8_t,pair<bool,_valueT>> results;
267 std::map<uint8_t,thread> threads;
268 for (int i = 32; i >= 0; --i) {
269 if (! _hashMaps[i].empty()) {
270 results[i] = {false,_valueT()};
271 Ipv4Prefix pfx(ipAddr, i);
272 threads[i] = thread(&Ipv4Routes::FindInSubMap, this,
273 std::ref(_hashMaps[i]), pfx.Network(),
274 std::ref(results[i]));
275 }
276 }
277 for (auto it = threads.rbegin(); it != threads.rend(); ++it) {
278 it->second.join();
279 if (results[it->first].first) {
280 rc = true;
281 match.first = Ipv4Prefix(ipAddr, it->first);
282 match.second = results[it->first].second;
283 }
284 }
285 return rc;
286 }
287
288 //------------------------------------------------------------------------
292 //------------------------------------------------------------------------
293 bool FindLongest(const Ipv4Address & ipAddr,
294 std::pair<Ipv4Prefix,_valueT> & match) const
295 {
296 bool rc = false;
297
298 Ipv4Prefix lp(ipAddr, 32);
299 typename _RepSubType::const_iterator iter;
300 for (int8_t i = 32; i >= 0; --i) {
301 if (_hashMaps[i].empty())
302 continue;
303 lp.MaskLength(i);
304 iter = _hashMaps[i].find(lp.Network());
305 if (iter != _hashMaps[i].end()) {
306 match.first = lp;
307 match.second = iter->second;
308 rc = true;
309 break;
310 }
311 }
312 return(rc);
313 }
314
315 //------------------------------------------------------------------------
322 //------------------------------------------------------------------------
323 bool
324 FindLongest(const Ipv4Address & ipAddr,
325 std::pair<Ipv4Prefix, const _valueT *> & match) const
326 {
327 bool rc = false;
328 Ipv4Prefix lp(ipAddr, 32);
329 typename _RepSubType::const_iterator iter;
330 for (int8_t i = 32; i >= 0; --i) {
331 if (_hashMaps[i].empty())
332 continue;
333 lp.MaskLength(i);
334 iter = _hashMaps[i].find(lp.Network());
335 if (iter != _hashMaps[i].end()) {
336 match.first = lp;
337 match.second = &(iter->second);
338 rc = true;
339 break;
340 }
341 }
342 return(rc);
343 }
344
345 //------------------------------------------------------------------------
349 //------------------------------------------------------------------------
350 bool Find(const Ipv4Address & ipAddr,
351 std::vector<std::pair<Ipv4Prefix,_valueT> > & matches) const
352 {
353 if (! matches.empty())
354 matches.clear();
355
356 typename _RepSubType::const_iterator iter;
357
358 for (int8_t i = 32; i >= 0; --i) {
359 if (_hashMaps[i].empty())
360 continue;
361 Ipv4Prefix prefix(ipAddr, i);
362 iter = _hashMaps[i].find(prefix.Network());
363 if (iter != _hashMaps[i].end()) {
364 std::pair<Ipv4Prefix,_valueT> match(prefix, iter->second);
365 matches.push_back(match);
366 }
367 }
368 return(! matches.empty());
369 }
370
371 //------------------------------------------------------------------------
373 //------------------------------------------------------------------------
374 void MaxLoadFactor(float loadFactor)
375 {
376 for (int8_t i = 32; i >= 0; --i) {
377 _hashMaps[i].max_load_factor(loadFactor);
378 }
379 return;
380 }
381
382 //------------------------------------------------------------------------
386 //------------------------------------------------------------------------
387 bool operator == (const Ipv4Routes<_valueT> & r) const
388 {
389 for (int8_t i = 32; i >= 0; --i) {
390 if (_hashMaps[i] != r._hashMaps[i])
391 return(false);
392 }
393 return(true);
394 }
395
396 //------------------------------------------------------------------------
400 //------------------------------------------------------------------------
401 bool operator != (const Ipv4Routes<_valueT> & r) const
402 {
403 return(! (*this == r));
404 }
405
406 //------------------------------------------------------------------------
408 //------------------------------------------------------------------------
409 uint32_t Size() const
410 {
411 uint32_t rc = 0;
412 for (uint8_t i = 0; i < 33; ++i)
413 rc += _hashMaps[i].size();
414 return(rc);
415 }
416
417 //------------------------------------------------------------------------
419 //------------------------------------------------------------------------
420 void HashSizes(std::vector<std::pair<uint8_t, uint32_t> > & sizes) const
421 {
422 if (! sizes.empty())
423 sizes.clear();
424 for (uint8_t i = 0; i < 33; ++i) {
425 if (! _hashMaps[i].empty()) {
426 sizes.push_back(std::pair<uint8_t,uint32_t>(i,_hashMaps[i].size()));
427 }
428 }
429 return;
430 }
431
432 //------------------------------------------------------------------------
434 //------------------------------------------------------------------------
435 uint64_t StreamedLength() const
436 {
437 return(IOUtils::StreamedLength(_hashMaps));
438 }
439
440 //------------------------------------------------------------------------
442 //------------------------------------------------------------------------
443 std::istream & Read(std::istream & is)
444 {
445 return(StreamIO::Read(is, _hashMaps));
446 }
447
448 //------------------------------------------------------------------------
450 //------------------------------------------------------------------------
451 std::ostream & Write(std::ostream & os) const
452 {
453 return(StreamIO::Write(os, _hashMaps));
454 }
455
456 //------------------------------------------------------------------------
459 //------------------------------------------------------------------------
460 size_t Read(FILE *f)
461 {
462 return(FileIO::Read(f, _hashMaps));
463 }
464
465 //------------------------------------------------------------------------
468 //------------------------------------------------------------------------
469 size_t Write(FILE *f) const
470 {
471 return(FileIO::Write(f, _hashMaps));
472 }
473
474 //------------------------------------------------------------------------
477 //------------------------------------------------------------------------
478 ssize_t Read(int fd)
479 {
480 return(DescriptorIO::Read(fd, _hashMaps));
481 }
482
483 //------------------------------------------------------------------------
486 //------------------------------------------------------------------------
487 ssize_t Write(int fd) const
488 {
489 return(DescriptorIO::Write(fd, _hashMaps));
490 }
491
492 //------------------------------------------------------------------------
495 //------------------------------------------------------------------------
496 int Read(gzFile gzf)
497 {
498 return(GZIO::Read(gzf, _hashMaps));
499 }
500
501 //------------------------------------------------------------------------
504 //------------------------------------------------------------------------
505 int Write(gzFile gzf) const
506 {
507 return(GZIO::Write(gzf, _hashMaps));
508 }
509
510 //------------------------------------------------------------------------
513 //------------------------------------------------------------------------
514 int BZRead(BZFILE *bzf)
515 {
516 return(BZ2IO::BZRead(bzf, _hashMaps));
517 }
518
519 //------------------------------------------------------------------------
522 //------------------------------------------------------------------------
523 int BZWrite(BZFILE *bzf) const
524 {
525 return(BZ2IO::BZWrite(bzf, _hashMaps));
526 }
527
528 //------------------------------------------------------------------------
537 //------------------------------------------------------------------------
538 template <typename BinaryPredicate>
539 void Coalesce(BinaryPredicate pred)
540 {
541 // Combine adjacents.
542 for (uint8_t maskLen = 32; maskLen > 0; --maskLen) {
543 auto & hm = this->_hashMaps[maskLen];
544 auto hmi = hm.begin();
545 while (hmi != hm.end()) {
546 bool erased = false;
547 Ipv4Prefix pfx(hmi->first, maskLen);
548 Ipv4Prefix nextpfx = pfx;
549 ++nextpfx;
550 std::pair<bool,Ipv4Prefix> combpfx = pfx.Combine(nextpfx);
551 if (combpfx.first) {
552 auto nextit = hm.find(nextpfx.Network());
553 if (nextit != hm.end()) {
554 if (pred(hmi->second, nextit->second)) {
555 hm.erase(nextit);
556 _hashMaps[maskLen-1][combpfx.second.Network()] = hmi->second;
557 hmi = hm.erase(hmi);
558 erased = true;
559 }
560 }
561 }
562 if (! erased) {
563 ++hmi;
564 }
565 }
566 }
567 // Remove entries that are covered by matching entry with wider
568 // netmask.
569 for (uint8_t maskLen = 32; maskLen > 0; --maskLen) {
570 auto & hm = this->_hashMaps[maskLen];
571 auto hmi = hm.begin();
572 while (hmi != hm.end()) {
573 if (HaveWiderMatch(hmi->first, maskLen, hmi->second, pred)) {
574 hmi = hm.erase(hmi);
575 }
576 else {
577 ++hmi;
578 }
579 }
580 }
581 return;
582 }
583
584 //------------------------------------------------------------------------
586 //------------------------------------------------------------------------
587 void Coalesce()
588 {
589 return Coalesce(std::equal_to<_valueT>());
590 }
591
592 //------------------------------------------------------------------------
594 //------------------------------------------------------------------------
595 void GetAllKeys(std::vector<Ipv4Prefix> & keys) const
596 {
597 keys.resize(this->Size());
598 if (! keys.empty()) {
599 uint32_t pfx = 0;
600 for (uint8_t hashNum = 0; hashNum < 33; ++hashNum) {
601 for (const auto & entry : this->_hashMaps[hashNum]) {
602 keys[pfx] = Ipv4Prefix(entry.first, hashNum);
603 ++pfx;
604 }
605 }
606 }
607 return;
608 }
609
610 //------------------------------------------------------------------------
612 //------------------------------------------------------------------------
613 void SortByKey(std::vector<std::pair<Ipv4Prefix,_valueT>> & target,
614 bool ascending = true) const
615 {
616 if (! target.empty())
617 target.clear();
618 if (! this->_hashMaps.empty()) {
619 target.resize(this->Size());
620 auto iter = this->_hashMaps.begin();
621 uint32_t pfx = 0;
622 for (uint8_t hashNum = 0; hashNum < 33; ++hashNum) {
623 if (! this->_hashMaps[hashNum].empty()) {
624 auto hiter = this->_hashMaps[hashNum].begin();
625 for ( ; hiter != iter->end(); ++hiter) {
626 target[pfx].first = Ipv4Prefix(hiter->first, hashNum);
627 target[pfx].second = hiter->second;
628 ++pfx;
629 }
630 }
631 }
632 if (! target.empty()) {
633 if (ascending) {
634 std::sort(target.begin(), target.end(), KeyLess());
635 }
636 else {
637 std::sort(target.begin(), target.end(), KeyGreater());
638 }
639 }
640 }
641
642 return;
643 }
644
645 //------------------------------------------------------------------------
651 //------------------------------------------------------------------------
652 void SortByValue(std::vector<std::pair<Ipv4Prefix,_valueT> > & target)
653 {
654 if (! target.empty())
655 target.clear();
656 if (! this->_hashMaps.empty()) {
657 target.resize(this->Size());
658 auto iter = this->_hashMaps.begin();
659 uint32_t pfx = 0;
660 for (uint8_t hashNum = 0; hashNum < 33; ++hashNum) {
661 if (! this->_hashMaps[hashNum].empty()) {
662 auto hiter = this->_hashMaps[hashNum].begin();
663 for ( ; hiter != iter->end(); ++hiter) {
664 target[pfx].first = Ipv4Prefix(hiter->first, hashNum);
665 target[pfx].second = hiter->second;
666 ++pfx;
667 }
668 }
669 }
670 if (! target.empty())
671 std::sort(target.begin(), target.end(),
672 [] (const auto & e1, const auto & e2)
673 { return (e1.second > e2.second); });
674 }
675
676 return;
677 }
678
679 //------------------------------------------------------------------------
682 //------------------------------------------------------------------------
683 uint32_t AddressesCovered() const
684 {
685 uint32_t rc = 0;
686 for (int8_t hashNum = 32; hashNum > 1; --hashNum) {
687 typename _RepSubType::const_iterator hiter =
688 _hashMaps[hashNum].begin();
689 for ( ; hiter != _hashMaps[hashNum].end(); ++hiter) {
690 bool foundWider = false;
691 for (int8_t widerHash = hashNum - 1; widerHash > 0; --widerHash) {
692 Ipv4Prefix widerPfx(hiter->first, widerHash);
693 if (_hashMaps[widerHash].find(widerPfx.Network())
694 != _hashMaps[widerHash].end()) {
695 // found wider match, don't count
696 foundWider = true;
697 break;
698 }
699 }
700 if (! foundWider) {
701 rc += ((uint32_t)1 << (32 - hashNum));
702 }
703 }
704 }
705 return rc;
706 }
707
708 struct KeyGreater
709 {
710 public:
711 bool operator () (const std::pair<Ipv4Prefix,_valueT> & e1,
712 const std::pair<Ipv4Prefix,_valueT> & e2) const
713 {
714 return(e1.first > e2.first);
715 }
716 };
717
718 struct KeyLess
719 {
720 public:
721 bool operator () (const std::pair<Ipv4Prefix,_valueT> & e1,
722 const std::pair<Ipv4Prefix,_valueT> & e2) const
723 {
724 return(e1.first < e2.first);
725 }
726 };
727
728#if 0
729 struct ValueGreater
730 {
731 public:
732 bool operator () (const std::pair<Ipv4Prefix,_valueT> & e1,
733 const std::pair<Ipv4Prefix,_valueT> & e2) const
734 {
735 return(e1.second > e2.second);
736 }
737 };
738#endif
739
740 //------------------------------------------------------------------------
742 //------------------------------------------------------------------------
743 const std::array<_RepSubType,33> & HashMaps() const
744 {
745 return _hashMaps;
746 }
747
748 protected:
749 std::array<_RepSubType,33> _hashMaps;
750
751 template <typename BinaryPredicate>
752 bool HaveWiderMatch(const Ipv4Address & addr, uint8_t maskLen,
753 const _valueT & val, BinaryPredicate pred) const
754 {
755 bool rc = false;
756 if (maskLen > 0) {
757 for (int8_t wml = maskLen - 1; wml > 0; --wml) {
758 Ipv4Prefix pfx(addr, wml);
759 auto iter = _hashMaps[wml].find(pfx.Network());
760 if (iter != _hashMaps[wml].end()) {
761 if (pred(iter->second, val)) {
762 rc = true;
763 break;
764 }
765 }
766 }
767 }
768 return rc;
769 }
770
771 };
772
773
774} // namespace Dwm
775
776#endif // _DWMIPV4ROUTES_HH_
777
778//---------------------------- emacs settings -----------------------------
779// Local Variables:
780// mode: C++
781// tab-width: 2
782// indent-tabs-mode: nil
783// c-basic-offset: 2
784// End:
785//-------------------------------------------------------------------------
Dwm::BZ2IO class declaration.
Dwm::DescriptorIO class declaration.
Dwm::FileIO class declaration.
Dwm::GZIO class definition.
Dwm::IOUtils class declaration and implementation.
Dwm::Ipv4Prefix class definition.
Miscellaneous operators.
A configure target for dealing with OS differences.
Dwm::StreamIO class declaration.
static int BZRead(BZFILE *bzf, char &c)
Reads from bzf.
static int BZWrite(BZFILE *bzf, char c)
Writes c to bzf.
static ssize_t Write(int fd, char c)
Writes c to fd.
static ssize_t Read(int fd, char &c)
Reads c from fd.
static size_t Write(FILE *f, char c)
Writes c to f.
static size_t Read(FILE *f, char &c)
Reads c from f.
static int Write(gzFile gzf, char c)
Writes c to gzf.
static int Read(gzFile gzf, char &c)
Reads from gzf.
static uint64_t StreamedLength(char c)
Returns the number of bytes that would be written if we called Write() for a char.
Definition DwmIOUtils.hh:85
This class encapsulates an IPv4 address.
Definition DwmIpv4Address.hh:63
ipv4addr_t Raw() const
Returns an ipv4addr_t representation (32-bit value in network byte order).
Definition DwmIpv4Address.hh:86
This class encapsulates an IPv4 address and netmask.
Definition DwmIpv4Prefix.hh:59
std::pair< bool, Ipv4Prefix > Combine(const Ipv4Prefix &prefix) const
If the given prefix can be combined with this prefix to form a single prefix, returns [true,...
uint8_t MaskLength() const
Returns the length of the netmask (number of significant bits).
Definition DwmIpv4Prefix.hh:137
Ipv4Address Network() const
Returns the network portion of the prefix.
Definition DwmIpv4Prefix.hh:116
This template class provides an associative container keyed by IPv4 addresses, with longest-match sea...
Definition DwmIpv4Routes.hh:127
bool Find(const Ipv4Address &ipAddr, std::vector< std::pair< Ipv4Prefix, _valueT > > &matches) const
Finds all matches for ipAddr.
Definition DwmIpv4Routes.hh:350
bool FindLongest(const Ipv4Address &ipAddr, std::pair< Ipv4Prefix, _valueT > &match) const
Finds the longest match for ipAddr.
Definition DwmIpv4Routes.hh:293
int Read(gzFile gzf)
Reads the routes from a gzFile.
Definition DwmIpv4Routes.hh:496
bool Find(const Ipv4Prefix &prefix, _valueT &match) const
Find the entry for the given prefix.
Definition DwmIpv4Routes.hh:230
Ipv4Routes()
Constructor.
Definition DwmIpv4Routes.hh:136
std::ostream & Write(std::ostream &os) const
Writes the routes to an ostream. Returns the ostream.
Definition DwmIpv4Routes.hh:451
bool operator==(const Ipv4Routes< _valueT > &r) const
operator == It's unlikely you'd ever need to use this, and it's expensive.
Definition DwmIpv4Routes.hh:387
bool Delete(const Ipv4Prefix &prefix)
Deletes the entry for prefix.
Definition DwmIpv4Routes.hh:213
void Coalesce(BinaryPredicate pred)
Combines adjacent prefixes that can be combined (same value and prefixes can be represented by a pref...
Definition DwmIpv4Routes.hh:539
size_t Write(FILE *f) const
Writes the routes to a FILE pointer.
Definition DwmIpv4Routes.hh:469
void SortByValue(std::vector< std::pair< Ipv4Prefix, _valueT > > &target)
Sorts the contained pair<Ipv4Prefix,_valueT> values into a vector, in descending order by the value s...
Definition DwmIpv4Routes.hh:652
std::istream & Read(std::istream &is)
Reads the routes from an istream. Returns the istream.
Definition DwmIpv4Routes.hh:443
ssize_t Write(int fd) const
Writes the routes to a file descriptor.
Definition DwmIpv4Routes.hh:487
int BZRead(BZFILE *bzf)
Reads the routes from a BZFILE pointer.
Definition DwmIpv4Routes.hh:514
void Clear()
Clears all entries.
Definition DwmIpv4Routes.hh:147
bool FindLongest(const Ipv4Address &ipAddr, std::pair< Ipv4Prefix, const _valueT * > &match) const
Finds the longest match for ipAddr.
Definition DwmIpv4Routes.hh:324
size_t Read(FILE *f)
Reades the routes from a FILE pointer.
Definition DwmIpv4Routes.hh:460
const std::array< _RepSubType, 33 > & HashMaps() const
Returns a const reference to the contained hash maps.
Definition DwmIpv4Routes.hh:743
int BZWrite(BZFILE *bzf) const
Writes the routes to a BZFILE pointer.
Definition DwmIpv4Routes.hh:523
_valueT & operator[](const Ipv4Prefix &prefix)
operator [] works like you would expect from an STL map.
Definition DwmIpv4Routes.hh:204
int Write(gzFile gzf) const
Writes the routes to a gzFile.
Definition DwmIpv4Routes.hh:505
uint32_t Size() const
Returns the number of routes.
Definition DwmIpv4Routes.hh:409
bool Empty() const
Returns true if there are no entries.
Definition DwmIpv4Routes.hh:157
void Add(const Ipv4Routes< _valueT > &routes)
Bulk add all routes. Note this will overwrite existing routes.
Definition DwmIpv4Routes.hh:189
bool Add(const Ipv4Prefix &prefix, const _valueT &value)
Adds an entry.
Definition DwmIpv4Routes.hh:173
uint32_t AddressesCovered() const
Returns the number of addresses covered by the contained prefixes, not including 0/0.
Definition DwmIpv4Routes.hh:683
bool operator!=(const Ipv4Routes< _valueT > &r) const
operator != It's unlikely you'd ever need to use this, and it's expensive.
Definition DwmIpv4Routes.hh:401
ssize_t Read(int fd)
Reads the routes from a file descriptor.
Definition DwmIpv4Routes.hh:478
static std::istream & Read(std::istream &is, char &c)
Reads c from is. Returns is.
static std::ostream & Write(std::ostream &os, char c)
Writes c to os. Returns os.