Navigation


Changeset 637:22e8fac3b2d6 in freeDiameter for doc


Ignore:
Timestamp:
Dec 16, 2010 6:56:41 PM (2 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Message:

Split interface file in modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/dbg_interactive.py.sample

    r636 r637  
    6666# Display the local Diameter Identity: 
    6767print "Local Diameter Identity:", cvar.fd_g_config.cnf_diamid 
    68 # Display realm, without using the low-level functions (skip proxy classe definitions): 
     68 
     69# Display realm, using the low-level functions (skip proxy classe definitions): 
    6970print "Realm:", _fDpy.fd_config_cnf_diamrlm_get(_fDpy.cvar.fd_g_config) 
    7071 
     
    7273 
    7374############# Lists ############ 
    74 l1 = fd_list()   # The creator has an implicit fd_list_init call 
     75 
     76# Note: we use different names from the C API here, for usability. 
     77l1 = fd_list()   # Will be our sentinel 
    7578l2 = fd_list() 
    76 fd_list_insert_after(l1, l2) 
     79l3 = fd_list() 
     80l1.isempty() 
     81l1.insert_next(l2)   # l1 -> l2 
     82l1.isempty() 
     83l1.insert_prev(l3)   # l1 -> l2 -> l3 (circular list) 
    7784l1.dump() 
    78 del l2           # The destructor has an implicit fd_list_unlink call 
    79 l1.dump() 
     85l3.detach()          # l1 -> l2 
     86l4=fd_list() 
     87l5=fd_list() 
     88l3.insert_next(l4)   #   l3 -> l4 
     89l3.insert_next(l5)   #   l3 -> l5 -> l4 
     90l1.concat(l3)        # l1 -> l2 -> l5 -> l4 
     91 
     92elements = l1.enum_as()  # default: enumerates as fd_list. Warning: this a copy, changing the python list has no effect on the underlying list. 
     93for li in elements: 
     94  li.dump() 
     95 
     96del elements 
     97del l2 
     98del l3 
     99del l4 
     100del l5 
     101l1.isempty() # The destructor has an implicit fd_list_unlink call 
    80102del l1 
    81103 
     
    214236s2 = session("this.is.a.full.session.id") 
    215237r,s3,isnew = fd_sess_fromsid("this.is.a.full.session.id") 
    216 s4 = session("host.id", "opt.part") 
     238s4 = session("host.id", "optional.part") 
    217239s4.settimeout(30) # the python wrapper takes a number of seconds as parameter for simplicity 
    218240s4.dump() 
     
    241263 
    242264list = rd.extract(-1) 
    243 list[0].dump() 
     265for c in list.enum_as("struct rtd_candidate *"): 
     266  print "%s (%s): %s" % (c.diamid, c.realm, c.score) 
     267 
     268 
     269 
     270############# Messages, AVPs ############ 
     271 
     272## AVP 
     273 
     274# Create empty (as for messages, pass None or a dictionary object as 1st param, and flags as optional 2nd param) 
     275blank_avp = avp() 
     276del blank_avp 
     277 
     278oh = avp(cvar.fd_g_config.cnf_dict.search ( DICT_AVP, AVP_BY_NAME, "Origin-Host"))                      # Octet String 
     279vi = avp(cvar.fd_g_config.cnf_dict.search ( DICT_AVP, AVP_BY_NAME, "Vendor-Id"))                        # U32 
     280vsai = avp(cvar.fd_g_config.cnf_dict.search ( DICT_AVP, AVP_BY_NAME, "Vendor-Specific-Application-Id")) # Grouped 
     281 
     282# Set values 
     283val = avp_value() 
     284val.u32 = 123 
     285vi.setval(None)  # this cleans a previous value (not needed) 
     286vi.setval(val) 
     287val.os = "my.origin.host" 
     288oh.setval(val) 
     289vsai.add_child(vi) # call as add_child(vi, 1) to add the new AVP at the beginning, default is at the end 
     290 
     291 
     292## Messages 
     293 
     294# Create empty 
     295a_msg = msg() 
     296a_msg.dump() 
     297del a_msg 
     298 
     299# It is also possible to pass MSGFL_* flags in second parameter (ALLOC_ETEID is default) 
     300msg_no_eid = msg(None, 0) 
     301msg_no_eid.dump() 
     302del msg_no_eid 
     303 
     304# Create from dictionary 
     305dwr_dict = cvar.fd_g_config.cnf_dict.search ( DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request" ) 
     306dwr = msg(dwr_dict) 
     307dwr.dump() 
     308 
     309# Create msg from a binary buffer (then you should call parse_dict and parse_rules methods) 
     310dwr2 = msg("\x01\x00\x00\x14\x80\x00\x01\x18\x00\x00\x00\x00\x00\x00\x00\x00\x1b\xf0\x00\x01") 
     311 
     312# Create answer from request (optional parameters: dictionary to use, and flags): 
     313dwr3 = msg(cvar.fd_g_config.cnf_dict.search ( DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request" )) 
     314dwa3 = dwr3.create_answer() 
     315dwr3cpy = dwa3.get_query() 
     316 
     317 
     318## Other functions with AVPs & messages 
     319 
     320# Add the AVPs in the message 
     321dwr.add_child(oh) 
     322oh.add_next(vsai)   # equivalent to add_child on the parent 
     323 
     324# Create a network byte buffer from the message 
     325dwr.bufferize() 
     326 
     327# Get first child AVP (fast) 
     328avp = dwr.first_child() 
     329 
     330# then: 
     331avp = avp.get_next() # when last AVP, returns None 
     332 
     333 
     334# Get all 1st level children (slower) -- warning, changes to the python list will not be reflected on the underlying message. read-only use. 
     335dwr.children() 
     336# example use: 
     337for a in dwr.children() 
     338  a.dump(0)  # 0 means: dump only this object, do not walk the tree 
     339 
     340 
     341# Search the first AVP of a given type 
     342oh_dict = cvar.fd_g_config.cnf_dict.search( DICT_AVP, AVP_BY_NAME, "Origin-Host") 
     343oh = dwr.search( oh_dict ) 
     344 
     345# After adding AVPs, the length in the message header is outdated, refresh as follow: 
     346dwr.update_length() 
     347 
     348# Get dictionary model for a message or avp 
     349dwr.model() 
     350oh.model().dump() 
     351 
     352# Retrieve the header of messages & avp: 
     353dwr_hdr = dwr.header() 
     354dwr_hdr.msg_version 
     355dwr_hdr.msg_hbhid 
     356 
     357oh_hdr = oh.header() 
     358hex(oh_hdr.avp_flags) 
     359oh_hdr.avp_vendor 
     360oh_hdr.avp_value.os.dump()  # The initial avp value must be set with setval(), but then this accessor is allowed. 
     361 
     362# Get or set the routing data 
     363rd = rt_data() 
     364dwr.set_rtd(rd) 
     365rd = dwr.get_rtd() 
     366 
     367# Test if message is routable 
     368dwr.is_routable() 
     369 
     370# Which peer the message was received from (when received from network) 
     371dwr.source() 
     372 
     373# The session corresponding to this message (returns None when no Session-Id AVP is included) 
     374dwr.get_session() 
     375 
     376 
     377# Parse a buffer 
     378buf = "\x01\x00\x00@\x80\x00\x01\x18\x00\x00\x00\x00\x00\x00\x00\x00N\x10\x00\x00\x00\x00\x01\x08@\x00\x00\x16my.origin.host\x00\x00\x00\x00\x01\x04@\x00\x00\x14\x00\x00\x01\n@\x00\x00\x0c\x00\x00\x00{" 
     379mydwr = msg(buf) 
     380# Resolve objects in the dictionary. Return value is None or a struct pei_error in case of problem. 
     381mydwr.parse_dict()  # if not using the fD global dict, pass it as parameter 
     382err = mydwr.parse_rules() 
     383err.pei_errcode 
     384 
     385 
     386# Grouped AVPs are browsed with same methods as messages: 
     387gavp = dwr.children()[1] 
     388gavp.first_child().dump() 
     389gavp.children() 
     390 
     391 
     392 
     393 
    244394 
    245395 
     
    249399 
    250400######################### old stuff (need update) ###################### 
    251  
    252  
    253  
    254 # Messages 
    255 gdict = fd_config_cnf_dict_get(cvar.fd_g_config) 
    256 pobj = new_dict_object_pptr() 
    257 fd_dict_search ( gdict, DICT_COMMAND, CMD_BY_NAME, char_to_void("Capabilities-Exchange-Request"), pobj, -1 ) 
    258 cerdict = dict_object_pptr_value(pobj) 
    259 fd_dict_search ( gdict, DICT_AVP, AVP_BY_NAME, char_to_void("Origin-Host"), pobj, -1 ) 
    260 ohdict = dict_object_pptr_value(pobj) 
    261 delete_dict_object_pptr(pobj) 
    262  
    263 pmsg = new_msg_pptr() 
    264 fd_msg_new(cerdict, MSGFL_ALLOC_ETEID, pmsg) 
    265 msg = msg_pptr_value(pmsg); 
    266 pavp = new_avp_pptr() 
    267 fd_msg_avp_new(ohdict, 0, pavp) 
    268 avp = avp_pptr_value(pavp); 
    269 fd_msg_avp_add(msg, MSG_BRW_FIRST_CHILD, avp) 
    270 fd_msg_dump_walk(0, msg) 
    271  
    272 pahdr = new_avp_hdr_pptr() 
    273 fd_msg_avp_hdr(avp, pahdr) 
    274 ahdr = avp_hdr_pptr_value(pahdr) 
    275 delete_avp_hdr_pptr(pahdr) 
    276 avp_hdr_avp_code_get(ahdr) 
    277 os = new_avp_value_os() 
    278 avp_value_os_fromstr(os, fd_config_cnf_diamid_get(cvar.fd_g_config)) 
    279 val = new_avp_value() 
    280 avp_value_os_set(val, os) 
    281 delete_avp_value_os(os) 
    282 fd_msg_avp_setvalue(avp, val) 
    283 delete_avp_value(val) 
    284  
    285 r,buf = fd_msg_bufferize_py(msg) 
    286 fd_msg_free(msg) 
    287 delete_avp_pptr(pavp) 
    288401 
    289402 
Note: See TracChangeset for help on using the changeset viewer.