1*5630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 2*5630257fSFerruh Yigit Copyright(c) 2017 Intel Corporation. 355694b2aSYipeng Wang 455694b2aSYipeng WangMembership Library 555694b2aSYipeng Wang================== 655694b2aSYipeng Wang 755694b2aSYipeng WangIntroduction 855694b2aSYipeng Wang------------ 955694b2aSYipeng Wang 1055694b2aSYipeng WangThe DPDK Membership Library provides an API for DPDK applications to insert a 1155694b2aSYipeng Wangnew member, delete an existing member, or query the existence of a member in a 1255694b2aSYipeng Wanggiven set, or a group of sets. For the case of a group of sets, the library 1355694b2aSYipeng Wangwill return not only whether the element has been inserted before in one of 1455694b2aSYipeng Wangthe sets but also which set it belongs to. The Membership Library is an 1555694b2aSYipeng Wangextension and generalization of a traditional filter structure (for example 1655694b2aSYipeng WangBloom Filter [Member-bloom]) that has multiple usages in a wide variety of 1755694b2aSYipeng Wangworkloads and applications. In general, the Membership Library is a data 1855694b2aSYipeng Wangstructure that provides a "set-summary" on whether a member belongs to a set, 1955694b2aSYipeng Wangand as discussed in detail later, there are two advantages of using such a 2055694b2aSYipeng Wangset-summary rather than operating on a "full-blown" complete list of elements: 2155694b2aSYipeng Wangfirst, it has a much smaller storage requirement than storing the whole list of 2255694b2aSYipeng Wangelements themselves, and secondly checking an element membership (or other 2355694b2aSYipeng Wangoperations) in this set-summary is much faster than checking it for the 2455694b2aSYipeng Wangoriginal full-blown complete list of elements. 2555694b2aSYipeng Wang 2655694b2aSYipeng WangWe use the term "Set-Summary" in this guide to refer to the space-efficient, 2755694b2aSYipeng Wangprobabilistic membership data structure that is provided by the library. A 2855694b2aSYipeng Wangmembership test for an element will return the set this element belongs to or 2955694b2aSYipeng Wangthat the element is "not-found" with very high probability of accuracy. Set-summary 3055694b2aSYipeng Wangis a fundamental data aggregation component that can be used in many network 3155694b2aSYipeng Wang(and other) applications. It is a crucial structure to address performance and 3255694b2aSYipeng Wangscalability issues of diverse network applications including overlay networks, 3355694b2aSYipeng Wangdata-centric networks, flow table summaries, network statistics and 3455694b2aSYipeng Wangtraffic monitoring. A set-summary is useful for applications who need to 3555694b2aSYipeng Wanginclude a list of elements while a complete list requires too much space 3655694b2aSYipeng Wangand/or too much processing cost. In these situations, the set-summary works as 3755694b2aSYipeng Wanga lossy hash-based representation of a set of members. It can dramatically 3855694b2aSYipeng Wangreduce space requirement and significantly improve the performance of set 3955694b2aSYipeng Wangmembership queries at the cost of introducing a very small membership test error 4055694b2aSYipeng Wangprobability. 4155694b2aSYipeng Wang 4255694b2aSYipeng Wang.. _figure_membership1: 4355694b2aSYipeng Wang.. figure:: img/member_i1.* 4455694b2aSYipeng Wang 4555694b2aSYipeng Wang Example Usages of Membership Library 4655694b2aSYipeng Wang 4755694b2aSYipeng WangThere are various usages for a Membership Library in a very 4855694b2aSYipeng Wanglarge set of applications and workloads. Interested readers can refer to 4955694b2aSYipeng Wang[Member-survey] for a survey of possible networking usages. The above figure 5055694b2aSYipeng Wangprovide a small set of examples of using the Membership Library: 5155694b2aSYipeng Wang 5255694b2aSYipeng Wang* Sub-figure (a) 5355694b2aSYipeng Wang depicts a distributed web cache architecture where a collection of proxies 5455694b2aSYipeng Wang attempt to share their web caches (cached from a set of back-end web servers) to 5555694b2aSYipeng Wang provide faster responses to clients, and the proxies use the Membership 5655694b2aSYipeng Wang Library to share summaries of what web pages/objects they are caching. With the 5755694b2aSYipeng Wang Membership Library, a proxy receiving an http request will inquire the 5855694b2aSYipeng Wang set-summary to find its location and quickly determine whether to retrieve the 5955694b2aSYipeng Wang requested web page from a nearby proxy or from a back-end web server. 6055694b2aSYipeng Wang 6155694b2aSYipeng Wang* Sub-figure (b) depicts another example for using the Membership Library to 6255694b2aSYipeng Wang prevent routing loops which is typically done using slow TTL countdown and 6355694b2aSYipeng Wang dropping packets when TTL expires. As shown in Sub-figure (b), an embedded 6455694b2aSYipeng Wang set-summary in the packet header itself can be used to summarize the set of 6555694b2aSYipeng Wang nodes a packet has gone through, and each node upon receiving a packet can check 6655694b2aSYipeng Wang whether its id is a member of the set of visited nodes, and if it is, then a 6755694b2aSYipeng Wang routing loop is detected. 6855694b2aSYipeng Wang 6955694b2aSYipeng Wang* Sub-Figure (c) presents another usage of the Membership 7055694b2aSYipeng Wang Library to load-balance flows to worker threads with in-order guarantee where a 7155694b2aSYipeng Wang set-summary is used to query if a packet belongs to an existing flow or a new 7255694b2aSYipeng Wang flow. Packets belonging to a new flow are forwarded to the current least loaded 7355694b2aSYipeng Wang worker thread, while those belonging to an existing flow are forwarded to the 7455694b2aSYipeng Wang pre-assigned thread to guarantee in-order processing. 7555694b2aSYipeng Wang 7655694b2aSYipeng Wang* Sub-figure (d) highlights 7755694b2aSYipeng Wang yet another usage example in the database domain where a set-summary is used to 7855694b2aSYipeng Wang determine joins between sets instead of creating a join by comparing each 7955694b2aSYipeng Wang element of a set against the other elements in a different set, a join is done 8055694b2aSYipeng Wang on the summaries since they can efficiently encode members of a given set. 8155694b2aSYipeng Wang 8255694b2aSYipeng WangMembership Library is a configurable library that is optimized to cover set 8355694b2aSYipeng Wangmembership functionality for both a single set and multi-set scenarios. Two set-summary 8455694b2aSYipeng Wangschemes are presented including (a) vector of Bloom Filters and (b) Hash-Table based 8555694b2aSYipeng Wangset-summary schemes with and without false negative probability. 8655694b2aSYipeng WangThis guide first briefly describes these different types of set-summaries, usage examples for each, 8755694b2aSYipeng Wangand then it highlights the Membership Library API. 8855694b2aSYipeng Wang 8955694b2aSYipeng WangVector of Bloom Filters 9055694b2aSYipeng Wang----------------------- 9155694b2aSYipeng Wang 9255694b2aSYipeng WangBloom Filter (BF) [Member-bloom] is a well-known space-efficient 9355694b2aSYipeng Wangprobabilistic data structure that answers set membership queries (test whether 9455694b2aSYipeng Wangan element is a member of a set) with some probability of false positives and 9555694b2aSYipeng Wangzero false negatives; a query for an element returns either it is "possibly in 9655694b2aSYipeng Wanga set" (with very high probability) or "definitely not in a set". 9755694b2aSYipeng Wang 9855694b2aSYipeng WangThe BF is a method for representing a set of ``n`` elements (for example flow keys 9955694b2aSYipeng Wangin network applications domain) to support membership queries. The idea of BF is 10055694b2aSYipeng Wangto allocate a bit-vector ``v`` with ``m`` bits, which are initially all set to 0. Then 10155694b2aSYipeng Wangit chooses ``k`` independent hash functions ``h1``, ``h2``, ... ``hk`` with hash values range from 10255694b2aSYipeng Wang``0`` to ``m-1`` to perform hashing calculations on each element to be inserted. Every time when an 10355694b2aSYipeng Wangelement ``X`` being inserted into the set, the bits at positions ``h1(X)``, ``h2(X)``, ... 10455694b2aSYipeng Wang``hk(X)`` in ``v`` are set to 1 (any particular bit might be set to 1 multiple times 10555694b2aSYipeng Wangfor multiple different inserted elements). Given a query for any element ``Y``, the 10655694b2aSYipeng Wangbits at positions ``h1(Y)``, ``h2(Y)``, ... ``hk(Y)`` are checked. If any of them is 0, 10755694b2aSYipeng Wangthen Y is definitely not in the set. Otherwise there is a high probability that 10855694b2aSYipeng WangY is a member of the set with certain false positive probability. As shown in 10955694b2aSYipeng Wangthe next equation, the false positive probability can be made arbitrarily small 11055694b2aSYipeng Wangby changing the number of hash functions (``k``) and the vector length (``m``). 11155694b2aSYipeng Wang 11255694b2aSYipeng Wang.. _figure_membership2: 11355694b2aSYipeng Wang.. figure:: img/member_i2.* 11455694b2aSYipeng Wang 11555694b2aSYipeng Wang Bloom Filter False Positive Probability 11655694b2aSYipeng Wang 11755694b2aSYipeng WangWithout BF, an accurate membership testing could involve a costly hash table 11855694b2aSYipeng Wanglookup and full element comparison. The advantage of using a BF is to simplify 11955694b2aSYipeng Wangthe membership test into a series of hash calculations and memory accesses for a 12055694b2aSYipeng Wangsmall bit-vector, which can be easily optimized. Hence the lookup throughput 12155694b2aSYipeng Wang(set membership test) can be significantly faster than a normal hash table 12255694b2aSYipeng Wanglookup with element comparison. 12355694b2aSYipeng Wang 12455694b2aSYipeng Wang.. _figure_membership3: 12555694b2aSYipeng Wang.. figure:: img/member_i3.* 12655694b2aSYipeng Wang 12755694b2aSYipeng Wang Detecting Routing Loops Using BF 12855694b2aSYipeng Wang 12955694b2aSYipeng WangBF is used for applications that need only one set, and the 13055694b2aSYipeng Wangmembership of elements is checked against the BF. The example discussed 13155694b2aSYipeng Wangin the above figure is one example of potential applications that uses only one 13255694b2aSYipeng Wangset to capture the node IDs that have been visited so far by the packet. Each 13355694b2aSYipeng Wangnode will then check this embedded BF in the packet header for its own id, and 13455694b2aSYipeng Wangif the BF indicates that the current node is definitely not in the set then a 13555694b2aSYipeng Wangloop-free route is guaranteed. 13655694b2aSYipeng Wang 13755694b2aSYipeng Wang 13855694b2aSYipeng Wang.. _figure_membership4: 13955694b2aSYipeng Wang.. figure:: img/member_i4.* 14055694b2aSYipeng Wang 14155694b2aSYipeng Wang Vector Bloom Filter (vBF) Overview 14255694b2aSYipeng Wang 14355694b2aSYipeng WangTo support membership test for both multiple sets and a single set, 14455694b2aSYipeng Wangthe library implements a Vector Bloom Filter (vBF) scheme. 14555694b2aSYipeng WangvBF basically composes multiple bloom filters into a vector of bloom filers. 14655694b2aSYipeng WangThe membership test is conducted on all of the 14755694b2aSYipeng Wangbloom filters concurrently to determine which set(s) it belongs to or none of 14855694b2aSYipeng Wangthem. The basic idea of vBF is shown in the above figure where an element is 14955694b2aSYipeng Wangused to address multiple bloom filters concurrently and the bloom filter 15055694b2aSYipeng Wangindex(es) with a hit is returned. 15155694b2aSYipeng Wang 15255694b2aSYipeng Wang.. _figure_membership5: 15355694b2aSYipeng Wang.. figure:: img/member_i5.* 15455694b2aSYipeng Wang 15555694b2aSYipeng Wang vBF for Flow Scheduling to Worker Thread 15655694b2aSYipeng Wang 15755694b2aSYipeng WangAs previously mentioned, there are many usages of such structures. vBF is used 15855694b2aSYipeng Wangfor applications that need to check membership against multiple sets 15955694b2aSYipeng Wangsimultaneously. The example shown in the above figure uses a set to capture 16055694b2aSYipeng Wangall flows being assigned for processing at a given worker thread. Upon receiving 16155694b2aSYipeng Wanga packet the vBF is used to quickly figure out if this packet belongs to a new flow 16255694b2aSYipeng Wangso as to be forwarded to the current least loaded worker thread, or otherwise it 16355694b2aSYipeng Wangshould be queued for an existing thread to guarantee in-order processing (i.e. 16455694b2aSYipeng Wangthe property of vBF to indicate right away that a given flow is a new one or 16555694b2aSYipeng Wangnot is critical to minimize response time latency). 16655694b2aSYipeng Wang 16755694b2aSYipeng WangIt should be noted that vBF can be implemented using a set of single bloom 16855694b2aSYipeng Wangfilters with sequential lookup of each BF. However, being able to concurrently 16955694b2aSYipeng Wangsearch all set-summaries is a big throughput advantage. In the library, certain 17055694b2aSYipeng Wangparallelism is realized by the implementation of checking all bloom filters 17155694b2aSYipeng Wangtogether. 17255694b2aSYipeng Wang 17355694b2aSYipeng Wang 17455694b2aSYipeng WangHash-Table based Set-Summaries 17555694b2aSYipeng Wang------------------------------ 17655694b2aSYipeng Wang 17755694b2aSYipeng WangHash-table based set-summary (HTSS) is another scheme in the membership library. 17855694b2aSYipeng WangCuckoo filter [Member-cfilter] is an example of HTSS. 17955694b2aSYipeng WangHTSS supports multi-set membership testing like 18055694b2aSYipeng WangvBF does. However, while vBF is better for a small number of targets, HTSS is more suitable 18155694b2aSYipeng Wangand can easily outperform vBF when the number of sets is 18255694b2aSYipeng Wanglarge, since HTSS uses a single hash table for membership testing while vBF 18355694b2aSYipeng Wangrequires testing a series of Bloom Filters each corresponding to one set. 18455694b2aSYipeng WangAs a result, generally speaking vBF is more adequate for the case of a small limited number of sets 18555694b2aSYipeng Wangwhile HTSS should be used with a larger number of sets. 18655694b2aSYipeng Wang 18755694b2aSYipeng Wang.. _figure_membership6: 18855694b2aSYipeng Wang.. figure:: img/member_i6.* 18955694b2aSYipeng Wang 19055694b2aSYipeng Wang Using HTSS for Attack Signature Matching 19155694b2aSYipeng Wang 19255694b2aSYipeng WangAs shown in the above figure, attack signature matching where each set 19355694b2aSYipeng Wangrepresents a certain signature length (for correctness of this example, an 19455694b2aSYipeng Wangattack signature should not be a subset of another one) in the payload is a good 19555694b2aSYipeng Wangexample for using HTSS with 0% false negative (i.e., when an element returns not 19655694b2aSYipeng Wangfound, it has a 100% certainty that it is not a member of any set). The packet 19755694b2aSYipeng Wanginspection application benefits from knowing right away that the current payload 19855694b2aSYipeng Wangdoes not match any attack signatures in the database to establish its 19955694b2aSYipeng Wanglegitimacy, otherwise a deep inspection of the packet is needed. 20055694b2aSYipeng Wang 20155694b2aSYipeng WangHTSS employs a similar but simpler data structure to a traditional hash table, 20255694b2aSYipeng Wangand the major difference is that HTSS stores only the signatures but not the 20355694b2aSYipeng Wangfull keys/elements which can significantly reduce the footprint of the table. 20455694b2aSYipeng WangAlong with the signature, HTSS also stores a value to indicate the target set. 20555694b2aSYipeng WangWhen looking up an element, the element is hashed and the HTSS is addressed 20655694b2aSYipeng Wangto retrieve the signature stored. If the signature matches then the value is 20755694b2aSYipeng Wangretrieved corresponding to the index of the target set which the element belongs 20855694b2aSYipeng Wangto. Because signatures can collide, HTSS can still has false positive 20955694b2aSYipeng Wangprobability. Furthermore, if elements are allowed to be 21055694b2aSYipeng Wangoverwritten or evicted when the hash table becomes full, it will also have a 21155694b2aSYipeng Wangfalse negative probability. We discuss this case in the next section. 21255694b2aSYipeng Wang 21355694b2aSYipeng WangSet-Summaries with False Negative Probability 21455694b2aSYipeng Wang~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 21555694b2aSYipeng Wang 21655694b2aSYipeng WangAs previously mentioned, traditional set-summaries (e.g. Bloom Filters) do not 21755694b2aSYipeng Wanghave a false negative probability, i.e., it is 100% certain when an element 21855694b2aSYipeng Wangreturns "not to be present" for a given set. However, the Membership Library 21955694b2aSYipeng Wangalso supports a set-summary probabilistic data structure based on HTSS which 22055694b2aSYipeng Wangallows for false negative probability. 22155694b2aSYipeng Wang 22255694b2aSYipeng WangIn HTSS, when the hash table becomes full, keys/elements will fail to be added 22355694b2aSYipeng Wanginto the table and the hash table has to be resized to accommodate for these new 22455694b2aSYipeng Wangelements, which can be expensive. However, if we allow new elements to overwrite 22555694b2aSYipeng Wangor evict existing elements (as a cache typically does), then the resulting 22655694b2aSYipeng Wangset-summary will begin to have false negative probability. This is because the 22755694b2aSYipeng Wangelement that was evicted from the set-summary may still be present in the target 22855694b2aSYipeng Wangset. For subsequent inquiries the set-summary will falsely report the element 22955694b2aSYipeng Wangnot being in the set, hence having a false negative probability. 23055694b2aSYipeng Wang 23155694b2aSYipeng WangThe major usage of HTSS with false negative is to use it as a cache for 23255694b2aSYipeng Wangdistributing elements to different target sets. By allowing HTSS to evict old 23355694b2aSYipeng Wangelements, the set-summary can keep track of the most recent elements 23455694b2aSYipeng Wang(i.e. active) as a cache typically does. Old inactive elements (infrequently 23555694b2aSYipeng Wangused elements) will automatically and eventually get evicted from the 23655694b2aSYipeng Wangset-summary. It is worth noting that the set-summary still has false positive 23755694b2aSYipeng Wangprobability, which means the application either can tolerate certain false positive 23855694b2aSYipeng Wangor it has fall-back path when false positive happens. 23955694b2aSYipeng Wang 24055694b2aSYipeng Wang.. _figure_membership7: 24155694b2aSYipeng Wang.. figure:: img/member_i7.* 24255694b2aSYipeng Wang 24355694b2aSYipeng Wang Using HTSS with False Negatives for Wild Card Classification 24455694b2aSYipeng Wang 24555694b2aSYipeng WangHTSS with false negative (i.e. a cache) also has its wide set of applications. 24655694b2aSYipeng WangFor example wild card flow classification (e.g. ACL rules) highlighted in the 24755694b2aSYipeng Wangabove figure is an example of such application. In that case each target set 24855694b2aSYipeng Wangrepresents a sub-table with rules defined by a certain flow mask. The flow masks 24955694b2aSYipeng Wangare non-overlapping, and for flows matching more than one rule only the highest 25055694b2aSYipeng Wangpriority one is inserted in the corresponding sub-table (interested readers can 25155694b2aSYipeng Wangrefer to the Open vSwitch (OvS) design of Mega Flow Cache (MFC) [Member-OvS] 25255694b2aSYipeng Wangfor further details). Typically the rules will have a large number of distinct 25355694b2aSYipeng Wangunique masks and hence, a large number of target sets each corresponding to one 25455694b2aSYipeng Wangmask. Because the active set of flows varies widely based on the network 25555694b2aSYipeng Wangtraffic, HTSS with false negative will act as a cache for <flowid, target ACL 25655694b2aSYipeng Wangsub-table> pair for the current active set of flows. When a miss occurs (as 25755694b2aSYipeng Wangshown in red in the above figure) the sub-tables will be searched sequentially 25855694b2aSYipeng Wangone by one for a possible match, and when found the flow key and target 25955694b2aSYipeng Wangsub-table will be inserted into the set-summary (i.e. cache insertion) so 26055694b2aSYipeng Wangsubsequent packets from the same flow don’t incur the overhead of the 26155694b2aSYipeng Wangsequential search of sub-tables. 26255694b2aSYipeng Wang 26355694b2aSYipeng WangLibrary API Overview 26455694b2aSYipeng Wang-------------------- 26555694b2aSYipeng Wang 26655694b2aSYipeng WangThe design goal of the Membership Library API is to be as generic as possible to 26755694b2aSYipeng Wangsupport all the different types of set-summaries we discussed in previous 26855694b2aSYipeng Wangsections and beyond. Fundamentally, the APIs need to include creation, 26955694b2aSYipeng Wanginsertion, deletion, and lookup. 27055694b2aSYipeng Wang 27155694b2aSYipeng Wang 27255694b2aSYipeng WangSet-summary Create 27355694b2aSYipeng Wang~~~~~~~~~~~~~~~~~~ 27455694b2aSYipeng Wang 27555694b2aSYipeng WangThe ``rte_member_create()`` function is used to create a set-summary structure, the input parameter 27655694b2aSYipeng Wangis a struct to pass in parameters that needed to initialize the set-summary, while the function returns the 27755694b2aSYipeng Wangpointer to the created set-summary or ``NULL`` if the creation failed. 27855694b2aSYipeng Wang 27955694b2aSYipeng WangThe general input arguments used when creating the set-summary should include ``name`` 28055694b2aSYipeng Wangwhich is the name of the created set-summary, *type* which is one of the types 28155694b2aSYipeng Wangsupported by the library (e.g. ``RTE_MEMBER_TYPE_HT`` for HTSS or ``RTE_MEMBER_TYPE_VBF`` for vBF), and ``key_len`` 28255694b2aSYipeng Wangwhich is the length of the element/key. There are other parameters 28355694b2aSYipeng Wangare only used for certain type of set-summary, or which have a slightly different meaning for different types of set-summary. 28455694b2aSYipeng WangFor example, ``num_keys`` parameter means the maximum number of entries for Hash table based set-summary. 28555694b2aSYipeng WangHowever, for bloom filter, this value means the expected number of keys that could be 28655694b2aSYipeng Wanginserted into the bloom filter(s). The value is used to calculate the size of each 28755694b2aSYipeng Wangbloom filter. 28855694b2aSYipeng Wang 28955694b2aSYipeng WangWe also pass two seeds: ``prim_hash_seed`` and 29055694b2aSYipeng Wang``sec_hash_seed`` for the primary and secondary hash functions to calculate two independent hash values. 29155694b2aSYipeng Wang``socket_id`` parameter is the NUMA socket ID for the memory used to create the 29255694b2aSYipeng Wangset-summary. For HTSS, another parameter ``is_cache`` is used to indicate 29355694b2aSYipeng Wangif this set-summary is a cache (i.e. with false negative probability) or not. 29455694b2aSYipeng WangFor vBF, extra parameters are needed. For example, ``num_set`` is the number of 29555694b2aSYipeng Wangsets needed to initialize the vector bloom filters. This number is equal to the 29655694b2aSYipeng Wangnumber of bloom filters will be created. 29755694b2aSYipeng Wang``false_pos_rate`` is the false positive rate. num_keys and false_pos_rate will be used to determine 29855694b2aSYipeng Wangthe number of hash functions and the bloom filter size. 29955694b2aSYipeng Wang 30055694b2aSYipeng Wang 30155694b2aSYipeng WangSet-summary Element Insertion 30255694b2aSYipeng Wang~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 30355694b2aSYipeng Wang 30455694b2aSYipeng WangThe ``rte_member_add()`` function is used to insert an element/key into a set-summary structure. If it fails an 30555694b2aSYipeng Wangerror is returned. For success the returned value is dependent on the 30655694b2aSYipeng Wangset-summary mode to provide extra information for the users. For vBF 30755694b2aSYipeng Wangmode, a return value of 0 means a successful insert. For HTSS mode without false negative, the insert 30855694b2aSYipeng Wangcould fail with ``-ENOSPC`` if the table is full. With false negative (i.e. cache mode), 30955694b2aSYipeng Wangfor insert that does not cause any eviction (i.e. no overwriting happens to an 31055694b2aSYipeng Wangexisting entry) the return value is 0. For insertion that causes eviction, the return 31155694b2aSYipeng Wangvalue is 1 to indicate such situation, but it is not an error. 31255694b2aSYipeng Wang 31355694b2aSYipeng WangThe input arguments for the function should include the ``key`` which is a pointer to the element/key that needs to 31455694b2aSYipeng Wangbe added to the set-summary, and ``set_id`` which is the set id associated 31555694b2aSYipeng Wangwith the key that needs to be added. 31655694b2aSYipeng Wang 31755694b2aSYipeng Wang 31855694b2aSYipeng WangSet-summary Element Lookup 31955694b2aSYipeng Wang~~~~~~~~~~~~~~~~~~~~~~~~~~ 32055694b2aSYipeng Wang 32155694b2aSYipeng WangThe ``rte_member_lookup()`` function looks up a single key/element in the set-summary structure. It 32255694b2aSYipeng Wangreturns as soon as the first match is found. The return value is 1 if a 32355694b2aSYipeng Wangmatch is found and 0 otherwise. The arguments for the function include ``key`` which is a pointer to the 32455694b2aSYipeng Wangelement/key that needs to be looked up, and ``set_id`` which is used to return the 32555694b2aSYipeng Wangfirst target set id where the key has matched, if any. 32655694b2aSYipeng Wang 32755694b2aSYipeng WangThe ``rte_member_lookup_bulk()`` function is used to look up a bulk of keys/elements in the 32855694b2aSYipeng Wangset-summary structure for their first match. Each key lookup returns as soon as the first match is found. The 32955694b2aSYipeng Wangreturn value is the number of keys that find a match. The arguments of the function include ``keys`` 33055694b2aSYipeng Wangwhich is a pointer to a bulk of keys that are to be looked up, 33155694b2aSYipeng Wang``num_keys`` is the number 33255694b2aSYipeng Wangof keys that will be looked up, and ``set_ids`` are the return target set 33355694b2aSYipeng Wangids for the first match found for each of the input keys. ``set_ids`` is an array 33455694b2aSYipeng Wangneeds to be sized according to the ``num_keys``. If there is no match, the set id 33555694b2aSYipeng Wangfor that key will be set to RTE_MEMBER_NO_MATCH. 33655694b2aSYipeng Wang 33755694b2aSYipeng WangThe ``rte_member_lookup_multi()`` function looks up a single key/element in the 33855694b2aSYipeng Wangset-summary structure for multiple matches. It 33955694b2aSYipeng Wangreturns ALL the matches (possibly more than one) found for this key when it 34055694b2aSYipeng Wangis matched against all target sets (it is worth noting that for cache mode HTSS, 34155694b2aSYipeng Wangthe current implementation matches at most one target set). The return value is 34255694b2aSYipeng Wangthe number of matches 34355694b2aSYipeng Wangthat was found for this key (for cache mode HTSS the return value 34455694b2aSYipeng Wangshould be at most 1). The arguments for the function include ``key`` which is a pointer to the 34555694b2aSYipeng Wangelement/key that needs to be looked up, ``max_match_per_key`` which is to indicate the maximum number of matches 34655694b2aSYipeng Wangthe user expects to find for each key, and ``set_id`` which is used to return all 34755694b2aSYipeng Wangtarget set ids where the key has matched, if any. The ``set_id`` array should be sized 34855694b2aSYipeng Wangaccording to ``max_match_per_key``. For vBF, the maximum number of matches per key is equal 34955694b2aSYipeng Wangto the number of sets. For HTSS, the maximum number of matches per key is equal to two time 35055694b2aSYipeng Wangentry count per bucket. ``max_match_per_key`` should be equal or smaller than the maximum number of 35155694b2aSYipeng Wangpossible matches. 35255694b2aSYipeng Wang 35355694b2aSYipeng WangThe ``rte_membership_lookup_multi_bulk()`` function looks up a bulk of keys/elements in the 35455694b2aSYipeng Wangset-summary structure for multiple matches, each key lookup returns ALL the matches (possibly more 35555694b2aSYipeng Wangthan one) found for this key when it is matched against all target sets (cache mode HTSS 35655694b2aSYipeng Wangmatches at most one target set). The 35755694b2aSYipeng Wangreturn value is the number of keys that find one or more matches in the 35855694b2aSYipeng Wangset-summary structure. The arguments of the 35955694b2aSYipeng Wangfunction include ``keys`` which is 36055694b2aSYipeng Wanga pointer to a bulk of keys that are to be looked up, ``num_keys`` is the number 36155694b2aSYipeng Wangof keys that will be looked up, ``max_match_per_key`` is the possible 36255694b2aSYipeng Wangmaximum number of matches for each key, ``match_count`` which is the returned number 36355694b2aSYipeng Wangof matches for each key, and ``set_ids`` are the returned target set 36455694b2aSYipeng Wangids for all matches found for each keys. ``set_ids`` is 2-D array 36555694b2aSYipeng Wangcontaining a 1-D array for each key (the size of 1-D array per key should be set by the user according to ``max_match_per_key``). 36655694b2aSYipeng Wang``max_match_per_key`` should be equal or smaller than the maximum number of 36755694b2aSYipeng Wangpossible matches, similar to ``rte_member_lookup_multi``. 36855694b2aSYipeng Wang 36955694b2aSYipeng Wang 37055694b2aSYipeng WangSet-summary Element Delete 37155694b2aSYipeng Wang~~~~~~~~~~~~~~~~~~~~~~~~~~ 37255694b2aSYipeng Wang 37355694b2aSYipeng WangThe ``rte_membership_delete()`` function deletes an element/key from a set-summary structure, if it fails 37455694b2aSYipeng Wangan error is returned. The input arguments should include ``key`` which is a pointer to the 37555694b2aSYipeng Wangelement/key that needs to be deleted from the set-summary, and ``set_id`` 37655694b2aSYipeng Wangwhich is the set id associated with the key to delete. It is worth noting that current 37755694b2aSYipeng Wangimplementation of vBF does not support deletion [1]_. An error code ``-EINVAL`` will be returned. 37855694b2aSYipeng Wang 37955694b2aSYipeng Wang.. [1] Traditional bloom filter does not support proactive deletion. Supporting proactive deletion require additional implementation and performance overhead. 38055694b2aSYipeng Wang 38155694b2aSYipeng WangReferences 38255694b2aSYipeng Wang----------- 38355694b2aSYipeng Wang 38455694b2aSYipeng Wang[Member-bloom] B H Bloom, "Space/Time Trade-offs in Hash Coding with Allowable Errors," Communications of the ACM, 1970. 38555694b2aSYipeng Wang 38655694b2aSYipeng Wang[Member-survey] A Broder and M Mitzenmacher, "Network Applications of Bloom Filters: A Survey," in Internet Mathematics, 2005. 38755694b2aSYipeng Wang 38855694b2aSYipeng Wang[Member-cfilter] B Fan, D G Andersen and M Kaminsky, "Cuckoo Filter: Practically Better Than Bloom," in Conference on emerging Networking Experiments and Technologies, 2014. 38955694b2aSYipeng Wang 39055694b2aSYipeng Wang[Member-OvS] B Pfaff, "The Design and Implementation of Open vSwitch," in NSDI, 2015. 391