Changeset 640:237cf6339546 in freeDiameter for doc/dbg_interactive.py.sample
- Timestamp:
- Dec 20, 2010, 7:36:40 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/dbg_interactive.py.sample
r639 r640 90 90 l1.concat(l3) # l1 -> l2 -> l5 -> l4 91 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.92 elements = l1.enum_as() # default: enumerates as fd_list. Warning: this a copy, changing the python list has no effect on the underlying fd_list. 93 93 for li in elements: 94 94 li.dump() … … 224 224 del r 225 225 226 d.dump()227 del d228 229 226 r2 = dict_rule_data(my_avp_int, RULE_REQUIRED) # min & max are optional parameters, default to -1 230 227 r3 = dict_rule_data(my_avp_int, RULE_REQUIRED, 2, 3) # min is 2, max is 3 … … 234 231 del r4 235 232 233 d.dump() 234 del d 235 236 236 ####### Now play with the "real" dictionary 237 237 … … 273 273 s1.getsid() 274 274 s2 = session("this.is.a.full.session.id") 275 r,s3,isnew = fd_sess_fromsid("this.is.a.full.session.id") 275 r,s3,isnew = fd_sess_fromsid("this.is.a.full.session.id") # use this call if "isnew" is really needed... 276 276 s4 = session("host.id", "optional.part") 277 277 s4.settimeout(30) # the python wrapper takes a number of seconds as parameter for simplicity … … 304 304 print "%s (%s): %s" % (c.diamid, c.realm, c.score) 305 305 306 del rd 307 308 309 # A rt_fwd callback has the following prototype: 310 def my_rtfwd_cb(msg): 311 print "Forwarding the following message:" 312 msg.dump() 313 return [ 0, msg ] # return None instead of msg to stop forwarding. 314 315 fwdhdl = fd_rt_fwd_hdl( my_rtfwd_cb, RT_FWD_REQ ) 316 317 318 # A rt_out cb has the following prototype: 319 def my_rtout_cb(msg, list): 320 print "Sending out the following message:" 321 msg.dump() 322 print "The possible candidates are:" 323 for c in list.enum_as("struct rtd_candidate *"): 324 print "%s (%s): %s" % (c.diamid, c.realm, c.score) 325 return 0 # returns an error code (standard errno values) 326 327 outhdl = fd_rt_out_hdl( my_rtout_cb ) # a priority can be specified as 2nd parameter, default is 0. 328 329 330 306 331 307 332 … … 322 347 val = avp_value() 323 348 val.u32 = 123 324 vi.setval(None) # this cleans a previous value ( not needed)349 vi.setval(None) # this cleans a previous value (usually not needed) 325 350 vi.setval(val) 326 351 val.os = "my.origin.host" … … 379 404 dwr.children() 380 405 # example use: 381 for a in dwr.children() 406 for a in dwr.children(): 382 407 a.dump(0) # 0 means: dump only this object, do not walk the tree 383 408 … … 436 461 437 462 # Send a message: 463 mydwr = msg(buf) 438 464 mydwr.send() 439 465 … … 447 473 return None 448 474 475 mydwr = msg(buf) 449 476 mydwr.send(send_callback, some_object) 450 477 451 478 452 479 # Set a result code in an answer message. 480 mydwr = msg(buf) 453 481 dwa = mydwr.create_answer() 454 482 dwa.rescode_set() # This adds the DIAMETER_SUCCESS result code … … 598 626 myqueue.length() 599 627 628 629 ## Variants: 630 # All the previous calls are suitable to queue Python objects. 631 # In order to interact with objects queued / poped by C counterpart, 632 # a second parameter must be passed to specify the object type, 633 # as follow: 634 ev = fd_event() 635 ev.code = FDEV_DUMP_EXT 636 cvar.fd_g_config.cnf_main_ev.post(ev, "struct fd_event *") 637 638 # Similarly, for *get, we can specify the structure that was queued: 639 myqueue.get("struct fd_event *") 640 myqueue.tryget("struct fd_event *") 641 myqueue.timedget(3, "struct fd_event *") 642 600 643 del myqueue 601 644 … … 614 657 np = peer_info() 615 658 np.pi_diamid = "nas.localdomain" 616 np.config.pic_flags.pro4 = 1 # 1 for TCP, for some reason PI_P4_TCP is not defined 617 618 659 np.config.pic_flags.pro4 = PI_P4_TCP 619 660 620 661 … … 634 675 print "The peer has been destroyed before it completed the connection." 635 676 636 # Then add the peer simplylike this:677 # Then add the peer like this: 637 678 np.add(add_cb) 638 679 639 680 681 # Search a peer by its diameter id (returns a peer_hdr object if found) -- similar to fd_peer_getbyid 682 p = peer_search("nas.domain.aaa") 683 684 685 ## Validation callback (see fd_peer_validate_register documentation) 686 687 # cb2 prototype: 688 def my_validate_cb2(pinfo): 689 print "Cb2 callback trigged for peer %s" % (pinfo.pi_diamid) 690 # Usually, this would be used only to check some TLS properties, 691 # which is not really possible yet through the python interpreter... 692 return 0 # return an error code if the peer is not validated 693 694 # cb prototype: 695 def my_validate_cb(pinfo): 696 print "Validate callback trigged for peer %s" % (pinfo.pi_diamid) 697 # If the peer is not allowed to connect: 698 #return -1 699 # If the peer is authorized: 700 #return 1 701 # In addition, if IPsec is allowed, 702 #pinfo.config.pic_flags.sec = PI_SEC_NONE 703 # If no decision has been made: 704 #return 0 705 # If the peer is temporarily authorized but a second callback must be called after TLS negociation: 706 return my_validate_cb2 707 708 # Register the callback, it will be called on new incoming connections. 709 peer_validate_register(my_validate_cb) 710 711 712 713 ############# ENDPOINTS ############ 714 715 ep = fd_endpoint("129.168.168.192") 716 717 # with port: 718 ep = fd_endpoint("129.168.168.192", 3868) 719 720 # With different flags: 721 ep = fd_endpoint("129.168.168.192", 3868, EP_FL_PRIMARY) 722 723 # Add IP information for the peer 724 np = peer_info() 725 ep.add_merge(np.pi_endpoints) 726 fd_ep_dump(0, np.pi_endpoints) 727 728
Note: See TracChangeset
for help on using the changeset viewer.