Emulator

Emulator

class tangotest.vim.emulator.Emulator(vnv_checker=False, *args, **kwargs)

This class can be used to run tests on the VIM-EMU emulator. In order to use this class you need VIM-EMU to be installed locally. More information about VIM-EMU and installation instructions can be found on the project wiki-page: https://osm.etsi.org/wikipub/index.php/VIM_emulator

Example

>>> from tangotest.vim.emulator import Emulator
>>> vim = Emulator()
>>> vim.start()
>>> /* your code here */
>>> vim.stop()

You can also use this class with the context manager:

>>> with Emulator() as vim:
>>>      /* your code here */
start(*args, **kwargs)

Run the Emulator and the endpoints.

stop(*args, **kwargs)

Stop the Emulator and the endpoints.

add_instances_from_package(*args, **kwargs)

Run VNFs using a package. The library will run all the VNFs from the package and connect the according to the descriptors.

Parameters:
  • package (str) – The path to the package
  • package_format (str) – “tango” or “sonata”
Returns:

The list of (BaseInstance)s

Return type:

list

add_instance_from_image(*args, **kwargs)

Run a Docker image on the Emulator.

Parameters:
  • name (str) – The name of an instance
  • image (str) – The name of an image
  • interfaces (int), (list) (str) or (dict) – Network configuration
  • docker_command (str) – The command to execute when starting the instance
Returns:

The added instance

Return type:

(EmulatorInstance)

add_instance_from_source(*args, **kwargs)

Build and run a Docker image on the Emulator.

Parameters:
  • name (str) – The name of an instance
  • path (str) – The path to the directory containing Dockerfile
  • interfaces (int), (list) (str) or (dict) – Network configuration
  • image_name (str) – The name of an image. Default: tangotest<name>
  • docker_command (str) – The command to execute when starting the instance
  • **docker_build_args – Extra arguments to be used by the Docker engine to build the image
Returns:

The added instance

Return type:

(EmulatorInstance)

add_test_vnf(name, vnf_name)

Add addtitional test VNFs.

Parameters:
  • name (str) – The name of an instance
  • vnf_name (str) – The name of the VNF
Returns:

The added instance

Return type:

(BaseInstance)

Add a link between two instances.

Parameters:
  • src_vnf (str) – The name of a source VNF
  • src_if (str) – The name of a source interface
  • dst_vnf (str) – The name of a destination VNF
  • dst_if (str) – The name of a destination interface
  • sniff (bool) – Add the sniffer to the link
Returns:

‘’True’’ if successfull

Return type:

(bool)

get_traffic(src_vnf, src_if, dst_vnf, dst_if)

Get sniffed traffic.

Parameters:
  • src_vnf (str) – The name of a source VNF
  • src_if (str) – The name of an interface of a source VNF
  • dst_vnf (str) – The name of a destination VNF
  • dst_if (str) – The name of an interface of a destination VNF
Returns:

Sniffed packets

Return type:

(generator)

EmulatorInstance

class tangotest.vim.emulator.EmulatorInstance(vim, name)

A representation of an instance on the Emulator. Should not be created manually but by the Emulator class.

execute(cmd, stream=False, **kwargs)

Execute a command or script on the instance.

Parameters:cmd (str) – The command or path to the script
Returns:Output of the executed command or script
Return type:(str)
get_ip(interface)

Get an IP address of an interface.

Parameters:interface (str) – The name of the interface
Returns:
The IP address of the interface or None if the interface doesn’t exist
or if the interface has no IP address
Return type:(str) or (None)
get_mac(interface)

Get a MAC address of an interface.

Parameters:interface (str) – The name of the interface
Returns:The MAC address of the interface or None if the interface doesn’t exist
Return type:(str) or (None)
get_file(path)

Get file content.

Parameters:path (str) – A path to the file
Returns:The content of the file
Return type:(str)
get_journal(params)

Get records from systemd journal.

Parameters:params (str) – Parameters of the request
Returns:The list of records
Return type:(list)