summaryrefslogtreecommitdiffstats
path: root/docs/sections/homingspecification.rst
blob: 4950a9af928aa0f8ab8dbc306690e2fe35fdb6e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
.. This work is licensed under a Creative Commons Attribution 4.0 International License.
.. Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
.. Copyright (C) 2020 Wipro Limited. All rights reserved.

Homing Specification Guide
==========================


This document describes the Homing Template format, used by the Homing
service. It is a work in progress and subject to frequent revision.

Template Structure
------------------

Homing templates are defined in YAML and follow the structure outlined
below.

.. code:: yaml

    homing_template_version: 2017-10-10
    parameters:
      PARAMETER_DICT
    locations:
      LOCATION_DICT
    demands:
      DEMAND_DICT
    constraints:
      CONSTRAINT_DICT
    reservations:
      RESERVATION_DICT
    optimization:
      OPTIMIZATION

-  ``homing_template_version``: This key with value 2017-10-10 (or a
   later date) indicates that the YAML document is a Homing template of
   the specified version.
-  ``parameters``: This section allows for specifying input parameters
   that have to be provided when instantiating the homing template.
   Typically, this section is used for providing runtime parameters
   (like SLA thresholds), which in turn is used in the existing homing
   policies. The section is optional and can be omitted when no input is
   required.
-  ``locations``: This section contains the declaration of geographic
   locations. This section is optional and can be omitted when no input
   is required.
-  ``demands``: This section contains the declaration of demands. This
   section with at least one demand should be defined in any Homing
   template, or the template would not really do anything when being
   instantiated.
-  ``constraints``: This section contains the declaration of
   constraints. The section is optional and can be omitted when no input
   is required.
-  ``reservations``: This section contains the declaration of required
   reservations. This section is optional and can be omitted when
   reservations are not required.
-  ``optimization``: This section allows the declaration of an
   optimization. This section is optional and can be omitted when no
   input is required.

Homing Template Version
-----------------------

The value of ``homing_template_version`` tells HAS not only the format
of the template but also features that will be validated and supported.
Only one value is supported: ``2017-10-10`` in the initial release of
HAS.

.. code:: yaml

    homing_template_version: 2017-10-10

Parameters
----------

The **parameters** section allows for specifying input parameters that
have to be provided when instantiating the template. Such parameters are
typically used for providing runtime inputs (like SLA thresholds), which
in turn is used in the existing homing policies. This also helps build
reusable homing constraints where these parameters can be embedded
design time, and it corresponding values can be supplied during runtime.

Each parameter is specified with the name followed by its value. Values
can be strings, lists, or dictionaries.

Example
~~~~~~~

In this example, ``provider_name`` is a string and ``service_info`` is a
dictionary containing both a string and a list (keyed by ``base_url``
and ``nod_config``, respectively).

.. code:: yaml

    parameters:
      provider_name: multicloud
      service_info:
        base_url: http://serviceprovider.sdngc.com/
        nod_config:
        - http://nod/config_a.yaml
        - http://nod/config_b.yaml
        - http://nod/config_c.yaml
        - http://nod/config_d.yaml

A parameter can be referenced in place of any value. See the **Intrinsic
Functions** section for more details.

Locations
---------

One or more **locations** may be declared. A location may be referenced
by one or more ``constraints``. Locations may be defined in any of the
following ways:

Coordinate
~~~~~~~~~~

A geographic coordinate expressed as a latitude and longitude.

+---------------+----------------------------+
| Key           | Value                      |
+===============+============================+
| ``latitude``  | Latitude of the location.  |
+---------------+----------------------------+
| ``longitude`` | Longitude of the location. |
+---------------+----------------------------+

Host Name
~~~~~~~~~

An opaque host name that can be translated to a coordinate via an
inventory provider (e.g., A&AI).

+---------------+-----------------------------------+
| Key           | Value                             |
+===============+===================================+
| ``host_name`` | Host name identifying a location. |
+---------------+-----------------------------------+

CLLI
~~~~

