def testAllocationMemLimit(self):
        """
        Test MEM allocation limit
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 500
        E_MEM = 512
        MAX_MU = 2048
        # create dummy resource model environment
        reg = ResourceModelRegistrar(dc_emulation_max_cpu=E_CPU,
                                     dc_emulation_max_mem=E_MEM)
        rm = UpbSimpleCloudDcRM(max_cu=MAX_CU, max_mu=MAX_MU)
        reg.register("test_dc", rm)

        # test over provisioning exeption
        exception = False
        try:
            c6 = createDummyContainerObject("c6", flavor="xlarge")
            c7 = createDummyContainerObject("c7", flavor="xlarge")
            c8 = createDummyContainerObject("c8", flavor="xlarge")
            rm.allocate(c6)  # calculate allocation
            rm.allocate(c7)  # calculate allocation
            rm.allocate(c8)  # calculate allocation
        except NotEnoughResourcesAvailable as e:
            self.assertIn("Not enough memory", str(e))
            exception = True
        self.assertTrue(exception)
Exemplo n.º 2
0
    def testAllocationMemLimit(self):
        """
        Test MEM allocation limit
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 500
        E_MEM = 512
        MAX_MU = 2048
        # create dummy resource model environment
        reg = ResourceModelRegistrar(dc_emulation_max_cpu=E_CPU, dc_emulation_max_mem=E_MEM)
        rm = UpbSimpleCloudDcRM(max_cu=MAX_CU, max_mu=MAX_MU)
        reg.register("test_dc", rm)

        # test over provisioning exeption
        exception = False
        try:
            c6 = createDummyContainerObject("c6", flavor="xlarge")
            c7 = createDummyContainerObject("c7", flavor="xlarge")
            c8 = createDummyContainerObject("c8", flavor="xlarge")
            rm.allocate(c6)  # calculate allocation
            rm.allocate(c7)  # calculate allocation
            rm.allocate(c8)  # calculate allocation
        except NotEnoughResourcesAvailable as e:
            self.assertIn("Not enough memory", e.message)
            exception = True
        self.assertTrue(exception)
