📄 rangeiplookup.hh
字号:
// -*- c-basic-offset: 4 -*-#ifndef CLICK_RANGEIPLOOKUP_HH#define CLICK_RANGEIPLOOKUP_HH#include "iproutetable.hh"#include "directiplookup.hh"CLICK_DECLS/*=cRangeIPLookup(ADDR1/MASK1 [GW1] OUT1, ADDR2/MASK2 [GW2] OUT2, ...)=s IP, classificationIP routing lookup through binary search in a very compact table=dExpects a destination IP address annotation with each packet. Looks up thataddress in its routing table, using longest-prefix-match, sets the destinationannotation to the corresponding GW (if specified), and emits the packet on theindicated OUTput port.Each argument is a route, specifying a destination and mask, an optionalgateway IP address, and an output port. No destination-mask pair should occurmore than once.RangeIPLookup aims at achieving high lookup speeds through exploiting the CPUcache locality. The routing table is expanded into a very small lookupstructure, typically occupying less then 4 bytes per IP prefix. As an example,a lookup structure corresponding to a routing table with 167000 entries (arealistic snapshot taken from a core Internet router) occupies only around512 KBytes of RAM. Depending on how sucessfully the CPU cacheaffinity can be maintained, worst-case lookup rates exceeding 20 millionlookups per second can be achieved using modern commodity CPUs.RangeIPLookup maintains a large DirectIPLookup table as well as its owntables. Although this subsidiary table is only accessed during route updates,it significantly adds to RangeIPLookup's total memory footprint.=h table read-onlyOutputs a human-readable version of the current routing table.=h lookup read-onlyReports the OUTput port and GW corresponding to an address.=h add write-onlyAdds a route to the table. Format should be `C<ADDR/MASK [GW] OUT>'.Fails if a route for C<ADDR/MASK> already exists.=h set write-onlySets a route, whether or not a route for the same prefix already exists.=h remove write-onlyRemoves a route from the table. Format should be `C<ADDR/MASK>'.=h ctrl write-onlyAdds or removes a group of routes. Write `C<add>/C<set ADDR/MASK [GW] OUT>' toadd a route, and `C<remove ADDR/MASK>' to remove a route. You can supplymultiple commands, one per line; all commands are executed as one atomicoperation.=h flush write-onlyClears the entire routing table in a single atomic operation.=nSee IPRouteTable for a performance comparison of the various IP routingelements.=a IPRouteTable, RadixIPLookup, DirectIPLookup, LinearIPLookup,SortedIPLookup, StaticIPLookup, LinuxIPLookup*/class RangeIPLookup : public IPRouteTable { public: RangeIPLookup(); ~RangeIPLookup(); const char *class_name() const { return "RangeIPLookup"; } const char *processing() const { return PUSH; } int initialize(ErrorHandler *); void add_handlers(); void notify_noutputs(int n); void push(int port, Packet* p); int add_route(const IPRoute&, bool, IPRoute*, ErrorHandler *); int remove_route(const IPRoute&, IPRoute*, ErrorHandler *); int lookup_route(IPAddress, IPAddress&) const; String dump_routes(); static int flush_handler(const String &, Element *, void *, ErrorHandler *);; protected: void flush_table(); void expand(); enum { KICKSTART_BITS = 12 }; enum { RANGES_MAX = 256 * 1024 }; enum { RANGE_MASK = 0xffffffff >> KICKSTART_BITS }; enum { RANGE_SHIFT = 32 - KICKSTART_BITS }; uint32_t _range_base[1 << KICKSTART_BITS]; uint32_t _range_len[1 << KICKSTART_BITS]; uint32_t _range_t[RANGES_MAX]; bool _active; DirectIPLookup _helper;};CLICK_ENDDECLS#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -