REG : Calculatiing MAC delay in WIFI

482 views
Skip to first unread message

saumil shah

unread,
Feb 8, 2018, 11:50:31 AM2/8/18
to ns-3-users
Dear All,

I am interested in calculating MAC delay including backoff time. For wifi we have MacTX trace but this trace includes queue delay too.

I don't want to include queue delay in my calculation.

To capture the end time  we can use MacRx trace to capture when packet is received at mac layer.

Can anyone help me with it to provide any suggestion or direction?

Best Regards
Saumil


saumil shah

unread,
Feb 9, 2018, 10:58:10 AM2/9/18
to ns-3-users
Dear All,

I have done some studies and as per my understanding i am calculating MAC to MAC delay without including MAC queue delay as below.

I am basically using TimestampTag class to Tag the packet.

First:
I have added Tag inside Dequeue() method in file wifi-mac-queue.cc as shown below.

Ptr<const Packet>
WifiMacQueue::Dequeue (WifiMacHeader *hdr)
{

  Cleanup ();

  if (!m_queue.empty ())
    {
-----------
     
      TimestampTag timestamp;
      timestamp.SetTimestamp(Simulator::Now());
      i.packet->AddByteTag(timestamp);

     
return i.packet;
    }
 
  return 0;
}


Second:
I am removing Tag in ForwardUp() method in wifi-net-device.cc file as shown below.

void
WifiNetDevice::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
{
--------------------------------------------
if (type != NetDevice::PACKET_OTHERHOST)
    {
      m_mac->NotifyRx (packet);
      TimestampTag timestamp;
      if (packet->FindFirstMatchingByteTag (timestamp))
      {
          Time tx = timestamp.GetTimestamp();
          Time delay = Simulator::Now () - tx;
      }

      packet->RemoveHeader (llc);
      m_forwardUp (this, packet, llc.GetType (), from);
    }

I am removing Tag here because at this point we are calling NotifyRx which is basically MacRx trace.

Can anyone tell me if this way is correct to calculate MAC to MAC delay or am i doing something wrong here?

Best Regards
Saumil

Tommaso Pecorella

unread,
Feb 10, 2018, 3:25:50 PM2/10/18
to ns-3-users
Hi,

if you do it right, then I don't see why it should be a bad idea.

T.

saumil shah

unread,
Feb 11, 2018, 4:32:21 AM2/11/18
to ns-3-users
Hi Tommaso,


I have done it the way i have explained in above post. So i didn't get actually what do you exactly mean by if you do it right? 
It is just i want to know if am i missing something or logically is it correct or not?

Best Regards
Saumil

Tommaso Pecorella

unread,
Feb 11, 2018, 4:41:39 PM2/11/18
to ns-3-users
Hi,

if it works, then it's done right. Simple as that :D

T.

saumil shah

unread,
Feb 13, 2018, 5:48:03 AM2/13/18
to ns-3-users
Hi Tommaso,

As mentioned in above post i am calculating MAC to MAC delay and currently i am testing for different possibilities. But i have observed below things. Consider both cells are configured as WIFI.

1) When both AP of different cells are in deferring range of each other that time i am getting average delay for each AP is 4.12 ms and when both of them are not in deferring range of each other that time also i am getting same average delay of 4.12 ms for each AP.

2) As per my understanding when both AP are in range of each other that time we should get delay higher than when both are not in range of each other as APs have to wait because channel will be busy almost half of the time. So why it is not reflecting in average delay?

3) When i don't use frame aggregation that time i am always getting that time i am not getting any Delay values. That means where we are adding the timestamp to packet in wifi-mac-queue.cc file is not executing. Why is so? and to track delay in non frame aggregation case where can we add timestamp?

Steps to produce the results:
1) Put attached timestamp-tag.cc and timestamp-tag.h files to /ns3lbt/src/wifi/model/ directory and also add them to wscript.
2) Put attached laa-wifi-simple.cc file in to /ns3lbt/src/laa-wifi-coexistence/examples/ directory.
3) Put attached  wifi-mac-queue.cc and wifi-net-device.cc files in  /ns3lbt/src/wifi/model/  directory.

Run the script as below:

Case 1: When both APs are in range of each other
1) ./waf --run "laa-wifi-simple --logPhyArrivals=true --duration=10 --logBackoffChanges=true --logCwChanges=true --wifiQueueMaxSize=45 --d2=1" >> output.txt
2) Then copy all the below commands and run it in sequence. last two commands will give you the average delay for each AP.

