dummynet.Scoped

class dummynet.Scoped(name, uid=<factory>)

Meta class to namespace devices, linux namespaces, and cgroups.

Supports concurrent execution by namespacing names using a standard pattern.

The naming pattern follows the format: {prefix}-{uid}-{name}

Examples:
  • d-XXXX-veth0 - interface name

  • d-XXXX-demo0 - namespace name

  • d-XXXX-limitcpu - cgroup name

Where:
  • d is the DummyNet prefix

  • XXXX is the base58 encoded contents of uid, typically the process ID

  • name is the user-defined string

Variables:
  • SCOPED_MAX_LEN – Maximum length for scoped names

  • UNSCOPED_NAMES – Special names that remain unscoped

  • SCOPED_ATTR_NAME – The special attribute name to look for in from_any.

  • PREFIX_LEN – Length of the prefix (7 characters: “d-XXXX-“)

  • UID_MAX – Maximum allowed UID value (58^4 - 1, max 4 characters in base58).

Parameters:
  • name (str) – User-defined name component

  • uid (int) – Unique ID to namespace by, defaults to current process ID

Warning

Do not use this class directly! Please instead use one of the below subclasses InterfaceScoped, NamespaceScoped, or CGroupScoped.

classmethod from_any(any)

Parse unknown input into a class instance.

Supports multiple input types:

  • String: Attempts first to parse as a scoped name, then falls back to creating a new class

  • Object with special attribute: Extracts the scoped attribute

  • Instance of this class: Returns as-is

Parameters:

any – Input to parse (string, object with scoped attribute, or class instance)

Returns:

Instance of the class

Raises:

NotImplementedError – If the input type is not supported

Return type:

Self

Note

For parsing DummyNet instances, this method also checks for attributes like .namespace, .interface, or .cgroup depending on the used subclass.

classmethod from_scoped(name)

Parse a scoped name string to its class representation.

Parameters:

name (str) – Scoped name string to parse (e.g., “d-XXXX-veth0”)

Returns:

Instance of the class with parsed name and uid

Raises:

ValueError – If the name is not a valid scoped name

Return type:

Self

property scoped: str

Get the scoped string representation.

Returns:

Scoped name string (e.g., “d-XXXX-name”) or unscoped name if in UNSCOPED_NAMES or uid is 0

class dummynet.InterfaceScoped(name, uid=<factory>)

Scoped subclass for network interfaces.

Represents scoped network interface names with specific constraints for Linux network interfaces.

Variables:
  • SCOPED_MAX_LEN – Maximum interface name length (15 characters).

  • UNSCOPED_NAMES – Names that remain unscoped ([“lo”]).

  • SCOPED_ATTR_NAME – Attribute name for scoping (“.interface”).

Parameters:
  • name (str)

  • uid (int)

class dummynet.NamespaceScoped(name, uid=<factory>)

Scoped subclass for Linux namespaces.

Represents scoped Linux namespace names.

Variables:
  • SCOPED_MAX_LEN – Maximum namespace name length (255 characters).

  • UNSCOPED_NAMES – Names that remain unscoped ([“1”]).

  • SCOPED_ATTR_NAME – Attribute name for scoping (“.namespace”).

Parameters:
  • name (str)

  • uid (int)

class dummynet.CGroupScoped(name, uid=<factory>)

Scoped subclass for cgroups.

Represents scoped cgroup names for resource management.

Variables:
  • SCOPED_MAX_LEN – Maximum cgroup name length (255 characters).

  • UNSCOPED_NAMES – Names that remain unscoped (empty list).

  • SCOPED_ATTR_NAME – Attribute name for scoping (“.cgroup”).

Parameters:
  • name (str)

  • uid (int)