Common Language Location Identification (CLLI)
code(https://en.wikipedia.org/wiki/CLLI_code).

+---------------+-------------------+
| Key           | Value             |
+===============+===================+
| ``clli_code`` | 8 character CLLI. |
+---------------+-------------------+

**Questions**

-  Do we need functions that can convert one of these to the other?
   E.g., CLLI Codes to a latitude/longitude

Placemark
~~~~~~~~~

An address expressed in geographic region-agnostic terms (referred to as
a *placemark*).

*This is an example as of Frankfurt release. Support for this schema is
 deferred to subsequent release.*

+-----------------------------------+----------------------------------+
| Key                               | Value                            |
+===================================+==================================+
| ``iso_country_code``              | The abbreviated country name     |
|                                   | associated with the placemark.   |
+-----------------------------------+----------------------------------+
| ``postal_code``                   | The postal code associated with  |
|                                   | the placemark.                   |
+-----------------------------------+----------------------------------+
| ``administrative_area``           | The state or province associated |
|                                   | with the placemark.              |
+-----------------------------------+----------------------------------+
| ``sub_administrative_area``       | Additional administrative area   |
|                                   | information for the placemark.   |
+-----------------------------------+----------------------------------+
| ``locality``                      | The city associated with the     |
|                                   | placemark.                       |
+-----------------------------------+----------------------------------+
| ``sub_locality``                  | Additional city-level            |
|                                   | information for the placemark.   |
+-----------------------------------+----------------------------------+
| ``thoroughfare``                  | The street address associated    |
|                                   | with the placemark.              |
+-----------------------------------+----------------------------------+
| ``sub_thoroughfare``              | Additional street-level          |
|                                   | information for the placemark.   |
+-----------------------------------+----------------------------------+

**Note:**

-  A geocoder could be used to convert placemarks to a
   latitude/longitude

Examples
~~~~~~~~

The following examples illustrate a location expressed in coordinate,
host_name, CLLI, and placemark, respectively.

.. code:: yaml

    locations:
      location_using_coordinates:
        latitude: 32.897480
        longitude: -97.040443

      host_location_using_host_name:
        host_name: USESTCDLLSTX55ANZ123

      location_using_clli:
        clli_code: DLLSTX55

      location_using_placemark:
        sub_thoroughfare: 1
        thoroughfare: ATT Way
        locality: Bedminster
        administrative_area: NJ
        postal_code: 07921-2694

Demands
-------

A **demand** can be satisfied by using candidates drawn from
inventories. Each demand is uniquely named. Inventory is considered to
be opaque and can represent anything from which candidates can be drawn.

A demand’s resource requirements are determined by asking an **inventory
provider** for one or more sets of **inventory candidates** against
which the demand will be made. An explicit set of candidates may also be
declared, for example, if the only candidates for a demand are
predetermined.

Demand criteria is dependent upon the inventory provider in use.

**Provider-agnostic Schema**

+-----------------------------+------------------------------------+
| Key                         | Value                              |
+=============================+====================================+
| ``inventory_provider``      | A HAS-supported inventory          |
|                             | provider.                          |
+-----------------------------+------------------------------------+
| ``inventory_type``          | The reserved words ``cloud``       |
|                             | (cloud regions), ``service`` (for  |
|                             | existing service instances),       |
|                             | ``vfmodule`` (for vf instances),   |
|                             | ``nssi`` (for slice subnet         |
|                             | instances). Exactly one inventory  |
|                             | type may be specified.             |
+-----------------------------+------------------------------------+
| ``filtering_attributes``    | A list of key-value pairs, that is |
| (Optional)                  | used to select inventory           |
|                             | candidates that match *all* the    |
|                             | specified attributes. The key      |
|                             | should be a uniquely identifiable  |
|                             | attribute at the inventory         |
|                             | provider.                          |
+-----------------------------+------------------------------------+
| ``passthrough_attributes``  | A list of key-value pairs, that    |
| (Optional)                  | will be added to the candidate's   |
|                             | attribute directly from template.  |
+-----------------------------+------------------------------------+
| ``service_type`` (Optional) | If ``inventory_type`` is           |
|                             | ``service``, a list of one or more |
|                             | provider-defined service types. If |
|                             | only one service type is           |
|                             | specified, it may appear without   |
|                             | list markers (``[]``).             |
+-----------------------------+------------------------------------+
| ``service_id`` (Optional)   | If ``inventory_type`` is           |
|                             | ``service``, a list of one or more |
|                             | provider-defined service ids. If   |
|                             | only one service id is specified,  |
|                             | it may appear without list markers |
|                             | (``[]``).                          |
+-----------------------------+------------------------------------+
| ``default_cost`` (Optional) | The default cost of an inventory   |
|                             | candidate, expressed as currency.  |
|                             | This must be specified if the      |
|                             | inventory provider may not always  |
|                             | return a cost.                     |
+-----------------------------+------------------------------------+
| ``required_candidates``     | A list of one or more candidates   |
| (Optional)                  | from which a solution will be      |
|                             | explored. Must be a valid          |
|                             | candidate as described in the      |
|                             | **candidate schema**.              |
+-----------------------------+------------------------------------+
| ``excluded_candidates``     | A list of one or more candidates   |
| (Optional)                  | that should be excluded from the   |
|                             | search space. Must be a valid      |
|                             | candidate as described in the      |
|                             | **candidate schema**.              |
+-----------------------------+------------------------------------+
| ``existing_placement``      | The current placement for the      |
| (Optional)                  | demand. Must be a valid candidate  |
|                             | as described in the **candidate    |
|                             | schema**.                          |
+-----------------------------+------------------------------------+

**Note**

- The demand attributes in the template come from either policy or from
  a northbound request scope.

.. _examples-1:

Examples
~~~~~~~~

The following example helps understand a demand specification using
Active & Available Inventory (A&AI), the inventory provider-of-record
for ONAP.

**Inventory Provider Criteria**

+-----------------------------+------------------------------------+
| Key                         | Value                              |
+=============================+====================================+
| ``inventory_provider``      | Examples: ``aai``, ``multicloud``. |
+-----------------------------+------------------------------------+
| ``inventory_type``          | The reserved words ``cloud``       |
|                             | (cloud regions), ``service`` (for  |
|                             | existing service instances),       |
|                             | ``vfmodule`` (for vf instances),   |
|                             | ``nssi`` (for slice subnet         |
|                             | instances). Exactly one inventory  |
|                             | type may be specified.             |
+-----------------------------+------------------------------------+
| ``filtering attributes``    | A list of key-value pairs to match |
|  (Optional)                 | against inventory when drawing     |
|                             | candidates.                        |
+-----------------------------+------------------------------------+
| ``passthrough_attributes``  | A list of key-value pairs, that    |
| (Optional)                  | will be added to the candidate's   |
|                             | attribute directly from template.  |
+-----------------------------+------------------------------------+
| ``service_type`` (Optional) | Examples may include ``vG``,       |
|                             | ``vG_MuxInfra``, etc.              |
+-----------------------------+------------------------------------+
| ``service_id`` (Optional)   | Must be a valid service id.        |
|                             | Examples may include ``vCPE``,     |
|                             | ``VoLTE``, etc.                    |
+-----------------------------+------------------------------------+
| ``default_cost`` (Optional) | The default cost of an inventory   |
|                             | candidate, expressed as a unitless |
|                             | number.                            |
+-----------------------------+------------------------------------+
| ``required_candidates``     | A list of one or more valid        |
| (Optional)                  | candidates. See **Candidate        |
|                             | Schema** for details.              |
+-----------------------------+------------------------------------+
| ``excluded_candidates``     | A list of one or more valid        |
| (Optional)                  | candidates. See **Candidate        |
|                             | Schema** for details.              |
+-----------------------------+------------------------------------+
| ``existing_placement``      | A single valid candidate,          |
| (Optional)                  | representing the current placement |
|                             | for the demand. See **candidate    |
|                             | schema** for details.              |
+-----------------------------+------------------------------------+

**Candidate Schema**

The following is the schema for a valid ``candidate``:

- ``candidate_id`` uniquely identifies a candidate. Currently, it is
  either a Service Instance ID or Cloud Region ID.
- ``candidate_type`` identifies the type of the candidate. Currently, it
  is either ``cloud`` or ``service``. \* ``inventory_type`` is defined
  as described in **Inventory Provider Criteria** (above).
- ``inventory_provider`` identifies the inventory from which the
  candidate was drawn. \*
- ``host_id`` is an ID of a specific host (used only when referring to
  service/existing inventory).
- ``cost`` is expressed as a unitless number.
- ``location_id`` is always a location ID of the specified location type
  (e.g., for a type of ``cloud`` this will be an Cloud Region ID).
- ``location_type`` is an inventory provider supported location type.
- ``latitude`` is a valid latitude corresponding to the *location_id*.
- ``longitude`` is a valid longitude corresponding to the *location_id*.
- ``city`` (Optional) city corresponding to the *location_id*.
- ``state`` (Optional) state corresponding to the *location_id*.
- ``country`` (Optional) country corresponding to the *location_id*.
- ``region`` (Optional) geographic region corresponding to the
  *location_id*.
- ``complex_name`` (Optional) Name of the complex corresponding to the
  *location_id*.
- ``cloud_owner`` (Optional) refers to the *cloud owner*
  (e.g., ``azure``, ``aws``, ``att``, etc.).
- ``cloud_region_version`` (Optional) is an inventory provider supported
  version of the cloud region.
- ``physical_location_id`` (Optional) is an inventory provider supported
  CLLI code corresponding to the cloud region.

**Examples**

**Service Candidate**

.. code-block:: json

    {
        "candidate_id": "1ac71fb8-ad43-4e16-9459-c3f372b8236d",
        "candidate_type": "service",
        "inventory_type": "service",
        "inventory_provider": "aai",
        "host_id": "vnf_123456",
        "cost": "100",
        "location_id": "DLLSTX9A",
        "location_type": "azure",
        "latitude": "32.897480",
        "longitude": "-97.040443",
        "city": "Dallas",
        "state": "TX",
        "country": "USA",
        "region": "US",
        "complex_name": "dalls_one",
        "cloud_owner": "att-aic",
        "cloud_region_version": "1.1",
        "physical_location_id": "DLLSTX9A"
    }

**Cloud Candidate**

.. code-block:: json

    {
        "candidate_id": "NYCNY55",
        "candidate_type": "cloud",
        "inventory_type": "cloud",
        "inventory_provider": "aai",
        "cost": "100",
        "location_id": "NYCNY55",
        "location_type": "azure",
        "latitude": "40.7128",
        "longitude": "-74.0060",
        "city": "New York",
        "state": "NY",
        "country": "USA",
        "region": "US",
        "complex_name": "ny_one",
        "cloud_owner": "att-aic",
        "cloud_region_version": "1.1",
        "physical_location_id": "NYCNY55",
        "flavors": {
           "flavor":[
              {
                 "flavor-id":"9cf8220b-4d96-4c30-a426-2e9382f3fff2",
                 "flavor-name":"flavor-numa-cpu-topology-instruction-set",
                 "flavor-vcpus":64,
                 "flavor-ram":65536,
                 "flavor-disk":1048576,
                 "flavor-ephemeral":128,
                 "flavor-swap":"0",
                 "flavor-is-public":false,
                 "flavor-selflink":"pXtX",
                 "flavor-disabled":false,
                 "hpa-capabilities":{
                    "hpa-capability":[
                       {
                          "hpa-capability-id":"01a4bfe1-1993-4fda-bd1c-ef333b4f76a9",
                          "hpa-feature":"cpuInstructionSetExtensions",
                          "hpa-version":"v1",
                          "architecture":"Intel64",
                          "resource-version":"1521306560982",
                          "hpa-feature-attributes":[
                             {
                                "hpa-attribute-key":"instructionSetExtensions",
                                "hpa-attribute-value":"{\"value\":{['AAA', 'BBB', 'CCC', 'DDD']}}",
                                "resource-version":"1521306560989"
                             }
                          ]
                       },
                       {
                          "hpa-capability-id":"167ad6a2-7d9c-4bf2-9a1b-30e5311b8c66",
                          "hpa-feature":"numa",
                          "hpa-version":"v1",
                          "architecture":"generic",
                          "resource-version":"1521306561020",
                          "hpa-feature-attributes":[
                             {
                                "hpa-attribute-key":"numaCpu-1",
                                "hpa-attribute-value":"{\"value\":4}",
                                "resource-version":"1521306561060"
                             },
                             {
                                "hpa-attribute-key":"numaNodes",
                                "hpa-attribute-value":"{\"value\":2}",
                                "resource-version":"1521306561088"
                             },
                             {
                                "hpa-attribute-key":"numaCpu-0",
                                "hpa-attribute-value":"{\"value\":2}",
                                "resource-version":"1521306561028"
                             },
                             {
                                "hpa-attribute-key":"numaMem-0",
                                "hpa-attribute-value":"{\"value\":2, \"unit\":\"GB\" }",
                                "resource-version":"1521306561044"
                             },
                             {
                                "hpa-attribute-key":"numaMem-1",
                                "hpa-attribute-value":"{\"value\":4, \"unit\":\"GB\" }",
                                "resource-version":"1521306561074"
                             }
                          ]
                       },
                       {
                          "hpa-capability-id":"13ec6d4d-7fee-48d8-9e4a-c598feb101ed",
                          "hpa-feature":"basicCapabilities",
                          "hpa-version":"v1",
                          "architecture":"generic",
                          "resource-version":"1521306560909",
                          "hpa-feature-attributes":[
                             {
                                "hpa-attribute-key":"numVirtualCpu",
                                "hpa-attribute-value":"{\"value\":64}",
                                "resource-version":"1521306560932"
                             },
                             {
                                "hpa-attribute-key":"virtualMemSize",
                                "hpa-attribute-value":"{\"value\":65536, \"unit\":\"MB\" }",
                                "resource-version":"1521306560954"
                             }
                          ]
                       },
                       {
                          "hpa-capability-id":"8fa22e64-41b4-471f-96ad-6c4708635e4c",
                          "hpa-feature":"cpuTopology",
                          "hpa-version":"v1",
                          "architecture":"generic",
                          "resource-version":"1521306561109",
                          "hpa-feature-attributes":[
                             {
                                "hpa-attribute-key":"numCpuCores",
                                "hpa-attribute-value":"{\"value\":8}",
                                "resource-version":"1521306561114"
                             },
                             {
                                "hpa-attribute-key":"numCpuThreads",
                                "hpa-attribute-value":"{\"value\":8}",
                                "resource-version":"1521306561138"
                             },
                             {
                                "hpa-attribute-key":"numCpuSockets",
                                "hpa-attribute-value":"{\"value\":6}",
                                "resource-version":"1521306561126"
                             }
                          ]
                       }
                    ]
                 },
                 "resource-version":"1521306560203"
              },
              {
                 "flavor-id":"f5aa2b2e-3206-41b6-80d5-cf041b098c43",
                 "flavor-name":"flavor-cpu-pinning-ovsdpdk-instruction-set",
                 "flavor-vcpus":32,
                 "flavor-ram":131072,
                 "flavor-disk":2097152,
                 "flavor-ephemeral":128,
                 "flavor-swap":"0",
                 "flavor-is-public":false,
                 "flavor-selflink":"pXtX",
                 "flavor-disabled":false,
                 "hpa-capabilities":{
                    "hpa-capability":[
                       {
                          "hpa-capability-id":"4d04f4d8-e257-4442-8417-19a525e56096",
                          "hpa-feature":"cpuInstructionSetExtensions",
                          "hpa-version":"v1",
                          "architecture":"generic",
                          "resource-version":"1521306561223",
                          "hpa-feature-attributes":[
                             {
                                "hpa-attribute-key":"instructionSetExtensions",
                                "hpa-attribute-value":"{\"value\":{['A11', 'B22']}}",
                                "resource-version":"1521306561228"
                             }
                          ]
                       },
                       {
                          "hpa-capability-id":"8d36a8fe-bfee-446a-bbcb-881ee66c8f78",
                          "hpa-feature":"ovsDpdk",
                          "hpa-version":"v1",
                          "architecture":"generic",
                          "resource-version":"1521306561170",
                          "hpa-feature-attributes":[
                             {
                                "hpa-attribute-key":"dataProcessingAccelerationLibrary",
                                "hpa-attribute-value":"{\"value\":\"v18.02\"}",
                                "resource-version":"1521306561175"
                             }
                          ]
                       },
                       {
                          "hpa-capability-id":"c140c945-1532-4908-86c9-d7f71416f1dd",
                          "hpa-feature":"cpuPinning",
                          "hpa-version":"v1",
                          "architecture":"generic",
                          "resource-version":"1521306561191",
                          "hpa-feature-attributes":[
                             {
                                "hpa-attribute-key":"logicalCpuPinningPolicy",
                                "hpa-attribute-value":"{\"value\":\"dedicated\"}",
                                "resource-version":"1521306561196"
                             },
                             {
                                "hpa-attribute-key":"logicalCpuThreadPinningPolicy",
                                "hpa-attribute-value":"{value:\"prefer\"}",
                                "resource-version":"1521306561206"
                             }
                          ]
                       },
                       {
                          "hpa-capability-id":"4565615b-1077-4bb5-a340-c5be48db2aaa",
                          "hpa-feature":"basicCapabilities",
                          "hpa-version":"v1",
                          "architecture":"generic",
                          "resource-version":"1521306561244",
                          "hpa-feature-attributes":[
                             {
                                "hpa-attribute-key":"numVirtualCpu",
                                "hpa-attribute-value":"{\"value\":32}",
                                "resource-version":"1521306561259"
                             },
                             {
                                "hpa-attribute-key":"virtualMemSize",
                                "hpa-attribute-value":"{\"value\":131072, \"unit\":\"MB\" }",
                                "resource-version":"1521306561248"
                             }
                          ]
                       }
                    ]
                 },
                 "resource-version":"1521306561164"
              }
           ]
        }
    }

**vfmodule candidate**

.. code-block:: json

    {
        "candidate_id": "d187d743-5932-4fb9-a42d-db0a5be5ba7e",
        "city": "example-city-val-27150",
        "cloud_owner": "CloudOwner",
        "cloud_region_version": "1",
        "complex_name": "clli1",
        "cost": 1.0,
        "country": "example-country-val-94173",
        "existing_placement": "false",
        "host_id": "vFW-PKG-MC",
        "inventory_provider": "aai",
        "inventory_type": "vfmodule",
        "ipv4-oam-address": "oam_network_zb4J",
        "ipv6-oam-address": "",
        "latitude": "example-latitude-val-89101",
        "location_id": "RegionOne",
        "location_type": "att_aic",
        "longitude": "32.89948",
        "nf-id": "fcbff633-47cc-4f38-a98d-4ba8285bd8b6",
        "nf-name": "vFW-PKG-MC",
        "nf-type": "vnf",
        "passthrough_attributes": {
            "td-role": "anchor"
        },
        "physical_location_id": "clli1",
        "port_key": "vlan_port",
        "region": "example-region-val-13893",
        "service_instance_id": "3e8d118c-10ca-4b4b-b3db-089b5e9e6a1c",
        "service_resource_id": "vPGN-XX",
        "sriov_automation": "false",
        "state": "example-state-val-59487",
        "uniqueness": "false",
        "vf-module-id": "d187d743-5932-4fb9-a42d-db0a5be5ba7e",
        "vf-module-name": "vnf-pkg-r1-t2-mc",
        "vim-id": "CloudOwner_RegionOne",
        "vlan_key": "vlan_key",
        "vnf-type": "5G_EVE_Demo/5G_EVE_PKG 0",
        "vservers": [
            {
                "l-interfaces": [
                    {
                        "interface-id": "4b333af1-90d6-42ae-8389-d440e6ff0e93",
                        "interface-name": "vnf-pkg-r1-t2-mc-vpg_private_2_port-mf7lu55usq7i",
                        "ipv4-addresses": [
                            "10.100.100.2"
                        ],
                        "ipv6-addresses": [],
                        "macaddr": "fa:16:3e:c4:07:7f",
                        "network-id": "59763a33-3296-4dc8-9ee6-2bdcd63322fc",
                        "network-name": ""
                    },
                    {
                        "interface-id": "85dd57e9-6e3a-48d0-a784-4598d627e798",
                        "interface-name": "vnf-pkg-r1-t2-mc-vpg_private_1_port-734xxixicw6r",
                        "ipv4-addresses": [
                            "10.0.110.2"
                        ],
                        "ipv6-addresses": [],
                        "macaddr": "fa:16:3e:b5:86:38",
                        "network-id": "cdb4bc25-2412-4b77-bbd5-791a02f8776d",
                        "network-name": ""
                    },
                    {
                        "interface-id": "edaff25a-878e-4706-ad52-4e3d51cf6a82",
                        "interface-name": "vnf-pkg-r1-t2-mc-vpg_private_0_port-e5qdm3p5ijhe",
                        "ipv4-addresses": [
                            "192.168.10.200"
                        ],
                        "ipv6-addresses": [],
                        "macaddr": "fa:16:3e:ff:d8:6f",
                        "network-id": "932ac514-639a-45b2-b1a3-4c5bb708b5c1",
                        "network-name": ""
                    }
                ],
                "vserver-id": "00bddefc-126e-4e4f-a18d-99b94d8d9a30",
                "vserver-name": "zdfw1fwl01pgn01"
            }
        ]
    }

**nssi candidate**

.. code-block:: json

    {
        "candidate_id": "1a636c4d-5e76-427e-bfd6-241a947224b0",
        "candidate_type": "nssi",
        "conn_density": 0,
        "cost": 1.0,
        "domain": "cn",
        "e2e_latency": 0,
        "exp_data_rate": 0,
        "exp_data_rate_dl": 100,
        "exp_data_rate_ul": 100,
        "instance_name": "nssi_test_0211",
        "inventory_provider": "aai",
        "inventory_type": "nssi",
        "jitter": 0,
        "latency": 20,
        "max_number_of_ues": 0,
        "nsi_id": "4115d3c8-dd59-45d6-b09d-e756dee9b518",
        "nsi_model_invariant_id": "39b10fe6-efcc-40bc-8184-c38414b80771",
        "nsi_model_version_id": "8b664b11-6646-4776-9f59-5c3de46da2d6",
        "nsi_name": "nsi_test_0211",
        "payload_size": 0,
        "reliability": 99.99,
        "resource_sharing_level": "0",
        "survival_time": 0,
        "traffic_density": 0,
        "ue_mobility_level": "stationary",
        "uniqueness": "true"
    }

**Examples**

The following examples illustrate two demands:

-  ``vGMuxInfra``: A vGMuxInfra service, drawing candidates of type
   *service* from the inventory. Only candidates that match the
   customer_id and orchestration-status will be included in the search
   space.
-  ``vG``: A vG, drawing candidates of type *service* and *cloud* from
   the inventory. Only candidates that match the customer_id and
   provisioning-status will be included in the search space.

.. code:: yaml

    demands:
      vGMuxInfra:
      - inventory_provider: aai
        inventory_type: service
        attributes:
          equipment_type: vG_Mux
          customer_id: some_company
          orchestration-status: Activated
          model-id: 174e371e-f514-4913-a93d-ed7e7f8fbdca
          model-version: 2.0
      vG:
      - inventory_provider: aai
        inventory_type: service
        attributes:
          equipment_type: vG
          customer_id: some_company
          provisioning-status: provisioned
      - inventory_provider: aai
        inventory_type: cloud

**Note**

- Cost could be used to specify the cost of choosing a specific
  candidate. For example, choosing an existing VNF instance can be less
  costlier than creating a new instance.

Constraints
-----------

A **Constraint** is used to *eliminate* inventory candidates from one or
more demands that do not meet the requirements specified by the
constraint. Since reusability is one of the cornerstones of HAS,
Constraints are designed to be service-agnostic, and is parameterized
such that it can be reused across a wide range of services. Further, HAS
is designed with a plug-in architecture that facilitates easy addition
of new constraint types.

Constraints are denoted by a ``constraints`` key. Each constraint is
uniquely named and set to a dictionary containing a constraint type, a
list of demands to apply the constraint to, and a dictionary of
constraint properties.

**Considerations while using multiple constraints** \* Constraints
should be treated as a unordered list, and no assumptions should be made
as regards to the order in which the constraints are evaluated for any
given demand. \* All constraints are effectively AND-ed together.
Constructs such as “Constraint X OR Y” are unsupported. \* Constraints
are reducing in nature, and does not increase the available candidates
at any point during the constraint evaluations.

**Schema**

+-------------------------------------------+--------------------------+
| Key                                       | Value                    |
+===========================================+==========================+
| ``CONSTRAINT_NAME``                       | Key is a unique name.    |
+-------------------------------------------+--------------------------+
| ``type``                                  | The type of constraint.  |
|                                           | See **Constraint Types** |
|                                           | for a list of currently  |
|                                           | supported values.        |
+-------------------------------------------+--------------------------+
| ``demands``                               | One or more previously   |
|                                           | declared demands. If     |
|                                           | only one demand is       |
|                                           | specified, it may appear |
|                                           | without list markers     |
|                                           | (``[]``).                |
+-------------------------------------------+--------------------------+
| ``properties`` (Optional)                 | Properties particular to |
|                                           | the specified constraint |
|                                           | type. Use if required by |
|                                           | the constraint.          |
+-------------------------------------------+--------------------------+

.. code:: yaml

    constraints:
      CONSTRAINT_NAME_1:
        type: CONSTRAINT_TYPE
        demands: DEMAND_NAME | [DEMAND_NAME_1, DEMAND_NAME_2, ...]
        properties: PROPERTY_DICT

      CONSTRAINT_NAME_2:
        type: CONSTRAINT_TYPE
        demands: DEMAND_NAME | [DEMAND_NAME_1, DEMAND_NAME_2, ...]
        properties: PROPERTY_DICT

      ...

Constraint Types
~~~~~~~~~~~~~~~~

+-------------------------------------------+--------------------------+
| Type                                      | Description              |
+===========================================+==========================+
| ``attribute``                             | Constraint that matches  |
|                                           | the specified list of    |
|                                           | Attributes.              |
+-------------------------------------------+--------------------------+
| ``distance_between_demands``              | Geographic distance      |
|                                           | constraint between each  |
|                                           | pair of a list of        |
|                                           | demands.                 |
+-------------------------------------------+--------------------------+
| ``distance_to_location``                  | Geographic distance      |
|                                           | constraint between each  |
|                                           | of a list of demands and |
|                                           | a specific location.     |
+-------------------------------------------+--------------------------+
| ``instance_fit``                          | Constraint that ensures  |
|                                           | available capacity in an |
|                                           | existing service         |
|                                           | instance for an incoming |
|                                           | demand.                  |
+-------------------------------------------+--------------------------+
| ``inventory_group``                       | Constraint that enforces |
|                                           | two or more demands are  |
|                                           | satisfied using          |
|                                           | candidates from a        |
|                                           | pre-established group in |
|                                           | the inventory.           |
+-------------------------------------------+--------------------------+
| ``region_fit``                            | Constraint that ensures  |
|                                           | available capacity in an |
|                                           | existing cloud region    |
|                                           | for an incoming demand.  |
+-------------------------------------------+--------------------------+
| ``zone``                                  | Constraint that enforces |
|                                           | co-location/diversity at |
|                                           | the granularities of     |
|                                           | clouds/regions/availabil |
|                                           | ity-zones.               |
+-------------------------------------------+--------------------------+
| ``hpa``                                   | Constraint that          |
|                                           | recommends cloud region  |
|                                           | with an optimal flavor   |
|                                           | based on required HPA    |
|                                           | capabilities for an      |
|                                           | incoming demand.         |
+-------------------------------------------+--------------------------+
| ``vim_fit``                               | Constraint that checks if|
|                                           | the incoming demand fits |
|                                           | the VIM instance.        |
+-------------------------------------------+--------------------------+
| ``license`` (Deferred)                    | License availability     |
|                                           | constraint.              |
+-------------------------------------------+--------------------------+
| ``network_between_demands`` (Deferred)    | Network constraint       |
|                                           | between each pair of a   |
|                                           | list of demands.         |
+-------------------------------------------+--------------------------+
| ``network_to_location`` (Deferred)        | Network constraint       |
|                                           | between each of a list   |
|                                           | of demands and a         |
|                                           | specific                 |
|                                           | location/address.        |
+-------------------------------------------+--------------------------+
| ``threshold``                             | Constraint that checks if|
|                                           | an attribute is within   |
|                                           | the threshold.           |
+-------------------------------------------+--------------------------+

*Note: Constraint names marked “Deferred” **will not** be supported in
the current release of HAS.*

Threshold Values
~~~~~~~~~~~~~~~~

Constraint property values representing a threshold may be an integer or
floating point number, optionally prefixed with a comparison operator:
``=``, ``<``, ``>``, ``<=``, or ``>=``. The default is ``=`` and
optionally suffixed with a unit.

Whitespace may appear between the comparison operator and value, and
between the value and units. When a range values is specified (e.g.,
``10-20 km``), the comparison operator is omitted.

Each property is documented with a default unit. The following units are
supported:

+------------+------------------------------+----------+
| Unit       | Values                       | Default  |
+============+==============================+==========+
| Currency   | ``USD``                      | ``USD``  |
+------------+------------------------------+----------+
| Time       | ``ms``, ``sec``              | ``ms``   |
+------------+------------------------------+----------+
| Distance   | ``km``, ``mi``               | ``km``   |
+------------+------------------------------+----------+
| Throughput | ``Kbps``, ``Mbps``, ``Gbps`` | ``Mbps`` |
+------------+------------------------------+----------+

Attribute
~~~~~~~~~

Constrain one or more demands by one or more attributes, expressed as
properties. Attributes are mapped to the **inventory provider**
specified properties, referenced by the demands. For example, properties
could be hardware capabilities provided by the platform (flavor,
CPU-Pinning, NUMA), features supported by the services, etc.

**Schema**

+--------------+---------------------------------------------------------+
| Property     | Value                                                   |
+==============+=========================================================+
| ``evaluate`` | Opaque dictionary of attribute name and value pairs.    |
|              | Values must be strings or numbers. Encoded and sent to  |
|              | the service provider via a plugin.                      |
+--------------+---------------------------------------------------------+

*Note: Attribute values are not detected/parsed as thresholds by the
Homing framework. Such interpretations and evaluations are inventory
provider-specific and delegated to the corresponding plugin*

.. code:: yaml

    constraints:
      sriov_nj:
        type: attribute
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          evaluate:
            cloud_version: 1.1
            flavor: SRIOV
            subdivision: US-TX
            vcpu_pinning: True
            numa_topology: numa_spanning

Proposal: Evaluation Operators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To assist in evaluating attributes, the following operators and notation
are proposed:

+-----------+-----------+------------------------------------------------+
| Operator  | Name      | Operand                                        |
+===========+===========+================================================+
| ``eq``    | ``==``    | Any object (string, number, list, dict)        |
+-----------+-----------+------------------------------------------------+
| ``ne``    | ``!=``    |                                                |
+-----------+-----------+------------------------------------------------+
| ``lt``    | ``<``     | A number (strings are converted to float)      |
+-----------+-----------+------------------------------------------------+
| ``gt``    | ``>``     |                                                |
+-----------+-----------+------------------------------------------------+
| ``lte``   | ``<=``    |                                                |
+-----------+-----------+------------------------------------------------+
| ``gte``   | ``>=``    |                                                |
+-----------+-----------+------------------------------------------------+
| ``any``   | ``Any``   | A list of objects (string, number, list, dict) |
+-----------+-----------+------------------------------------------------+
| ``all``   | ``All``   |                                                |
+-----------+-----------+------------------------------------------------+
| ``regex`` | ``RegEx`` | A regular expression pattern                   |
+-----------+-----------+------------------------------------------------+

Example usage:

.. code:: yaml

    constraints:
      sriov_nj:
        type: attribute
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          evaluate:
            cloud_version: {gt: 1.0}
            flavor: {regex: /^SRIOV$/i}
            subdivision: {any: [US-TX, US-NY, US-CA]}

Distance Between Demands
~~~~~~~~~~~~~~~~~~~~~~~~

Constrain each pairwise combination of two or more demands by distance
requirements.

**Schema**

+--------------+------------------------------------------------------------+
| Name         | Value                                                      |
+==============+============================================================+
| ``distance`` | Distance between demands, measured by the geographic path. |
+--------------+------------------------------------------------------------+

The constraint is applied between each pairwise combination of demands.
For this reason, at least two demands must be specified, implicitly or
explicitly.

.. code:: yaml

    constraints:
      distance_vnf1_vnf2:
        type: distance_between_demands
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          distance: < 250 km

Distance To Location
~~~~~~~~~~~~~~~~~~~~

Constrain one or more demands by distance requirements relative to a
specific location.

**Schema**

+--------------+------------------------------------------------------------+
| Property     | Value                                                      |
+==============+============================================================+
| ``distance`` | Distance between demands, measured by the geographic path. |
+--------------+------------------------------------------------------------+
| ``location`` | A previously declared location.                            |
+--------------+------------------------------------------------------------+

The constraint is applied between each demand and the referenced
location, not across all pairwise combinations of Demands.

.. code:: yaml

    constraints:
      distance_vnf1_loc:
        type: distance_to_location
        demands: [my_vnf_demand, my_other_vnf_demand, another_vnf_demand]
        properties:
          distance: < 250 km
          location: LOCATION_ID

Instance Fit
~~~~~~~~~~~~

Constrain each demand by its service requirements.

Requirements are sent as a request to a **service controller**. Service
controllers are defined by plugins in Homing (e.g., ``sdn-c``).

A service controller plugin knows how to communicate with a particular
endpoint (via HTTP/REST, DMaaP, etc.), obtain necessary information, and
make a decision. The endpoint and credentials can be configured through
plugin settings.

**Schema**

+---------------------+------------------------------------------------+
| Property            | Description                                    |
+=====================+================================================+
| ``controller``      | Name of a service controller.                  |
+---------------------+------------------------------------------------+
| ``request``         | Opaque dictionary of key/value pairs. Values   |
|                     | must be strings or numbers. Encoded and sent   |
|                     | to the service provider via a plugin.          |
+---------------------+------------------------------------------------+

.. code:: yaml

    constraints:
      check_for_availability:
        type: instance_fit
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          controller: sdn-c
          request: REQUEST_DICT

Region Fit
~~~~~~~~~~

Constrain each demand’s inventory candidates based on inventory provider
membership.

Requirements are sent as a request to a **service controller**. Service
controllers are defined by plugins in Homing (e.g., ``sdn-c``).

A service controller plugin knows how to communicate with a particular
endpoint (via HTTP/REST, DMaaP, etc.), obtain necessary information, and
make a decision. The endpoint and credentials can be configured through
plugin settings.

**Schema**

+---------------------+------------------------------------------------+
| Property            | Description                                    |
+=====================+================================================+
| ``controller``      | Name of a service controller.                  |
+---------------------+------------------------------------------------+
| ``request``         | Opaque dictionary of key/value pairs. Values   |
|                     | must be strings or numbers. Encoded and sent   |
|                     | to the service provider via a plugin.          |
+---------------------+------------------------------------------------+

.. code:: yaml

    constraints:
      check_for_membership:
        type: region_fit
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          controller: sdn-c
          request: REQUEST_DICT

Zone
~~~~

Constrain two or more demands such that each is located in the same or
different zone category.

Zone categories are inventory provider-defined, based on the demands
being constrained.

**Schema**

+---------------+--------------------------------------------------------+
| Property      | Value                                                  |
+===============+========================================================+
| ``qualifier`` | Zone qualifier. One of ``same`` or ``different``.      |
|               |                                                        |
+---------------+--------------------------------------------------------+
| ``category``  | Zone category. One of ``disaster``, ``region``,        |
|               | ``complex``, ``time``, or ``maintenance``.             |
+---------------+--------------------------------------------------------+

For example, to place two demands in different disaster zones:

.. code:: yaml

    constraints:
      vnf_diversity:
        type: zone
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          qualifier: different
          category: disaster

Or, to place two demands in the same region:

.. code:: yaml

    constraints:
      vnf_affinity:
        type: zone
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          qualifier: same
          category: region

**Notes**

-  These categories could be any of the following: ``disaster_zone``,
   ``region``, ``complex``, ``time_zone``, and ``maintenance_zone``.
   Really, we are talking affinity/anti-affinity at the level of DCs,
   but these terms may cause confusion with affinity/anti-affinity in
   OpenStack.

HPA & Cloud Agnostic Intent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Constrain each demand's inventory candidates based on cloud regions' Hardware
platform capabilities (HPA) and also intent support. Note that currently HPA
the cloud agnostic constraints will use the same schema.

Requirements mapped to the inventory provider specified properties, referenced
by the demands. For eg, properties could be hardware capabilities provided by
the platform through flavors or cloud-region eg:(CPU-Pinning, NUMA), features
supported by the services, etc.


**Schema**

+---------------+--------------------------------------------------------+
| Property      | Value                                                  |
+===============+========================================================+
| ``evaluate``  | List of id, type, directives and flavorProperties of   |
|               | each VM of the VNF demand.                             |
+---------------+--------------------------------------------------------+

+-------------------------+--------------------------------------------------------+
| Property for evaluation | Value                                                  |
+=========================+========================================================+
| ``id``                  | Name of VFC                                            |
+-------------------------+--------------------------------------------------------+
| ``type``                | Type of VFC. Could be ``vnfc`` or ``tocsa.nodes.nfv.   |
|                         | Vdu.Compute`` according to different models            |
+-------------------------+--------------------------------------------------------+
| ``directives``          | Directives for one VFC. Now we only have flavor        |
|                         | directives inside. Each VFC must have one directive    |
+-------------------------+--------------------------------------------------------+
| ``flavorProperties``    | Flavor properties for one VFC. Contains detailed       |
|                         | HPA requirements                                       |
+-------------------------+--------------------------------------------------------+

+--------------------------+-------------------------------------------+
| Property for directives  | Value                                     |
+==========================+===========================================+
| ``type``                 | Type of directive                         |
+--------------------------+-------------------------------------------+
| ``attributes``           | Attributes inside directive               |
+--------------------------+-------------------------------------------+

+--------------------------+-------------------------------------------+
| Property for attributes  | Value                                     |
+==========================+===========================================+
| ``attribute_name``       | Attribute name/label                      |
+--------------------------+-------------------------------------------+
| ``attributes_value``     | Attributes value                          |
+--------------------------+-------------------------------------------+

*Note*: Each VFC must have one directive with type 'flavor_directives' to put the
flavors inside. The ``attribute_name`` is the place to put flavor label and the
``attribute_value`` will first left blank. After getting the proper flavor, OOF will
merge the flavor name into the ``attribute_value`` inside flavor directives. Also,
all the directives coming from one VFC inside the same request will be merged
together in ``directives``, as they are using the same structure as 'directives'.

.. code:: yaml

    constraints:
      hpa_constraint:
        type: hpa
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          evaluate:
            - [ List of {id: {vdu Name},
                        type: {type of VF },
                        directives: DIRECTIVES LIST,
                        flavorProperties: HPACapability DICT} ]

    HPACapability DICT :
      hpa-feature: basicCapabilities
      hpa-version: v1
      architecture: generic
      directives:
        - DIRECTIVES LIST
      hpa-feature-attributes:
        - HPAFEATUREATTRIBUTES LIST

    DIRECTIVES LIST:
      type: String
      attributes:
        - ATTRIBUTES LIST

    ATTRIBUTES LIST:
      attribute_name: String,
      attribute_value: String

    HPAFEATUREATTRIBUTES LIST:
      hpa-attribute-key: String
      hpa-attribute-value: String
      operator: One of OPERATOR
      unit: String
    OPERATOR : ['=', '<', '>', '<=', '>=', 'ALL']

**Example**

Example for HEAT request(SO)

*Note*: Where "attributes":[{"attribute_name":" oof_returned_flavor_label_for_vgw_1 ",
    Admin needs to ensure that this value is same as flavor parameter in HOT

.. code-block:: json

    {
        "hpa_constraint":{
            "type":"hpa",
            "demands":[
               "vG"
            ],
            "properties":{
               "evaluate":[
                  {
                     "id": "vgw_0",
                     "type": "vnfc",
                     "directives": [
                        {
                         "type":"flavor_directives",
                         "attributes":[
                            {
                             "attribute_name":" oof_returned_flavor_label_for_vgw_0 ", 
                             "attribute_value": "<Blank>"
                            }
                         ]
                        }
                     ],
                     "flavorProperties":[
                        {
                           "hpa-feature":"basicCapabilities",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "True",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"numVirtualCpu",
                                 "hpa-attribute-value":"32",
                                 "operator":"="
                              }
                           ]
                        },
                        {
                           "hpa-feature":"basicCapabilities",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "True",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"virtualMemSize",
                                 "hpa-attribute-value":"64",
                                 "operator":"=",
                                 "unit":"GB"
                              }
                           ]
                        },
                        {
                           "hpa-feature":"ovsDpdk",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "False",
                           "score": "10",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"dataProcessingAccelerationLibrary",
                                 "hpa-attribute-value":"v18.02",
                                 "operator":"="
                              }
                           ]
                        },
                        {
                           "hpa-feature": "qosIntentCapabilities",
                           "mandatory": "True",
                           "architecture": "generic",
                           "hpa-version": "v1",
                           "directives": [],
                           "hpa-feature-attributes": [
                              {
                                 "hpa-attribute-key":"Infrastructure Resource Isolation for VNF",
                                 "hpa-attribute-value": "Burstable QoS",
                                 "operator": "=",
                                 "unit": ""
                              },
                              {  "hpa-attribute-key":"Burstable QoS Oversubscription Percentage",
                                 "hpa-attribute-value": "25",
                                 "operator": "=",
                                 "unit": ""
                              }
                           ]
                        }
                     ]
                  },
                  {
                     "id": "vgw_1",
                     "type": "vnfc",
                     "directives": [
                        {
                         "type":"flavor_directives",
                         "attributes":[
                            {
                             "attribute_name":" oof_returned_flavor_label_for_vgw_1 ", 
                             "attribute_value": "<Blank>"
                            }
                         ]
                        }
                     ],
                     "flavorProperties":[
                        {
                           "hpa-feature":"basicCapabilities",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "False",
                           "score": "5",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"numVirtualCpu",
                                 "hpa-attribute-value":"8",
                                 "operator":">="
                              }
                           ]
                        },
                        {
                           "hpa-feature":"basicCapabilities",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "False",
                           "score": "5",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"virtualMemSize",
                                 "hpa-attribute-value":"16",
                                 "operator":">=",
                                 "unit":"GB"
                              }
                           ]
                        },
                        {
                           "hpa-feature":"sriovNICNetwork",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "True",
                           "directives": [
                              {
                                "type": "sriovNICNetwork_directives",
                                "attributes": [
                                   { "attribute_name": "oof_returned_vnic_type_for_vgw_1",
                                     "attribute_value": "direct"
                                   },
                                   { "attribute_name": "oof_returned_provider_network_for_vgw_1",
                                     "attribute_value": "physnet2"
                                   }
                                ]
                              }
                           ],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"pciVendorId",
                                 "hpa-attribute-value":"8086",
                                 "operator":"=",
                                 "unit":""
                              },
                              {
                                 "hpa-attribute-key":"pciDeviceId",
                                 "hpa-attribute-value":"0443",
                                 "operator":"=",
                                 "unit":""
                              },
                              {
                                 "hpa-attribute-key":"pciCount",
                                 "hpa-attribute-value":"1",
                                 "operator":"=",
                                 "unit":""
                              },
                              {
                                 "hpa-attribute-key":"physicalNetwork",
                                 "hpa-attribute-value":"physnet2",
                                 "operator":"=",
                                 "unit":""
                              }
                           ]
                        }
                     ]
                  }
               ]
            }
         }
      }
      
