/* ************************************************** */ void cs_init(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); /* log */ if (nodedata->tx_busy != -1) { PRINT_REPLAY("radio-tx1 %"PRId64" %d\n", get_time(), c->node); } if (nodedata->rx_busy != -1) { PRINT_REPLAY("radio-rx1 %"PRId64" %d\n", get_time(), c->node); } /* init cs */ nodedata->tx_busy = -1; nodedata->rx_busy = -1; nodedata->rxdBm = MIN_DBM; }
/* ************************************************** */ void tx(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); array_t *down = get_entity_bindings_down(c); int i = down->size; /* radio sleep */ if (nodedata->sleep) { packet_dealloc(packet); return; } /* radio activity */ cs_init(c); nodedata->tx_busy = packet->id; /* log tx */ PRINT_REPLAY("radio-tx0 %"PRId64" %d 50\n", get_time(), c->node); /* transmit to antenna */ while (i--) { packet_t *packet_down; if (i > 0) { packet_down = packet_clone(packet); } else { packet_down = packet; } c->from = down->elts[i]; MEDIA_TX(c, packet_down); } return; }
/* ************************************************** */ void rx(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); array_t *up = get_entity_bindings_up(c); int i = up->size; /* radio sleep */ if (nodedata->sleep) { packet_dealloc(packet); return; } /* half-duplex */ if (nodedata->tx_busy != -1) { packet_dealloc(packet); return; } /* handle carrier sense */ if (nodedata->rx_busy == packet->id) { nodedata->rx_busy = -1; nodedata->rxdBm = MIN_DBM; /* log rx */ PRINT_REPLAY("radio-rx1 %"PRId64" %d\n", get_time(), c->node); /* consume energy */ battery_consume_rx(c, packet->duration); } else { packet_dealloc(packet); return; } /* check wether the reception has killed us */ if (!is_node_alive(c->node)) { packet_dealloc(packet); return; } /* drop packet depending on the FER */ if (get_random_double() < packet->PER) { packet_dealloc(packet); return; } /* forward to upper layers */ while (i--) { call_t c_up = {up->elts[i], c->node, c->entity}; packet_t *packet_up; if (i > 0) { packet_up = packet_clone(packet); } else { packet_up = packet; } RX(&c_up, packet_up); } return; }
/* ************************************************** */ int bootstrap(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); PRINT_REPLAY("mobility %"PRId64" %d %lf %lf %lf\n", get_time(), c->node, get_node_position(c->node)->x, get_node_position(c->node)->y, get_node_position(c->node)->z); nodedata->lupdate = get_time(); nodedata->nupdate = get_time() + nodedata->pausetime; return 0; }
void cs(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); /* radio sleep */ if (nodedata->sleep) { return; } /* half-duplex */ if (nodedata->tx_busy != -1) { return; } /* check sensibility */ if (packet->rxdBm < nodedata->mindBm) { return; } /* check channel */ if (nodedata->channel != packet->channel) { return; } /* check Ts */ if (nodedata->Ts != (packet->Tb*radio_get_modulation_bit_per_symbol(c))) { return; } /* check channel */ if (packet->modulation != nodedata->modulation) { return; } /* capture effect */ if (packet->rxdBm > nodedata->rxdBm) { nodedata->rxdBm = packet->rxdBm; nodedata->rx_busy = packet->id; /* log cs */ PRINT_REPLAY("radio-rx0 %"PRId64" %d\n", get_time(), c->node); return; } return; }
void tx_end(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); /* consume energy */ battery_consume_tx(c, packet->duration, nodedata->power); /* check wether the reception has killed us */ if (!is_node_alive(c->node)) { return; } /* log tx */ if (nodedata->tx_busy == packet->id) { PRINT_REPLAY("radio-tx1 %"PRId64" %d\n", get_time(), c->node); nodedata->tx_busy = -1; } return; }
/* ************************************************** */ void update_position(call_t *c) { struct nodedata *nodedata = get_node_private_data(c); while (nodedata->lupdate < get_time()) { if (nodedata->nupdate <= get_time()) { nodedata->lupdate = nodedata->nupdate; nodedata->nupdate += nodedata->pausetime; 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(); PRINT_REPLAY("mobility %"PRId64" %d %lf %lf %lf\n", nodedata->lupdate, c->node, get_node_position(c->node)->x, get_node_position(c->node)->y, get_node_position(c->node)->z); } else { nodedata->lupdate = get_time(); break; } } return; }
/* ************************************************** */ int bootstrap(call_t *c) { PRINT_REPLAY("mobility %"PRId64" %d %lf %lf %lf\n", get_time(), c->node, get_node_position(c->node)->x, get_node_position(c->node)->y, get_node_position(c->node)->z); return 0; }