Changeset 637:22e8fac3b2d6 in freeDiameter for doc/dbg_interactive.py.sample
- Timestamp:
- Dec 16, 2010, 6:56:41 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/dbg_interactive.py.sample
r636 r637 66 66 # Display the local Diameter Identity: 67 67 print "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): 69 70 print "Realm:", _fDpy.fd_config_cnf_diamrlm_get(_fDpy.cvar.fd_g_config) 70 71 … … 72 73 73 74 ############# 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. 77 l1 = fd_list() # Will be our sentinel 75 78 l2 = fd_list() 76 fd_list_insert_after(l1, l2) 79 l3 = fd_list() 80 l1.isempty() 81 l1.insert_next(l2) # l1 -> l2 82 l1.isempty() 83 l1.insert_prev(l3) # l1 -> l2 -> l3 (circular list) 77 84 l1.dump() 78 del l2 # The destructor has an implicit fd_list_unlink call 79 l1.dump() 85 l3.detach() # l1 -> l2 86 l4=fd_list() 87 l5=fd_list() 88 l3.insert_next(l4) # l3 -> l4 89 l3.insert_next(l5) # l3 -> l5 -> l4 90 l1.concat(l3) # l1 -> l2 -> l5 -> l4 91 92 elements = l1.enum_as() # default: enumerates as fd_list. Warning: this a copy, changing the python list has no effect on the underlying list. 93 for li in elements: 94 li.dump() 95 96 del elements 97 del l2 98 del l3 99 del l4 100 del l5 101 l1.isempty() # The destructor has an implicit fd_list_unlink call 80 102 del l1 81 103 … … 214 236 s2 = session("this.is.a.full.session.id") 215 237 r,s3,isnew = fd_sess_fromsid("this.is.a.full.session.id") 216 s4 = session("host.id", "opt .part")238 s4 = session("host.id", "optional.part") 217 239 s4.settimeout(30) # the python wrapper takes a number of seconds as parameter for simplicity 218 240 s4.dump() … … 241 263 242 264 list = rd.extract(-1) 243 list[0].dump() 265 for 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) 275 blank_avp = avp() 276 del blank_avp 277 278 oh = avp(cvar.fd_g_config.cnf_dict.search ( DICT_AVP, AVP_BY_NAME, "Origin-Host")) # Octet String 279 vi = avp(cvar.fd_g_config.cnf_dict.search ( DICT_AVP, AVP_BY_NAME, "Vendor-Id")) # U32 280 vsai = avp(cvar.fd_g_config.cnf_dict.search ( DICT_AVP, AVP_BY_NAME, "Vendor-Specific-Application-Id")) # Grouped 281 282 # Set values 283 val = avp_value() 284 val.u32 = 123 285 vi.setval(None) # this cleans a previous value (not needed) 286 vi.setval(val) 287 val.os = "my.origin.host" 288 oh.setval(val) 289 vsai.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 295 a_msg = msg() 296 a_msg.dump() 297 del a_msg 298 299 # It is also possible to pass MSGFL_* flags in second parameter (ALLOC_ETEID is default) 300 msg_no_eid = msg(None, 0) 301 msg_no_eid.dump() 302 del msg_no_eid 303 304 # Create from dictionary 305 dwr_dict = cvar.fd_g_config.cnf_dict.search ( DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request" ) 306 dwr = msg(dwr_dict) 307 dwr.dump() 308 309 # Create msg from a binary buffer (then you should call parse_dict and parse_rules methods) 310 dwr2 = 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): 313 dwr3 = msg(cvar.fd_g_config.cnf_dict.search ( DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request" )) 314 dwa3 = dwr3.create_answer() 315 dwr3cpy = dwa3.get_query() 316 317 318 ## Other functions with AVPs & messages 319 320 # Add the AVPs in the message 321 dwr.add_child(oh) 322 oh.add_next(vsai) # equivalent to add_child on the parent 323 324 # Create a network byte buffer from the message 325 dwr.bufferize() 326 327 # Get first child AVP (fast) 328 avp = dwr.first_child() 329 330 # then: 331 avp = 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. 335 dwr.children() 336 # example use: 337 for 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 342 oh_dict = cvar.fd_g_config.cnf_dict.search( DICT_AVP, AVP_BY_NAME, "Origin-Host") 343 oh = dwr.search( oh_dict ) 344 345 # After adding AVPs, the length in the message header is outdated, refresh as follow: 346 dwr.update_length() 347 348 # Get dictionary model for a message or avp 349 dwr.model() 350 oh.model().dump() 351 352 # Retrieve the header of messages & avp: 353 dwr_hdr = dwr.header() 354 dwr_hdr.msg_version 355 dwr_hdr.msg_hbhid 356 357 oh_hdr = oh.header() 358 hex(oh_hdr.avp_flags) 359 oh_hdr.avp_vendor 360 oh_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 363 rd = rt_data() 364 dwr.set_rtd(rd) 365 rd = dwr.get_rtd() 366 367 # Test if message is routable 368 dwr.is_routable() 369 370 # Which peer the message was received from (when received from network) 371 dwr.source() 372 373 # The session corresponding to this message (returns None when no Session-Id AVP is included) 374 dwr.get_session() 375 376 377 # Parse a buffer 378 buf = "\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{" 379 mydwr = msg(buf) 380 # Resolve objects in the dictionary. Return value is None or a struct pei_error in case of problem. 381 mydwr.parse_dict() # if not using the fD global dict, pass it as parameter 382 err = mydwr.parse_rules() 383 err.pei_errcode 384 385 386 # Grouped AVPs are browsed with same methods as messages: 387 gavp = dwr.children()[1] 388 gavp.first_child().dump() 389 gavp.children() 390 391 392 393 244 394 245 395 … … 249 399 250 400 ######################### old stuff (need update) ###################### 251 252 253 254 # Messages255 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)288 401 289 402
Note: See TracChangeset
for help on using the changeset viewer.