示例#1
0
/* someone sent a cloud ping message to us.  we send a ping response back. */
void process_ping_msg(message_t *message, int device_index)
{
    mac_address_ptr_t sender;
    message_t response;
    memset(&response, 0, sizeof(response));

    sender = get_name(device_index, message->eth_header.h_source);

    if (db[7].d) {
        ddprintf("got ping from ");
        if (sender == NULL) {
            ddprintf(" <NULL> (from get_name)\n");
        } else {
            mac_dprint(eprintf, stderr, sender);
        }
    }

    if (sender != NULL) {
        if (db[7].d) {
            ddprintf("send response..\n");
        }
        response.message_type = ping_response_msg;
        mac_copy(response.dest, sender);
        send_cloud_message(&response);
    } else {
        ddprintf("process_ping_msg; get_name could not find mac address "
                "of sender\n");
    }
}
示例#2
0
/**
 * Parent process: Sends & Receives commands from the Cloud
 * Sets up Signal Handlers
 **/
void parent(){
	
	int user_cmnd;
	int receive_pipe_fd;
	char receive_buffer[BUFFER_SIZE];
	char *test;
	char *word;
	char cloud_request[2][50];
	int number_of_words = 0;

	struct sigaction parent_action;
	struct sigaction notification_action;

	if (access(USER_FIFO_NAME,F_OK) == -1) {
		if (mkfifo(USER_FIFO_NAME,0777) != 0) {
			fprintf(stderr,"Could not create fifo: %s\n", USER_FIFO_NAME);
			exit(EXIT_FAILURE);
		} 
	}
	
	receive_pipe_fd = open(USER_FIFO_NAME, O_RDONLY);
	
	parent_action.sa_handler = sigint_parent_handler;
	notification_action.sa_handler = sigusr1_parent_handler;
	
	sigemptyset(&parent_action.sa_mask);
	sigemptyset(&notification_action.sa_mask);

	parent_action.sa_flags = 0;
	notification_action.sa_flags = 0;
	
	sigaction(SIGINT, &parent_action, 0);
	sigaction(SIGUSR1, &notification_action, 0);
	
	while(1) {
		user_cmnd = read(receive_pipe_fd, receive_buffer, BUFFER_SIZE);
		if(user_cmnd > 0){
			test = strdup(receive_buffer);
			word = test;
			number_of_words = 0;
			while( (word = strsep(&test, " ")) != NULL && number_of_words < 2 ) {
				strcpy(cloud_request[number_of_words], word); 
				number_of_words++;
			}
			if ( (number_of_words == 2) && (word == NULL) )  {
				send_cloud_message(cloud_request[0], cloud_request[1]);
			}
		}
	}
}
示例#3
0
/* broadcast a ping message so that other cloud boxes can see that we are
 * still alive.  these messages are received via cloud protocol interface,
 * so they are more reliable than 802.11 beacons.
 * we just want to send them a little keep-alive message, and don't need
 * a response.  So we send ping_response_msg.
 */
void do_ping_neighbors()
{
    message_t message;

    memset(&message, 0, sizeof(message));

    got_interrupt[ping_neighbors] = 0;

    if (!db[46].d) { return; }

    message.message_type = ping_response_msg;

     mac_copy(message.dest, mac_address_bcast);
     send_cloud_message(&message);

    set_next_ping_alarm();
}
示例#4
0
/* send a sequence number message.  this is an addition to the protocol
 * to attempt to improve message delivery robustness at the link level,
 * at the expense of bandwidth.
 */
