How to schedule data transmission duration based on queue status

222 views
Skip to first unread message

S Tanin

unread,
Jun 9, 2020, 6:12:48 AM6/9/20
to OMNeT++ Users
Hi everyone,

Using INET framework, i need to implement a MAC protocol, where each node will keep sending packets for a scheduled duration (data transmission duration).

Can anyone suggest me if the following code is ok for this purpose? If not, can anyone please advice the correct code for this purpose?


 if (!txQueue->isEmpty()) {
                scheduleAt(simTime() + slotduration*3, c); 
                macState = send_data;
                while(c == 0) {
                    senddatapacket(); 
                }
}

Many thanks.

Alfonso Ariza Quintana

unread,
Jun 9, 2020, 6:37:52 AM6/9/20
to omn...@googlegroups.com
With your description it is not easy, byt I suppose that you want a TDMA protocol, you can use L-MAC like reference, LMac is a TDMA protocol

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de S Tanin <stan...@gmail.com>
Enviado: martes, 9 de junio de 2020 12:12
Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: [Omnetpp-l] How to schedule data transmission duration based on queue status
 
--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/bced71d7-b1ba-47af-a0b5-0cbd906f23f9o%40googlegroups.com.
Message has been deleted

Alfonso Ariza Quintana

unread,
Jun 9, 2020, 7:01:28 AM6/9/20
to omn...@googlegroups.com

No necessarily, you can use an accumulate timer counter that is set to 0 at the beginning of the transmission, if the accumulate time since the node access to the channel is smaller than the limit + the packet pending in the queue it sends the packet, in other case change to listen (the timer is bigger or the queue is empty), this avoid the event and avoid that the timer could arrive in middle of a transmission.

 

If it doesn't matter to exceed the time for a bit, it is even more simple.




Enviado: martes, 9 de junio de 2020 12:45
Para: omn...@googlegroups.com <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] How to schedule data transmission duration based on queue status
 
Hello Alfonso,

I want to implement a CSMA -based duty cycled protocol like BMAC/xmac. When a node finds the channel clear, it will schedule a timer to transmit all packets (one after another) that is in its queue. After sending all packets within that timer, it will go back to sleep.

So, i will need to schedule a timer to set data transmission duration. The node will keep sending packets until that time expires. I am not getting any change with the above mentioned code. Can you please correct me the code for this purpose?

Thank you.

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.

S Tanin

unread,
Jun 10, 2020, 2:58:14 AM6/10/20
to OMNeT++ Users
Hello Alfonso,

Sir, considering your suggestions, i have tried to implement it in different way but it is not working.

I am new in omnet++. Would you kindly correct my below code? Or can you suggest me code for this purpose?

if(!txQueue->isEmpty()) {
                scheduleAt(simTime() + 5, timer); // max duration 5s
                WATCH(timer);
                macState = SEND_DATA;
                if (timer == 0){
                    EV << "node " << address << " data transmission over" << endl;
                }
                else {
                    EV << "node " << address << " : Sending data" << endl;
                    sendDataPacket();
                    deleteCurrentTxFrame();
                }
                cancelEvent(timer);
                scheduleAt(simTime() + checkinterval, wakeup);
                }


Kind Regards,
To unsubscribe from this group and stop receiving emails from it, send an email to omn...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omn...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omn...@googlegroups.com.

Alfonso Ariza Quintana

unread,
Jun 10, 2020, 6:03:58 AM6/10/20
to OMNeT++ Users
I suspect that you are sending the timer several times

Enviado: miércoles, 10 de junio de 2020 8:58
Para: OMNeT++ Users <omn...@googlegroups.com>
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/66d2fd79-c228-4d6a-9e63-7c1e278277cdo%40googlegroups.com.

S Tanin

unread,
Jun 10, 2020, 6:17:57 AM6/10/20
to OMNeT++ Users
Hello Alfonso,

Sir, would you kindly suggest me any sample code/syntax for this purpose?

Can you point me where the above code is in error?

I have been trying last 2 days, but could not figure out.

Kind Regards,

Alfonso Ariza Quintana

unread,
Jun 10, 2020, 6:24:26 AM6/10/20
to omn...@googlegroups.com

 

if(!txQueue->isEmpty()) {

                 
                macState = SEND_DATA;

                startSendDataState = simTime();

                 EV << "node " << address << " : Sending data" << endl;
                    sendDataPacket();
                    deleteCurrentTxFrame();

         eduleAt(simTime() + checkinterval, wakeup);
            }

 

 

 

 

The FSM can be complex in function if the node receives ACK or not

 

If they receives ack, in the ACK state

 

If (simTime() - startSendDataState < 5 && ¡txQueue->isEmpty()) {

         macState = SEND_DATA;

         sendDataPacket();

}

 

 

 

But you Will need to check if the changes in the FSM is correct.

 

Enviado desde Correo para Windows 10

 


Enviado: Wednesday, June 10, 2020 12:17:57 PM
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/8ce50f4c-18c1-4afa-99a1-976d1fe54343o%40googlegroups.com.

S Tanin

unread,
Jun 10, 2020, 7:16:15 AM6/10/20
to omn...@googlegroups.com
Hello Alfonso,

Thank you Sir. I am confused about a couple of things. Would you please help me to understand these?

- why I need to schedule a wakeup timer (underlined) before all data packet transmission over?
- without ACK for data, if the state machine is like sleep->CCA-> send preamble->send data

then, under send data, should I have to write the below code you suggested?

if(!txQueue->isEmpty()) {

                 
                macState = SEND_DATA;

                startSendDataState = simTime();

                 EV << "node " << address << " : Sending data" << endl;
                    sendDataPacket();
                    deleteCurrentTxFrame();

         scheduleAt(simTime() + checkinterval, wakeup);  //
            }

   If (simTime() - startSendDataState < 5 && ¡txQueue->isEmpty()) {

         macState = SEND_DATA;

         sendDataPacket(); // don't i need to delete the sent frames after this?

}


Sorry for asking these questions, Sir. I am a newbie in omnet.


Thank you for your answers.


Alfonso Ariza Quintana

unread,
Jun 10, 2020, 7:21:22 AM6/10/20
to omn...@googlegroups.com

I don’t know the FSM, the wakeup Will depend of the FSM. You have incldue it, I suppose that you have included for some reason.

 

You need to check the FSM, I suppose that this is in the CCA state, after the transmission end (you need to check the event) instead of to change the state, you need to continue en send state and send the next packet.

 

Enviado desde Correo para Windows 10

 

De: S Tanin
Enviado: miércoles, 10 de junio de 2020 13:16
Para: omn...@googlegroups.com
Asunto: Re: [Omnetpp-l] How to schedule data transmission duration based on queue status

 

Hello Alfonso,

 

Thank you Sir. I am confused about a couple of things. Would you please help me to understand these?

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de S Tanin <stan...@gmail.com>
Enviado: Wednesday, June 10, 2020 12:17:57 PM
Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] How to schedule data transmission duration based on queue status

 

Hello Alfonso,

 

Sir, would you kindly suggest me any sample code/syntax for this purpose?

 

Can you point me where the above code is in error?

 

I have been trying last 2 days, but could not figure out.

 

Kind Regards,


On Wednesday, June 10, 2020 at 8:03:58 PM UTC+10, Alfonso Ariza Quintana wrote:

I suspect that you are sending the timer several times

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de S Tanin <stan...@gmail.com>
Enviado: miércoles, 10 de junio de 2020 8:58
Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] How to schedule data transmission duration based on queue status

 

Hello Alfonso,

 

Sir, considering your suggestions, i have tried to implement it in different way but it is not working.

 

I am new in omnet++. Would you kindly correct my below code? Or can you suggest me code for this purpose?

 

if(!txQueue->isEmpty()) {
                scheduleAt(simTime() + 5, timer); // max duration 5s
                WATCH(timer);
                macState = SEND_DATA;
                if (timer == 0){
                    EV << "node " << address << " data transmission over" << endl;
                }
                else {
                    EV << "node " << address << " : Sending data" << endl;
                    sendDataPacket();
                    deleteCurrentTxFrame();
                }
                cancelEvent(timer);
                scheduleAt(simTime() + checkinterval, wakeup);
                }

 

 

Kind Regards,

 

On Tuesday, June 9, 2020 at 9:01:28 PM UTC+10, Alfonso Ariza Quintana wrote:

