NS3中一些难以理解的常数
摘要:在NS3的学习中,PHY MAC中总有一些常数,需要理解才能修改。如帧间间隔等。那么,本文做个简单分析,帮助大家理解。针对802.11标准中MAC协议。
void
WifiMac::Configure80211b (void)
{
SetSifs (MicroSeconds (10));
SetSlot (MicroSeconds (20));
SetEifsNoDifs (MicroSeconds (10 + 304));
SetPifs (MicroSeconds (10 + 20));
SetCtsTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
SetAckTimeout (MicroSeconds (10 + 304 + 20 + GetDefaultMaxPropagationDelay ().GetMicroSeconds () * 2));
}
304是怎么来的呢??
1、PHY
采用DSSS,1Mbps模式下。在802.11-2012中,17.2.2.3节中,有PPDU format规定了帧格式。如下图:
其中,大家比较关心的2个参数就是 PLCP Preamble 和 PLCP Header,分别为144bits和48bits。也就是192us,英文为192 MicroSeconds。
计算时间的相关代码,在NS3中 wifi-phy.cc中,代码如下:
uint32_t
WifiPhy::GetPlcpHeaderDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble)
{
switch (payloadMode.GetModulationClass ())
{
case WIFI_MOD_CLASS_OFDM:
{
switch (payloadMode.GetBandwidth ())
{
case 20000000:
default:
// (Section 18.3.3 "PLCP preamble (SYNC))" and Figure 18-4 "OFDM training structure"; IEEE Std 802.11-2012)
// also (Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
// We return the duration of the SIGNAL field only, since the
// SERVICE field (which strictly speaking belongs to the PLCP
// header, see Section 18.3.2 and Figure 18-1) is sent using the
// payload mode.
return 4;
case 10000000:
// (Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
return 8;
case 5000000:
// (Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
return 16;
}
}
//Added by Ghada to support 11n
case WIFI_MOD_CLASS_HT:
{ //IEEE 802.11n Figure 20.1
switch (preamble)
{
case WIFI_PREAMBLE_HT_MF:
// L-SIG
return 4;
case WIFI_PREAMBLE_HT_GF:
//L-SIG
return 0;
default:
// L-SIG
return 4;
}
}
case WIFI_MOD_CLASS_ERP_OFDM:
return 4; case WIFI_MOD_CLASS_DSSS:
if (preamble == WIFI_PREAMBLE_SHORT)
{
// (Section 17.2.2.3 "Short PPDU format" and Figure 17-2 "Short PPDU format"; IEEE Std 802.11-2012)
return 24;
}
else // WIFI_PREAMBLE_LONG
{
// (Section 17.2.2.2 "Long PPDU format" and Figure 17-1 "Short PPDU format"; IEEE Std 802.11-2012)
return 48;
} default:
NS_FATAL_ERROR ("unsupported modulation class");
return 0;
}
} uint32_t
WifiPhy::GetPlcpPreambleDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble)
{
switch (payloadMode.GetModulationClass ())
{
case WIFI_MOD_CLASS_OFDM:
{
switch (payloadMode.GetBandwidth ())
{
case 20000000:
default:
// (Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
// also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
return 16;
case 10000000:
// (Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
// also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
return 32;
case 5000000:
// (Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
// also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
return 64;
}
}
case WIFI_MOD_CLASS_HT:
{ //IEEE 802.11n Figure 20.1 the training symbols before L_SIG or HT_SIG
return 16;
}
case WIFI_MOD_CLASS_ERP_OFDM:
return 16; case WIFI_MOD_CLASS_DSSS:
if (preamble == WIFI_PREAMBLE_SHORT)
{
// (Section 17.2.2.3 "Short PPDU format)" Figure 17-2 "Short PPDU format"; IEEE Std 802.11-2012)
return 72;
}
else // WIFI_PREAMBLE_LONG
{
// (Section 17.2.2.2 "Long PPDU format)" Figure 17-1 "Long PPDU format"; IEEE Std 802.11-2012)
return 144;
}
default:
NS_FATAL_ERROR ("unsupported modulation class");
return 0;
}
} double
WifiPhy::GetPayloadDurationMicroSeconds (uint32_t size, WifiTxVector txvector)
{
WifiMode payloadMode=txvector.GetMode(); NS_LOG_FUNCTION (size << payloadMode); switch (payloadMode.GetModulationClass ())
{
case WIFI_MOD_CLASS_OFDM:
case WIFI_MOD_CLASS_ERP_OFDM:
{
// (Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012
// corresponds to T_{SYM} in the table)
uint32_t symbolDurationUs; switch (payloadMode.GetBandwidth ())
{
case 20000000:
default:
symbolDurationUs = 4;
break;
case 10000000:
symbolDurationUs = 8;
break;
case 5000000:
symbolDurationUs = 16;
break;
} // (Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
// corresponds to N_{DBPS} in the table
double numDataBitsPerSymbol = payloadMode.GetDataRate () * symbolDurationUs / 1e6; // (Section 18.3.5.4 "Pad bits (PAD)" Equation 18-11; IEEE Std 802.11-2012)
uint32_t numSymbols = lrint (ceil ((16 + size * 8.0 + 6.0) / numDataBitsPerSymbol)); // Add signal extension for ERP PHY
if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM)
{
return numSymbols * symbolDurationUs + 6;
}
else
{
return numSymbols * symbolDurationUs;
}
}
case WIFI_MOD_CLASS_HT:
{
double symbolDurationUs;
double m_Stbc;
//if short GI data rate is used then symbol duration is 3.6us else symbol duration is 4us
//In the future has to create a stationmanager that only uses these data rates if sender and reciever support GI
if (payloadMode.GetUniqueName() == "OfdmRate135MbpsBW40MHzShGi" || payloadMode.GetUniqueName() == "OfdmRate65MbpsBW20MHzShGi" )
{
symbolDurationUs=3.6;
}
else
{
switch (payloadMode.GetDataRate ()/ (txvector.GetNss()))
{ //shortGi
case 7200000:
case 14400000:
case 21700000:
case 28900000:
case 43300000:
case 57800000:
case 72200000:
case 15000000:
case 30000000:
case 45000000:
case 60000000:
case 90000000:
case 120000000:
case 150000000:
symbolDurationUs=3.6;
break;
default:
symbolDurationUs=4;
}
}
if (txvector.IsStbc())
m_Stbc=2;
else
m_Stbc=1;
double numDataBitsPerSymbol = payloadMode.GetDataRate () *txvector.GetNss() * symbolDurationUs / 1e6;
//check tables 20-35 and 20-36 in the standard to get cases when nes =2
double Nes=1;
// IEEE Std 802.11n, section 20.3.11, equation (20-32)
uint32_t numSymbols = lrint (m_Stbc*ceil ((16 + size * 8.0 + 6.0*Nes) / (m_Stbc* numDataBitsPerSymbol))); return numSymbols * symbolDurationUs; }
case WIFI_MOD_CLASS_DSSS:
// (Section 17.2.3.6 "Long PLCP LENGTH field"; IEEE Std 802.11-2012)
NS_LOG_LOGIC (" size=" << size
<< " mode=" << payloadMode
<< " rate=" << payloadMode.GetDataRate () );
return lrint (ceil ((size * 8.0) / (payloadMode.GetDataRate () / 1.0e6))); default:
NS_FATAL_ERROR ("unsupported modulation class");
return 0;
}
} Time
WifiPhy::CalculateTxDuration (uint32_t size, WifiTxVector txvector, WifiPreamble preamble)
{
WifiMode payloadMode=txvector.GetMode();
double duration = GetPlcpPreambleDurationMicroSeconds (payloadMode, preamble)
+ GetPlcpHeaderDurationMicroSeconds (payloadMode, preamble)
+ GetPlcpHtSigHeaderDurationMicroSeconds (payloadMode, preamble)
+ GetPlcpHtTrainingSymbolDurationMicroSeconds (payloadMode, preamble,txvector)
+ GetPayloadDurationMicroSeconds (size, txvector);
return MicroSeconds (duration);
}
在函数CalculateTxDuration中,duration的计算方法。
那么,假如你开启4次握手机制,那么rts的duration如何计算呢?
也就是当你生成pacp文件,用wiresharp打开时,看到rts帧中,那个duration是怎么得到的呢?
如下图中17342 是怎么得到的呢?
你需要知道应用层的包是如何封装的,这涉及到计算机网络的知识。这里以上面的包大小举例说明,packet =2000bytes.
上图中可以看到:data—>udp(8)—>ip(20)—>llc(8)—>mac (28)包封装过程
ip和udp封装包头大小,一般计算机网络书中有介绍。llc 这个没搞懂为啥是8个。mac数据帧可以看下图:
一共40字节,但是地址4,qos,ht不用。ns3中使用的是non qos mac。
好了,我们开始计算,但是还需要看一个代码在mac-low.cc:
void
MacLow::SendRtsForPacket (void)
{
NS_LOG_FUNCTION (this);
/* send an RTS for this packet. */
WifiMacHeader rts;
rts.SetType (WIFI_MAC_CTL_RTS);
rts.SetDsNotFrom ();
rts.SetDsNotTo ();
rts.SetNoRetry ();
rts.SetNoMoreFragments ();
rts.SetAddr1 (m_currentHdr.GetAddr1 ());
rts.SetAddr2 (m_self);
WifiTxVector rtsTxVector = GetRtsTxVector (m_currentPacket, &m_currentHdr);
Time duration = Seconds (0); WifiPreamble preamble;
//standard says RTS packets can have GF format sec 9.6.0e.1 page 110 bullet b 2
if ( m_phy->GetGreenfield()&& m_stationManager->GetGreenfieldSupported (m_currentHdr.GetAddr1 ()))
preamble= WIFI_PREAMBLE_HT_GF;
else if (rtsTxVector.GetMode().GetModulationClass () == WIFI_MOD_CLASS_HT)
preamble= WIFI_PREAMBLE_HT_MF;
else
preamble=WIFI_PREAMBLE_LONG; if (m_txParams.HasDurationId ())
{
duration += m_txParams.GetDurationId ();
}
else
{
WifiTxVector dataTxVector = GetDataTxVector (m_currentPacket, &m_currentHdr);
duration += GetSifs ();
duration += GetCtsDuration (m_currentHdr.GetAddr1 (), rtsTxVector);
duration += GetSifs ();
duration += m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr),
dataTxVector, preamble);
duration += GetSifs ();
duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector);
}
rts.SetDuration (duration); Time txDuration = m_phy->CalculateTxDuration (GetRtsSize (), rtsTxVector, preamble);
Time timerDelay = txDuration + GetCtsTimeout (); NS_ASSERT (m_ctsTimeoutEvent.IsExpired ());
NotifyCtsTimeoutStartNow (timerDelay);
m_ctsTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::CtsTimeout, this); Ptr<Packet> packet = Create<Packet> ();
packet->AddHeader (rts);
WifiMacTrailer fcs;
packet->AddTrailer (fcs); ForwardDown (packet, &rts, rtsTxVector,preamble);
}
公式就是上面这个代码中提取出来的。sifs查这个802.11-2012中上图
duration += GetSifs (); 10
duration += GetCtsDuration (m_currentHdr.GetAddr1 (), rtsTxVector); cts:14*8+192=304
duration += GetSifs (); 10
duration += m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), dataTxVector, preamble); 2064*8+192=16704
duration += GetSifs ();10
duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxVector); ack:14*8+192=304
duration = 10+304+10+16704+10+304=17342
结果符合wiresharp中那个duration。
NS3中一些难以理解的常数的更多相关文章
- 通过作用域链解析js函数一些难以理解的的作用域问题
基本原理 js函数在执行时,系统会创建一个隐式的属性scope,scope中存储的是函数的作用域链. 通过对这个scope的分析,就能解释JavaScript中许多难以理解的问题: 例1: funct ...
- Java中hashcode的理解
Java中hashcode的理解 原文链接http://blog.csdn.net/chinayuan/article/details/3345559 怎样理解hashCode的作用: 以 java. ...
- RxSwift 系列(九) -- 那些难以理解的概念
前言 看完本系列前面几篇之后,估计大家也还是有点懵逼,本系列前八篇也都是参考RxSwift官方文档和一些概念做的解读.上几篇文章概念性的东西有点多,一时也是很难全部记住,大家脑子里面知道有这么个概念就 ...
- 难以理解的AQS(下)
在上一篇博客,简单的说下了AQS的基本概念,核心源码解析,但是还有一部分内容没有涉及到,就是AQS对条件变量的支持,这篇博客将着重介绍这方面的内容. 条件变量 基本应用 我们先通过模拟一个消费者/生产 ...
- Java的内部类真的那么难以理解?
01 前言 昨天晚上,我把车停好以后就回家了.回家后才发现手机落在车里面了,但外面太冷,冷到骨头都能感受到寒意——实在是不想返回一趟去取了(小区的安保还不错,不用担心被砸车玻璃),于是打定主意过几个小 ...
- 对于新手来说,Python 中有哪些难以理解的概念?
老手都是从新手一路过来的,提起Python中难以理解的概念,可能很多人对于Python变量赋值的机制有些疑惑,不过对于习惯于求根究底的程序员,只有深入理解了某个事物本质,掌握了它的客观规律,才能得心应 ...
- js中的闭包理解一
闭包是一个比较抽象的概念,尤其是对js新手来说.书上的解释实在是比较晦涩,对我来说也是一样. 但是他也是js能力提升中无法绕过的一环,几乎每次面试必问的问题,因为在回答的时候.你的答案的深度,对术语的 ...
- Fouandation(NSString ,NSArray,NSDictionary,NSSet) 中常见的理解错误区
Fouandation 中常见的理解错误区 1.NSString //快速创建(实例和类方法) 存放的地址是 常量区 NSString * string1 = [NSString alloc]init ...
- linux中socket的理解
对linux中socket的理解 一.socket 一般来说socket有一个别名也叫做套接字. socket起源于Unix,都可以用“打开open –> 读写write/read –> ...
随机推荐
- spark 源码分析之十二 -- Spark内置RPC机制剖析之八Spark RPC总结
在spark 源码分析之五 -- Spark内置RPC机制剖析之一创建NettyRpcEnv中,剖析了NettyRpcEnv的创建过程. Dispatcher.NettyStreamManager.T ...
- UVa 1440:Inspection(带下界的最小流)***
https://vjudge.net/problem/UVA-1440 题意:给出一个图,要求每条边都必须至少走一次,问最少需要一笔画多少次. 思路:看了好久才勉强看懂模板.良心推荐:学习地址. 看完 ...
- Codeforces 758B:Blown Garland(模拟)
http://codeforces.com/problemset/problem/758/B 题意:给出一个字符串,每4个位置对应一个颜色,如果为‘!’的话,代表该灯泡是坏的,问最后每个颜色坏的灯泡的 ...
- c++学习书籍推荐《数据结构C++语言描述:应用标准模板库STL(第2版)》下载
本书是Ford和Topp两位教授于1996看出版的名著Data Structures with C++的第2版,在全球范围内已经有数以万计的学生从中受益.作者将C++语言作为算法描述语言,应用包含规范 ...
- C语言学习书籍推荐《C语言入门经典(第5版)》下载
霍尔顿 (Ivor Horton) (作者), 杨浩 (译者) 下载地址:点我 C语言是每一位程序员都应该掌握的基础语言.C语言是微软.NET编程中使用的C#语言的基础:C语言是iPhone.iPad ...
- 与某公司CTO的一次闲聊
这是一次与某公司CTO的交流沟通,收获不少,记录下分享给大家,其中个别词句有自己增改成分. 既然是领导,就要学会画饼,画图的都是底下干活的. 管理好别人的预期,并能兑现承诺,不能只靠画大饼忽悠.针对某 ...
- 哈夫曼编码与解码的C++实现:建立哈夫曼树、进行哈夫曼编码与解码
最近完成了数据结构课程设计,被分到的题目是<哈夫曼编码和解码>,现在在这篇博文里分享一下自己的成果. 我在设计时,在网上参考了很多老师和前辈的算法和代码,向他们表示感谢!他们的成果给了我很 ...
- g++ -std=c++11 -g -o test emit_log_direct.cpp
g++ -std=c++11 -g -o test emit_log_direct.cpp
- 曹工杂谈:手把手带你读懂 JVM 的 gc 日志
一.前言 今天下午本来在划水,突然看到微信联系人那一个红点点,看了下,应该是博客园的朋友.加了后,这位朋友问了我一个问题: 问我,这两块有什么关系? 看到这段 gc 日志,一瞬间脑子还有点懵,嗯,这个 ...
- 物联网时代-跟着Thingsboard学IOT架构-MQTT设备协议
Thingsboard的MQTT设备协议 thingsboard官网: https://thingsboard.io/ thingsboard GitHub: https://github.com/t ...