comnetsemu.net module

About: ComNetsEmu Network Module.

class comnetsemu.net.APPContainerManager(net: Mininet)

Bases: object

Manager for application containers (sibling containers) deployed on Mininet hosts.

addContainer(name: str, dhost: str, dimage: str, dcmd: str, docker_args: dict | None = None, wait: bool = True) APPContainer

Create and run a new container inside a Mininet DockerHost.

Parameters:
  • name (str) – Name of the container.

  • dhost – Name of the host used for deployment.

  • dimage (str) – Name of the docker image.

  • dcmd (str) – Command to run after the creation.

  • docker_args (dict) – All other keyword arguments supported by Docker-py. e.g. CPU and memory related limitations. Some parameters are overriden for APPContainerManager’s functionalities.

  • wait (bool) – Wait until the container has the running state if True.

Check cls.docker_args_default.

Returns:

Added APPContainer instance or None if the creation process failed.

Return type:

APPContainer

docker_args_default = {'detach': True, 'init': True, 'labels': {'comnetsemu': 'dockercontainer'}, 'security_opt': ['seccomp:unconfined'], 'tty': True}
docker_volumes_default = {'/tmp/comnetsemu/appcontainermanger': {'bind': '/tmp/comnetsemu/appcontainermanger', 'mode': 'rw'}}
getAllContainers() list

Get a list of names of all containers in current container queue.

Return type:

list

getContainerInstance(name: str, default=None) APPContainer

Get the APPContainer instance with the given name.

Parameters:
  • name (str) – The name of the given container.

  • default – The default return value if not found.

Return type:

APPContainer

getContainersDhost(dhost: str) list

Get containers deployed on the given DockerHost.

Parameters:

dhost (str) – Name of the DockerHost.

Returns:

A list of APPContainer instances on given DockerHost.

Return type:

list

monResourceStats(name: str, sample_num: int = 3, sample_period: float = 1.0) list

Monitor the resource stats of a container within the given name. This function measure the CPU and memory usages sample_num times and sleep for sample_period between each time. All measurement results are returned as a list.

Parameters:
  • container (str) – Name of the container

  • sample_num (int) – Number of samples.

  • sample_period (float) – Sleep period for each sample

Returns:

A list of resource usages. Each item is a tuple (cpu_usg, mem_usg)

Return type:

list

Raises:

ValueError – container is not found

removeContainer(name: str, wait: bool = True)

Remove the APP container with the given name.

Parameters:
  • name (str) – Name of the to be removed container.

  • wait (bool) – Wait until the container is fully removed if True.

reserved_docker_args = ['init', 'tty', 'detach', 'labels', 'security_opt', 'cgroup_parent', 'network_mode']
retry_delay_secs = 0.1
runRESTServerThread(ip: str, port: int = 8000, enable_log: bool = True) None

Run the REST API server in a separate daemon thread. threading is used to avoid blocking the main thread in the emulation scripts. Since to be performed operation is more IO-bounded and this server should have no impact on the concurrency approach of main thread, the threading with a Lock is used instead of multi-processing or asyncio.

Parameters:
  • ip (str) – Listening IP address.

  • port (int) – Port number.

  • enable_log (bool) – Print logs using stdout if True.

stop()

Stop the APPContainerManager.

class comnetsemu.net.APPContainerManagerRequestHandler(appcontainermanager, enable_log=True, *args, **kargs)

Bases: BaseHTTPRequestHandler

Basic implementation of a REST API for app containers.

Python’s built-in http server only does basic security checks and this class has basic and limited sanity checks on the requests. Designed only for teaching.

do_DELETE()
do_GET()
do_POST()

Create a new APP container.

log_message(format, *args)

Log an arbitrary message.

This is used by all other logging functions. Override it if you have specific logging wishes.

The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it’s just like printf!).

The client ip and current date/time are prefixed to every message.

class comnetsemu.net.Containernet(**params)

Bases: Mininet

Network emulation with containerized network nodes.

addDockerHost(name: str, **params)

Wrapper for addHost method that adds a Docker container as a host.

Parameters:

name (str) – Name of the host.

addLinkNamedIfce(src, dst, *args, **kwargs)

Add a link with two named interfaces. - Name of interface 1: src-dst - Name of interface 2: dst-src

startTerms()

Start a terminal for each node.

class comnetsemu.net.VNFManager(net: Mininet)

Bases: APPContainerManager

App container for Virtualized Network Functions