No necessarily, you can use an accumulate timer counter that is set to 0 at the beginning of the transmission, if the accumulate time since the node access to the channel is smaller than the limit + the packet pending in the queue it sends the packet, in other case change to listen (the timer is bigger or the queue is empty), this avoid the event and avoid that the timer could arrive in middle of a transmission.

 

If it doesn't matter to exceed the time for a bit, it is even more simple.

 

 

 

De: omn...@googlegroups.com <omn...@googlegroups.com> en nombre de S Tanin <stan...@gmail.com>
Enviado: martes, 9 de junio de 2020 12:45
Para: omn...@googlegroups.com <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] How to schedule data transmission duration based on queue status

 

Hello Alfonso,

 

I want to implement a CSMA -based duty cycled protocol like BMAC/xmac. When a node finds the channel clear, it will schedule a timer to transmit all packets (one after another) that is in its queue. After sending all packets within that timer, it will go back to sleep.

 

So, i will need to schedule a timer to set data transmission duration. The node will keep sending packets until that time expires. I am not getting any change with the above mentioned code. Can you please correct me the code for this purpose?

 

Thank you.

 

On Tue, Jun 9, 2020 at 8:37 PM Alfonso Ariza Quintana <aari...@hotmail.com> wrote:

With your description it is not easy, byt I suppose that you want a TDMA protocol, you can use L-MAC like reference, LMac is a TDMA protocol

Message has been deleted

Alfonso Ariza Quintana

unread,
Jun 11, 2020, 3:56:52 AM6/11/20
to OMNeT++ Users
In cca and send_data, in cca you need to reset the timer

Enviado: miércoles, 10 de junio de 2020 14:07

Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] How to schedule data transmission duration based on queue status
 

Hello Alfonso,

Sir, If i consider xmac FSM, I supposed your suggested code should be under send_data. Is not it?
There, under send_data node only transmit 1 packet, but in this case,  node will continue sending.

I had another questions: For startSendDataState, data type should be simtime_t or double?

Don't i need to delete the sent frames after this (Bolded below)?

if(!txQueue->isEmpty()) {

                 
                macState = SEND_DATA;

                startSendDataState = simTime(); // what data type of startSendDataState

                 EV << "node " << address << " : Sending data" << endl;
                    sendDataPacket();
                    deleteCurrentTxFrame();
         scheduleAt(simTime() + checkinterval, wakeup);  //
            }

   If (simTime() - startSendDataState < 5 && ¡txQueue->isEmpty()) {

         macState = SEND_DATA;

         sendDataPacket(); // don't i need to delete the sent frames after this?

}


Thank you Sir.


 

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to omn...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to omn...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.

S Tanin

unread,
Jun 11, 2020, 9:40:43 AM6/11/20
to OMNeT++ Users
Hello Alfonso,

Sir, would you tell me in cca, which timer i have to reset? cca_timeout or wakeup timer?

Thank you

Alfonso Ariza Quintana

unread,
Jun 11, 2020, 9:42:07 AM6/11/20
to omn...@googlegroups.com
The variable that mark the beggining of the burst duration

Enviado: jueves, 11 de junio de 2020 15:40
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/91cbc01f-c6be-4eab-a2ca-2e2e017a961eo%40googlegroups.com.

Alfonso Ariza Quintana

unread,
Jun 11, 2020, 9:42:38 AM6/11/20
to omn...@googlegroups.com
Message has been deleted

Alfonso Ariza Quintana

unread,
Jun 15, 2020, 7:52:17 AM6/15/20
to omn...@googlegroups.com
You need to check the FSM, the actual FSM change to sleep after it sends a packet, it needs to program an end transmission event of the previous packet and continue en sending or you can include an additional state where the node wait until it finish,

You need to have clear the FSM and the transitions, in other case it will never work

Enviado: lunes, 15 de junio de 2020 13:42

Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] How to schedule data transmission duration based on queue status
 
Hi Alfonso,

Sir, i have been trying to impement data transmission based on queue status on xmac, but nothing is working.

I am attaching the code as below. SEND_DATA part is added.

The purpose is: when a node gets turn to transmit data to the receiver, it will send all packets in its queue.

Would you kindly check below code and correct me?



