kohler / click

The Click modular router: fast modular packet processing and analysis
Other
740 stars 321 forks source link

need help with add_handlers #382

Closed peterrz closed 6 years ago

peterrz commented 6 years ago

Hi, I want to access simplequeue handler in another class but I'm confused how to do it. i will be appreciated if you help me.

void SimpleQueue::add_handlers() { add_read_handler("length", read_handler, 0); add_read_handler("highwater_length", read_handler, 1); add_read_handler("capacity", read_handler, 2, Handler::h_calm); add_read_handler("drops", read_handler, 3); add_write_handler("capacity", reconfigure_keyword_handler, "0 CAPACITY"); add_write_handler("reset_counts", write_handler, 0, Handler::h_button | Handler::h_nonexclusive); add_write_handler("reset", write_handler, 1, Handler::h_button); }

peterrz commented 6 years ago

I want to access the number of Queue() q :: Queue(50) -> SetTXRate (12) -> RadiotapEncap() -> to_dev :: ToDevice ();

tbarbette commented 6 years ago

I'm not sure you're speaking run-time or from another element? At runtime you can either use a ControlSocket and connect to it with Clicky, ClickController (in the apps folder) or using telnet. In FastClick there is a HTTPServer you can use to read handlers using a navigator or client like curl. Or you can write a script to display the value on stdout. Eg those will read the capacity once, in loop every second, or when you kill the router. Script(TYPE ACTIVE, read q.capacity) Script(TYPE ACTIVE, label r, read q.capacity, wait 1s, goto r) DriverManager(wait, read q.capacity)

To read from code, best is probably to have some handler parameter in your element configuration (eg look at Counter / counter.cc) and then access the handler that was given by the config when you want.

ahenning commented 6 years ago

Another possibility: Do you want your custom element to access the number in Queue()?

peterrz commented 6 years ago

thanks! @tbarbette , @ahenning for your time and concerning . this project Wi5 use click to manage the router. the *.cli which will be build for router is click-file and The clicky diagram like this: diagram_odin_click_agent_2ifaces

as you notice odinagent use port 2 so send packets for q // create a queue and connect it to SetTXRate-RadiotapEncap and send it to the network interface q :: Queue(50) -> SetTXRate (12) -> RadiotapEncap() -> to_dev :: ToDevice (mon0); odinagent[2] -> q

I want to access the Queue capacity and other features in odinagent.cc for managing my packet. if Queue was full then stop sending more packet to this Queue. in odinagent.cc void OdinAgent::push(int port, Packet *p) { just we have // send the frame by the output number 2 output(2).push(p_out); port[2] connect to q which lead us to Queue(), and i need call the Queue handler in odinagent. thanks!

ahenning commented 6 years ago

There are two ways I am aware of: via the handlercall.h method which I think counter.cc uses, or the other method is how arpquerier uses arptable. Have a look at those examples to call a handler or function in another element (Queue) from your custom element (OdinAgent)

peterrz commented 6 years ago

unfortunately, I didn't get it, can you show me examples, please. I wrote show_size() function in SimpleQueue String SimpleQueue:: show_size() { Element *_other; String result = HandlerCall::call_read(_other, "highwater_length"); return result; } and when show_size() called in odinagent.cc didn't show anything

cinhori commented 6 years ago

Hi, I want to install click on Ubuntu, can you tell me which ubuntu version you use? Or another linux releases?

peterrz commented 6 years ago

thank you so much! I used ControlSocket.