kohler / click

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

Question about Script Element and Handlers #393

Closed ervance closed 6 years ago

ervance commented 6 years ago

Hi everyone,

I hope this is the place to ask a question like this, I know it is not an issue.

Click is great for what I want to do with my project. However I am running into either my own lack of knowledge or a limitation of click. Pretty much all of the elements exist that I want to use, however, I would like to add a bit more functionality to them. Keeping it short, I want to be able to call the handlers of the elements from a different element, ie allow my elements to share information. I would like to keep track of the number of one type of packet and cause a reaction. Lets say, start to drop the packets for switch its behavior in some way. Another example would be that I want my queue to be able to report to, maybe a custom element or an element already provided, the number of packets currently queued.

My only idea to solve this would be to create a custom element and inherit the element classes who's functionality is similar or who's I would like to share. For example an element with its own queue. But that seems counter of what click does.

I ran into Scripting and was trying to understand it / play with it. Can it do what I am asking? It seems like a very powerful piece, but I am not exactly sure how to use it with handlers, ie the Script( TYPE PASSIVE, .... ).

Does anyone have anywhere they can point me or able to provide an explanation?

TLDR: Is it possible to share information between elements in a configuration, ie use handlers in the configuration, such as Script(), to add more functionality and logic to packet flows.

Thank you anyone who takes the time in advance!

tbarbette commented 6 years ago

What you described seem to be the role of handlers. You can read/write handlers of one element from another one "programmatically" or :

https://github.com/kohler/click/wiki/Script will explain scripts further. Your scripts can for example write the handler of a Switch that will send the packets to different outputs according to the logic.

ervance commented 6 years ago

Thank you very much for your detailed explanation! I was thinking that Script would be able to help me build an event driven configuration, but was falling short on how exactly to fire the scripts. You have helped tremendously, thank you again!

bcronje commented 6 years ago

@ervance just as a side note, you can obviously also gain programmatic access to other elements inside your own custom elements. This is useful in cases where using Script might not give you what you want to achieve.