void XXMac::handleSelfMessage(cMessage *msg)
{
    MacAddress address = interfaceEntry->getMacAddress();

    switch (macState)
    {
    case INIT: // node has just started and its status is unclear. 1. set the radio for sleep 2. change state to sleep 3. schedule next wakeup
        if (msg->getKind() == XXMAC_START_XXMAC) {            //xmac-start-xmac: self message type defined in .msg file
            EV_DEBUG << "State INIT, message XMAC_START, new state SLEEP" << endl;
            changeDisplayColor(BLACK); // black is for sleeping
            radio->setRadioMode(IRadio::RADIO_MODE_SLEEP);
            macState = SLEEP;
            scheduleAt(simTime()+dblrand()*slotDuration, wakeup); //scheduleAt() – to schedule an event (the module “sends a message to itself”)
            return;
        }
        break;
        // in sleep case, there are 3 conditions/states: 1. if msg is wakeup 2. if msg is ack (too lately received)
    case SLEEP: //if node is in sleep state, and msg type = xmac wakeup, 1. record CCA duration (from current time to 1.7f of checkinterval)
        if (msg->getKind() == XXMAC_WAKE_UP) {
            EV_DEBUG << "node " << address << " : State SLEEP, message XMAC_WAKEUP, new state CCA, simTime " <<
                    simTime() << " to " << simTime() + 1.7f * checkInterval << endl;
            // this CCA is useful when in RX to detect preamble and has to make room for
            // 0.2f = Tx switch, 0.5f = Tx send_preamble, 1f = time_for_ack_back
            scheduleAt(simTime() + 1.7f * checkInterval, cca_timeout); //schedule cca timeout after simtime()+1.7f*checkinterval
            radio->setRadioMode(IRadio::RADIO_MODE_RECEIVER); //set the radio in receiver mode
            changeDisplayColor(GREEN); // receiving
            macState = CCA;
            return;
        }
        // we receive an ACK back but it is too late
        else if (msg->getKind() == XXMAC_ACK) {
            nbMissedAcks++;
            delete msg;
            return;
        }
        // received messages prior real-switching to SLEEP? I'm sorry, out
        else { return; }
        break;
    case CCA: // in cca conditions 1. cca timeout > if cca timeout, send if queue is not empty 2.
        if (msg->getKind() == XXMAC_CCA_TIMEOUT)//if the node needs to transmit or it receives something in the CCA, the time sequence change
        {
            // channel is clear and we wanna SEND
            if (!txQueue->isEmpty()) // where is channel status? if queue is not empty, send preamble
            {
                radio->setRadioMode(IRadio::RADIO_MODE_TRANSMITTER);
                changeDisplayColor(YELLOW);
                macState = SEND_PREAMBLE;
                // We send the preamble for a whole SLOT duration :)
                scheduleAt(simTime() + slotDuration, stop_preambles); // schedule an event to stop preambles after slot duration
                // if 0.2f * CI = 2ms to switch to TX -> has to be accounted for RX_preamble_detection
                scheduleAt(simTime() + 0.2f * checkInterval, switch_preamble_phase); // ignore switching time
                return;
            }
            // 2. if anything to send, go back to sleep and wake up after a full period (slot duration)
            else
            {
                scheduleAt(simTime() + slotDuration, wakeup);
                macState = SLEEP;
                radio->setRadioMode(IRadio::RADIO_MODE_SLEEP);
                changeDisplayColor(BLACK);
                return;
            }
        }
        // during CCA, we received a preamble. Go to state WAIT_DATA and
        // schedule the timeout.

        // check_and_cast : performs a standard C++ dynamic_cast, and checks the result: if it is nullptr, check_and_cast
        //raises an OMNeT++ error.
        if (msg->getKind() == XXMAC_PREAMBLE) {
            auto incoming_preamble = check_and_cast<Packet *>(msg)->peekAtFront<XXMacControlFrame>(); // check if msg received is preamble (peekatfront of controlframe)

            // preamble is for me
            if (incoming_preamble->getDestAddr() == address || incoming_preamble->getDestAddr().isBroadcast() || incoming_preamble->getDestAddr().isMulticast()) {
                cancelEvent(cca_timeout);
                nbRxPreambles++;
                EV << "node " << address << " : State CCA, message XMAC_PREAMBLE received, new state SEND_ACK" << endl;
                macState = SEND_ACK;
                lastPreamblePktSrcAddr = incoming_preamble->getSrcAddr();
                changeDisplayColor(YELLOW);
                radio->setRadioMode(IRadio::RADIO_MODE_TRANSMITTER);
            }
            // the preamble is not for us
            else {
                EV << "node " << address << " : State CCA, message XMAC_PREAMBLE not for me." << endl;
                //~ better overhearing management? :)
                cancelEvent(cca_timeout);
                scheduleAt(simTime() + slotDuration, wakeup);
                macState = SLEEP;
                radio->setRadioMode(IRadio::RADIO_MODE_SLEEP);
                changeDisplayColor(BLACK);
            }

            delete msg;
            return;
        }
        //in case we get an ACK, we simply discard it, because it means the end
        //of another communication
        if (msg->getKind() == XXMAC_ACK) {
            EV_DEBUG << "State CCA, message XMAC_ACK, new state CCA" << endl;
            delete msg;
            return;
        }
        // this case is very, very, very improbable, but let's do it.
        // if in CCA the node receives directly the data packet, accept it
        // even if we increased nbMissedAcks in state SLEEP
        if (msg->getKind() == XXMAC_DATA) {
            auto incoming_data = check_and_cast<Packet *>(msg)->peekAtFront<XXMacDataFrameHeader>();

            // packet is for me
            if (incoming_data->getDestAddr() == address) {
                EV << "node " << address << " : State CCA, received XMAC_DATA, accepting it." << endl;
                cancelEvent(cca_timeout);
                cancelEvent(switch_preamble_phase);
                cancelEvent(stop_preambles);
                macState = WAIT_DATA;
                scheduleAt(simTime(), msg);
            }
            return;
        }
        break;

    case SEND_PREAMBLE:
        if (msg->getKind() == SWITCH_PREAMBLE_PHASE) {
            //~ make room for preamble + time_for_ack_back, check_interval is 10ms by default (from xmac.ned)
            // 0.5f* = 5ms
            if (radio->getRadioMode() == IRadio::RADIO_MODE_RECEIVER) { // tx: the node was in receiver/listening mode. moderx
                radio->setRadioMode(IRadio::RADIO_MODE_TRANSMITTER);
                changeDisplayColor(YELLOW);
                EV_DEBUG << "node " << address << " : preamble_phase tx, simTime = " << simTime() << endl;
                scheduleAt(simTime() + 0.5f * checkInterval, switch_preamble_phase); //preamble plus ack time
            }
            // 1.0f* = 10ms
            else if (radio->getRadioMode() == IRadio::RADIO_MODE_TRANSMITTER) { //rx. if a node receive switch_preamble when it is in transmitted mode
                radio->setRadioMode(IRadio::RADIO_MODE_RECEIVER);
                changeDisplayColor(GREEN);
                EV_DEBUG << "node " << address << " : preamble_phase rx, simTime = " << simTime() << endl;
                scheduleAt(simTime() + 1.0f *checkInterval, switch_preamble_phase); //stay in switch-preamble-phase for 10 ms
            }
            return;
        }
        // radio switch from above
        if (msg->getKind() == XXMAC_SWITCHING_FINISHED) {
            if (radio->getRadioMode() == IRadio::RADIO_MODE_TRANSMITTER) {
                if (currentTxFrame == nullptr)
                    popTxQueue(); // if currenttxframe not null, throw an error, if txqueue not empty, pop a packet
                auto pkt_preamble = currentTxFrame->peekAtFront<XXMacHeaderBase>();
                sendPreamble(pkt_preamble->getDestAddr());
            }
            return;
        }
        // ack_rx within sending_preamble or preamble_timeout without an ACK
        if ((msg->getKind() == XXMAC_ACK) || (msg->getKind() == XXMAC_STOP_PREAMBLES)) {
            //~ ADDED THE SECOND CONDITION! :) if not, below
            if (msg->getKind() == XXMAC_ACK) {
                delete msg;
                EV << "node " << address << " : State SEND_PREAMBLE, message XMAC_ACK, new state SEND_DATA" << endl;
            }
            else if (msg->getKind() == XXMAC_STOP_PREAMBLES) {
                EV << "node " << address << " : State SEND_PREAMBLE, message XMAC_STOP_PREAMBLES" << endl;
            }
            macState = SEND_DATA;

           
            simtime_t preamble_ack_duration = simTime() - stop_preambles->getSendingTime();//added preamble + ack = slot duration
            double pre_ack_dur = preamble_ack_duration.dbl(); //added to convert simtime to double
            EV << "node " << address << " : Urmi: after CCA, time elapsed to receive an ACK of preamble = " << pre_ack_dur << endl; //pre+ack = 0.25s
           
            cancelEvent(stop_preambles); // how to to record elapsed time of a timer.
            cancelEvent(switch_preamble_phase);
            changeDisplayColor(RED);
            radio->setRadioMode(IRadio::RADIO_MODE_TRANSMITTER);
            txAttempts = 1;
            return;
        }

        // next is the case of a node receiving 1 preamble or data while in his preamble gaps, ignore, we are sending!
        if ((msg->getKind() == XXMAC_PREAMBLE) || (msg->getKind() == XXMAC_DATA)) {
            if (msg->getKind() == XXMAC_DATA) {
                nbDroppedDataPackets++;
            }
            delete msg;
            return;
        }
        else {
            EV << "**node " << address << " : State SEND_PREAMBLE, received message " << msg->getKind() << endl;
            return;
        }
        break;

    case SEND_DATA:
            if (msg->getKind() == XXMAC_STOP_PREAMBLES) {
                EV << "node " << address << " : State SEND_DATA, message XXMAC_STOP_PREAMBLES" << endl;
                // send the data packet. schedule time
                if(!txQueue->isEmpty()){
                    //scheduleAt(simTime() + (slotDuration / 2), rest_data);
                    auto startSendData = simTime();
                    EV<<"node "<< address << ": sending data" <<endl;
                  while(simTime() - startSendData <=(slotDuration / 2) && !txQueue->isEmpty()) {
                        sendDataPacket();
                        deleteCurrentTxFrame();
                    }
                   break;
                }
                /***************add************************/
                //if (msg)
                scheduleAt(simTime() + slotDuration, wakeup);
                macState = SLEEP;
                radio->setRadioMode(IRadio::RADIO_MODE_SLEEP);
                changeDisplayColor(BLACK);
                return;
            }
            else if (msg->getKind() == XXMAC_SWITCHING_FINISHED) {
                EV << "node " << address << " : State SEND_DATA, message RADIO_SWITCHING OVER, sending packet..." << endl;
                // send the data packet
                if(!txQueue->isEmpty()){
                  //scheduleAt(simTime() + (slotDuration / 2), rest_data);
                  auto startSendData = simTime();
                  EV<<"node "<< address << ": sending data" <<endl;

                  EV<<"node "<< address << ": sending data" <<endl;
                   while(simTime() - startSendData <=(slotDuration / 2) && !txQueue->isEmpty()) {
                          sendDataPacket();
                          deleteCurrentTxFrame();
                   }
                  break;
                }

               scheduleAt(simTime() + slotDuration, wakeup);
               macState = SLEEP;
               radio->setRadioMode(IRadio::RADIO_MODE_SLEEP);
               changeDisplayColor(BLACK);
               return;
            }
           
            else {
                return;
            }
            break;

       case WAIT_ACK: // to acknowledge data?
        //not used
        break;
    case WAIT_DATA: //waiting for data
        if (msg->getKind() == XXMAC_PREAMBLE) {
            //nothing happens
            nbRxPreambles++;
            delete msg;
            return;
        }
        if (msg->getKind() == XXMAC_ACK) {
            //nothing happens
            delete msg;
            return;
        }
        if (msg->getKind() == XXMAC_DATA) {
            auto packet = check_and_cast<Packet *>(msg);
            auto mac = packet->peekAtFront<XXMacDataFrameHeader>();
            const MacAddress& dest = mac->getDestAddr(); // dest stores mac address

            if ((dest == address) || dest.isBroadcast() || dest.isMulticast()) {
                decapsulate(packet);
                sendUp(packet); // send pkt to upper layer
                nbRxDataPackets++;
                cancelEvent(data_timeout);

                // if something in the queue, wakeup soon.
                if (!txQueue->isEmpty())
                    scheduleAt(simTime() + dblrand()*checkInterval, wakeup);
                else
                    scheduleAt(simTime() + slotDuration, wakeup);
                macState = SLEEP;
                radio->setRadioMode(IRadio::RADIO_MODE_SLEEP);
                changeDisplayColor(BLACK);

            }
            else {
                delete msg;
                msg = NULL;
                mac = NULL;
            }

            EV << "node " << address << " : State WAIT_DATA, message XMAC_DATA, new state  SLEEP" << endl;
            return;
        }
        // data does not arrives in time// retransmission can be added
        if (msg->getKind() == XXMAC_DATA_TIMEOUT) {
            EV << "node " << address << " : State WAIT_DATA, message XMAC_DATA_TIMEOUT, new state SLEEP" << endl;
            // if something in the queue, wakeup soon.
            if (!txQueue->isEmpty())
                scheduleAt(simTime() + dblrand()*checkInterval, wakeup);
            else
                scheduleAt(simTime() + slotDuration, wakeup);
            macState = SLEEP;
            radio->setRadioMode(IRadio::RADIO_MODE_SLEEP);
            changeDisplayColor(BLACK);
            return;
        }
        break;
    case SEND_ACK:
        // send now the ack packet
        if (msg->getKind() == DELAY_FOR_ACK_WITHIN_REMOTE_RX) {
            EV_DEBUG << "node " << address << " : State SEND_ACK, message XXMAC_SEND_ACK, new state WAIT_ACK_TX" << endl;
            sendMacAck(); // send one short preamble packet immediately-used as an ack
            macState = WAIT_ACK_TX;
            return;
        }
        break;
    case WAIT_ACK_TX:
        // wait for the ACK to be sent back to the Transmitter
        if (msg->getKind() == XXMAC_ACK_TX_OVER) {
            EV_DEBUG << "node " << address << " : State WAIT_ACK_TX, message XXMAC_ACK_TX_OVER, new state WAIT_DATA" << endl;
            changeDisplayColor(GREEN);
            macState = WAIT_DATA;
            cancelEvent(cca_timeout);
            scheduleAt(simTime() + (slotDuration / 2), data_timeout);
            radio->setRadioMode(IRadio::RADIO_MODE_RECEIVER);
            return;
        }
        break;
    } //end switch(macstate)
    throw cRuntimeError("Undefined event of type %d in state %d (Radio state %d)!",
              msg->getKind(), macState, radio->getRadioMode());
}


