Navigation


Changeset 627:330be61dbf43 in freeDiameter for doc


Ignore:
Timestamp:
Dec 14, 2010 11:53:24 AM (2 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Message:

Improvements to usability, still work ongoing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/dbg_interactive.py.sample

    r624 r627  
    66# The adaptation layer between Python and C is provided by SWIG (http://swig.org).  
    77# You may refer to SWIG documentation for more information on how the wrapper is generated and used. 
    8 # Please note that the high-level wrapper file (python file) is not used in dbg_interactive at the moment, 
    9 # but all symbols from the module are imported. 
     8# The name of the module wrapping freeDiameter framework is: _fDpy 
    109# 
    1110# Similar to all freeDiameter extensions, an optional filename can be specified in the 
     
    1413# to execute. Otherwise, the interpreter will be interactive. 
    1514# 
    16 # Bellow are some example use of the python interpreter: 
    17  
    18  
    19 # Display current version 
    20 print FD_PROJECT_NAME, FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, FD_PROJECT_VERSION_REV 
    21  
    22  
    23 # Change the global debug level of the framework (cvar contains all global variables) 
    24 cvar.fd_g_debug_lvl = FULL 
    25  
    26  
    27 # Turn on debug for a specific function 
    28 cvar.fd_debug_one_function = "gc_th_fct" 
    29  
    30  
    31 # Print messages to freeDiameter's debug facility 
    32 fd_log_debug("3 + 4 = %d\n" % (7)) 
    33 # See SWIG documentation about varargs functions for more information 
    34  
    35  
    3615# SWIG deals with structures as follow: 
    37 # Take the structure: 
     16# Given the structure: 
    3817# struct foo { int a; } 
    39 # The following functions are available to python: 
    40 # s = new_foo()    --> s = calloc(1, sizeof(struct foo)) 
    41 # foo_a_set(s, 2)  --> s->a = 2 
    42 # foo_a_get(s)     --> returns s->a value 
    43 # delete_foo(s)    --> free(s) 
    44 # 
    45 # In addition, thanks to proxy (aka shadow) class, we can also do: 
     18# The following functions are available to python (their C equivalent processing is given in [ ]): 
     19# s = new_foo()    [ s = calloc(1, sizeof(struct foo)) ] 
     20# foo_a_set(s, 2)  [ s->a = 2 ] 
     21# foo_a_get(s)     [ returns s->a value ] 
     22# delete_foo(s)    [ free(s)  ] 
     23# 
     24# In addition, thanks to the proxy (aka shadow) class, we can also do the more user-friendly: 
    4625# s = foo() 
    4726# s.a = 2 
    4827# s.a 
    4928# del s 
    50  
     29# 
     30 
     31# The remaining of this file gives some examples of how to use the python interpreter. 
     32# Note that the support is not yet totally usable. You'll probably have to extend some classes 
     33# or write some typemaps in the source code of the extension to do what you want. 
     34 
     35 
     36############# Compilation-time constants (from freeDiameter-host.h) ############ 
     37 
     38# Display current version 
     39print "%s %d.%d.%d" % (FD_PROJECT_NAME, FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, FD_PROJECT_VERSION_REV) 
     40 
     41 
     42############# Debug ############ 
     43 
     44# Change the global debug level of the framework (cvar contains all global variables) 
     45cvar.fd_g_debug_lvl = FULL 
     46 
     47 
     48# Turn on debug for a specific function (if framework compiled with DEBUG support) 
     49cvar.fd_debug_one_function = "gc_th_fct" 
     50 
     51 
     52# Print messages to freeDiameter's debug facility 
     53# Note: the python version does not support printf-like argument list. The formating should be done in python. 
     54#       See SWIG documentation about varargs functions for more information. 
     55fd_log_debug("3 + 4 = %d\n" % (7)) 
     56 
     57 
     58# Display some framework state information 
     59r = fd_event_send(cvar.fd_g_config.cnf_main_ev, FDEV_DUMP_PEERS, 0, None) 
     60r = fd_event_send(cvar.fd_g_config.cnf_main_ev, FDEV_DUMP_SERV, 0, None) 
     61r = fd_event_send(cvar.fd_g_config.cnf_main_ev, FDEV_DUMP_EXT, 0, None) 
     62 
     63 
     64############# Global variables ############ 
    5165 
    5266# Display the local Diameter Identity: 
    53 print "Local Diameter Identity:", fd_config_cnf_diamid_get(cvar.fd_g_config) 
    54 print "Realm:", fd_config_cnf_diamrlm_get(cvar.fd_g_config) 
    55  
    56  
    57 # Display some states information 
    58 evl = fd_config_cnf_main_ev_get(cvar.fd_g_config) 
    59 r = fd_event_send(evl, FDEV_DUMP_PEERS, 0, None) 
    60 r = fd_event_send(evl, FDEV_DUMP_SERV, 0, None) 
    61 r = fd_event_send(evl, FDEV_DUMP_EXT, 0, None) 
    62  
    63  
    64 # Create a new peer_info structure and add the peer to the framework. 
    65 mypeer = new_peer_info() 
    66 peer_info_pi_diamid_set( mypeer, "nas.testbed.aaa" ) 
    67 myconfig = peer_info_config_get(mypeer) 
    68 mypicflag = peer_info_config_pic_flags_get(myconfig) 
    69 peer_info_config_pic_flags_pro4_set(mypicflag, 1)   # 1 for TCP 
    70 fd_peer_add(mypeer, "python", None, None) 
    71 delete_peer_info(mypeer) 
    72  
    73  
    74 # Lists 
    75 l1 = new_fd_list() 
    76 l2 = new_fd_list() 
     67print "Local Diameter Identity:", cvar.fd_g_config.cnf_diamid 
     68# Display realm, without using the low-level functions (skip proxy classe definitions): 
     69print "Realm:", _fDpy.fd_config_cnf_diamrlm_get(_fDpy.cvar.fd_g_config) 
     70 
     71 
     72 
     73############# Lists ############ 
     74l1 = fd_list()   # The creator has an implicit fd_list_init call 
     75l2 = fd_list() 
    7776fd_list_insert_after(l1, l2) 
    78 fd_list_dump(l1) 
    79 fd_list_dump(l2) 
    80 delete_fd_list(l2) 
    81 fd_list_dump(l1) 
    82 delete_fd_list(l1) 
    83  
    84  
    85 # Dictionary 
    86 gdict = fd_config_cnf_dict_get(cvar.fd_g_config) 
    87  
    88 id = new_int_ptr() 
    89 int_ptr_assign(id, 3) 
    90 pobj = new_dict_object_pptr() 
    91 fd_dict_search ( gdict, DICT_APPLICATION, APPLICATION_BY_ID, id, pobj, -1 ) 
    92 delete_int_ptr(id) 
    93 obj = dict_object_pptr_value(pobj) 
    94 delete_dict_object_pptr(pobj) 
     77l1.dump() 
     78del l2           # The destructor has an implicit fd_list_unlink call 
     79l1.dump() 
     80del l1 
     81 
     82 
     83############# Hash ############ 
     84hex(fd_hash("hello world"))     # A typemap is applied to accept binary data 
     85 
     86 
     87############# Dictionary ############ 
     88 
     89# Create a dedicated dictionary for our tests 
     90d = dictionary() 
     91d.dump() 
     92 
     93# New vendor 
     94v = dict_vendor_data() 
     95v.vendor_id = 123 
     96v.vendor_name = "My test vendor" 
     97r, my_vendor = fd_dict_new(d, DICT_VENDOR, v, None) 
     98del v 
     99d.dump() 
     100d.vendors_list() 
     101 
     102# New application 
     103a = dict_application_data() 
     104a.application_id = 99 
     105a.application_name = "My test appl" 
     106r, my_appl = fd_dict_new(d, DICT_APPLICATION, a, my_vendor) 
     107del a 
     108 
     109# New type (callbacks are not supported yet...) 
     110t = dict_type_data() 
     111t.type_base = AVP_TYPE_INTEGER32 
     112t.type_name = "My integer AVP" 
     113r, my_type_int = fd_dict_new(d, DICT_TYPE, t, my_appl) 
     114t.type_base = AVP_TYPE_OCTETSTRING 
     115t.type_name = "My binary buffer AVP" 
     116r, my_type_os = fd_dict_new(d, DICT_TYPE, t, my_appl) 
     117del t 
     118 
     119# Constants 
     120c = dict_enumval_data() 
     121c.enum_name = "AVP_VALUE_TROIS" 
     122c.enum_value.i32 = 3 
     123fd_dict_new(d, DICT_ENUMVAL, c, my_type_int) 
     124 
     125c.enum_name = "A_BUFFER_CONSTANT" 
     126osval = avp_value_os("This is a very long AVP value that we prefer to represent as a constant") 
     127c.enum_value.os = osval 
     128c.enum_value.os.dump() 
     129del d 
     130 
     131c = dict_enumval_data() 
     132c.enum_value.os = "coucou" 
     133c.enum_value.os.dump() 
     134 
     135 
     136gdict = cvar.fd_g_config.cnf_dict 
     137r, obj = fd_dict_search ( gdict, DICT_APPLICATION, APPLICATION_BY_ID, 3, -1 ) 
     138obj.dump() 
     139r, obj = fd_dict_search( gdict, DICT_AVP, AVP_BY_NAME, "Origin-Host", -1) 
     140obj.dump() 
     141 
    95142t = new_dict_object_type_ptr() 
    96143fd_dict_gettype(obj, t) 
     
    182229delete_avp_pptr(pavp) 
    183230 
     231 
     232# Create a new peer_info structure and add the peer to the framework. 
     233mypeer = peer_info() 
     234mypeer.pi_diamid = "nas.testbed.aaa" 
     235mypeer.config.pic_flags.pro4 = 1   # 1 for TCP, for some reason PI_P4_TCP is not defined 
     236fd_peer_add(mypeer, "python", None, None) 
     237del mypeer 
     238 
Note: See TracChangeset for help on using the changeset viewer.