This page contains the Classification Package documentation.
Module providing operations with sets of prefixes.
Bases: object
Class for operations with sets of prefixes
Adds one prefix into the PrefixSet. Prefixes are kept sorted by length. If you add something other than Prefix, it’s appended to the end.
prefix: Prefix or MaskedInt to be added into the PrefixSet.
Adds one prefix into the PrefixSet. Prefixes are NOT kept sorted by length. Added prefix is simply appended to the end.
prefix: Prefix or MaskedInt to be added into the PrefixSet.
Add range to the PrefixSet. Range will be converted to the form of prefixes and these will be added to the existing ones in the set.
r_from: Lower bound of the range (including this value). r_to: Higher bound of the range (including this value). domain_size: Number of bits of the domain.
Return True if prefixset fully covers another prefixset.
other: Prefixset that we want to cover.
Print all prefixes in human-readable format.
format: Format of printing. Possible values: ‘ipv4_prefix’, ‘ipv6_prefix’, ‘range’, ‘value’, ‘’ (‘’ - use previously set format, if none is set, guess from domain_size)
Return list of all matching prefixes. The list is sorted by length from the longest to shortest. Return empty list if ip matches no prefix.
ip: value to compare with
Return True if ip matches any prefix, False if it matches no prefix. (Fastest if you don’t care about the value of the prefix.)
ip: value to compare with
Return the longest matching prefix, if ip matches some prefix. Return None if ip matches no prefix.
ip: value to compare with
Set the PrefixSet to contain given prefixes. Delete previous prefixes.
prefixes: list of prefixes. Will be automatically sorted and checked for duplicates.
Set the PrefixSet to cover the given continous range by prefixes. All necessary prefixes will be generated and added.
r_from: Lower bound of the range (including this value). r_to: Higher bound of the range (including this value). domain_size: Number of bits of the domain.
Module providing basic operations with prefixes.
Bases: netbench.classification.maskedint.MaskedInt
Class for basic operations with prefixes of arbitrary length (IP or other). It’s subclass of MaskedInt.
Set mask of Prefix. Length is recomputed to correspond to the new mask.
mask: int or long, must be a valid mask of prefix
Bases: netbench.classification.range.Range
Range which has bitvector (list, its length is equal of number of rules) It’s subclass of Range
Module providing operations with packet classification ruletets.
Bases: object
Class for the set of Rules
Add Rule into RuleSet.
rule: Instance of the Rule class. check: Add only rules that are not covered by any of existing rules.
Add zero-length prefix for every unused field in all rules, so every rule will define a condition for all fields.
Return list of rules matching the packet. The list is sorted by priority, higest priority is first. If no rule matches the packet, empty list is returned.
packetheader: instance of PacketHeader class.
Return True if packet matches any rule, False if it matches no rule.
packetheader: instance of PacketHeader class.
Return the first matching rule. Return None if no rule matches.
packetheader: instance of PacketHeader class.
Delete rule at the given index.
index: Index of rule, rules are ordered by priority, highest priority first
Add rules into ruleset, such that every possible LPM combination is covered by some rule.
Every rule should define a condition for all fields (add_universal_prefixes() method).
Ruleset should already contain only one-prefix conditions (expand_prefixsets() method).
Also user will probably want to remove universal rule from the ruleset before calling this method.
Return list of names of all fields used in the ruleset.
Create a list of all prefixes that appears in the ruleset.
Return dictionary containing a PrefixSet for every field.
Get the rule at the given index.
index: Index of rule, rules are ordered by priority, highest priority first
Detect rules that generate excessive number of pseudorules. These rules are removed from the ruleset, and returned as a list.
count: Number of rules to be removed.
Module providing operations with packet classification rules.
Bases: object
Class representing one classification rule.
Return True if rule fully covers another rule.
other: Rule that we want to compare
allow_same_priority: Do not require different priorities
has_same_conds: set to True to skip check for same rule conditions
Get the condition for one packet header field. Return None if the condition for the given field doesn’t exist.
name: Name of packet header field.
Return True if packet satisfies all conditions of the rule.
packetheader: instance of the PacketHeader class.
Set the rule condition for one packet header field.
name: Name of the packet header field. Currently supported header fields: srcipv4, dstipv4, protocol, src_port, dst_port
value: Condition on the packet header field. It should be PrefixSet.
Recursive function returns crossproduct of all items from all lists. Result is a list of lists.
lists: list of lists of items to be crossproducted.
Module providing extensions to the original Prefix class.
Bases: netbench.classification.prefix.Prefix
Derived class extending original Prefix class. Allows to add some specific information to the prefix object. This class is used in Prefix Coloured Crossproduct Algorithm.
Module with some common functions. Currently, only function for extracting fields from packet header is implemented.
Extracts value of specified filed from given packet header. If the name of field is unknown, an UnknownFieldError exception is raised. If the field is not present in packet header, a FieldNotFoundError exception is raised.
header - Instance of PacketHeader, in which the field will be looked for.
Module providing basic operations with values with mask.
Bases: object
Class for basic operations with values of arbitrary length with a bitmask (usually prefixes).
Return True if the MaskedInt fully covers another MaskedInt, given as parameter (ie. if every possible value of other is also possible value of this).
other: MaskedInt that we want to compare.
Print prefix in human-readable format, without newline
format: Format of printing. Possible values: ‘ipv4_prefix’, ‘ipv6_prefix’, ‘range’, ‘value’, ‘’ (‘’ - use previously set format, if none is set, guess from domain_size)
Return True if valid bits of given value matches the value of MaskedInt.
value: list of numbers, one number for each 32bits, value[0] is MSB.
Set value and mask of MaskedInt.
value: int or long mask: int or long
Set mask of MaskedInt.
mask: int or long
Set value of MaskedInt.
value: int or long