Changeset 627:330be61dbf43 in freeDiameter for doc
- Timestamp:
- Dec 14, 2010, 11:53:24 AM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/dbg_interactive.py.sample
r624 r627 6 6 # The adaptation layer between Python and C is provided by SWIG (http://swig.org). 7 7 # 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 10 9 # 11 10 # Similar to all freeDiameter extensions, an optional filename can be specified in the … … 14 13 # to execute. Otherwise, the interpreter will be interactive. 15 14 # 16 # Bellow are some example use of the python interpreter:17 18 19 # Display current version20 print FD_PROJECT_NAME, FD_PROJECT_VERSION_MAJOR, FD_PROJECT_VERSION_MINOR, FD_PROJECT_VERSION_REV21 22 23 # Change the global debug level of the framework (cvar contains all global variables)24 cvar.fd_g_debug_lvl = FULL25 26 27 # Turn on debug for a specific function28 cvar.fd_debug_one_function = "gc_th_fct"29 30 31 # Print messages to freeDiameter's debug facility32 fd_log_debug("3 + 4 = %d\n" % (7))33 # See SWIG documentation about varargs functions for more information34 35 36 15 # SWIG deals with structures as follow: 37 # Takethe structure:16 # Given the structure: 38 17 # 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 = 242 # foo_a_get(s) --> returns s->a value43 # 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: 46 25 # s = foo() 47 26 # s.a = 2 48 27 # s.a 49 28 # 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 39 print "%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) 45 cvar.fd_g_debug_lvl = FULL 46 47 48 # Turn on debug for a specific function (if framework compiled with DEBUG support) 49 cvar.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. 55 fd_log_debug("3 + 4 = %d\n" % (7)) 56 57 58 # Display some framework state information 59 r = fd_event_send(cvar.fd_g_config.cnf_main_ev, FDEV_DUMP_PEERS, 0, None) 60 r = fd_event_send(cvar.fd_g_config.cnf_main_ev, FDEV_DUMP_SERV, 0, None) 61 r = fd_event_send(cvar.fd_g_config.cnf_main_ev, FDEV_DUMP_EXT, 0, None) 62 63 64 ############# Global variables ############ 51 65 52 66 # 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() 67 print "Local Diameter Identity:", cvar.fd_g_config.cnf_diamid 68 # Display realm, without using the low-level functions (skip proxy classe definitions): 69 print "Realm:", _fDpy.fd_config_cnf_diamrlm_get(_fDpy.cvar.fd_g_config) 70 71 72 73 ############# Lists ############ 74 l1 = fd_list() # The creator has an implicit fd_list_init call 75 l2 = fd_list() 77 76 fd_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) 77 l1.dump() 78 del l2 # The destructor has an implicit fd_list_unlink call 79 l1.dump() 80 del l1 81 82 83 ############# Hash ############ 84 hex(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 90 d = dictionary() 91 d.dump() 92 93 # New vendor 94 v = dict_vendor_data() 95 v.vendor_id = 123 96 v.vendor_name = "My test vendor" 97 r, my_vendor = fd_dict_new(d, DICT_VENDOR, v, None) 98 del v 99 d.dump() 100 d.vendors_list() 101 102 # New application 103 a = dict_application_data() 104 a.application_id = 99 105 a.application_name = "My test appl" 106 r, my_appl = fd_dict_new(d, DICT_APPLICATION, a, my_vendor) 107 del a 108 109 # New type (callbacks are not supported yet...) 110 t = dict_type_data() 111 t.type_base = AVP_TYPE_INTEGER32 112 t.type_name = "My integer AVP" 113 r, my_type_int = fd_dict_new(d, DICT_TYPE, t, my_appl) 114 t.type_base = AVP_TYPE_OCTETSTRING 115 t.type_name = "My binary buffer AVP" 116 r, my_type_os = fd_dict_new(d, DICT_TYPE, t, my_appl) 117 del t 118 119 # Constants 120 c = dict_enumval_data() 121 c.enum_name = "AVP_VALUE_TROIS" 122 c.enum_value.i32 = 3 123 fd_dict_new(d, DICT_ENUMVAL, c, my_type_int) 124 125 c.enum_name = "A_BUFFER_CONSTANT" 126 osval = avp_value_os("This is a very long AVP value that we prefer to represent as a constant") 127 c.enum_value.os = osval 128 c.enum_value.os.dump() 129 del d 130 131 c = dict_enumval_data() 132 c.enum_value.os = "coucou" 133 c.enum_value.os.dump() 134 135 136 gdict = cvar.fd_g_config.cnf_dict 137 r, obj = fd_dict_search ( gdict, DICT_APPLICATION, APPLICATION_BY_ID, 3, -1 ) 138 obj.dump() 139 r, obj = fd_dict_search( gdict, DICT_AVP, AVP_BY_NAME, "Origin-Host", -1) 140 obj.dump() 141 95 142 t = new_dict_object_type_ptr() 96 143 fd_dict_gettype(obj, t) … … 182 229 delete_avp_pptr(pavp) 183 230 231 232 # Create a new peer_info structure and add the peer to the framework. 233 mypeer = peer_info() 234 mypeer.pi_diamid = "nas.testbed.aaa" 235 mypeer.config.pic_flags.pro4 = 1 # 1 for TCP, for some reason PI_P4_TCP is not defined 236 fd_peer_add(mypeer, "python", None, None) 237 del mypeer 238
Note: See TracChangeset
for help on using the changeset viewer.