<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html xmlns:fn="http://www.w3.org/2005/02/xpath-functions"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css"> <title>Erlang -- diameter(3)</title> </head> <body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container"> <script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript"> <!-- function getWinHeight() { var myHeight = 0; if( typeof( window.innerHeight ) == 'number' ) { //Non-IE myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myHeight = document.body.clientHeight; } return myHeight; } function setscrollpos() { var objf=document.getElementById('loadscrollpos'); document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2; } function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, true); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } addEvent(window, 'load', setscrollpos); //--></script><div id="leftnav"><div class="innertube"> <img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/diameter-1.3.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>Diameter</strong><br><strong>Reference Manual</strong><br><small>Version 1.3</small></p> <br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Table of Contents</strong></small></p> <ul class="flipMenu"> <li id="loadscrollpos" title="diameter " expanded="true">diameter<ul> <li><a href="diameter.html"> Top of manual page </a></li> <li title="add_transport-2"><a href="diameter.html#add_transport-2">add_transport/2</a></li> <li title="call-4"><a href="diameter.html#call-4">call/4</a></li> <li title="origin_state_id-0"><a href="diameter.html#origin_state_id-0">origin_state_id/0</a></li> <li title="remove_transport-2"><a href="diameter.html#remove_transport-2">remove_transport/2</a></li> <li title="service_info-2"><a href="diameter.html#service_info-2">service_info/2</a></li> <li title="services-0"><a href="diameter.html#services-0">services/0</a></li> <li title="session_id-1"><a href="diameter.html#session_id-1">session_id/1</a></li> <li title="start-0"><a href="diameter.html#start-0">start/0</a></li> <li title="start_service-2"><a href="diameter.html#start_service-2">start_service/2</a></li> <li title="stop-0"><a href="diameter.html#stop-0">stop/0</a></li> <li title="stop_service-1"><a href="diameter.html#stop_service-1">stop_service/1</a></li> <li title="subscribe-1"><a href="diameter.html#subscribe-1">subscribe/1</a></li> <li title="unsubscribe-1"><a href="diameter.html#unsubscribe-1">unsubscribe/1</a></li> </ul> </li> <li title="diameterc"><a href="diameterc.html">diameterc</a></li> <li id="no" title="diameter_app " expanded="false">diameter_app<ul> <li><a href="diameter_app.html"> Top of manual page </a></li> <li title="Mod:peer_up-3"><a href="diameter_app.html#Mod:peer_up-3">Mod:peer_up/3</a></li> <li title="Mod:peer_down-3"><a href="diameter_app.html#Mod:peer_down-3">Mod:peer_down/3</a></li> <li title="Mod:pick_peer-4"><a href="diameter_app.html#Mod:pick_peer-4">Mod:pick_peer/4</a></li> <li title="Mod:prepare_request-3"><a href="diameter_app.html#Mod:prepare_request-3">Mod:prepare_request/3</a></li> <li title="Mod:prepare_retransmit-3"><a href="diameter_app.html#Mod:prepare_retransmit-3">Mod:prepare_retransmit/3</a></li> <li title="Mod:handle_answer-4"><a href="diameter_app.html#Mod:handle_answer-4">Mod:handle_answer/4</a></li> <li title="Mod:handle_error-4"><a href="diameter_app.html#Mod:handle_error-4">Mod:handle_error/4</a></li> <li title="Mod:handle_request-3"><a href="diameter_app.html#Mod:handle_request-3">Mod:handle_request/3</a></li> </ul> </li> <li id="no" title="diameter_codec " expanded="false">diameter_codec<ul> <li><a href="diameter_codec.html"> Top of manual page </a></li> <li title="decode-2"><a href="diameter_codec.html#decode-2">decode/2</a></li> <li title="encode-2"><a href="diameter_codec.html#encode-2">encode/2</a></li> </ul> </li> <li title="diameter_dict"><a href="diameter_dict.html">diameter_dict</a></li> <li id="no" title="diameter_make " expanded="false">diameter_make<ul> <li><a href="diameter_make.html"> Top of manual page </a></li> <li title="codec-2"><a href="diameter_make.html#codec-2">codec/2</a></li> </ul> </li> <li id="no" title="diameter_transport " expanded="false">diameter_transport<ul> <li><a href="diameter_transport.html"> Top of manual page </a></li> <li title="Mod:start-3"><a href="diameter_transport.html#Mod:start-3">Mod:start/3</a></li> </ul> </li> <li id="no" title="diameter_tcp " expanded="false">diameter_tcp<ul> <li><a href="diameter_tcp.html"> Top of manual page </a></li> <li title="start-3"><a href="diameter_tcp.html#start-3">start/3</a></li> </ul> </li> <li id="no" title="diameter_sctp " expanded="false">diameter_sctp<ul> <li><a href="diameter_sctp.html"> Top of manual page </a></li> <li title="start-3"><a href="diameter_sctp.html#start-3">start/3</a></li> </ul> </li> </ul> </div></div> <div id="content"> <div class="innertube"> <!-- refpage --><center><h1>diameter</h1></center> <h3>MODULE</h3> <div class="REFBODY">diameter</div> <h3>MODULE SUMMARY</h3> <div class="REFBODY">Main API of the diameter application.</div> <h3>DESCRIPTION</h3> <div class="REFBODY"><p> <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 RFC 6733.</p> <p> Basic usage consists of creating a representation of a locally implemented Diameter node and its capabilities with <span class="bold_code"><a href="#start_service-2">start_service/2</a></span>, adding transport capability using <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span> and sending Diameter requests and receiving Diameter answers with <span class="bold_code"><a href="#call-4">call/4</a></span>. Incoming Diameter requests are communicated as callbacks to a <span class="bold_code"><a href="diameter_app.html">diameter_app(3)</a></span> callback modules as specified in the service configuration.</p> <p> Beware the difference between <strong>diameter</strong> (not capitalised) and <strong>Diameter</strong> (capitalised). The former refers to the Erlang application named diameter whose main api is defined here, the latter to Diameter protocol in the sense of RFC 6733.</p> <p> The diameter application must be started before calling most functions in this module.</p> </p></div> <h3><a name="id64675">DATA TYPES</a></h3> <div class="REFBODY"> <dl> <dt><strong><span class="code">Address()</span></strong></dt> <dt><strong><span class="code">DiameterIdentity()</span></strong></dt> <dt><strong><span class="code">Grouped()</span></strong></dt> <dt><strong><span class="code">OctetString()</span></strong></dt> <dt><strong><span class="code">Time()</span></strong></dt> <dt><strong><span class="code">Unsigned32()</span></strong></dt> <dt><strong><span class="code">UTF8String()</span></strong></dt> <dd> <p> Types corresponding to RFC 6733 AVP Data Formats. Defined in <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">diameter_dict(4)</a></span>.</p> <a name="application_alias"></a> </dd> <dt><strong><span class="code">application_alias() = term()</span></strong></dt> <dd> <p> A name identifying a Diameter application in service configuration. Passed to <span class="bold_code"><a href="#call-4">call/4</a></span> when sending requests defined by the application.</p> <a name="application_module"></a> </dd> <dt><strong><span class="code">application_module() = Mod | [Mod | ExtraArgs] | #diameter_callback{}</span></strong></dt> <dd> <div class="example"><pre> Mod = atom() ExtraArgs = list() </pre></div> <p> A module implementing the callback interface defined in <span class="bold_code"><a href="diameter_app.html">diameter_app(3)</a></span>, along with any extra arguments to be appended to those documented for the interface. Note that extra arguments specific to an outgoing request can be specified to <span class="bold_code"><a href="#call-4">call/4</a></span>, in which case those are are appended to any module-specific extra arguments.</p> <p> Specifying a <span class="code">#diameter_callback{}</span> record allows individual functions to be configured in place of the usual <span class="bold_code"><a href="diameter_app.html">diameter_app(3)</a></span> callbacks. See that module for details.</p> <a name="application_opt"></a> </dd> <dt><strong><span class="code">application_opt()</span></strong></dt> <dd> <p> Options defining a Diameter application. Has one the following types.</p> <dl> <dt><strong><span class="code">{alias, <span class="bold_code"><a href="#application_alias">application_alias()</a></span>}</span></strong></dt> <dd> <p> An unique identifier for the application in the scope of the service. Defaults to the value of the <span class="code">dictionary</span> option if unspecified.</p> </dd> <dt><strong><span class="code">{dictionary, atom()}</span></strong></dt> <dd> <p> The name of an encode/decode module for the Diameter messages defined by the application. These modules are generated from a specification file whose format is documented in <span class="bold_code"><a href="diameter_dict.html">diameter_dict(4)</a></span>.</p> </dd> <dt><strong><span class="code">{module, <span class="bold_code"><a href="#application_module">application_module()</a></span>}</span></strong></dt> <dd> <p> The callback module with which messages of the Diameter application are handled. See <span class="bold_code"><a href="diameter_app.html">diameter_app(3)</a></span> for the required interface and semantics.</p> </dd> <dt><strong><span class="code">{state, term()}</span></strong></dt> <dd> <p> The initial callback state. The prevailing state is passed to some <span class="bold_code"><a href="diameter_app.html">diameter_app(3)</a></span> callbacks, which can then return a new state. Defaults to the value of the <span class="code">alias</span> option if unspecified.</p> </dd> <dt><strong><span class="code">{call_mutates_state, true|false}</span></strong></dt> <dd> <p> Specifies whether or not the <span class="bold_code"><a href="diameter_app.html#Mod:pick_peer-4">pick_peer/4</a></span> application callback can modify the application state, Defaults to <span class="code">false</span> if unspecified.</p> <div class="note"> <div class="label">Note</div> <div class="content"><p> <p> <span class="bold_code"><a href="diameter_app.html#Mod:pick_peer-4">pick_peer/4</a></span> callbacks are serialized when these are allowed to modify state, 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> </p></div> </div> </dd> <dt><strong><span class="code">{answer_errors, callback|report|discard}</span></strong></dt> <dd> <p> Determines the manner in which incoming answer messages containing decode errors are handled. If <span class="code">callback</span> then errors result in a <span class="bold_code"><a href="diameter_app.html#Mod:handle_answer-4">handle_answer/4</a></span> callback in the same fashion as for <span class="bold_code"><a href="diameter_app.html#Mod:handle_request-3">handle_request/3</a></span>, with errors communicated in the <span class="code">errors</span> field of the <span class="code">#diameter_packet{}</span> record passed to the callback. If <span class="code">report</span> then an answer containing errors is discarded without a callback and a warning report is written to the log. If <span class="code">discard</span> then an answer containing errors is silently discarded without a callback. In both the <span class="code">report</span> and <span class="code">discard</span> cases the return value for the <span class="bold_code"><a href="#call-4">call/4</a></span> invocation in question is as if a callback had taken place and returned <span class="code">{error, failure}</span>.</p> <p> Defaults to <span class="code">report</span> if unspecified.</p> </dd> </dl> <a name="call_opt"></a> </dd> <dt><strong><span class="code">call_opt()</span></strong></dt> <dd> <p> Options available to <span class="bold_code"><a href="#call-4">call/4</a></span> when sending an outgoing Diameter request. Has one of the following types.</p> <dl> <dt><strong><span class="code">{extra, list()}</span></strong></dt> <dd> <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> </dd> <dt><strong><span class="code">{filter, <span class="bold_code"><a href="#peer_filter">peer_filter()</a></span>}</span></strong></dt> <dd> <p> A filter to apply to the list of available peers before passing them to the <span class="bold_code"><a href="diameter_app.html#Mod:pick_peer-4">pick_peer/4</a></span> callback for the application in question. Multiple options are equivalent a single <span class="code">all</span> filter on the corresponding list of filters. Defaults to <span class="code">none</span>.</p> </dd> <dt><strong><span class="code">{timeout, <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>}</span></strong></dt> <dd> <p> The number of milliseconds after which the request should timeout. Defaults to 5000.</p> </dd> <dt><strong><span class="code">detach</span></strong></dt> <dd> <p> Causes <span class="bold_code"><a href="#call-4">call/4</a></span> to return <span class="code">ok</span> as soon as the request in question has been encoded instead of waiting for and returning the result from a subsequent <span class="bold_code"><a href="diameter_app.html#Mod:handle_answer-4">handle_answer/4</a></span> or <span class="bold_code"><a href="diameter_app.html#Mod:handle_error-4">handle_error/4</a></span> callback.</p> </dd> </dl> <p> An invalid option will cause <span class="bold_code"><a href="#call-4">call/4</a></span> to fail.</p> <a name="capability"></a> </dd> <dt><strong><span class="code">capability()</span></strong></dt> <dd> <p> AVP values sent in outgoing CER or CEA messages during capabilities exchange. Can be configured both on a service and a transport, values specified on the latter taking precedence over any specified on the former. Has one of the following types.</p> <dl> <dt><strong><span class="code">{'Origin-Host', <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">DiameterIdentity()</a></span>}</span></strong></dt> <dt><strong><span class="code">{'Origin-Realm', <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">DiameterIdentity()</a></span>}</span></strong></dt> <dt><strong><span class="code">{'Host-IP-Address', [<span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Address()</a></span>]}</span></strong></dt> <dd> <p> An address list is available to the start function of a <span class="bold_code"><a href="diameter_transport.html">transport module</a></span>, which can return a new list for use in the subsequent CER or CEA. Host-IP-Address need not be specified if the transport start function returns an address list.</p> </dd> <dt><strong><span class="code">{'Vendor-Id', <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>}</span></strong></dt> <dt><strong><span class="code">{'Product-Name', <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">UTF8String()</a></span>}</span></strong></dt> <dt><strong><span class="code">{'Origin-State-Id', <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>}</span></strong></dt> <dd> <p> Origin-State-Id is optional but will be included in outgoing messages sent by diameter itself: CER/CEA, DWR/DWA and DPR/DPA. Setting a value of <span class="code">0</span> (zero) is equivalent to not setting a value as documented in RFC 6733. The function <span class="bold_code"><a href="#origin_state_id-0">origin_state_id/0</a></span> can be used as to retrieve a value that is computed when the diameter application is started.</p> </dd> <dt><strong><span class="code">{'Supported-Vendor-Id', [<span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>]}</span></strong></dt> <dt><strong><span class="code">{'Auth-Application-Id', [<span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>]}</span></strong></dt> <dt><strong><span class="code">{'Inband-Security-Id', [<span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>]}</span></strong></dt> <dd> <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> </dd> <dt><strong><span class="code">{'Acct-Application-Id', [<span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>]}</span></strong></dt> <dt><strong><span class="code">{'Vendor-Specific-Application-Id', [<span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Grouped()</a></span>]}</span></strong></dt> <dt><strong><span class="code">{'Firmware-Revision', <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>}</span></strong></dt> </dl> <p> Note that each tuple communicates one or more AVP values. It is an error to specify duplicate tuples.</p> <a name="evaluable"></a> </dd> <dt><strong><span class="code">evaluable() = {M,F,A} | fun() | [evaluable() | A]</span></strong></dt> <dd> <p> An expression that can be evaluated as a function in the following sense.</p> <div class="example"><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></div> <p> Applying an <span class="code"><span class="bold_code"><a href="#evaluable">evaluable()</a></span></span> <span class="code">E</span> to an argument list <span class="code">A</span> is meant in the sense of <span class="code">eval([E|A])</span>.</p> <div class="warning"> <div class="label">Warning</div> <div class="content"><p> <p> Beware of using fun expressions of the form <span class="code">fun Name/Arity</span> 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 <span class="bold_code"><a href="#start_service-2">start_service/2</a></span> or <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span>.</p> </p></div> </div> <a name="peer_filter"></a> </dd> <dt><strong><span class="code">peer_filter() = term()</span></strong></dt> <dd> <p> A filter passed to <span class="bold_code"><a href="#call-4">call/4</a></span> in order to select candidate peers for a <span class="bold_code"><a href="diameter_app.html#Mod:pick_peer-4">pick_peer/4</a></span> callback. Has one of the following types.</p> <dl> <dt><strong><span class="code">none</span></strong></dt> <dd> <p> Matches any peer. This is a convenience that provides a filter equivalent to no filter at all.</p> </dd> <dt><strong><span class="code">host</span></strong></dt> <dd> <p> Matches only those peers whose <span class="code">Origin-Host</span> has the same value as <span class="code">Destination-Host</span> in the outgoing request in question, or any peer if the request does not contain a <span class="code">Destination-Host</span> AVP.</p> </dd> <dt><strong><span class="code">realm</span></strong></dt> <dd> <p> Matches only those peers whose <span class="code">Origin-Realm</span> has the same value as <span class="code">Destination-Realm</span> in the outgoing request in question, or any peer if the request does not contain a <span class="code">Destination-Realm</span> AVP.</p> </dd> <dt><strong><span class="code">{host, any|<span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">DiameterIdentity()</a></span>}</span></strong></dt> <dd> <p> Matches only those peers whose <span class="code">Origin-Host</span> has the specified value, or all peers if the atom <span class="code">any</span>.</p> </dd> <dt><strong><span class="code">{realm, any|<span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">DiameterIdentity()</a></span></span></strong></dt> <dd> <p> Matches only those peers whose <span class="code">Origin-Realm</span> has the specified value, or all peers if the atom <span class="code">any</span>.</p> </dd> <dt><strong><span class="code">{eval, <span class="bold_code"><a href="#evaluable">evaluable()</a></span>}</span></strong></dt> <dd> <p> Matches only those peers for which the specified <span class="code"><span class="bold_code"><a href="#evaluable">evaluable()</a></span></span> returns <span class="code">true</span> on the connection's <span class="code">diameter_caps</span> record. Any other return value or exception is equivalent to <span class="code">false</span>.</p> </dd> <dt><strong><span class="code">{neg, <span class="bold_code"><a href="#peer_filter">peer_filter()</a></span>}</span></strong></dt> <dd> <p> Matches only those peers not matched by the specified filter.</p> </dd> <dt><strong><span class="code">{all, [<span class="bold_code"><a href="#peer_filter">peer_filter()</a></span>]}</span></strong></dt> <dd> <p> Matches only those peers matched by each filter in the specified list.</p> </dd> <dt><strong><span class="code">{any, [<span class="bold_code"><a href="#peer_filter">peer_filter()</a></span>]}</span></strong></dt> <dd> <p> Matches only those peers matched by at least one filter in the specified list.</p> </dd> </dl> <p> An invalid filter is equivalent to <span class="code">{any,[]}</span>, a filter that matches no peer.</p> <div class="note"> <div class="label">Note</div> <div class="content"><p> <p> The <span class="code">host</span> and <span class="code">realm</span> filters examine the outgoing request as passed to <span class="bold_code"><a href="#call-4">call/4</a></span>, assuming that this is a record- or list-valued <span class="code"><span class="bold_code"><a href="diameter_codec.html#message">diameter_codec:message()</a></span></span>, and that the message contains at most one of each AVP. If this is not the case then the <span class="code">{host|realm, <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">DiameterIdentity()</a></span>}</span> filters must be used to achieve the desired result. An empty <span class="code"><span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">DiameterIdentity()</a></span></span> (which should not be typical) matches all hosts/realms for the purposes of filtering.</p> </p></div> </div> <div class="warning"> <div class="label">Warning</div> <div class="content"><p> <p> A <span class="code">host</span> filter is not typically desirable when setting Destination-Host since it will remove peer agents from the candidates list.</p> </p></div> </div> <a name="service_event"></a> </dd> <dt><strong><span class="code">service_event() = #diameter_event{}</span></strong></dt> <dd> <p> An event message sent to processes that have subscribed to these using <span class="bold_code"><a href="#subscribe-1">subscribe/1</a></span>.</p> <p> The <span class="code">info</span> field of the event record can have one of the following types.</p> <dl> <dt><strong><span class="code">start</span></strong></dt> <dt><strong><span class="code">stop</span></strong></dt> <dd> <p> The service is being started or stopped. No event precedes a <span class="code">start</span> event. No event follows a <span class="code">stop</span> event and this event implies the termination of all transport processes.</p> </dd> <dt><strong><span class="code">{up, Ref, Peer, Config, Pkt}</span></strong></dt> <dt><strong><span class="code">{up, Ref, Peer, Config}</span></strong></dt> <dt><strong><span class="code">{down, Ref, Peer, Config}</span></strong></dt> <dd> <div class="example"><pre> Ref = <span class="bold_code"><a href="#transport_ref">transport_ref()</a></span> Peer = <span class="bold_code"><a href="diameter_app.html#peer">diameter_app:peer()</a></span> Config = {connect|listen, [<span class="bold_code"><a href="#transport_opt">transport_opt()</a></span>]} Pkt = #diameter_packet{} </pre></div> <p> The RFC 3539 watchdog state machine has transitioned into (<span class="code">up</span>) or out of (<span class="code">down</span>) the OKAY state. If a <span class="code">#diameter_packet{}</span> record is present in an <span class="code">up</span> event then there has been a capabilties exchange on a newly established transport connection and the record contains the received CER or CEA. Otherwise a connection has reestablished without the loss or connectivity.</p> <p> Note that a single <span class="code">up</span>/<span class="code">down</span> event for a given peer corresponds to one <span class="bold_code"><a href="diameter_app.html#Mod:peer_up-3">peer_up/3</a></span>/<span class="bold_code"><a href="diameter_app.html#Mod:peer_down-3">peer_up/3</a></span> callback for each of the Diameter applications negotiated during capablilities 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> </dd> <dt><strong><span class="code">{reconnect, Ref, Opts}</span></strong></dt> <dd> <div class="example"><pre> Ref = <span class="bold_code"><a href="#transport_ref">transport_ref()</a></span> Opts = [<span class="bold_code"><a href="#transport_opt">transport_opt()</a></span>] </pre></div> <p> A connecting transport is attempting to establish/reestablish a transport connection with a peer following <span class="bold_code"><a href="#reconnect_timer">reconnect_timer</a></span> or <span class="bold_code"><a href="#watchdog_timer">watchdog_timer</a></span> expiry.</p> </dd> <dt><strong><span class="code">{closed, Ref, Reason, Config}</span></strong></dt> <dd> <div class="example"><pre> Ref = <span class="bold_code"><a href="#transport_ref">transport_ref()</a></span> Config = {connect|listen, [<span class="bold_code"><a href="#transport_opt">transport_opt()</a></span>]} </pre></div> <p> Capabilities exchange has failed. <span class="code">Reason</span> can have one of the following types.</p> <dl> <dt><strong><span class="code">{'CER', Result, Caps, Pkt}</span></strong></dt> <dd> <div class="example"><pre> Result = ResultCode | {capabilities_cb, CB, ResultCode|discard} Caps = #diameter_caps{} Pkt = #diameter_packet{} ResultCode = integer() CB = <span class="bold_code"><a href="#evaluable">evaluable()</a></span> </pre></div> <p> An incoming CER has been answered with the indicated result code or discarded. <span class="code">Caps</span> contains pairs of values for the the local node and remote peer. <span class="code">Pkt</span> contains the CER in question. In the case of rejection by a capabilities callback, the tuple contains the rejecting callback.</p> </dd> <dt><strong><span class="code">{'CER', Caps, {ResultCode, Pkt}}</span></strong></dt> <dd> <div class="example"><pre> ResultCode = integer() Caps = #diameter_caps{} Pkt = #diameter_packet{} </pre></div> <p> An incoming CER contained errors and has been answered with the indicated result code. <span class="code">Caps</span> contains only values for the the local node. <span class="code">Pkt</span> contains the CER in question.</p> </dd> <dt><strong><span class="code">{'CER', timeout}</span></strong></dt> <dd> <p> An expected CER was not received within <span class="bold_code"><a href="#capx_timeout">capx_timeout</a></span> of connection establishment.</p> </dd> <dt><strong><span class="code">{'CEA', Result, Caps, Pkt}</span></strong></dt> <dd> <div class="example"><pre> Result = integer() | atom() | {capabilities_cb, CB, ResultCode|discard} Caps = #diameter_caps{} Pkt = #diameter_packet{} ResultCode = integer() </pre></div> <p> An incoming CEA has been rejected for the indicated reason. An integer-valued <span class="code">Result</span> indicates the result code sent by the peer. <span class="code">Caps</span> contains pairs of values for the the local node and remote peer. <span class="code">Pkt</span> contains the CEA in question. In the case of rejection by a capabilities callback, the tuple contains the rejecting callback.</p> </dd> <dt><strong><span class="code">{'CEA', Caps, Pkt}</span></strong></dt> <dd> <div class="example"><pre> Caps = #diameter_caps{} Pkt = #diameter_packet{} </pre></div> <p> An incoming CEA contained errors and has been rejected. <span class="code">Caps</span> contains only values for the the local node. <span class="code">Pkt</span> contains the CEA in question.</p> </dd> <dt><strong><span class="code">{'CEA', timeout}</span></strong></dt> <dd> <p> An expected CEA was not received within <span class="bold_code"><a href="#capx_timeout">capx_timeout</a></span> of connection establishment.</p> </dd> </dl> </dd> <dt><strong><span class="code">{watchdog, Ref, PeerRef, {From, To}, Config}</span></strong></dt> <dd> <div class="example"><pre> Ref = <span class="bold_code"><a href="#transport_ref">transport_ref()</a></span> PeerRef = <span class="bold_code"><a href="diameter_app.html#peer_ref">diameter_app:peer_ref()</a></span> From, To = initial | okay | suspect | down | reopen Config = {connect|listen, [transport_opt()]} </pre></div> <p> An RFC 3539 watchdog state machine has changed state.</p> </dd> </dl> <p> For forward compatibility, a subscriber should be prepared to receive info fields of forms other than the above.</p> <a name="service_name"></a> </dd> <dt><strong><span class="code">service_name() = term()</span></strong></dt> <dd> <p> The name of a service as passed to <span class="bold_code"><a href="#start_service-2">start_service/2</a></span> and with which the service is identified. There can be at most one service with a given name on a given node. Note that <span class="bold_code"><a href="javascript:erlhref('../../../../doc/../','erts','erlang.html#make_ref-0');">erlang:make_ref/0</a></span> can be used to generate a service name that is somewhat unique.</p> <a name="service_opt"></a> </dd> <dt><strong><span class="code">service_opt()</span></strong></dt> <dd> <p> An option passed to <span class="bold_code"><a href="#start_service-2">start_service/2</a></span>. Can be any <span class="code"><span class="bold_code"><a href="#capability">capability()</a></span></span> as well as the following.</p> <dl> <dt><strong><span class="code">{application, [<span class="bold_code"><a href="#application_opt">application_opt()</a></span>]}</span></strong></dt> <dd> <p> Defines 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 Diameter request, the relevant <span class="code"><span class="bold_code"><a href="#application_alias">application_alias()</a></span></span> is passed to <span class="bold_code"><a href="#call-4">call/4</a></span>, while for an incoming request the application identifier in the message header determines the application, the identifier being specified in the application's <span class="bold_code"><a href="diameter_dict.html">dictionary</a></span> file.</p> </dd> <dt><strong><span class="code">{restrict_connections, false | node | nodes | [node()] | evaluable()}</span></strong></dt> <dd> <p> Specifies the degree to which multiple transport connections to the same peer are accepted by the service.</p> <p> If type <span class="code">[node()]</span> then a connection is rejected if another already exists on any of the specified nodes. Values of type <span class="code">false</span>, <span class="code">node</span>, <span class="code">nodes</span> or <span class="bold_code"><a href="#evaluable">evaluable()</a></span> are equivalent to values <span class="code">[]</span>, <span class="code">[node()]</span>, <span class="code">[node()|nodes()]</span> and the evaluated value, respectively, evaluation of each expression taking place whenever a new connection is to be established. Note that <span class="code">false</span> 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 <span class="code">nodes</span>.</p> </dd> <dt><strong><span class="code">{sequence, {H,N} | <span class="bold_code"><a href="#evaluable">evaluable()</a></span>}</span></strong></dt> <dd> <p> Specifies a constant value <span class="code">H</span> for the topmost <span class="code">32-N</span> bits of of 32-bit End-to-End and Hop-by-Hop identifiers generated by the service, either explicity or as a return value of a function to be evaluated at <span class="bold_code"><a href="#start_service-2">start_service/2</a></span>. In particular, an identifier <span class="code">Id</span> is mapped to a new identifier as follows.</p> <div class="example"><pre> (H bsl N) bor (Id band ((1 bsl N) - 1)) </pre></div> <p> Note that RFC 6733 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 the appropriate values of <span class="code">N</span>: at a rate of <span class="code">R</span> requests per second an <span class="code">N</span>-bit counter traverses all of its values in <span class="code">(1 bsl N) div (R*60)</span> minutes so the bound is <span class="code">4*R*60 =< 1 bsl N</span>.</p> <p><span class="code">N</span> must lie in the range <span class="code">0..32</span> and <span class="code">H</span> must be a non-negative integer less than <span class="code">1 bsl (32-N)</span>.</p> <p> Defaults to <span class="code">{0,32}</span>.</p> </dd> </dl> <a name="transport_opt"></a> </dd> <dt><strong><span class="code">transport_opt()</span></strong></dt> <dd> <p> An option passed to <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span>. Has one of the following types.</p> <dl> <a name="applications"></a> <dt><strong><span class="code">{applications, [<span class="bold_code"><a href="#application_alias">application_alias()</a></span>]}</span></strong></dt> <dd> <p> The list of 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> </dd> <a name="capabilities"></a> <dt><strong><span class="code">{capabilities, [<span class="bold_code"><a href="#capability">capability()</a></span>]}</span></strong></dt> <dd> <p> AVP's 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 <span class="bold_code"><a href="diameter_tcp.html">diameter_tcp(3)</a></span>.</p> </dd> <a name="capabilities_cb"></a> <dt><strong><span class="code">{capabilities_cb, <span class="bold_code"><a href="#evaluable">evaluable()</a></span>}</span></strong></dt> <dd> <p> A 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 <span class="code"><span class="bold_code"><a href="#transport_ref">transport_ref()</a></span></span> and <span class="code">#diameter_caps{}</span> record of the connection.</p> <p> The return value can have one of the following types.</p> <dl> <dt><strong><span class="code">ok</span></strong></dt> <dd> <p> Accept the connection.</p> </dd> <dt><strong><span class="code">integer()</span></strong></dt> <dd> <p> Causes an incoming CER to be answered with the specified Result-Code.</p> </dd> <dt><strong><span class="code">discard</span></strong></dt> <dd> <p> Causes an incoming CER to be discarded without CEA being sent.</p> </dd> <dt><strong><span class="code">unknown</span></strong></dt> <dd> <p> Equivalent to returning <span class="code">3010</span>, DIAMETER_UNKNOWN_PEER.</p> </dd> </dl> <p> Returning anything but <span class="code">ok</span> or a 2xxx series result code causes the transport connection to be broken. Multiple <span class="bold_code"><a href="#capabilities_cb">capabilities_cb</a></span> options can be specified, in which case the corresponding callbacks are applied until either all return <span class="code">ok</span> or one does not.</p> </dd> <a name="capx_timeout"></a> <dt><strong><span class="code">{capx_timeout, <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>}</span></strong></dt> <dd> <p> The 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 reconnection attempts is governed by <span class="bold_code"><a href="#watchdog_timer">watchdog_timer</a></span> or <span class="bold_code"><a href="#reconnect_timer">reconnect_timer</a></span> expiry. For a listening transport, the peer determines the timing.</p> <p> Defaults to 10000.</p> </dd> <a name="disconnect_cb"></a> <dt><strong><span class="code">{disconnect_cb, <span class="bold_code"><a href="#evaluable">evaluable()</a></span>}</span></strong></dt> <dd> <p> A callback invoked prior to terminating the transport process of a transport connection having watchdog state <span class="code">OKAY</span>. Applied to <span class="code">Reason=transport|service|application</span> and the <span class="code"><span class="bold_code"><a href="#transport_ref">transport_ref()</a></span></span> and <span class="code"><span class="bold_code"><a href="diameter_app.html#peer">diameter_app:peer()</a></span></span> in question, <span class="code">Reason</span> indicating whether the the diameter application is being stopped, the service in question is being stopped at <span class="bold_code"><a href="#stop_service-1">stop_service/1</a></span> or the transport in question is being removed at <span class="bold_code"><a href="#remove_transport-2">remove_transport/2</a></span>, respectively.</p> <p> The return value can have one of the following types.</p> <dl> <dt><strong><span class="code">{dpr, [option()]}</span></strong></dt> <dd> <p> Causes Disconnect-Peer-Request to be sent to the peer, the transport process being terminated following reception of Disconnect-Peer-Answer or timeout. An <span class="code">option()</span> can be one of the following.</p> <dl> <dt><strong><span class="code">{cause, 0|rebooting|1|busy|2|goaway}</span></strong></dt> <dd> <p> The Disconnect-Cause to send, <span class="code">REBOOTING</span>, <span class="code">BUSY</span> and <span class="code">DO_NOT_WANT_TO_TALK_TO_YOU</span> respectively. Defaults to <span class="code">rebooting</span> for <span class="code">Reason=service|application</span> and <span class="code">goaway</span> for <span class="code">Reason=transport</span>.</p> </dd> <dt><strong><span class="code">{timeout, <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>}</span></strong></dt> <dd> <p> The number of milliseconds after which the transport process is terminated if DPA has not been received. Defaults to 1000.</p> </dd> </dl> </dd> <dt><strong><span class="code">dpr</span></strong></dt> <dd> <p> Equivalent to <span class="code">{dpr, []}</span>.</p> </dd> <dt><strong><span class="code">close</span></strong></dt> <dd> <p> Causes the transport process to be terminated without Disconnect-Peer-Request being sent to the peer.</p> </dd> <dt><strong><span class="code">ignore</span></strong></dt> <dd> <p> Equivalent to not having configured the callback.</p> </dd> </dl> <p> Multiple <span class="bold_code"><a href="#disconnect_cb">disconnect_cb</a></span> options can be specified, in which case the corresponding callbacks are applied until one of them returns a value other than <span class="code">ignore</span>. All callbacks returning <span class="code">ignore</span> is equivalent to not having configured them.</p> <p> Defaults to a single callback returning <span class="code">dpr</span>.</p> </dd> <a name="reconnect_timer"></a> <dt><strong><span class="code">{reconnect_timer, Tc}</span></strong></dt> <dd> <div class="example"><pre> Tc = <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span> </pre></div> <p> For a connecting transport, the RFC 6733 Tc timer, in milliseconds. Note that this timer determines the frequency with which a transport will attempt to establish a connection with its peer only <strong>before</strong> an initial connection is established: once there is an initial connection it's <span class="bold_code"><a href="#watchdog_timer">watchdog_timer</a></span> that 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 a 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 <span class="bold_code"><a href="#reconnect_timer">reconnect_timer</a></span> 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> </dd> <a name="transport_config"></a> <dt><strong><span class="code">{transport_config, term()}</span></strong></dt> <dt><strong><span class="code">{transport_config, term(), <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span>}</span></strong></dt> <dd> <p> A term passed as the third argument to the <span class="bold_code"><a href="diameter_transport.html#Mod:start-3">start/3</a></span> function of the relevant <span class="bold_code"><a href="diameter_transport.html">transport module</a></span> in order to start a transport process. Defaults to the empty list if unspecified.</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> <div class="example"><pre> {transport_module, diameter_sctp} {transport_config, SctpOpts, 5000} {transport_module, diameter_tcp} {transport_config, TcpOpts} </pre></div> <p> To listen on both SCTP and TCP, define one transport for each.</p> </dd> <a name="transport_module"></a> <dt><strong><span class="code">{transport_module, atom()}</span></strong></dt> <dd> <p> A module implementing a transport process as defined in <span class="bold_code"><a href="diameter_transport.html">diameter_transport(3)</a></span>. Defaults to <span class="code">diameter_tcp</span> if unspecified.</p> <p> Multiple <span class="code">transport_module</span> and <span class="bold_code"><a href="#transport_config">transport_config</a></span> options are allowed. The order of these is significant in this case (and only in this case), a <span class="code">transport_module</span> being paired with the first <span class="bold_code"><a href="#transport_config">transport_config</a></span> 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> </dd> <a name="watchdog_timer"></a> <dt><strong><span class="code">{watchdog_timer, TwInit}</span></strong></dt> <dd> <div class="example"><pre> TwInit = <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Unsigned32()</a></span> | {M,F,A} </pre></div> <p> The RFC 3539 watchdog timer. An integer value is interpreted as the RFC's TwInit in milliseconds, a jitter of ± 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 if unspecified.</p> </dd> </dl> <p> Unrecognized options are silently ignored but are returned unmodified by <span class="bold_code"><a href="#service_info-2">service_info/2</a></span> and can be referred to in predicate functions passed to <span class="bold_code"><a href="#remove_transport-2">remove_transport/2</a></span>.</p> <a name="transport_ref"></a> </dd> <dt><strong><span class="code">transport_ref() = reference()</span></strong></dt> <dd> <p> An reference returned by <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span> that identifies the configuration.</p> </dd> </dl> </div> <h3>EXPORTS</h3> <p><a name="add_transport-2"><span class="bold_code">add_transport(SvcName, {connect|listen, [Opt]}) -> {ok, Ref} | {error, Reason}</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Opt = <span class="bold_code"><a href="#transport_opt">transport_opt()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Ref = <span class="bold_code"><a href="#transport_ref">transport_ref()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = term()</span><br> </div> </div> <div class="REFBODY"><p> <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 (<span class="code">connect</span>) or by accepting incoming connection requests (<span class="code">listen</span>). 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 <span class="bold_code"><a href="diameter_app.html#Mod:peer_up-3">peer_up/3</a></span> 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> <div class="note"> <div class="label">Note</div> <div class="content"><p> <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> </p></div> </div> </p></div> <p><a name="call-4"><span class="bold_code">call(SvcName, App, Request, [Opt]) -> Answer | ok | {error, Reason}</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">App = <span class="bold_code"><a href="#application_alias">application_alias()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Request = <span class="bold_code"><a href="diameter_codec.html#message">diameter_codec:message()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Answer = term()</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Opt = <span class="bold_code"><a href="#call_opt">call_opt()</a></span></span><br> </div> </div> <div class="REFBODY"><p> <p> Send a Diameter request message.</p> <p> <span class="code">App</span> specifies the Diameter application in which the request is defined and callbacks to the corresponding callback module will follow as described below and in <span class="bold_code"><a href="diameter_app.html">diameter_app(3)</a></span>. Unless the <span class="code">detach</span> 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 <span class="bold_code"><a href="diameter_app.html#Mod:handle_answer-4">handle_answer/4</a></span> callback. In the error case, whether or not the error is returned directly by diameter or from a <span class="bold_code"><a href="diameter_app.html#Mod:handle_error-4">handle_error/4</a></span> 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 <span class="bold_code"><a href="diameter_app.html#Mod:pick_peer-4">pick_peer/4</a></span> rejects them by returning <span class="code">false</span>, then <span class="code">{error,no_connection}</span> is returned. Otherwise <span class="bold_code"><a href="diameter_app.html#Mod:pick_peer-4">pick_peer/4</a></span> is followed by a <span class="bold_code"><a href="diameter_app.html#Mod:prepare_request-3">prepare_request/3</a></span> 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 <span class="bold_code"><a href="diameter_app.html#Mod:handle_answer-4">handle_answer/4</a></span> callback:</p> <ul> <li> <p> If the initial encode of the outgoing request fails, then the request process fails and <span class="code">{error,encode}</span> is returned.</p> </li> <li> <p> If the request is successfully encoded and sent but the answer times out then a <span class="bold_code"><a href="diameter_app.html#Mod:handle_error-4">handle_error/4</a></span> callback takes place with <span class="code">Reason = timeout</span>.</p> </li> <li> <p> If the request is successfully encoded and sent but the service in question is stopped before an answer is received then a <span class="bold_code"><a href="diameter_app.html#Mod:handle_error-4">handle_error/4</a></span> callback takes place with <span class="code">Reason = cancel</span>.</p> </li> <li> <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 <span class="bold_code"><a href="diameter_app.html#Mod:pick_peer-4">pick_peer/4</a></span> callback rejects the candidates, then a <span class="bold_code"><a href="diameter_app.html#Mod:handle_error-4">handle_error/4</a></span> callback takes place with <span class="code">Reason = failover</span>. If a peer is selected then a <span class="bold_code"><a href="diameter_app.html#Mod:prepare_retransmit-3">prepare_retransmit/3</a></span> callback takes place, after which the semantics are the same as following an initial <span class="bold_code"><a href="diameter_app.html#Mod:prepare_request-3">prepare_request/3</a></span> callback.</p> </li> <li> <p> If an encode error takes place during retransmission then the request process fails and <span class="code">{error,failure}</span> is returned.</p> </li> <li> <p> If an application callback made in processing the request fails (pick_peer, prepare_request, prepare_retransmit, handle_answer or handle_error) then either <span class="code">{error,encode}</span> or <span class="code">{error,failure}</span> is returned depending on whether or not there has been an attempt to send the request over the transport.</p> </li> </ul> <p> Note that <span class="code">{error,encode}</span> is the only return value which guarantees that the request has <strong>not</strong> been sent over the transport connection.</p> </p></div> <p><a name="origin_state_id-0"><span class="bold_code">origin_state_id() -> Unsigned32()</span></a><br></p> <div class="REFBODY"><p> <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 <span class="code"><span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">Time()</a></span></span>, at the time the diameter application was started.</p> </p></div> <p><a name="remove_transport-2"><span class="bold_code">remove_transport(SvcName, Pred) -> ok | {error, Reason}</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Pred = Fun | MFA | <span class="bold_code"><a href="#transport_ref">transport_ref()</a></span> | list() | true | false</span><br> </div> <div class="REFTYPES"> <span class="bold_code"></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Fun = fun((<span class="bold_code"><a href="#transport_ref">transport_ref()</a></span>, connect|listen, list()) -> boolean())</span><br> </div> <div class="REFTYPES"> <span class="bold_code"> | fun((<span class="bold_code"><a href="#transport_ref">transport_ref()</a></span>, list()) -> boolean())</span><br> </div> <div class="REFTYPES"> <span class="bold_code"> | fun((list()) -> boolean())</span><br> </div> <div class="REFTYPES"> <span class="bold_code">MFA = {atom(), atom(), list()}</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = term()</span><br> </div> </div> <div class="REFBODY"><p> <p> Remove previously added transports.</p> <p> <span class="code">Pred</span> determines which transports to remove. An arity-3-valued <span class="code">Pred</span> removes all transports for which <span class="code">Pred(Ref, Type, Opts)</span> returns <span class="code">true</span>, where <span class="code">Type</span> and <span class="code">Opts</span> are as passed to <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span> and <span class="code">Ref</span> is as returned by it. The remaining forms are equivalent to an arity-3 fun as follows.</p> <div class="example"><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></div> <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 <span class="bold_code"><a href="#disconnect_cb">disconnect_cb</a></span> configured on the transport.</p> </p></div> <p><a name="service_info-2"><span class="bold_code">service_info(SvcName, Info) -> term()</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Info = Item | [Info]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Item = atom()</span><br> </div> </div> <div class="REFBODY"><p> <p> Return information about a started service. Requesting info for an unknown service causes <span class="code">undefined</span> to be returned. Requesting a list of items causes a tagged list to be returned.</p> <p> <span class="code">Item</span> can be one of the following.</p> <dl> <dt><strong><span class="code">'Origin-Host'</span></strong></dt> <dt><strong><span class="code">'Origin-Realm'</span></strong></dt> <dt><strong><span class="code">'Vendor-Id'</span></strong></dt> <dt><strong><span class="code">'Product-Name'</span></strong></dt> <dt><strong><span class="code">'Origin-State-Id'</span></strong></dt> <dt><strong><span class="code">'Host-IP-Address'</span></strong></dt> <dt><strong><span class="code">'Supported-Vendor'</span></strong></dt> <dt><strong><span class="code">'Auth-Application-Id'</span></strong></dt> <dt><strong><span class="code">'Inband-Security-Id'</span></strong></dt> <dt><strong><span class="code">'Acct-Application-Id'</span></strong></dt> <dt><strong><span class="code">'Vendor-Specific-Application-Id'</span></strong></dt> <dt><strong><span class="code">'Firmware-Revision'</span></strong></dt> <dd> <p> Return a capability value as configured with <span class="bold_code"><a href="#start_service-2">start_service/2</a></span>.</p> </dd> <dt><strong><span class="code">applications</span></strong></dt> <dd> <p> Return the list of applications as configured with <span class="bold_code"><a href="#start_service-2">start_service/2</a></span>. </p> </dd> <dt><strong><span class="code">capabilities</span></strong></dt> <dd> <p> Return a tagged list of all capabilities values as configured with <span class="bold_code"><a href="#start_service-2">start_service/2</a></span>.</p> </dd> <dt><strong><span class="code">transport</span></strong></dt> <dd> <p> Return a list containing one entry for each of the service's transport as configured with <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span>. 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> <div class="example"><pre> [[{ref,#Ref<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,{<0.66.0>,{1346,171491,996448},okay}}, {peer,{<0.67.0>,{1346,171491,999906}}}, {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,<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,257,0},recv},1}, {{{0,257,1},send},1}, {{{0,258,0},recv,{'Result-Code',2001}},3}, {{{0,280,1},recv},2}, {{{0,280,0},send},2}]}]] </pre></div> <p> Here <span class="code">ref</span> is a <span class="code"><span class="bold_code"><a href="#transport_ref">transport_ref()</a></span></span> and <span class="code">options</span> the corresponding <span class="code"><span class="bold_code"><a href="#transport_opt">transport_opt()</a></span></span> list passed to <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span>. The <span class="code">watchdog</span> entry shows the state of a connection's RFC 3539 watchdog state machine. The <span class="code">peer</span> entry identifies the <span class="code"><span class="bold_code"><a href="diameter_app.html#peer_ref">diameter_app:peer_ref()</a></span></span> for which there will have been <span class="bold_code"><a href="diameter_app.html#Mod:peer_up-3">peer_up/3</a></span> callbacks for the Diameter applications identified by the <span class="code">apps</span> entry, <span class="code">common</span> being the <span class="code"><span class="bold_code"><a href="#application_alias">application_alias()</a></span></span>. The <span class="code">caps</span> entry identifies the capabilities sent by the local node and received from the peer during capabilities exchange. The <span class="code">port</span> entry displays socket-level information about the transport connection. The <span class="code">statistics</span> entry presents Diameter-level counters, an entry like <span class="code">{{{0,280,1},recv},2}</span> saying that the client has received 2 DWR messages: <span class="code">{0,280,1} = {Application_Id, Command_Code, R_Flag}</span>.</p> <p> Note that <span class="code">watchdog</span>, <span class="code">peer</span>, <span class="code">apps</span>, <span class="code">caps</span> and <span class="code">port</span> entries depend on connectivity with the peer and may not be present. Note also that the <span class="code">statistics</span> entry presents values acuumulated 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 <span class="code"><span class="bold_code"><a href="#transport_ref">transport_ref()</a></span></span>. The <span class="code">transport</span> info returned by a server with a single client connection might look as follows.</p> <div class="example"><pre> [[{ref,#Ref<0.0.0.61>}, {type,listen}, {options,[{transport_module,diameter_tcp}, {transport_config,[{reuseaddr,true}, {ip,{127,0,0,1}}, {port,3868}]}]}, {accept,[[{watchdog,{<0.56.0>,{1346,171481,226895},okay}}, {peer,{<0.58.0>,{1346,171491,999511}}}, {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,<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,{<0.72.0>,{1346,171491,998404},initial}}]]}, {statistics,[{{{0,280,0},recv},7}, {{{0,280,1},send},7}, {{{0,258,0},send,{'Result-Code',2001}},3}, {{{0,258,1},recv},3}, {{{0,258,0},send},3}, {{{0,280,1},recv},5}, {{{0,280,0},send},5}, {{{0,257,1},recv},1}, {{{0,257,0},send},1}]}]] </pre></div> <p> The information presented here is as in the <span class="code">connect</span> case except that the client connections are grouped under an <span class="code">accept</span> tuple.</p> </dd> <dt><strong><span class="code">connections</span></strong></dt> <dd> <p> Return a list containing one entry for every established transport connection whose watchdog state machine is not in the <span class="code">down</span> state. This is a flat view of <span class="code">transport</span> 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> <div class="example"><pre> [[{ref,#Ref<0.0.0.61>}, {type,accept}, {options,[{transport_module,diameter_tcp}, {transport_config,[{reuseaddr,true}, {ip,{127,0,0,1}}, {port,3868}]}]}, {watchdog,{<0.56.0>,{1346,171481,226895},okay}}, {peer,{<0.58.0>,{1346,171491,999511}}}, {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,<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,258,0},send,{'Result-Code',2001}},3}, {{{0,258,1},recv},3}, {{{0,258,0},send},3}, {{{0,280,1},recv},66}, {{{0,280,0},send},66}, {{{0,257,1},recv},1}, {{{0,257,0},send},1}]}]] </pre></div> <p> Note that there may be multiple entries with the same <span class="code">ref</span>, in contrast to <span class="code">transport</span> info.</p> </dd> <dt><strong><span class="code">statistics</span></strong></dt> <dd> <p> Return a <span class="code">{{Counter, Ref}, non_neg_integer()}</span> list of counter values. <span class="code">Ref</span> can be either a <span class="code"><span class="bold_code"><a href="#transport_ref">transport_ref()</a></span></span> or a <span class="code"><span class="bold_code"><a href="diameter_app.html#peer_ref">diameter_app:peer_ref()</a></span></span>. Entries for the latter are folded into corresponding entries for the former as peer connections go down. Entries for both are removed at <span class="bold_code"><a href="#remove_transport-2">remove_transport/2</a></span>. The Diameter-level statistics returned by <span class="code">transport</span> and <span class="code">connections</span> info are based upon these entries.</p> </dd> <dt><strong><span class="code"><span class="bold_code"><a href="diameter_app.html#peer_ref">diameter_app:peer_ref()</a></span></span></strong></dt> <dd> <p> Return transport configuration associated with a single peer, as passed to <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span>. The returned list is empty if the peer is unknown. Otherwise it contains the <span class="code">ref</span>, <span class="code">type</span> and <span class="code">options</span> tuples as in <span class="code">transport</span> and <span class="code">connections</span> info above. For example:</p> <div class="example"><pre> [{ref,#Ref<0.0.0.61>}, {type,accept}, {options,[{transport_module,diameter_tcp}, {transport_config,[{reuseaddr,true}, {ip,{127,0,0,1}}, {port,3868}]}]}] </pre></div> </dd> </dl> </p></div> <p><a name="services-0"><span class="bold_code">services() -> [SvcName]</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> </div> <div class="REFBODY"><p> <p> Return the list of started services.</p> </p></div> <p><a name="session_id-1"><span class="bold_code">session_id(Ident) -> OctetString()</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">Ident = <span class="bold_code"><a href="diameter_dict.html#DATA_TYPES">DiameterIdentity()</a></span></span><br> </div> </div> <div class="REFBODY"><p> <p> Return a value for a Session-Id AVP.</p> <p> The value has the form required by section 8.8 of RFC 6733. Ident should be the Origin-Host of the peer from which the message containing the returned value will be sent.</p> </p></div> <p><a name="start-0"><span class="bold_code">start() -> ok | {error, Reason}</span></a><br></p> <div class="REFBODY"><p> <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 <span class="code">start/0</span> explicitly.</p> </p></div> <p><a name="start_service-2"><span class="bold_code">start_service(SvcName, Options) -> ok | {error, Reason}</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Options = [<span class="bold_code"><a href="#service_opt">service_opt()</a></span>]</span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = term()</span><br> </div> </div> <div class="REFBODY"><p> <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 <span class="bold_code"><a href="#add_transport-2">add_transport/2</a></span>. </p> <div class="note"> <div class="label">Note</div> <div class="content"><p> <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> </p></div> </div> </p></div> <p><a name="stop-0"><span class="bold_code">stop() -> ok | {error, Reason}</span></a><br></p> <div class="REFBODY"><p> <p> Stop the diameter application.</p> <p> </p> </p></div> <p><a name="stop_service-1"><span class="bold_code">stop_service(SvcName) -> ok | {error, Reason}</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> <div class="REFTYPES"> <span class="bold_code">Reason = term()</span><br> </div> </div> <div class="REFBODY"><p> <p> Stop a diameter service.</p> <p> Stopping a service causes all associated transport connections to be broken. A DPR message with be sent as in the case of <span class="bold_code"><a href="#remove_transport-2">remove_transport/2</a></span>.</p> <div class="note"> <div class="label">Note</div> <div class="content"><p> <p> Stopping a service does not remove any associated transports: <span class="bold_code"><a href="#remove_transport-2">remove_transport/2</a></span> must be called to remove transport configuration.</p> </p></div> </div> </p></div> <p><a name="subscribe-1"><span class="bold_code">subscribe(SvcName) -> true</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> </div> <div class="REFBODY"><p> <p> Subscribe to <span class="code"><span class="bold_code"><a href="#service_event">service_event()</a></span></span> 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 related events.</p> </p></div> <p><a name="unsubscribe-1"><span class="bold_code">unsubscribe(SvcName) -> true</span></a><br></p> <div class="REFBODY"> <p>Types:</p> <div class="REFTYPES"> <span class="bold_code">SvcName = <span class="bold_code"><a href="#service_name">service_name()</a></span></span><br> </div> </div> <div class="REFBODY"><p> <p> Unsubscribe to event messages from a service.</p> </p></div> <h3><a name="id73621">SEE ALSO</a></h3> <div class="REFBODY"> <p> <span class="bold_code"><a href="diameter_app.html">diameter_app(3)</a></span>, <span class="bold_code"><a href="diameter_transport.html">diameter_transport(3)</a></span>, <span class="bold_code"><a href="diameter_dict.html">diameter_dict(4)</a></span></p> </div> </div> <div class="footer"> <hr> <p>Copyright © 2011-2012 Ericsson AB. All Rights Reserved.</p> </div> </div> </div></body> </html>