grep from=00:00:00:00:00:06 output.txt >>AP1_differ.txt
grep from=00:00:00:00:00:02 output.txt >>AP2_differ.txt
sed -i 's/Delay=//g' AP1_differ.txt
sed -i 's/Delay=//g' AP2_differ.txt
sed -i 's/+//g' AP2_differ.txt
sed -i 's/+//g' AP1_differ.txt
sed -i 's/ns//g' AP1_differ.txt
sed -i 's/ns//g' AP2_differ.txt
sed -i 's/from=00:00:00:00:00:06//g' AP1_differ.txt
sed -i 's/from=00:00:00:00:00:02//g' AP2_differ.txt
sed -i 's/to=00:00:00:00:00:03//g' AP2_differ.txt
sed -i 's/to=00:00:00:00:00:07//g' AP1_differ.txt
sed -i 's/To=00:00:00:00:00:07//g' AP1_differ.txt
sed -i 's/To=00:00:00:00:00:03//g' AP2_differ.txt
sed -i 's/,//g' AP2_differ.txt
sed -i 's/,//g' AP1_differ.txt
sort -n AP1_differ.txt >> AP1_delay_differ.txt
sort -n AP2_differ.txt >> AP2_delay_differ.txt

awk '{ total += $1 } END { print total/NR }' AP2_delay_differ.txt
awk '{ total += $1 } END { print total/NR }' AP1_delay_differ.txt

Case 2: When both APs are not in range of each other
1) ./waf --run "laa-wifi-simple --logPhyArrivals=true --duration=10 --logBackoffChanges=true --logCwChanges=true --wifiQueueMaxSize=45 --d2=200" >> outpu2.txt
2) Then copy all the below commands and run it in sequence. last two commands will give you the average delay for each AP.

grep from=00:00:00:00:00:06 output2.txt >>AP1_nodiffer.txt
grep from=00:00:00:00:00:02 output2.txt >>AP2_nodiffer.txt
sed -i 's/Delay=//g' AP1_nodiffer.txt
sed -i 's/Delay=//g' AP2_nodiffer.txt
sed -i 's/+//g' AP2_nodiffer.txt
sed -i 's/+//g' AP1_nodiffer.txt
sed -i 's/ns//g' AP1_nodiffer.txt
sed -i 's/ns//g' AP2_nodiffer.txt
sed -i 's/from=00:00:00:00:00:06//g' AP1_nodiffer.txt
sed -i 's/from=00:00:00:00:00:02//g' AP2_nodiffer.txt
sed -i 's/to=00:00:00:00:00:03//g' AP2_nodiffer.txt
sed -i 's/to=00:00:00:00:00:07//g' AP1_nodiffer.txt
sed -i 's/To=00:00:00:00:00:07//g' AP1_nodiffer.txt
sed -i 's/To=00:00:00:00:00:03//g' AP2_nodiffer.txt
sed -i 's/,//g' AP2_nodiffer.txt
sed -i 's/,//g' AP1_nodiffer.txt
sort -n AP1_nodiffer.txt >> AP1_delay_nodiffer.txt
sort -n AP2_nodiffer.txt >> AP2_delay_nodiffer.txt

awk '{ total += $1 } END { print total/NR }' AP2_delay_nodiffer.txt
awk '{ total += $1 } END { print total/NR }' AP1_delay_nodiffer.txt

Case 3 : No frame Aggregation.
1) In laa-wifi-simple file set BE_BlockAckThreshold to 0.
 Config::SetDefault ("ns3::RegularWifiMac::BE_BlockAckThreshold", UintegerValue (0));

2)./waf --run "laa-wifi-simple --logPhyArrivals=true --duration=10 --logBackoffChanges=true --logCwChanges=true --wifiQueueMaxSize=45 --d2=200" >> outpu3.txt

3) If you check the output3.txt file then there will be no Delay values.

Kindly help me to understand this or let me know if my understanding is wrong.

Best Regards
Saumil
timestamp-tag.cc
timestamp-tag.h
wifi-mac-queue.cc
wifi-net-device.cc
laa-wifi-simple.cc

saumil shah

unread,
Feb 14, 2018, 6:07:15 AM2/14/18
to ns-3-users
Hi Tommaso,

