<!-- Module User's Guide -->

<chapter>

	<title>&adminguide;</title>

	<section id="overview" xreflabel="Overview">
	<title>Overview</title>
	<para>
		The <emphasis role='bold'>proto_hep</emphasis> module is a
		transport module which implements hepV1 and hepV2 UDP-based communication
		and hepV3 TCP-based communication. It also offers an API with which
		you can register callbacks which are called after the HEP header is
		parsed and also can pack sip messages to HEP messages.The unpacking
		part is done internally.</para>
	</section>
	<para>
		Once loaded, you will be able to define HEP listeners in your
		configuration file by adding their IP and, optionally, a listening port.
		You can define both TCP, UDP, and TLS listeners. On UDP you will be able to
		receive HEP v1, v2 and v3 packets, on TCP and TLS only HEPv3.
	<para>
		<programlisting format="linespecific">
...
#HEPv3 listener
socket= hep_tcp:127.0.0.1:6061 		# change the listening IP
#HEPv1, v2, v3 listener
socket= hep_udp:127.0.0.1:6061 		# change the listening IP
...
</programlisting>
	</para>
	</para>

	<section id="dependencies" xreflabel="Dependencies">
	<title>Dependencies</title>
	<section>
		<title>&osips; Modules</title>
		<para>
		The following modules must be loaded before this module:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>tls_mgm</emphasis> - optional, only if a TLS based
				HEP listener is defined in the script.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>

	<section>
		<title>External Libraries or Applications</title>
		<para>
		The following libraries or applications must be installed before
		running &osips; with this module loaded:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>None</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	</section>

	<section id="exported_parameters" xreflabel="Exported Parameters">
	<title>Exported Parameters</title>


	<section id="param_hep_id" xreflabel="hep_id">
		<title><varname>hep_id</varname> (str)</title>
		<para>
			Specify a destination for HEP packets and the version of
			HEP protocol used. All parameters inside
			<emphasis role="bold">hep_id</emphasis> must be separated by
			<emphasis role="bold">;</emphasis>. The parameters
			are given in key-value format, the possible keys being
			<emphasis role="bold">uri</emphasis>, <emphasis role="bold">transport</emphasis>
			and <emphasis role="bold">version</emphasis>, except destiantion's
			URI which doesn't have a key and is in <emphasis role="bold">host:port
			</emphasis>. <emphasis role="bold">transport</emphasis> key can be
			<emphasis role="bold">TCP</emphasis>, <emphasis role="bold">UDP</emphasis> or
			<emphasis role="bold">TLS</emphasis>.
			<emphasis role="bold">TCP</emphasis> and <emphasis role="bold">TLS</emphasis>
			works only for HEP version 3.
			<emphasis role="bold">Version</emphasis> is the hep protocol version
			and can be <emphasis role="bold">1</emphasis>, <emphasis role="bold">2</emphasis>
			or <emphasis role="bold">3</emphasis>.
		</para>
		<para>
			HEPv1 and HEPv2 can use only UDP. HEPv3 can use TCP, UDP and TLS having the
			default set to TCP. If no hep version defined, the default is version 3 with
			TCP and TLS.
		</para>
		<para>
			NO default value. If <emphasis role="bold">hep_id</emphasis> the module
		can't be used for HEP tracing.
		</para>
		<example>
		<title> Set <varname>hep_id</varname> parameter</title>
		<programlisting format="linespecific">
...
/* define a destination to localhost on port 8001 using hepV3 on tcp */
modparam("proto_hep", "hep_id",
"[hep_dst] 127.0.0.1:8001; transport=tcp; version=3")
/* define a destination to 1.2.3.4 on port 5000 using hepV2; no transport(default UDP) */
modparam("proto_hep", "hep_id", "[hep_dst] 1.2.3.4:5000; version=2")
/* define only the destination uri; version will be 3(default) and transport TCP(default) */
modparam("proto_hep", "hep_id", "[hep_dst] 1.2.3.4:5000")
</programlisting>
	</example>
	</section>

	<section id="param_homer5_on" xreflabel="homer5_on">
		<title><varname>homer5_on</varname> (int) </title>
		<para>
			Specify how the data should be encapsulated in the HEP packet. If set to
			<emphasis>0</emphasis>, then the JSON based HOMER 6 format will be used. Otherwise,
			if set to anything different than <emphasis>0</emphasis>, the plain text HOMER 5
			format will be used for encapsulation. On the capturing node, this parameter
			affects the behavior of the <emphasis>report_capture</emphasis> function from the
			<ulink url="sipcapture#func_report_capture">sipcapture</ulink>
			module.
		</para>
		<para>
			Default value 1, HOMER5 format.
		</para>
		<example>
		<title> Set <varname>homer5_on</varname> parameter</title>
		<programlisting format="linespecific">
modparam("proto_hep", "homer5_on", 0)
</programlisting>
	</example>
	</section>

	<section id="param_homer5_delim" xreflabel="homer5_delim">
		<title><varname>homer5_delim</varname> (str) </title>
		<para>
			In case <emphasis role="bold">homer5_on</emphasis> is set
		(different than 0), with this parameter you will be able to set
		the delmiter between different payload parts.
		</para>
		<para>
			Default value ":".
		</para>
		<example>
		<title> Set <varname>homer5_on</varname> parameter</title>
		<programlisting format="linespecific">
modparam("proto_hep", "homer5_delim", "##")
</programlisting>
	</example>
	</section>

	<section id="param_hep_port" xreflabel="hep_port">
		<title><varname>hep_port</varname> (integer)</title>
		<para>
			The default port to be used by all TCP/UDP/TLS listeners.
		</para>
		<para>
		<emphasis>
			Default value is 5656.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hep_port</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "hep_port", 6666)
...
</programlisting>
		</example>
	</section>

	<section id="param_hep_send_timeout" xreflabel="hep_send_timeout">
		<title><varname>hep_send_timeout</varname> (integer)</title>
		<para>
		Time in milliseconds after a TCP connection will be closed if it is
		not available for blocking writing in this interval (and &osips; wants
		to send something on it).
		</para>
		<para>
		<emphasis>
			Default value is 100 ms.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hep_send_timeout</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "hep_send_timeout", 200)
...
</programlisting>
		</example>
	</section>
	<section id="param_hep_max_msg_chunks" xreflabel="hep_max_msg_chunks">
		<title><varname>hep_max_msg_chunks</varname> (integer)</title>
		<para>
			The maximum number of chunks in which a HEP message is expected to
			arrive via TCP. If a received packet is more fragmented than this,
			the connection is dropped (either the connection is very
			overloaded and this leads to high fragmentation - or we are the
			victim of an ongoing attack where the attacker is sending very
			fragmented traffic in order to decrease server performance).
		</para>
		<para>
		<emphasis>
			Default value is 32.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hep_max_msg_chunks</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "hep_max_msg_chunks", 8)
...
</programlisting>
		</example>
	</section>
	<section id="param_hep_async" xreflabel="hep_async">
		<title><varname>hep_async</varname> (integer)</title>
		<para>
			Specifies whether the TCP connect and write operations should be
			done in an asynchronous mode (non-blocking connect and
			write) or not. If disabled, OpenSIPS will block and wait for TCP
			operations like connect and write.
		</para>
		<para>
		<emphasis>
			Default value is 1 (enabled).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hep_async</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "hep_async", 0)
...
</programlisting>
		</example>
	</section>
	<section id="param_hep_async_max_postponed_chunks" xreflabel="hep_async_max_postponed_chunks">
		<title><varname>hep_async_max_postponed_chunks</varname> (integer)</title>
		<para>
			If <emphasis>hep_async</emphasis> is enabled, this specifies the
			maximum number of HEP messages that can be stashed for later/async
			writing. If the connection pending writes exceed this number, the
			connection will be marked as broken and dropped.
		</para>
		<para>
		<emphasis>
			Default value is 32.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hep_async_max_postponed_chunks</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "hep_async_max_postponed_chunks", 16)
...
</programlisting>
		</example>
	</section>

	<section id="param_hep_capture_id" xreflabel="hep_capture_id">
		<title><varname>hep_capture_id</varname> (integer)</title>
		<para>
			The parameter indicate the capture agent ID for HEPv2/v3 protocol.
		Limitation: 16-bit integer.
		</para>
		<para>
		<emphasis>
		Default value is "1".
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hep_capture_id</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "hep_capture_id", 234)
...
</programlisting>
		</example>
	</section>

	<section id="param_hep_async_local_connect_timeout" xreflabel="hep_async_local_connect_timeout">
		<title><varname>hep_async_local_connect_timeout</varname> (integer)</title>
		<para>
			If <emphasis>hep_async</emphasis> is enabled, this specifies the
			number of milliseconds that a connect will be tried in blocking
			mode (optimization). If the connect operation lasts more than
			this, the connect will go to async mode and will be passed to TCP
			MAIN for polling.
		</para>
		<para>
		<emphasis>
			Default value is 100 ms.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hep_async_local_connect_timeout</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "hep_async_local_connect_timeout", 200)
...
</programlisting>
		</example>
	</section>
	<section id="param_hep_async_local_write_timeout" xreflabel="hep_async_local_write_timeout">
		<title><varname>hep_async_local_write_timeout</varname> (integer)</title>
		<para>
			If <emphasis>hep_async</emphasis> is enabled, this specifies the
			number of milliseconds that a write op will be tried in blocking
			mode (optimization). If the write operation lasts more than this,
			the write will go to async mode and will be passed to bin MAIN for
			polling.
		</para>
		<para>
		<emphasis>
			Default value is 10 ms.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>hep_async_local_write_timeout</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_hep", "hep_async_local_write_timeout", 100)
...
</programlisting>
		</example>
	</section>

	</section>

	<section id="exported_functions" xreflabel="exported_functions">
	<title>Exported Functions</title>
	<section id="func_correlate" xreflabel="correlate()">
		<title>
		<function moreinfo="none">correlate(hep_id, type1, correlation1, type2, correlation2)</function>
		</title>
		<para>
			Send a hep message with an extra correlation id containing the two correlation given
			as arguments. The two types must differ. This will help
			on the capturing side to correlate two calls for example, being given their callid
			as correlation ids.
		</para>
		<para>
		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE, LOCAL_ROUTE.
		</para>
		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>hep_id (string)</emphasis>
				the name of the <emphasis>hep_id</emphasis> defined in modparam section,
				specifying where to do the tracing.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>type1 (string)</emphasis>
				the key name identify the first correlation id.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>correlation1 (string)</emphasis>
				the first extra correlation id that will be put in the extra correlation chunk.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>type2 (string)</emphasis>
				the key name identify the second correlation id.
			</para>
		</listitem>
		<listitem>
			<para><emphasis>correlation2 (string)</emphasis>
				the second extra correlation id that will be put in the extra correlation chunk.
			</para>
		</listitem>

		</itemizedlist>
		<example>
		<title><function>correlate</function> usage</title>
		<programlisting format="linespecific">
...
/* see declaration of hep_dst in trace_id section */
/* we suppose we have two correlations in two varibles: cor1 and cor2 */
	correlate("hep_dst", "correlation-no-1",$var(cor1),"correlation-no-2", $var(cor2));
...
</programlisting>
		</example>
	</section>
	</section>



</chapter>
