def create_topology(): net = DCNetwork(monitor=False, enable_learning=True) # create two data centers dc1 = net.addDatacenter("dc1") dc2 = net.addDatacenter("dc2") # interconnect data centers net.addLink(dc1, dc2, delay="20ms") # add the command line interface endpoint to the emulated DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) rapi1.connectDatacenter(dc2) rapi1.start() # add the 5GTANGO lightweight life cycle manager (LLCM) to the topology llcm1 = TangoLLCMEndpoint("0.0.0.0", 5000, deploy_sap=False, placement_algorithm_obj=StaticConfigPlacement( "~/static_placement.yml")) llcm1.connectDatacenter(dc1) llcm1.connectDatacenter(dc2) # run the dummy gatekeeper (in another thread, don't block) llcm1.start() # start the emulation and enter interactive CLI net.start() net.CLI() # when the user types exit in the CLI, we stop the emulator net.stop()
class EmulatorProfilingTopology(object): def __init__(self): pass def start(self): LOG.info("Starting emulation ...") setLogLevel('info') # set Mininet loglevel # create topology self.net = DCNetwork(monitor=False, enable_learning=False) # we only need one DC for benchmarking dc = self.net.addDatacenter("dc1") # add the command line interface endpoint to each DC (REST API) self.rapi1 = RestApiEndpoint("0.0.0.0", 5001) self.rapi1.connectDCNetwork(self.net) self.rapi1.connectDatacenter(dc) self.rapi1.start() # add the 5GTANGO lightweight life cycle manager (LLCM) to the topology self.llcm1 = TangoLLCMEndpoint("0.0.0.0", 5000, deploy_sap=False) self.llcm1.connectDatacenter(dc) self.llcm1.start() self.net.start() def stop(self): LOG.info("Stopping emulation ...") self.rapi1.stop() self.llcm1.stop() self.net.stop()
def start(self): LOG.info("Starting emulation ...") # pylint: disable=E0401 from mininet.log import setLogLevel from emuvim.dcemulator.net import DCNetwork from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint from emuvim.api.tango import TangoLLCMEndpoint setLogLevel('info') # set Mininet loglevel # create topology self.net = DCNetwork(monitor=False, enable_learning=False) # we only need one DC for benchmarking dc = self.net.addDatacenter("dc1") # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(self.net) rapi1.connectDatacenter(dc) rapi1.start() # add the 5GTANGO lightweight life cycle manager (LLCM) to the topology llcm1 = TangoLLCMEndpoint("0.0.0.0", 5000, deploy_sap=False) llcm1.connectDatacenter(dc) llcm1.start() self.net.start()
def create_topology(): net = DCNetwork(monitor=False, enable_learning=True) # create two data centers dc1 = net.addDatacenter("dc1") dc2 = net.addDatacenter("dc2") # interconnect data centers net.addLink(dc1, dc2, delay="20ms") # add the command line interface endpoint to the emulated DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) rapi1.connectDatacenter(dc2) rapi1.start() # add the 5GTANGO lightweight life cycle manager (LLCM) to the topology llcm1 = TangoLLCMEndpoint("0.0.0.0", 5000, deploy_sap=False) llcm1.connectDatacenter(dc1) llcm1.connectDatacenter(dc2) # run the dummy gatekeeper (in another thread, don't block) llcm1.start() # start the emulation and enter interactive CLI net.start() net.CLI() # when the user types exit in the CLI, we stop the emulator net.stop()
def test_tango_llcm_start_service(self): # create network self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0, enable_learning=True) # setup links self.net.addLink(self.dc[0], self.h[0]) self.net.addLink(self.dc[0], self.dc[1]) self.net.addLink(self.h[1], self.dc[1]) # connect llcm to data centers sdkg1 = TangoLLCMEndpoint("127.0.0.1", 56000) sdkg1.connectDatacenter(self.dc[0]) sdkg1.connectDatacenter(self.dc[1]) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() time.sleep(3) # start Mininet network self.startNet() time.sleep(3) # board package files = {"package": open(PACKAGE_PATH, "rb")} r = requests.post("http://127.0.0.1:56000/packages", files=files) self.assertEqual(r.status_code, 201) self.assertTrue(json.loads(r.text).get("service_uuid") is not None) # instantiate service self.service_uuid = json.loads(r.text).get("service_uuid") r2 = requests.post("http://127.0.0.1:56000/instantiations", data=json.dumps({"service_uuid": self.service_uuid})) self.assertEqual(r2.status_code, 201) # give the emulator some time to instantiate everything time.sleep(2) # check get request APIs r3 = requests.get("http://127.0.0.1:56000/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:56000/instantiations") self.assertEqual(len(json.loads(r4.text).get( "service_instantiations_list")), 1) # check number of running nodes self.assertTrue(len(self.getContainernetContainers()) == 2) self.assertTrue(len(self.net.hosts) == 4) self.assertTrue(len(self.net.switches) == 2) # check compute list result (considering placement) self.assertEqual(len(self.dc[0].listCompute()), 1) self.assertEqual(len(self.dc[1].listCompute()), 1) # check connectivity by using ping ELAN_list = [] # check E-Line connection, by checking the IP addresses for link in self.net.deployed_elines: vnf_src, intf_src = parse_interface( link['connection_points_reference'][0]) print vnf_src, intf_src src = self.net.getNodeByName(vnf_src) if not src: continue network_list = src.getNetworkStatus() src_ip = [intf['ip'] for intf in network_list if intf['intf_name'] == intf_src][0] src_mask = [intf['netmask'] for intf in network_list if intf['intf_name'] == intf_src][0] vnf_dst, intf_dst = parse_interface( link['connection_points_reference'][1]) dst = self.net.getNodeByName(vnf_dst) if not dst: continue network_list = dst.getNetworkStatus() dst_ip = [intf['ip'] for intf in network_list if intf['intf_name'] == intf_dst][0] dst_mask = [intf['netmask'] for intf in network_list if intf['intf_name'] == intf_dst][0] print "src = {0}:{1} ip={2} ".format( vnf_src, intf_src, src_ip, src_mask) print "dst = {0}:{1} ip={2} ".format( vnf_dst, intf_dst, dst_ip, dst_mask) # check if the E-Line IP's are in the same subnet ret = ip_network(u'{0}'.format(src_ip, src_mask), strict=False)\ .compare_networks(ip_network(u'{0}'.format(dst_ip, dst_mask), strict=False)) self.assertTrue(ret == 0) for vnf in self.dc[0].listCompute(): # check E LAN connection network_list = vnf.getNetworkStatus() mgmt_ip = [intf['ip'] for intf in network_list if intf['intf_name'] == 'mgmt'] self.assertTrue(len(mgmt_ip) > 0) ip_address = mgmt_ip[0] ELAN_list.append(ip_address) print ip_address # check ELAN connection by ping over the mgmt network (needs to be # configured as ELAN in the test service) for vnf in self.dc[0].listCompute(): network_list = vnf.getNetworkStatus() mgmt_ip = [intf['ip'] for intf in network_list if intf['intf_name'] == 'mgmt'] self.assertTrue(len(mgmt_ip) > 0) ip_address = mgmt_ip[0] print ELAN_list print ip_address test_ip_list = list(ELAN_list) test_ip_list.remove(ip_address) for ip in test_ip_list: # only take ip address, without netmask p = self.net.ping([vnf], manualdestip=ip.split('/')[0]) print p self.assertTrue(p <= 0.0) # stop Mininet network self.stopNet() initialize_GK()
def test_tango_llcm_stop_service(self): # create network self.createNet(ndatacenter=2, nhosts=2) # setup links self.net.addLink(self.dc[0], self.h[0]) self.net.addLink(self.dc[0], self.dc[1]) self.net.addLink(self.h[1], self.dc[1]) # connect dummy GK to data centers sdkg1 = TangoLLCMEndpoint("127.0.0.1", 56001) sdkg1.connectDatacenter(self.dc[0]) sdkg1.connectDatacenter(self.dc[1]) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() time.sleep(3) # start Mininet network self.startNet() time.sleep(3) print "starting tests" # board package files = {"package": open(PACKAGE_PATH, "rb")} r = requests.post("http://127.0.0.1:56001/packages", files=files) self.assertEqual(r.status_code, 201) self.assertTrue(json.loads(r.text).get("service_uuid") is not None) # instantiate service self.service_uuid = json.loads(r.text).get("service_uuid") r2 = requests.post("http://127.0.0.1:56001/instantiations", data=json.dumps({"service_uuid": self.service_uuid})) self.assertEqual(r2.status_code, 201) # give the emulator some time to instantiate everything time.sleep(2) # check get request APIs r3 = requests.get("http://127.0.0.1:56001/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:56001/instantiations") self.assertEqual(len(json.loads(r4.text).get( "service_instantiations_list")), 1) # check number of running nodes self.assertTrue(len(self.getContainernetContainers()) == 2) self.assertTrue(len(self.net.hosts) == 4) self.assertTrue(len(self.net.switches) == 2) # check compute list result (considering placement) self.assertEqual(len(self.dc[0].listCompute()), 1) self.assertEqual(len(self.dc[1].listCompute()), 1) # stop the service service_instance_uuid = json.loads( r2.text).get("service_instance_uuid") self.assertTrue(service_instance_uuid is not None) requests.delete("http://127.0.0.1:56001/instantiations", data=json.dumps( {"service_uuid": self.service_uuid, "service_instance_uuid": service_instance_uuid})) r5 = requests.get("http://127.0.0.1:56001/instantiations") # note that there was 1 instance before self.assertTrue(len(json.loads(r5.text).get( "service_instantiations_list")), 0) # stop Mininet network self.stopNet() initialize_GK()
class Emulator(DockerBasedVIM): """ 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 */ """ def __init__(self, endpoint_port=None, tango_port=None, sonata_port=None, enable_learning=False, vnv_checker=False, *args, **kwargs): """ Initialize the Emulator. This method doesn't start the Emulator. Args: endpoint_port (int): vim-emu REST API port. Default: random free port tango_port (int): Sonata gatekeeper port. Default: random free port sonata_port (int): Tango gatekeeper port. Default: random free port vnv_checker (bool): Check if the code can be reused on the 5GTANGO V&V platform enable_learning (bool): Enable learning switch """ super(Emulator, self).__init__(*args, **kwargs) self.endpoint_port = endpoint_port self.tango_port = tango_port self.sonata_port = sonata_port self.vnv_checker = vnv_checker self.enable_learning = enable_learning @property def InstanceClass(self): return EmulatorInstance @vnv_checker_start def start(self): """ Run the Emulator and the endpoints. """ super(Emulator, self).start() initialize_GK() self.net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=self.enable_learning) self.datacenter = self.net.addDatacenter('dc1') endpoint_ip = '0.0.0.0' endpoint_port = self.endpoint_port or get_free_tcp_port() self.endpoint = 'http://{}:{}'.format(endpoint_ip, endpoint_port) self.rest_api = RestApiEndpoint(endpoint_ip, endpoint_port) self.rest_api.connectDCNetwork(self.net) self.rest_api.connectDatacenter(self.datacenter) self.rest_api.start() sonata_ip = '0.0.0.0' sonata_port = self.sonata_port or get_free_tcp_port() self.sonata_address = 'http://{}:{}'.format(sonata_ip, sonata_port) self.sonata_gatekeeper = SonataDummyGatekeeperEndpoint( sonata_ip, sonata_port) self.sonata_gatekeeper.connectDatacenter(self.datacenter) self.sonata_gatekeeper.start() tango_ip = '0.0.0.0' tango_port = self.tango_port or get_free_tcp_port() self.tango_address = 'http://{}:{}'.format(tango_ip, tango_port) self.tango_gatekeeper = TangoLLCMEndpoint(tango_ip, tango_port) self.tango_gatekeeper.connectDatacenter(self.datacenter) self.tango_gatekeeper.start() self.net.start() @vnv_checker_stop def stop(self): """ Stop the Emulator and the endpoints. """ self.rest_api.stop() self.net.stop() super(Emulator, self).stop() @vnv_called_once def add_instances_from_package(self, package, package_format='tango'): if not os.path.isfile(package): raise Exception('Package {} not found'.format(package)) if package_format == 'tango': gatekeeper_address = self.tango_address elif package_format == 'sonata': gatekeeper_address = self.sonata_address else: raise Exception( 'package_format must be "tango" or "sonata", passed {}.'. format(package_format)) # Upload the package with open(package, 'rb') as package_content: files = {'package': package_content} url = '{}/packages'.format(gatekeeper_address) response = requests.post(url, files=files) if not response.ok: raise Exception('Something went wrong during uploading.') # Instantiate the service url = '{}/instantiations'.format(gatekeeper_address) response = requests.post(url, data='{}') if not response.ok: raise Exception('Something went wrong during instantiation.') instances = [] for name, instance in self.datacenter.containers.items(): if name in self.instances: continue instances.append(self._add_instance(name)) return instances @vnv_called_without_parameter('interfaces') def add_instance_from_image(self, name, image, interfaces=None, docker_command=None): """ Run a Docker image on the Emulator. Args: 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: (EmulatorInstance): The added instance """ if not self._image_exists(image): raise Exception('Docker image {} not found'.format(image)) if not interfaces: interfaces = '(id=emu0)' elif isinstance(interfaces, str): pass elif isinstance(interfaces, int): interfaces = ','.join( ['(id=emu{})'.format(i) for i in range(interfaces)]) elif isinstance(interfaces, list): interfaces = ','.join(['(id={})'.format(i) for i in interfaces]) elif isinstance(interfaces, dict): interfaces = ','.join( ['(id={},ip={})'.format(k, v) for k, v in interfaces.items()]) else: raise Exception( 'Wrong network configuration: {}'.format(interfaces)) params = { 'name': name, 'image': image, 'command': docker_command, 'network': interfaces, 'endpoint': self.endpoint, 'datacenter': 'dc1' } EmuComputeClient().start(params) return self._add_instance(name) @vnv_called_without_parameter('interfaces') def add_instance_from_source(self, name, path, interfaces=None, image_name=None, docker_command=None, **docker_build_args): """ Build and run a Docker image on the Emulator. Args: 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: (EmulatorInstance): The added instance """ return super(Emulator, self).add_instance_from_source(name, path, interfaces, image_name, docker_command, **docker_build_args) @vnv_not_called def add_link(self, src_vnf, src_if, dst_vnf, dst_if, sniff=False, **kwargs): result = super(Emulator, self).add_link(src_vnf, src_if, dst_vnf, dst_if, sniff, **kwargs) if result: return result params = { 'source': '{}:{}'.format(src_vnf, src_if), 'destination': '{}:{}'.format(dst_vnf, dst_if), 'weight': kwargs.get('weight'), 'match': kwargs.get('match'), 'bidirectional': kwargs.get('bidirectional', True), 'cookie': kwargs.get('cookie'), 'priority': kwargs.get('priority'), 'endpoint': self.endpoint } return EmuNetworkClient().add(params)