Example for Pure TOSCA request(VF-C)

.. code-block:: json

    {
        "hpa_constraint":{
            "type":"hpa",
            "demands":[
               "vG"
            ],
            "properties":{
               "evaluate":[
                  {
                     "id": "vgw_0",
                     "type": "tocsa.nodes.nfv.Vdu.Compute",
                     "directives": [
                        {
                         "type":"flavor_directives",
                         "attributes":[
                            {
                             "attribute_name":" flavor_name ",
                             "attribute_value": "<Blank>"
                            }
                         ]
                        }
                     ],
                     "flavorProperties":[
                        {
                           "hpa-feature":"basicCapabilities",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "True",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"numVirtualCpu",
                                 "hpa-attribute-value":"32",
                                 "operator":"="
                              }
                           ]
                        },
                        {
                           "hpa-feature":"basicCapabilities",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "True",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"virtualMemSize",
                                 "hpa-attribute-value":"64",
                                 "operator":"=",
                                 "unit":"GB"
                              }
                           ]
                        },
                        {
                           "hpa-feature":"ovsDpdk",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "False",
                           "score": "10",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"dataProcessingAccelerationLibrary",
                                 "hpa-attribute-value":"v18.02",
                                 "operator":"="
                              }
                           ]
                        },
                        {
                           "hpa-feature": "qosIntentCapabilities",
                           "mandatory": "True",
                           "architecture": "generic",
                           "hpa-version": "v1",
                           "directives": [],
                           "hpa-feature-attributes": [
                              {
                                 "hpa-attribute-key":"Infrastructure Resource Isolation for VNF",
                                 "hpa-attribute-value": "Burstable QoS",
                                 "operator": "=",
                                 "unit": ""
                              },
                              {  "hpa-attribute-key":"Burstable QoS Oversubscription Percentage",
                                 "hpa-attribute-value": "25",
                                 "operator": "=",
                                 "unit": ""
                              }
                           ]
                        }
                     ]
                  },
                  {
                     "id": "vgw_1",
                     "type": "tosca.nodes.nfv.Vdu.Compute",
                     "directives": [
                        {
                         "type":"flavor_directives",
                         "attributes":[
                            {
                             "attribute_name":" flavor_name ",
                             "attribute_value": "<Blank>"
                            }
                         ]
                        }
                     ],
                     "flavorProperties":[
                        {
                           "hpa-feature":"basicCapabilities",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "False",
                           "score": "5",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"numVirtualCpu",
                                 "hpa-attribute-value":"8",
                                 "operator":">="
                              }
                           ]
                        },
                        {
                           "hpa-feature":"basicCapabilities",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "False",
                           "score": "5",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"virtualMemSize",
                                 "hpa-attribute-value":"16",
                                 "operator":">=",
                                 "unit":"GB"
                              }
                           ]
                        },
                        {
                           "hpa-feature":"sriovNICNetwork",
                           "hpa-version":"v1",
                           "architecture":"generic",
                           "mandatory": "True",
                           "directives": [],
                           "hpa-feature-attributes":[
                              {
                                 "hpa-attribute-key":"pciVendorId",
                                 "hpa-attribute-value":"8086",
                                 "operator":"=",
                                 "unit":""
                              },
                              {
                                 "hpa-attribute-key":"pciDeviceId",
                                 "hpa-attribute-value":"0443",
                                 "operator":"=",
                                 "unit":""
                              },
                              {
                                 "hpa-attribute-key":"pciCount",
                                 "hpa-attribute-value":"1",
                                 "operator":"=",
                                 "unit":""
                              },
                           ]
                        }
                     ]
                  }
               ]
            }
         }
      }

