def create_topology1(): # create topology net = DCNetwork(controller=RemoteController, monitor=True, enable_learning=True) dc1 = net.addDatacenter("dc1") # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) # run API endpoint server (in another thread, don't block) rapi1.start() # specify a vnfd file to be deployed as internal SAP: sap_vnfd = 'custom_sap_vnfd.yml' dir_path = os.path.dirname(__file__) sap_vnfd_path = os.path.join(dir_path, sap_vnfd) sap_vnfd_path = None # add the SONATA dummy gatekeeper to each DC sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=True, auto_deploy=True, docker_management=True, auto_delete=True, sap_vnfd_path=sap_vnfd_path) sdkg1.connectDatacenter(dc1) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start the emulation platform net.start() net.CLI() net.stop()
def create_topology1(): # create topology net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=True) dc1 = net.addDatacenter("dc1") dc2 = net.addDatacenter("dc2") s1 = net.addSwitch("s1") net.addLink(dc1, s1, delay="10ms") net.addLink(dc2, s1, delay="20ms") # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) rapi1.connectDatacenter(dc2) # run API endpoint server (in another thread, don't block) rapi1.start() # add the SONATA dummy gatekeeper to each DC sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=False) sdkg1.connectDatacenter(dc1) sdkg1.connectDatacenter(dc2) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start the emulation platform net.start() net.CLI() rapi1.stop() net.stop()
def __init__(self, port=5000): GracefulKiller(self) # create topology self.net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=False) self.dc = self.net.addDatacenter("dc1") # add the command line interface endpoint to each DC (REST API) self.rapi1 = RestApiEndpoint("0.0.0.0", port + 1) self.rapi1.connectDCNetwork(self.net) self.rapi1.connectDatacenter(self.dc) # run API endpoint server (in another thread, don't block) self.rapi1.start() # add the SONATA dummy gatekeeper to each DC self.sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", port, deploy_sap=False) self.sdkg1.connectDatacenter(self.dc) # run the dummy gatekeeper (in another thread, don't block) self.sdkg1.start() self.net.start() LOG.info("Started topology") while (not self.stop_now): sleep(1) self.net.stop() LOG.info("Stopped topology")
def test_GK_Api_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 = SonataDummyGatekeeperEndpoint("127.0.0.1", 55001) 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:55001/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:55001/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:55001/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:55001/instantiations") self.assertEqual(len(json.loads(r4.text).get("service_instantiations_list")), 1) # check number of running nodes self.assertTrue(len(self.getContainernetContainers()) == 3) self.assertTrue(len(self.net.hosts) == 5) self.assertTrue(len(self.net.switches) == 2) # check compute list result self.assertEqual(len(self.dc[0].listCompute()), 2) # 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:55001/instantiations", data=json.dumps({"service_uuid": self.service_uuid, "service_instance_uuid":service_instance_uuid})) r5 = requests.get("http://127.0.0.1:55001/instantiations") self.assertTrue(len(json.loads(r5.text).get("service_instantiations_list")), 0) # note that there was 1 instance before # stop Mininet network self.stopNet() initialize_GK()
class DaemonTopology(object): def __init__(self): self.running = True signal.signal(signal.SIGINT, self._stop_by_signal) signal.signal(signal.SIGTERM, self._stop_by_signal) # create and start topology self.create_topology() self.start_topology() self.daemonize() self.stop_topology() def create_topology(self): self.net = DCNetwork(monitor=False, enable_learning=False) self.dc1 = self.net.addDatacenter("dc1") #self.dc2 = self.net.addDatacenter("dc2") #self.net.addLink(self.dc1, self.dc2, cls=TCLink, delay="20ms") # add OpenStack-like APIs to the emulated DC self.api1 = OpenstackApiEndpoint("0.0.0.0", 6001) self.api1.connect_datacenter(self.dc1) #self.api1.connect_datacenter(self.dc2) self.api1.connect_dc_network(self.net) # add the command line interface endpoint to the emulated DC (REST API) self.rapi1 = RestApiEndpoint("0.0.0.0", 5001) self.rapi1.connectDCNetwork(self.net) self.rapi1.connectDatacenter(self.dc1) #self.rapi1.connectDatacenter(self.dc2) self.sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=False) self.sdkg1.connectDatacenter(self.dc1) #self.sdkg1.connectDatacenter(self.dc2) def start_topology(self): self.api1.start() self.rapi1.start() self.sdkg1.start() self.net.start() def daemonize(self): print("Daemonizing vim-emu. Send SIGTERM or SIGKILL to stop.") while self.running: time.sleep(1) def _stop_by_signal(self, signum, frame): print("Received SIGNAL {}. Stopping.".format(signum)) self.running = False def stop_topology(self): self.api1.stop() self.rapi1.stop() #self.sdkg1.stop() self.net.stop()
def testAPI(self): # create network self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0) # 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 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000) sdkg1.connectDatacenter(self.dc[0]) sdkg1.connectDatacenter(self.dc[1]) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start Mininet network self.startNet() time.sleep(1) print "starting tests" # board package files = {"package": open(PACKAGE_PATH, "rb")} r = requests.post("http://127.0.0.1:5000/packages", files=files) self.assertEqual(r.status_code, 200) self.assertTrue(json.loads(r.text).get("service_uuid") is not None) # instantiate service service_uuid = json.loads(r.text).get("service_uuid") r2 = requests.post("http://127.0.0.1:5000/instantiations", data=json.dumps({"service_uuid": service_uuid})) self.assertEqual(r2.status_code, 200) # give the emulator some time to instantiate everything time.sleep(2) # check get request APIs r3 = requests.get("http://127.0.0.1:5000/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:5000/instantiations") self.assertEqual(len(json.loads(r4.text).get("service_instance_list")), 1) # check number of running nodes self.assertTrue(len(self.getContainernetContainers()) == 3) self.assertTrue(len(self.net.hosts) == 5) self.assertTrue(len(self.net.switches) == 2) # check compute list result self.assertTrue(len(self.dc[0].listCompute()) == 3) # check connectivity by using ping for vnf in self.dc[0].listCompute(): self.assertTrue(self.net.ping([self.h[0], vnf]) <= 0.0) # stop Mininet network self.stopNet()
def __init__(self): GracefulKiller(self) # create topology self.net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=False) self.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(self.dc) # run API endpoint server (in another thread, don't block) self.rapi1.start() # add the SONATA dummy gatekeeper to each DC self.sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=False) self.sdkg1.connectDatacenter(self.dc) # run the dummy gatekeeper (in another thread, don't block) self.sdkg1.start() self.net.start() LOG.info("Started topology") while(not self.stop_now): sleep(1) self.net.stop() LOG.info("Stopped topology")
def test_GK_stress_service(self): # create network self.createNet(ndatacenter=2, nhosts=2) # connect dummy GK to data centers sdkg1 = SonataDummyGatekeeperEndpoint("127.0.0.1", 55002) 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("misc/sonata-stress-service.son", "rb")} r = requests.post("http://127.0.0.1:55002/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:55002/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:55002/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:55002/instantiations") self.assertEqual(len(json.loads(r4.text).get("service_instantiations_list")), 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:55002/instantiations", data=json.dumps({"service_uuid": self.service_uuid, "service_instance_uuid":service_instance_uuid})) r5 = requests.get("http://127.0.0.1:55002/instantiations") self.assertTrue(len(json.loads(r5.text).get("service_instantiations_list")), 0) # note that there was 1 instance before # stop Mininet network self.stopNet() initialize_GK()
class Profiling: stop_now = False """ Set up a simple topology and start it :port: the port the REST interface will be using, port+1 will be in use as well """ def __init__(self, port=5000): GracefulKiller(self) # create topology self.net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=False) self.dc = self.net.addDatacenter("dc1") # add the command line interface endpoint to each DC (REST API) self.rapi1 = RestApiEndpoint("0.0.0.0", port + 1) self.rapi1.connectDCNetwork(self.net) self.rapi1.connectDatacenter(self.dc) # run API endpoint server (in another thread, don't block) self.rapi1.start() # add the SONATA dummy gatekeeper to each DC self.sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", port, deploy_sap=False) self.sdkg1.connectDatacenter(self.dc) # run the dummy gatekeeper (in another thread, don't block) self.sdkg1.start() self.net.start() LOG.info("Started topology") while (not self.stop_now): sleep(1) self.net.stop() LOG.info("Stopped topology") """ Set stop value to stop the topology """ def stop_it(self): self.stop_now = True
def create_topology(self): self.net = DCNetwork(monitor=False, enable_learning=False) self.dc1 = self.net.addDatacenter("dc1") #self.dc2 = self.net.addDatacenter("dc2") #self.net.addLink(self.dc1, self.dc2, cls=TCLink, delay="20ms") # add OpenStack-like APIs to the emulated DC self.api1 = OpenstackApiEndpoint("0.0.0.0", 6001) self.api1.connect_datacenter(self.dc1) #self.api1.connect_datacenter(self.dc2) self.api1.connect_dc_network(self.net) # add the command line interface endpoint to the emulated DC (REST API) self.rapi1 = RestApiEndpoint("0.0.0.0", 5001) self.rapi1.connectDCNetwork(self.net) self.rapi1.connectDatacenter(self.dc1) #self.rapi1.connectDatacenter(self.dc2) self.sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=False) self.sdkg1.connectDatacenter(self.dc1)
def create_topology1(): # create topology net = DCNetwork(controller=RemoteController, monitor=True, enable_learning=True) dc1 = net.addDatacenter("dc1") net.addLink(dc1, net.addSwitch("s1"), delay="10ms") # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) # run API endpoint server (in another thread, don't block) rapi1.start() # add the SONATA dummy gatekeeper to each DC sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=True, auto_deploy=True) sdkg1.connectDatacenter(dc1) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start the emulation platform net.start() net.CLI() net.stop()
def create_topology1(): # create topology net = DCNetwork(controller=RemoteController, monitor=True, enable_learning=True) dc1 = net.addDatacenter("dc1") # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) # run API endpoint server (in another thread, don't block) rapi1.start() # specify a vnfd file to be deployed as internal SAP: sap_vnfd = 'custom_sap_vnfd.yml' dir_path = os.path.dirname(__file__) sap_vnfd_path = os.path.join(dir_path, sap_vnfd) # sap_vnfd_path = None # add the SONATA dummy gatekeeper to each DC sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=True, auto_deploy=True, docker_management=True, auto_delete=True, sap_vnfd_path=sap_vnfd_path) sdkg1.connectDatacenter(dc1) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start the emulation platform net.start() net.CLI() net.stop()
def create_topology1(): # create topology net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=False) # add datecenters dc1 = net.addDatacenter("dc1") dc2 = net.addDatacenter("dc2") # add some intermediate switch s1 = net.addSwitch("s1") # connect data centers net.addLink(dc1, s1, delay="10ms") net.addLink(dc2, s1, delay="20ms") # add REST control endpoints to each datacenter (to be used with son-emu-cli) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) rapi1.connectDatacenter(dc2) rapi1.start() # add the SONATA dummy gatekeeper to each DC sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000) sdkg1.connectDatacenter(dc1) sdkg1.connectDatacenter(dc2) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start the emulation platform net.start() net.CLI() net.stop()
def create_topology1(): global exit # create topology net = DCNetwork(controller=RemoteController, monitor=True, enable_learning=False) dc1 = net.addDatacenter("dc1") dc2 = net.addDatacenter("dc2") s1 = net.addSwitch("s1") net.addLink(dc1, s1, delay="10ms") net.addLink(dc2, s1, delay="20ms") # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDatacenter(dc1) rapi1.connectDatacenter(dc2) # connect total network also, needed to do the chaining and monitoring rapi1.connectDCNetwork(net) # run API endpoint server (in another thread, don't block) rapi1.start() # add the SONATA dummy gatekeeper to each DC sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=True) sdkg1.connectDatacenter(dc1) sdkg1.connectDatacenter(dc2) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start the emulation platform net.start() # does not work from docker compose (cannot start container in interactive mode) # cli = net.CLI() # instead wait here: logging.info("waiting for SIGTERM or SIGINT signal") while not exit: time.sleep(1) logging.info("got SIG signal") net.stop()
def _create_dummygk_api_endpoints(self): # create apiSDK = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000) # connect PoPs apiSDK.connectDatacenter(self.pop1) apiSDK.connectDatacenter(self.pop2) # start apiSDK.start()
def test_GK_stress_service(self): # create network self.createNet(ndatacenter=2, nhosts=2) # connect dummy GK to data centers sdkg1 = SonataDummyGatekeeperEndpoint("127.0.0.1", 55002) 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("misc/sonata-stress-service.son", "rb")} r = requests.post("http://127.0.0.1:55002/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:55002/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:55002/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:55002/instantiations") self.assertEqual( len(json.loads(r4.text).get("service_instantiations_list")), 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:55002/instantiations", data=json.dumps({ "service_uuid": self.service_uuid, "service_instance_uuid": service_instance_uuid })) r5 = requests.get("http://127.0.0.1:55002/instantiations") self.assertTrue( len(json.loads(r5.text).get("service_instantiations_list")), 0) # note that there was 1 instance before # stop Mininet network self.stopNet() initialize_GK()
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()
def setup_topology(net): _LOGGER.info("Setting up the topology") dc = net.addDatacenter("dc1") # pylint: disable=invalid-name net.addLink(dc, net.addSwitch("s1"), delay="10ms") # add the SONATA dummy gatekeeper to each DC rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc) rapi1.start() sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=False) sdkg1.connectDatacenter(dc) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start()
def create_topology1(): global exit # create topology net = DCNetwork(controller=RemoteController, monitor=True, enable_learning=False) dc1 = net.addDatacenter("dc1") dc2 = net.addDatacenter("dc2") s1 = net.addSwitch("s1") net.addLink(dc1, s1, delay="10ms") net.addLink(dc2, s1, delay="20ms") # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDatacenter(dc1) rapi1.connectDatacenter(dc2) # connect total network also, needed to do the chaining and monitoring rapi1.connectDCNetwork(net) # run API endpoint server (in another thread, don't block) rapi1.start() # add the SONATA dummy gatekeeper to each DC sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000, deploy_sap=True) sdkg1.connectDatacenter(dc1) sdkg1.connectDatacenter(dc2) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start the emulation platform net.start() #does not work from docker compose (cannot start container in interactive mode) #cli = net.CLI() # instead wait here: logging.info("waiting for SIGTERM or SIGINT signal") while not exit: time.sleep(1) logging.info("got SIG signal") net.stop()
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)
def create_topology1(): # create topology net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=False) dc1 = net.addDatacenter("dc1") dc2 = net.addDatacenter("dc2") s1 = net.addSwitch("s1") linkopts = dict(delay="1ms",bw=100) net.addLink(dc1, s1, **linkopts) net.addLink(dc2, s1, **linkopts) # add the command line interface endpoint to each DC (REST API) rapi1 = RestApiEndpoint("0.0.0.0", 5001) rapi1.connectDCNetwork(net) rapi1.connectDatacenter(dc1) rapi1.connectDatacenter(dc2) # run API endpoint server (in another thread, don't block) rapi1.start() # add the SONATA dummy gatekeeper to each DC sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000) sdkg1.connectDatacenter(dc1) sdkg1.connectDatacenter(dc2) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start the emulation platform net.start() # create hosts and vnfs #use ./init_vnfs_rubis for rubis experiments #use ./init_vnfs for stratos experiments subprocess.call("./init_vnfs_rubis.sh",shell=True) subprocess.call("./chain_vnfs.sh",shell=True) fw, snort, client, server = net.getNodeByName('fw','snort','client','server') print "Waiting warmup" time.sleep(10) #run experiment #CONFIGURE number of cores cores = 4 for i in range(0,4): #Set here the number of repetitions for fwbw in [5,50,100]: # set here the network bandwidth range for the firewall for snortbw in [5,50,100]: # set here the network bandwidth range for the dpi for reqsize in ['128KB']: #available sizes are: '4KB','8KB','16KB','32KB','64KB','128KB','256KB','512KB','1024KB','2048KB','4096KB','8192KB','16384KB','32768KB']: for fwcpu in [5,50,100]: # set here the cpu capacity range for the firewall, 5 means 5% of one cpu for snortcpu in [5,50,100]: # set here the cpu capacity range for the dpi, 5 means 5% of one cpu r=0 fw.setParam(r,'setCPUFrac',cpu=fwcpu/(cores*100)) snort.setParam(r,'setCPUFrac',cpu=snortcpu/(cores*100)) strcmd = "%s %d %d %d %d %s %d &" % ('./start_firewall.sh',fwbw,snortbw,fwcpu,snortcpu,reqsize,i) fw.cmd(strcmd) time.sleep(1) strcmd = "%s %d %d %d %d %s %d &" % ('./start_snort.sh',fwbw,snortbw,fwcpu,snortcpu,reqsize,i) snort.cmd(strcmd) strcmd = "%s %d %d %d %d %s %d &" % ('./start_server.sh',fwbw,snortbw,fwcpu,snortcpu,reqsize,i) server.cmd(strcmd) time.sleep(1) client.cmd("ping -c 2 10.0.0.50 >> log-ping") client.cmd("ping -c 2 10.0.0.50 >> log-ping") strcmd = "%s %d %d %d %d %s %d &" % ('./start_client.sh',fwbw,snortbw,fwcpu,snortcpu,reqsize,i) client.cmd(strcmd) #the parameter for iperfc is the target bandwidth strcmd = "%s %d" % ('./start_iperfc.sh',30) client.cmd(strcmd) print "Waiting to the experiment %d-%d-%d-%d-%s-%d"%(fwbw,snortbw,fwcpu,snortcpu,reqsize,i) #use 180 for rubis workload #use 100 for the stratos time.sleep(180) print "Copy results and cleanup" strcmd = "scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no guiltiness* [email protected]:/home/vagrant/son-emu/logs/" fw.cmd(strcmd) snort.cmd(strcmd) strcmd = "scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no log* [email protected]:/home/vagrant/son-emu/logs/" client.cmd(strcmd) server.cmd(strcmd) fw.cmd("rm guiltiness*") snort.cmd("rm guiltiness*") client.cmd("rm log*") server.cmd("rm log*")
def test_GK_Api_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 = SonataDummyGatekeeperEndpoint("127.0.0.1", 55001) 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:55001/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:55001/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:55001/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:55001/instantiations") self.assertEqual( len(json.loads(r4.text).get("service_instantiations_list")), 1) # check number of running nodes self.assertTrue(len(self.getContainernetContainers()) == 3) self.assertTrue(len(self.net.hosts) == 5) self.assertTrue(len(self.net.switches) == 2) # check compute list result self.assertEqual(len(self.dc[0].listCompute()), 2) # 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:55001/instantiations", data=json.dumps({ "service_uuid": self.service_uuid, "service_instance_uuid": service_instance_uuid })) r5 = requests.get("http://127.0.0.1:55001/instantiations") self.assertTrue( len(json.loads(r5.text).get("service_instantiations_list")), 0) # note that there was 1 instance before # stop Mininet network self.stopNet() initialize_GK()
def test_GK_Api_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 dummy GK to data centers sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000) sdkg1.connectDatacenter(self.dc[0]) sdkg1.connectDatacenter(self.dc[1]) # run the dummy gatekeeper (in another thread, don't block) sdkg1.start() # start Mininet network self.startNet() time.sleep(1) print "starting tests" # board package files = {"package": open(PACKAGE_PATH, "rb")} r = requests.post("http://127.0.0.1:5000/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:5000/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:5000/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:5000/instantiations") self.assertEqual( len(json.loads(r4.text).get("service_instantiations_list")), 1) # check number of running nodes self.assertTrue(len(self.getContainernetContainers()) == 3) self.assertTrue(len(self.net.hosts) == 5) self.assertTrue(len(self.net.switches) == 2) # check compute list result self.assertEqual(len(self.dc[0].listCompute()), 2) # check connectivity by using ping ELAN_list = [] for i in [0]: for vnf in self.dc[i].listCompute(): # check connection p = self.net.ping([self.h[i], vnf]) print p self.assertTrue(p <= 0.0) # 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: p = self.net.ping([vnf], manualdestip=ip) print p self.assertTrue(p <= 0.0) # stop Mininet network self.stopNet() initialize_GK()
def test_GK_Api_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 dummy GK to data centers sdkg1 = SonataDummyGatekeeperEndpoint("127.0.0.1", 55000) 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:55000/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:55000/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:55000/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:55000/instantiations") self.assertEqual(len(json.loads(r4.text).get("service_instantiations_list")), 1) # check number of running nodes self.assertTrue(len(self.getContainernetContainers()) == 3) self.assertTrue(len(self.net.hosts) == 5) self.assertTrue(len(self.net.switches) == 2) # check compute list result self.assertEqual(len(self.dc[0].listCompute()), 2) # 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, vnf_sap_docker_name = 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, vnf_sap_docker_name = 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_GK_Api_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 dummy GK to data centers sdkg1 = SonataDummyGatekeeperEndpoint("127.0.0.1", 55000) 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:55000/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:55000/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:55000/packages") self.assertEqual(len(json.loads(r3.text).get("service_uuid_list")), 1) r4 = requests.get("http://127.0.0.1:55000/instantiations") self.assertEqual( len(json.loads(r4.text).get("service_instantiations_list")), 1) # check number of running nodes self.assertTrue(len(self.getContainernetContainers()) == 3) self.assertTrue(len(self.net.hosts) == 5) self.assertTrue(len(self.net.switches) == 2) # check compute list result self.assertEqual(len(self.dc[0].listCompute()), 2) # 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, vnf_sap_docker_name = 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, vnf_sap_docker_name = 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()