Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-design struct ccnl_relay_s #281

Open
mfrey opened this issue Jun 28, 2018 · 4 comments
Open

re-design struct ccnl_relay_s #281

mfrey opened this issue Jun 28, 2018 · 4 comments

Comments

@mfrey
Copy link
Collaborator

mfrey commented Jun 28, 2018

I propose to re-design the struct ccnl_relay_s data structure gradually. The struct is used as a global variable which is passed to functions throughout CCN-lites codebase which already has caused issues within respect to parallel access.

The basic idea is to provide a common API to data structures which allows to interchange the underlying implementation, e.g. one could provide a hash map or linked list for the content store. This would affect the following entries in struct ccnl_relay_s

struct ccnl_relay_s {
    ...
    struct ccnl_face_s *faces;  /**< The existing forwarding faces */
    struct ccnl_forward_s *fib; /**< The Forwarding Information Base (FIB) */

    struct ccnl_interest_s *pit; /**< The Pending Interest Table (PIT) */
    struct ccnl_content_s *contents; /**< contentsend; */
    ...
};

In a first step one would need to define a common API for example for a content store, e.g.

...
/** adds a content store entry */
void add(...);
/** removes a content store entry */
void del(...);
/** searches the content store for an entry and returns its position */
int search(...);
/** retrieves an item of the content store */
struct ccnl_content_s get(...);
...

There would be also need for management functions which would allow to set different implementations (and also set a default implementation by default). The down-side so to speak introduces function pointers and it is also not clear if we can come up with a really generic API for different data structures (e.g. think e.g. for example of additional parameters/functions a data structure needs (this is a solvable problem, but it raises the question if we can have a clean and easy to grasp API)).

Any thoughts? Comments?

@mfrey mfrey added the question label Jun 28, 2018
@mfrey mfrey changed the title red re-design struct ccnl_relay_s Jun 28, 2018
@mfrey
Copy link
Collaborator Author

mfrey commented Jun 28, 2018

This probably would also ease our efforts to get rid of malloc for IoT devices (by having a component which provides data structures which have been "statically allocated").

@blacksheeep
Copy link
Contributor

I like this idea

@blacksheeep
Copy link
Contributor

Can you explain the point with the management funcitons with more details.
I did not get, why they are related to the content store?

@mfrey
Copy link
Collaborator Author

mfrey commented Jun 28, 2018

Can you explain the point with the management funcitons with more details.
I did not get, why they are related to the content store?

Management functions is probably a bit exaggerating. You need functions to set your implementation, e.g. (the header)

/** our generic function to add to the content store */
void add(struct ccnl_prefix_s prefix, uint8_t** data);
/** function to set our function pointer */
void set_add(void (* function_pointer)(struct ccnl_prefix_s, uint8_t**));

and your implementation

/** a "private" function pointer for the add function */
static void (*add_func)(struct ccnl_prefix_s, uint8_t**);

void add(struct ccnl_prefix_s prefix, uint8_t** data) {
       /** check if the pointer is set */
       if (add_func) {
              /** pass the paramaters to our underlying implementation */
              add_func(prefix, data);
       }
}

void set_add(void (* function_pointer)(struct ccnl_prefix_s, uint8_t**)) { 
       if (function_pointer) {
              add_func = function_pointer;       
       }
}

and then somewhere else

void hash_map_add(struct ccnl_prefix_s prefix, uint8_t** data) { ... }

and again somewhere else

void init(...) {
     /** let's use a hash map for our content store */ 
     set_add(&hash_map_add);
}

If you provide a hash_map you would set the hash_map functions to the corresponding implementation. You have one "generic" interface, but can choose which "concrete" implementation of a data structure you will use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants