summaryrefslogtreecommitdiff
path: root/lib/diameter/doc/src/diameter.xml
blob: aa4eb6ad456e7b4eda3a7b03e2861a5595701eee (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
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd" [
  <!ENTITY spawn_opt2
  '<seealso marker="erts:erlang#spawn_opt-2">erlang:spawn_opt/2</seealso>'>
  <!ENTITY spawn_opt5
  '<seealso marker="erts:erlang#spawn_opt-5">erlang:spawn_opt/5</seealso>'>
  <!ENTITY nodes
  '<seealso marker="erts:erlang#nodes-0">erlang:nodes/0</seealso>'>
  <!ENTITY make_ref
  '<seealso marker="erts:erlang#make_ref-0">erlang:make_ref/0</seealso>'>
  <!ENTITY transport_module
  '<seealso marker="diameter_transport">transport module</seealso>'>
  <!ENTITY dictionary
  '<seealso marker="diameter_dict">dictionary</seealso>'>
  <!ENTITY % also SYSTEM "seealso.ent" >
  <!ENTITY % here SYSTEM "seehere.ent" >
  %also;
  %here;
]>

<erlref>
<header>

<copyright>
<year>2011</year>
<year>2020</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

</legalnotice>

<title>diameter(3)</title>

<prepared>Anders Svensson</prepared>
<responsible></responsible>
<docno></docno>
<approved></approved>
<checked></checked>
<date></date>
<rev></rev>
<file>diameter.xml</file>

</header>

<!-- ===================================================================== -->
<!-- ===================================================================== -->

<module since="OTP R14B03">diameter</module>
<modulesummary>Main API of the diameter application.</modulesummary>

<description>
<p>
This module provides the interface with which a user can
implement a Diameter node that sends and receives messages using the
Diameter protocol as defined in &the_rfc;.</p>

<p>
Basic usage consists of creating a representation of a
locally implemented Diameter node and its capabilities with
&start_service;, adding transport capability using
&add_transport; and sending Diameter
requests and receiving Diameter answers with &call;.
Incoming Diameter requests are communicated as callbacks to a
&man_app; callback modules as
specified in the service configuration.</p>

<p>
Beware the difference between <em>diameter</em> (not capitalized) and
<em>Diameter</em> (capitalized).
The former refers to the Erlang application named diameter whose main
api is defined here, the latter to Diameter protocol in the sense of
&the_rfc;.</p>

<p>
The diameter application must be started before calling most functions
in this module.</p>

</description>

<!-- ===================================================================== -->
<!-- ===================================================================== -->
<section>
<title>DATA TYPES</title>

<taglist>

<tag><c>Address()</c></tag><item/>
<tag><c>DiameterIdentity()</c></tag><item/>
<tag><c>Grouped()</c></tag><item/>
<tag><c>OctetString()</c></tag><item/>
<tag><c>Time()</c></tag><item/>
<tag><c>Unsigned32()</c></tag><item/>
<tag><c>UTF8String()</c></tag>
<item>
<p>
Types corresponding to &the_rfc; AVP Data Formats.
Defined in &dict_data_types;.</p>

<marker id="application_alias"/>
</item>

<tag><c>application_alias() = term()</c></tag>
<item>
<p>
Name identifying a Diameter application in
service configuration.
Passed to &call; when sending requests
defined by the application.</p>

<marker id="application_module"/>
</item>

<tag><c>application_module() = Mod
                             | [Mod | ExtraArgs]
                             | #diameter_callback{}</c></tag>
<item>
<pre>
Mod = atom()
ExtraArgs = list()
</pre>

<p>
Module implementing the callback interface defined in &man_app;,
along with any
extra arguments to be appended to those documented.
Note that extra arguments specific to an outgoing request can be
specified to &call;, in which case
those are appended to any module-specific extra arguments.</p>

<p>
Specifying a <c>#diameter_callback{}</c> record allows individual
functions to be configured in place of the usual &man_app; callbacks.
See <c>diameter_callback.erl</c> for details.</p>

<marker id="application_opt"/>
</item>

<tag><c>application_opt()</c></tag>
<item>

<p>
Options defining a Diameter application.
Has one of the following types.</p>

<taglist>

<tag><c>{alias, &application_alias;}</c></tag>
<item>
<p>
Unique identifier for the application in the scope of the
service.
Defaults to the value of the <c>dictionary</c> option.</p>
</item>

<tag><c>{dictionary, atom()}</c></tag>
<item>
<p>
Name of an encode/decode module for the Diameter
messages defined by the application.
These modules are generated from files whose format is documented in
&man_dict;.</p>
</item>

<tag><c>{module, &application_module;}</c></tag>
<item>
<p>
Callback module in which messages of the Diameter application are
handled.
See &man_app; for the required interface and semantics.</p>
</item>

<tag><c>{state, term()}</c></tag>
<item>
<p>
Initial callback state.
The prevailing state is passed to some
&man_app;
callbacks, which can then return a new state.
Defaults to the value of the <c>alias</c> option.</p>
</item>

<tag><c>{call_mutates_state, true|false}</c></tag>
<item>
<p>
Whether or not the &app_pick_peer;
application callback can modify the application state.
Defaults to <c>false</c>.</p>

<warning>
<p>
&app_pick_peer; callbacks are serialized when this option is <c>true</c>,
which is a potential performance bottleneck.
A simple Diameter client may suffer no ill effects from using mutable
state but a server or agent that responds to incoming request should
probably avoid it.</p>
</warning>
</item>

<tag><c>{answer_errors, callback|report|discard}</c></tag>
<item>
<p>
Manner in which incoming answer messages containing
decode errors are handled.</p>

<p>
If <c>callback</c> then errors result in a &app_handle_answer;
callback in the same fashion as for &app_handle_request;, with
errors communicated in the <c>errors</c> field of the
<c>#diameter_packet{}</c> passed to the callback.
If <c>report</c> then an answer containing errors is discarded
without a callback and a warning report is written to the log.
If <c>discard</c> then an answer containing errors is silently
discarded without a callback.
In both the <c>report</c> and <c>discard</c> cases the return value
for the &call; invocation in
question is as if a callback had taken place and returned
<c>{error, failure}</c>.</p>

<p>
Defaults to <c>discard</c>.</p>
</item>

<tag><c>{request_errors, answer_3xxx|answer|callback}</c></tag>
<item>
<p>
Manner in which incoming requests are handled when an
error other than 3007 (DIAMETER_APPLICATION_UNSUPPORTED, which cannot
be associated with an application callback module), is detected.</p>

<p>
If <c>answer_3xxx</c> then requests are answered without a
&app_handle_request; callback taking place.
If <c>answer</c> then even 5xxx errors are answered without a
callback unless the connection in question has configured the RFC 3588
common dictionary as noted below.
If <c>callback</c> then a &app_handle_request; callback always takes
place and its return value determines the answer sent to the peer, if
any.</p>

<p>
Defaults to <c>answer_3xxx</c>.</p>

<note>
<p>
Answers sent by diameter set the E-bit in the Diameter Header.
Since RFC 3588 allows only 3xxx result codes in an
<c>answer-message</c>, <c>answer</c> has the same semantics as
<c>answer_3xxx</c> when the transport in question has
been configured with <c>diameter_gen_base_rfc3588</c> as its common
dictionary.
Since RFC 6733 allows both 3xxx and 5xxx result codes in an
<c>answer-message</c>, a transport with
<c>diameter_gen_base_rfc6733</c> as its common dictionary does
distinguish between <c>answer_3xxx</c> and <c>answer</c>.</p>
</note>
</item>

</taglist>

<marker id="call_opt"/>
</item>

<tag><c>call_opt()</c></tag>
<item>

<p>
Options available to &call; when
sending an outgoing Diameter request.
Has one of the following types.</p>

<taglist>

<tag><c>{extra, list()}</c></tag>
<item>
<p>
Extra arguments to append to callbacks to the callback
module in question.
These are appended to any extra arguments configured on the callback
itself.
Multiple options append to the argument list.</p>
</item>

<tag><c>{filter, &peer_filter;}</c></tag>
<item>
<p>
Filter to apply to the list of available peers before passing it to
the &app_pick_peer; callback for the application in question.
Multiple options are equivalent a single <c>all</c> filter on the
corresponding list of filters.
Defaults to <c>none</c>.</p>
</item>

<tag><c>{peer, &app_peer_ref;}</c></tag>
<item>
<p>
Peer to which the request in question can be sent, preempting the
selection of peers having advertised support for the Diameter
application in question.
Multiple options can be specified, and their order is
respected in the candidate lists passed to a subsequent
&app_pick_peer; callback.</p>
</item>