void send_seq(int stp_ind, byte *message, int msg_len)
{
    message_t seq_msg;

    if (!db[22].d) { return; }

    if (db[23].d) {
        ddprintf("send_seq sending <%d %d> to ",
                stp_list[stp_ind].box.send_sequence,
                msg_len);
        mac_dprint(eprintf, stderr, stp_list[stp_ind].box.name);
    }

    #if 0
    /* test-harness code; don't send a sequence message, to test the
     * protocol when a sequence message gets dropped.
     */
    if (db[24].d) {
        ddprintf("send_seq intentionally dropping packet..\n");
        db[24].d = false;
        return;
    }
    #endif

    seq_msg.message_type = sequence_msg;
    seq_msg.v.seq.sequence_num = stp_list[stp_ind].box.send_sequence;
    stp_list[stp_ind].box.awaiting_ack = true;

    if (msg_len > CLOUD_BUF_LEN) {
        seq_msg.v.seq.message_len = 0;
        stp_list[stp_ind].box.message_len = 0;
        ddprintf("send_seq got message with invalid length %d\n", msg_len);

    } else {
        seq_msg.v.seq.message_len = msg_len;
        stp_list[stp_ind].box.message_len = msg_len;
        memmove((void *) &stp_list[stp_ind].box.message, message, msg_len);
    }

    mac_copy(seq_msg.dest, stp_list[stp_ind].box.name);
    send_cloud_message(&seq_msg);

    update_ack_timer();

} /* send_seq */
示例#5
0
/* debugging (non-protocol) routine to send a ping message to every
 * neighbor box
 */
void send_nbr_pings()
{
    int i;
    message_t message;

    memset(&message, 0, sizeof(message));

    memset(&message, 0, sizeof(message));
    message.message_type = ping_msg;

    for (i = 0; i < nbr_device_list_count; i++) {
        if (db[7].d) {
            ddprintf("send ping to ");
                mac_dprint(eprintf, stderr, nbr_device_list[i].name);
        }
        mac_copy(message.dest, nbr_device_list[i].name);
        send_cloud_message(&message);
    }
}
示例#6
0
/* just got a message from raw device d.  if d is not a wds device, the
 * message is ok.  (for now we are just doing flow control over wds
 * connections.)  if it is a wds device, find the corresponding stp link
 * and return true iff we have gotten a sequence packet and are expecting
 * a message.
 */
bool_t message_ok(int d, int message_len)
{
    int i;

    if (!db[22].d) { return true; }

    if (db[23].d) { ddprintf("message_ok;\n"); }

    if (device_list[d].device_type != device_type_wds) {
        if (db[23].d) { ddprintf("    not wds; returning true\n"); }
        return true;
    }

    for (i = 0; i < stp_list_count; i++) {

        if (stp_list[i].box.has_eth_mac_addr
            || !mac_equal(stp_list[i].box.name, device_list[d].mac_address))
        {
            continue;
        }

        if (stp_list[i].box.expect_seq) {
            if (db[23].d) { ddprintf("    !expect_seq; "
                    "returning false\n"); }
            stp_list[i].box.recv_error++;
            return false;
        }

        if (stp_list[i].box.recv_message_len != message_len) {
            if (db[23].d) { ddprintf("    bad message_len; "
                    "returning false\n"); }
            stp_list[i].box.recv_error++;
            return false;
        }

        {
            message_t response;
            memset(&response, 0, sizeof(response));
            response.message_type = ack_sequence_msg;
            response.v.seq.sequence_num = stp_list[i].box.recv_sequence;
            response.v.seq.message_len = stp_list[i].box.recv_message_len;

            if (db[23].d) {
                ddprintf("    sending ack_sequence_msg <%d %d>\n",
                        stp_list[i].box.recv_sequence,
                        stp_list[i].box.recv_message_len);
            }
            mac_copy(response.dest, stp_list[i].box.name);
            if (db[24].d) {
                ddprintf("    not sending ack message..\n");
                db[24].d = false;
            } else {
                send_cloud_message(&response);
            }

            stp_list[i].box.expect_seq = true;

            if (!stp_list[i].box.received_duplicate) {
                stp_list[i].box.recv_sequence++;
            } else {
                stp_list[i].box.received_duplicate = false;
                if (db[23].d) { ddprintf("    received_duplicate; "
                        "returning false\n"); }
                return false;
            }
        }

        if (db[23].d) { ddprintf("    found it; returning true\n"); }
        return true;
    }

    if (db[23].d) { ddprintf("    didn't find it; returning false\n"); }
    return false;
}