1 # Copyright 2020 ArctosLabs Scandinavia AB
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 # from collections import Counter
18 from unittest
import TestCase
, mock
21 from osm_pla
.placement
.mznplacement
import MznPlacementConductor
, MznModelGenerator
24 % This minizinc model is generated using
25 % C:/Users/LG/PycharmProjects/dynamic_jijna2_mzn/osm_pla/placement/mznplacement.py
26 % at 2019-10-24 11:12:02.058905.
28 %This is the NETWORK RESOURCE MODEL
30 vimaaaaaaaa_38f5_438d_b8ee_3f93b3531f87,
31 vimbbbbbbbb_38f5_438d_b8ee_3f93b3531f87,
32 vimcccccccc_ed84_4e49_b5df_a9d117bd731f,
33 vimdddddddd_ed84_4e49_b5df_a9d117bd731f,
34 vimeeeeeeee_38f5_438d_b8ee_3f93b3531f87}; % The vim-accounts
35 array[Vims, Vims] of int: trp_link_latency = [|0,50,100,150,200,
40 |]; % Transport link latency between data centers
41 array[Vims, Vims] of int: trp_link_jitter = [|0,50,100,150,200,
46 |]; % Transport link jitter between data centers
47 array[Vims, Vims] of int: trp_link_price_list = [|0,5,6,6,7,
52 |]; % Transport link price list
53 array[Vims] of int: vim_price_list_1 = [500,51,52,53,54];
54 array[Vims] of int: vim_price_list_2 = [20,21,22,23,24];
55 array[Vims] of int: vim_price_list_3 = [70,71,72,73,74];
56 array[Vims] of int: vim_price_list_4 = [40,41,42,43,44];
59 % This is the NETWORK BASIC LOAD MODEL (CONSUMED)
60 % NOTE. This is not applicable in OSM Release 7
62 % This is the SERVICE CONSUMPTION MODEL
63 % These are the variables, i.e. which DC to select for each VNF
70 % These are the set of rules for selecting DCs to VNFs
71 constraint trp_link_latency[VNF1, VNF2] <= 150;
72 constraint trp_link_latency[VNF2, VNF3] <= 140;
73 constraint trp_link_latency[VNF3, VNF4] <= 130;
74 constraint trp_link_jitter[VNF1, VNF2] <= 30;
75 constraint trp_link_jitter[VNF2, VNF3] <= 30;
76 constraint trp_link_jitter[VNF3, VNF4] <= 30;
78 % Calculate the cost for VNFs and cost for transport link and total cost
79 var int: used_transport_cost =trp_link_price_list[VNF1, VNF2]+
80 trp_link_price_list[VNF2, VNF3]+
81 trp_link_price_list[VNF3, VNF4];
83 var int: used_vim_cost =vim_price_list_1[VNF1]+
84 vim_price_list_2[VNF2]+
85 vim_price_list_3[VNF3]+
86 vim_price_list_4[VNF4];
88 var int: total_cost = used_transport_cost + used_vim_cost;
90 solve minimize total_cost;
94 test_mzn_model_w_pinning
= """
95 % This minizinc model is generated using
96 % C:/Users/LG/PycharmProjects/dynamic_jijna2_mzn/osm_pla/placement/mznplacement.py
97 % at 2019-10-24 11:12:02.058905.
99 %This is the NETWORK RESOURCE MODEL
101 vimaaaaaaaa_38f5_438d_b8ee_3f93b3531f87,
102 vimbbbbbbbb_38f5_438d_b8ee_3f93b3531f87,
103 vimcccccccc_ed84_4e49_b5df_a9d117bd731f,
104 vimdddddddd_ed84_4e49_b5df_a9d117bd731f,
105 vimeeeeeeee_38f5_438d_b8ee_3f93b3531f87}; % The vim-accounts
106 array[Vims, Vims] of int: trp_link_latency = [|0,50,100,150,200,
111 |]; % Transport link latency between data centers
112 array[Vims, Vims] of int: trp_link_jitter = [|0,50,100,150,200,
117 |]; % Transport link jitter between data centers
118 array[Vims, Vims] of int: trp_link_price_list = [|0,5,6,6,7,
123 |]; % Transport link price list
124 array[Vims] of int: vim_price_list_1 = [500,51,52,53,54];
125 array[Vims] of int: vim_price_list_2 = [20,21,22,23,24];
126 array[Vims] of int: vim_price_list_3 = [70,71,72,73,74];
127 array[Vims] of int: vim_price_list_4 = [40,41,42,43,44];
130 % This is the NETWORK BASIC LOAD MODEL (CONSUMED)
131 % NOTE. This is not applicable in OSM Release 7
133 % This is the SERVICE CONSUMPTION MODEL
134 % These are the variables, i.e. which DC to select for each VNF
135 Vims: VNF1 = vimbbbbbbbb_38f5_438d_b8ee_3f93b3531f87;
137 Vims: VNF3 = vimbbbbbbbb_38f5_438d_b8ee_3f93b3531f87;
141 % These are the set of rules for selecting DCs to VNFs
142 constraint trp_link_latency[VNF1, VNF2] <= 150;
143 constraint trp_link_latency[VNF2, VNF3] <= 140;
144 constraint trp_link_latency[VNF3, VNF4] <= 130;
145 constraint trp_link_jitter[VNF1, VNF2] <= 30;
146 constraint trp_link_jitter[VNF2, VNF3] <= 30;
147 constraint trp_link_jitter[VNF3, VNF4] <= 30;
149 % Calculate the cost for VNFs and cost for transport link and total cost
150 var int: used_transport_cost =trp_link_price_list[VNF1, VNF2]+
151 trp_link_price_list[VNF2, VNF3]+
152 trp_link_price_list[VNF3, VNF4];
154 var int: used_vim_cost =vim_price_list_1[VNF1]+
155 vim_price_list_2[VNF2]+
156 vim_price_list_3[VNF3]+
157 vim_price_list_4[VNF4];
159 var int: total_cost = used_transport_cost + used_vim_cost;
161 solve minimize total_cost;
165 test_mzn_unsatisfiable_model
= """
168 constraint item1 + item2 == 5;
174 class TestMznPlacementConductor(TestCase
):
175 def test__run_placement_model(self
):
178 "vimAccountId": "bbbbbbbb-38f5-438d-b8ee-3f93b3531f87",
179 "member-vnf-index": "1",
182 "vimAccountId": "aaaaaaaa-38f5-438d-b8ee-3f93b3531f87",
183 "member-vnf-index": "2",
186 "vimAccountId": "aaaaaaaa-38f5-438d-b8ee-3f93b3531f87",
187 "member-vnf-index": "3",
190 "vimAccountId": "aaaaaaaa-38f5-438d-b8ee-3f93b3531f87",
191 "member-vnf-index": "4",
195 mpc
= MznPlacementConductor(logging
.getLogger(__name__
))
196 placement
= mpc
._run
_placement
_model
(mzn_model
=test_mzn_model
, ns_desc
={})
197 # sort the result to ease assert with expected result
198 sorted_placement
= sorted(placement
, key
=lambda k
: k
["member-vnf-index"])
199 self
.assertEqual(expected_result
, sorted_placement
, "Faulty syntax or content")
201 def test__run_placement_model_w_pinning(self
):
204 "vimAccountId": "bbbbbbbb-38f5-438d-b8ee-3f93b3531f87",
205 "member-vnf-index": "1",
208 "vimAccountId": "bbbbbbbb-38f5-438d-b8ee-3f93b3531f87",
209 "member-vnf-index": "2",
212 "vimAccountId": "bbbbbbbb-38f5-438d-b8ee-3f93b3531f87",
213 "member-vnf-index": "3",
216 "vimAccountId": "aaaaaaaa-38f5-438d-b8ee-3f93b3531f87",
217 "member-vnf-index": "4",
222 {"vnf_price_per_vim": [10, 9, 7, 8], "vnf_id": "2"},
224 "vim_account": "vimbbbbbbbb_38f5_438d_b8ee_3f93b3531f87",
225 "vnf_price_per_vim": [10, 9, 7, 8],
228 {"vnf_price_per_vim": [10, 9, 7, 8], "vnf_id": "4"},
230 "vim_account": "vimbbbbbbbb_38f5_438d_b8ee_3f93b3531f87",
231 "vnf_price_per_vim": [10, 9, 7, 8],
236 mpc
= MznPlacementConductor(logging
.getLogger(__name__
))
237 placement
= mpc
._run
_placement
_model
(
238 mzn_model
=test_mzn_model_w_pinning
, ns_desc
=ns_desc
240 # sort the result to ease assert with expected result
241 sorted_placement
= sorted(placement
, key
=lambda k
: k
["member-vnf-index"])
242 self
.assertEqual(expected_result
, sorted_placement
, "Faulty syntax or content")
244 def test__run_placement_model_unsatisfiable(self
):
245 mpc
= MznPlacementConductor(logging
.getLogger(__name__
))
248 mpc
._run
_placement
_model
(
249 mzn_model
=test_mzn_unsatisfiable_model
, ns_desc
={}
251 "Faulty syntax or content for unsatisfiable model",
254 @mock.patch
.object(MznModelGenerator
, "create_model", side_effect
=["%model"])
255 @mock.patch
.object(MznPlacementConductor
, "_run_placement_model")
256 def test_do_placement_computation(self
, mock_run
, mock_create
):
257 mpc
= MznPlacementConductor(logging
.getLogger(__name__
))
258 dummy_nspd
= {"ns_desc": {}}
259 _
= mpc
.do_placement_computation(dummy_nspd
)
260 mock_create
.assert_called_with(dummy_nspd
)
261 mock_run
.assert_called_with("%model", {})