VIM Fit
~~~~~~~

Constrain each demand's inventory candidates based on capacity check for
available capacity at the VIM instances.

Requirements are sent as an opaque request object understood by the VIM
controllers or MultiCloud. Each controller is defined and implemented as a
plugin in Conductor.

A vim controller plugin knows how to communicate with a particular endpoint
(via HTTP/REST, DMaaP, etc.), obtain necessary information, and make a
decision. The endpoint and credentials can be configured through plugin
settings.


**Schema**

+----------------+--------------------------------------------------------+
| Property       | Value                                                  |
+================+========================================================+
| ``controller`` | Name of a vim controller. (e.g., multicloud)           |
+----------------+--------------------------------------------------------+
| ``request``    | Opaque dictionary of key/value pairs. Values           |
|                | must be strings or numbers. Encoded and sent           |
|                | to the vim controller via a plugin.                    |
+----------------+--------------------------------------------------------+

.. code:: yaml

    constraints:
      check_cloud_capacity:
        type: vim_fit
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          controller: multicloud
          request: REQUEST_DICT

**Notes**

-  For the current release the REQUEST_DICT is of the following format as
   defined by the policy for vim_fit. The REQUEST_DICT is an opaque request
   object defined through policy, so it is not restricted to this format. In
   the current release MultiCloud supports the check_vim_capacity using the
   following grammar.

   .. code-block:: json

       {
         "request":{
           "vCPU":10,
           "Memory":{
             "quantity":{
               "get_param":"REQUIRED_MEM"
             },
             "unit":"GB"
           },
           "Storage":{
             "quantity":{
               "get_param":"REQUIRED_DISK"
             },
             "unit":"GB"
           }
         }
       }

