/* Greedy geographic routing => computing the nexthop */ struct xy_neighbor *xy_next_hop(call_t *c, position_t *position) { struct nodedata *nodedata = get_node_private_data(c); struct xy_neighbor *neighbor = NULL, *n_hop = NULL; double dist = distance(get_node_position(c->node), position); double d = dist; uint64_t clock = get_time(); /* parse neighbors */ das_init_traverse(nodedata->neighbors); while ((neighbor = (struct xy_neighbor *) das_traverse(nodedata->neighbors)) != NULL) { #ifdef CHECK_ACTIVE_NODE if ( !is_node_alive(neighbor->id) || ((nodedata->h_timeout > 0) && (clock - neighbor->time) >= nodedata->h_timeout) ) { continue; } #else if ((nodedata->h_timeout > 0) && (clock - neighbor->time) >= nodedata->h_timeout ) { continue; } #endif /* choose next hop */ if ((d = distance(&(neighbor->position), position)) < dist) { dist = d; n_hop = neighbor; } } return n_hop; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; char *filepath = NULL; /* default values */ filepath = "mobility.data"; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "file")) { filepath = param->value; } } /* open file */ if ((entitydata->file = fopen(filepath, "r")) == NULL) { fprintf(stderr, "filestatic: can not open file %s in init()\n", filepath); goto error; } set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* RECUPERATION DES PROPRIETE DE PROTOCOLE*/ int init(call_t *c, void *params) { struct protocoleData *entitydata = malloc(sizeof(struct protocoleData)); param_t *param; /* init entity variables */ entitydata->debug = 0; /* reading the "init" markup from the xml config file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "debug")) { if (get_param_integer(param->value, &(entitydata->debug))) { goto error; } } } //INITAILISATION DES FICHIER DE SORTIES init_files(); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
void add_neighbor(call_t *c, struct routing_header *header) { struct nodedata *nodedata = get_node_private_data(c); struct neighbor *neighbor = NULL; /* check wether neighbor already exists */ das_init_traverse(nodedata->neighbors); while ((neighbor = (struct neighbor *) das_traverse(nodedata->neighbors)) != NULL) { if (neighbor->id == header->src) { neighbor->position.x = header->src_pos.x; neighbor->position.y = header->src_pos.y; neighbor->position.z = header->src_pos.z; neighbor->time = get_time(); return; } } neighbor = (struct neighbor *) malloc(sizeof(struct neighbor)); neighbor->id = header->src; neighbor->position.x = header->src_pos.x; neighbor->position.y = header->src_pos.y; neighbor->position.z = header->src_pos.z; neighbor->time = get_time(); das_insert(nodedata->neighbors, (void *) neighbor); return; }
/* ************************************************** */ int setnode(call_t *c, void *params) { struct nodedata *nodedata = malloc(sizeof(struct nodedata)); param_t *param; uint64_t min_pausetime, max_pausetime; /* default values */ get_node_position(c->node)->x = get_random_x_position(); get_node_position(c->node)->y = get_random_y_position(); get_node_position(c->node)->z = get_random_z_position(); nodedata->pausetime = 2000000000; min_pausetime = 0; max_pausetime = 0; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "x")) { if (get_param_x_position(param->value, &(get_node_position(c->node)->x))) { goto error; } } if (!strcmp(param->key, "y")) { if (get_param_y_position(param->value, &(get_node_position(c->node)->y))) { goto error; } } if (!strcmp(param->key, "z")) { if (get_param_z_position(param->value, &(get_node_position(c->node)->z))) { goto error; } } if (!strcmp(param->key, "pausetime")) { if (get_param_time(param->value, &(nodedata->pausetime))) { goto error; } } if (!strcmp(param->key, "min-pausetime")) { if (get_param_time(param->value, &min_pausetime)) { goto error; } } if (!strcmp(param->key, "max-pausetime")) { if (get_param_time(param->value, &max_pausetime)) { goto error; } } } if (min_pausetime < max_pausetime ) { nodedata->pausetime = get_random_time_range(min_pausetime, max_pausetime); } set_node_private_data(c, nodedata); return 0; error: free(nodedata); return -1; }
/* ************************************************** */ void rx_xy_hello(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); struct xy_hello_p *hello = (struct xy_hello_p *) (packet->data + nodedata->overhead); struct xy_neighbor *neighbor; /* check for existing neighbors */ das_init_traverse(nodedata->neighbors); while ((neighbor = (struct xy_neighbor *) das_traverse(nodedata->neighbors)) != NULL) { if (neighbor->id == hello->src) { neighbor->position.x = hello->position.x; neighbor->position.y = hello->position.y; neighbor->position.z = hello->position.z; neighbor->time = get_time(); packet_dealloc(packet); return; } } /* new neighbor */ neighbor = (struct xy_neighbor *) malloc(sizeof(struct xy_neighbor)); neighbor->id = hello->src; neighbor->position.x = hello->position.x; neighbor->position.y = hello->position.y; neighbor->position.z = hello->position.z; neighbor->time = get_time(); das_insert(nodedata->neighbors, (void *) neighbor); packet_dealloc(packet); return; }
void *get_entity_params(nodeid_t node, entityid_t entity, bundleid_t bundle) { dflt_param_t *dflt_param; dflt_param_t *best = NULL; int match = 0; das_init_traverse(dflt_params); while ((dflt_param = (dflt_param_t *) das_traverse(dflt_params)) != NULL) { int c_match = 0; if ((dflt_param->nodeid != -1) && (dflt_param->nodeid != node)) continue; if (dflt_param->entityid != entity) continue; if ((dflt_param->bundleid != -1) && (dflt_param->bundleid != bundle)) continue; if (dflt_param->nodeid == node) c_match++; if (dflt_param->entityid == entity) c_match++; if (dflt_param->bundleid == bundle) c_match++; if (c_match > match) { best = dflt_param; match = c_match; } } if (best == NULL) return best; return best->params; }
/* RECUPERATION DES PROPRIETES DE PROTOCOLE*/ int init(call_t *c, void *params) { struct protocoleData *entitydata = malloc(sizeof(struct protocoleData)); param_t *param; /* init entity variables */ entitydata->alpha = 1; entitydata->c = 0; entitydata->eps = 0.01; entitydata->debug = 0; //entitydata->debut = time_seconds_to_nanos(3); //entitydata->periodEVE = time_seconds_to_nanos(1); /* reading the "init" markup from the xml config file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "alpha")) { if (get_param_integer(param->value, &(entitydata->alpha))) { goto error; } } if (!strcmp(param->key, "c")) { if (get_param_integer(param->value, &(entitydata->c))) { goto error; } } if (!strcmp(param->key, "eps")) { if (get_param_double(param->value, &(entitydata->eps))) { goto error; } } if (!strcmp(param->key, "debut")) { if (get_param_integer(param->value, &(entitydata->debug))) { goto error; } } } init_files(); set_entity_private_data(c, entitydata); printf("dlbip : alpha : %d ; c : %d\n", entitydata->alpha, entitydata->c); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ void monitor_event(call_t *c) { struct entitydata *entitydata = get_entity_private_data(c); struct monitor_callback *callback; /* log energy map */ log_energymap(c); /* call callbacks */ das_init_traverse(entitydata->callbacks); while ((callback = (struct monitor_callback *) das_traverse(entitydata->callbacks)) != NULL) { callback->callback(&(callback->c), callback->arg); } }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); char filenode[100]; param_t *param; /* default values */ entitydata->callbacks = das_create(); entitydata->nbr_nodes = get_node_count(); strcpy(entitydata->map_prefix, "energymap"); strcpy(entitydata->directory,"./"); entitydata->map_period = 1000000000; das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { int i = 0; if (!strcmp(param->key, "directory")) { strcpy(entitydata->directory, param->value); goto parse_key_ok; } if (!strcmp(param->key, "prefix")) { strcpy(entitydata->map_prefix, param->value); goto parse_key_ok; } if (!strcmp(param->key, "map-period")) { if (get_param_time(param->value, &(entitydata->map_period))) { goto error; } goto parse_key_ok; } (void) fprintf(stderr, "WARNING: token %s is not recognized\n", param->key); parse_key_ok: i++; } /* open node activity file */ sprintf(filenode, "%s/%s.data", entitydata->directory, "activenodes"); if ((entitydata->filenode = fopen(filenode, "w")) == NULL) { fprintf(stderr, "NRJ monitor: can not open file %s !\n", filenode); goto error; } set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int setnode(call_t *c, void *params) { struct nodedata *nodedata = malloc(sizeof(struct nodedata)); param_t *param; /* default values */ nodedata->neighbors = das_create(); nodedata->overhead = -1; nodedata->hello_tx = 0; nodedata->hello_rx = 0; nodedata->data_tx = 0; nodedata->data_rx = 0; nodedata->data_noroute = 0; nodedata->data_hop = 0; nodedata->start = 0; nodedata->hop = 32; nodedata->period = 1000000000; nodedata->timeout = 2500000000ull; /* get params */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "start")) { if (get_param_time(param->value, &(nodedata->start))) { goto error; } } if (!strcmp(param->key, "period")) { if (get_param_time(param->value, &(nodedata->period))) { goto error; } } if (!strcmp(param->key, "hop")) { if (get_param_integer(param->value, &(nodedata->hop))) { goto error; } } if (!strcmp(param->key, "timeout")) { if (get_param_time(param->value, &(nodedata->timeout))) { goto error; } } } set_node_private_data(c, nodedata); return 0; error: free(nodedata); return -1; }
/* ************************************************** */ int setnode(call_t *c, void *params) { struct nodedata *nodedata = malloc(sizeof(struct nodedata)); param_t *param; /* Find all the neighbors for this node */ nodedata->neighbors = das_create(); nodedata->curr_dst = -1; nodedata->curr_nexthop = NULL; /* default values */ nodedata->overhead = -1; nodedata->hop = 32; nodedata->range = 1; nodedata->random_nexthop = 0; /* Get parameters from config file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { /* Hop-limit */ if (!strcmp(param->key, "hop")) { if (get_param_integer(param->value, &(nodedata->hop))) { goto error; } } /* Range in which neighbors are selected */ if (!strcmp(param->key, "range")) { if (get_param_double(param->value, &(nodedata->range))) { goto error; } } /* Randomize the choice of the next hop. 0 means never (always * take the nearest one from the destination), and a value >= 1 * randomizes the next hop every "value" time */ if (!strcmp(param->key, "random")) { if (get_param_integer(param->value, &(nodedata->random_nexthop))) { goto error; } } } nodedata->random_counter = nodedata->random_nexthop; set_node_private_data(c, nodedata); return 0; error: free(nodedata); return -1; }
/* ************************************************** */ int setnode(call_t *c, void *params) { struct nodedata *nodedata = malloc(sizeof(struct nodedata)); param_t *param; /* default values */ nodedata->Ts = 91; nodedata->channel = 0; nodedata->power = 0; nodedata->modulation = -1; nodedata->mindBm = -92; nodedata->sleep = 0; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "sensibility")) { if (get_param_double(param->value, &(nodedata->mindBm))) { goto error; } } if (!strcmp(param->key, "T_s")) { if (get_param_time(param->value, &(nodedata->Ts))) { goto error; } } if (!strcmp(param->key, "channel")) { if (get_param_integer(param->value, &(nodedata->channel))) { goto error; } } if (!strcmp(param->key, "dBm")) { if (get_param_double(param->value, &(nodedata->power))) { goto error; } } if (!strcmp(param->key, "modulation")) { if (get_param_entity(param->value, &(nodedata->modulation))) { goto error; } } } set_node_private_data(c, nodedata); return 0; error: free(nodedata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; char *filepath = NULL; int src, dst; double proba; FILE *file; char str[128]; /* default values */ filepath = "propagation.data"; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "file")) { filepath = param->value; } } /* open file */ if ((file = fopen(filepath, "r")) == NULL) { fprintf(stderr, "filestatic: can not open file %s in init()\n", filepath); goto error; } /* extract link success probability */ entitydata->node_cnt = get_node_count(); entitydata->success = malloc(sizeof(double) * entitydata->node_cnt *entitydata->node_cnt); for (src = 0; src < entitydata->node_cnt; src++) { for (dst = 0; dst < entitydata->node_cnt; dst++) { *(entitydata->success + (src * entitydata->node_cnt) + dst) = MIN_DBM; } } fseek(file, 0L, SEEK_SET); while (fgets(str, 128, file) != NULL) { sscanf(str, "%d %d %lf\n", &src, &dst, &proba); *(entitydata->success + (src * entitydata->node_cnt) + dst) = proba; } fclose(file); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
int xy_is_nearest(call_t *c, position_t *sink_position) { struct nodedata *nodedata = get_node_private_data(c); struct xy_neighbor *neighbor = NULL; double dist = distance(get_node_position(c->node), sink_position); das_init_traverse(nodedata->neighbors); while ((neighbor = (struct xy_neighbor *) das_traverse(nodedata->neighbors)) != NULL) { if ((distance(&(neighbor->position), sink_position) < dist) && (is_node_alive(neighbor->id))) { return 0; } } return 1; }
/* ************************************************** */ int setnode(call_t *c, void *params) { struct nodedata *nodedata = malloc(sizeof(struct nodedata)); param_t *param; /* default values */ nodedata->noise = 0; nodedata->gain_tx = 0; nodedata->gain_rx = 0; nodedata->angle.xy = get_random_double_range(0, 2 * M_PI); nodedata->angle.z = get_random_double_range(0, 2 * M_PI); /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "gain-tx")) { if (get_param_double(param->value, &(nodedata->gain_tx))) { goto error; } } if (!strcmp(param->key, "gain-rx")) { if (get_param_double(param->value, &(nodedata->gain_rx))) { goto error; } } if (!strcmp(param->key, "loss")) { if (get_param_double(param->value, &(nodedata->noise))) { goto error; } } if (!strcmp(param->key, "angle-xy")) { if (get_param_double_range(param->value, &(nodedata->angle.xy), 0, 2*M_PI)) { goto error; } } if (!strcmp(param->key, "angle-z")) { if (get_param_double_range(param->value, &(nodedata->angle.z), 0, 2*M_PI)) { goto error; } } } set_node_private_data(c, nodedata); return 0; error: free(nodedata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; double frequency = 868; /* default values */ entitydata->pathloss = 2.0; entitydata->deviation = 4.0; entitydata->dist0 = 1.0; entitydata->last_rxdBm = 9999; entitydata->Pr0 = 0.0; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "pathloss")) { if (get_param_distance(param->value, &(entitydata->pathloss))) { goto error; } } if (!strcmp(param->key, "frequency_MHz")) { if (get_param_double(param->value, &(frequency))) { goto error; } } if (!strcmp(param->key, "deviation")) { if (get_param_double(param->value, &(entitydata->deviation))) { goto error; } } if (!strcmp(param->key, "dist0")) { if (get_param_double(param->value, &(entitydata->dist0))) { goto error; } } } /* update factor */ entitydata->factor = 300 / (4 * M_PI * frequency); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; double frequency = 868; /* default values */ entitydata->pathloss = 2.0; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "frequency_MHz")) { if (get_param_double(param->value, &(frequency))) { goto error; } } if (!strcmp(param->key, "pathloss")) { if (get_param_double(param->value, &(entitydata->pathloss))) { goto error; } } } /* * Compute attenuation at reference distance d=1 with reference power Pt=1 : * * Pt * Gt * Gr * lambda^2 * Pr(d) = ------------------------- * (4 * pi * d)^2 * L * * Note: rxmW = Pt * Gt * Gr, and L = 1 * * cf p71 ref "Wireless Communications: Principles and Practice", Theodore Rappaport, 1996. * */ entitydata->Pr0 = mW2dBm((300 / (4 * M_PI * frequency)) * (300 / (4 * M_PI * frequency))); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ int modulation_bootstrap(void) { entity_t *entity; das_init_traverse(modulation_entities); while ((entity = (entity_t *) das_traverse(modulation_entities)) != NULL) { call_t c = {entity->id, -1, -1}; if (entity->model->type != MODELTYPE_MODULATION) { fprintf(stderr, "entity %s is not a modulation model\n", entity->name); return -1; } if (entity->bootstrap) { entity->bootstrap(&c); } } return 0; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; /* default values */ entitydata->step = 2; /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "step")) { if (get_param_double(param->value, &(entitydata->step))) { goto error; } } } set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
/* ************************************************** */ struct neighbor* get_nexthop(call_t *c, position_t *dst) { struct nodedata *nodedata = get_node_private_data(c); struct neighbor *neighbor = NULL, *n_hop = NULL; uint64_t clock = get_time(); double dist = distance(get_node_position(c->node), dst); double d = dist; /* parse neighbors */ das_init_traverse(nodedata->neighbors); while ((neighbor = (struct neighbor *) das_traverse(nodedata->neighbors)) != NULL) { if ((nodedata->timeout > 0) && (clock - neighbor->time) >= nodedata->timeout ) { continue; } /* choose next hop */ if ((d = distance(&(neighbor->position), dst)) < dist) { dist = d; n_hop = neighbor; } } return n_hop; }
/* ************************************************** */ int setnode(call_t *c, void *params) { struct nodedata *nodedata = malloc(sizeof(struct nodedata)); param_t *param; nodedata->clock = 0; nodedata->state = STATE_IDLE; nodedata->packets = das_create(); nodedata->txbuf = NULL; nodedata->cca = 1; nodedata->cs = 1; nodedata->EDThreshold = EDThresholdMin; nodedata->MaxCSMABackoffs = macMaxCSMABackoffs; nodedata->MaxBE = macMaxBE; nodedata->MinBE = macMinBE; das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "cca")) { if (get_param_integer(param->value, &(nodedata->cca))) { goto error; } } if (!strcmp(param->key, "cs")) { if (get_param_integer(param->value, &(nodedata->cs))) { goto error; } } if (!strcmp(param->key, "max-csma-backoffs")) { if (get_param_integer(param->value, &(nodedata->MaxCSMABackoffs))) { goto error; } } if (!strcmp(param->key, "max-backoff-exponent")) { if (get_param_integer(param->value, &(nodedata->MaxBE))) { goto error; } } if (!strcmp(param->key, "min-backoff-exponent")) { if (get_param_integer(param->value, &(nodedata->MinBE))) { goto error; } } if (!strcmp(param->key, "cca-threshold")) { if (get_param_double(param->value, &(nodedata->EDThreshold))) { goto error; } } } if (nodedata->EDThreshold < EDThresholdMin) { nodedata->EDThreshold = EDThresholdMin; } if ((nodedata->MaxCSMABackoffs < macMaxCSMABackoffsMin) || (nodedata->MaxCSMABackoffs > macMaxCSMABackoffsMax)) { nodedata->MaxCSMABackoffs = macMaxCSMABackoffs; } if ((nodedata->MaxBE < macMaxBEMin) || (nodedata->MaxBE > macMaxBEMax)) { nodedata->MaxBE = macMaxBE; } if ((nodedata->MinBE < macMinBEMin) || (nodedata->MinBE > nodedata->MaxBE)) { nodedata->MinBE = macMinBE; } set_node_private_data(c, nodedata); return 0; error: free(nodedata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct _env_data *entitydata = malloc(sizeof(struct _env_data)); char *filepath = "collection_ctrl.data"; int line; struct _collec_event *event; param_t *param; char str[128]; char event_str[30]; FILE *file; /* We use a sorted list for the events (sorted by time) */ entitydata->events = sodas_create(event_compare); /* Get parameters from the configuration file */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "file")) { filepath = param->value; } } /* Open the data collection scheme file */ if ((file = fopen(filepath, "r")) == NULL) { DBG("ERROR: cannot open file %s in init()\n", filepath); goto error; } /* Save the events in a data structure */ /* Structure of the file is: * <time> <node id> <event type> <value> */ fseek(file, 0L, SEEK_SET); line = 1; while (fgets(str, 128, file) != NULL) { event = malloc(sizeof(struct _collec_event)); memset(event_str, 0, sizeof(event_str)); if (event == NULL) { DBG("ERROR: malloc failed\n"); goto error; } if (str[0] == '#' || str[0] == '\n') { /* Line is a comment or an empty line */ line++; continue; } if (sscanf(str, "%"PRId64" %d %s %d\n", &event->time, &event->node_id, event_str, &event->event_value) != 4) { DBG("ERROR: cannot read event in file %s, line %d\n", filepath, line); free(event); goto error; } if (!strncmp(event_str, "APP_TIME_DRV", sizeof(event_str))) { event->event_type = APP_TIME_DRV; } else if (!strncmp(event_str, "APP_EVENT_DRV", sizeof(event_str))) { event->event_type = APP_EVENT_DRV; } else if (!strncmp(event_str, "APP_QUERY_DRV", sizeof(event_str))) { event->event_type = APP_QUERY_DRV; } else if (!strncmp(event_str, "APP_PAYLOAD_SIZE", sizeof(event_str))) { event->event_type = APP_PAYLOAD_SIZE; } else if (!strncmp(event_str, "ENV_EVENT", sizeof(event_str))) { event->event_type = ENV_EVENT; } else if (!strncmp(event_str, "QUERY_MSG", sizeof(event_str))) { event->event_type = QUERY_MSG; } else if (!strncmp(event_str, "CHANGE_APP_DST", sizeof(event_str))) { event->event_type = CHANGE_APP_DST; } else { DBG("ERROR: event type %s unknown in file %s, line %d\n", event_str, filepath, line); free(event); goto error; } //DBG("EVENT: %"PRId64" %d %d %d\n", // event->time, event->node_id, // event->event_type, event->event_value); if (event->node_id >= get_node_count()) { DBG("ERROR: node id %d (line %d) does not exist, " "skipping this event \n", event->node_id, line); free(event); } else { /* Insert the event in the sorted data structure */ sodas_insert(entitydata->events, &event->time, event); } line++; } /* Close the opened file */ fclose(file); set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; }
int setnode(call_t *c, void *params) { struct nodedata *nodedata = malloc(sizeof(struct nodedata)); param_t *param; int i = MAX_METADATA; int j = MAX_SOURCE; int k = MAX_SINK; /* default values */ nodedata->h_start = 0; nodedata->h_period = 1000000000; nodedata->h_timeout = nodedata->h_period * 2.5; nodedata->h_nbr = -1; nodedata->neighbors = das_create(); while (i--) { nodedata->d_source[i] = -1; nodedata->d_value[i] = -1; nodedata->d_seq[i] = -1; nodedata->d_hop[i] = -1; nodedata->d_time[i] = -1; } while (j--) { nodedata->s_seq[j] = -1; } while (k--) { nodedata->r_seq[k] = -1; } /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "hello-start")) { if (get_param_time(param->value, &(nodedata->h_start))) { fprintf(stderr,"[XY] Error while reading the hello-start parameter ! (%s)\n",param->value); goto error; } } if (!strcmp(param->key, "hello-period")) { if (get_param_time(param->value, &(nodedata->h_period))) { fprintf(stderr,"[XY] Error while reading the hello-period parameter ! (%s)\n",param->value); goto error; } } if (!strcmp(param->key, "hello-timeout")) { if (get_param_time(param->value, &(nodedata->h_timeout))) { fprintf(stderr,"[XY] Error while reading the hello-timeout parameter ! (%s)\n",param->value); goto error; } } if (!strcmp(param->key, "hello-nbr")) { if (get_param_integer(param->value, &(nodedata->h_nbr))) { fprintf(stderr,"[XY] Error while reading the hello-nbr parameter ! (%s)\n",param->value); goto error; } } } set_node_private_data(c, nodedata); return 0; error: free(nodedata); return -1; }
/* ************************************************** */ int init(call_t *c, void *params) { struct entitydata *entitydata = malloc(sizeof(struct entitydata)); param_t *param; double frequency = 868; /* default values */ entitydata->ht = 1; entitydata->hr = 1; entitydata->pathloss = 2.0; entitydata->deviation = 4.0; entitydata->dist0 = 1.0; entitydata->last_rxdBm = 9999; entitydata->Pr0 = 0.0; entitydata->propagation = FREESPACE; entitydata->m = 1.0; entitydata->period = 0; // coorelation time /* get parameters */ das_init_traverse(params); while ((param = (param_t *) das_traverse(params)) != NULL) { if (!strcmp(param->key, "propagation")) { if (!strcmp(param->value, "freespace")) { entitydata->propagation = FREESPACE; } else if (!strcmp(param->value, "tworayground")) { entitydata->propagation = TWORAYGROUND; } else if (!strcmp(param->value, "logdistance")) { entitydata->propagation = LOGDISTANCE; } else if (!strcmp(param->value, "shadowing")) { entitydata->propagation = LOGNORMAL; } else { fprintf(stderr,"\n[nakagami_fading] Unknown propagation type (%s) !\n", param->value); fprintf(stderr,"[nakagami_fading] Possible propagation models are: freespace, tworayground, logdistance and shadowing\n\n"); goto error; } } if (!strcmp(param->key, "pathloss")) { if (get_param_distance(param->value, &(entitydata->pathloss))) { goto error; } } if (!strcmp(param->key, "frequency_MHz")) { if (get_param_double(param->value, &(frequency))) { goto error; } } if (!strcmp(param->key, "deviation")) { if (get_param_double(param->value, &(entitydata->deviation))) { goto error; } } if (!strcmp(param->key, "dist0")) { if (get_param_double(param->value, &(entitydata->dist0))) { goto error; } } if (!strcmp(param->key, "m")) { if (get_param_double(param->value, &(entitydata->m))) { goto error; } } } /* update factor */ entitydata->factor = 300 / (4 * M_PI * frequency); entitydata->crossover_distance = entitydata->ht * entitydata->hr / entitydata->factor; set_entity_private_data(c, entitydata); return 0; error: free(entitydata); return -1; printf("Parameters for nakagmi-m model are error.\n"); }
/** * Forge response to a node connect request */ static void worldsens_rx_connect_req(struct _worldsens_c_connect_req *pkt, struct sockaddr_in *addr) { node_t *node = get_node_by_id(worldsens_register_node_infos(pkt->node_id)); bundle_t *bundle = get_bundle_by_id(node->bundle); entity_t *entity; union _worldsens_pkt pkt0; int offset = 0; int i; int nb_mod = 0; if (node->worldsens != NODE_DISCONNECTED) { //PRINT_WORLDSENS("wsnet:worldsens_rx_connect_req (%"PRId64"): node %d not disconnected!\n", get_time(), node->id); return; } /* forge response*/ pkt0.cnx_rsp_ok.type = WORLDSENS_S_CONNECT_RSP_OK; pkt0.cnx_rsp_ok.seq = ws_seq; pkt0.cnx_rsp_ok.rp_next = ws_nsyncseq; pkt0.cnx_rsp_ok.rp_duration = ws_nsync - ws_csync; pkt0.cnx_rsp_ok.n_antenna_id = bundle->antenna.size; pkt0.cnx_rsp_ok.n_measure_id = measures.size; /* pkt->cnx_rsp_ok.names_and_ids format: */ /*|***************antennas***************|**************modulations*************|***************measures***************|*/ /*|ant id1|ant name1|ant id2|ant name2|..|mod id1|mod name1|mod id2|mod name2|..|mea id1|mea name1|mea id2|mea name2|..|*/ /* *********************************************************************************************************************/ /* forge list of available antennas */ for (i = 0; i < bundle->antenna.size; i++) { entity = get_entity_by_id(bundle->antenna.elts[i]); /* PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): antenna '%s' (id %d) available\n", get_time(), entity->name, entity->id); */ *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = entity->id; offset += sizeof(uint32_t); strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, entity->name); offset += strlen(entity->name) + 1; } /* forge list of available modulations */ das_init_traverse(modulation_entities); while ((entity = (entity_t *) das_traverse(modulation_entities)) != NULL) { /*PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): modulation '%s' (id %d) available\n", get_time(), entity->library.name, entity->id); */ *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = entity->id; offset += sizeof(uint32_t); strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, entity->library.name); offset += strlen(entity->library.name) + 1; nb_mod++; if ((nb_mod == 1) || (strcmp(entity->library.name, "modulation_none") == 0)) { ws_default_mod = entity->id; } } pkt0.cnx_rsp_ok.n_modulation_id = nb_mod; /* forge list of available measure */ for (i = 0; i < measures.size; i++) { measure_t *measure = get_measure_by_id(i); /* PRINT_WORLDSENS("wsnet: worldsens_rx_connect_req (%"PRId64"): measure '%s' (id %d) available\n", get_time(), measure->name, measure->id); */ *((uint32_t *) (pkt0.cnx_rsp_ok.names_and_ids + offset)) = measure->id; offset += sizeof(uint32_t); strcpy(pkt0.cnx_rsp_ok.names_and_ids + offset, measure->name); offset += strlen(measure->name) + 1; } /* give birth to node */ ws_connected++; node->worldsens = NODE_CONNECTED; node_birth(node->id); WSNET_S_DBG_DBG("WSNET2:: <-- CONNECT(%d/%d) (ip: %d)\n", ws_connected, ws_count, pkt->node_id); WSNET_S_DBG_DBG("WSNET2:: --> RP (seq: %"PRId64") (rp seq: %"PRId64", period: %"PRId64", rp:%"PRId64")\n", ws_seq, ws_nsyncseq, ws_nsync - ws_csync, ws_nsync); /* send response */ worldsens_packet_display(&pkt0); worldsens_packet_hton(&pkt0); wsens_srv_send(addr, (char *) &pkt0, sizeof(struct _worldsens_s_connect_rsp_ok)); }
/* Get the best next hop for a specific destination */ struct neighbor* get_nexthop(call_t *c, nodeid_t dst) { struct nodedata *nodedata = get_node_private_data(c); struct neighbor *neighbor = NULL, *n_hop = NULL; double dist = distance(get_node_position(c->node), get_node_position(dst)); double d = dist; if (nodedata->curr_dst != dst || (nodedata->curr_nexthop != NULL && !is_node_alive(nodedata->curr_nexthop->id))) { /* If the destination is different from the last one, * or if the current next hop is dead, reinit the * random counters (to force the selection of a * new next_hop) */ nodedata->random_counter = nodedata->random_nexthop; } if (nodedata->random_nexthop == 0) { /* We keep the current next hop if * - next hop is not randomized * - the next hop is is still alive * - the destination is the same */ if (nodedata->curr_nexthop != NULL && nodedata->curr_dst == dst && is_node_alive(nodedata->curr_nexthop->id)) { return nodedata->curr_nexthop; } /* Parse neighbors */ das_init_traverse(nodedata->neighbors); while ((neighbor = (struct neighbor *) das_traverse(nodedata->neighbors)) != NULL) { /* Choose next hop (the one the nearest from the final dst) * and verify if it is still alive */ if ((d = distance(&(neighbor->position), get_node_position(dst))) < dist && is_node_alive(neighbor->id)) { dist = d; n_hop = neighbor; } } } else if (nodedata->random_counter == nodedata->random_nexthop) { void *next_hops = das_create(); int nh = 0; double nexthop_dst = 0; /* Random geographic routing : we choose randomly among * the neighbors that are nearer from the destination * than the current node. */ das_init_traverse(nodedata->neighbors); while ((neighbor = (struct neighbor *) das_traverse(nodedata->neighbors)) != NULL) { /* If the neighbor happens to be the final destination, * then we just choose it as the next hop */ if (neighbor->id == dst) { n_hop = neighbor; goto out; } /* Store the neighbors that are nearer from the destination * and that are still alive */ nexthop_dst = distance(&(neighbor->position), get_node_position(dst)); if (nexthop_dst < dist && is_node_alive(neighbor->id)) { das_insert(next_hops, (void *) neighbor); } } /* Choose next hop randomly among the list */ nh = das_getsize(next_hops); if (nh > 0) { int rnd = get_random_integer_range(1, nh); while (rnd--) { neighbor = das_pop(next_hops); } n_hop = neighbor; } das_destroy(next_hops); } else /* nodedata->random_counter != nodedata->random_nexthop */ { /* Keep the current next hop */ n_hop = nodedata->curr_nexthop; } out: nodedata->random_counter--; if (nodedata->random_counter <= 0) { nodedata->random_counter = nodedata->random_nexthop; } /* Save the current next hop and destination */ nodedata->curr_nexthop = n_hop; nodedata->curr_dst = dst; return n_hop; }