[Click] how do I dynamically create an element ?

bartvdb Bart.VandenBroeck at esat.kuleuven.ac.be
Wed Mar 30 14:10:31 EST 2005


Hi all


I fear the configuration will probably need to be "hotswapped" too
often.  I've tried a bit to create elements dynamically anyway in the
C++ code of a custom element, and that seems to work up to a certain
level, but now the router.cc code gives me a SIGABORT signal...


Could anyone tell me please why this doesn't work and how I could make
it to work:
##############
int Valve::configure(Vector<String> &conf, ErrorHandler *errh)
{   
    int result;
    Vector<String> v;
    v.push_back("1000");
    queue->configure(v,errh);
    queue->initialize(errh);
    _errh=errh;
    //fill hashmap with dummy value;
    unsigned hash=hashcode("255.255.255.255");
    Usershaper *ushaper=new Usershaper();
    ushaper->usershaper=new BandwidthShaper();
    ushaper->userqueue=new SimpleQueue();

    Vector<String> vqueue;
    vqueue.push_back("1000");
    result = ushaper->userqueue->configure(vqueue,_errh);
    click_chatter("result: %i", result);

    Vector<String> tempv;
    tempv.push_back("56000bps");
    result = ushaper->usershaper->configure(tempv,_errh);
    click_chatter("result: %i", result);

    // cf.     
http://www.pdos.lcs.mit.edu/click/doc/progman.html#Initialization%20Phases
    //                  First configure, then connect ports, then initialize
    //  cf.     $CLICKDIR/lib/router.cc: "Router::set_connections()"
    //                  First connect output port then input port
    int *input_codes, *output_codes;
    ushaper->userqueue->processing_vector(input_codes, output_codes, _errh);
    ushaper->userqueue->initialize_ports(input_codes, output_codes);
    ushaper->usershaper->processing_vector(input_codes, output_codes,
_errh);
    ushaper->usershaper->initialize_ports(input_codes, output_codes);
    result = ushaper->userqueue->connect_output(0,ushaper->usershaper,0);
    click_chatter("result: %i", result);
    result = ushaper->usershaper->connect_input(0,ushaper->userqueue,0);
    click_chatter("result: %i", result);
    result = ushaper->userqueue->initialize(_errh);
    click_chatter("result: %i", result);
    result = ushaper->usershaper->initialize(_errh);
    click_chatter("result: %i", result);

    _shapermap.insert(hash, ushaper);
    
    return 0;
}
##############


Starting a configuration with this element in userlevel Click returns
this on the command line:
##############
result: 0
result: 0
result: -1
result: 0
result: 0
result: 0
Segmentation fault
##############


All seems very much OK, up till the segmentation fault.  As mentioned
before, the segmentation fault corresponds to a SIGABORT signal (as seen
when debugging the code with DDD) when the configuration of this element
finishes and the code of router.cc resumes executing.  Some memory
address cannot be accessed and it seems the "this" pointer has changed...


Thanks in advance
Bart



> Hi Bart,
> 
> Click doesn't yet support this directly, but it is possible to 
> "hotswap" a new configuration.  State from the old config will be 
> inserted into the new.
> 
> Eddie
> 
> 
> On Mar 16, 2005, at 6:08 AM, Bart Van Keyenberg wrote:
> 
> > Hi,
> >
> > I want to create a click configuration where I don't know how much 
> > elements of a certain kind I will need beforehand (number of elements 
> > depends on number of users).  Can I dynamically create an element 
> > (e.g. from within another element), and if so, how do I handle this 
> > kind of thing?
> >
> > Kind Regards
> >
> > Bart



More information about the click mailing list