Navigation


Changeset 640:237cf6339546 in freeDiameter for doc


Ignore:
Timestamp:
Dec 20, 2010, 7:36:40 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

dbg_interactive almost complete

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/dbg_interactive.py.sample

    r639 r640  
    9090l1.concat(l3)        # l1 -> l2 -> l5 -> l4
    9191
    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.
     92elements = l1.enum_as()  # default: enumerates as fd_list. Warning: this a copy, changing the python list has no effect on the underlying fd_list.
    9393for li in elements:
    9494  li.dump()
     
    224224del r
    225225
    226 d.dump()
    227 del d
    228 
    229226r2 = dict_rule_data(my_avp_int, RULE_REQUIRED) # min & max are optional parameters, default to -1
    230227r3 = dict_rule_data(my_avp_int, RULE_REQUIRED, 2, 3) # min is 2, max is 3
     
    234231del r4
    235232
     233d.dump()
     234del d
     235
    236236####### Now play with the "real" dictionary
    237237
     
    273273s1.getsid()
    274274s2 = session("this.is.a.full.session.id")
    275 r,s3,isnew = fd_sess_fromsid("this.is.a.full.session.id")
     275r,s3,isnew = fd_sess_fromsid("this.is.a.full.session.id")  # use this call if "isnew" is really needed...
    276276s4 = session("host.id", "optional.part")
    277277s4.settimeout(30) # the python wrapper takes a number of seconds as parameter for simplicity
     
    304304  print "%s (%s): %s" % (c.diamid, c.realm, c.score)
    305305
     306del rd
     307
     308
     309# A rt_fwd callback has the following prototype:
     310def 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
     315fwdhdl = fd_rt_fwd_hdl( my_rtfwd_cb, RT_FWD_REQ )
     316
     317
     318# A rt_out cb has the following prototype:
     319def 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
     327outhdl = fd_rt_out_hdl( my_rtout_cb )  # a priority can be specified as 2nd parameter, default is 0.
     328
     329
     330
    306331
    307332
     
    322347val = avp_value()
    323348val.u32 = 123
    324 vi.setval(None)  # this cleans a previous value (not needed)
     349vi.setval(None)  # this cleans a previous value (usually not needed)
    325350vi.setval(val)
    326351val.os = "my.origin.host"
     
    379404dwr.children()
    380405# example use:
    381 for a in dwr.children()
     406for a in dwr.children():
    382407  a.dump(0)  # 0 means: dump only this object, do not walk the tree
    383408
     
    436461
    437462# Send a message:
     463mydwr = msg(buf)
    438464mydwr.send()
    439465
     
    447473    return None
    448474
     475mydwr = msg(buf)
    449476mydwr.send(send_callback, some_object)
    450477
    451478
    452479# Set a result code in an answer message.
     480mydwr = msg(buf)
    453481dwa = mydwr.create_answer()
    454482dwa.rescode_set()   # This adds the DIAMETER_SUCCESS result code
     
    598626myqueue.length()
    599627
     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:
     634ev = fd_event()
     635ev.code = FDEV_DUMP_EXT
     636cvar.fd_g_config.cnf_main_ev.post(ev, "struct fd_event *")
     637
     638# Similarly, for *get, we can specify the structure that was queued:
     639myqueue.get("struct fd_event *")
     640myqueue.tryget("struct fd_event *")
     641myqueue.timedget(3, "struct fd_event *")
     642
    600643del myqueue
    601644
     
    614657np = peer_info()
    615658np.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 
     659np.config.pic_flags.pro4 = PI_P4_TCP
    619660
    620661
     
    634675        print "The peer has been destroyed before it completed the connection."
    635676
    636 # Then add the peer simply like this:
     677# Then add the peer like this:
    637678np.add(add_cb)
    638679
    639680
     681# Search a peer by its diameter id (returns a peer_hdr object if found) -- similar to fd_peer_getbyid
     682p = peer_search("nas.domain.aaa")
     683
     684
     685## Validation callback (see fd_peer_validate_register documentation)
     686
     687# cb2 prototype:
     688def 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:
     695def 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.
     709peer_validate_register(my_validate_cb)
     710
     711
     712
     713############# ENDPOINTS ############
     714
     715ep = fd_endpoint("129.168.168.192")
     716
     717# with port:
     718ep = fd_endpoint("129.168.168.192", 3868)
     719
     720# With different flags:
     721ep = fd_endpoint("129.168.168.192", 3868, EP_FL_PRIMARY)
     722
     723# Add IP information for the peer
     724np = peer_info()
     725ep.add_merge(np.pi_endpoints)
     726fd_ep_dump(0, np.pi_endpoints)
     727
     728
Note: See TracChangeset for help on using the changeset viewer.