{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "int: N_CLOUD_REGIONS; % number of cloud regions\n", "% set of 1..N_CLOUD_REGIONS: C_REGIONS;\n", "\n", "int: N_ATTRIBUTES; % number of capability related attributes\n", "% set of 1..N_ATTRIBUTES: ATTRIBS;\n", "array[1..N_ATTRIBUTES] of float: w_attributes; % weights of each attribute\n", "\n", "int: N_UTILIZATION_METRICS; % number of dynamic capacity metrics of interest\n", "% set of 1..N_UTILIZATION_METRICS: U_METRICS;\n", "array[1..N_UTILIZATION_METRICS] of float: w_metrics; % weights of each capacity metric\n", "\n", "int: cust_type; % customer type, 0 = regular, 1 = silver, 2 = gold\n", "int: N_VMS; % number of VMs in VNF\n", "int: N_CAPACITY_METRICS; % number of metrics for cloud region capacity check\n", "\n", "float: C_ALLOC_THRESHOLD; % allocation threshold for cloud\n", "float: CUST_ALLOC_THRESHOLD; % allocation threshold for customer in cloud\n", "float: AVG_CPU_UTILIZATION_THRESHOLD;\n", "float: PEAK_CPU_UTILIZATION_THRESHOLD;\n", "\n", "enum CUST_TYPES = { STANDARD, SILVER, GOLD };\n", "enum ATTRIBUTES = { CORE_DC, DIRECT_CONN, MIN_GUARANTEE, SRIOV };\n", "enum METRICS = { AVG_CPU_UTILIZATION, PEAK_CPU_UTILIZATION };\n", "enum CLOUD_REGION_CAPACITY = {CPU_CLOUD, MEMORY_CLOUD};\n", "enum VNFS_TYPES = { VDNS, VFW };\n", "int: N_VNFS;\n", "\n", "% set of 1..N_CAPACITY_METRICS: CAP_METRICS;\n", "\n", "% whether a cloud region has the corresponding capability -- data will be customer specific\n", "% array[1..N_CLOUD_REGIONS, 1..N_CLOUD_REGIONS] of float: c_dist;\n", "array[1..N_CLOUD_REGIONS, 1..N_ATTRIBUTES] of int: capabilities;\n", "array[1..N_CLOUD_REGIONS, 1..N_UTILIZATION_METRICS] of float: cpu_utilization; % how much capacity is already dynamically utilized (fraction)\n", "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of int: c_alloc_capacity; % how much percent is already allocated in the cloud\n", "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of int: c_total_capacity; % total cloud capacity\n", "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of float: c_alloc_capacity_norm;\n", "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of int: cust_alloc_capacity; % how much percent is already allocated in the cloud for the customer\n", "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of int: cust_total_capacity; % total cloud capacity for customer\n", "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of float: cust_alloc_capacity_norm;\n", "\n", "% VM requirements for each type of capacity (vm cpu, memory, etc.)\n", "% TODO: establish a standard for units (MB RAM, GB disk, N virtual cores, etc.)\n", "array[1..N_VMS, 1..N_CAPACITY_METRICS] of int: vm_reqs;\n", "array[1..N_CAPACITY_METRICS] of int: vm_reqs_sums = [ sum(k in 1..N_VMS) (vm_reqs[k,j]) | j in 1..N_CAPACITY_METRICS ];\n", "array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of float: vm_reqs_sums_norm;\n", "%forall(i in 1..N_CLOUD_REGIONS, j in 1..N_CAPACITY_METRICS) (\n", "% vm_reqs_sums_norm[i, j] = vm_reqs_sums[j]/c_total_capacity[i, j]\n", "%)\n", "%array[1..N_CLOUD_REGIONS, 1..N_CAPACITY_METRICS] of float: vm_reqs_sums_norm = [ ((vm_reqs_sums[j]/c_total_capacity[i,j]) | j in 1..N_CAPACITY_METRICS) | i in 1..N_CLOUD_REGIONS ];\n", "\n", "array[1..N_VNFS] of var int: s_regions; % target cloud regions (solution to the problem)\n", "\n", "% custom constraints\n", "constraint forall (s in s_regions) (\n", " cpu_utilization[s, AVG_CPU_UTILIZATION] <= AVG_CPU_UTILIZATION_THRESHOLD /\\ % hard constraint: need some capacity available\n", " cpu_utilization[s, PEAK_CPU_UTILIZATION] <= PEAK_CPU_UTILIZATION_THRESHOLD /\\ % hard constraint: need some capacity available\n", " cust_alloc_capacity[s, CPU_CLOUD] <= (CUST_ALLOC_THRESHOLD*(cust_total_capacity[s, CPU_CLOUD])) - (vm_reqs_sums[CPU_CLOUD]) /\\\n", " cust_alloc_capacity[s, MEMORY_CLOUD] <= (CUST_ALLOC_THRESHOLD*(cust_total_capacity[s, MEMORY_CLOUD])) - (vm_reqs_sums[MEMORY_CLOUD]) /\\\n", " c_alloc_capacity[s, CPU_CLOUD] <= (C_ALLOC_THRESHOLD*(c_total_capacity[s, CPU_CLOUD])) - (vm_reqs_sums[CPU_CLOUD]) /\\\n", " c_alloc_capacity[s, MEMORY_CLOUD] <= (C_ALLOC_THRESHOLD*(c_total_capacity[s, MEMORY_CLOUD])) - (vm_reqs_sums[MEMORY_CLOUD])\n", ");\n", "\n", "% specific constraints based on the VNF\n", "constraint capabilities[s_regions[VDNS], CORE_DC] = 1; % hard constraint for vDNS: has to be placed in CORE DC\n", "\n", "% custom soft constraint for gold customers -- give a large weight to direct connection\n", "var float: additional_obj = sum(s in s_regions) (bool2int(cust_type = GOLD) * capabilities[s, MIN_GUARANTEE] * 1000);\n", "\n", "% TODO: global constraints (such as data validation)\n", "\n", "% Objective for utilization\n", "var float: obj_c_capacity = sum(k in 1..N_CAPACITY_METRICS, s in s_regions) (\n", "\t\t (1 - c_alloc_capacity_norm[s, k] - vm_reqs_sums_norm[s, k]) +\n", " (1 - cust_alloc_capacity_norm[s, k] - vm_reqs_sums_norm[s, k]));\n", "\n", "% Objective for utilization\n", "var float: obj_utilization = sum(k in 1..N_UTILIZATION_METRICS, s in s_regions) ( w_metrics[k] * (1 - cpu_utilization[s, k]) );\n", "\n", "% Objective for capabilities\n", "var float: obj_capabilities = sum(k in 1..N_ATTRIBUTES, s in s_regions) ( w_attributes[k] * capabilities[s, k] );\n", "\n", "% Overall objective function\n", "var float: obj = obj_c_capacity + obj_utilization + obj_capabilities + additional_obj;\n", "\n", "solve maximize obj;\n", "\n", "output [ \"Solution: \\nCloud Region for vDNS = \", show(s_regions[VDNS]) ] \n", "++ [ if N_VNFS = 2 then \"\\nCloud Region for vFW = \" ++ show(s_regions[VFW]) ++ \"\\n\" else \"\\n\" endif ]\n", "++ [ \"Objective function value: \", show(obj), \"\\n\", \"Customer type: \", show(cust_type), \"\\n\"];\n" ] } ], "source": [ "!cat placement.mzn" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "% enum CUST_TYPES = { STANDARD, SILVER, GOLD };\n", "% enum ATTRIBUTES = { CORE_DC, DIRECT_CONN, MIN_GUARANTEE, SRIOV };\n", "% enum METRICS = { AVG_CPU_UTILIZATION, PEAK_CPU_UTILIZATION };\n", "% enum CLOUD_REGION_CAPACITY = {CPU_CLOUD, MEMORY_CLOUD};\n", "\n", "N_CLOUD_REGIONS = 3; % e-dc-1, core-dc-1, core-dc-2\n", "N_ATTRIBUTES = 4;\n", "N_UTILIZATION_METRICS = 2;\n", "N_CAPACITY_METRICS = 2;\n", "N_VMS = 3;\n", "C_ALLOC_THRESHOLD = 0.65;\n", "CUST_ALLOC_THRESHOLD = 0.95;\n", "AVG_CPU_UTILIZATION_THRESHOLD = 0.7;\n", "PEAK_CPU_UTILIZATION_THRESHOLD = 0.95;\n", "\n", "cust_type = GOLD;\n", "N_VNFS = 1;\n", "\n", "w_metrics = [0.9, 0.1];\n", "w_attributes = [0.1, 0.9, 0.05, 0.05]; \n", "\n", "capabilities = [| 0, 1, 1, 1\n", " | 1, 0, 1, 1\n", " | 1, 1, 0, 1 |];\n", "\n", "cpu_utilization = [| 0.05, 0.9\n", " | 0.1, 0.5\n", " | 0.6, 0.8 |];\n", "\n", "c_alloc_capacity = [| 600, 1200\n", " | 1200, 2400\n", " | 2400, 4800 |];\n", "\n", "c_total_capacity = [| 1000, 2000\n", " | 2000, 4000\n", " | 4000, 8000 |];\n", "\n", "c_alloc_capacity_norm = [| 0.6, 0.6\n", " | 0.6, 0.6\n", " | 0.6, 0.6 |];\n", "\n", "cust_alloc_capacity = [| 60, 120\n", " | 120, 240\n", " | 240, 480 |];\n", "\n", "cust_total_capacity = [| 100, 200\n", " | 200, 400\n", " | 400, 800 |];\n", "\n", "cust_alloc_capacity_norm = [| 0.6, 0.6\n", " | 0.6, 0.6\n", " | 0.6, 0.6 |];\n", "\n", "vm_reqs = [| 1, 4\n", " | 2, 8\n", " | 4, 16 |];\n", "\n", "%vm_reqs_sums = [ 14, 56 ];\n", "\n", "vm_reqs_sums_norm = [| 0.007, 0.014\n", " | 0.0035, 0.007\n", " | 0.00175, 0.0035 |];\n" ] } ], "source": [ "!cat gold.dzn" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "23c23\n", "< | 1, 0, 1, 1\n", "---\n", "> | 1, 0, 0, 1\n" ] } ], "source": [ "!diff gold.dzn gold-no-min-guarantee.dzn" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "23c23\n", "< | 1, 0, 1, 1\n", "---\n", "> | 1, 0, 0, 1\n" ] } ], "source": [ "!diff gold.dzn gold-no-min-guarantee.dzn" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "% enum CUST_TYPES = { STANDARD, SILVER, GOLD };\n", "% enum ATTRIBUTES = { CORE_DC, DIRECT_CONN, MIN_GUARANTEE, SRIOV };\n", "% enum METRICS = { AVG_CPU_UTILIZATION, PEAK_CPU_UTILIZATION };\n", "% enum CLOUD_REGION_CAPACITY = {CPU_CLOUD, MEMORY_CLOUD};\n", "\n", "N_CLOUD_REGIONS = 3; % e-dc-1, core-dc-1, core-dc-2\n", "N_ATTRIBUTES = 4;\n", "N_UTILIZATION_METRICS = 2;\n", "N_CAPACITY_METRICS = 2;\n", "N_VMS = 3;\n", "C_ALLOC_THRESHOLD = 0.65;\n", "CUST_ALLOC_THRESHOLD = 0.95;\n", "AVG_CPU_UTILIZATION_THRESHOLD = 0.7;\n", "PEAK_CPU_UTILIZATION_THRESHOLD = 0.95;\n", "\n", "cust_type = SILVER;\n", "N_VNFS = 2;\n", "\n", "w_metrics = [0.9, 0.1];\n", "w_attributes = [0.1, 0.9, 0.05, 0.05]; \n", "\n", "capabilities = [| 0, 1, 1, 1\n", " | 1, 0, 1, 1\n", " | 1, 1, 0, 1 |];\n", "\n", "cpu_utilization = [| 0.05, 0.9\n", " | 0.1, 0.5\n", " | 0.6, 0.8 |];\n", "\n", "c_alloc_capacity = [| 600, 1200\n", " | 1200, 2400\n", " | 2400, 4800 |];\n", "\n", "c_total_capacity = [| 1000, 2000\n", " | 2000, 4000\n", " | 4000, 8000 |];\n", "\n", "c_alloc_capacity_norm = [| 0.6, 0.6\n", " | 0.6, 0.6\n", " | 0.6, 0.6 |];\n", "\n", "cust_alloc_capacity = [| 60, 120\n", " | 120, 240\n", " | 240, 480 |];\n", "\n", "cust_total_capacity = [| 100, 200\n", " | 200, 400\n", " | 400, 800 |];\n", "\n", "cust_alloc_capacity_norm = [| 0.6, 0.6\n", " | 0.6, 0.6\n", " | 0.6, 0.6 |];\n", "\n", "vm_reqs = [| 1, 4\n", " | 2, 8\n", " | 4, 16 |];\n", "\n", "%vm_reqs_sums = [ 14, 56 ];\n", "\n", "vm_reqs_sums_norm = [| 0.007, 0.014\n", " | 0.0035, 0.007\n", " | 0.00175, 0.0035 |];\n" ] } ], "source": [ "!cat silver.dzn" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "26c26\n", "< cpu_utilization = [| 0.05, 0.9\n", "---\n", "> cpu_utilization = [| 0.05, 0.96\n" ] } ], "source": [ "!diff silver.dzn silver-high-edge-load.dzn" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Solution: \n", "Cloud Region for vDNS = 2\n", "Objective function value: 1002.639\n", "Customer type: 3\n", "----------\n", "==========\n" ] } ], "source": [ "!mzn-gecode -a placement.mzn gold.dzn" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Solution: \n", "Cloud Region for vDNS = 2\n", "Objective function value: 2.589\n", "Customer type: 3\n", "----------\n", "Solution: \n", "Cloud Region for vDNS = 3\n", "Objective function value: 3.0195\n", "Customer type: 3\n", "----------\n", "==========\n" ] } ], "source": [ "!mzn-gecode -a placement.mzn gold-no-min-guarantee.dzn" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Solution: \n", "Cloud Region for vDNS = 2\n", "Cloud Region for vFW = 1\n", "Objective function value: 6.062\n", "Customer type: 2\n", "----------\n", "Solution: \n", "Cloud Region for vDNS = 3\n", "Cloud Region for vFW = 1\n", "Objective function value: 6.4425\n", "Customer type: 2\n", "----------\n", "==========\n" ] } ], "source": [ "!mzn-gecode -a placement.mzn silver.dzn" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Solution: \n", "Cloud Region for vDNS = 2\n", "Cloud Region for vFW = 2\n", "Objective function value: 5.278\n", "Customer type: 2\n", "----------\n", "Solution: \n", "Cloud Region for vDNS = 3\n", "Cloud Region for vFW = 2\n", "Objective function value: 5.6585\n", "Customer type: 2\n", "----------\n", "Solution: \n", "Cloud Region for vDNS = 3\n", "Cloud Region for vFW = 3\n", "Objective function value: 6.039\n", "Customer type: 2\n", "----------\n", "==========\n" ] } ], "source": [ "!mzn-gecode -a placement.mzn silver-high-edge-load.dzn" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }