Brekeke SIP Server Session Plug-in Developer's Guide for Accounting (C) 2002-2018, Brekeke Software, Inc. All rights reserved. Date: January 12, 2018 This Document explains how to create a Session plug-in for accounting purposes. Supported version: OnDO SIP Server 1.4.0.1 and later Brekeke SIP Server 2.0 and later 1. HOW TO CREATE A PLUG-IN Extend the class AccountingBase for making your own accounting plug-in. This class is in the package com.brekeke.net.sip.sv.session.plug-ins. It is an empty class that extends the class InviteSession. The class hierarchy is as follows: SIPex // Thread class for each session | +--- SessionPlugin // Base class for Session Plug-in | +--- InviteSession // Session Plug-in for INVITE | +--- AccountingBase // Base class for Accounting Session Plug-in | +--- Your Class for making your own accounting plug-in Please import the following: import com.brekeke.net.sip.sv.session.* ; import com.brekeke.net.sip.sv.session.plugins.* ; For building your program, please include \webapps\sip\WEB-INF\lib\ondosip.jar in the classpath. 2. EVENT METHOD Event methods are called at the beginning of a session, when talking starts, when talking stops, and at the end of a session. Please use these methods if necessary. 1) eventSessionStart public int eventSessionStart( EventStat evstat, String[] argprm ) An event method which is called at the beginning of a session, i.e. when Brekeke SIP Server receives INVITE. argprm includes parameters which are specified in the Dial Plan. Parameters: EventStat evstat - Status String[] argprm - Parameters Return: The value 0 to accept this session Error code (A response code which is greater than or equal to 400) to reject this session If an error code is returned, the response packet is sent to the caller and the session will not start. 2) eventTalkStart public void eventTalkStart( EventStat evstat ) An event method which is called when talking starts, i.e. when Brekeke SIP Server receives 2xx response. Parameters: EventStat evstat - Status 3) eventTalkEnd public void eventTalkEnd( EventStat evstat ) An event method which is called when talking ends, i.e. when Brekeke SIP Server receives BYE. Parameters: EventStat evstat - Status 4) eventSessionEnd public void eventSessionEnd( EventStat evstat ) An event method which is called at the end of a session, i.e. when Brekeke SIP Server receives 2xx response for BYE after talking or when releasing all related resources such as RTP after receiving an error response for INVITE. 5) eventTimerup public void eventTimerup( EventStat evstat, long id ) An event method which is called at a scheduled time. A Timer can be set using setSchedule(). Parameters: EventStat evstat - Status long id - timer ID 3. SIP-METHOD PROCEDURE SIP-METHOD PROCEDURE is a method which is called when Brekeke SIP Server receives a specified SIP-method. Please implement only when necessary. You can specify any SIP method. But you do not need it for accounting in most cases. For example, to use a procedure for INFO method, you will use an interface as follows. public void procINFO( ClientStat cs, SIPpacket sippacket, boolean bRequest ) This method is called when Brekeke SIP Server receives an INFO request or a response for INFO. Parameters: ClientStat cs - Packet sender's client status SIPpacket sippacket - Corresponding SIP packet boolean bRequest - If true, this is request. If false, this is response. You can use other SIP Methods in the same way. For example, for unknown SIP-Method "TESTTEST", you can use the following interface. public void procTESTTEST( ClientStat cs, SIPpacket sippacket, boolean bRequest ) 4. CONTROL METHOD You can call CONTROL METHODS from your plug-in. 1) doTerminate public void doTerminate() This method terminates a session safely and sends BYE/CANCEL or some response (depending on the session status) to UAs. 2) setSchedule public void setSchedule( long id, long secdelay ) This method calls eventTimerup() at a scheduled time. Parameters: long id - timer ID long secdelay - Timer, i.e. delay in seconds before the method is called 3) setScheduleTerminate public void setScheduleTerminate( long secdelay ) This method terminates a session safely at a scheduled time Parameter: long secdelay - Timer, i.e. delay in seconds before terminating a session 4) getTalkLength public long getTalkLength() This method returns Talk length. Returns: Talk length (msec) 5. EventStat - EVENT STATUS EventStat object which is passed by Event Methods contains the following variables: int sid // Session-ID String callid // Call-ID: String username // Caller's user name String usernameAuth // Caller's user name for authentication String urlCaller // Caller's SIP-URI String tagCaller // Caller's tag parameter AddrPort apCaller // Caller's IP address/port String urlCallee // Call recipient's SIP-URI String tagCallee // Call recipient's SIP-URI AddrPort apCallee // Call recipient's IP address/port String methodStart // SIP method for the start of the session long seqStart // CSeq number of the SIP method for the start of the session String methodEnd // SIP method for the end of the session long seqEnd // CSeq number of the SIP method for the end of the session int senderEnd // Sender of the SIP method for the end of the session // (1=Caller, 2=Call recipient) long timeSessionStart // Session start time long timeSessionEnd // Session end time long timeTalkStart // Talk start time long timeTalkEnd // Talk end time int result // Result // 0 = Success // 1 = BUSY // 2 = CANCEL // 3 = Fail // 4 = Timeout // 5 = Disconnect by Brekeke SIP Server (for Shutdown, etc.) // 6 = Other int errorcode // Error code (SIP response codej 6. HOW TO INSTALL THE PLUG-IN 1) After the compilation is done, please place your class file into \webapps\sip\WEB-INF\classes or create a jar file and place it into \webapps\sip\WEB-INF\lib 2)Please specify your plug-in using $session variable in Deploy Patterns. For example, if you use a plug-in called CDRSample, please write a rule as follows: ============================= Matching Patterns: $request = ^INVITE Deploy Patterns: $session = CDRsample $continue = true ============================= In this case, Brekeke SIP Server searches the CDRSample class in the package which is specified by a property net.sip.session.plugins.pkg. If no class can be found, Brekeke SIP Server searches the CDRSample class within the package com.brekeke.net.sip.sv.session.plugins. You can specify your plug-in class including the package name in Dial Plan. Example: $session = com.test.CDRSample If you need to pass arguments to the plug-in, you can specify as follows. $session = CDRSample arg1 arg2 These arguments are passed to the method eventSessionStart() (please refer to 2. (1) above).