<tag><c>{timeout, &dict_Unsigned32;}</c></tag>
<item>
<p>
Number of milliseconds after which the request should
timeout.
Defaults to 5000.</p>
</item>

<tag><c>detach</c></tag>
<item>
<p>
Cause &call; to return <c>ok</c> as
soon as the request in
question has been encoded, instead of waiting for and returning
the result from a subsequent &app_handle_answer; or
&app_handle_error; callback.</p>
</item>

</taglist>

<p>
An invalid option will cause &call; to fail.</p>

<marker id="capability"/>
</item>

<tag><c>capability()</c></tag>
<item>

<p>
AVP values sent in outgoing CER or CEA messages during capabilities
exchange.
Can be configured both on a service and a transport, values
on the latter taking precedence.
Has one of the following types.</p>

<taglist>

<tag><c>{'Origin-Host', &dict_DiameterIdentity;}</c></tag><item/>
<tag><c>{'Origin-Realm', &dict_DiameterIdentity;}</c></tag><item/>
<tag><c>{'Host-IP-Address', [&dict_Address;]}</c></tag>
<item>
<p>
An address list is available to the start function of a
&transport_module;, which
can return a new list for use in the subsequent CER or CEA.
Host-IP-Address need not be specified if the transport module in
question communicates an address list as described in
&man_transport;</p>
</item>

<tag><c>{'Vendor-Id', &dict_Unsigned32;}</c></tag><item/>
<tag><c>{'Product-Name', &dict_UTF8String;}</c></tag><item/>
<tag><c>{'Origin-State-Id', &dict_Unsigned32;}</c></tag>
<item>
<p>
Origin-State-Id is optional but, if configured, will be included in
outgoing CER/CEA and DWR/DWA messages.
Setting a value of <c>0</c> (zero) is equivalent to not setting a
value, as documented in &the_rfc;.
The function &origin_state_id;
can be used as to retrieve a value that is computed when the diameter
application is started.</p>
</item>

<tag><c>{'Supported-Vendor-Id', [&dict_Unsigned32;]}</c></tag><item/>
<tag><c>{'Auth-Application-Id', [&dict_Unsigned32;]}</c></tag><item/>
<tag><c>{'Inband-Security-Id', [&dict_Unsigned32;]}</c></tag>
<item>
<p>
Inband-Security-Id defaults to the empty list, which is equivalent to a
list containing only 0 (NO_INBAND_SECURITY).
If 1 (TLS) is specified then TLS is selected if the CER/CEA received
from the peer offers it.</p>
</item>

<tag><c>{'Acct-Application-Id', [&dict_Unsigned32;]}</c></tag><item/>
<tag><c>{'Vendor-Specific-Application-Id', [&dict_Grouped;]}</c></tag><item/>
<tag><c>{'Firmware-Revision', &dict_Unsigned32;}</c></tag><item/>

</taglist>

<p>
Note that each tuple communicates one or more AVP values.
It is an error to specify duplicate tuples.</p>

<marker id="eval"/>
</item>

<tag><c>eval() = {M,F,A} | fun() | [eval() | A]</c></tag>
<item>
<p>
An expression that can be evaluated as a function in the following
sense.</p>

<pre>
eval([{M,F,A} | T]) ->
    apply(M, F, T ++ A);
eval([[F|A] | T]) ->
    eval([F | T ++ A]);
eval([F|A]) ->
    apply(F, A);
eval(F) ->
    eval([F]).
</pre>

<p>
Applying an <c>&eval;</c>
<c>E</c> to an argument list <c>A</c>
is meant in the sense of <c>eval([E|A])</c>.</p>

<warning>
<p>
Beware of using fun expressions of the form <c>fun Name/Arity</c> in
situations in which the fun is not short-lived
and code is to be upgraded at runtime since any processes retaining
such a fun will have a reference to old code.
In particular, such a value is typically inappropriate in
configuration passed to &start_service; or &add_transport;.</p>
</warning>

<marker id="peer_filter"/>
</item>

<tag><c>peer_filter() = term()</c></tag>
<item>
<p>
Filter passed to &call; in order to select candidate peers for a
&app_pick_peer; callback.
Has one of the following types.</p>

<taglist>

<tag><c>none</c></tag>
<item>
<p>
Matches any peer.
This is a convenience that provides a filter equivalent to no
filter.</p>
</item>

<tag><c>host</c></tag>
<item>
<p>
Matches only those peers whose Origin-Host has the same value
as Destination-Host in the outgoing request in question,
or any peer if the request does not contain
a Destination-Host AVP.</p>
</item>

<tag><c>realm</c></tag>
<item>
<p>
Matches only those peers whose Origin-Realm has the same value
as Destination-Realm in the outgoing request in question,
or any peer if the request does not contain
a Destination-Realm AVP.</p>
</item>

<tag><c>{host, any|&dict_DiameterIdentity;}</c></tag>
<item>
<p>
Matches only those peers whose Origin-Host has the
specified value, or all peers if the atom <c>any</c>.</p>
</item>

<tag><c>{realm, any|&dict_DiameterIdentity;}</c></tag>
<item>
<p>
Matches only those peers whose Origin-Realm has the
specified value, or all peers if the atom <c>any</c>.</p>
</item>

<tag><c>{eval, &eval;}</c></tag>
<item>
<p>
Matches only those peers for which the specified
<c>&eval;</c> returns
<c>true</c> when applied to the connection's <c>diameter_caps</c>
record.
Any other return value or exception is equivalent to <c>false</c>.</p>
</item>

<tag><c>{neg, &peer_filter;}</c></tag>
<item>
<p>
Matches only those peers not matched by the specified filter.</p>
</item>

<tag><c>{all, [&peer_filter;]}</c></tag>
<item>
<p>
Matches only those peers matched by each filter in the specified list.</p>
</item>

<tag><c>{any, [&peer_filter;]}</c></tag>
<item>
<p>
Matches only those peers matched by at least one filter in the
specified list.
The resulting list will be in match order, peers matching the
first filter of the list sorting before those matched by the second,
and so on.</p>
</item>

<tag><c>{first, [&peer_filter;]}</c></tag>
<item>
<p>
Like <c>any</c>, but stops at the first filter for which there are
matches, which can be much more efficient when there are many peers.
For example, the following filter causes only peers best matching
both the host and realm filters to be presented.</p>

<pre>
{first, [{all, [host, realm]}, realm]}
</pre>
</item>

</taglist>

<p>
An invalid filter is equivalent to <c>{any,[]}</c>, a filter
that matches no peer.</p>

<note>
<p>
The <c>host</c> and <c>realm</c> filters cause the Destination-Host
and Destination-Realm AVPs to be extracted from the
outgoing request, assuming it to be a record- or list-valued
<c>&codec_message;</c>, and assuming at most one of each AVP.
If this is not the case then the <c>{host|realm, &dict_DiameterIdentity;}</c>
filters must be used to achieve the desired result.
An empty <c>&dict_DiameterIdentity;</c>
(which should not be typical)
matches all hosts/realms for the purposes of filtering.</p>
</note>

<warning>
<p>
A <c>host</c> filter is not typically desirable when setting
Destination-Host since it will remove peer agents from the
candidates list.</p>
</warning>

<marker id="service_event"/>
</item>
<tag><c>service_event() = #diameter_event{service = &service_name;,
                                          info = &service_event_info;}</c></tag>
<item>
<p>
An event message sent to processes that have subscribed to these using
&subscribe;.</p>

<marker id="service_event_info"/>
</item>

<tag><c>service_event_info() = term()</c></tag>

<item>

<p>
The <c>info</c> field of a &service_event; record.
Can have one of the following types.</p>

<taglist>

<tag><c>start</c></tag><item/>
<tag><c>stop</c></tag>
<item>
<p>
The service is being started or stopped.
No event precedes a <c>start</c> event.
No event follows a <c>stop</c> event, and this event
implies the termination of all transport processes.</p>
</item>

<tag><c>{up, Ref, Peer, Config, Pkt}</c></tag><item/>
<tag><c>{up, Ref, Peer, Config}</c></tag><item/>
<tag><c>{down, Ref, Peer, Config}</c></tag>
<item>
<pre>
Ref    = &transport_ref;
Peer   = &app_peer;
Config = {connect|listen, [&transport_opt;]}
Pkt    = #diameter_packet{}
</pre>

<p>
The RFC 3539 watchdog state machine has
transitioned into (<c>up</c>) or out of (<c>down</c>) the OKAY
state.
If a <c>#diameter_packet{}</c> is present in an <c>up</c> event
then there has been a capabilities exchange on a newly established
transport connection and the record contains the received CER or
CEA.</p>

<p>
Note that a single <c>up</c> or <c>down</c> event for a given peer
corresponds to multiple &app_peer_up; or &app_peer_down;
callbacks, one for each of the Diameter applications negotiated during
capabilities exchange.
That is, the event communicates connectivity with the
peer as a whole while the callbacks communicate connectivity with
respect to individual Diameter applications.</p>
</item>

<tag><c>{reconnect, Ref, Opts}</c></tag>
<item>
<pre>
Ref  = &transport_ref;
Opts = [&transport_opt;]
</pre>

<p>
A connecting transport is attempting to establish/reestablish a
transport connection with a peer following &connect_timer; or
&watchdog_timer; expiry.</p>
</item>

<tag><c>{closed, Ref, Reason, Config}</c></tag>
<item>
<pre>
Ref = &transport_ref;
Config = {connect|listen, [&transport_opt;]}
</pre>

<p>
Capabilities exchange has failed.
<c>Reason</c> can have one of the following types.</p>

<taglist>

<tag><c>{'CER', Result, Caps, Pkt}</c></tag>
<item>
<pre>
Result = ResultCode | {capabilities_cb, CB, ResultCode|discard}
Caps = #diameter_caps{}
Pkt  = #diameter_packet{}
ResultCode = integer()
CB = &eval;
</pre>

<p>
An incoming CER has been answered with the indicated result code, or
discarded.
<c>Caps</c> contains pairs of values, for the local node and remote
peer respectively.
<c>Pkt</c> contains the CER in question.
In the case of rejection by a capabilities callback, the tuple
contains the rejecting callback.</p>
</item>

<tag><c>{'CER', Caps, {ResultCode, Pkt}}</c></tag>
<item>
<pre>
ResultCode = integer()
Caps = #diameter_caps{}
Pkt  = #diameter_packet{}
</pre>

<p>
An incoming CER contained errors and has been answered with the
indicated result code.
<c>Caps</c> contains values for the local node only.
<c>Pkt</c> contains the CER in question.</p>
</item>

<tag><c>{'CER', timeout}</c></tag>
<item>
<p>
An expected CER was not received within &capx_timeout; of
connection establishment.</p>
</item>

<tag><c>{'CEA', Result, Caps, Pkt}</c></tag>
<item>
<pre>
Result = ResultCode | atom() | {capabilities_cb, CB, ResultCode|discard}
Caps = #diameter_caps{}
Pkt  = #diameter_packet{}
ResultCode = integer()
</pre>

<p>
An incoming CEA has been rejected for the indicated reason.
An integer-valued <c>Result</c> indicates the result code sent
by the peer.
<c>Caps</c> contains pairs of values for the local node and remote
peer.
<c>Pkt</c> contains the CEA in question.
In the case of rejection by a capabilities callback, the tuple
contains the rejecting callback.</p>
</item>

<tag><c>{'CEA', Caps, Pkt}</c></tag>
<item>
<pre>
Caps = #diameter_caps{}
Pkt  = #diameter_packet{}
</pre>

<p>
An incoming CEA contained errors and has been rejected.
<c>Caps</c> contains only values for the local node.
<c>Pkt</c> contains the CEA in question.</p>
</item>

<tag><c>{'CEA', timeout}</c></tag>
<item>
<p>
An expected CEA was not received within &capx_timeout;
of connection establishment.</p>
</item>

</taglist>
</item>

<tag><c>{watchdog, Ref, PeerRef, {From, To}, Config}</c></tag>
<item>
<pre>
Ref = &transport_ref;
PeerRef = &app_peer_ref;
From, To = initial | okay | suspect | down | reopen
Config = {connect|listen, [transport_opt()]}
</pre>

<p>
An RFC 3539 watchdog state machine has changed state.</p>
</item>

<tag><c>any()</c></tag>
<item>
<p>
For forward compatibility, a subscriber should be prepared to receive
info fields of forms other than the above.</p>
</item>

</taglist>

<marker id="service_name"/>
</item>

<tag><c>service_name() = term()</c></tag>
<item>
<p>
Name of a service as passed to &start_service; and with which the
service is identified.
There can be at most one service with a given name on a given node.
Note that &make_ref;
can be used to generate a service name that is somewhat unique.</p>

<marker id="service_opt"/>
</item>

<tag><c>service_opt()</c></tag>
<item>
<p>
Option passed to &start_service;.
Can be any <c>&capability;</c> as well as the following.</p>

<taglist>

<tag><c>{application, [&application_opt;]}</c></tag>
<item>
<p>
A Diameter application supported by the service.</p>

<p>
A service must configure one tuple for each Diameter
application it intends to support.
For an outgoing request, the relevant <c>&application_alias;</c> is
passed to &call;, while for an
incoming request the application identifier in the message
header determines the application, the identifier being specified in
the application's &dictionary; file.</p>

<warning>
<p>
The capabilities advertised by a node must match its configured
applications. In particular, <c>application</c> configuration must
be matched by corresponding &capability; configuration, of
*-Application-Id AVPs in particular.</p>
</warning>

</item>

<tag>
<marker id="decode_format"/>
<c>{decode_format, record | list | map | none}</c></tag>
<item>
<p>
The format of decoded messages and grouped AVPs in the <c>msg</c> field
of diameter_packet records and <c>value</c> field of diameter_avp
records respectively.
If <c>record</c> then a record whose definition is generated from the
dictionary file in question.
If <c>list</c> or <c>map</c> then a <c>[Name | Avps]</c> pair where
<c>Avps</c> is a list of AVP name/values pairs or a map keyed on
AVP names respectively.
If <c>none</c> then the atom-value message name, or <c>undefined</c>
for a Grouped AVP.
See also &codec_message;.</p>

<p>
Defaults to <c>record</c>.</p>

<note>
<p>
AVPs are decoded into a list of diameter_avp records in <c>avps</c>
field of diameter_packet records independently of
<c>decode_format</c>.</p>
</note>

</item>

<tag><c>{restrict_connections, false
                             | node
                             | nodes
                             | [node()]
                             | eval()}</c></tag>
<item>
<p>
The degree to which the service allows multiple transport
connections to the same peer, as identified by its Origin-Host
at capabilities exchange.</p>

<p>
If <c>[node()]</c> then a connection is rejected if another already
exists on any of the specified nodes.
Types <c>false</c>, <c>node</c>, <c>nodes</c> and
&eval; are equivalent to
<c>[]</c>, <c>[node()]</c>, <c>[node()|nodes()]</c> and the
evaluated value respectively, evaluation of each expression taking
place whenever a new connection is to be established.
Note that <c>false</c> allows an unlimited number of connections to be
established with the same peer.</p>

<p>
Multiple connections are independent and governed
by their own peer and watchdog state machines.</p>

<p>
Defaults to <c>nodes</c>.</p>
</item>

<tag><c>{sequence, {H,N} | &eval;}</c></tag>
<item>
<p>
A constant value <c>H</c> for the topmost <c>32-N</c> bits of
of 32-bit End-to-End and Hop-by-Hop Identifiers generated
by the service, either explicitly or as a return value of a function
to be evaluated at &start_service;.
In particular, an identifier <c>Id</c> is mapped to a new identifier
as follows.</p>
<pre>
(H bsl N) bor (Id band ((1 bsl N) - 1))
</pre>
<p>
Note that &the_rfc; requires that End-to-End Identifiers remain unique
for a period of at least 4 minutes and that this and the call rate
places a lower bound on appropriate values of <c>N</c>:
at a rate of <c>R</c> requests per second, an <c>N</c>-bit counter
traverses all of its values in <c>(1 bsl N) div (R*60)</c> minutes, so
the bound is <c>4*R*60 =&lt; 1 bsl N</c>.</p>

<p><c>N</c> must lie in the range <c>0..32</c> and <c>H</c> must be a
non-negative integer less than <c>1 bsl (32-N)</c>.</p>

<p>
Defaults to <c>{0,32}</c>.</p>

<warning>
<p>
Multiple Erlang nodes implementing the same Diameter node should
be configured with different sequence masks to ensure that each node
uses a unique range of End-to-End and Hop-by-Hop Identifiers for
outgoing requests.</p>
</warning>
</item>

<tag><c>{share_peers, boolean() | [node()] | eval()}</c></tag>
<item>
<p>
Nodes to which peer connections established on the local
Erlang node are communicated.
Shared peers become available in the remote candidates list passed to
&app_pick_peer; callbacks on remote nodes whose services are
configured to use them: see <c>use_shared_peers</c> below.</p>

<p>
If <c>false</c> then peers are not shared.
If <c>[node()]</c> then peers are shared with the specified list of
nodes.
If <c>eval()</c> then peers are shared with the nodes returned
by the specified function, evaluated whenever a peer connection
becomes available or a remote service requests information about local
connections.
The value <c>true</c> is equivalent to <c>fun &nodes;</c>.
The value <c>node()</c> in a list is ignored, so a collection of
services can all be configured to share with the same list of
nodes.</p>

<p>
Defaults to <c>false</c>.</p>

<note>
<p>
Peers are only shared with services of the same name for the purpose
of sending outgoing requests.
Since the value of the &application_opt; <c>alias</c>, passed to
&call;, is the handle for identifying a peer as a suitable
candidate, services that share peers must use the same aliases to
identify their supported applications.
They should typically also configure identical &capabilities;, since
by sharing peer connections they are distributing the implementation
of a single Diameter node across multiple Erlang nodes.</p>
</note>
</item>

<tag>
<marker id="strict_arities"/><c>{strict_arities, boolean()
                                               | encode
                                               | decode}</c></tag>
<item>
<p>
Whether or not to require that the number of AVPs in a message or
grouped AVP agree with those specified in the dictionary in question
when passing messages to &man_app; callbacks.
If <c>true</c> then mismatches in an outgoing messages cause message
encoding to fail, while mismatches in an incoming message are reported
as 5005/5009 errors in the errors field of the diameter_packet record
passed to &app_handle_request; or &app_handle_answer; callbacks.
If <c>false</c> then neither error is enforced/detected.
If <c>encode</c> or <c>decode</c> then errors are only
enforced/detected on outgoing or incoming messages respectively.</p>

<p>
Defaults to <c>true</c>.</p>

<note>
<p>
Disabling arity checks affects the form of messages at encode/decode.
In particular, decoded AVPs are represented as lists of values,
regardless of the AVP's arity (ie. expected number in the message/AVP
grammar in question), and values are expected to be supplied as lists
at encode.
This differs from the historic decode behaviour of representing AVPs
of arity 1 as bare values, not wrapped in a list.</p>
</note>
</item>

<tag>
<marker id="string_decode"/><c>{string_decode, boolean()}</c></tag>
<item>
<p>
Whether or not to decode AVPs of type &dict_OctetString; and its
derived types &dict_DiameterIdentity;, &dict_DiameterURI;,
&dict_IPFilterRule;, &dict_QoSFilterRule;, and &dict_UTF8String;.
If <c>true</c> then AVPs of these types are decoded to string().
If <c>false</c> then values are retained as binary().</p>

<p>
Defaults to <c>true</c>.</p>

<warning>
<p>
This option should be set to <c>false</c>
since a sufficiently malicious peer can otherwise cause large amounts
of memory to be consumed when decoded Diameter messages are passed
between processes.
The default value is for backwards compatibility.</p>
</warning>

</item>

<tag>
<marker id="traffic_counters"/><c>{traffic_counters, boolean()}</c></tag>
<item>
<p>
Whether or not to count application-specific messages; those for which
&man_app; callbacks take place.
If false then only messages handled by diameter itself are counted:
CER/CEA, DWR/DWA, DPR/DPA.</p>

<p>
Defaults to <c>true</c>.</p>

<note>
<p>
Disabling counters is a performance improvement, but means that the
omitted counters are not returned by &service_info;.</p>
</note>

</item>

<tag><c>{use_shared_peers, boolean() | [node()] | eval()}</c></tag>
<item>
<p>
Nodes from which communicated peers are made available in
the remote candidates list of &app_pick_peer; callbacks.</p>

<p>
If <c>false</c> then remote peers are not used.
If <c>[node()]</c> then only peers from the specified list of nodes
are used.
If <c>eval()</c> then only peers returned by the specified
function are used, evaluated whenever a remote service communicates
information about an available peer connection.
The value <c>true</c> is equivalent to <c>fun &nodes;</c>.
The value <c>node()</c> in a list is ignored.</p>

<p>
Defaults to <c>false</c>.</p>

<note>
<p>
A service that does not use shared peers will always pass the empty
list as the second argument of &app_pick_peer; callbacks.</p>
</note>

<warning>
<p>
Sending a request over a peer connection on a remote node is less
efficient than sending it over a local connection.
It may be preferable to make use of the &service_opt;
<c>restrict_connections</c> and maintain a dedicated connection on
each node from which requests are sent.</p>
</warning>
</item>

<tag><c>&transport_opt;</c></tag>
<item>
<p>
Any transport option except <c>applications</c>,
<c>capabilities</c>, <c>transport_config</c>, and
<c>transport_module</c>.
Used as defaults for transport configuration, values passed to
&add_transport; overriding values configured on the service.</p>
</item>

</taglist>

<marker id="transport_opt"/>
</item>

<tag><c>transport_opt()</c></tag>
<item>
<p>
Option passed to &add_transport;.
Has one of the following types.</p>

<taglist>

<tag>
<marker id="applications"/><c>{applications, [&application_alias;]}</c></tag>
<item>
<p>
Diameter applications to which the transport should be restricted.
Defaults to all applications configured on the service in question.
Applications not configured on the service in question are ignored.</p>

<warning>
<p>
The capabilities advertised by a node must match its configured
applications.
In particular, setting <c>applications</c> on a transport typically
implies having to set matching *-Application-Id AVPs in a
&capabilities; tuple.</p>
</warning>

</item>

<tag>
<marker id="avp_dictionaries"/><c>{avp_dictionaries, [module()]}</c></tag>
<item>
<p>
A list of alternate dictionary modules with which to encode/decode
AVPs that are not defined by the dictionary of the application in
question.
At decode, such AVPs are represented as diameter_avp records in the
<c>'AVP'</c> field of a decoded message or Grouped AVP, the first
alternate that succeeds in decoding the AVP setting the record's value
field.
At encode, values in an <c>'AVP'</c> list can be passed as AVP
name/value 2-tuples, and it is an encode error for no alternate to
define the AVP of such a tuple.</p>

<p>
Defaults to the empty list.</p>

<note>
<p>
The motivation for alternate dictionaries is RFC 7683, Diameter
Overload Indication Conveyance (DOIC), which defines AVPs to
be piggybacked onto existing application messages rather than defining
an application of its own.
The DOIC dictionary is provided by the diameter application, as module
<c>diameter_gen_doic_rfc7683</c>, but alternate dictionaries can be
used to encode/decode any set of AVPs not known to an application
dictionary.</p>
</note>
</item>

<tag>
<marker id="capabilities"/><c>{capabilities, [&capability;]}</c></tag>
<item>
<p>
AVPs used to construct outgoing CER/CEA messages.
Values take precedence over any specified on the service in
question.</p>

<p>
Specifying a capability as a transport option
may be particularly appropriate for Inband-Security-Id, in case
TLS is desired over TCP as implemented by &man_tcp;.</p>
</item>

<tag>
<marker id="capabilities_cb"/><c>{capabilities_cb, &eval;}</c></tag>
<item>
<p>
Callback invoked upon reception of CER/CEA during capabilities
exchange in order to ask whether or not the connection should
be accepted.
Applied to the <c>&transport_ref;</c> and
<c>#diameter_caps{}</c> record of the connection.</p>

<p>
The return value can have one of the following types.</p>

<taglist>
<tag><c>ok</c></tag>
<item>
<p>
Accept the connection.</p>
</item>

<tag><c>integer()</c></tag>
<item>
<p>
Causes an incoming CER to be answered with the specified Result-Code.</p>
</item>

<tag><c>discard</c></tag>
<item>
<p>
Causes an incoming CER to be discarded without CEA being sent.</p>
</item>

<tag><c>unknown</c></tag>
<item>
<p>
Equivalent to returning <c>3010</c>, DIAMETER_UNKNOWN_PEER.</p>
</item>
</taglist>

<p>
Returning anything but <c>ok</c> or a 2xxx series result
code causes the transport connection to be broken.
Multiple &capabilities_cb;
options can be specified, in which
case the corresponding callbacks are applied until either all return
<c>ok</c> or one does not.</p>
</item>

<tag>
<marker id="capx_timeout"/><c>{capx_timeout, &dict_Unsigned32;}</c></tag>
<item>
<p>
Number of milliseconds after which a transport process having an
established transport connection will be terminated if the expected
capabilities exchange message (CER or CEA) is not received from the peer.
For a connecting transport, the timing of connection attempts is
governed by &connect_timer; or &watchdog_timer; expiry.
For a listening transport, the peer determines the timing.</p>

<p>
Defaults to 10000.</p>
</item>

<tag>
<marker id="connect_timer"/><c>{connect_timer, Tc}</c></tag>
<item>
<pre>
Tc = &dict_Unsigned32;
</pre>

<p>
For a connecting transport, the &the_rfc; Tc timer, in milliseconds.
This timer determines the frequency with which a transport
attempts to establish an initial connection with its peer
following transport configuration.
Once an initial connection has been
established, &watchdog_timer; determines the frequency of
reconnection attempts, as required by RFC 3539.</p>

<p>
For a listening transport, the timer specifies the time after which a
previously connected peer will be forgotten: a connection after this time is
regarded as an initial connection rather than reestablishment,
causing the RFC 3539 state machine to pass to state OKAY rather than
REOPEN.
Note that these semantics are not governed by the RFC and
that a listening transport's &connect_timer; should be greater
than its peer's Tw plus jitter.</p>

<p>
Defaults to 30000 for a connecting transport and 60000 for a listening
transport.</p>
</item>

<tag>
<marker id="disconnect_cb"/><c>{disconnect_cb, &eval;}</c></tag>
<item>
<p>
Callback invoked prior to terminating the transport process of a
transport connection having watchdog state <c>OKAY</c>.
Applied to <c>application|service|transport</c> and the
<c>&transport_ref;</c> and <c>&app_peer;</c> in question:
<c>application</c> indicates that the diameter application is
being stopped, <c>service</c> that the service in question is being
stopped by &stop_service;, and <c>transport</c> that the transport in
question is being removed by &remove_transport;.</p>

<p>
The return value can have one of the following types.</p>

<taglist>
<tag><c>{dpr, [option()]}</c></tag>
<item>
<p>
Send Disconnect-Peer-Request to the peer, the transport
process being terminated following reception of
Disconnect-Peer-Answer or timeout.
An <c>option()</c> can be one of the following.</p>

<taglist>
<tag><c>{cause, 0|rebooting|1|busy|2|goaway}</c></tag>
<item>
<p>
Disconnect-Cause to send, <c>REBOOTING</c>, <c>BUSY</c> and
<c>DO_NOT_WANT_TO_TALK_TO_YOU</c> respectively.
Defaults to <c>rebooting</c> for <c>Reason=service|application</c> and
<c>goaway</c> for <c>Reason=transport</c>.</p>
</item>

<tag><c>{timeout, &dict_Unsigned32;}</c></tag>
<item>
<p>
Number of milliseconds after which the transport process is
terminated if DPA has not been received.
Defaults to the value of &dpa_timeout;.</p>
</item>
</taglist>
</item>

<tag><c>dpr</c></tag>
<item>
<p>
Equivalent to <c>{dpr, []}</c>.</p>
</item>

<tag><c>close</c></tag>
<item>
<p>
Terminate the transport process without
Disconnect-Peer-Request being sent to the peer.</p>
</item>

<tag><c>ignore</c></tag>
<item>
<p>
Equivalent to not having configured the callback.</p>
</item>
</taglist>

<p>
Multiple &disconnect_cb;
options can be specified, in which
case the corresponding callbacks are applied until one of them returns
a value other than <c>ignore</c>.
All callbacks returning <c>ignore</c> is equivalent to not having
configured them.</p>

<p>
Defaults to a single callback returning <c>dpr</c>.</p>
</item>

<tag>
<marker id="dpa_timeout"/><c>{dpa_timeout, &dict_Unsigned32;}</c></tag>
<item>
<p>
Number of milliseconds after which a transport connection is
terminated following an outgoing DPR if DPA is not received.</p>

<p>
Defaults to 1000.</p>
</item>

<tag>
<marker id="dpr_timeout"/><c>{dpr_timeout, &dict_Unsigned32;}</c></tag>
<item>
<p>
Number of milliseconds after which a transport connection is
terminated following an incoming DPR if the peer does not close the
connection.</p>

<p>
Defaults to 5000.</p>
</item>

<tag>
<marker id="incoming_maxlen"/><c>{incoming_maxlen, 0..16777215}</c></tag>
<item>
<p>
Bound on the expected size of incoming Diameter messages.
Messages larger than the specified number of bytes are discarded.</p>

<p>
Defaults to <c>16777215</c>, the maximum value of the 24-bit Message
Length field in a Diameter Header.</p>

</item>

<tag>
<marker id="length_errors"/><c>{length_errors, exit|handle|discard}</c></tag>
<item>
<p>
How to deal with errors in the Message Length field of the
Diameter Header in an incoming message.
An error in this context is that the length is not at least 20 bytes
(the length of a Header), is not a multiple of 4 (a valid length) or
is not the length of the message in question, as received over the
transport interface documented in &man_transport;.</p>

<p>
If <c>exit</c> then the transport process in question exits.
If <c>handle</c> then the message is processed as usual, a resulting
&app_handle_request; or &app_handle_answer; callback (if one takes
place) indicating the <c>5015</c> error (DIAMETER_INVALID_MESSAGE_LENGTH).
If <c>discard</c> then the message in question is silently discarded.</p>

<p>
Defaults to <c>exit</c>.</p>

<note>
<p>
The default value reflects the fact that a transport module for a
stream-oriented transport like TCP may not be able to recover from a
message length error since such a transport must use the Message
Length header to divide the incoming byte stream into individual
Diameter messages.
An invalid length leaves it with no reliable way to rediscover message
boundaries, which may result in the failure of subsequent messages.
See &man_tcp; for the behaviour of that module.</p>
</note>
</item>

<tag><c>{pool_size, pos_integer()}</c></tag>
<item>
<p>
Number of transport processes to start.
For a listening transport, determines the size of the pool of
accepting transport processes, a larger number being desirable for
processing multiple concurrent peer connection attempts.
For a connecting transport, determines the number of connections to
the peer in question that will be attempted to be establshed:
the &service_opt;: <c>restrict_connections</c> should also be
configured on the service in question to allow multiple connections to
the same peer.</p>

</item>

<tag>
<marker id="spawn_opt"/><c>{spawn_opt, [term()] | {M,F,A}}</c></tag>
<item>
<p>
An options list passed to &spawn_opt2; to spawn a handler process for an
incoming Diameter request on the local node, or an MFA that returns
the pid of a handler process.</p>

<p>
Options <c>monitor</c> and <c>link</c> are ignored in the list-valued
case.
An MFA is applied with an additional term prepended to its argument
list, and should return either the pid of the handler process that
invokes <c>diameter_traffic:request/1</c> on the argument in order to
process the request, or the atom <c>discard</c>.
The handler process need not be local, and diameter need not be
started on the remote node, but diameter and relevant application
callbacks must be on the code path.</p>

<p>
Defaults to the empty list.</p>
</item>

<tag>
<marker id="strict_capx"/><c>{strict_capx, boolean()]}</c></tag>
<item>
<p>
Whether or not to enforce the RFC 6733 requirement that any message
before capabilities exchange should close the peer connection.
If false then unexpected messages are discarded.</p>

<p>
Defaults to true.
Changing this results in non-standard behaviour, but can be useful in
case peers are known to be behave badly.</p>
</item>

<tag>
<marker id="strict_mbit"/><c>{strict_mbit, boolean()}</c></tag>
<item>
<p>
Whether or not to regard an AVP setting the M-bit as erroneous when
the command grammar in question does not explicitly allow the AVP.
If <c>true</c> then such AVPs are regarded as 5001 errors,
DIAMETER_AVP_UNSUPPORTED.
If <c>false</c> then the M-bit is ignored and policing
it becomes the receiver's responsibility.</p>

<p>
Defaults to <c>true</c>.</p>

<warning>
<p>
RFC 6733 is unclear about the semantics of the M-bit.
One the one hand, the CCF specification in section 3.2 documents AVP
in a command grammar as meaning <em>any</em> arbitrary AVP; on the
other hand, 1.3.4 states that AVPs setting the M-bit cannot be added
to an existing command: the modified command must instead be
placed in a new Diameter application.</p>
<p>
The reason for the latter is presumably interoperability:
allowing arbitrary AVPs setting the M-bit in a command makes its
interpretation implementation-dependent, since there's no
guarantee that all implementations will understand the same set of
arbitrary AVPs in the context of a given command.
However, interpreting <c>AVP</c> in a command grammar as any
AVP, regardless of M-bit, renders 1.3.4 meaningless, since the receiver
can simply ignore any AVP it thinks isn't relevant, regardless of the
sender's intent.</p>
<p>
Beware of confusing mandatory in the sense of the M-bit with mandatory
in the sense of the command grammar.
The former is a semantic requirement: that the receiver understand the
semantics of the AVP in the context in question.
The latter is a syntactic requirement: whether or not the AVP must
occur in the message in question.</p>
</warning>

</item>

<tag>
<marker id="transport_config"/><c>{transport_config, term()}</c></tag><item/>
<tag><c>{transport_config, term(), &dict_Unsigned32; | infinity}</c></tag>
<item>
<p>
Term passed as the third argument to the &transport_start; function of
the relevant &transport_module; in order to
start a transport process.
Defaults to the empty list.</p>

<p>
The 3-tuple form additionally specifies an interval, in milliseconds,
after which a started transport process should be terminated if it has
not yet established a connection.
For example, the following options on a connecting transport
request a connection with one peer over SCTP or another
(typically the same) over TCP.</p>

<pre>
{transport_module, diameter_sctp}
{transport_config, SctpOpts, 5000}
{transport_module, diameter_tcp}
{transport_config, TcpOpts}
</pre>

<p>
To listen on both SCTP and TCP, define one transport for each.</p>
</item>

<tag>
<marker id="transport_module"/><c>{transport_module, atom()}</c></tag>
<item>
<p>
Module implementing a transport process as defined in &man_transport;.
Defaults to <c>diameter_tcp</c>.</p>

<p>
Multiple <c>transport_module</c> and &transport_config;
options are allowed.
The order of these is significant in this case (and only in this case),
a <c>transport_module</c> being paired with the first
&transport_config;
following it in the options list, or the default value for trailing
modules.
Transport starts will be attempted with each of the
modules in order until one establishes a connection within the
corresponding timeout (see below) or all fail.</p>
</item>

<tag>
<marker id="watchdog_config"/><c>{watchdog_config,
                       [{okay|suspect, non_neg_integer()}]}</c></tag>
<item>
<p>
Configuration that alters the behaviour of the watchdog
state machine.
On key <c>okay</c>, the non-negative number of answered DWR
messages before transitioning from REOPEN to OKAY.
On key <c>suspect</c>, the number of watchdog timeouts before
transitioning from OKAY to SUSPECT when DWR is unanswered, or 0 to
not make the transition.</p>

<p>
Defaults to <c>[{okay, 3}, {suspect, 1}]</c>.
Not specifying a key is equivalent to specifying
the default value for that key.</p>
<warning>
<p>
The default value is as required by RFC 3539: changing it results
in non-standard behaviour that should only be used to simulate
misbehaving nodes during test.</p>
</warning>
</item>

<tag>
<marker id="watchdog_timer"/><c>{watchdog_timer, TwInit}</c></tag>
<item>
<pre>
TwInit = &dict_Unsigned32;
       | {M,F,A}
</pre>

<p>
The RFC 3539 watchdog timer.
An integer value is interpreted as the RFC's TwInit in milliseconds,
a jitter of &plusmn; 2 seconds being added at each rearming of the
timer to compute the RFC's Tw.
An MFA is expected to return the RFC's Tw directly, with jitter
applied, allowing the jitter calculation to be performed by
the callback.</p>

<p>
An integer value must be at least 6000 as required by RFC 3539.
Defaults to 30000.</p>
</item>

</taglist>

<p>
Unrecognized options are silently ignored but are returned unmodified
by &service_info; and can be referred to
in predicate functions passed to &remove_transport;.</p>

</item>

<tag>
<marker id="transport_ref"/><c>transport_ref() = reference()</c></tag>
<item>
<p>
Reference returned by &add_transport; that
identifies the configuration.</p>
</item>

</taglist>

</section>

<funcs>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">add_transport(SvcName, {connect|listen, [Opt]})
        -> {ok, Ref} | {error, Reason}</name>
<fsummary>Add transport capability to a service.</fsummary>
<type>
<v>SvcName = &service_name;</v>
<v>Opt = &transport_opt;</v>
<v>Ref = &transport_ref;</v>
<v>Reason = term()</v>
</type>
<desc>
<p>
Add transport capability to a service.</p>

<p>
The service will start transport processes as required in order to
establish a connection with the peer, either by connecting to the peer
(<c>connect</c>) or by  accepting incoming connection requests
(<c>listen</c>).
A connecting transport establishes transport connections with at most
one peer, an listening transport potentially with many.</p>

<p>
The diameter application takes responsibility for exchanging
CER/CEA with the peer.
Upon successful completion of capabilities exchange the service
calls each relevant application module's &app_peer_up; callback
after which the caller can exchange Diameter messages with the peer over
the transport.
In addition to CER/CEA, the service takes responsibility for the
handling of DWR/DWA and required by RFC 3539, as well as for DPR/DPA.</p>

<p>
The returned reference uniquely identifies the transport within the
scope of the service.
Note that the function returns before a transport connection has been
established.</p>

<note>
<p>
It is not an error to add a transport to a service that has not yet
been configured: a service can be started after configuring
its transports.</p>
</note>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">call(SvcName, App, Request, [Opt]) -> Answer | ok | {error, Reason}</name>
<fsummary>Send a Diameter request message.</fsummary>
<type>
<v>SvcName = &service_name;</v>
<v>App = &application_alias;</v>
<v>Request = &codec_message;</v>
<v>Answer = term()</v>
<v>Opt = &call_opt;</v>
</type>
<desc>
<p>
Send a Diameter request message.</p>

<p>
<c>App</c> specifies the Diameter application in which the request is
defined and callbacks to the corresponding callback module
will follow as described below and in &man_app;.
Unless the <c>detach</c> option is specified, the call returns either
when an answer message is received from the peer or an error occurs.
In the answer case, the return value is as returned by a
&app_handle_answer; callback.
In the error case, whether or not the error is returned directly
by diameter or from a &app_handle_error;
callback depends on whether or not the outgoing request is
successfully encoded for transmission to the peer, the cases being
documented below.</p>

<p>
If there are no suitable peers, or if
&app_pick_peer;
rejects them by returning <c>false</c>, then <c>{error,no_connection}</c>
is returned.
Otherwise &app_pick_peer; is followed by a
&app_prepare_request; callback, the message is encoded and then sent.</p>

<p>
There are several error cases which may prevent an
answer from being received and passed to a
&app_handle_answer; callback:</p>

<list>

<item>
<p>
If the initial encode of the outgoing request
fails, then the request process fails and <c>{error,encode}</c>
is returned.</p>
</item>

<item>
<p>
If the request is successfully encoded and sent but
the answer times out then a
&app_handle_error; callback takes place with <c>Reason = timeout</c>.</p>
</item>

<item>
<p>
If the request is successfully encoded and sent but the service in
question is stopped before an answer is received then a
&app_handle_error; callback takes place with <c>Reason = cancel</c>.</p>
</item>

<item>
<p>
If the transport connection with the peer goes down after the request
has been sent but before an answer has been received then an attempt
is made to resend the request to an alternate peer.
If no such peer is available, or if the subsequent
&app_pick_peer; callback rejects the candidates, then a
&app_handle_error; callback takes place with <c>Reason = failover</c>.
If a peer is selected then a &app_prepare_retransmit;
callback takes place, after which the semantics are the same as
following an initial &app_prepare_request; callback.</p>
</item>

<item>
<p>
If an encode error takes place during
retransmission then the request process fails and
<c>{error,failure}</c> is returned.</p>
</item>

<item>
<p>
If an application callback made in processing the request fails
(pick_peer, prepare_request, prepare_retransmit,
handle_answer or handle_error) then either
<c>{error,encode}</c> or <c>{error,failure}</c>
is returned depending on whether or not there has been an
attempt to send the request over the transport.</p>
</item>

</list>

<p>
Note that <c>{error,encode}</c> is the only return value which
guarantees that the request has <em>not</em> been sent over the
transport connection.</p>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">origin_state_id() -> &dict_Unsigned32;</name>
<fsummary>Returns a reasonable Origin-State-Id.</fsummary>
<desc>
<p>
Return a reasonable value for use as Origin-State-Id in
outgoing messages.</p>

<p>
The value returned is the number of seconds since 19680120T031408Z,
the first value that can be encoded as a Diameter <c>&dict_Time;</c>,
at the time the diameter application was started.</p>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">remove_transport(SvcName, Pred) -> ok | {error, Reason}</name>
<fsummary>Remove previously added transports.</fsummary>
<type>
<v>SvcName = &service_name;</v>
<v>Pred = Fun | MFA | &transport_ref; | list() | true | false</v>
<v></v>
<v>Fun = fun((&transport_ref;, connect|listen, list()) -> boolean())</v>
<v>&nbsp;&nbsp;&nbsp; | fun((&transport_ref;, list()) -> boolean())</v>
<v>&nbsp;&nbsp;&nbsp; | fun((list()) -> boolean())</v>
<v>MFA = {atom(), atom(), list()}</v>
<v>Reason = term()</v>
</type>
<desc>
<p>
Remove previously added transports.</p>

<p>
<c>Pred</c> determines which transports to remove.
An arity-3-valued <c>Pred</c> removes all transports for which
<c>Pred(Ref, Type, Opts)</c> returns <c>true</c>, where <c>Type</c> and
<c>Opts</c> are as passed to &add_transport; and <c>Ref</c> is
as returned by it.
The remaining forms are equivalent to an arity-3 fun as follows.</p>

<pre>
Pred = fun(transport_ref(), list()):  fun(Ref, _, Opts) -> Pred(Ref, Opts) end
Pred = fun(list()):                   fun(_, _, Opts) -> Pred(Opts) end
Pred = transport_ref():               fun(Ref, _, _)  -> Pred == Ref end
Pred = list():                        fun(_, _, Opts) -> [] == Pred -- Opts end
Pred = true:                          fun(_, _, _) -> true end
Pred = false:                         fun(_, _, _) -> false end
Pred = {M,F,A}:  fun(Ref, Type, Opts) -> apply(M, F, [Ref, Type, Opts | A]) end
</pre>

<p>
Removing a transport causes the corresponding transport processes to
be terminated.
Whether or not a DPR message is sent to a peer is
controlled by value of &disconnect_cb;
configured on the transport.</p>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">service_info(SvcName, Info) -> term()</name>
<fsummary>Return information about a started service.</fsummary>
<type>
<v>SvcName = &service_name;</v>
<v>Info = Item | [Info]</v>
<v>Item = atom()</v>
</type>
<desc>
<p>
Return information about a started service.
Requesting info for an unknown service causes <c>undefined</c> to be
returned.
Requesting a list of items causes a tagged list to be
returned.</p>

<p>
<c>Item</c> can be one of the following.</p>

<taglist>

<tag><c>'Origin-Host'</c></tag><item/>
<tag><c>'Origin-Realm'</c></tag><item/>
<tag><c>'Vendor-Id'</c></tag><item/>
<tag><c>'Product-Name'</c></tag><item/>
<tag><c>'Origin-State-Id'</c></tag><item/>
<tag><c>'Host-IP-Address'</c></tag><item/>
<tag><c>'Supported-Vendor'</c></tag><item/>
<tag><c>'Auth-Application-Id'</c></tag><item/>
<tag><c>'Inband-Security-Id'</c></tag><item/>
<tag><c>'Acct-Application-Id'</c></tag><item/>
<tag><c>'Vendor-Specific-Application-Id'</c></tag><item/>
<tag><c>'Firmware-Revision'</c></tag>
<item>
<p>
Return a capability value as configured with &start_service;.</p>
</item>

<tag><c>applications</c></tag>
<item>
<p>
Return the list of applications as configured with &start_service;.
</p>
</item>

<tag><c>capabilities</c></tag>
<item>
<p>
Return a tagged list of all capabilities values as configured with
&start_service;.</p>
</item>

<tag><c>transport</c></tag>
<item>
<p>
Return a list containing one entry for each of the service's transport
as configured with &add_transport;.
Each entry is a tagged list containing both configuration and
information about established peer connections.
An example return value with for a client service with Origin-Host
"client.example.com" configured with a single transport connected to
"server.example.com" might look as follows.</p>

<pre>
[[{ref,#Ref&lt;0.0.0.93>},
  {type,connect},
  {options,[{transport_module,diameter_tcp},
            {transport_config,[{ip,{127,0,0,1}},
                               {raddr,{127,0,0,1}},
                               {rport,3868},
                               {reuseaddr,true}]}]},
  {watchdog,{&lt;0.66.0>,-576460736368485571,okay}},
  {peer,{&lt;0.67.0>,-576460736357885808}},
  {apps,[{0,common}]},
  {caps,[{origin_host,{"client.example.com","server.example.com"}},
         {origin_realm,{"example.com","example.com"}},
         {host_ip_address,{[{127,0,0,1}],[{127,0,0,1}]}},
         {vendor_id,{0,193}},
         {product_name,{"Client","Server"}},
         {origin_state_id,{[],[]}},
         {supported_vendor_id,{[],[]}},
         {auth_application_id,{[0],[0]}},
         {inband_security_id,{[],[0]}},
         {acct_application_id,{[],[]}},
         {vendor_specific_application_id,{[],[]}},
         {firmware_revision,{[],[]}},
         {avp,{[],[]}}]},
  {port,[{owner,&lt;0.69.0>},
         {module,diameter_tcp},
         {socket,{{127,0,0,1},48758}},
         {peer,{{127,0,0,1},3868}},
         {statistics,[{recv_oct,656},
                      {recv_cnt,6},
                      {recv_max,148},
                      {recv_avg,109},
                      {recv_dvi,19},
                      {send_oct,836},
                      {send_cnt,6},
                      {send_max,184},
                      {send_avg,139},
                      {send_pend,0}]}]},
  {statistics,[{{{0,258,0},recv},3},
               {{{0,258,1},send},3},
               {{{0,258,0},recv,{'Result-Code',2001}},3},
               {{{0,257,0},recv},1},
               {{{0,257,1},send},1},
               {{{0,257,0},recv,{'Result-Code',2001}},1},
               {{{0,280,1},recv},2},
               {{{0,280,0},send},2},
               {{{0,280,0},send,{'Result-Code',2001}},2}]}]]
</pre>

<p>
Here <c>ref</c> is a <c>&transport_ref;</c> and <c>options</c>
the corresponding <c>&transport_opt;</c> list passed to
&add_transport;.
The <c>watchdog</c> entry shows the state of a connection's RFC 3539 watchdog
state machine.
The <c>peer</c> entry identifies the <c>&app_peer_ref;</c> for
which there will have been &app_peer_up; callbacks for the
Diameter applications identified by the <c>apps</c> entry,
<c>common</c> being the <c>&application_alias;</c>.
The <c>caps</c> entry identifies the capabilities sent by the local
node and received from the peer during capabilities exchange.
The <c>port</c> entry displays socket-level information about the
transport connection.
The <c>statistics</c> entry presents Diameter-level counters,
an entry like <c>{{{0,280,1},recv},2}</c> saying that the client has
received 2 DWR messages: <c>{0,280,1} = {Application_Id, Command_Code,
R_Flag}</c>.</p>

<p>
Note that <c>watchdog</c>, <c>peer</c>, <c>apps</c>, <c>caps</c>
and <c>port</c> entries depend on connectivity
with the peer and may not be present.
Note also that the <c>statistics</c> entry presents values accumulated
during the lifetime of the transport configuration.</p>

<p>
A listening transport presents its information slightly differently
since there may be multiple accepted connections for the same
<c>&transport_ref;</c>.
The <c>transport</c> info returned by a server with a single client
connection might look as follows.</p>

<pre>
[[{ref,#Ref&lt;0.0.0.61>},
  {type,listen},
  {options,[{transport_module,diameter_tcp},
            {transport_config,[{reuseaddr,true},
                               {ip,{127,0,0,1}},
                               {port,3868}]}]},
  {accept,[[{watchdog,{&lt;0.56.0>,-576460739249514012,okay}},
            {peer,{&lt;0.58.0>,-576460638229179167}},
            {apps,[{0,common}]},
            {caps,[{origin_host,{"server.example.com","client.example.com"}},
                   {origin_realm,{"example.com","example.com"}},
                   {host_ip_address,{[{127,0,0,1}],[{127,0,0,1}]}},
                   {vendor_id,{193,0}},
                   {product_name,{"Server","Client"}},
                   {origin_state_id,{[],[]}},
                   {supported_vendor_id,{[],[]}},
                   {auth_application_id,{[0],[0]}},
                   {inband_security_id,{[],[]}},
                   {acct_application_id,{[],[]}},
                   {vendor_specific_application_id,{[],[]}},
                   {firmware_revision,{[],[]}},
                   {avp,{[],[]}}]},
            {port,[{owner,&lt;0.62.0>},
                   {module,diameter_tcp},
                   {socket,{{127,0,0,1},3868}},
                   {peer,{{127,0,0,1},48758}},
                   {statistics,[{recv_oct,1576},
                                {recv_cnt,16},
                                {recv_max,184},
                                {recv_avg,98},
                                {recv_dvi,26},
                                {send_oct,1396},
                                {send_cnt,16},
                                {send_max,148},
                                {send_avg,87},
                                {send_pend,0}]}]}],
           [{watchdog,{&lt;0.72.0>,-576460638229717546,initial}}]]},
  {statistics,[{{{0,280,0},recv},7},
               {{{0,280,1},send},7},
               {{{0,280,0},recv,{'Result-Code',2001}},7},
               {{{0,258,1},recv},3},
               {{{0,258,0},send},3},
               {{{0,258,0},send,{'Result-Code',2001}},3},
               {{{0,280,1},recv},5},
               {{{0,280,0},send},5},
               {{{0,280,0},send,{'Result-Code',2001}},5},
               {{{0,257,1},recv},1},
               {{{0,257,0},send},1},
               {{{0,257,0},send,{'Result-Code',2001}},1}]}]]
</pre>

<p>
The information presented here is as in the <c>connect</c> case except
that the client connections are grouped under an <c>accept</c> tuple.</p>

<p>
Whether or not the &transport_opt; <c>pool_size</c> has been
configured affects the format
of the listing in the case of a connecting transport, since a value
greater than 1 implies multiple transport processes for the same
<c>&transport_ref;</c>, as in the listening case.
The format in this case is similar to the listening case, with a
<c>pool</c> tuple in place of an <c>accept</c> tuple.</p>

</item>

<tag><c>connections</c></tag>
<item>
<p>
Return a list containing one entry for every established transport
connection whose watchdog state machine is not in the <c>down</c>
state.
This is a flat view of <c>transport</c> info which lists only active
connections and for which Diameter-level statistics are accumulated
only for the lifetime of the transport connection.
A return value for the server above might look as follows.</p>

<pre>
[[{ref,#Ref&lt;0.0.0.61>},
  {type,accept},
  {options,[{transport_module,diameter_tcp},
            {transport_config,[{reuseaddr,true},
                               {ip,{127,0,0,1}},
                               {port,3868}]}]},
  {watchdog,{&lt;0.56.0>,-576460739249514012,okay}},
  {peer,{&lt;0.58.0>,-576460638229179167}},
  {apps,[{0,common}]},
  {caps,[{origin_host,{"server.example.com","client.example.com"}},
         {origin_realm,{"example.com","example.com"}},
         {host_ip_address,{[{127,0,0,1}],[{127,0,0,1}]}},
         {vendor_id,{193,0}},
         {product_name,{"Server","Client"}},
         {origin_state_id,{[],[]}},
         {supported_vendor_id,{[],[]}},
         {auth_application_id,{[0],[0]}},
         {inband_security_id,{[],[]}},
         {acct_application_id,{[],[]}},
         {vendor_specific_application_id,{[],[]}},
         {firmware_revision,{[],[]}},
         {avp,{[],[]}}]},
  {port,[{owner,&lt;0.62.0>},
         {module,diameter_tcp},
         {socket,{{127,0,0,1},3868}},
         {peer,{{127,0,0,1},48758}},
         {statistics,[{recv_oct,10124},
                      {recv_cnt,132},
                      {recv_max,184},
                      {recv_avg,76},
                      {recv_dvi,9},
                      {send_oct,10016},
                      {send_cnt,132},
                      {send_max,148},
                      {send_avg,75},
                      {send_pend,0}]}]},
  {statistics,[{{{0,280,0},recv},62},
               {{{0,280,1},send},62},
               {{{0,280,0},recv,{'Result-Code',2001}},62},
               {{{0,258,1},recv},3},
               {{{0,258,0},send},3},
               {{{0,258,0},send,{'Result-Code',2001}},3},
               {{{0,280,1},recv},66},
               {{{0,280,0},send},66},
               {{{0,280,0},send,{'Result-Code',2001}},66},
               {{{0,257,1},recv},1},
               {{{0,257,0},send},1},
               {{{0,257,0},send,{'Result-Code',2001}},1}]}]]
</pre>

<p>
Note that there may be multiple entries with the same <c>ref</c>, in
contrast to <c>transport</c> info.</p>
</item>

<tag><c>statistics</c></tag>
<item>
<p>
Return a <c>{{Counter, Ref}, non_neg_integer()}</c> list of counter values.
<c>Ref</c> can be either a <c>&transport_ref;</c>
or a <c>&app_peer_ref;</c>.
Entries for the latter are folded into corresponding entries for the
former as peer connections go down.
Entries for both are removed at &remove_transport;.
The Diameter-level statistics returned by <c>transport</c> and
<c>connections</c> info are based upon these entries.</p>
</item>

<tag><c>&app_peer_ref;</c></tag>
<item>
<p>
Return transport configuration associated with a single peer, as
passed to &add_transport;.
The returned list is empty if the peer is unknown.
Otherwise it contains the <c>ref</c>, <c>type</c> and <c>options</c>
tuples as in <c>transport</c> and <c>connections</c> info above.
For example:</p>

<pre>
[{ref,#Ref&lt;0.0.0.61>},
 {type,accept},
 {options,[{transport_module,diameter_tcp},
           {transport_config,[{reuseaddr,true},
                              {ip,{127,0,0,1}},
                              {port,3868}]}]}]
</pre>
</item>

</taglist>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">services() -> [SvcName]</name>
<fsummary>Return the list of started services.</fsummary>
<type>
<v>SvcName = &service_name;</v>
</type>
<desc>
<p>
Return the list of started services.</p>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">session_id(Ident) -> &dict_OctetString;</name>
<fsummary>Return a value for a Session-Id AVP.</fsummary>
<type>
<v>Ident = &dict_DiameterIdentity;</v>
</type>
<desc>
<p>
Return a value for a Session-Id AVP.</p>

<p>
The value has the form required by section 8.8 of &the_rfc;.
Ident should be the Origin-Host of the peer from which
the message containing the returned value will be sent.</p>

</desc>
</func>

<!-- ===================================================================== -->
<func>
<name since="OTP R14B03">start() -> ok | {error, Reason}</name>
<fsummary>Start the diameter application.</fsummary>
<desc>
<p>
Start the diameter application.</p>

<p>
The diameter application must be started before starting a service.
In a production system this is typically accomplished by a boot
file, not by calling <c>start/0</c> explicitly.</p>

</desc>
</func>

<!-- ===================================================================== -->
<func>
<name since="OTP R14B03">start_service(SvcName, Options) -> ok | {error, Reason}</name>
<fsummary>Start a Diameter service.</fsummary>
<type>
<v>SvcName = &service_name;</v>
<v>Options = [&service_opt;]</v>
<v>Reason  = term()</v>
</type>
<desc>
<p>
Start a diameter service.</p>

<p>
A service defines a locally-implemented Diameter node, specifying the
capabilities to be advertised during capabilities exchange.
Transports are added to a service using &add_transport;.
</p>

<note>
<p>
A transport can both override its service's
capabilities and restrict its supported Diameter applications so
"service = Diameter node as identified by Origin-Host" is not
necessarily the case.</p>
</note>

</desc>
</func>

<!-- ===================================================================== -->
<func>
<name since="OTP R14B03">stop() -> ok | {error, Reason}</name>
<fsummary>Stop the diameter application.</fsummary>
<desc>
<p>
Stop the diameter application.</p>

<p>
</p>

</desc>
</func>

<!-- ===================================================================== -->
<func>
<name since="OTP R14B03">stop_service(SvcName) -> ok | {error, Reason}</name>
<fsummary>Stop a Diameter service.</fsummary>
<type>
<v>SvcName = &service_name;</v>
<v>Reason = term()</v>
</type>
<desc>
<p>
Stop a diameter service.</p>

<p>
Stopping a service causes all associated transport connections to be
broken.
A DPR message will be sent as in the case of &remove_transport;.</p>

<note>
<p>
Stopping a service does not remove any associated transports:
&remove_transport; must
be called to remove transport configuration.</p>
</note>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">subscribe(SvcName) -> true</name>
<fsummary>Subscribe to event messages.</fsummary>
<type>
<v>SvcName = &service_name;</v>
</type>
<desc>
<p>
Subscribe to <c>&service_event;</c> messages from
a service.</p>

<p>
It is not an error to subscribe to events from a service
that does not yet exist.
Doing so before adding transports is required to guarantee the
reception of all transport-related events.</p>

</desc>
</func>

<!-- ===================================================================== -->

<func>
<name since="OTP R14B03">unsubscribe(SvcName) -> true</name>
<fsummary>Unsubscribe to event messages.</fsummary>
<type>
<v>SvcName = &service_name;</v>
</type>
<desc>
<p>
Unsubscribe to event messages from a service.</p>

</desc>
</func>

</funcs>

<!-- ===================================================================== -->
<!-- ===================================================================== -->
<section>
<title>SEE ALSO</title>

<p>
&man_app;, &man_transport;, &man_dict;</p>

</section>

</erlref>