mustash.utils – Miscellaneous utilities

pydantic model mustash.utils.Runk

Bases: BaseModel

Ronald’s universal number kounter.

This counts lines, columns and offsets.

Fields:
field column: int = 1

Column number, counting from 1.

field line: int = 1

Line number, counting from 1.

field offset: int = 0

Offset in the string, counting from 0.

count(raw: str, /) None

Add a string to the count.

Parameters:

raw (str) – Raw string to take into account.

Return type:

None

class mustash.utils.NoValueType(*args, **kwargs)

Bases: object

Type for the NO_VALUE constant.

mustash.utils.NO_VALUE = NO_VALUE

Constant representing the absence of a value.

The type of this value is a singleton.

mustash.utils.get_generic_args(generic: Any, value: Any, /) tuple[Any, ...]

Get the generic arguments.

Parameters:
  • generic (Any) – The generic class to detect and extract parameters from.

  • value (Any) – The value from which to get the generic class parameters.

Returns:

The generic class parameters.

Raises:

TypeError – The value is not an instance of the generic class.

Return type:

tuple[Any, …]

mustash.utils.get_generic_arg(generic: Any, value: Any, /, *, default: type | NoValueType = NO_VALUE) Any

Get the generic argument.

Parameters:
  • generic (Any) – The generic class to detect and extract parameters from.

  • value (Any) – The value from which to get the generic class parameters.

  • default (type | NoValueType) – Default value to return.

Returns:

The generic class parameters.

Raises:

TypeError – The value is not an instance of the generic class.

Return type:

Any

pydantic model mustash.utils.CommunityIDTransport

Bases: BaseModel

Details regarding the community ID transport.

classmethod from_iana_number(number: int, /) CommunityIDTransport

Get transport details from the IANA protocol number.

Parameters:

number (int) – IANA number of the protocol.

Returns:

Transport details.

Return type:

CommunityIDTransport

classmethod from_name(name: str, /) CommunityIDTransport

Get transport details from the protocol name.

Parameters:

name (str) – Name of the protocol.

Returns:

Transport details.

Return type:

CommunityIDTransport

is_icmp() bool

Check if the transport is ICMP.

Return type:

bool

pydantic model mustash.utils.CommunityID

Bases: BaseModel

Details regarding a community ID to compute.

See Community ID Flow Hashing Specification for more information.

Fields:
field destination_ip: IPv4Address | IPv6Address [Required]

Destination IP address.

field destination_port: Annotated[int, Ge(0), Lt(65536)] [Required]

Destination port.

Constraints:
  • ge = 0

  • lt = 65536

field icmp_code: str | None = None

ICMP packet code, if relevant.

field icmp_type: str | None = None

ICMP packet type, if relevant.

field seed: Annotated[int, Ge(0), Lt(65536)] = 0

Seed for the community ID hash.

This seed can prevent hash collisions between network domains, such as staging and production network that use the same addressing scheme.

Constraints:
  • ge = 0

  • lt = 65536

field source_ip: IPv4Address | IPv6Address [Required]

Source IP address.

field source_port: Annotated[int, Ge(0), Lt(65536)] [Required]

Source port.

Constraints:
  • ge = 0

  • lt = 65536

field transport: CommunityIDTransport [Required]

Transport protocol.

compute() str

Compute the community ID out of the provided details.

Returns:

Community ID.

Return type:

str