コード例 #1
0
/* ************************************************** */
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;
}
コード例 #2
0
ファイル: omnidirectionnal.c プロジェクト: gabrielleLQX/wsnet
/* ************************************************** */
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;
}
コード例 #3
0
ファイル: shadowing.c プロジェクト: gabrielleLQX/wsnet
/* ************************************************** */
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;
}
コード例 #4
0
ファイル: freespace.c プロジェクト: barriquello/wsnet_ec
/* ************************************************** */
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;
}
コード例 #5
0
/* 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;
}
コード例 #6
0
/* ************************************************** */
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;
}
コード例 #7
0
ファイル: threshold.c プロジェクト: gabrielleLQX/wsnet
/* ************************************************** */
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;
}
コード例 #8
0
/* ************************************************** */
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");
}
/* ************************************************** */
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;
}