multinet documentation

21
MULTINET Documentation Release 1.0.1 Intracom S.A. Telecom Solutions February 28, 2017

Upload: others

Post on 16-May-2022

22 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MULTINET Documentation

MULTINET DocumentationRelease 1.0.1

Intracom S.A. Telecom Solutions

February 28, 2017

Page 2: MULTINET Documentation
Page 3: MULTINET Documentation

Contents:

1 bin package 11.1 Subpackages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Module contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2 multi package 32.1 Submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 multi.master module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.3 multi.worker module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.4 Module contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 net package 53.1 Submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.2 net.multinet module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.3 net.topologies module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.4 Module contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

4 test package 74.1 Submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.2 test.test_travis module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74.3 Module contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

5 util package 95.1 Submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95.2 util.multinet_requests module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95.3 util.netutil module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105.4 Module contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

6 Indices and tables 13

Python Module Index 15

i

Page 4: MULTINET Documentation

ii

Page 5: MULTINET Documentation

CHAPTER 1

bin package

Subpackages

Module contents

1

Page 6: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

2 Chapter 1. bin package

Page 7: MULTINET Documentation

CHAPTER 2

multi package

Submodules

multi.master module

With this module we create the master REST server to manage the distributed topologies

multi.master.detect_hosts()Broadcast the POST request to the ‘detect_hosts’ endpoint of the workers Aggregate the responses

Returns: requests.models.Response: An HTTP Response with the aggregated status codes and bodies of thebroadcasted requests

multi.master.generate_traffic()Broadcast the POST request to the ‘generate_traffic’ endpoint of the workers Aggregate the responses

Returns: requests.models.Response: An HTTP Response with the aggregated status codes and bodies of thebroadcasted requests

multi.master.get_flows()Broadcast the POST request to the ‘get_flows’ endpoint of the workers Aggregate the responses

Returns: requests.models.Response: An HTTP Response with the aggregated status codes and bodies of thebroadcasted requests

multi.master.get_switches()Broadcast the POST request to the ‘get_switches’ endpoint of the workers Aggregate the responses

Returns: requests.models.Response: An HTTP Response with the aggregated status codes and bodies of thebroadcasted requests

multi.master.init()Broadcast the POST request to the ‘init’ endpoint of the workers Aggregate the responses

Args: controller_ip_address (str): The IP address of the controller controller_of_port (int): The OpenFlowport of the controller switch_type (str): The type of soft switch to use for the emulation topo_type (str):The type of the topology we want to build topo_size (int): The size of the topology we want to buildgroup_size (int): The number of switches in a gorup for gradual bootup group_delay (int): The delaybetween the bootup of each group hosts_per_switch (int): The number of hosts connected to each switch

Returns: requests.models.Response: An HTTP Response with the aggregated status codes and bodies of thebroadcasted requests

multi.master.ping_all()Broadcast the POST request to the ‘ping_all’ endpoint of the workers Aggregate the responses

3

Page 8: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

Returns: requests.models.Response: An HTTP Response with the aggregated status codes and bodies of thebroadcasted requests

multi.master.rest_start()Parse the command line arguments and start the master server

multi.master.start()Broadcast the POST request to the ‘start’ endpoint of the workers Aggregate the responses

Returns: requests.models.Response: An HTTP Response with the aggregated status codes and bodies of thebroadcasted requests

multi.master.stop()Broadcast the POST request to the ‘stop’ endpoint of the workers Aggregate the responses

Returns: requests.models.Response: An HTTP Response with the aggregated status codes and bodies of thebroadcasted requests

multi.worker module

Module contents

4 Chapter 2. multi package

Page 9: MULTINET Documentation

CHAPTER 3

net package

Submodules

net.multinet module

net.topologies module

Module contents

5

Page 10: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

6 Chapter 3. net package

Page 11: MULTINET Documentation

CHAPTER 4

test package

Submodules

test.test_travis module

Module contents

7

Page 12: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

8 Chapter 4. test package

Page 13: MULTINET Documentation

CHAPTER 5

util package

Submodules

util.multinet_requests module

Multinet utility functions to communicate with the master and the worker machines

util.multinet_requests.aggregate_broadcast_response(responses)Perform an aggregation on a list of HTTP responses If all the responses status code is successful return 200 elsereturn 500 Gather all the responses text in a list

Args: responses (list): A list of HTTP responses

Returns: status (int): The aggregate status code body (list): The list of all the responses text

util.multinet_requests.broadcast_cmd(worker_ip_list, worker_port_list, opcode, data=None)Broadcast a POST request to all the workers Use multiple processes to send POST requests to a specifiedendpoint of all the workers simultaneously.

Args: worker_ip_list (list): A list of IP addresses to broadcast the POST request worker_port (int): The port ofthe workers opcode (str): The REST API endpoint topo_size (int): The number of topology switches data(dict): JSON data to go with the request

Returns: list: A list of responses for all the POST requests performed

util.multinet_requests.dpid_offset_range(num_vms)Generate a range of dpid dpid_offset_list Every VM has allocates 1000 unique dpid offsets

Args: num_vms (int): The number of virtual machines topo_size (int): The number of topology switches

Returns: list: The dpid offset range

util.multinet_requests.handle_post_request(post_call, exit_on_fail=True)Handle the response of a REST request If the status code is not successful and the caller specifies so, sys.exitElse log the response text

Args: post_call (requests.models.Response): The response to handle exit_on_fail (Optional[bool]): True ->Exit on error status code / False -> continue

util.multinet_requests.make_post_request(host_ip, host_port, route, data=None)Make a POST request Make a POST request to a remote REST server and log the response

Args: host_ip (str): The ip of the remote REST server host_port (int): The port of the remote REST serverroute (str): The REST API endpoint data (dict): A dictionary or a list with any additional data

Returns: requests.models.Response: The HTTP response for the performed request

9

Page 14: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

util.multinet_requests.make_post_request_runner(host_ip, host_port, route, data, queue)Wrapper function to create a new job for each POST request. Make a POST request and put the response in aqueue. Used for multiprocessing.

Args: host_ip (str): The IP address of the REST server host_port (int): The port of the REST server route (str):The REST API endpoint data (str): Any additional JSON data queue (multiprocessing.Queue): The queuewhere all the responses are stored

util.multinet_requests.master_cmd(master_ip, master_port, opcode, data=None)Wrapper function to send a command to the master

Args: master_ip (str): The IP address of the master master_port (int): The port of the master opcode (str): TheREST API endpoint (the command we want to send)

Returns: requests.models.Response: The HTTP response for the performed request

util.multinet_requests.parse_arguments()Reads the arguments passed from command line.

Command line Args: –json-config (str): Compulsory argument. The path to the JSON configuration file. –serial-requests (bool): Optional argument. Defines if the requests will be sent from the master to theworkers parallely, simultaneusly to all workers, or serially, one worker each time.

Returns: collection: An object containing the values of all arguments.

util.multinet_requests.parse_json_conf(json_config)Parse a JSON configuration file. The path to this file is given from command line argument –json-config andpassed as an argument in this function.

Args: json_config (str): The path to the JSON configuration file

Returns: dict: The parsed json configuration

util.netutil module

General network utilities

util.netutil.copy_directory_to_target(ipaddr, user, passwd, local_path, remote_path, re-mote_port=22)

Copy a local directory on a remote machine.

Parameters

• ipaddr (str) – IP adress of the remote machine

• user (str) – username of the remote user

• passwd (str) – password of the remote user

• local_path (str) – directory path from local machine to copy, full location required

• remote_path (str) – remote destination, full location required

• remote_port (int) – port to perform sftp from

util.netutil.create_remote_directory(ipaddr, user, passwd, remote_path, remote_port=22)Opens an ssh connection to a remote machine and creates a new directory.

Parameters

• ipaddr (str) – Ip adress of the remote machine

• user (str) – username of the remote user

10 Chapter 5. util package

Page 15: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

• passwd (str) – password of the remote user

• remote_path (str) – maximum number of times to connect

• remote_port (int) – port to perform sftp from

util.netutil.isdir(path, sftp)Checks if a given remote path is a directory

Parameters

• path (str) – A string with the full path we want to check

• sftp (paramiko.SSHClient) – An sftp connection object (paramico)

Returns True if the given path is a directory false otherwise.

Return type bool

util.netutil.make_remote_file_executable(ipaddr, user, passwd, remote_file, re-mote_port=22)

Makes the remote file executable.

Parameters

• ipaddr (str) – Ip adress of the remote machine

• user (str) – username of the remote user

• passwd (str) – password of the remote user

• remote_file (str) – remote file to make executable

• remote_port (int) – port to perform sftp from

util.netutil.remove_remote_directory(ipaddr, user, passwd, path, remote_port=22)Removes recursively remote directories (removes all files and other sub-directories).

Parameters

• ipaddr (str) – Ip adress of the remote machine

• user (str) – username of the remote user

• passwd (str) – password of the remote user

• remote_file (str) – remote file to make executable

• remote_port (int) – port to perform sftp from

util.netutil.ssh_connect_or_return(ipaddr, user, passwd, maxretries, remote_port=22)Opens a connection and returns a connection object. If it fails to open a connection after a specified number oftries, it returns -1.

Parameters

• ipaddr (str) – Ip adress of the remote machine

• user (str) – username of the remote user

• passwd (str) – password of the remote user

• maxretries (int) – maximum number of times to connect

Returns an ssh connection handle or -1

Return type paramiko.SSHClient (or -1 when failure)

5.3. util.netutil module 11

Page 16: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

util.netutil.ssh_copy_file_to_target(ipaddr, user, passwd, local_file, remote_file, re-mote_port=22)

Copies local file on a remote machine target.

Parameters

• ipaddr (str) – Ip adress of the remote machine

• user (str) – username of the remote user

• passwd (str) – password of the remote user

• local_file (str) – file from local machine to copy,full location required

• remote_file (str) – remote destination, full location required i.e /tmp/foo.txt

• remote_port (int) – port to perform sftp from

util.netutil.ssh_delete_file_if_exists(ipaddr, user, passwd, remote_file, remote_port=22)Deletes the file on e remote machine, if it exists

Parameters

• ipaddr (str) – Ip adress of the remote machine

• user (str) – username of the remote user

• passwd (str) – password of the remote user

• remote_file (str) – remote file to remove, full path must be used.

• remote_port (int) – port to perform sftp from

util.netutil.ssh_run_command(ssh_session, command_to_run)Runs the specified command on a remote machine

:param ssh_session : SSH session provided by paramiko to run the command :param command_to_run: Com-mand to execute :returns: the output of the remotely executed command :rtype: tuple (stdin, stdout, stderr) :typessh_session: paramiko.SSHClient :type command_to_run: str

Module contents

12 Chapter 5. util package

Page 17: MULTINET Documentation

CHAPTER 6

Indices and tables

• genindex

• modindex

• search

13

Page 18: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

14 Chapter 6. Indices and tables

Page 19: MULTINET Documentation

Python Module Index

bbin, 1

mmulti, 4multi.master, 3

nnet, 5

ttest, 7

uutil, 12util.multinet_requests, 9util.netutil, 10

15

Page 20: MULTINET Documentation

MULTINET Documentation, Release 1.0.1

16 Python Module Index

Page 21: MULTINET Documentation

Index

Aaggregate_broadcast_response() (in module

util.multinet_requests), 9

Bbin (module), 1broadcast_cmd() (in module util.multinet_requests), 9

Ccopy_directory_to_target() (in module util.netutil), 10create_remote_directory() (in module util.netutil), 10

Ddetect_hosts() (in module multi.master), 3dpid_offset_range() (in module util.multinet_requests), 9

Ggenerate_traffic() (in module multi.master), 3get_flows() (in module multi.master), 3get_switches() (in module multi.master), 3

Hhandle_post_request() (in module util.multinet_requests),

9

Iinit() (in module multi.master), 3isdir() (in module util.netutil), 11

Mmake_post_request() (in module util.multinet_requests),

9make_post_request_runner() (in module

util.multinet_requests), 10make_remote_file_executable() (in module util.netutil),

11master_cmd() (in module util.multinet_requests), 10multi (module), 4multi.master (module), 3

Nnet (module), 5

Pparse_arguments() (in module util.multinet_requests), 10parse_json_conf() (in module util.multinet_requests), 10ping_all() (in module multi.master), 3

Rremove_remote_directory() (in module util.netutil), 11rest_start() (in module multi.master), 4

Sssh_connect_or_return() (in module util.netutil), 11ssh_copy_file_to_target() (in module util.netutil), 11ssh_delete_file_if_exists() (in module util.netutil), 12ssh_run_command() (in module util.netutil), 12start() (in module multi.master), 4stop() (in module multi.master), 4

Ttest (module), 7

Uutil (module), 12util.multinet_requests (module), 9util.netutil (module), 10

17