Exemplo n.º 1
0
/**
   If this neighbor is unknown, use node to connect to neighbor.
   @return neighbor from bucket.  NULL if given self id.
*/
KDA_Neighbor*
check_neighbor(MPIRPC_Node node, KDA_Neighbor* neighbor)
{
  NOTE_FX(neighbor->id);
  KDA_Neighbor* result;

  if (neighbor_add(neighbor))
    KDA_Join(node, neighbor);

  result = neighbor_lookup(neighbor);
  return result;
}
Exemplo n.º 2
0
void
KDA_Init_conn()
{
  NOTE_F;
  // Add self to world_ranks...
  world_ranks = hashtable_create(mpi_size);
  int* heap_mpi_rank = malloc(sizeof(int));
  *heap_mpi_rank = mpi_size;
  hashtable_add(world_ranks, xheap(id), heap_mpi_rank);

  MPIRPC_Comm_add(MPI_COMM_WORLD);

  MPIRPC_Register("get_id", handle_get_id);
  MPIRPC_Register("get_rank", handle_get_rank);

  sleep(mpi_rank * 3);

  if (mpi_rank > 0)
  {
    int other_rank = rand_lt(mpi_rank);
    MPIRPC_Node node;
    MPIRPC_Node_make(MPI_COMM_WORLD, other_rank, &node);
    SHOW_I(other_rank);
    char* result = MPIRPC_Block(node, "get_id", NULL);
    KDA_ID other_id;
    sscanf(result, "%X", &other_id);
    free(result);
    KDA_Neighbor neighbor;
    KDA_Neighbor_make_id(other_id, node, &neighbor);
    neighbor_add(&neighbor);
    MPIRPC_Node dummy = {0};
    KDA_Join(dummy, &neighbor);
  }

  /*
  int client =
      cmpi_mode_first_client(mpi_rank, mpi_size, kda_nodes);
  SHOW_I(client);
  int msg = -2;
  // MPI_Send(&msg, 1, MPI_INT, client, 0, MPI_COMM_WORLD);
*/
  listen_loop();
}
Exemplo n.º 3
0
void NS_CLASS aodv_socket_process_packet(AODV_msg * aodv_msg, int len,
					 struct in_addr src,
					 struct in_addr dst,
					 int ttl, unsigned int ifindex)
{

    /* If this was a HELLO message... Process as HELLO. */
    if ((aodv_msg->type == AODV_RREP && ttl == 1 &&
	 dst.s_addr == AODV_BROADCAST)) {
	hello_process((RREP *) aodv_msg, len, ifindex);
	return;
    }

    /* Make sure we add/update neighbors */
    neighbor_add(aodv_msg, src, ifindex);

    /* Check what type of msg we received and call the corresponding
       function to handle the msg... */
    switch (aodv_msg->type) {

    case AODV_RREQ:
	rreq_process((RREQ *) aodv_msg, len, src, dst, ttl, ifindex);
	break;
    case AODV_RREP:
	DEBUG(LOG_DEBUG, 0, "Received RREP");
	rrep_process((RREP *) aodv_msg, len, src, dst, ttl, ifindex);
	break;
    case AODV_RERR:
	DEBUG(LOG_DEBUG, 0, "Received RERR");
	rerr_process((RERR *) aodv_msg, len, src, dst);
	break;
    case AODV_RREP_ACK:
	DEBUG(LOG_DEBUG, 0, "Received RREP_ACK");
	rrep_ack_process((RREP_ack *) aodv_msg, len, src, dst);
	break;
    default:
	alog(LOG_WARNING, 0, __FUNCTION__,
	     "Unknown msg type %u rcvd from %s to %s", aodv_msg->type,
	     ip_to_str(src), ip_to_str(dst));
    }
}
Exemplo n.º 4
0
static void
adv_received(struct neighbor_discovery_conn *c, const rimeaddr_t *from,
             uint16_t rtmetric)
{
    struct collect_conn *tc = (struct collect_conn *)
                              ((char *)c - offsetof(struct collect_conn, neighbor_discovery_conn));
    struct neighbor *n;

    n = neighbor_find(from);

    if(n == NULL) {
        neighbor_add(from, rtmetric, 1);
    } else {
        neighbor_update(n, rtmetric);
        PRINTF("%d.%d: updating neighbor %d.%d, etx %d\n",
               rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1],
               n->addr.u8[RIMEADDR_SIZE-2], n->addr.u8[RIMEADDR_SIZE-1], rtmetric);
    }

    update_rtmetric(tc);
}
Exemplo n.º 5
0
void
handle_join(MPIRPC_Node caller, int unique, char* args,
	    char* blob, int blob_length)
{
  SHOW_FI(caller.rank);
  KDA_ID other_id;
  int* other_rank = malloc(sizeof(int));
  sscanf(args, "%X %i", &other_id, other_rank);

  if (other_id != KDA_ID_CLIENT)
  {
    MPIRPC_Node node;
    MPIRPC_Node_make(caller.comm, caller.rank, &node);

    KDA_Neighbor neighbor;
    KDA_Neighbor_make_id(other_id, node, &neighbor);
    neighbor_add(&neighbor);
    hashtable_add(world_ranks, xheap(other_id), other_rank);
  }

  MPIRPC_Null(caller, unique);
}
Exemplo n.º 6
0
static void
received_announcement(struct announcement *a, const rimeaddr_t *from,
                      uint16_t id, uint16_t value)
{
    struct collect_conn *tc = (struct collect_conn *)
                              ((char *)a - offsetof(struct collect_conn, announcement));
    struct neighbor *n;

    n = neighbor_find(from);

    if(n == NULL) {
        neighbor_add(from, value, 1);
        PRINTF("%d.%d: new neighbor %d.%d, etx %d\n",
               rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1],
               from->u8[RIMEADDR_SIZE-2], from->u8[RIMEADDR_SIZE-1], value);
    } else {
        neighbor_update(n, value);
        PRINTF("%d.%d: updating neighbor %d.%d, etx %d\n",
               rimeaddr_node_addr.u8[RIMEADDR_SIZE-2], rimeaddr_node_addr.u8[RIMEADDR_SIZE-1],
               n->addr.u8[RIMEADDR_SIZE-2], n->addr.u8[RIMEADDR_SIZE-1], value);
    }

    update_rtmetric(tc);
}