Exemplo n.º 3
0
    def testAllocationComputations(self):
        """
        Test the allocation procedures and correct calculations.
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 100
        E_MEM = 512
        MAX_MU = 2048
        # create dummy resource model environment
        reg = ResourceModelRegistrar(
            dc_emulation_max_cpu=E_CPU, dc_emulation_max_mem=E_MEM)
        rm = UpbSimpleCloudDcRM(max_cu=MAX_CU, max_mu=MAX_MU)
        reg.register("test_dc", rm)

        c1 = createDummyContainerObject("c1", flavor="tiny")
        rm.allocate(c1)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c1.resources['cpu_quota']) / c1.resources['cpu_period'], E_CPU / MAX_CU * 0.5)
        # validate memory result
        self.assertEqual(
            float(c1.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 32)

        c2 = createDummyContainerObject("c2", flavor="small")
        rm.allocate(c2)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c2.resources['cpu_quota']) / c2.resources['cpu_period'], E_CPU / MAX_CU * 1)
        # validate memory result
        self.assertEqual(
            float(c2.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 128)

        c3 = createDummyContainerObject("c3", flavor="medium")
        rm.allocate(c3)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c3.resources['cpu_quota']) / c3.resources['cpu_period'], E_CPU / MAX_CU * 4)
        # validate memory result
        self.assertEqual(
            float(c3.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 256)

        c4 = createDummyContainerObject("c4", flavor="large")
        rm.allocate(c4)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c4.resources['cpu_quota']) / c4.resources['cpu_period'], E_CPU / MAX_CU * 8)
        # validate memory result
        self.assertEqual(
            float(c4.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 512)

        c5 = createDummyContainerObject("c5", flavor="xlarge")
        rm.allocate(c5)  # calculate allocation
        # validate compute result
        self.assertEqual(float(
            c5.resources['cpu_quota']) / c5.resources['cpu_period'], E_CPU / MAX_CU * 16)
        # validate memory result
        self.assertEqual(
            float(c5.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 1024)
Exemplo n.º 4
0
    def testAllocationComputations(self):
        """
        Test the allocation procedures and correct calculations.
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 3
        E_MEM = 512
        MAX_MU = 2048
        # create dummy resource model environment
        reg = ResourceModelRegistrar(
            dc_emulation_max_cpu=E_CPU, dc_emulation_max_mem=E_MEM)
        rm = UpbOverprovisioningCloudDcRM(max_cu=MAX_CU, max_mu=MAX_MU)
        reg.register("test_dc", rm)

        c1 = createDummyContainerObject("c1", flavor="small")
        rm.allocate(c1)  # calculate allocation
        self.assertAlmostEqual(float(
            c1.resources['cpu_quota']) / c1.resources['cpu_period'], E_CPU / MAX_CU * 1.0, places=5)
        self.assertAlmostEqual(
            float(c1.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 128)
        self.assertAlmostEqual(rm.cpu_op_factor, 1.0)

        c2 = createDummyContainerObject("c2", flavor="small")
        rm.allocate(c2)  # calculate allocation
        self.assertAlmostEqual(float(
            c2.resources['cpu_quota']) / c2.resources['cpu_period'], E_CPU / MAX_CU * 1.0, places=5)
        self.assertAlmostEqual(
            float(c2.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 128)
        self.assertAlmostEqual(rm.cpu_op_factor, 1.0)

        c3 = createDummyContainerObject("c3", flavor="small")
        rm.allocate(c3)  # calculate allocation
        self.assertAlmostEqual(float(
            c3.resources['cpu_quota']) / c3.resources['cpu_period'], E_CPU / MAX_CU * 1.0, places=5)
        self.assertAlmostEqual(
            float(c3.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 128)
        self.assertAlmostEqual(rm.cpu_op_factor, 1.0)

        # from this container onwards, we should go to over provisioning mode:
        c4 = createDummyContainerObject("c4", flavor="small")
        rm.allocate(c4)  # calculate allocation
        self.assertAlmostEqual(float(
            c4.resources['cpu_quota']) / c4.resources['cpu_period'], E_CPU / MAX_CU * (float(3) / 4), places=5)
        self.assertAlmostEqual(float(
            c4.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 128, places=5)
        self.assertAlmostEqual(rm.cpu_op_factor, 0.75)

        c5 = createDummyContainerObject("c5", flavor="small")
        rm.allocate(c5)  # calculate allocation
        self.assertAlmostEqual(float(
            c5.resources['cpu_quota']) / c5.resources['cpu_period'], E_CPU / MAX_CU * (float(3) / 5), places=5)
        self.assertAlmostEqual(
            float(c5.resources['mem_limit'] / 1024 / 1024), float(E_MEM) / MAX_MU * 128)
        self.assertAlmostEqual(rm.cpu_op_factor, 0.6)
 def testFree(self):
     """
     Test the free procedure.
     :return:
     """
     # create dummy resource model environment
     reg = ResourceModelRegistrar(dc_emulation_max_cpu=1.0,
                                  dc_emulation_max_mem=512)
     rm = UpbSimpleCloudDcRM(max_cu=100, max_mu=100)
     reg.register("test_dc", rm)
     c1 = createDummyContainerObject("c6", flavor="tiny")
     rm.allocate(c1)  # calculate allocation
     self.assertTrue(rm.dc_alloc_cu == 0.5)
     rm.free(c1)
     self.assertTrue(rm.dc_alloc_cu == 0)
Exemplo n.º 6
0
 def testFree(self):
     """
     Test the free procedure.
     :return:
     """
     # create dummy resource model environment
     reg = ResourceModelRegistrar(
         dc_emulation_max_cpu=1.0, dc_emulation_max_mem=512)
     rm = UpbSimpleCloudDcRM(max_cu=100, max_mu=100)
     reg.register("test_dc", rm)
     c1 = createDummyContainerObject("c6", flavor="tiny")
     rm.allocate(c1)  # calculate allocation
     self.assertTrue(rm.dc_alloc_cu == 0.5)
     rm.free(c1)
     self.assertTrue(rm.dc_alloc_cu == 0)
Exemplo n.º 7
0
    def testAllocationComputations(self):
        """
        Test the allocation procedures and correct calculations.
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 3
        E_MEM = 512
        MAX_MU = 2048
        # create dummy resource model environment
        reg = ResourceModelRegistrar(dc_emulation_max_cpu=E_CPU, dc_emulation_max_mem=E_MEM)
        rm = UpbDummyRM(max_cu=MAX_CU, max_mu=MAX_MU)
        reg.register("test_dc", rm)

        c1 = createDummyContainerObject("c1", flavor="small")
        rm.allocate(c1)  # calculate allocation
        self.assertEqual(len(rm._allocated_compute_instances), 1)

        c2 = createDummyContainerObject("c2", flavor="small")
        rm.allocate(c2)  # calculate allocation
        self.assertEqual(len(rm._allocated_compute_instances), 2)
    def testAllocationComputations(self):
        """
        Test the allocation procedures and correct calculations.
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 3
        E_MEM = 512
        MAX_MU = 2048
        # create dummy resource model environment
        reg = ResourceModelRegistrar(dc_emulation_max_cpu=E_CPU,
                                     dc_emulation_max_mem=E_MEM)
        rm = UpbDummyRM(max_cu=MAX_CU, max_mu=MAX_MU)
        reg.register("test_dc", rm)

        c1 = createDummyContainerObject("c1", flavor="small")
        rm.allocate(c1)  # calculate allocation
        self.assertEqual(len(rm._allocated_compute_instances), 1)

        c2 = createDummyContainerObject("c2", flavor="small")
        rm.allocate(c2)  # calculate allocation
        self.assertEqual(len(rm._allocated_compute_instances), 2)
    def testAllocationComputations(self):
        """
        Test the allocation procedures and correct calculations.
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 3
        E_MEM = 512
        MAX_MU = 2048
        # create dummy resource model environment
        reg = ResourceModelRegistrar(dc_emulation_max_cpu=E_CPU,
                                     dc_emulation_max_mem=E_MEM)
        rm = UpbOverprovisioningCloudDcRM(max_cu=MAX_CU, max_mu=MAX_MU)
        reg.register("test_dc", rm)

        c1 = createDummyContainerObject("c1", flavor="small")
        rm.allocate(c1)  # calculate allocation
        self.assertAlmostEqual(float(c1.resources['cpu_quota']) /
                               c1.resources['cpu_period'],
                               E_CPU / MAX_CU * 1.0,
                               places=5)
        self.assertAlmostEqual(float(c1.resources['mem_limit'] / 1024 / 1024),
                               float(E_MEM) / MAX_MU * 128)
        self.assertAlmostEqual(rm.cpu_op_factor, 1.0)

        c2 = createDummyContainerObject("c2", flavor="small")
        rm.allocate(c2)  # calculate allocation
        self.assertAlmostEqual(float(c2.resources['cpu_quota']) /
                               c2.resources['cpu_period'],
                               E_CPU / MAX_CU * 1.0,
                               places=5)
        self.assertAlmostEqual(float(c2.resources['mem_limit'] / 1024 / 1024),
                               float(E_MEM) / MAX_MU * 128)
        self.assertAlmostEqual(rm.cpu_op_factor, 1.0)

        c3 = createDummyContainerObject("c3", flavor="small")
        rm.allocate(c3)  # calculate allocation
        self.assertAlmostEqual(float(c3.resources['cpu_quota']) /
                               c3.resources['cpu_period'],
                               E_CPU / MAX_CU * 1.0,
                               places=5)
        self.assertAlmostEqual(float(c3.resources['mem_limit'] / 1024 / 1024),
                               float(E_MEM) / MAX_MU * 128)
        self.assertAlmostEqual(rm.cpu_op_factor, 1.0)

        # from this container onwards, we should go to over provisioning mode:
        c4 = createDummyContainerObject("c4", flavor="small")
        rm.allocate(c4)  # calculate allocation
        self.assertAlmostEqual(float(c4.resources['cpu_quota']) /
                               c4.resources['cpu_period'],
                               E_CPU / MAX_CU * (float(3) / 4),
                               places=5)
        self.assertAlmostEqual(float(c4.resources['mem_limit'] / 1024 / 1024),
                               float(E_MEM) / MAX_MU * 128,
                               places=5)
        self.assertAlmostEqual(rm.cpu_op_factor, 0.75)

        c5 = createDummyContainerObject("c5", flavor="small")
        rm.allocate(c5)  # calculate allocation
        self.assertAlmostEqual(float(c5.resources['cpu_quota']) /
                               c5.resources['cpu_period'],
                               E_CPU / MAX_CU * (float(3) / 5),
                               places=5)
        self.assertAlmostEqual(float(c5.resources['mem_limit'] / 1024 / 1024),
                               float(E_MEM) / MAX_MU * 128)
        self.assertAlmostEqual(rm.cpu_op_factor, 0.6)
    def testAllocationComputations(self):
        """
        Test the allocation procedures and correct calculations.
        :return:
        """
        # config
        E_CPU = 1.0
        MAX_CU = 100
        E_MEM = 512
        MAX_MU = 2048
        # create dummy resource model environment
        reg = ResourceModelRegistrar(dc_emulation_max_cpu=E_CPU,
                                     dc_emulation_max_mem=E_MEM)
        rm = UpbSimpleCloudDcRM(max_cu=MAX_CU, max_mu=MAX_MU)
        reg.register("test_dc", rm)

        c1 = createDummyContainerObject("c1", flavor="tiny")
        rm.allocate(c1)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c1.resources['cpu_quota']) / c1.resources['cpu_period'],
            E_CPU / MAX_CU * 0.5)
        # validate memory result
        self.assertEqual(float(c1.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 32)

        c2 = createDummyContainerObject("c2", flavor="small")
        rm.allocate(c2)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c2.resources['cpu_quota']) / c2.resources['cpu_period'],
            E_CPU / MAX_CU * 1)
        # validate memory result
        self.assertEqual(float(c2.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 128)

        c3 = createDummyContainerObject("c3", flavor="medium")
        rm.allocate(c3)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c3.resources['cpu_quota']) / c3.resources['cpu_period'],
            E_CPU / MAX_CU * 4)
        # validate memory result
        self.assertEqual(float(c3.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 256)

        c4 = createDummyContainerObject("c4", flavor="large")
        rm.allocate(c4)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c4.resources['cpu_quota']) / c4.resources['cpu_period'],
            E_CPU / MAX_CU * 8)
        # validate memory result
        self.assertEqual(float(c4.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 512)

        c5 = createDummyContainerObject("c5", flavor="xlarge")
        rm.allocate(c5)  # calculate allocation
        # validate compute result
        self.assertEqual(
            float(c5.resources['cpu_quota']) / c5.resources['cpu_period'],
            E_CPU / MAX_CU * 16)
        # validate memory result
        self.assertEqual(float(c5.resources['mem_limit'] / 1024 / 1024),
                         float(E_MEM) / MAX_MU * 1024)
Exemplo n.º 11
0
    def __init__(
            self,
            controller=RemoteController,
            monitor=False,
            enable_learning=False,
            # learning switch behavior of the default ovs switches icw Ryu
            # controller can be turned off/on, needed for E-LAN
            # functionality
            dc_emulation_max_cpu=1.0,  # fraction of overall CPU time for emulation
            dc_emulation_max_mem=512,  # emulation max mem in MB
            **kwargs):
        """
        Create an extended version of a Containernet network
        :param dc_emulation_max_cpu: max. CPU time used by containers in data centers
        :param kwargs: path through for Mininet parameters
        :return:
        """
        # members
        self.dcs = {}
        self.ryu_process = None
        # list of deployed nsds.E_Lines and E_LANs (uploaded from the dummy
        # gatekeeper)
        self.deployed_nsds = []
        self.deployed_elines = []
        self.deployed_elans = []
        self.installed_chains = []

        # always cleanup environment before we start the emulator
        self.killRyu()
        cleanup()

        # call original Docker.__init__ and setup default controller
        Containernet.__init__(self,
                              switch=OVSKernelSwitch,
                              controller=controller,
                              **kwargs)

        # default switch configuration
        enable_ryu_learning = False
        if enable_learning:
            self.failMode = 'standalone'
            enable_ryu_learning = True
        else:
            self.failMode = 'secure'

        # Ryu management
        if controller == RemoteController:
            # start Ryu controller
            self.startRyu(learning_switch=enable_ryu_learning)

        # add the specified controller
        self.addController('c0', controller=controller)

        # graph of the complete DC network
        self.DCNetwork_graph = nx.MultiDiGraph()

        # initialize pool of vlan tags to setup the SDN paths
        self.vlans = range(1, 4095)[::-1]

        # link to Ryu REST_API
        ryu_ip = 'localhost'
        ryu_port = '8080'
        self.ryu_REST_api = 'http://{0}:{1}'.format(ryu_ip, ryu_port)
        self.RyuSession = requests.Session()

        # monitoring agent
        if monitor:
            self.monitor_agent = DCNetworkMonitor(self)
        else:
            self.monitor_agent = None

        # initialize resource model registrar
        self.rm_registrar = ResourceModelRegistrar(dc_emulation_max_cpu,
                                                   dc_emulation_max_mem)
        self.cpu_period = CPU_PERIOD