-----Update------------

The logic i have applied to add timestamp when packet will dequeue is not considering the backoff time. It is considering the time when it starts transmission. I have verified this based on first tx timestamp and checking the same in PhyTxBegin trace. Both are equal and once we use aggregation each sub frame will be delayed by payload duration which is 190030 ns in my case.

Check the attached picture to see the same. All  aggregated frame will dequeue at same time so they will have same tx timestamp but different delay as each payload duration will be added for the next frame delay.

And as tx timestamp in dequeue function is not considering backoff time we are getting same delay when both APs are in range of each other and when they are not in the range of each other.

I have found below two threads related to similar question.

https://groups.google.com/forum/#!searchin/ns-3-users/DIFS%7Csort:date/ns-3-users/eqhP0wzgUXI/Emky3l2aFwAJ

in above thread Tom has suggested to extract information from DcfManager LOG. I have tried the same but it is not matching with what Tom has suggested.

2.00482s 1 DcfManager:MostRecent(0x73dfe0, +2002747840.0ns, +2004619840.0ns)
2.00482s 1 DcfManager:UpdateBackoff(): +2004819840.0ns 0x73dfe0 dcf 2 dec backoff slots=0

So here we do as per Tom's suggestion 2004819840.0 ns - 2002747840.0 ns = 2072 us which we can't get based on 0 back off slots.

https://groups.google.com/forum/#!searchin/ns-3-users/wifi$20mac$20delay/ns-3-users/CRg6fKLHMzs/gqj6b0BCfi8J

In above thread Sebastein suggested to add trace when backoff starts. I have added the below print statement in StartBackoffNow() function

void
DcfState::StartBackoffNow (uint32_t nSlots)
{
  NS_ASSERT (m_backoffSlots == 0);
  MY_DEBUG ("start backoff=" << nSlots << " slots");
  m_backoffSlots = nSlots;
  m_backoffStart = Simulator::Now ();
  std::cout << "backoffslots=" << m_backoffSlots << "  m_backoffStart=" << m_backoffStart<<std::endl;
}
Also i am printing delays as per initial logic too. So i am getting below output.

backoffslots=4  m_backoffStart=+2035459840.0ns
Delay=+226369.0ns,from=00:00:00:00:00:06,To=00:00:00:00:00:07   tx=+2035615840.0ns   now_time=+2035842209.0ns
Delay=+416399.0ns,from=00:00:00:00:00:06,To=00:00:00:00:00:07   tx=+2035615840.0ns   now_time=+2036032239.0ns
Delay=+606429.0ns,from=00:00:00:00:00:06,To=00:00:00:00:00:07   tx=+2035615840.0ns   now_time=+2036222269.0ns
Delay=+796459.0ns,from=00:00:00:00:00:06,To=00:00:00:00:00:07   tx=+2035615840.0ns   now_time=+2036412299.0ns
Delay=+986489.0ns,from=00:00:00:00:00:06,To=00:00:00:00:00:07   tx=+2035615840.0ns   now_time=+2036602329.0ns
Delay=+1176519.0ns,from=00:00:00:00:00:06,To=00:00:00:00:00:07   tx=+2035615840.0ns   now_time=+2036792359.0ns
Delay=+1366549.0ns,from=00:00:00:00:00:06,To=00:00:00:00:00:07   tx=+2035615840.0ns   now_time=+2036982389.0ns

So basically as per my understanding here before transmission of A-MPDU random backoff will start at m_backoffStart time. If we calculate based on number of slot total back off duration and if we add extra DIFS then also it will not match with tx time which can be reasoned based on that during backoff if channel is found busy then backoff will freeze so that time will also we be added but in that i am not interested.

based on this whatever delay we were getting before we need to add extra delay (backoff delay) = tx - m_backoffStart for each received A-MPDU.

Can you tell me if this understanding is correct or here again am i missing something or is there some other delays also need to be added ?

Also this is the case when we use aggregation. But when we don't use it then how it can be done? Because as i have explained in above post that when we don't use aggregation Dequeue is not triggred and hence tx timestamp is not added and i am not getting delay. This is might be related to comment from Sebastien in the post "if queue is empty this will not work".

Best Regards
Saumil
Screenshot from 2018-02-13 18-13-01.png
Reply all
Reply to author
Forward
0 new messages