implementing slotted aloha

724 views
Skip to first unread message

nasrin.ahmdp

unread,
May 30, 2018, 1:37:33 PM5/30/18
to ns-3-users

hello everyone

i need to implement the slotted aloha mac protocol. so as you know i need to devide the time to some slots like a system clock 

and all nodes just allowed to transmit at the beginnenig of timeslots . 

i am new to ns3. could you please guide me how to do it? Is there any similar implementation in ns3 ?

best regards.

jared...@gmail.com

unread,
Jun 1, 2018, 8:23:45 PM6/1/18
to ns-3-users
Nasrin,

There is the AlohaNoackNetDevice already in NS-3.  If you look at the code, the operative functions are SendFrom and StartTransmission.  In the former function, if the device is IDLE then the packet is sent ASAP.  This could be replaced with a scheduled transmission e.g. something like Simulator::Schedule(slotTime, &AlohaNoackNetDevice::StartTransmission, this).  That slotTime argument can be computed from Simulation::Now() and discretized to some slot size.  Likely you'd need to have another state like WAITING_FOR_TX to set in SendFrom to prevent subsequent calls to SendFrom from stomping on your previously scheduled transmission.  Hope that helps.

Good luck,
Jared.

nasrin.ahmdp

unread,
Jun 2, 2018, 1:50:15 AM6/2/18
to ns-3-users
hello jared
thank you so much for replying.
can you please tell me how to set the slot time in more detail?
when a node wants to send a packet how it can find out how much time left from the slot and when is the beginning of slot?
best regards

jared...@gmail.com

unread,
Jun 4, 2018, 5:48:30 PM6/4/18
to ns-3-users
Nasrin,

Well, I think you'll need to extend the Aloha class a bit.  You might be able to base the slot duration on the MTU or you can add a new attribute to specify the slot duration explicitly.  To determine when the next slot time is it seems the simplest thing to do would be assume all nodes are synchronized at time 0 and then just divide the current time (Simulation::Now()) by the slot duration.  If there's a remainder then you need to wait to the next integer multiple of the slot time.  You don't need the node (or maybe you mean application) to know when to send, it just sends and the netdevice handles delaying the packet transmission to the right slot time.  That's kind of what I was describing in my first post.  Try re-reading it and it might click.

Good luck,
Jared.

nasrin.ahmdp

unread,
Jun 7, 2018, 2:09:57 PM6/7/18
to ns-3-users
thank you jared 

 this is my code :

  rmind = fmod (Simulator::Now ().GetNanoSeconds () , slot_time ); //my slot should be in nano scale
  if (rmind == 0 ){
//if (rmind < (0.1*slot_time) || rmind  > (0.9*slot_time) ){
phy->StartTx (p);          //sending to the physical layer
NS_LOG_FUNCTION (this <<"now:"<<Simulator::Now ().GetNanoSeconds () << "reminder" << rmind);
 
  if (m_queue.size () > 0)       //if still there is packet(s) in the queue then start to send the next packet
{
  double backoff = rand () % 100000;
  Simulator::Schedule (PicoSeconds (backoff), &BackoffBasedNanoMacEntity::DoSendPacket, this);  //sending the next packet
}
}
else {
Simulator::Schedule (NanoSeconds (slot_time - rmind), &BackoffBasedNanoMacEntity::call_StartTx , this , phy , p  ); //wait for the beginning of next slot.
}
    }
    
but unfortunately i got more packet loss . could you please tell me whats wrong with my code ?
do you think i need a small interval to determine the beginning of slot?(like the second "if" that is commented ) or not...
if so , what should be its boundries?
best regards

jared...@gmail.com

unread,
Jun 13, 2018, 1:21:09 PM6/13/18
to ns-3-users
Well, there's a few things.  First it's hard to tell how this will work since the code is so out of context.  I don't know what function is executing this, Send?  SendFrom?  With respect to the packet losses, have you activated some of the logging facilities for the net device, phy, or channel?  That may clue you in to where the packets are being dropped.

If your slot time is nano-scale, then you might want to try a plain old modulo operator on integers rather than fmod that might give more precise rmind.  (BTW it's not reminder, rather the value returned from a modulo operation can be called the remainder.)  Second, you prob want to have a new state that flags whether a packet is already scheduled.  If so, then you want to queue up any incoming packets for transmit until that prior packet is sent.

Hope that helps.

amanda

unread,
Jun 17, 2018, 3:12:43 PM6/17/18
to ns-3-users
thank you so much for your help.
best regards
Reply all
Reply to author
Forward
0 new messages