Thanks

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
Message has been deleted

Alfonso Ariza Quintana

unread,
Jun 16, 2020, 4:15:34 AM6/16/20
to OMNeT++ Users
You can use the thrugmeter to measure the evolution of the througput.

Enviado: lunes, 15 de junio de 2020 15:55

Para: OMNeT++ Users <omn...@googlegroups.com>
Asunto: Re: [Omnetpp-l] How to schedule data transmission duration based on queue status
 
Hello Alfonso,

Sir, actually after implementing this, there is no change in the number of received packets.

Can you suggest how i can verify if my implementation is right or what change i should notice in output after impementing this?

I think in this case, throughput for each node should be better. Please correct me if i am wrong.

Can you suggest me how to calculate throughput per node? 

Thanks and Regards,

--
You received this message because you are subscribed to the Google Groups "OMNeT++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.

S Tanin

unread,
Jun 16, 2020, 4:55:54 AM6/16/20
to OMNeT++ Users
Hello Alfonso,

Sir, can you please refer me an example code for that? Is there any example given in INET for this module to measure throughput per node?

Thank you

Alfonso Ariza Quintana

unread,
Jun 16, 2020, 5:02:30 AM6/16/20
to OMNeT++ Users
You can check in inetmanet how to include it in the node definition

Enviado: martes, 16 de junio de 2020 10:55
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/f08b4053-6784-4c19-919e-c8e2737f5564o%40googlegroups.com.

S Tanin

unread,
Jun 29, 2020, 8:29:49 AM6/29/20
to OMNeT++ Users

Hello Alfonso, Sir I did not find any parameter named thrugmeter to measure throughput per node.

Would you refer me a file location, where I can see the example code to measure throughput per node?

Thank you

Alfonso Ariza Quintana

unread,
Jun 29, 2020, 8:56:55 AM6/29/20
to OMNeT++ Users
INET Framework for the OMNeT++ discrete event simulator - inet-framework/inet


Enviado: lunes, 29 de junio de 2020 14:29
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/omnetpp/46096497-08fb-49cd-bb56-766fa57d629co%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages