Initial commit to gerrit repo
[osm/PLA.git] / osm_pla / placement / macros.j2
1 % Copyright 2020 ArctosLabs Scandinavia AB
2 %
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
6 %
7 %    http://www.apache.org/licenses/LICENSE-2.0
8 %
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
12 % implied.
13 % See the License for the specific language governing permissions and
14 % limitations under the License.
15 {%- macro vim_accounts(vim_accounts) -%}
16 enum  Vims = {
17 {%- for vim in vim_accounts %}
18 {{vim}}{% if loop.nextitem is defined%},{% endif %}
19 {%- endfor -%}
20 }; % The vim-accounts
21 {%- endmacro -%}
22
23 {%- macro variables_vnf(ns_desc) -%}
24 {%- for vnf in ns_desc -%}
25 {%- if vnf.vim_account %}
26 Vims: VNF{{vnf.vnf_id}} = {{vnf.vim_account}};
27 {%- else %}
28 var Vims: VNF{{vnf.vnf_id}};
29 {%- endif -%}
30 {% endfor -%}
31 {%- endmacro -%}
32
33 {%- macro trp_link_latency(trp_link_latency) -%}
34 array[Vims, Vims] of int: trp_link_latency = [
35 {%- for row in trp_link_latency -%}
36 |
37 {%- for col in row -%}
38 {{col}},
39 {%- endfor %}
40 {% endfor -%}
41 |]; % Transport link latency between data centers
42 {%- endmacro -%}
43
44 {%- macro trp_link_jitter(trp_link_jitter) -%}
45 array[Vims, Vims] of int: trp_link_jitter = [
46 {%- for row in trp_link_jitter -%}
47 |
48 {%- for col in row -%}
49 {{col}},
50 {%- endfor %}
51 {% endfor -%}
52 |]; % Transport link jitter between data centers
53 {%- endmacro -%}
54
55 {%- macro trp_link_price_list(trp_link_price_list) -%}
56 array[Vims, Vims] of int: trp_link_price_list = [
57 {%- for row in trp_link_price_list -%}
58 |
59 {%- for col in row -%}
60 {{col}},
61 {%- endfor %}
62 {% endfor -%}
63 |]; % Transport link price list
64 {%- endmacro -%}
65
66 {%- macro vnf_price_list_per_vim(ns_desc) -%}
67 {%- for vnf in ns_desc -%}
68 array[Vims] of int: vim_price_list_{{vnf.vnf_id}} = [
69 {%- for price in vnf.vnf_price_per_vim -%}
70 {{price}}{% if loop.nextitem is defined%},{% endif %}
71 {%- endfor -%}
72 ];
73 {% endfor %}
74 {%- endmacro -%}
75
76 {%- macro vld_constraints(vld_desc) -%}
77 {%- for cp in vld_desc -%}
78 {%- if 'latency' in cp.keys()%}
79 constraint trp_link_latency[VNF{{cp.cp_refs[0]}}, VNF{{cp.cp_refs[1]}}] <= {{cp.latency}};
80 {% endif -%}
81 {% endfor -%}
82 {%- for cp in vld_desc -%}
83 {%- if 'jitter' in cp.keys()%}
84 constraint trp_link_jitter[VNF{{cp.cp_refs[0]}}, VNF{{cp.cp_refs[1]}}] <= {{cp.jitter}};
85 {% endif -%}
86 {% endfor -%}
87 {%- endmacro -%}
88
89 {% macro transport_cost(vld_desc) -%}
90 var int: used_transport_cost =
91 {%- if not vld_desc -%}
92 0;
93 {% else %}
94 {%- for cp in vld_desc -%}
95 trp_link_price_list[VNF{{cp.cp_refs[0]}}, VNF{{cp.cp_refs[1]}}]{% if loop.nextitem is defined %}+{% else %};{% endif %}
96 {% endfor -%}
97 {% endif -%}
98 {%- endmacro -%}
99
100 {%- macro used_vim_cost(ns_desc) -%}
101 var int: used_vim_cost =
102 {%- for vnf in ns_desc -%}
103 vim_price_list_{{vnf.vnf_id}}[VNF{{vnf.vnf_id}}]{% if loop.nextitem is defined %}+{% else %};{% endif %}
104 {% endfor -%}
105 {%- endmacro -%}