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/Emky3l2aFwAJin 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/gqj6b0BCfi8JIn 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