/* 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;
}
/* ************************************************** */
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;
}
/* 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;
}
/* ************************************************** */
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;
    
    /* 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;
}
Пример #6
0
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 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;
}