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

<chapter>
	
	<title>&adminguide;</title>
	
	<section id="overview" xreflabel="Overview">
		<title>Overview</title>

		<para>The sst module provides a way to update the
		dialog expire timer based on the SIP INVITE/200 OK
		Session-Expires header value. You can use the sst
		module in an OpenSIPS proxy to allow freeing of local
		resources of dead (expired) calls.</para>

		<para>You can also use the sst module to validate the
		MIN_SE header value and reply to any request with a
		"422 - Session Timer Too Small" if the value is too
		small for your OpenSIPS configuration.</para>

	</section>
	
	<section>
	<title>How it works</title>
	
	<para>The sst module uses the dialog module to be notified of
	any new or updated dialogs. It will then look for and extract
	the session-expire: header value (if there is one) and
	override the dialog expire timer value for the current context
	dialog.</para>

	<para>You flag any call setup INVITE that you want to cause a
	timed session to be established. This will cause OpenSIPS to
	request the use of session times if the UAC does not request
	it.</para>

	<para>All of this happens with a properly configured dialog
	and sst module and setting the dialog flag and the sst flag at
	the time any INVITE sip message is seen. There is no
	opensips.cfg script function call required to set the dialog
	expire timeout value. See the dialog module users guide for
	more information.</para>

	<para>The sstCheckMin() script function can be used to varify
	the Session-expires / MIN-SE header field values are not too
	small for a proxy. If the SST min_se parameter value is
	smaller then the messages Session-Expires / MIN-SE values, the
	test will return true. You can also configure the function to
	send the 422 response for you.</para>

	<para>The following was taken from the RFC as a call flow
	example:</para>

	<example>
	<title>Session timer call flow</title>
	<programlisting format="linespecific">
+-------+    +-------+       +-------+
| UAC-1 |    | PROXY |       | UAC-2 |
+-------+    +-------+       +-------+
    |(1) INVITE  |               |
    |SE: 50      |               |
    |-----------&gt;|               |
    |            |(2)sstCheckMin |
    |            |-----+         |
    |            |     |         |
    |            |&lt;----+         |
    |(3) 422     |               |
    |MSE:1800    |               |
    |&lt;-----------|               |
    |            |               |
    |(4)ACK      |               |
    |-----------&gt;|               |
    |            |               |
    |(5) INVITE  |               |
    |SE: 1800    |               |
    |MSE: 1800   |               |
    |-----------&gt;|               |
    |            |(6)sstCheckMin |
    |            |-----+         |
    |            |     |         |
    |            |&lt;----+         |
    |            |(7)setflag     |
    |            |create dialog  |
    |            |Set expire     |
    |            |-----+         |
    |            |     |         |
    |            |&lt;----+         |
    |            |               |
    |            |(8)INVITE      |
    |            |SE: 1800       |
    |            |MSE: 1800      |
    |            |--------------&gt;|
    |            |               |
 ...
     			</programlisting>
		</example>

	</section>

	<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>dialog</emphasis> - dialog module and its decencies. (tm)
		</para>
		</listitem>
		<listitem>
		<para>
			<emphasis>sl</emphasis> - stateless module.
		</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_enable_stats" xreflabel="enable_stats">
		<title><varname>enable_stats</varname> (integer)</title>

		<para>If the statistics support should be enabled or
		not. Via statistic variables, the module provide
		information about the dialog processing. Set it to zero to
		disable or to non-zero to enable it.</para>

		<para>
		<emphasis>
			Default value is <quote>1</quote> (enabled).
		</emphasis>
		</para>

		<example>
		<title>Set <varname>enable_stats</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("sst", "enable_stats", 0)
...
</programlisting>
		</example>
	</section>

	<section id="param_min_se" xreflabel="min_se">
		<title><varname>min_se</varname> (integer)</title>

		<para>The value is used to set the proxies MIN-SE
		value and is used in the 422 reply as the proxies
		MIN-SE: header value if the sstCheckMin() flag is set
		to true and the check fails.</para>

		<para>If not set and sstCheckMin() is called with the
		send-reply flag set to true, the default 1800 seconds
		will be used as the compare and the MIN-SE: header
		value if the 422 reply is sent.</para>

		<para>
		<emphasis>
			Default value is <quote>1800</quote> seconds.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>min_se</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("sst", "min_se", 2400)
...
</programlisting>
		</example>
	</section>

	<section id="param_sst_interval" xreflabel="sst_interval">
		<title><varname>sst_interval</varname> (integer)</title>

		<para>The sst minimum interval in Session-Expires header if OpenSIPS
		request the use of session times. The used value will be the
		maximum value between OpenSIPS minSE, UAS minSE and this value.</para>

		<para>Per default the interval used will be the min_se value</para>

		<para>
		<emphasis>
			Default value is <quote>0</quote> seconds.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>sst_interval</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("sst", "sst_interval", 2400)
...
</programlisting>
		</example>
	</section>

	<section id="param_reject_to_small" xreflabel="reject_to_small">
		<title><varname>reject_to_small</varname> (integer)</title>

		<para>In the initial INVITE if the UAC has requested a
		Session-Expire: and it's value is smaller then our
		local policies Min-SE (see min_se above), then the
		PROXY has the right to reject the call by replying to
		the message with a 422 Session Timer Too Small and
		state our local Min-SE: value. The INVITE is NOT
		forwarded on through the PROXY.</para>

		<para>This flag if true will tell the SST module to
		reject the INVITE with a 422 response. If false, the
		INVITE is forwarded through the PROXY with out any
		modifications.</para>

		<para>
		<emphasis>
			Default value is <quote>1</quote> (true/on).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>reject_to_small</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("sst", "reject_to_small", 0)
...
</programlisting>
		</example>
	</section>
<section id="param_sst_flag" xreflabel="sst_flag">
		<title><varname>sst_flag</varname> (string)</title>
		
		<para>Keeping with OpenSIPS, the module will not do
		anything to any message unless instructed to do so via
		the opensips.cfg script. You must set the sst_flag
		value in the setflag() call of the INVITE you want the
		sst module to process. But before you can do that, you
		need to tell the sst module which flag value you are
		assigning to sst.</para>

		<para>In most cases when ever you create a new dialog
		via create_dialog() function,you will want to set the sst flag. 
		If create_dialog() is not called and the sst flag is set, 
		it will not have any effect.</para>

		<para>This parameter must be set of the module will
		not load.</para>

		<para>
		<emphasis>
			Default value is <quote>Not set!</quote>.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>sst_flag</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("sst", "sst_flag", "SST_FLAG")
...
route {
  ...
  if ($rm=="INVITE") {
    setflag(SST_FLAG); # Set the sst flag
    create_dialog(); # and then create the dialog
  }
  ...
}
</programlisting>
		</example>
	</section>

	</section>
	<section id="exported_functions" xreflabel="exported_functions">
	<title>Exported Functions</title>
	<section id="func_sstCheckMin" xreflabel="sstCheckMin()">
		<title>
		<function moreinfo="none">sstCheckMin(send_reply_flag)</function>
		</title>

		<para>Check the current Session-Expires / MIN-SE values
		against the sst_min_se parameter value. If the
		Session-Expires or MIN_SE header value is less then
		modules minimum value, this function will return
		true. </para>

		<para>If the fuction is called with the
		send_reply_flag set to true (1) and the requested
		Session-Expires / MIN-SE values are too small, a 422
		reply will be sent for you. The 422 will carry a
		MIN-SE: header with the sst min_se parameter value
		set.</para>

		<para>Meaning of the parameters is as follows:</para>
		<itemizedlist>
		<listitem>
			<para><emphasis>min_allowed</emphasis> (int, optional) - The value
			to compare the MIN_SE header value to.</para>
		</listitem>
		</itemizedlist>
		<example>
		<title><function>sstCheckMin</function> usage</title>
		<programlisting format="linespecific">

...
modparam("sst", "sst_flag", "SST_FLAG")
modparam("sst", "min_se", 2400) # Must be >= 90
...

route {
  if ($rm=="INVITE") {
	if (sstCheckMin(1)) {
		xlog("L_ERR", "422 Session Timer Too Small reply sent.\n");
		exit;
	}
	# track the session timers via the dialog module
	setflag(SST_FLAG);
	create_dialog();
  }
}

...
</programlisting>
		</example>
	</section>
	</section>


	<section id="exported_statistics">
	<title>Exported Statistics</title>
	<section id="stat_expired_sst" xreflabel="expired_sst">
		<title><varname>expired_sst</varname></title>
		<para>
		Number of dialogs which got expired session timer.
		</para>
	</section>
	</section>

</chapter>