Inventory Group
~~~~~~~~~~~~~~~

Constrain demands such that inventory items are grouped across two
demands.

This constraint has no properties.

.. code:: yaml

    constraints:
      my_group:
        type: inventory_group
        demands: [demand_1, demand_2]

*Note: Only pair-wise groups are supported at this time. The list must
have only two demands.*

License
~~~~~~~

Constrain demands according to license availability.

*Support for this constraint is deferred to a later release.*

**Schema**

+----------+----------------------------------------------------------+
| Property | Value                                                    |
+==========+==========================================================+
| ``id``   | Unique license identifier                                |
+----------+----------------------------------------------------------+
| ``key``  | Opaque license key, particular to the license identifier |
+----------+----------------------------------------------------------+

.. code:: yaml

    constraints:
      my_software:
        type: license
        demands: [demand_1, demand_2, ...]
        properties:
          id: SOFTWARE_ID
          key: LICENSE_KEY

Network Between Demands
~~~~~~~~~~~~~~~~~~~~~~~

Constrain each pairwise combination of two or more demands by network
requirements.

*Support for this constraint is deferred to a later release.*

**Schema**

+-------------------+--------------------------------------------------+
| Property          | Value                                            |
+===================+==================================================+
| ``bandwidth``     | Desired network bandwidth.                       |
| (Optional)        |                                                  |
+-------------------+--------------------------------------------------+
| ``distance``      | Desired distance between demands, measured by    |
| (Optional)        | the network path.                                |
+-------------------+--------------------------------------------------+
| ``latency``       | Desired network latency.                         |
| (Optional)        |                                                  |
+-------------------+--------------------------------------------------+

