30 static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator") |
30 static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator") |
31 .SetParent<Object> () |
31 .SetParent<Object> () |
32 .AddConstructor<AirtimeLinkMetricCalculator> () |
32 .AddConstructor<AirtimeLinkMetricCalculator> () |
33 .AddAttribute ( "TestLength", |
33 .AddAttribute ( "TestLength", |
34 "Rate should be estimated using test length.", |
34 "Rate should be estimated using test length.", |
35 UintegerValue (1024), |
35 UintegerValue (1024), |
36 MakeUintegerAccessor ( |
36 MakeUintegerAccessor ( |
37 &AirtimeLinkMetricCalculator::SetTestLength), |
37 &AirtimeLinkMetricCalculator::SetTestLength), |
38 MakeUintegerChecker<uint16_t> (1) |
38 MakeUintegerChecker<uint16_t> (1) |
39 ) |
39 ) |
40 .AddAttribute ( "Dot11MetricTid", |
40 .AddAttribute ( "Dot11MetricTid", |
41 "TID used to calculate metric (data rate)", |
41 "TID used to calculate metric (data rate)", |
42 UintegerValue (0), |
42 UintegerValue (0), |
43 MakeUintegerAccessor ( |
43 MakeUintegerAccessor ( |
44 &AirtimeLinkMetricCalculator::SetHeaderTid), |
44 &AirtimeLinkMetricCalculator::SetHeaderTid), |
45 MakeUintegerChecker<uint8_t> (0) |
45 MakeUintegerChecker<uint8_t> (0) |
46 ) |
46 ) |
47 .AddAttribute ( "Dot11sMeshHeaderLength", |
47 .AddAttribute ( "Dot11sMeshHeaderLength", |
48 "Length of the mesh header", |
48 "Length of the mesh header", |
49 UintegerValue (6), |
49 UintegerValue (6), |
50 MakeUintegerAccessor ( |
50 MakeUintegerAccessor ( |
51 &AirtimeLinkMetricCalculator::m_meshHeaderLength), |
51 &AirtimeLinkMetricCalculator::m_meshHeaderLength), |
52 MakeUintegerChecker<uint16_t> (0) |
52 MakeUintegerChecker<uint16_t> (0) |
53 ) |
53 ) |
54 ; |
54 ; |
55 return tid; |
55 return tid; |
56 } |
56 } |
57 AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator () : |
57 AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator () : |
58 m_overheadNanosec (0) |
58 m_overheadNanosec (0) |
59 { |
59 { |
67 m_testHeader.SetQosTid (tid); |
67 m_testHeader.SetQosTid (tid); |
68 } |
68 } |
69 void |
69 void |
70 AirtimeLinkMetricCalculator::SetTestLength (uint16_t testLength) |
70 AirtimeLinkMetricCalculator::SetTestLength (uint16_t testLength) |
71 { |
71 { |
72 m_testFrame = Create<Packet> (testLength + 6 /*Mesh header*/ + 36/*802.11 header*/); |
72 m_testFrame = Create<Packet> (testLength + 6 /*Mesh header*/ + 36 /*802.11 header*/); |
73 } |
73 } |
74 uint32_t |
74 uint32_t |
75 AirtimeLinkMetricCalculator::CalculateMetric (Mac48Address peerAddress, Ptr<MeshWifiInterfaceMac> mac) |
75 AirtimeLinkMetricCalculator::CalculateMetric (Mac48Address peerAddress, Ptr<MeshWifiInterfaceMac> mac) |
76 { |
76 { |
77 /* Airtime link metric is defined in 11B.10 of 802.11s Draft D3.0 as: |
77 /* Airtime link metric is defined in 11B.10 of 802.11s Draft D3.0 as: |
89 WifiMode mode = mac->GetWifiRemoteStationManager ()->GetDataMode (peerAddress, &m_testHeader, m_testFrame, m_testFrame->GetSize ()); |
89 WifiMode mode = mac->GetWifiRemoteStationManager ()->GetDataMode (peerAddress, &m_testHeader, m_testFrame, m_testFrame->GetSize ()); |
90 //obtain frame error rate: |
90 //obtain frame error rate: |
91 double failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate (); |
91 double failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate (); |
92 NS_ASSERT (failAvg < 1.0); |
92 NS_ASSERT (failAvg < 1.0); |
93 //calculate metric |
93 //calculate metric |
94 uint32_t metric = (uint32_t)((double)(/*Overhead + payload*/ |
94 uint32_t metric = (uint32_t)((double)( /*Overhead + payload*/ |
95 mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs |
95 mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs |
96 mac->GetWifiPhy () ->CalculateTxDuration (m_testFrame->GetSize (), mode, WIFI_PREAMBLE_LONG) |
96 mac->GetWifiPhy ()->CalculateTxDuration (m_testFrame->GetSize (), mode, WIFI_PREAMBLE_LONG) |
97 ).GetMicroSeconds () / (10.24 * (1.0 - failAvg))); |
97 ).GetMicroSeconds () / (10.24 * (1.0 - failAvg))); |
98 return metric; |
98 return metric; |
99 } |
99 } |
100 } //namespace dot11s |
100 } //namespace dot11s |
101 } //namespace ns3 |
101 } //namespace ns3 |