Skip to content

Commit

Permalink
NS: Fetch defines from the NS simulator.
Browse files Browse the repository at this point in the history
Requires very recent versions of ns-3, but works anywhere.

Signed-off-by: Eddie Kohler <ekohler@gmail.com>
  • Loading branch information
Sascha Alexander Jopen authored and kohler committed Feb 6, 2013
1 parent b395c79 commit 8c07428
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/click/simclick.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ int simclick_gettimeofday(struct timeval* tv);
#define SIMCLICK_IF_PROMISC 12 // int ifid
#define SIMCLICK_IPPREFIX_FROM_NAME 13 // const char *ifname, char *buf, int len
#define SIMCLICK_GET_RANDOM_INT 14 // uint32_t *result, uint32_t max
#define SIMCLICK_GET_DEFINES 15 // char *buf, size_t *size

int simclick_sim_command(simclick_node_t *sim, int cmd, ...);
int simclick_click_command(simclick_node_t *sim, int cmd, ...);
Expand Down
23 changes: 23 additions & 0 deletions ns/nsclick.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,29 @@ int simclick_click_create(simclick_node_t *simnode, const char* router_file) {
ErrorHandler *errh = ErrorHandler::default_handler();
int before = errh->nerrors();

// Get the defines from the simulator, if supported.
if (simclick_sim_command(simnode, SIMCLICK_SUPPORTS, SIMCLICK_GET_DEFINES)) {
size_t defines_size = 512;
char *defines = (char *) malloc(defines_size);
if ((simclick_sim_command(simnode, SIMCLICK_GET_DEFINES, defines, &defines_size) == -1)) {
// Our buffer was too small, resize and try again.
defines = (char *) realloc(defines, defines_size);
simclick_sim_command(simnode, SIMCLICK_GET_DEFINES, defines, &defines_size);
}

// Process defines for click file parsing.
size_t defines_offset = 0;
while (defines_offset < defines_size) {
char *key = defines + defines_offset;
char *value = key + strlen(key) + 1;
defines_offset += (size_t) (value + strlen(value) + 1 - defines);
if (!click_lexer()->global_scope().define(key, value, false)) {
errh->error("parameter %s multiply defined", key);
}
}
free(defines);
}

Router *r = click_read_router(router_file, false, errh, false);
simnode->clickinfo = r;
if (!r)
Expand Down

0 comments on commit 8c07428

Please sign in to comment.