Any combination of ``bandwidth``, ``distance``, or ``latency`` must be
specified. If none of these properties are used, it is treated as a
malformed request.

The constraint is applied between each pairwise combination of demands.
For this reason, at least two demands must be specified, implicitly or
explicitly.

.. code:: yaml

    constraints:
      network_requirements:
        type: network_between_demands
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          bandwidth: >= 1000 Mbps
          distance: < 250 km
          latency: < 50 ms

Network To Location
~~~~~~~~~~~~~~~~~~~

Constrain one or more demands by network requirements relative to a
specific location.

*Support for this constraint is deferred to a later release.*

**Schema**

+-----------------------------------+-----------------------------------+
| Property                          | Value                             |
+===================================+===================================+
| ``bandwidth``                     | Desired network bandwidth.        |
+-----------------------------------+-----------------------------------+
| ``distance``                      | Desired distance between demands, |
|                                   | measured by the network path.     |
+-----------------------------------+-----------------------------------+
| ``latency``                       | Desired network latency.          |
+-----------------------------------+-----------------------------------+
| ``location``                      | A previously declared location.   |
+-----------------------------------+-----------------------------------+

Any combination of ``bandwidth``, ``distance``, or ``latency`` must be
specified. If none of these properties are used, it is treated as a
malformed request.

The constraint is applied between each demand and the referenced
location, not across all pairwise combinations of Demands.

.. code:: yaml

    constraints:
      my_access_network_constraint:
        type: network_to_location
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          bandwidth: >= 1000 Mbps
          distance: < 250 km
          latency: < 50 ms
          location: LOCATION_ID

Capabilities
~~~~~~~~~~~~

Constrain each demand by its cluster capability requirements. For
example, as described by an OpenStack Heat template and operational
environment.

*Support for this constraint is deferred to a later release.*

**Schema**

+-------------------+---------------------------------------------------------+
| Property          | Value                                                   |
+===================+=========================================================+
| ``specification`` | Indicates the kind of specification being provided in   |
|                   | the properties. Must be ``heat``. Future values may     |
|                   | include ``tosca``, ``Homing``, etc.                     |
+-------------------+---------------------------------------------------------+
| ``template``      | For specifications of type ``heat``, a single stack in  |
|                   | OpenStack Heat Orchestration Template (HOT) format.     |
|                   | Stacks may be expressed as a URI reference or a string  |
|                   | of well-formed YAML/JSON. Templates are validated by    |
|                   | the Heat service configured for use by HAS. Nested      |
|                   | stack references are unsupported.                       |
+-------------------+---------------------------------------------------------+
| ``environment``   | For specifications of type ``heat``, an optional Heat   |
|                   | environment. Environments may be expressed as a URI     |
| (Optional)        | reference or a string of well-formed YAML/JSON.         |
|                   | Environments are validated by the Heat service          |
|                   | configured for use by Homing.                           |
+-------------------+---------------------------------------------------------+

.. code:: yaml

    constraints:
      check_for_fit:
        type: capability
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          specification: heat
          template: http://repository/my/stack_template
          environment: http://repository/my/stack_environment

Threshold
~~~~~~~~~

Constrain each demand by an attribute which is within a certain
threshold.

**Schema**

+---------------+--------------------------------------------------------+
| Property      | Value                                                  |
+===============+========================================================+
| ``evaluate``  | List of  attributes and its threshold                  |
+---------------+--------------------------------------------------------+

+-------------------------+------------------------------------------+
| Property for evaluation | Value                                    |
+=========================+==========================================+
| ``attribute``           | Attribute of a candidate                 |
+-------------------------+------------------------------------------+
| ``threshold``           | Threshold Value                          |
+-------------------------+------------------------------------------+
| ``operator``            | Condition to check. Supported Values are |
|                         | ``gte``, ``lte``, ``lt``, ``gt``, ``eq`` |
+-------------------------+------------------------------------------+
| ``unit`` (optional)     | Attribute's unit of measurement          |
+-------------------------+------------------------------------------+

