# HG changeset patch # User Sebastien Decugis # Date 1272271313 -32400 # Node ID a26655da5c14ba0490f2f17b674953d85780200c # Parent 50bfb29bf036cd2f50017a0dc2f53a28f86b2272 Added a dummy accounting server for tests diff -r 50bfb29bf036 -r a26655da5c14 extensions/CMakeLists.txt --- a/extensions/CMakeLists.txt Fri Apr 23 17:22:09 2010 +0900 +++ b/extensions/CMakeLists.txt Mon Apr 26 17:41:53 2010 +0900 @@ -86,6 +86,11 @@ SUBDIRS(dbg_rt) ENDIF (BUILD_DBG_RT) +OPTION(BUILD_TEST_ACCT "Build test_acct.fdx? (Receive Accounting-Requests and display the data, but no storage)" OFF) + IF (BUILD_TEST_ACCT) + SUBDIRS(test_acct) + ENDIF (BUILD_TEST_ACCT) + OPTION(BUILD_TEST_APP "Build test_app.fdx? (Testing application to send dummy message to another peer, for testing purpose only)" OFF) IF (BUILD_TEST_APP) SUBDIRS(test_app) diff -r 50bfb29bf036 -r a26655da5c14 extensions/test_acct/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/test_acct/CMakeLists.txt Mon Apr 26 17:41:53 2010 +0900 @@ -0,0 +1,4 @@ +# The test_acct extension +PROJECT("Accounting dummy server" C) + +FD_ADD_EXTENSION(test_acct test_acct.c) diff -r 50bfb29bf036 -r a26655da5c14 extensions/test_acct/test_acct.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/test_acct/test_acct.c Mon Apr 26 17:41:53 2010 +0900 @@ -0,0 +1,133 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Sebastien Decugis * +* * +* Copyright (c) 2010, WIDE Project and NICT * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the WIDE Project or NICT nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of WIDE Project and * +* NICT. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ + +/* This extension simply receives ACR and sends positive ACA after displaying the content, +but does not commit the data to any storage */ + +#include + +static struct { + struct dict_object * Accounting_Record_Number; + struct dict_object * Accounting_Record_Type; +} tac_dict; + +/* Callback for incoming Base Accounting application messages */ +static int tac_cb( struct msg ** msg, struct avp * avp, struct session * sess, enum disp_action * act) +{ + struct msg_hdr *hdr = NULL; + + TRACE_ENTRY("%p %p %p %p", msg, avp, sess, act); + + if (msg == NULL) + return EINVAL; + + fd_log_debug("--------------Received the following Accounting message:--------------\n"); + fd_msg_dump_walk(NONE, *msg); + fd_log_debug("----------------------------------------------------------------------\n"); + + /* Now check what we received */ + CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); + + if (hdr->msg_flags & CMD_FLAG_REQUEST) { + /* It was a request, create an answer */ + struct msg *ans, *qry; + + qry = *msg; + /* Create the answer message, including the Session-Id AVP */ + CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, msg, 0 ) ); + ans = *msg; + + /* Set the Origin-Host, Origin-Realm, Result-Code AVPs */ + CHECK_FCT( fd_msg_rescode_set( ans, "DIAMETER_SUCCESS", NULL, NULL, 1 ) ); + + /* Search for Accounting required AVPs */ + { + struct avp * a = NULL; + struct avp_hdr * h = NULL; + + CHECK_FCT( fd_msg_search_avp ( qry, tac_dict.Accounting_Record_Number, &a) ); + if (a) { + CHECK_FCT( fd_msg_avp_hdr( a, &h ) ); + CHECK_FCT( fd_msg_avp_new ( tac_dict.Accounting_Record_Number, 0, &a ) ); + CHECK_FCT( fd_msg_avp_setvalue( a, h->avp_value ) ); + CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, a ) ); + } + + CHECK_FCT( fd_msg_search_avp ( qry, tac_dict.Accounting_Record_Type, &a) ); + if (a) { + CHECK_FCT( fd_msg_avp_hdr( a, &h ) ); + CHECK_FCT( fd_msg_avp_new ( tac_dict.Accounting_Record_Type, 0, &a ) ); + CHECK_FCT( fd_msg_avp_setvalue( a, h->avp_value ) ); + CHECK_FCT( fd_msg_avp_add( ans, MSG_BRW_LAST_CHILD, a ) ); + } + } + + /* Send the answer */ + CHECK_FCT( fd_msg_send( msg, NULL, NULL ) ); + + } else { + /* We received an answer message, just discard it */ + CHECK_FCT( fd_msg_free( *msg ) ); + *msg = NULL; + } + + return 0; +} + +/* entry point: register handler for Base Accounting messages in the daemon */ +static int tac_entry(char * conffile) +{ + struct disp_when data; + + TRACE_ENTRY("%p", conffile); + + memset(&tac_dict, 0, sizeof(tac_dict)); + memset(&data, 0, sizeof(data)); + + /* Initialize the dictionary objects we use */ + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_NAME, "Diameter Base Accounting", &data.app, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Accounting-Record-Number", &tac_dict.Accounting_Record_Number, ENOENT) ); + CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, "Accounting-Record-Type", &tac_dict.Accounting_Record_Type, ENOENT) ); + + /* Register the dispatch callback */ + CHECK_FCT( fd_disp_register( tac_cb, DISP_HOW_APPID, &data, NULL ) ); + + /* Advertise the support for the Diameter Base Accounting application in the peer */ + CHECK_FCT( fd_disp_app_support ( data.app, NULL, 0, 1 ) ); + + return 0; +} + +EXTENSION_ENTRY("test_acct", tac_entry);