[LiSA-Devel] Switch API prototyping

Radu Rendec radu.rendec at mindbit.ro
Tue Mar 12 00:00:46 EET 2013


On Mon, 2013-03-11 at 17:38 +0200, Ionut Nicu wrote:
> On Mon, 2013-03-11 at 10:43 -0400, Victor Duta wrote:
> > I think that the API should also include the swcli_context in order to
> > use the message qeues to comunicate with the daemons and the AF_SWITCH
> > sockets .

Ideally the API should be usable outside the CLI, so it shouldn't
include anything that is CLI-specific, such as the swcli_context.
Besides, AF_SWITCH sockets are specific to the "switch" kernel module
and they make no sense for other backends, such as bridge+8021q.

On the other hand, if you don't persist the AF_SWITCH sockets anywhere
(and pass them back to the backend), you have to open and close them in
every backend function. This makes the code inefficient and ugly.

The clever way to fix this is to add init and cleanup "methods" to the
API. The purpose of the init method is to allocate any resources that
may be required for the normal backend operation (such as the AF_SWITCH
socket, for the switch kernel module backend).

The API client (which is the CLI in our case) doesn't need to know the
"implementation details" and it doesn't really care anyway (since they
are hidden by the API). So, from the client point of view, the init
method can simply return a "void *". The only requirement is to pass it
back to backend in all subsequent method calls. Then then backend
function implementations would cast this pointer to whatever structure
they use internally.

The cleanup method should release any resources that were allocated by
the init method (for instance close the AF_SWITCH sockets).

So, to summarize all that I've explained: you need a sort of "context"
to hold all the backend data, but it's backend-specific and it's NOT
swcli_context. The AF_SWITCH sockets must be removed from swcli_context
and moved to the switch backend specific structure.

I hope this makes things a little bit more clear.

Radu




More information about the LiSA-Devel mailing list