예제 #1
0
void
packerMAC::printMyHdrFields(Packet *p)
{

	hdr_mac *hmac = HDR_MAC(p);

	if (n_bits[0] != 0)
		cout << "\033[0;45;30m ftype:\033[0m " << hmac->ftype_ << " "
			 << hex_bytes(hmac->ftype_, n_bits[0]) << std::endl;
	if (n_bits[1] != 0)
		cout << "\033[0;45;30m macSA:\033[0m " << hmac->macSA_ << " "
			 << hex_bytes(hmac->macSA_, n_bits[1]) << std::endl;
	if (n_bits[2] != 0)
		cout << "\033[0;45;30m macDA:\033[0m " << hmac->macDA_ << " "
			 << hex_bytes(hmac->macDA_, n_bits[2]) << std::endl;
	if (n_bits[3] != 0)
		cout << "\033[0;45;30m hdr_type:\033[0m " << hmac->hdr_type_ << " "
			 << hex_bytes(hmac->hdr_type_, n_bits[3]) << std::endl;
	if (n_bits[4] != 0)
		cout << "\033[0;45;30m txtime:\033[0m " << hmac->txtime_ << " "
			 << hex_bytes(hmac->txtime_) << std::endl;
	if (n_bits[5] != 0)
		cout << "\033[0;45;30m sstime:\033[0m " << hmac->sstime_ << " "
			 << hex_bytes(hmac->sstime_) << std::endl;
	if (n_bits[6] != 0)
		cout << "\033[0;45;30m padding:\033[0m " << hmac->padding_ << " "
			 << hex_bytes(hmac->padding_, n_bits[6]) << std::endl;
	// cout << "\033[0;41;30m packerMAC::printMyHdrField WARNING \033[0m, Field
	// index " << field << " does not exist or its printing is not implemented."
	// << std::endl;
}
예제 #2
0
void CsmaAloha::initPkt( Packet* p, CSMA_PKT_TYPE type, int dest_addr ) {
    hdr_cmn* ch = hdr_cmn::access(p);
    hdr_mac* mach = HDR_MAC(p);

    int curr_size = ch->size();

    switch(type) {

    case(CSMA_DATA_PKT): {
        ch->size() = curr_size + HDR_size;
        data_sn_queue.push(u_data_id);
        u_data_id++;
    }
    break;

    case(CSMA_ACK_PKT): {
        ch->ptype() = PT_MMAC_ACK;
        ch->size() = ACK_size;
        ch->uid() = u_pkt_id++;
        mach->set(MF_CONTROL,addr,dest_addr);
        mach->macSA() = addr;
        mach->macDA() = dest_addr;
    }
    break;

    }

}
void
UwCsmaAloha_Trigger_SINK::initPkt(Packet *p, int dest_addr)
{
	hdr_cmn *ch = hdr_cmn::access(p);
	hdr_mac *mach = HDR_MAC(p);
	ch->ptype() = PT_MMAC_TRIGGER;
	ch->size() = TRIGGER_size;
	mach->macSA() = addr;
	mach->macDA() = dest_addr;
}
예제 #4
0
size_t
packerMAC::unpackMyHdr(unsigned char *buf, size_t offset, Packet *p)
{

	// Pointer to the MAC packet header
	hdr_mac *hmac = HDR_MAC(p);

	int field_idx = 0;

	memset(&(hmac->ftype_), 0, sizeof(hmac->ftype_));
	offset += get(buf, offset, &(hmac->ftype_), n_bits[field_idx++]);

	memset(&(hmac->macSA_), 0, sizeof(hmac->macSA_));
	offset += get(buf, offset, &(hmac->macSA_), n_bits[field_idx++]);
	hmac->macSA_ = restoreSignedValue(hmac->macSA_, n_bits[field_idx - 1]);

	memset(&(hmac->macDA_), 0, sizeof(hmac->macDA_));
	offset += get(buf, offset, &(hmac->macDA_), n_bits[field_idx++]);
	hmac->macDA_ = restoreSignedValue(hmac->macDA_, n_bits[field_idx - 1]);

	/* Old function to uncompresso signed value
	if (n_bits[field_idx - 1] < sizeof(hmac->macDA()) * 8) { // Compression!
		bitset<sizeof(hmac->macDA()) * 8 > my_bitset(hmac->macDA());
		if (my_bitset[n_bits[field_idx - 1] - 1] == 1) {
			for (int i = n_bits[field_idx - 1]; i < sizeof(hmac->macDA()) * 8;
	++i) {
				my_bitset.set(i,1);
			}
		}
		hmac->macDA() = static_cast<int>(my_bitset.to_ulong());
	}
	 */

	memset(&(hmac->hdr_type_), 0, sizeof(hmac->hdr_type_));
	offset += get(buf, offset, &(hmac->hdr_type_), n_bits[field_idx++]);

	memset(&(hmac->txtime_), 0, sizeof(hmac->txtime_));
	offset += get(buf, offset, &(hmac->txtime_), n_bits[field_idx++]);

	memset(&(hmac->sstime_), 0, sizeof(hmac->sstime_));
	offset += get(buf, offset, &(hmac->sstime_), n_bits[field_idx++]);

	memset(&(hmac->padding_), 0, sizeof(hmac->padding_));
	offset += get(buf, offset, &(hmac->padding_), n_bits[field_idx++]);
	hmac->padding_ = restoreSignedValue(hmac->padding_, n_bits[field_idx - 1]);

	if (debug_) {
		printf("\033[0;45;30m RX MAC packer hdr \033[0m \n");
		printMyHdrFields(p);
	}

	return offset;
}
예제 #5
0
void CsmaAloha::Phy2MacEndRx(Packet* p) {


    hdr_cmn* ch = HDR_CMN(p);
    packet_t rx_pkt_type = ch->ptype();
    hdr_mac* mach = HDR_MAC(p);
    hdr_MPhy* ph = HDR_MPHY(p);

    int source_mac = mach->macSA();
    int dest_mac = mach->macDA();

    double gen_time = ph->txtime;
    double received_time = ph->rxtime;
    double diff_time = received_time - gen_time;

    double distance = diff_time * prop_speed;

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::Phy2MacEndRx() "
                         << status_info[curr_state] << ", received a pkt type = "
                         << ch->ptype() << ", src addr = " << mach->macSA()
                         << " dest addr = " << mach->macDA()
                         << ", estimated distance between nodes = " << distance << " m " << endl;

    if ( ch->error() ) {

        if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::Phy2MacEndRx() dropping corrupted pkt " << endl;
        incrErrorPktsRx();

        refreshReason(CSMA_REASON_PKT_ERROR);
        drop(p, 1, CSMA_DROP_REASON_ERROR);
        stateRxPacketNotForMe(NULL);
    }
    else {
        if ( dest_mac == addr || dest_mac == MAC_BROADCAST ) {
            if ( rx_pkt_type == PT_MMAC_ACK ) {
                refreshReason(CSMA_REASON_ACK_RX);
                stateRxAck(p);
            }
            else if ( curr_state != CSMA_STATE_RX_WAIT_ACK ) {
                refreshReason(CSMA_REASON_DATA_RX);
                stateRxData(p);
            }
            else {
                refreshReason(CSMA_REASON_PKT_NOT_FOR_ME);
                stateRxPacketNotForMe(p);
            }
        }
        else {
            refreshReason(CSMA_REASON_PKT_NOT_FOR_ME);
            stateRxPacketNotForMe(p);
        }
    }
}
예제 #6
0
void CsmaAloha::stateRxData(Packet* data_pkt) {
    refreshState( CSMA_STATE_DATA_RX );

    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateRxData() in state " << status_info[curr_state] << endl;
    refreshReason( CSMA_REASON_DATA_RX );

    hdr_mac* mach = HDR_MAC(data_pkt);
    int dst_addr = mach->macSA();

    switch( prev_state ) {

    case CSMA_STATE_RX_IDLE: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);

        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateIdle();
    }
    break;

    case CSMA_STATE_RX_LISTEN: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);

        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateCheckListenExpired();
    }
    break;

    case CSMA_STATE_RX_BACKOFF: {
        hdr_cmn* ch = hdr_cmn::access(data_pkt);
        ch->size() = ch->size() - HDR_size;
        incrDataPktsRx();
        sendUp(data_pkt);
        if (ack_mode == CSMA_ACK_MODE) stateTxAck(dst_addr);
        else stateCheckBackoffExpired();
    }
    break;


    default:

        cerr << NOW << " CsmaAloha("<< addr << ")::stateRxData() logical error, prev state = " << status_info[prev_state]
             << endl;

    }
}
예제 #7
0
int
UWMllModule::arpResolve(nsaddr_t dst, Packet *p)
{
	hdr_mac *mh = HDR_MAC(p);
	UWARPEntry *llinfo;
	llinfo = arptable_->lookup(dst);

	// Found entry, set dest and return
	if (llinfo && llinfo->up_) {
		mh->macDA() = llinfo->macaddr_;
		return 0;
	}
	return EADDRNOTAVAIL;
}
예제 #8
0
counter
uwinterference::getCounters(Packet *p)
{
	hdr_mac *mach = HDR_MAC(p);
	hdr_MPhy *ph = HDR_MPHY(p);

	PKT_TYPE recv_pkt_type;
	if (mach->ftype() == MF_CONTROL) {
		recv_pkt_type = CTRL;
	} else {
		recv_pkt_type = DATA;
	}
	return (getCounters(ph->rxtime, recv_pkt_type));
}
void
UwCsmaAloha_Trigger_SINK::Phy2MacEndRx(Packet *p)
{
	if (receiving_state_active) {
		hdr_cmn *ch = HDR_CMN(p);
		packet_t rx_pkt_type = ch->ptype();
		hdr_mac *mach = HDR_MAC(p);
		hdr_MPhy *ph = HDR_MPHY(p);

		int dest_mac = mach->macDA();

		if (ch->error()) {
			if (debug_)
				cout << NOW << "  UwCsmaAloha_Trigger_SINK(" << addr
					 << ")::Phy2MacEndRx() dropping corrupted pkt " << endl;
			incrErrorPktsRx();
			refreshReason(UW_CS_ALOHA_TRIG_SINK_REASON_PKT_ERROR);
			drop(p, 1, UW_CS_ALOHA_TRIG_SINK_DROP_REASON_ERROR);
			stateRxPacketNotForMe(NULL);
		} else {
			if (dest_mac == addr || dest_mac == (int) MAC_BROADCAST) {
				if (rx_pkt_type != PT_MMAC_TRIGGER) {
					refreshReason(UW_CS_ALOHA_TRIG_SINK_REASON_DATA_RX);
					stateRxData(p);
				} else {
					if (debug_)
						cout << "  UwCsmaAloha_Trigger_SINK(" << addr
							 << "):: Received a packet of wrong type " << endl;
					drop(p, 1, UW_CS_ALOHA_TRIG_SINK_DROP_REASON_UNKNOWN_TYPE);
				}
			} else {
				refreshReason(UW_CS_ALOHA_TRIG_SINK_REASON_PKT_NOT_FOR_ME);
				stateRxPacketNotForMe(p);
			}
		}
	} else {
		if (debug_)
			cout << NOW << "  UwCsmaAloha_Trigger_SINK(" << addr
				 << "):: Phy2MacEndRx ---> Not enabled to receive data "
				 << endl;
		drop(p, 1, UW_CS_ALOHA_TRIG_SINK_DROP_REASON_RECEIVING_NOT_ENABLED);
	}
}
예제 #10
0
size_t packerMAC::packMyHdr(Packet* p, unsigned char* buf, size_t offset) {

    // Pointer to the MAC packet header
    hdr_mac* hmac = HDR_MAC(p);

    int field_idx = 0;

    offset += put(buf, offset, &(hmac->ftype_), n_bits[field_idx++]);
    offset += put(buf, offset, &(hmac->macSA_), n_bits[field_idx++]);
    offset += put(buf, offset, &(hmac->macDA_), n_bits[field_idx++]);
    offset += put(buf, offset, &(hmac->hdr_type_), n_bits[field_idx++]);
    offset += put(buf, offset, &(hmac->txtime_), n_bits[field_idx++]);
    offset += put(buf, offset, &(hmac->sstime_), n_bits[field_idx++]);
    offset += put(buf, offset, &(hmac->padding_), n_bits[field_idx++]);

    if (debug_) {
        printf("\033[0;45;30m TX MAC packer hdr \033[0m \n");
        printMyHdrFields(p);
    }
    return offset;
}
예제 #11
0
void
uwinterference::addToInterference(Packet *p)
{
	hdr_MPhy *ph = HDR_MPHY(p);
	hdr_mac *mach = HDR_MAC(p);
	// CollisionEvent* ce;
	PKT_TYPE type_rcv_pkt;
	if (mach->ftype() == MF_CONTROL) {
		// ce->type = CTRL;
		type_rcv_pkt = CTRL;
		addToCollisionCounters(CTRL, NOW, 1);
	} else {
		// ce->type = DATA;
		type_rcv_pkt = DATA;
		addToCollisionCounters(DATA, NOW, 1);
	}
	CollisionEvent *ce = new CollisionEvent(type_rcv_pkt);
	// Scheduler::instance().schedule(&endinterftimer, pe, ph->duration -
	// EPSILON_TIME);
	Scheduler::instance().schedule(
			&end_collision_timer, ce, ph->duration - EPSILON_TIME);
	MInterferenceMIV::addToInterference(p);
}
예제 #12
0
void CsmaAloha::stateTxData()
{
    refreshState(CSMA_STATE_TX_DATA);


    if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateTxData() " << endl;
    if (print_transitions) printStateInfo();

    curr_data_pkt = Q.front();


    if ( data_sn_queue.front() != last_sent_data_id) {
        resetCurrTxRounds();
        ack_timer.resetCounter();
        listen_timer.resetCounter();
        backoff_timer.resetCounter();
    }
    if ( curr_tx_rounds < max_tx_tries ) {
        hdr_mac* mach = HDR_MAC(curr_data_pkt);

        mach->macSA() = addr;
        start_tx_time = NOW;
        last_sent_data_id = data_sn_queue.front();
        txData();
    }
    else {
        queuePop(false);
        incrDroppedPktsTx();

        refreshReason(CSMA_REASON_MAX_TX_TRIES);

        if (debug_) cout << NOW << "  CsmaAloha("<< addr << ")::stateTxData() curr_tx_rounds " << curr_tx_rounds
                             << " > max_tx_tries = " << max_tx_tries << endl;

        stateIdle();
    }
}
예제 #13
0
void
UWMllModule::sendDown(Packet *p)
{
	hdr_cmn *ch = HDR_CMN(p);
	hdr_uwip *ih = HDR_UWIP(p);
	nsaddr_t dst = ih->daddr();
	hdr_ll *llh = HDR_LL(p);
	hdr_mac *mh = HDR_MAC(p);

	llh->seqno_ = ++seqno_;
	llh->lltype() = LL_DATA;

	mh->macSA() = getDownAddr();
	mh->hdr_type() = ETHERTYPE_IP;
	int tx = 0;

	switch (ch->addr_type()) {

		case NS_AF_ILINK:
			/* Uhh!? nsaddr_t to int!? */
			mh->macDA() = ch->next_hop();
			//                        cout << "ILINK mode " << endl;
			break;

		case NS_AF_INET:
			if (ch->next_hop() == UWIP_BROADCAST)
				dst = ch->next_hop();
			else if (ch->next_hop() <= 0)
				dst = ih->daddr();
			else
				dst = ch->next_hop();
		//                        cout << "INET mode " << endl;

		case NS_AF_NONE:

			if (UWIP_BROADCAST == (u_int32_t) dst) {
				mh->macDA() = MAC_BROADCAST;
				break;
			}

			/* Resolv ARP */
			tx = arpResolve(dst, p);
			break;

		default:
			mh->macDA() = MAC_BROADCAST;
			break;
	}

	if (tx == 0) {
		Module::sendDown(p);
	} else {
		if (enable_addr_copy == 0) {
			std::cerr << NOW << "Node(" << mh->macSA()
					  << ")::UwMLL_Module -> WARNING: Entry not found for IP "
						 "address "
					  << dst << " Packet dropped" << endl;
			drop(p, 1, UWMLL_DROP_REASON_NOT_IN_ARP_LIST);
		} else {
			mh->macDA() = dst;
			Module::sendDown(p);
		}
	}
}
void
uwUFetch_NODE::state_DATA_HN_tx_without()
{

	if (debug_)
		std::cout << NOW << " uwUFetch_NODE (" << addr
				  << ") ::state_DATA_HN_tx() ---->HN is starting transmission "
					 "of the"
				  << " DATA packet number: " << (getDataPckTx_by_HN() + 1)
				  << " to the AUV with"
				  << " MAC address: " << mac_addr_AUV_in_trigger << std::endl;

	// Pick up the first element of the queue
	curr_DATA_HN_pck_tx = (Q_data_HN.front())->copy();
	// Remove the element from the queue that we have pick up
	Q_data_HN.pop();

	hdr_mac *mach = HDR_MAC(curr_DATA_HN_pck_tx);
	hdr_cmn *cmh = hdr_cmn::access(curr_DATA_HN_pck_tx);
	hdr_uwcbr *cbrh = HDR_UWCBR(curr_DATA_HN_pck_tx);

	mach->set(MF_CONTROL, addr, mac_addr_AUV_in_trigger);
	mach->macSA() = addr;
	mach->macDA() = mac_addr_AUV_in_trigger;
	cmh->size() = sizeof(curr_DATA_HN_pck_tx);

	if (burstDATA()) {
		//        hdr_uwmphy_modem* modemh =
		//        HDR_UWMPHY_MODEM(curr_DATA_HN_pck_tx);
		//        // modemh->use_burst_data() = 1;
		//        if (getDataPckTx_by_HN() == (max_data_HN_can_tx)) {
		//            modemh->last_packet() = 1;
		//            modemh->use_burst_data() = 1;
		//        } else {
		//            modemh->last_packet() = 0;
		//            modemh->use_burst_data() = 1;
		//        }
		txDATAEnabledHN = true;

		int old_sn = cbrh->sn();
		cbrh->sn() = pck_number_id;
		pck_number_id++;

		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::state_DATA_HN_tx()____________________DATA_"
								"pck_tx:_source_SN("
							 << Q_data_source_SN.front() << ")_source_HN("
							 << mach->macSA() << ")_"
							 << "destination(" << mach->macDA()
							 << ")_id_pck_original:" << old_sn
							 << "_new_id_pck:" << cbrh->sn()
							 << "_size:" << cmh->size() << "[byte]"
							 << std::endl;
		Q_data_source_SN.pop();

		DATA_HN_tx();
	} else {
		txDATAEnabledHN = true;

		int old_sn = cbrh->sn();
		cbrh->sn() = pck_number_id;
		pck_number_id++;

		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::state_DATA_HN_tx()_____________________"
								"DATA_pck_tx:_source_SN("
							 << Q_data_source_SN.front() << ")_source_HN("
							 << mach->macSA() << ")_"
							 << "destination(" << mach->macDA()
							 << ")_id_pck_original:" << old_sn
							 << "_new_id_pck:" << cbrh->sn()
							 << "_size:" << cmh->size() << "[byte]"
							 << std::endl;
		Q_data_source_SN.pop();

		DATA_HN_tx();
	}

} // end state_DATA_HN_tx_without();
void
uwUFetch_NODE::Phy2MacEndRx_HN_without(Packet *p)
{

	hdr_cmn *cmh = hdr_cmn::access(p);
	hdr_mac *mach = HDR_MAC(p);
	int src_mac_addr = mach->macSA();
	int dest_mac_addr = mach->macDA(); // Destination MAC address, the address
									   // to which the packet is addressed

	if (debug_)
		std::cout << NOW << "uwUFetch_NODE(" << addr
				  << ")::Phy2MacEndRx()______________________dest_mac_addr "
				  << dest_mac_addr << std::endl;
	// Control if the packet that the HN has received is really for him

	if ((dest_mac_addr == addr) || (dest_mac_addr == MAC_BROADCAST)) {
		// Packet is addressed to me HN

		if (cmh->ptype() == PT_TRIGGER_UFETCH) {
			// TRIGGER section
			if (debug_)
				std::cout << NOW << " uwUFetch_NODE (" << addr
						  << ") ::Phy2MacEndRx() ---->HN has finished to "
							 "receive a"
						  << " TRIGGER packet from the AUV with MAC address: "
						  << src_mac_addr << std::endl;

			if (debugMio_)
				out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
								 << ")::Phy2MacEndRx()______________________"
									"Finished_to_rx_TRIGGER_pck"
								 << "_from_AUV(" << src_mac_addr << ")."
								 << std::endl;

			mac_addr_AUV_in_trigger =
					mach->macSA(); // Save the Mac address of the

			if (rxTRIGGEREnabled) {
				int index_q = 0;
				/**
				 * Before to start the communication between AUV, HN move the
				 * data packets from the SN queue to the HN
				 * data queue. This operation is done only by the HN that
				 * function also as SN
				 */
				while ((!Q_data.empty()) &&
						(index_q <= MAX_PCK_HN_WANT_RX_FROM_NODE)) {
					// Pick up the first element of the queue
					curr_DATA_NODE_pck_tx_HN = (Q_data.front())->copy();
					// Remove the element from the queue that we have pick up
					// the packet
					Q_data.pop();
					// Add the packet to the queue of data packets that HN will
					// transmit to AUV when
					// will be required
					Q_data_HN.push(curr_DATA_NODE_pck_tx_HN);
					incrTotalDataPckTx_by_NODE();
					incrTotalDataPckRx_by_HN();
					hdr_uwcbr *cbrh = HDR_UWCBR(curr_DATA_NODE_pck_tx_HN);

					if (debugMio_)
						out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
										 << ")::Phy2MacEndRx()_________________"
											"_______DATA_pck_tx:_source("
										 << mach->macSA() << ")_"
										 << "destination(" << mach->macDA()
										 << ")_id_pck:" << cbrh->sn() << ""
										 << std::endl;
					index_q++;
				}
			}

			if ((cmh->error()) || (Q_data_HN.empty())) {
				if (cmh->error()) {
					// Packet it's in error
					if (debug_)
						std::cout << NOW << " uwUFetch_NODE (" << addr
								  << ") ::Phy2MacEndRx() ---->TRIGGER packet "
									 "received by the HN"
								  << " is corrupted: DROP IT" << std::endl;

					if (debugMio_)
						out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
										 << ")::Phy2MacEndRx()_________________"
											"_______TRIGGER_rx_from_AUV("
										 << mach->macSA()
										 << ")_It_s_in_ERROR:IGNORE_It."
										 << std::endl;

					rx_TRIGGER_finish_HN_time = NOW;

					incrTotalTriggerPckRx_HN();
					incrTotalTriggerPckRx_corrupted_HN();

					drop(p,
							1,
							UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
					refreshReason(UWFETCH_NODE_STATUS_CHANGE_PACKET_ERROR);

					if (rxTRIGGEREnabled) {
						if (debug_)
							std::cout << NOW << " uwUFetch_NODE (" << addr
									  << ") ::Phy2MacEndRx() ---->HN reset the "
										 "TRIGGER timer"
									  << std::endl;

						BeaconBeforeTx_timer.force_cancel();

						refreshReason(
								UWUFETCH_NODE_STATUS_CHANGE_HN_RX_TRIGGER_FROM_AUV_CORRUPTED);
						rxTRIGGEREnabled = true;

						stateIdle_HN();
					} else {
						// HN is not enable to receive a TRIGGER packet
						if (debug_)
							std::cout << NOW << " uwUFetch_NODE (" << addr
									  << ") ::Phy2MacEndRx() ---->HN is not "
										 "enabled to receive"
									  << " the TRIGGER packet: DROP IT."
									  << std::endl;
					}
				} else {
					if (debug_)
						std::cout << NOW << " uwUFetch_NODE (" << addr
								  << ") ::Phy2MacEndRx() ---->TRIGGER packet "
									 "received by the HN"
								  << " is not corrupted, but the HN has 0 DATA "
									 "packet enabled to tx to the AUV: DROP IT"
								  << std::endl;

					if (debugMio_)
						out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
										 << ")::Phy2MacEndRx()_________________"
											"_______TRIGGER_rx_It_s_CORRECT_"
											"but_0_DATA_to_tx:IGNORE_It."
										 << std::endl;

					rx_TRIGGER_finish_HN_time = NOW;

					incrTotalTriggerPckRx_HN();

					drop(p,
							1,
							UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
					refreshReason(UWFETCH_NODE_STATUS_CHANGE_PACKET_ERROR);

					if (rxTRIGGEREnabled) {
						if (debug_)
							std::cout << NOW << " uwUFetch_NODE (" << addr
									  << ") ::Phy2MacEndRx() ---->HN reset the "
										 "TRIGGER timer"
									  << std::endl;
						BeaconBeforeTx_timer.force_cancel();

						refreshReason(
								UWUFETCH_NODE_STATUS_CHANGE_HN_RX_TRIGGER_FROM_AUV_CORRUPTED);
						rxTRIGGEREnabled = true;

						stateIdle_HN();
					} else {
						// HN is not enable to receive a TRIGGER packet
						if (debug_)
							std::cout << NOW << " uwUFetch_NODE (" << addr
									  << ") ::Phy2MacEndRx() ---->HN is not "
										 "enabled to receive"
									  << " the TRIGGER packet: DROP IT."
									  << std::endl;
					}
				}
			} else {
				// Packet it's not in error
				if (debug_)
					std::cout << NOW << " uwUFetch_NODE (" << addr
							  << ") ::Phy2MacEndRx() ---->Physical layer of HN "
								 "with MAC"
							  << " address: " << dest_mac_addr
							  << " has finished to receive a TRIGGER packet"
							  << " from the AUV with MAC address: "
							  << src_mac_addr << std::endl;

				if (debugMio_)
					out_file_logging
							<< NOW << "uwUFetch_HEAD_NODE(" << addr
							<< ")::Phy2MacEndRx()________________________"
							   "TRIGGER_rx_It_s_CORRECT_>=1_DATA_to_tx."
							<< std::endl;

				rx_TRIGGER_finish_HN_time = NOW;

				incrTriggerPckRx_HN();
				incrTotalTriggerPckRx_HN();

				curr_TRIGGER_HN_pck_rx = p->copy();

				refreshReason(UWUFETCH_NODE_STATUS_CHANGE_TRIGGER_RX);

				Packet::free(p);

				TRIGGER_rx();
			}
		} else {
			// DATA section
			if (debug_)
				std::cout << NOW << " uwUFetch_NODE (" << addr
						  << ") ::Phy2MacEndRx() ---->HN has finished to "
							 "receive a"
						  << " DATA packet from the NODE with MAC address: "
						  << src_mac_addr << std::endl;

			rx_DATA_finish_HN_time = NOW;

			if (debugMio_)
				out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
								 << ")::Phy2MacEndRx()________________________"
									"End_to_rx_DATA_pck_"
								 << "from_SN(" << src_mac_addr << ")."
								 << std::endl;

			if (cmh->error()) {
				// Packet it's in error
				if (debug_)
					std::cout << NOW << " uwUFetch_NODE( " << addr
							  << ") ::Phy2MacEndRx() ---->DATA packet received "
								 "by the HN"
							  << " is corrupted: DROP IT" << std::endl;

				curr_DATA_HN_pck_rx = p->copy();

				rx_DATA_finish_HN_time = NOW;

				incrDataPckRx_by_HN();
				incrTotalDataPckRx_by_HN();
				incrTotalDataPckRx_corrupted_by_HN();

				hdr_uwcbr *cbrh = HDR_UWCBR(curr_DATA_HN_pck_rx);

				if (debugMio_)
					out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
									 << ")::Phy2MacEndRx()_____________________"
										"___DATA_pck_rx_by_HN("
									 << addr << ")_from_SN(" << src_mac_addr
									 << ")_id_pck:" << cbrh->sn() << ""
									 << "_It_s_in_ERROR." << std::endl;

				drop(p, 1, UWFETCH_NODE_DROP_REASON_ERROR); // drop the packet
				refreshReason(UWFETCH_NODE_STATUS_CHANGE_PACKET_ERROR);

			} else {
				// Packet it's not in error

				if (debug_)
					std::cout << NOW << " uwUFetch_NODE (" << addr
							  << ") ::Phy2MacEndRx() ---->Physical layer of HN "
								 "with MAC"
							  << " address: " << dest_mac_addr
							  << " has finished to receive a DATA packet"
							  << " number: " << (getDataPckRx_by_HN() + 1)
							  << " from the NODE with MAC address: "
							  << src_mac_addr << std::endl;

				rx_DATA_finish_HN_time = NOW;

				incrDataPckRx_by_HN();
				incrTotalDataPckRx_by_HN();

				curr_DATA_HN_pck_rx = p->copy();

				refreshReason(UWUFETCH_NODE_STATUS_CHANGE_DATA_RX);

				Packet::free(p);

				DATA_rx();
			}
		}
	} else {
		// Packet is not addressed to me HN
		if (debug_)
			std::cout << NOW << " uwUFetch_NODE (" << addr
					  << ") ::Phy2MacEndRx() ---->The packet received is not "
						 "for me HN:"
					  << " DROP IT." << std::endl;

		if (cmh->ptype() == PT_POLL_UFETCH) {
			// POLL section
			if (debug_)
				std::cout << NOW << " uwUFetch_NODE (" << addr
						  << ") ::Phy2MacEndRx() ---->HN has finished to "
							 "receive a"
						  << " POLL packet from the HN with MAC address: "
						  << src_mac_addr << " .DROP IT" << std::endl;

			drop(p, 1, UWUFETCH_NODE_DROP_CAN_NOT_RX_THIS_PCK);

		} else if (cmh->ptype() == PT_PROBE_UFETCH) {
			// BEACON section
			if (debug_)
				std::cout << NOW << " uwUFetch_NODE (" << addr
						  << ") ::Phy2MacEndRx() ---->HN has finished to "
							 "receive a"
						  << " PROBE packet from the SENSOR NODE with MAC "
							 "address: "
						  << src_mac_addr << " .DROP IT" << std::endl;

			if (debugMio_)
				out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
								 << ")::Phy2MacEndRx()________________________"
									"Finished_to_rx_PROBE"
								 << "_pck_from_SN(" << src_mac_addr
								 << ").Not_addressed_to_me:_IGNORE_IT."
								 << std::endl;

			drop(p, 1, UWUFETCH_NODE_DROP_CAN_NOT_RX_THIS_PCK);

		} else if (cmh->ptype() == PT_TRIGGER_UFETCH) {
			// TRIGGER section
			if (debug_)
				std::cout << NOW << " uwUFetch_NODE (" << addr
						  << ") ::Phy2MacEndRx() ---->HN has finished to "
							 "receive a"
						  << " TRIGGER packet from the AUV with MAC address ("
						  << src_mac_addr << ").DROP IT" << std::endl;

			if (debugMio_)
				out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
								 << ")::Phy2MacEndRx()________________________"
									"Finished_to_rx_TRIGGER"
								 << "_pck_from_AUV(" << src_mac_addr
								 << ")._Not_addressed_to_me:_IGNORE_IT."
								 << std::endl;

			drop(p, 1, UWUFETCH_NODE_DROP_CAN_NOT_RX_THIS_PCK);

		} else {
			// DATA section
			if (debug_)
				std::cout << NOW << " uwUFetch_NODE (" << addr
						  << ") ::Phy2MacEndRx() ---->HN has finished to "
							 "receive a"
						  << " DATA packet from the SENSOR NODE with MAC "
							 "address: "
						  << src_mac_addr << " .DROP IT" << std::endl;

			if (debugMio_)
				out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
								 << ")::Phy2MacEndRx()________________________"
									"End_to_rx_DATA_pck_"
								 << "from_SN(" << src_mac_addr
								 << ")._Not_addressed_to_me:_IGNORE_IT."
								 << std::endl;

			drop(p, 1, UWUFETCH_NODE_DROP_CAN_NOT_RX_THIS_PCK);
		}
	}
} // end Phy2MacEndRx_HN();
void
uwUFetch_NODE::TRIGGER_rx_without()
{

	if (rxTRIGGEREnabled) {
		// HN is enabled to receive a TRIGGER
		if (debug_)
			std::cout << NOW << " uwUFetch_NODE (" << addr
					  << ") ::TRIGGER_rx() ---->HN reset the TRIGGER timer"
					  << std::endl;

		if (debugMio_)
			out_file_logging
					<< NOW << "uwUFetch_HEAD_NODE(" << addr
					<< ")::TRIGGER_rx()_________________________TRIGGER_rx_It_"
					   "s_CORRECT_and_>= 1_DATA_to_tx_and_enabled_to_rx_It."
					<< std::endl;

		BeaconBeforeTx_timer.force_cancel(); // reset the timer in which the HN
											 // wait a TRIGGER packet

		refreshState(UWUFETCH_NODE_STATUS_TRIGGER_RECEIVE);
		if (print_transitions)
			printStateInfo();

		hdr_mac *mach = HDR_MAC(curr_TRIGGER_HN_pck_rx);
		hdr_TRIGGER_UFETCH *triggerh =
				HDR_TRIGGER_UFETCH(curr_TRIGGER_HN_pck_rx);

		/*
		 * Save the header data of the trigger
		 */

		T_min_bck_DATA = (double) triggerh->t_min() / 1000; // Minimum value
															// time before that
															// HN transmit a
															// DATA packet
		T_max_bck_DATA = (double) triggerh->t_max() / 1000; // Maximum value
															// time before that
															// HN transmit a
															// DATA packet
		max_pck_HN_can_tx =
				triggerh->max_pck_want_rx(); // Maximum number of DATA packet
											 // that HN can transmit to the AUV

		mac_addr_AUV_in_trigger =
				mach->macSA(); // Save the MAC address of the AUV node from
							   // which the HN has received a trigger packet

		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::TRIGGER_rx()__________________________"
								"PARAMETERS_of_TRIGGER_PACKET: "
							 << std::endl;
		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::TRIGGER_rx()__________________________"
								"Source_address:_"
							 << mach->macSA() << "." << std::endl;
		if (mach->macDA() == -1) {
			if (debugMio_)
				out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
								 << ")::TRIGGER_rx()__________________________"
									"Destination_Address:_BROADCAST."
								 << std::endl;
		} else {
			if (debugMio_)
				out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
								 << ")::TRIGGER_rx()__________________________"
									"Destination_Address:_"
								 << mach->macDA() << std::endl;
		}
		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::TRIGGER_rx()__________________________MIN_"
								"backoff_time_DATA_pck:_"
							 << T_min_bck_DATA << "[s]." << std::endl;
		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::TRIGGER_rx()__________________________MAX_"
								"backoff_time_DATA_pck:_"
							 << T_max_bck_DATA << "[s]." << std::endl;
		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::TRIGGER_rx()__________________________MAX_"
								"DATA_pck_want_rx_from_HN:_"
							 << max_pck_HN_can_tx << "[pck]." << std::endl;
		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::TRIGGER_rx()__________________________DATA_"
								"pck_would_like_to_tx_to_the_AUV:_"
							 << Q_data_HN.size() << "[pck]." << std::endl;

		rxTRIGGEREnabled = false;
		txBEACONEnabled = false;

		bck_before_tx_data = choiceBackOffTimer_HN();
		if (debugMio_)
			out_file_logging << NOW << "uwUFetch_HEAD_NODE(" << addr
							 << ")::TRIGGER_rx()__________________________"
								"Backoff_timeout_choice:_"
							 << bck_before_tx_data << "[s]." << std::endl;

		BCK_timer_data.schedule(bck_before_tx_data);

	} else {
		// HN is not enable to receive a TRIGGER packet
		if (debug_)
			std::cout << NOW << " uwUFetch_NODE (" << addr
					  << ") ::TRIGGER_rx() ---->HN is not enabled to receive"
					  << " the TRIGGER packet: DROP IT." << std::endl;

		if (debugMio_)
			out_file_logging
					<< NOW << "uwUFetch_HEAD_NODE(" << addr
					<< ")::TRIGGER_rx()_________________________TRIGGER_rx_It_"
					   "s_CORRECT_and_>= "
					   "1_DATA_to_tx_and_not_enabled_to_rx_It:IGNORE_It."
					<< std::endl;

		if (debugMio_)
			out_file_logging
					<< NOW << "uwUFetch_HEAD_NODE(" << addr
					<< ")::TRIGGER_rx()__________________________Not_ENABLED"
					<< "_to_rx_TRIGGER_pck." << std::endl;

		drop(curr_TRIGGER_HN_pck_rx, 1, UWUFETCH_NODE_DROP_REASON_NOT_ENABLE);
	}
} // end TRIGGER_rx();