.. code:: yaml

    urllc_threshold:
      type: threshold
      demands: ['URLLC']
      properties:
        evaluate:
        - attribute: latency
          operator: lte
          threshold: 50
          unit: ms
        - attribute: reliability
          operator: gte
          threshold: 99.99

**Note:**

- The status of the constraint support is of Frankfurt release.

Reservations
------------

A **Reservation** allows reservation of resources associated with
candidate that satisfies one or more demands.

Similar to the *instance_fit* constraint, requirements are sent as a
request to a **service controller** that handles the reservation.
Service controllers are defined by plugins in Homing (e.g., ``sdn-c``).

The service controller plugin knows how to make a reservation (and
initiate rollback on a failure) with a particular endpoint (via
HTTP/REST, DMaaP, etc.) of the service controller. The endpoint and
credentials can be configured through plugin settings.

**Schema**

+---------------------+------------------------------------------------+
| Property            | Description                                    |
+=====================+================================================+
| ``controller``      | Name of a service controller.                  |
+---------------------+------------------------------------------------+
| ``request``         | Opaque dictionary of key/value pairs. Values   |
|                     | must be strings or numbers. Encoded and sent   |
|                     | to the service provider via a plugin.          |
+---------------------+------------------------------------------------+

.. code:: yaml

    resource_reservation:
      type: instance_reservation
      demands: [my_vnf_demand, my_other_vnf_demand]
      properties:
        controller: sdn-c
        request: REQUEST_DICT

Optimizations
-------------

An **Optimization** allows specification of a objective function, which
aims to maximize or minimize a certain value that varies based on the
choice of candidates for one or more demands that are a part of the
objective function. For example, an objective function may be to find
the *closest* cloud-region to a customer to home a demand.

Optimization Components
~~~~~~~~~~~~~~~~~~~~~~~

Optimization definitions can be broken down into three components:

+-------+----------------+--------------------------------------------+
| Compo | Key            | Value                                      |
| nent  |                |                                            |
+=======+================+============================================+
| Goal  | ``minimize``   | A single Operand (usually ``sum``) or      |
|       |                | Function                                   |
+-------+----------------+--------------------------------------------+
| Opera | ``sum``,       | Two or more Operands (Numbers, Operators,  |
| tor   | ``product``    | Functions)                                 |
+-------+----------------+--------------------------------------------+
| Funct | ``distance_bet | A two-element list consisting of a         |
| ion   | ween``         | location and demand.                       |
+-------+----------------+--------------------------------------------+

.. _example-1:

Example
~~~~~~~

Given a customer location ``cl``, two demands ``vG1`` and ``vG2``, and
weights ``w1`` and ``w2``, the optimization criteria can be expressed
as:

``minimize(weight1 * distance_between(cl, vG1) + weight2 * distance_between(cl, vG2))``

This can be read as: “Minimize the sum of weighted distances from cl to
vG1 and from cl to vG2.”

Such optimizations may be expressed in a template as follows:

.. code:: yaml

    parameters:
      w1: 10
      w2: 20

    optimization:
      minimize:
        sum:
        - product:
          - {get_param: w1}
          - {distance_between: [cl, vG1]}
        - product:
          - {get_param: w2}
          - {distance_between: [cl, vG2]}

Or without the weights as:

.. code:: yaml

    optimization:
      minimize:
        sum:
        - {distance_between: [cl, vG1]}
        - {distance_between: [cl, vG2]}

**Template Restriction**

While the template format supports any number of arrangements of
numbers, operators, and functions, HAS’s solver presently expects a very
specific arrangement.

-  Optimizations must conform to a single goal of ``minimize`` followed
   by a ``sum`` operator.
-  The sum can consist of two ``distance_between`` function calls, or
   two ``product`` operators.
-  If a ``product`` operator is present, it must contain at least a
   ``distance_between`` function call, plus one optional number to be
   used for weighting.
-  Numbers may be referenced via ``get_param``.
-  The objective function has to be written in the sum-of-product
   format. In the future, HAS can convert product-of-sum into
   sum-of-product automatically.

The first two examples in this section illustrate both of these use
cases.

**Inline Operations**

If desired, operations can be rewritten inline. For example, the two
``product`` operations from the previous example can also be expressed
as:

.. code:: yaml

    parameters:
      w1: 10
      w2: 20

    optimization:
      minimize:
        sum:
        - {product: [{get_param: w1}, {distance_between: [cl, vG1]}]}
        - {product: [{get_param: w2}, {distance_between: [cl, vG2]}]}

In turn, even the ``sum`` operation can be rewritten inline, however
there is a point of diminishing returns in terms of readability!

**Notes**

-  We do not support more than one dimension in the optimization
   (e.g., Minimize distance and cost). For supporting multiple
   dimensions we would need a function the normalize the unit across
   dimensions.

Intrinsic Functions
-------------------

Homing provides a set of intrinsic functions that can be used inside
templates to perform specific tasks. The following section describes the
role and syntax of the intrinsic functions.

Functions are written as a dictionary with one key/value pair. The key
is the function name. The value is a list of arguments. If only one
argument is provided, a string may be used instead.

.. code:: yaml

    a_property: {FUNCTION_NAME: [ARGUMENT_LIST]}

    a_property: {FUNCTION_NAME: ARGUMENT_STRING}

*Note: These functions can only be used within “properties” sections.*

get_file
~~~~~~~~

The ``get_file`` function inserts the content of a file into the
template. It is generally used as a file inclusion mechanism for files
containing templates from other services (e.g., Heat).

The syntax of the ``get_file`` function is:

.. code:: yaml

    {get_file: <content key>}

The ``content`` key is used to look up the ``files`` dictionary that is
provided in the REST API call. The Homing client command (``Homing``) is
``get_file`` aware and populates the ``files`` dictionary with the
actual content of fetched paths and URLs. The Homing client command
supports relative paths and transforms these to the absolute URLs
required by the Homing API.

**Note**: The ``get_file`` argument must be a static path or URL and not
rely on intrinsic functions like ``get_param``. The Homing client does
not process intrinsic functions. They are only processed by the Homing
engine.

The example below demonstrates the ``get_file`` function usage with both
relative and absolute URLs:

.. code:: yaml

    constraints:
      check_for_fit:
        type: capacity
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          template: {get_file: stack_template.yaml}
          environment: {get_file: http://hostname/environment.yaml}

The ``files`` dictionary generated by the Homing client during
instantiation of the plan would contain the following keys. Each value
would be of that file’s contents.

-  ``file:///path/to/stack_template.yaml``
-  ``http://hostname/environment.yaml``

**Note**

-  If Homing will only be accessed over DMaaP, files will need to be
   embedded using the Homing API request format. This will be a
   consideration when DMaaP integration happens.

get_param
~~~~~~~~~

The ``get_param`` function references an input parameter of a template.
It resolves to the value provided for this input parameter at runtime.

The syntax of the ``get_param`` function is:

.. code:: yaml

    {get_param: <parameter name>}

    {get_param: [<parameter name>, <key/index1> (optional), <key/index2> (optional), ...]}

**parameter name** is the parameter name to be resolved. If the
parameters returns a complex data structure such as a list or a dict,
then subsequent keys or indices can be specified. These additional
parameters are used to navigate the data structure to return the desired
value. Indices are zero-based.

The following example demonstrates how the ``get_param`` function is
used:

.. code:: yaml

    parameters:
      software_id: SOFTWARE_ID
      license_key: LICENSE_KEY
      service_info:
        provider: dmaap:///full.topic.name
        costs: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

    constraints:
      my_software:
        type: license
        demands: [demand_1, demand_2, ...]
        properties:
          id: {get_param: software_id}
          key: {get_param: license_key}

      check_for_availability:
        type: service
        demands: [my_vnf_demand, my_other_vnf_demand]
        properties:
          provider_url: {get_param: [service_info, provider]}
          request: REQUEST_DICT
          cost: {get_param: [service_info, costs, 4]}

In this example, properties would be set as follows:

+------------------+--------------------------+
| Key              | Value                    |
+==================+==========================+
| ``id``           | SOFTWARE_ID              |
+------------------+--------------------------+
| ``key``          | LICENSE_KEY              |
+------------------+--------------------------+
| ``provider_url`` | dmaap:///full.topic.name |
+------------------+--------------------------+
| ``cost``         | 50                       |
+------------------+--------------------------+

Contact
-------

Shankar Narayanan shankarpnsn@gmail.com